leetcode刷题系列(二)

本文是LeetCode刷题系列的第二部分,主要探讨数组与字符串相关的题目。涉及的问题包括三数之和、求众数、缺失的第一个正数、反转字符串、翻转字符串里的单词以及字符串转换整数。提供了英文版和中文版的题目链接,以及使用Python的解决方案和优化技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1,数组:

Three Sum(求三数之和)

英文版:https://leetcode.com/problems/3sum/

中文版:https://leetcode-cn.com/problems/3sum/

在这里插入图片描述

Majority Element(求众数)

英文版:https://leetcode.com/problems/majority-element/

中文版:https://leetcode-cn.com/problems/majority-element/

见证python暴力的时候到了,一行代码搞定:​

return sorted(nums)[int(len(nums)/2)]

Missing Positive(求缺失的第一个正数)

英文版:https://leetcode.com/problems/first-missing-positive/

中文版:https://leetcode-cn.com/problems/first-missing-positive/

在这里插入图片描述

2,字符串: Reverse String (反转字符串)

英文版:https://leetcode.com/problems/reverse-string/

中文版:https://leetcode-cn.com/problems/reverse-string/

用python自带的函数反而是用时最少的,第一种放大是自建循环,用时居中,172s。

在这里插入图片描述

Reverse Words in a String(翻转字符串里的单词)

英文版:https://leetcode.com/problems/reverse-words-in-a-string/中文版:https://leetcode-cn.com/problems/reverse-words-in-a-string/

在这里插入图片描述

String to Integer (atoi)(字符串转换整数 (atoi))

英文版:https://leetcode.com/problems/string-to-integer-atoi/

中文版:https://leetcode-cn.com/problems/string-to-integer-atoi/
在这里插入图片描述

Reference:Leetcode-15: https://www.jianshu.com/p/dd8dcdd2baf8

Leetcode-41: https://blog.youkuaiyun.com/weixin_40449300/article/details/82532996

Leetcode-151: https://blog.youkuaiyun.com/sxingming/article/details/51597524

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值