当前位置:网站首页>[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
边栏推荐
- How to intercept the value of a key from the JSON string returned by wechat?
- 6.12 企业内部upp平台(Unified Process Platform)的关键一刻
- 【LeetCode】486-预测赢家
- 16_ Redis_ Redis persistence
- [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)
- Leetcode skimming -- verifying the preorder serialization of binary tree # 331 # medium
- LeetCode刷题——验证二叉树的前序序列化#331#Medium
- 2022 年辽宁省大学生数学建模A、B、C题(相关论文及模型程序代码网盘下载)
- 【LeetCode】19-删除链表的倒数第N个结点
- How to write sensor data into computer database
猜你喜欢

MySQL calculate n-day retention rate

语义分割学习笔记(一)

Download blender on Alibaba cloud image station

Loss function and positive and negative sample allocation: Yolo series

6.12 critical moment of Unified Process Platform

党史纪实主题公益数字文创产品正式上线

Set set you don't know

02_ Linear table_ Sequence table

Data analysis thinking analysis methods and business knowledge - business indicators

2022 college students in Liaoning Province mathematical modeling a, B, C questions (related papers and model program code online disk download)
随机推荐
5. Practice: jctree implements the annotation processor at compile time
MD5 encryption
Equipped with Ti am62x processor, Feiling fet6254-c core board is launched!
让您的HMI更具优势,FET-G2LD-C核心板是个好选择
百变大7座,五菱佳辰产品力出众,人性化大空间,关键价格真香
16_ Redis_ Redis persistence
【LeetCode】19-删除链表的倒数第N个结点
03_ Linear table_ Linked list
Real estate market trend outlook in 2022
【LeetCode】189-轮转数组
党史纪实主题公益数字文创产品正式上线
夏季高考文化成绩一分一段表
微信支付宝账户体系和支付接口业务流程
工程师评测 | RK3568开发板上手测试
SQL stored procedure
LeetCode刷题——验证二叉树的前序序列化#331#Medium
03_線性錶_鏈錶
LeetCode刷题——去除重复字母#316#Medium
【网络安全】网络资产收集
Pytoch saves tensor to Mat file