当前位置:网站首页>Leetcode 344. reverse string
Leetcode 344. reverse string
2022-07-29 06:23:00 【Zhangchuming ZCM】
Power button | 344. Reverse string

Method : Double pointer
Simple questions, punch hard !
Use double pointers directly , Move from both sides to the middle , Swap the elements pointed to by the left and right pointers , Complete inversion .
class Solution:
def reverseString(self, s: List[str]) -> None:
"""
Do not return anything, modify s in-place instead.
"""
n = len(s)
left, right = 0, n-1
while left < right:
s[left], s[right] = s[right], s[left]
left += 1
right -= 1Complete test code
from typing import List
class Solution:
def reverseString(self, s: List[str]) -> None:
"""
Do not return anything, modify s in-place instead.
"""
n = len(s)
left, right = 0, n-1
while left < right:
s[left], s[right] = s[right], s[left]
left += 1
right -= 1
class main:
a = Solution()
s = ["h","e","l","l","o"]
print(s)
b=a.reverseString(s)
print(s)
if __name__ == '__main__':
main()边栏推荐
- 利用云打码来破解登录遇到验证码的问题
- IDEA安装scala
- Sqlyog installation and configuration tutorial
- #6898 变幻的矩阵 题解
- Mathematical modeling experience
- 【软件工程之美 - 专栏笔记】27 | 软件工程师的核心竞争力是什么?(上)
- LeetCode #13. 罗马数字转整数
- Computer network interview questions
- Leetcode 26. delete duplicates in the ordered array
- [beauty of software engineering - column notes] 16 | how to write project documents?
猜你喜欢

LeetCode #26.删除有序数组中的重复项

Based on STM32: couple interactive doll (design scheme + source code +3d drawing +ad circuit)

封装——super关键字

Abstract encapsulation inheritance polymorphism

NoClassDefFoundError 处理

Joiner.on和stream().map联合使用技巧

2022 spring move - core technology FPGA post technical aspects (one side experience)

【软件工程之美 - 专栏笔记】22 | 如何为项目做好技术选型?

Ml9 self study notes

Zero basics FPGA (5): counter of sequential logic circuit design (with introduction to breathing lamp experiment and simple combinational logic design)
随机推荐
leetcode---技巧
Ml8 self study notes LDA principle formula derivation
循环链表和双向链表
NOI Online 2022普及组 题解&个人领悟
Rowkey设计
Markdown and typora
LeetCode #9.回文数
Abstract encapsulation inheritance polymorphism
【软件工程之美 - 专栏笔记】20 | 如何应对让人头疼的需求变更问题?
[beauty of software engineering - column notes] 14 | project management tools: all management problems should be considered whether they can be solved by tools
爬虫Requests库的一些简单用法
Pit avoidance: about the interconnection of two hc-05 master-slave integrated Bluetooth modules, there is no connection problem
Operating system interview questions
MySql-面试题
Open source based on STM32: MHD Bluetooth speaker (including source code +pcb)
Dynamic planning summary
leetcode刷题笔记 605. Can Place Flowers (Easy) 605.种花问题
LeetCode #7.整数反转
Shell tool finalshell
Sqlyog installation and configuration tutorial