Java solution, constant time, a two line code :)

  • 0

    String builder because, String objects are immutable so there'll be n objects if we try using String, whereas StringBuilder is mutable, also it has an existing reverse function available :)

    class Solution {
        public String reverseString(String s) {
            StringBuilder r = new StringBuilder(s);        
            return r.reverse().toString();

Log in to reply

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