LeetCode之Reverse String
来源:互联网 发布:淘宝电器商城首页 编辑:程序博客网 时间:2024/06/04 19:20
1、题目:
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh".
2、代码实现:
代码实现1:
public static String reverseString(String s) { if (s == null) { return null; } if (s.length() == 0) { return ""; } int length = s.length(); char[] chars = s.toCharArray(); String result = ""; for (int i = chars.length - 1; i >=0; --i) { result += chars[i]; } return result; }
代码实现2:
public String reverseString(String s) { return new StringBuffer(s).reverse().toString(); }
0 0
- LeetCode之Reverse String
- Leetcode之Reverse String 问题
- leetcode之Reverse Words in a string
- leetcode之Reverse Words in a String
- leetcode之Reverse Words in a String
- LeetCode之Reverse Words in a String
- Leetcode之Reverse Words in a String
- leetcode之Reverse Words in a String
- Leetcode之Reverse Words in a String
- LeetCode之Reverse Words in a String
- 【Leetcode】之 Reverse Words in a String
- leetcode之Reverse Vowels of a String
- leetcode算法题总结之Reverse String
- Leetcode之路 344. Reverse String
- leetcode 刷题之: reverse string
- LeetCode之路:344. Reverse String
- LeetCode之路:541. Reverse String II
- leetcode(2)--String reverse
- 字符串反转方法
- 2016北京PHP39期 ThinkPHP Discuz Dedecms 微信开发视频教程
- 排序数组内的查找——二分查找
- jquery获取c:foreach出来的onclick事件
- 顺序表应用4:元素位置互换之逆置算法
- LeetCode之Reverse String
- [07]javascript函数
- 网络爬虫之lxml
- ios上传appStore所需各种图片尺寸
- Qt UDP聊天软件
- 如何隐藏IP地址
- 第四周工作总结
- [编程题] 跳石板
- Pandas 数据框增、删、改、查、去重、抽样基本操作