IncredibleThings

导航

LeetCode-Reverse String

Write a function that takes a string as input and returns the string reversed.

Example:
Given s = "hello", return "olleh".
public class Solution {
    public String reverseString(String s) {
        char[] c=new char[s.length()];
        int j=0;
        for(int i=s.length()-1; i>=0; i--){
            c[j]=s.charAt(i);
            j++;
        }
        return new String(c);
    }
}

 

posted on 2016-07-19 03:28  IncredibleThings  阅读(91)  评论(0编辑  收藏  举报