首页 > 其他 > 详细

LeetCode Reverse String

时间:2016-08-27 06:31:15      阅读:238      评论:0      收藏:0      [点我收藏+]

原题链接在这里: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 }

 

LeetCode Reverse String

原文:http://www.cnblogs.com/Dylan-Java-NYC/p/5812194.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!