当前位置:网站首页>[leetcode] 344 reverse string
[leetcode] 344 reverse string
2022-07-02 15:36:00 【Crisp ~】
Write a function , Its function is to invert the input string . Input string as character array s Given in the form of .
Do not allocate extra space to another array , You have to modify the input array in place 、 Use O(1) To solve this problem .
Example 1:
Input : s = [“h”,“e”,“l”,“l”,“o”]
Output : [“o”,“l”,“l”,“e”,“h”]
Example 2:
Input : s = [“H”,“a”,“n”,“n”,“a”,“h”]
Output : [“h”,“a”,“n”,“n”,“a”,“H”]
Tips :
- 1 <= s.length <= 105
- s[i] All are ASCII Printable characters in code table
# utilize python Direct inversion of sequence characteristics
class Solution(object):
def reverseString(self, s):
s[:]=s[::-1]
# Double pointer
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
边栏推荐
猜你喜欢
【网络安全】网络资产收集
10_ Redis_ geospatial_ command
Leetcode skimming -- incremental ternary subsequence 334 medium
Practice of compiling principle course -- implementing an interpreter or compiler of elementary function operation language
NBA player analysis
百变大7座,五菱佳辰产品力出众,人性化大空间,关键价格真香
06_ Stack and queue conversion
党史纪实主题公益数字文创产品正式上线
Be a good gatekeeper on the road of anti epidemic -- infrared thermal imaging temperature detection system based on rk3568
6.12 critical moment of Unified Process Platform
随机推荐
MD5 encryption
Steps for Navicat to create a new database
【LeetCode】1162-地图分析
LeetCode刷题——奇偶链表#328#Medium
Wechat Alipay account system and payment interface business process
Pytorch 保存tensor到.mat文件
SQL transaction
【LeetCode】283-移动零
4. Data splitting of Flink real-time project
Practice of compiling principle course -- implementing an interpreter or compiler of elementary function operation language
【LeetCode】695-岛屿的最大面积
List set & UML diagram
02. After containerization, you must face golang
Bing.com網站
03.golang初步使用
高考录取分数线爬虫
Leetcode skimming -- sum of two integers 371 medium
03_线性表_链表
02_线性表_顺序表
How to find a sense of career direction