标签:
原题链接在这里:https://leetcode.com/problems/reverse-string/
题目:
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh".
题解:
Reverse string是常见题, string在Java中是primitive类型, 一旦生成不可改变.
AC Java:
1 public class Solution { 2 public String reverseString(String s) { 3 if(s == null || s.length() == 0){ 4 return s; 5 } 6 7 StringBuilder sb = new StringBuilder(s); 8 return sb.reverse().toString(); 9 } 10 }
标签:
原文地址:http://www.cnblogs.com/Dylan-Java-NYC/p/5812194.html