当前位置:网站首页>【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
边栏推荐
- LeetCode刷题——统计各位数字都不同的数字个数#357#Medium
- 14_Redis_乐观锁
- PHP method to get the index value of the array item with the largest key value in the array
- MySQL -- Index Optimization -- order by
- 你不知道的Set集合
- 数据分析思维分析方法和业务知识——业务指标
- Engineer evaluation | rk3568 development board hands-on test
- 【网络安全】网络资产收集
- Apprendre le Code de la méthode de conversion du calendrier lunaire grégorien en utilisant PHP
- Common English abbreviations for data analysis (I)
猜你喜欢
Leetcode question brushing - parity linked list 328 medium
Leetcode skimming -- incremental ternary subsequence 334 medium
How does the computer set up speakers to play microphone sound
How to avoid 7 common problems in mobile and network availability testing
飞凌嵌入式RZ/G2L处理器核心板及开发板上手评测
终于搞懂了JS中的事件循环,同步/异步,微任务/宏任务,运行机制(附笔试题)
Leetcode skimming -- count the number of numbers with different numbers 357 medium
NBA player analysis
18_ Redis_ Redis master-slave replication & cluster building
16_Redis_Redis持久化
随机推荐
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
02_ Linear table_ Sequence table
高考录取分数线爬虫
Principles, language, compilation, interpretation
Application of CDN in game field
NBA player analysis
13_ Redis_ affair
Application and practice of Jenkins pipeline
Practice of compiling principle course -- implementing an interpreter or compiler of elementary function operation language
数据分析常见的英文缩写(一)
Leetcode skimming - remove duplicate letters 316 medium
folium地图无法显示的问题,临时性解决方案如下
Solve the problem of frequent interruption of mobaxterm remote connection
哈夫曼树:(1)输入各字符及其权值(2)构造哈夫曼树(3)进行哈夫曼编码(4)查找HC[i],得到各字符的哈夫曼编码
面对“缺芯”挑战,飞凌如何为客户产能提供稳定强大的保障?
Bing. Site Internet
Real estate market trend outlook in 2022
Oracle primary key auto increment
06_栈和队列转换
Solution of Queen n problem