Java solution


  • 0
    class Solution {
        public String reverseString(String s) {
            if(s == null || s.length() < 2) {
                return s;
            }
            char[] stringArray = s.toCharArray();
            
            for(int i = 0, j = s.length() - 1; i < j; i++, j--) {
                char temp = stringArray[j];
                stringArray[j] = stringArray[i];
                stringArray[i] = temp;
            }
            return new String(stringArray);
        }
    }
    

Log in to reply
 

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