当前位置:网站首页>[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"])边栏推荐
- Market Research - current market situation and future development trend of high tibial osteotomy plate
- 存储单位换算
- 20220702 how do programmers build knowledge systems?
- 【ODX Studio编辑PDX】-0.1-如何快速查看各Variant变体间的支持的诊断信息差异(服务,Sub-Function...)
- Perceptron model and Application
- 对象与对象变量
- Additional: [login information storage] and [login status verification]; (including: summarizing all the contents of [login information storage] and [login status verification] so far;)
- Commodity information management system (C language document version)
- Market Research - current market situation and future development trend of intravenous injection (IV) bottles
- [001] [arm-cortex-m3/4] internal register
猜你喜欢

Utilisation de simpletk - 4. Question étrange

Oracle-PL/SQL编程

Struct, bit segment, enumeration, union

Lightgbm principle and its application in astronomical data

Phpcms realizes the direct Alipay payment function of orders

Developers share | HLS and skillfully use Axi_ Customize the master bus interface instructions and improve the data bandwidth - area exchange speed
![[error record] the flutter reports an error (could not read script 'xxx\flutter\u tools\gradle\app\u plugin\u loader.gradle')](/img/02/67448df1817e8b34b654722df8ecd4.jpg)
[error record] the flutter reports an error (could not read script 'xxx\flutter\u tools\gradle\app\u plugin\u loader.gradle')

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

Objects and object variables

Scrcpy this software solves the problem of sharing mobile screen with colleagues | community essay solicitation
随机推荐
[ODX studio edit PDX] -0.1- how to quickly view the differences in supported diagnostic information between variant variants (service, sub function...)
傑理之修改不需要長按開機功能【篇】
Oracle-游标
SimpleITK使用——4. 奇怪的問題
Solve the error of changing the selected file when uploading excel file. Net:: err_ UPLOAD_ FILE_ CHANGED
杰理之充电拔出,无法触摸开机【篇】
Learn computer knowledge from scratch
【AUTOSAR-DCM】-4.3-UDS $22和$2E服务如何读取和写入NVM数据
[shutter] shutter opens a third-party application (url|launcher plug-in search and installation | url| launcher plug-in official example | open browser | open a third-party application)
SimpleITK使用——3. 常见操作
Market Research - current market situation and future development trend of high tibial osteotomy plate
杰理之修改不需要长按开机功能【篇】
ArrayList analysis 2: pits in ITR, listiterator, and sublist
Based on asp Net (used mobile phone sales management system) +asp Net+c # language +vs2010+ database can be used for course design and post design learning
Leetcode circular linked list (fast and slow pointer) code line by line interpretation
Objects and object variables
`${}`的用法
Oracle-PL/SQL编程
[shutter] shutter page life cycle (initialization period | createstate | initstate | update period | build | destroy period | dispose)
建立自己的网站(22)