上一页 1 ··· 22 23 24 25 26 27 28 29 30 ··· 114 下一页
摘要: 1 class Solution: 2 def lexicalOrder(self, n: int) -> List[int]: 3 lis = [str(i) for i in range(1,n+1)] 4 lis.sort() 5 return lis 算法思路:按字符串顺序排序。 当然有能力 阅读全文
posted @ 2020-04-09 10:12 Sempron2800+ 阅读(99) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution: 2 def deserialize(self, s: str) -> NestedInteger: 3 4 if s[0] != '[': 5 return NestedInteger(int(s)) 6 7 stack = [] 8 # num为数字,sign为 阅读全文
posted @ 2020-04-09 09:44 Sempron2800+ 阅读(164) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution: 2 def integerReplacement(self, n: int) -> int: 3 count = 0 4 while n != 1: 5 if (n & 1) == 0: # 偶数直接右移 6 n >>= 1 7 else: 8 n += -1 i 阅读全文
posted @ 2020-04-09 09:41 Sempron2800+ 阅读(133) 评论(0) 推荐(0) 编辑
摘要: 方法一:深度优先搜索 1 class Solution: 2 def canMeasureWater(self, x: int, y: int, z: int) -> bool: 3 stack = [(0, 0)] 4 self.seen = set() 5 while stack: 6 rema 阅读全文
posted @ 2020-04-09 09:30 Sempron2800+ 阅读(165) 评论(0) 推荐(0) 编辑
摘要: 1 import heapq 2 import collections 3 class Twitter: 4 def __init__(self): 5 self.followers = collections.defaultdict(set)#key是被关注者,value是关注这个用户的人的集合 阅读全文
posted @ 2020-04-09 08:54 Sempron2800+ 阅读(226) 评论(0) 推荐(0) 编辑
摘要: 没能做出来,参考别人的: 1 from heapq import heapify, heappush, heappop 2 3 class Solution: 4 def findItinerary(self, tickets: List[List[str]]) -> List[str]: 5 gr 阅读全文
posted @ 2020-04-08 20:18 Sempron2800+ 阅读(188) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution: 2 def isValidSerialization(self, preorder: str) -> bool: 3 if preorder == '#':#空树是合法的 4 return True 5 nodes = preorder.split(',') 6 阅读全文
posted @ 2020-04-08 17:54 Sempron2800+ 阅读(175) 评论(0) 推荐(0) 编辑
摘要: 1 import sys 2 class Solution: 3 def nthSuperUglyNumber(self, n: int, primes: 'List[int]') -> int: 4 dp = [1]*n 5 m = len(primes) 6 plist = [0] * m 7 阅读全文
posted @ 2020-04-08 16:15 Sempron2800+ 阅读(152) 评论(0) 推荐(0) 编辑
摘要: 尝试使用bfs解决,但是TLE。给出代码如下: 1 import sys 2 class Solution: 3 def __init__(self): 4 self.depth = [] 5 self.mindepth = sys.maxsize 6 7 def bfs(self,n,visite 阅读全文
posted @ 2020-04-08 11:53 Sempron2800+ 阅读(151) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution: 2 def backTrack(self,num,l,idx,n): 3 if idx >= n: 4 if len(l) >= 3: 5 return True 6 else: 7 return False 8 for i in range(idx,n): 9 阅读全文
posted @ 2020-04-07 21:49 Sempron2800+ 阅读(174) 评论(0) 推荐(0) 编辑
上一页 1 ··· 22 23 24 25 26 27 28 29 30 ··· 114 下一页