[leetcode] 344.Reverse String 解题报告

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

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

即反转字符串,逆序遍历依次append到StringBuffer即可

一刷:

    public String reverseString(String s) {
        StringBuffer sb=new StringBuffer();
        for(int i=0;i<s.length();i++){
            sb.append(s.charAt(s.length()-1-i));
        }
        return sb.toString();
    }

 

posted @ 2016-09-04 21:49  pulusite  阅读(105)  评论(0编辑  收藏  举报