当前位置:网站首页>[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
边栏推荐
- 2022 年辽宁省大学生数学建模A、B、C题(相关论文及模型程序代码网盘下载)
- LeetCode_ Sliding window_ Medium_ 395. Longest substring with at least k repeated characters
- Application of CDN in game field
- 08_ strand
- 你不知道的Set集合
- 19_Redis_宕机后手动配置主机
- Set set you don't know
- 【LeetCode】486-预测赢家
- Build your own semantic segmentation platform deeplabv3+
- 【LeetCode】977-有序数组的平方
猜你喜欢

07_ Hash

Steps for Navicat to create a new database

LeetCode刷题——奇偶链表#328#Medium

18_Redis_Redis主从复制&&集群搭建

Facing the challenge of "lack of core", how can Feiling provide a stable and strong guarantee for customers' production capacity?

做好抗“疫”之路的把关人——基于RK3568的红外热成像体温检测系统

6.12 企业内部upp平台(Unified Process Platform)的关键一刻

21_ Redis_ Analysis of redis cache penetration and avalanche

Equipped with Ti am62x processor, Feiling fet6254-c core board is launched!
![[network security] network asset collection](/img/3e/6665b5af0dedfcbc7bd548cc486878.png)
[network security] network asset collection
随机推荐
18_ Redis_ Redis master-slave replication & cluster building
LeetCode刷题——统计各位数字都不同的数字个数#357#Medium
【LeetCode】189-轮转数组
5. Practice: jctree implements the annotation processor at compile time
Bing.com網站
党史纪实主题公益数字文创产品正式上线
Solution of Queen n problem
How to intercept the value of a key from the JSON string returned by wechat?
【LeetCode】200-岛屿数量
(4) Flink's table API and SQL table schema
Solve the problem of frequent interruption of mobaxterm remote connection
02_ Linear table_ Sequence table
LeetCode_ String_ Simple_ 412.Fizz Buzz
4. Data splitting of Flink real-time project
Force deduction solution summary 2029 stone game IX
工程师评测 | RK3568开发板上手测试
LeetCode_ Sliding window_ Medium_ 395. Longest substring with at least k repeated characters
Bing.com网站
【LeetCode】1254-统计封闭岛屿的数量
MySQL calculate n-day retention rate