随笔分类 -  leetcode

上一页 1 ··· 10 11 12 13 14 15 16 17 18 ··· 22 下一页
摘要:题目描述: 方法一:二叉搜索树+滑动窗口 方法二:桶排序 O(N) class Solution: def containsNearbyAlmostDuplicate(self, nums: List[int], k: int, t: int) -> bool: from collections i 阅读全文
posted @ 2019-10-04 13:40 oldby 阅读(309) 评论(0) 推荐(0)
摘要:题目描述: 第一次提交:超时 class Solution: def containsNearbyDuplicate(self, nums: List[int], k: int) -> bool: for i in range(len(nums)-1): for j in range(i+1,min 阅读全文
posted @ 2019-10-04 10:40 oldby 阅读(133) 评论(0) 推荐(0)
摘要:题目描述: 第一次提交: class Solution: def containsDuplicate(self, nums: List[int]) -> bool: nums2 = set(nums) return not len(nums2)==len(nums) 方法二:哈希表 class So 阅读全文
posted @ 2019-10-04 09:46 oldby 阅读(109) 评论(0) 推荐(0)
摘要:题目描述: 方法一:回溯 class Solution: def combinationSum3(self, k: int, n: int) -> List[List[int]]: res = [] def helper(k,n,start,tmp): if k==0: if n==0: res.a 阅读全文
posted @ 2019-10-03 17:00 oldby 阅读(188) 评论(0) 推荐(0)
摘要:题目描述: 方法一:堆排序* class Solution: def findKthLargest(self, nums: List[int], k: int) -> int: def adjust_heap(idx, max_len): left = 2 * idx + 1 right = 2 * 阅读全文
posted @ 2019-10-03 16:20 oldby 阅读(164) 评论(0) 推荐(0)
摘要:题目描述: 第一次提交: class Solution: def findOrder(self, numCourses: int, prerequisites: List[List[int]]) -> List[int]: indegree = [0 for _ in range(numCourse 阅读全文
posted @ 2019-10-03 16:04 oldby 阅读(260) 评论(0) 推荐(0)
摘要:题目描述: 方法一:双指针 O(N) class Solution: def minSubArrayLen(self, s: int, nums: List[int]) -> int: left = 0 res = float('inf') sum = 0 for i in range(len(nu 阅读全文
posted @ 2019-10-03 11:17 oldby 阅读(129) 评论(0) 推荐(0)
摘要:题目描述: 方法一: class Solution: def findMaximumXOR(self, nums: List[int]) -> int: root = TreeNode(-1) for num in nums: cur_node = root #当前的node for i in ra 阅读全文
posted @ 2019-10-03 09:50 oldby 阅读(406) 评论(0) 推荐(0)
摘要:题目描述: 第一次提交:(超出时间限制) class Solution: def findWords(self, board: List[List[str]], words: List[str]) -> List[str]: def dfs(word,i,j,visited): if len(wor 阅读全文
posted @ 2019-10-02 18:54 oldby 阅读(220) 评论(0) 推荐(0)
摘要:题目描述: 方法一: class WordDictionary: def __init__(self): """ Initialize your data structure here. """ #from collections import defaultdict self.lookup = { 阅读全文
posted @ 2019-10-02 16:49 oldby 阅读(223) 评论(0) 推荐(0)
摘要:题目描述: 方法一: class Trie: def __init__(self): """ Initialize your data structure here. """ self.tree = {} def insert(self, word: str) -> None: """ Insert 阅读全文
posted @ 2019-10-02 15:58 oldby 阅读(274) 评论(0) 推荐(0)
摘要:题目描述: 方法一:dfs class Solution: def canFinish(self, numCourses: int, prerequisites: List[List[int]]) -> bool: def dfs(i, adjacency, flags): if flags[i] 阅读全文
posted @ 2019-10-02 14:39 oldby 阅读(194) 评论(0) 推荐(0)
摘要:题目描述: 第一次提交: class Solution: def isIsomorphic(self, s: str, t: str) -> bool: dicA = {} dicB = {} for i in range(len(s)): if s[i] not in dicA: dicA[s[i 阅读全文
posted @ 2019-10-02 11:14 oldby 阅读(141) 评论(0) 推荐(0)
摘要:方法一: class Solution(object): def minimumSemesters(self, N, relations): """ :type N: int :type relations: List[List[int]] :rtype: int """ dic = {} dic2 阅读全文
posted @ 2019-07-30 17:15 oldby 阅读(339) 评论(0) 推荐(0)
摘要:方法一: class Solution: def minimumCost(self, N: int, conections: List[List[int]]) -> int: def find(i): if father[i]==i: return i else: father[i]=find(fa 阅读全文
posted @ 2019-07-30 17:10 oldby 阅读(921) 评论(0) 推荐(0)
摘要:第一次提交: class Solution: def isArmstrong(self, N: int) -> bool: n = N l = len(str(N)) res = 0 while N: a = N % 10 res += a**l N = N//10 if res == n: ret 阅读全文
posted @ 2019-07-30 16:13 oldby 阅读(178) 评论(0) 推荐(0)
摘要:第一次提交: class Solution: def largestUniqueNumber(self, A: List[int]) -> int: dict = {} for i in A: if i not in dict: dict[i] = 1 else: dict[i] += 1 res 阅读全文
posted @ 2019-07-30 16:10 oldby 阅读(302) 评论(0) 推荐(0)
摘要:题目描述: 方法一:dfs class Solution: def numIslands(self, grid: List[List[str]]) -> int: def dfs(grid,r,c): nr = len(grid) nc = len(grid[0]) if r<0 or c<0 or 阅读全文
posted @ 2019-07-30 15:46 oldby 阅读(273) 评论(0) 推荐(0)
摘要:题目描述: class Solution: def maxAbsValExpr(self, arr1, arr2) -> int: def function(s1,s2): result1=[] result2=[] result3=[] result4=[] for i in range(len( 阅读全文
posted @ 2019-07-25 09:33 oldby 阅读(311) 评论(0) 推荐(0)
摘要:题目描述: class Solution(object): def mctFromLeafValues(self, arr): """ :type arr: List[int] :rtype: int """ n = len(arr) f = {1: [0] * n} for l in range( 阅读全文
posted @ 2019-07-24 11:45 oldby 阅读(589) 评论(0) 推荐(0)

上一页 1 ··· 10 11 12 13 14 15 16 17 18 ··· 22 下一页