Loop


  • 0
    V

    Algorithm
    The solution is straight-forward. We check each of the char of the String. Then concat every single char to string

    String reverseString(String s) {
    if (s == null || s.length() == 0)
    return "";
    StringBuilder ret = new StringBuilder();
    for (int i = s.length() - 1; i > -1; i --) {
    ret.append(s.charAt(i));
    }
    return ret.toString();
    }

    Complexity Analysis

    The run time depends on the String in s. the time complexity is O(1)O(1).


Log in to reply
 

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