当前位置:网站首页>[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
边栏推荐
- 党史纪实主题公益数字文创产品正式上线
- LeetCode_ Sliding window_ Medium_ 395. Longest substring with at least k repeated characters
- 15_ Redis_ Redis. Conf detailed explanation
- 07_ Hash
- LeetCode刷题——验证二叉树的前序序列化#331#Medium
- How to avoid 7 common problems in mobile and network availability testing
- 【Leetcode】167-两数之和II -输入有序数组
- FPGA - 7系列 FPGA内部结构之Clocking -03- 时钟管理模块(CMT)
- 05_ queue
- 做好抗“疫”之路的把关人——基于RK3568的红外热成像体温检测系统
猜你喜欢
随机推荐
06_ Stack and queue conversion
Custom exception
【LeetCode】577-反转字符串中的单词 III
I made an istio workshop. This is the first introduction
搭载TI AM62x处理器,飞凌FET6254-C核心板首发上市!
10_ Redis_ geospatial_ command
QML pop-up frame, customizable
17_Redis_Redis发布订阅
05_ queue
语义分割学习笔记(一)
士官类学校名录
党史纪实主题公益数字文创产品正式上线
【Leetcode】167-两数之和II -输入有序数组
【LeetCode】283-移动零
Basic knowledge of cryptography
损失函数与正负样本分配:YOLO系列
LeetCode_ String_ Simple_ 412.Fizz Buzz
18_ Redis_ Redis master-slave replication & cluster building
21_ Redis_ Analysis of redis cache penetration and avalanche
Leetcode skimming -- sum of two integers 371 medium









