点名(LeetCode

题目 解题 def takeAttendance(records): """ 找出缺席学生的学号。 参数: records (list of int): 点名记录的升序数组 返回: int: 缺席学生的学号 """ left, right = 0, len(records) - 1 while left <= right: mid = left + (right - left) // 2 # 如果 records...

LeetCode //C - 330. Patching Array

<=104nums is sorted in ascending order. 1 < = n < = 2 31 − 1 1 <= n <= 2^{31} - 1 1<=n<=231−1 From: LeetCode Link: 330. Patching Array Solution: Ideas: miss: This variable represents the smallest sum that can...

搜索二维矩阵 II(LeetCode

题目 解题 """时间复杂度为 O(m + n),其中 m 是矩阵的行数,n 是矩阵的列数。""" def searchMatrix(matrix, target) -> bool: if not matrix or not matrix[0]: return False # 从右上角开始搜索 row, col = 0, len(matrix[0]) - 1 while row < len(matrix) a...

搜索二维矩阵(LeetCode

题目 解题 """时间复杂度为 O(log(m * n)),其中 m 是矩阵的行数,n 是矩阵的列数。""" def searchMatrix(matrix, target): if not matrix or not matrix[0]: return False m, n = len(matrix), len(matrix[0]) left, right = 0, m * n - 1 while left...

爱吃香蕉的珂珂(LeetCode

题目 解题 """时间复杂度: O(n log m),其中 n 是堆的数量,m 是香蕉堆中最大数量。空间复杂度: O(1),只使用了常数空间。""" import math def minEatingSpeed(piles, h): # 二分查找的初始范围 left, right = 1, max(piles) while left < right: # 取中间速度 mid = (left + right)...

至少有k个重复字符的最长子串(LeetCode

题目 解题 def longestSubstring(s, k): # 如果字符串长度为0或者字符串长度小于k,返回0 if len(s) == 0 or len(s) < k: return 0 # 如果字符串中所有字符的出现次数都大于等于k,返回字符串的长度 if all(s.count(char) >= k for char in set(s)): return len(s) # 否则进行分治 for ch...

LeetCode //C - 316. Remove Duplicate Letters

t h < = 1 0 4 1 <= s.length <= 10^4 1<=s.length<=104s consists of lowercase English letters. From: LeetCode Link: 316. Remove Duplicate Letters Solution: Ideas: 1. lastIndex[]: This array stores the last occ...

三数之和(LeetCode

题目 解题 def threeSum(nums): nums.sort() # 首先对数组进行排序 result = [] # 用于存储最终结果的列表 for i in range(len(nums) - 2): if i > 0 and nums[i] == nums[i - 1]: # 避免重复的三元组 continue left, right = i + 1, len(nums) - 1 while lef...

LeetCode:3152. 特殊数组 II + 前缀和】

🍔 目录 🚩 题目链接⛲ 题目描述🌟 求解思路&实现代码&运行结果⚡ 前缀和🥦 求解思路🥦 实现代码🥦 运行结果 💬 共勉 🚩 题目链接 3152. 特殊数组 II ⛲ 题目描述 如果数组的每一对相邻元素都是两个奇偶性不同的数字,则该数组被认为是一个 特殊数组 。 周洋哥有一个整数数组 nums 和一个二维整数矩阵 queries,对于 queries[i] = [fromi, toi],请你帮助周洋哥检查子数...

LeetCode //C - 301. Remove Invalid Parentheses

ercase English letters and parentheses ‘(’ and ‘)’.There will be at most 20 parentheses in s. From: LeetCode Link: 301. Remove Invalid Parentheses Solution: Ideas: 1. Dynamic Queue and Result Resizing: Queue ...
© 2024 LMLPHP 关于我们 联系我们 友情链接 耗时0.002762(s)
2024-10-23 03:09:44 1729624184