String reverse with Strbuf / T : O(N), S : O(N)


  • 0
    J
    public String reverseString(String s) {
            StringBuffer strbuf = new StringBuffer();
            for(int i = s.length() - 1; i >= 0; i--){
                strbuf.append(s.charAt(i));
            }
            return strbuf.toString();
        }
    

Log in to reply
 

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