当前位置:网站首页>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()边栏推荐
- Ml9 self study notes
- 【软件工程之美 - 专栏笔记】“一问一答”第3期 | 18个软件开发常见问题解决策略
- Huawei cloud 14 day Hongmeng device development -day3 kernel development
- FPGA based: multi-target motion detection (hand-in-hand teaching ①)
- Based on STM32: couple interactive doll (design scheme + source code +3d drawing +ad circuit)
- 2022 spring recruit - Shanghai an road FPGA post Manager (and Lexin SOC interview)
- 【软件工程之美 - 专栏笔记】19 | 作为程序员,你应该有产品意识
- 寒假集训总结 (1.23~1.28) [第一梯队]
- 单链表面试题
- 八大排序----------------冒泡排序
猜你喜欢

Ml self study notes 5

FPGA based: moving target detection (schematic + source code + hardware selection, available)

JVM内存结构

从头安装MYSQL(MYSQL安装文档-解压版)

Computer network interview questions

Pit avoidance: about the interconnection of two hc-05 master-slave integrated Bluetooth modules, there is no connection problem

Dynamic planning summary

LeetCode #83. 删除排序链表中的重复元素

Encapsulation - Super keyword

Leetcode 14. longest public prefix
随机推荐
Simple code to realize PDF to word document
LeetCode #83. 删除排序链表中的重复元素
Install MySQL from scratch (MySQL installation document - unzipped version)
Multithreading and concurrency
IDEA 实用快捷键 新手必看
Eight sorts ----------- bubble sort
STM32 printf问题总结 semihosting microLIB理解
抽象类以及接口
【软件工程之美 - 专栏笔记】29 | 自动化测试:如何把Bug杀死在摇篮里?
LeetCode #283.移动零
arduino uno错误分析avrdude: stk500_recv(): programmer is not responding
Dynamic planning summary
【软件工程之美 - 专栏笔记】“一问一答”第2期 | 30个软件开发常见问题解决策略
LeetCode #35.搜索插入位置
Add time series index to two-dimensional table
Huawei cloud 14 days Hongmeng device development -day1 environment construction
关于【链式前向星】的自学理解
【软件工程之美 - 专栏笔记】19 | 作为程序员,你应该有产品意识
八大排序-----------------堆排序
UE5 纹理系统讲解及常见问题设置及解决方案