首页 > 代码库 > [leetcode] 344.Reverse String

[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();    }

 

[leetcode] 344.Reverse String