码迷,mamicode.com
首页 > 编程语言 > 详细

344. Reverse String Java Solutions

时间:2016-05-01 17:40:03      阅读:248      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!