55. 跳跃游戏 小黑代码
class Solution:def canJump(self, nums: List[int]) -> bool:# 数组长度n = len(nums)# 探索的最大范围develop_max = 0for i in range(n):develop_max = max(develop_max, i+nums[i])if develop_max <= i and i != n-1:return Falsereturn True
56. 合并区间 贪心排序法
class Solution:def merge(self, intervals: List[List[int]]) -> List[List[int]]:# 结果数组res = []if not intervals:return res# 数组长度n = len(intervals)# 数组排序intervals.sort(key=lambda x:x[0])for interval in intervals:# 结果数组为空,则插入if not res:res.append(interval)continueif interval[0] <= res[-1][1]:res[-1][1] = max(interval[1], res[-1][1])else:res.append(interval)return res