上一页 1 ··· 68 69 70 71 72 73 74 75 76 ··· 114 下一页
摘要: 1 class Solution: 2 def commonChars(self, A: 'List[str]') -> 'List[str]': 3 n = len(A) 4 if n == 1: 5 return A 6 basestr = A[0] 7 baselist = {} ... 阅读全文
posted @ 2019-03-03 13:26 Sempron2800+ 阅读(143) 评论(0) 推荐(0) 编辑
摘要: 40ms,13.1mb 二分查找的变种,感觉怪怪的。相较而言,还是下面的这种更容易理解吧: 40ms,13.4mb 至少从oj提供的testcase来看,效率是几乎一致的,当然理论上是有O(logN)与O(N)的区别的。 阅读全文
posted @ 2019-02-25 22:05 Sempron2800+ 阅读(119) 评论(0) 推荐(0) 编辑
摘要: 这道题目的要求,Note: Your solution should run in O(log n) time and O(1) space. 因此应该用二分查找的方式,代码如下: 52ms,13.8mb 传统的方式,就是已经两次遍历,先遍历一遍数组,记录每一个值出现的次数,存储到一个字典中。 然后 阅读全文
posted @ 2019-02-25 21:35 Sempron2800+ 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 使用贪心思想,先按照end排序,然后依次寻找下一个(结束时前最早的)不重叠的区域,这样就得到了数量最多的构成不重叠的区域的数量,再用总数量减去最大不重叠区域的数量,就得到了最少的会引起重叠的区域的数量。 阅读全文
posted @ 2019-02-25 19:05 Sempron2800+ 阅读(119) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution: 2 def numRookCaptures(self, board: 'List[List[str]]') -> int: 3 basei = 0 4 basej = 0 5 row = len(board) 6 coloum = len(board[0]) 7 8 ... 阅读全文
posted @ 2019-02-24 12:58 Sempron2800+ 阅读(110) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution: 2 def findJudge(self, N: int, trust: 'List[List[int]]') -> int: 3 if N==1 and len(trust)==0: 4 return 1 5 s = list(range(1,N+1)) 6 d = ... 阅读全文
posted @ 2019-02-24 12:37 Sempron2800+ 阅读(118) 评论(0) 推荐(0) 编辑
摘要: 1 public class Solution 2 { 3 int row = 0; 4 int column = 0; 5 int FreshOrangeCount = 0; 6 int RottenOrangeCount = 0; 7 int Minute = 0; 8 ... 阅读全文
posted @ 2019-02-17 15:15 Sempron2800+ 阅读(137) 评论(0) 推荐(0) 编辑
摘要: 1 public class Node 2 { 3 public int CurNode; 4 public int FatherNode; 5 public int Layer; 6 } 7 8 public class Solution 9 { 10 public List L... 阅读全文
posted @ 2019-02-17 13:43 Sempron2800+ 阅读(120) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution: 2 3 def insertIntoBST(self, root, val): 4 """ 5 Time: O(log(n)) [average case] 6 Space: O(1) 7 """ 8 new_node = TreeNode(val) ... 阅读全文
posted @ 2019-02-11 16:34 Sempron2800+ 阅读(88) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution: 2 def brokenCalc(self, X: 'int', Y: 'int') -> 'int': 3 if X>=Y : 4 return Y-X 5 else: 6 num = 0 7 while Y > X: 8 ... 阅读全文
posted @ 2019-02-11 16:26 Sempron2800+ 阅读(165) 评论(0) 推荐(0) 编辑
上一页 1 ··· 68 69 70 71 72 73 74 75 76 ··· 114 下一页