上一页 1 ··· 25 26 27 28 29 30 31 32 33 ··· 114 下一页
摘要: 1 class Solution: 2 def rangeBitwiseAnd(self, m: int, n: int) -> int: 3 while n > m: 4 n &= (n-1) 5 return n 算法思路:位运算。 “按位与”操作有一个特点,就是 n & (n-1),是将n的最 阅读全文
posted @ 2020-03-31 08:20 Sempron2800+ 阅读(123) 评论(0) 推荐(0) 编辑
摘要: 1 class UndergroundSystem: 2 def __init__(self): 3 self.startStation = collections.defaultdict(lambda: collections.defaultdict(int)) 4 self.endStation 阅读全文
posted @ 2020-03-29 12:44 Sempron2800+ 阅读(211) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution: 2 def __init__(self): 3 #self.l = [] 4 self.count = 0 5 6 def backTrack(self,rating,temp,idx,inc): 7 if inc == 0:#递减 8 if len(temp) 阅读全文
posted @ 2020-03-29 12:38 Sempron2800+ 阅读(187) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution: 2 def findLucky(self, arr: List[int]) -> int: 3 dic = dict() 4 n = len(arr) 5 for i in range(n): 6 if arr[i] not in dic: 7 dic[arr[i 阅读全文
posted @ 2020-03-29 12:37 Sempron2800+ 阅读(178) 评论(0) 推荐(0) 编辑
摘要: 先给出一个TLE的方案,思路很简单: 1 class Solution: 2 def maxNumberOfFamilies(self, n: int, reservedSeats: 'List[List[int]]') -> int: 3 dic_row = dict() 4 for seats 阅读全文
posted @ 2020-03-28 15:39 Sempron2800+ 阅读(193) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution: 2 def getKth(self, lo: int, hi: int, k: int) -> int: 3 memo = dict() 4 memo[1] = 0 5 for i in range(1,hi+1): 6 cur = i 7 count = 0 8 阅读全文
posted @ 2020-03-26 10:54 Sempron2800+ 阅读(189) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution: 2 def __init__(self): 3 self.l = [] 4 5 def inOrder(self,node): 6 if node != None: 7 self.inOrder(node.left) 8 self.l.append(node.va 阅读全文
posted @ 2020-03-26 10:30 Sempron2800+ 阅读(152) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution: 2 def numOfMinutes(self, n: int, headID: int, manager: 'List[int]', informTime: 'List[int]') -> int: 3 graph = collections.defaultdi 阅读全文
posted @ 2020-03-25 08:01 Sempron2800+ 阅读(181) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution: 2 def dfs(self,grid,visited,x,y,m,n): 3 if x < 0 or x >= m or y < 0 or y >= n or visited[x][y] == 1: 4 return False 5 if x == m - 1 阅读全文
posted @ 2020-03-22 12:43 Sempron2800+ 阅读(186) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution: 2 def sumFourDivisors(self, nums: 'List[int]') -> int: 3 result = 0 4 n = len(nums) 5 for i in range(n): 6 s = set() 7 cur = nums[i] 阅读全文
posted @ 2020-03-22 12:38 Sempron2800+ 阅读(167) 评论(0) 推荐(0) 编辑
上一页 1 ··· 25 26 27 28 29 30 31 32 33 ··· 114 下一页