LeetCode012 : python反转字符串
2019-03-03 20:12
225 查看
原题地址:
https://leetcode-cn.com/problems/reverse-string/
题目描述
编写一个函数,其作用是将输入的字符串反转过来。输入字符串以字符数组
char[]的形式给出。
不要给另外的数组分配额外的空间,你必须原地修改输入数组、使用 O(1) 的额外空间解决这一问题。
你可以假设数组中的所有字符都是 ASCII 码表中的可打印字符。
示例 1:
[code]输入:["h","e","l","l","o"] 输出:["o","l","l","e","h"]
示例 2:
[code]输入:["H","a","n","n","a","h"] 输出:["h","a","n","n","a","H"]
[code]class Solution: def reverseString(self, s): """ :type s: str :rtype: str """ n = len(s) ret = [] for i in range(n): ret.append(s[n - i - 1]) return "".join(ret)
相关文章推荐
- [leetcode, python] Reverse Words in a String 反转字符串
- [Leetcode,python] Reverse String 反转字符串
- [leetcode, python] Reverse Words in a String 反转字符串
- LeetCode 345. 反转字符串中的元音字母 Python
- [Leetcode,python] Reverse String 反转字符串
- [leetcode, python] Reverse Words in a String 反转字符串
- LeetCode557.python实现: 反转字符串中的单词 III问题☆
- [Leetcode,python] Reverse String 反转字符串
- [leetcode, python] Reverse Words in a String 反转字符串
- LeetCode344.python实现: 反转字符串问题☆
- [Leetcode,python] Reverse String 反转字符串
- [leetcode, python] Reverse Words in a String 反转字符串
- LeetCode--Reverse String 反转字符串(Python)
- [Leetcode,python] Reverse String 反转字符串
- [leetcode, python] Reverse Words in a String 反转字符串
- leetcode-344. 反转字符串[python]
- [Leetcode,python] Reverse String 反转字符串
- 【LeetCode】Python实现-557. 反转字符串中的单词 III
- [leetcode, python] Reverse Words in a String 反转字符串
- [Leetcode,python] Reverse String 反转字符串