Java Solution in O(log n) time without using functions


  • 0
    B
        public String reverseString(String s) {
            char[] try1 = s.toCharArray();
            int j = 0;
            char t = 'a';
    		for (int i = try1.length-1; i>j; i--){
    		    t = try1[j];
    		    try1[j]=try1[i];
    		    try1[i] = t;
    		    j++;
    		}
    		return new String(try1);
        }
    }
    

Log in to reply
 

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