Java Solution in O(n) time


  • 0
    S

    public class Solution {
    public String reverseString(String s) {
    int len = s.length();
    char[] arr = new char[len];
    for(int i=0; i<len ; i++){
    arr[i]= s.charAt(len-i-1); // check that the string index go from 0 to len-1
    }
    return new String(arr);
    }
    }


Log in to reply
 

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