摘要:
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 算法思路:按字符串顺序排序。 当然有能力 阅读全文
摘要:
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为 阅读全文
摘要:
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 阅读全文
摘要:
方法一:深度优先搜索 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 阅读全文
摘要:
1 import heapq 2 import collections 3 class Twitter: 4 def __init__(self): 5 self.followers = collections.defaultdict(set)#key是被关注者,value是关注这个用户的人的集合 阅读全文