首页 > 编程语言 > 详细

344. Reverse String Java Solutions

时间:2016-05-01 17:39:56      阅读:249      评论:0      收藏:0      [点我收藏+]

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

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

Subscribe to see which companies asked this question

 

 1 public class Solution {
 2     public String reverseString(String s) {
 3         if(s == null || s.length() <=1) return s;
 4         StringBuffer res = new StringBuffer(s.length());
 5         for(int i = s.length()-1;i >=0 ;i--){
 6             res.append(s.charAt(i));
 7         }
 8         return res.toString();
 9     }
10 }

 

344. Reverse String Java Solutions

原文:http://www.cnblogs.com/guoguolan/p/5450795.html

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