Advertisement
exmkg

1-5

Jan 14th, 2025
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | None | 0 0
  1. public class Solution {
  2.     public String reverseString(char[] s) {
  3.         int i = 0;
  4.         int j = s.length - 1;
  5.         while (i < j) {
  6.             char temp = s[i];
  7.             s[i] = s[j];
  8.             s[j] = temp;
  9.             i++;
  10.             j--;
  11.         }
  12.         return null;
  13.     }
  14. }
  15.  
  16.  
  17.  
  18. public class Solution {
  19.     public String reverseString(char[] s) {
  20.         char[] t = new StringBuilder().append(s).reverse().toString().toCharArray();
  21.         System.arraycopy(t, 0, s, 0, s.length);
  22.         return null;
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement