摘要:
738.单调递增的数字 class Solution: def monotoneIncreasingDigits(self, n: int) -> int: # 主要思路当前数字比前面数字小时。前面数字 -1,当前数字变2为 9 str_n = str(n) for i in range(len(s 阅读全文
摘要:
435. 无重叠区间 class Solution: def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int: intervals.sort(key=lambda x: x[0]) count = 0 for i in r 阅读全文
摘要:
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 阅读全文
摘要:
1005.K次取反后最大化的数组和 class Solution: def largestSumAfterKNegations(self, nums: List[int], k: int) -> int: nums.sort(key=lambda x:abs(x), reverse=True) fo 阅读全文
摘要:
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 阅读全文
摘要:
455.分发饼干 1、优先大饼干 class Solution: def findContentChildren(self, g: List[int], s: List[int]) -> int: g.sort() s.sort() index = len(s) - 1 # 最后一块饼干 res = 阅读全文
摘要:
332.重新安排行程 方法一和方法二在力扣用例会超时 方法一、 class Solution: def findItinerary(self, tickets: List[List[str]]) -> List[str]: tickets.sort() res = [] used = [False] 阅读全文
摘要:
491.递增子序列 class Solution: def findSubsequences(self, nums: List[int]) -> List[List[int]]: res = [] self.tracebacking(nums, 0, [], res) return res def 阅读全文
摘要:
93.复原IP地址 1、方法一 class Solution: def restoreIpAddresses(self, s: str) -> List[str]: res = [] self.tracebacking(s, 0, [], res) return res def tracebacki 阅读全文
摘要:
39. 组合总和 class Solution: def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]: res = [] candidates.sort() self.tracebacking 阅读全文