- 博客(11)
- 收藏
- 关注
原创 剑指 Offer 03. 数组中重复的数字
class Solution: def findRepeatNumber(self, nums: List[int]) -> int: if not nums or len(nums) == 0: return False for index in range(len(nums)): if nums[index] <0 or nums[index] > len(nums)-1:...
2022-01-26 22:01:39 428
原创 Leetcode:1456. 定长子串中元音的最大数目(Python3)
class Solution: def maxVowels(self, s: str, k: int) -> int: # 边界条件 if not s or len(s)==0 or k> len(s): return 0 # 哈希map hashmap = { 'a', 'e', 'i', 'o', 'u'} count, result = 0,0 ...
2022-01-20 16:51:52 257
原创 Leetcode:209. 长度最小的子数组(Python3)
class Solution: def minSubArrayLen(self, target: int, nums: List[int]) -> int: # 边界条件 if not nums or len(nums) == 0: return 0 left, right = 0, 0 total, result = 0, len(nums)+1 # 滑动 wh...
2022-01-20 16:26:09 223
原创 Leetcode:74.搜索二维矩阵 (Python3)
class Solution: def searchMatrix(self, matrix: List[List[int]], target: int) -> bool: # 边界条件 if not matrix or len(matrix) == 0: return False # 遍历二维数组 for nums in matrix: if nums[0] <...
2022-01-20 10:29:59 360
原创 Leetcode:162.寻找峰值 (Python3)
class Solution: def findPeakElement(self, nums: List[int]) -> int: # 边界条件 if not nums or len(nums) == 0: return -1 # 左右双指针 left, right = 0, len(nums)-1 # 循环体 while left < right: ...
2022-01-20 10:14:52 220
原创 Leetcode:35.搜索插入位置 Python3
# 二分查找法class Solution: def searchInsert(self, nums: List[int], target: int) -> int: # 边界条件 if not nums or len(nums) == 0: return 0 # 左右双指针 left, right = 0, len(nums)-1 # 循环体 while le...
2022-01-20 09:48:18 410
原创 Leetcode:704.二分查找 Python3
# 二分查找法class Solution: def search(self, nums: List[int], target: int) -> int: # 边界条件 if not nums: return -1 # 左右指针 left, right = 0, len(nums)-1 # 循环体 while left <= right: ...
2022-01-20 09:40:48 316
原创 Leetcode:141.环形链表 Python3
# 快慢双指针class Solution: def hasCycle(self, head: Optional[ListNode]) -> bool: # 边界条件 链表不为空 if not head: return False # 定义快慢双指针 slow,fast = head, head # 循环体 while fast and fast.next...
2022-01-20 09:13:18 87
原创 Leetcode:881.救生艇 Python3
# 对撞双指针class Solution: def numRescueBoats(self, people: List[int], limit: int) -> int: # 进行排序 people.sort() # 最小船数 result = 0 # 定义双指针 left,right = 0,len(people)-1 # 循环体 while lef...
2022-01-20 09:13:00 277 1
原创 Leetcode:55. 跳跃游戏(python3)
class Solution: def canJump(self, nums: List[int]) -> bool: # 如果nums内不存在0一定会到达最终点因为最小移动为1 # 如果nums长度为一 开始即满足题目要求 if 0 not in nums or len(nums)==1: return True # 如果nums长度不为一 且初始位置处无法移动 elif nu...
2021-10-28 19:59:53 1534
原创 Leetcode:547. 省份数量(python3)
class Solution:def findCircleNum(self, isConnected: List[List[int]]) -> int:if isConnected is None:return 0uf = UnionFind(isConnected)row,col = len(isConnected), len(isConnected[-1])for i in range(row):for j in range(col):if j == i:con
2021-10-28 09:25:53 266
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人