当前位置:网站首页>【LeetCode】344-反转字符串
【LeetCode】344-反转字符串
2022-07-02 12:09:00 【酥酥~】
编写一个函数,其作用是将输入的字符串反转过来。输入字符串以字符数组 s 的形式给出。
不要给另外的数组分配额外的空间,你必须原地修改输入数组、使用 O(1) 的额外空间解决这一问题。
示例 1:
输入: s = [“h”,“e”,“l”,“l”,“o”]
输出: [“o”,“l”,“l”,“e”,“h”]
示例 2:
输入: s = [“H”,“a”,“n”,“n”,“a”,“h”]
输出: [“h”,“a”,“n”,“n”,“a”,“H”]
提示:
- 1 <= s.length <= 105
- s[i] 都是 ASCII 码表中的可打印字符
#利用python数列特征直接反转
class Solution(object):
def reverseString(self, s):
s[:]=s[::-1]
#双指针
class Solution(object):
def reverseString(self, s):
left = 0
right = len(s)-1
while left<right:
tmp = s[left]
s[left] = s[right]
s[right] = tmp
left+=1
right-=1
边栏推荐
- 18_ Redis_ Redis master-slave replication & cluster building
- 面对“缺芯”挑战,飞凌如何为客户产能提供稳定强大的保障?
- Let your HMI have more advantages. Fet-g2ld-c core board is a good choice
- LeetCode刷题——两整数之和#371#Medium
- Party History Documentary theme public welfare digital cultural and creative products officially launched
- Common English abbreviations for data analysis (I)
- Bing.com網站
- Case introduction and problem analysis of microservice
- 5. Practice: jctree implements the annotation processor at compile time
- The traversal methods of binary tree mainly include: first order traversal, middle order traversal, second order traversal, and hierarchical traversal. First order, middle order, and second order actu
猜你喜欢
随机推荐
13_ Redis_ affair
Infra11199 database system
. Solution to the problem of Chinese garbled code when net core reads files
Record an interview
13_Redis_事务
18_ Redis_ Redis master-slave replication & cluster building
工程师评测 | RK3568开发板上手测试
16_ Redis_ Redis persistence
搭建自己的语义分割平台deeplabV3+
How to solve the problem of database content output
Yolo format data set processing (XML to txt)
The traversal methods of binary tree mainly include: first order traversal, middle order traversal, second order traversal, and hierarchical traversal. First order, middle order, and second order actu
Deploy tidb cluster with tiup
Solve the problem of frequent interruption of mobaxterm remote connection
SQL transaction
Map introduction
SQL stored procedure
Common English abbreviations for data analysis (I)
夏季高考文化成绩一分一段表
高考录取分数线爬取