字符串反序输出

来源:互联网 发布:python 渗透测试 编辑:程序博客网 时间:2024/06/05 09:08

题目: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) {        int size = s.length();        StringBuilder sb = new StringBuilder();        for (int i=size - 1; i>=0; i--) {            sb.append(s.charAt(i));        }        return sb.toString();    }}

性能排名

0 0
原创粉丝点击