Leetcode题解14 344. Reverse String

来源:互联网 发布:js unix时间戳转换 编辑:程序博客网 时间:2024/05/29 11:10

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) {        StringBuilder sb=new StringBuilder();        for(int i=s.length()-1;i>=0;i--){            sb.append(s.charAt(i));        }        return sb.toString();    }}
0 0
原创粉丝点击