当前位置:网站首页>【LeetCode】344-反转字符串
【LeetCode】344-反转字符串
2022-07-02 12:09:00 【酥酥~】
编写一个函数,其作用是将输入的字符串反转过来。输入字符串以字符数组 s 的形式给出。
不要给另外的数组分配额外的空间,你必须原地修改输入数组、使用 O(1) 的额外空间解决这一问题。
示例 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”]
提示:
- 1 <= s.length <= 105
- s[i] 都是 ASCII 码表中的可打印字符
#利用python数列特征直接反转
class Solution(object):
def reverseString(self, s):
s[:]=s[::-1]
#双指针
class Solution(object):
def reverseString(self, s):
left = 0
right = len(s)-1
while left<right:
tmp = s[left]
s[left] = s[right]
s[right] = tmp
left+=1
right-=1
边栏推荐
- Data analysis thinking analysis methods and business knowledge - business indicators
- 基于RZ/G2L | OK-G2LD-C开发板存储读写速度与网络实测
- . Solution to the problem of Chinese garbled code when net core reads files
- 17_ Redis_ Redis publish subscription
- Tidb data migration tool overview
- 你不知道的Set集合
- Bing.com网站
- 语义分割学习笔记(一)
- Facing the challenge of "lack of core", how can Feiling provide a stable and strong guarantee for customers' production capacity?
- 彻底弄懂浏览器强缓存和协商缓存
猜你喜欢

飞凌嵌入式RZ/G2L处理器核心板及开发板上手评测

. Solution to the problem of Chinese garbled code when net core reads files

15_ Redis_ Redis. Conf detailed explanation

终于搞懂了JS中的事件循环,同步/异步,微任务/宏任务,运行机制(附笔试题)

How to choose a third-party software testing organization for automated acceptance testing of mobile applications

18_ Redis_ Redis master-slave replication & cluster building

LeetCode刷题——统计各位数字都不同的数字个数#357#Medium

百变大7座,五菱佳辰产品力出众,人性化大空间,关键价格真香

. Net again! Happy 20th birthday

Practice of compiling principle course -- implementing an interpreter or compiler of elementary function operation language
随机推荐
Leetcode skimming -- verifying the preorder serialization of binary tree # 331 # medium
Beijing rental data analysis
17_ Redis_ Redis publish subscription
怎样从微信返回的json字符串中截取某个key的值?
Engineer evaluation | rk3568 development board hands-on test
搭建自己的语义分割平台deeplabV3+
Force deduction solution summarizes the lucky numbers in 1380 matrix
党史纪实主题公益数字文创产品正式上线
Oracle primary key auto increment
How to choose a third-party software testing organization for automated acceptance testing of mobile applications
The traversal methods of binary tree mainly include: first order traversal, middle order traversal, second order traversal, and hierarchical traversal. First order, middle order, and second order actu
Principles, language, compilation, interpretation
03. Preliminary use of golang
Topology architecture of the minimum deployment of tidb cluster
19_ Redis_ Manually configure the host after downtime
Steps for Navicat to create a new database
N皇后问题的解决
Let your HMI have more advantages. Fet-g2ld-c core board is a good choice
16_ Redis_ Redis persistence
03_ Linear table_ Linked list