Leetcode no. 344
2016-05-25 17:11
288 查看
344. Reverse String
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh".
public class Solution {
public String reverseString(String s) {
if (s.length()==0) return s;
char[] c= s.toCharArray();
int i=0, j=c.length-1;
while (i<j){
char tmp= c[i];
c[i]=c[j];
c[j]=tmp;
i++; j--;
}
return new String(c);
}
}
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh".
public class Solution {
public String reverseString(String s) {
if (s.length()==0) return s;
char[] c= s.toCharArray();
int i=0, j=c.length-1;
while (i<j){
char tmp= c[i];
c[i]=c[j];
c[j]=tmp;
i++; j--;
}
return new String(c);
}
}
相关文章推荐
- 网络流
- MySQL索引设计一些策略
- 深入理解异步加载--Handler和Looper源码解析(1)
- 如何学习 Javascript
- UITextView动态调整高度
- ayoutSubviews layoutIfNeeded setNeedsLayout 的区别
- iOS开发之高级视图—— UITableView(五)表视图索引
- 《Head First C#》学习 ---第一个实例中遇到的问题
- 多重背包
- 第13周阅读程序——虚析构函数
- HDU 5691 状压dp
- Android 同步网络时间
- MQ基础
- 面试题目——《剑指Offer》
- NSOperationQueue
- 请求编码与响应编码
- Java 多态的主板示例
- 蓝牙4.0
- iOS 添加翼支付打包上传出错 ERROR ITMS-90535
- Volley的基本用法 使用Volley加载网络图片