Reverse String Using Java


  • 0
    K

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


Log in to reply
 

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