上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 47 下一页
摘要: 题目描述: 方法: class Solution { public int countDigitOne(int n) { int digit = 1,res = 0; int high = n / 10,cur = n % 10,low = 0; while(high != 0 || cur != 阅读全文
posted @ 2020-05-15 20:24 oldby 阅读(156) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:快排 O(N) java class Solution { public int[] getLeastNumbers(int[] arr, int k) { if(k == 0|| arr.length == 0){ return new int[0]; } return qui 阅读全文
posted @ 2020-05-13 10:19 oldby 阅读(121) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 提交:O(N) class Solution: def buildArray(self, target: List[int], n: int) -> List[str]: res = [] a = "Push" b = "Pop" index = 1 for i in target: w 阅读全文
posted @ 2020-05-10 22:07 oldby 阅读(81) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 提交:O(N3) class Solution: def countTriplets(self, arr: List[int]) -> int: # count = 0 # for i in range(len(arr)): # for j in range(i+1,len(arr)): 阅读全文
posted @ 2020-05-10 21:48 oldby 阅读(147) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 解:动态规划 参考自: 作者:coldme-2链接:https://leetcode-cn.com/problems/number-of-ways-of-cutting-a-pizza/solution/dong-tai-gui-hua-by-coldme-2-2/来源:力扣(LeetC 阅读全文
posted @ 2020-05-10 21:30 oldby 阅读(193) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:dfs 从父节点到子节点 class Solution: def minTime(self, n: int, edges: List[List[int]], hasApple: List[bool]) -> int: maps = collections.defaultdict( 阅读全文
posted @ 2020-05-10 21:07 oldby 阅读(164) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:DFS枚举 O(s*t) O(max(ds,dt) d代表深度 class Solution: def isSubtree(self, s: TreeNode, t: TreeNode) -> bool: def isSameTree(s, t): if not s and no 阅读全文
posted @ 2020-05-07 16:15 oldby 阅读(128) 评论(0) 推荐(0) 编辑
摘要: 一、0/1 背包 • 你背着一个背包闯入一家珠宝店,店里有林林总总的格式珠宝,各不重样。每一个珠 宝都有重量和价值。但是你的书包有承载上限。 • 想成为江湖老大,你需要找到一种装包方法使得包内物品的重量不超过其限定值且使 包内物品的价值最大 def knapSack(W, wt, val, n): 阅读全文
posted @ 2020-05-07 12:21 oldby 阅读(146) 评论(0) 推荐(0) 编辑
摘要: 一:买卖股票 I • 给定一个数组,表示每天的股票价格。 • 你可以进行一次交易(先买再卖),问如何能得到最大利润。 def maxProfit(prices): if len(prices) < 2: return 0 min_price = prices[0] max_profit = 0 fo 阅读全文
posted @ 2020-05-07 12:00 oldby 阅读(175) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:O(W) O(W) W =365 class Solution: def mincostTickets(self, days: List[int], costs: List[int]) -> int: dayset = set(days) durations = [1,7,30] 阅读全文
posted @ 2020-05-07 00:00 oldby 阅读(148) 评论(0) 推荐(0) 编辑
上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 47 下一页