Accepted Java using StringBuilder (simple solution)


  • 0
    V

    Hi all! I am new at coding, so any tips on how I could improve my code will be appreciated!!

    class Solution {
        public String reverseString(String s) {
            StringBuilder sb = new StringBuilder();
            for(int i=s.length()-1;i>=0;i--){
                sb.append(s.charAt(i));
            }
            return sb.toString();
        }
    }
    

    this is O(N) time complexity


Log in to reply
 

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