Java solution- O(n)

  • 0

    Time complexity: O(n). Travel the input string array index.
    Space complexity: O(n). Depend on how many chars are stored in the StringBuffer.

      class Solution {
        public String reverseString(String s) {
    		StringBuffer buildS= new StringBuffer();
    		for(int i= s.length()-1; i >=0 ; i--){
    		return buildS.toString();

Log in to reply

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