当前位置:网站首页>[leetcode] reverse string [344]
[leetcode] reverse string [344]
2022-07-02 22:52:00 【When camellia flowers bloom.】
problem : Write a function , Its function is to invert the input string . Input string as character array s Given in the form of
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"]
Python3 Problem solving
# solution 1: Double pointer
def reverseString(s):
left, right = 0, len(s) - 1
while left < right:
s[left], s[right] = s[right], s[left]
left = left + 1
right = right - 1
return s
# solution 2
def reverseString(s):
s.reverse()
return s
# ['o', 'l', 'l', 'e', 'h']
reverseString(["h","e","l","l","o"])
# ['h', 'a', 'n', 'n', 'a', 'H']
reverseString(["H","a","n","n","a","h"])边栏推荐
猜你喜欢

Dahua cloud native load balancing article - the passenger flow of small restaurants has increased

大话云原生之负载均衡篇-小饭馆客流量变大了

Niuke: Dragon and dungeon games

牛客网:最大子矩阵

Leetcode circular linked list (fast and slow pointer) code line by line interpretation

手写ORM(对象关系映射)增删改查

小鹏P7出事故,安全气囊未弹出,这正常吗?

Baidu AI Cloud - create a face recognition application

Objects and object variables

Radis:Linux上安装Redis(步骤)
随机推荐
解决 excel 文件上传时更改选中的文件出现错误net::ERR_UPLOAD_FILE_CHANGED
U++ learning note pile
Golang's learning route
How can I use knockout's $parent/$root pseudovariables from inside a . computed() observable?
【ODX Studio编辑PDX】-0.1-如何快速查看各Variant变体间的支持的诊断信息差异(服务,Sub-Function...)
go 条件变量
Leetcode circular linked list (fast and slow pointer) code line by line interpretation
Oracle cursor
UE4 game architecture learning notes
Source code analysis - lightweight asynchronous crawler framework Ruia
[foreign journal] sleep and weight loss
[ODX studio edit PDX] -0.1- how to quickly view the differences in supported diagnostic information between variant variants (service, sub function...)
傑理之修改不需要長按開機功能【篇】
Go 4 modes Singleton
[QT] Q multithreaded development - Analysis of multithreaded application examples (Mandelbrot)
UE4 游戏架构 学习笔记
Golang的学习路线
Film and television excerpts
Utilisation de simpletk - 4. Question étrange
【板栗糖GIS】arcscene—如何做出有高度的高程图