当前位置:网站首页>[LeetCode] 反转字符串【344】
[LeetCode] 反转字符串【344】
2022-07-02 22:06:00 【山茶花开时。】
问题: 编写一个函数,其作用是将输入的字符串反转过来。输入字符串以字符数组s的形式给出
示例1
输入: s = ["h","e","l","l","o"]
输出: ["o","l","l","e","h"]
示例2
输入: s = ["H","a","n","n","a","h"]
输出: ["h","a","n","n","a","H"]
Python3解题
# 解法1:双指针
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
# 解法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"])边栏推荐
- Introduction to database system Chapter 1 short answer questions - how was the final exam?
- Market Research - current market situation and future development trend of aircraft audio control panel system
- An overview of the development of affective computing and understanding research
- 服务器响应状态码
- Socket套接字C/S端流程
- PHP implements querying the data matching the date of birth according to the entered age
- Market Research - current market situation and future development trend of intravenous injection (IV) bottles
- Server response status code
- SimpleITK使用——4. 奇怪的问题
- Necessary browser plug-ins for network security engineers
猜你喜欢

C language, to achieve three chess games

Promise optimized callback hell

Micro service gateway selection, please accept my knees!

540. Single element in ordered array

Source code analysis - lightweight asynchronous crawler framework Ruia

Get off work on time! Episode 6 of Excel Collection - how to split and count document amounts

建立自己的网站(22)

杰理之、产线装配环节【篇】

NC50965 Largest Rectangle in a Histogram
![[shutter] shutter custom fonts (download TTF fonts | pubspec.yaml configure font resources | synchronize resources | globally apply fonts | locally apply fonts)](/img/27/8594ba0b49d5008b7469967babed17.jpg)
[shutter] shutter custom fonts (download TTF fonts | pubspec.yaml configure font resources | synchronize resources | globally apply fonts | locally apply fonts)
随机推荐
Simpleitk use - 3 Common operations
Get off work on time! Episode 6 of Excel Collection - how to split and count document amounts
Source code analysis - lightweight asynchronous crawler framework Ruia
Oracle PL / SQL programming
杰理之内置关机电流 1.2uA,之后不能长按开机【篇】
任务和特权级保护
wait解决僵尸进程
Unity3d learning notes 4 - create mesh advanced interface
佩服,竟然有人把高等数学这么晦涩难懂的科目,讲解得如此通俗易懂
对象与对象变量
附加:【登录信息存储】与【登录状态校验】;(包括:总结了到目前为止,有关【登录信息存储】与【登录状态校验】的所有内容;)
Market Research - current situation and future development trend of marine clutch Market
Build your own website (22)
ArrayList analysis 2: pits in ITR, listiterator, and sublist
NC24325 [USACO 2012 Mar S]Flowerpot
Developers share | HLS and skillfully use Axi_ Customize the master bus interface instructions and improve the data bandwidth - area exchange speed
【AUTOSAR-DCM】-4.3-UDS $22和$2E服务如何读取和写入NVM数据
杰理之样机在多次触摸后会触发关机【篇】
Film and television excerpts
#include errors detected. Please update your includePath.