344. Reverse String
2017-05-09 21:58
309 查看
344. Reverse String
Write a function that takes a string as input and returns the string reversed. Example: Given s = "hello", return "olleh".
解:
可以直接用python的字符串处理,也可以用交换字符的位置来完成,交换位置的话需要先把字符串拆分成一个个字符,因为字符串是不可变的,最后用了join()来拼接字符。
class Solution(object): def reverseString(self, s): """ :type s: str :rtype: str """ #return s[::-1] s = list(s) i = 0 j = len(s) - 1 while(i < j): temp = s[i] s[i] = s[j] s[j] = temp i += 1 j -= 1 return ''.join(s)
相关文章推荐
- 344-e-Reverse String
- [LeetCode]-344. Reverse String(Easy)(C)
- leetcode No344.Reverse String Note
- 344. Reverse String
- Python [Leetcode 344]Reverse String
- LeetCode----344. Reverse String 字符串反转
- leetcode_c++: Reverse String(344)
- reverse string (leetcode 344) java
- leetcode --344. Reverse String
- 小白笔记--------------leetcode(344. Reverse String)
- Leetcode 344 Reverse String
- 344.Reverse String
- 344. Reverse String
- 344. Reverse String
- LeetCode——344. Reverse String(字符串反转)
- 344. Reverse String
- 344. Reverse String
- leetcode_344_ Reverse String(C++)(easy)
- LeetCode 第 344 题(Reverse String)
- leetcode_344 Reverse String