Java Solution


  • 0
    P
    class Solution {
        public String reverseString(String s) {
            char[] word = s.toCharArray();
            int i = 0;
            int j = word.length - 1;
            
            while(i<j){
                char c = word[i];
                word[i] = word[j];
                word[j] = c;
                i++;
                j--;
            }
            
            return new String(word);
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.