当前位置:网站首页>[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
边栏推荐
- 02_ Linear table_ Sequence table
- 4. Data splitting of Flink real-time project
- Wechat Alipay account system and payment interface business process
- 03_ Linear table_ Linked list
- Redux - detailed explanation
- Summary of the first three passes of sqli Labs
- 【Leetcode】167-两数之和II -输入有序数组
- LeetCode刷题——两整数之和#371#Medium
- How to avoid 7 common problems in mobile and network availability testing
- 自定义异常
猜你喜欢

21_ Redis_ Analysis of redis cache penetration and avalanche

Leetcode skimming -- count the number of numbers with different numbers 357 medium

2022 年辽宁省大学生数学建模A、B、C题(相关论文及模型程序代码网盘下载)

Semantic segmentation learning notes (1)
![[network security] network asset collection](/img/3e/6665b5af0dedfcbc7bd548cc486878.png)
[network security] network asset collection

03_ Linear table_ Linked list

4. Jctree related knowledge learning

Party History Documentary theme public welfare digital cultural and creative products officially launched

Download blender on Alibaba cloud image station

党史纪实主题公益数字文创产品正式上线
随机推荐
微信支付宝账户体系和支付接口业务流程
彻底弄懂浏览器强缓存和协商缓存
4. Jctree related knowledge learning
4. Data splitting of Flink real-time project
LeetCode_ Sliding window_ Medium_ 395. Longest substring with at least k repeated characters
How to solve the problem of database content output
03_線性錶_鏈錶
LeetCode刷题——递增的三元子序列#334#Medium
【LeetCode】189-轮转数组
03. Preliminary use of golang
【LeetCode】1140-石子游戏II
Steps for Navicat to create a new database
[development environment] install the Chinese language pack for the 2013 version of visual studio community (install test agents 2013 | install visual studio 2013 simplified Chinese)
Engineer evaluation | rk3568 development board hands-on test
yolo格式数据集处理(xml转txt)
LeetCode刷题——统计各位数字都不同的数字个数#357#Medium
Equipped with Ti am62x processor, Feiling fet6254-c core board is launched!
损失函数与正负样本分配:YOLO系列
MySQL -- Index Optimization -- order by
(Video + graphic) machine learning introduction series - Chapter 5 machine learning practice