A simple solution loop from the back of the original string.


  • 0
    F

    A simple solution loop from the back of the original string.

    public class Solution {
    public String reverseString(String s) {
    char[] chars = s.toCharArray();
    StringBuffer buffer = new StringBuffer();
    for (int i=s.length()-1; i>=0; i--) {
    buffer.append(chars[i]);
    }
    return buffer.toString();
    }
    }


Log in to reply
 

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