当前位置:网站首页>【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
边栏推荐
- Tidb environment and system configuration check
- 13_ Redis_ affair
- Common English abbreviations for data analysis (I)
- 04. Some thoughts on enterprise application construction after entering cloud native
- yolo格式数据集处理(xml转txt)
- 21_Redis_浅析Redis缓存穿透和雪崩
- 2022 年辽宁省大学生数学建模A、B、C题(相关论文及模型程序代码网盘下载)
- 12_Redis_Bitmap_命令
- Yolov5 code reproduction and server operation
- Party History Documentary theme public welfare digital cultural and creative products officially launched
猜你喜欢

16_Redis_Redis持久化

Facing the challenge of "lack of core", how can Feiling provide a stable and strong guarantee for customers' production capacity?

08_ 串

Set set you don't know

Pytorch 保存tensor到.mat文件

FPGA - clock-03-clock management module (CMT) of internal structure of 7 Series FPGA

Kibana basic operation

语义分割学习笔记(一)

Evaluation of embedded rz/g2l processor core board and development board of Feiling

SQL stored procedure
随机推荐
yolo格式数据集处理(xml转txt)
Bing.com網站
13_ Redis_ affair
Application of CDN in game field
Tidb cross data center deployment topology
How to find a sense of career direction
LeetCode刷题——验证二叉树的前序序列化#331#Medium
QML pop-up frame, customizable
11_Redis_Hyperloglog_命令
高考录取分数线爬取
Be a good gatekeeper on the road of anti epidemic -- infrared thermal imaging temperature detection system based on rk3568
Redux——详解
07_哈希
LeetCode刷题——奇偶链表#328#Medium
Loss function and positive and negative sample allocation: Yolo series
07_ Hash
6.12 企业内部upp平台(Unified Process Platform)的关键一刻
微信支付宝账户体系和支付接口业务流程
基于RZ/G2L | OK-G2LD-C开发板存储读写速度与网络实测
03.golang初步使用