当前位置:网站首页>[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"])边栏推荐
- [micro service sentinel] rewrite Sentinel's interface blockexceptionhandler
- UE4 游戏架构 学习笔记
- 数学建模——图与网络模型及方法(一)
- Market Research - current situation and future development trend of carob chocolate market
- php实现根据输入的年龄查询出生日期符合的数据
- U++ 学习笔记 堆
- 基于ASP.net的手机销售管理系统(二手手机销售管理系统)+ASP.NET+C#语言+VS2010+数据库可以用于课设、毕设学习
- Methods of adding styles to native JS
- Objects and object variables
- 杰理之内置短按再长按,不管长按多长时间都是短按【篇】
猜你喜欢

NC50965 Largest Rectangle in a Histogram
![[001] [arm-cortex-m3/4] internal register](/img/49/a0eceac1a67267216dd9b2566033a1.jpg)
[001] [arm-cortex-m3/4] internal register

Utilisation de simpletk - 4. Question étrange

任务和特权级保护

Simpleitk use - 4 Strange question

Mathematical modeling -- graph and network models and methods (I)

kubernetes 使用主机名将 pod 分配在指定节点上

"Actbert" Baidu & Sydney University of technology proposed actbert to learn the global and local video text representation, which is effective in five video text tasks!

建立自己的网站(22)
![[shutter] shutter application life cycle (foreground state resumed | background state paused | inactive | component separation state detached)](/img/4c/c8dae41fc2eb18b5153cf36861fc7d.jpg)
[shutter] shutter application life cycle (foreground state resumed | background state paused | inactive | component separation state detached)
随机推荐
phpcms实现订单直接支付宝支付功能
NC50965 Largest Rectangle in a Histogram
Introduction to database system Chapter 1 short answer questions - how was the final exam?
【AUTOSAR-DCM】-4.3-UDS $22和$2E服务如何读取和写入NVM数据
Utilisation de simpletk - 4. Question étrange
NC50965 Largest Rectangle in a Histogram
Basic concepts of image and deep understanding of yuv/rgb
杰理之充电拔出,无法触摸开机【篇】
Simpleitk use - 3 Common operations
Kubernetes resource object introduction and common commands (4)
U++ 学习笔记 ----松弛
Pointer and string
任务和特权级保护
[shutter] shutter gesture interaction (small ball following the movement of fingers)
百度智能云-创建人脸识别应用
杰理之内置关机电流 1.2uA,之后不能长按开机【篇】
杰理之内置短按再长按,不管长按多长时间都是短按【篇】
UE4 UI adaptive screen
Market Research - current situation and future development trend of sickle cell therapy Market
New feature of go1.18: introduce new netip Network Library