Reverse String

1. Title

344. Reverse String

2. Http address

https://leetcode.com/problems/reverse-string/

3. The question

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

Example:
Given s = "hello", return "olleh".

 

4 My code(AC)

public class Solution {
    public String reverseString(String s) {
        
        
        if( s == null)
            return s;
        int len = s.length();
        if( len <=0)
            return s;
        
        StringBuilder sb = new StringBuilder();
        int index = len -1;
        while(index >= 0)
        {
            sb.append(s.charAt(index--));
        }
        
        return sb.toString();
    
    }
}

 

posted @ 2016-05-19 17:29  ordi  阅读(94)  评论(0编辑  收藏  举报