摘要: 738.单调递增的数字 class Solution: def monotoneIncreasingDigits(self, n: int) -> int: # 主要思路当前数字比前面数字小时。前面数字 -1,当前数字变2为 9 str_n = str(n) for i in range(len(s 阅读全文
posted @ 2023-11-17 23:30 忆象峰飞 阅读(4) 评论(0) 推荐(0) 编辑
摘要: 435. 无重叠区间 class Solution: def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int: intervals.sort(key=lambda x: x[0]) count = 0 for i in r 阅读全文
posted @ 2023-11-15 19:16 忆象峰飞 阅读(11) 评论(0) 推荐(0) 编辑
摘要: 860.柠檬水找零 class Solution: def lemonadeChange(self, bills: List[int]) -> bool: five, ten, twenty = 0, 0, 0 for bill in bills: if bill == 5: five += 1 e 阅读全文
posted @ 2023-11-14 13:01 忆象峰飞 阅读(9) 评论(0) 推荐(0) 编辑
摘要: 1005.K次取反后最大化的数组和 class Solution: def largestSumAfterKNegations(self, nums: List[int], k: int) -> int: nums.sort(key=lambda x:abs(x), reverse=True) fo 阅读全文
posted @ 2023-11-13 17:37 忆象峰飞 阅读(4) 评论(0) 推荐(0) 编辑
摘要: 122.买卖股票的最佳时机 II 1、贪心 class Solution: def maxProfit(self, prices: List[int]) -> int: res = 0 for i in range(1, len(prices)): res += max(prices[i]-pric 阅读全文
posted @ 2023-11-13 16:03 忆象峰飞 阅读(5) 评论(0) 推荐(0) 编辑
摘要: 455.分发饼干 1、优先大饼干 class Solution: def findContentChildren(self, g: List[int], s: List[int]) -> int: g.sort() s.sort() index = len(s) - 1 # 最后一块饼干 res = 阅读全文
posted @ 2023-11-10 21:08 忆象峰飞 阅读(12) 评论(0) 推荐(0) 编辑
摘要: 332.重新安排行程 方法一和方法二在力扣用例会超时 方法一、 class Solution: def findItinerary(self, tickets: List[List[str]]) -> List[str]: tickets.sort() res = [] used = [False] 阅读全文
posted @ 2023-11-10 00:16 忆象峰飞 阅读(8) 评论(0) 推荐(0) 编辑
摘要: 491.递增子序列 class Solution: def findSubsequences(self, nums: List[int]) -> List[List[int]]: res = [] self.tracebacking(nums, 0, [], res) return res def 阅读全文
posted @ 2023-11-08 20:20 忆象峰飞 阅读(8) 评论(0) 推荐(0) 编辑
摘要: 93.复原IP地址 1、方法一 class Solution: def restoreIpAddresses(self, s: str) -> List[str]: res = [] self.tracebacking(s, 0, [], res) return res def tracebacki 阅读全文
posted @ 2023-11-07 20:13 忆象峰飞 阅读(13) 评论(0) 推荐(0) 编辑
摘要: 39. 组合总和 class Solution: def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]: res = [] candidates.sort() self.tracebacking 阅读全文
posted @ 2023-11-06 21:21 忆象峰飞 阅读(9) 评论(0) 推荐(0) 编辑
点击右上角即可分享
微信分享提示