Skip to content

Latest commit

 

History

History
22 lines (16 loc) · 457 Bytes

Reverse_String.md

File metadata and controls

22 lines (16 loc) · 457 Bytes

344. Reverse String

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

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

Code:

class Solution {
    public String reverseString(String s) {
        StringBuilder sb = new StringBuilder(s);
        return sb.reverse().toString();
    }
}

解题思路

  • 使用使用字符串构造StringBuilder;
  • 使用StringBuilder的reverse函数和toString函数。