字符串反序输出

题目: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();
    }
}

字符串反序输出_第1张图片

你可能感兴趣的:(leetcode)