摘要: 维护一个大小为k的大根堆 class Solution: def heapfy(self,arr,i,length): left = 2*i+1 right = 2*i+2 if left<length and arr[left]>arr[i]: large = left else: large = 阅读全文
posted @ 2021-01-29 23:01 WangSJiNa 阅读(35) 评论(0) 推荐(0) 编辑
摘要: 使用队列 from threading import Thread from queue import Queue import random import time def produce(q): i = 0 while i<10: num = random.randint(1,10) q.put 阅读全文
posted @ 2021-01-27 17:15 WangSJiNa 阅读(42) 评论(0) 推荐(0) 编辑
摘要: 回溯的方法 class Solution: def permutation(self, s: str) -> List[str]: ans = set() def backtrace(path,tmp): if path=="": ans.add(tmp) return for i in range 阅读全文
posted @ 2021-01-19 16:21 WangSJiNa 阅读(29) 评论(0) 推荐(0) 编辑
摘要: class Solution: def longestConsecutive(self, nums: List[int]) -> int: cur_len = 0 nums = set(nums) ans = 0 for item in nums: if item-1 not in nums: cu 阅读全文
posted @ 2021-01-19 13:32 WangSJiNa 阅读(45) 评论(0) 推荐(0) 编辑
摘要: 方法1: class Solution: def longestCommonPrefix(self, strs: List[str]) -> str: if not strs: return "" ans = strs[0] i = 1 while i < len(strs): while strs 阅读全文
posted @ 2021-01-09 11:49 WangSJiNa 阅读(45) 评论(0) 推荐(0) 编辑