leetcode153
摘要:40ms,13.1mb 二分查找的变种,感觉怪怪的。相较而言,还是下面的这种更容易理解吧: 40ms,13.4mb 至少从oj提供的testcase来看,效率是几乎一致的,当然理论上是有O(logN)与O(N)的区别的。
阅读全文
posted @
2019-02-25 22:05
Sempron2800+
阅读(125)
推荐(0)
leetcode540
摘要:这道题目的要求,Note: Your solution should run in O(log n) time and O(1) space. 因此应该用二分查找的方式,代码如下: 52ms,13.8mb 传统的方式,就是已经两次遍历,先遍历一遍数组,记录每一个值出现的次数,存储到一个字典中。 然后
阅读全文
posted @
2019-02-25 21:35
Sempron2800+
阅读(165)
推荐(0)
leetcode435
摘要:使用贪心思想,先按照end排序,然后依次寻找下一个(结束时前最早的)不重叠的区域,这样就得到了数量最多的构成不重叠的区域的数量,再用总数量减去最大不重叠区域的数量,就得到了最少的会引起重叠的区域的数量。
阅读全文
posted @
2019-02-25 19:05
Sempron2800+
阅读(129)
推荐(0)
leetcode999
摘要: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+
阅读(119)
推荐(0)
leetcode997
摘要: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+
阅读(126)
推荐(0)
leetcode994
摘要: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+
阅读(167)
推荐(0)
leetcode993
摘要: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+
阅读(132)
推荐(0)
leetcode701
摘要: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+
阅读(96)
推荐(0)
leetcode991
摘要: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+
阅读(172)
推荐(0)
leetcode989
摘要:上面这个是参考别人的解决方案,思路不好理解,我又从新写了一个啰嗦的:
阅读全文
posted @
2019-02-10 13:59
Sempron2800+
阅读(175)
推荐(0)
leetcode988
摘要:1 public class Solution 2 { 3 private Stack ST = new Stack(); 4 private string SmallestStr = String.Empty; 5 private string[] Ary = new string[] { "a","b","c","d","e"...
阅读全文
posted @
2019-02-05 22:33
Sempron2800+
阅读(134)
推荐(0)
leetcode987
摘要:这道题的描述有一些不清楚,主要是If two nodes have the same position, then the value of the node that is reported first is the value that is smaller. 这一句,应该是先按照层排序,同层的
阅读全文
posted @
2019-02-05 21:52
Sempron2800+
阅读(158)
推荐(0)
leetcode986
摘要:class Solution: def judgeIntersection(self,a:'Interval',b:'Interval'): #返回值1,bool类型,是否有交集:True-有交集,False-无交集 #返回值2,int类型,哪个先结束:0-A先结束,1-B先结束,2-AB同时结束 #返回值3,Interval类型,交集的...
阅读全文
posted @
2019-02-05 18:34
Sempron2800+
阅读(216)
推荐(0)
leetcode985
摘要:import sys class Solution: def sumEvenAfterQueries(self, A: 'List[int]', queries: 'List[List[int]]') -> 'List[int]': result = list() len0 = len(A) len1 = len(queries) ...
阅读全文
posted @
2019-02-03 16:46
Sempron2800+
阅读(155)
推荐(0)