随笔分类 -  leetcode

上一页 1 ··· 9 10 11 12 13 14 15 16 17 ··· 22 下一页
摘要:题目描述: 方法:动态规划 class Solution: def isValidPalindrome(self, s: str, k: int) -> bool: def isKPalRec(str1, str2, m, n): dp = [[0] * (n + 1) for _ in range 阅读全文
posted @ 2019-10-07 14:58 oldby 阅读(113) 评论(0) 推荐(0)
摘要:题目描述: 自己的提交:参考全排列 class Solution: def countSteppingNumbers(self, low: int, high: int) -> List[int]: a = [i for i in range(10)] res =[] def helper(num) 阅读全文
posted @ 2019-10-07 14:23 oldby 阅读(155) 评论(0) 推荐(0)
摘要:题目描述: 自己的提交: class Solution: def twoSumBSTs(self, root1: TreeNode, root2: TreeNode, target: int) -> bool: if not root1 :return root_copy = root2 while 阅读全文
posted @ 2019-10-07 13:36 oldby 阅读(428) 评论(0) 推荐(0)
摘要:题目描述: 自己的提交: class Solution: def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]: arr = arr1 + arr2 +arr3 res 阅读全文
posted @ 2019-10-07 13:24 oldby 阅读(275) 评论(0) 推荐(0)
摘要:题目描述: 方法:倒推 class Solution(object): def countVowelPermutation(self, n): MOD = 10 ** 9 + 7 a=e=i=o=u= 1 for ZZZ in xrange(n-1): a2,e2,i2,o2,u2 = e+i+u, 阅读全文
posted @ 2019-10-07 11:13 oldby 阅读(266) 评论(0) 推荐(0)
摘要:题目描述: 方法一:dfs class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: maxx = 0 R, C = len(grid), len(grid[0]) def dfs(r, c, visited, c 阅读全文
posted @ 2019-10-07 10:17 oldby 阅读(183) 评论(0) 推荐(0)
摘要:题目描述: class Solution: def longestSubsequence(self, arr: List[int], difference: int) -> int: dp = dict() for a in arr: pre = a - difference if pre in d 阅读全文
posted @ 2019-10-07 09:46 oldby 阅读(132) 评论(0) 推荐(0)
摘要:题目描述: 自己的提交: class Solution: def minCostToMoveChips(self, chips: List[int]) -> int: res = float('inf') nums = set(chips) for num in nums: ans = 0 for 阅读全文
posted @ 2019-10-07 09:35 oldby 阅读(172) 评论(0) 推荐(0)
摘要:题目描述; 方法一:O(N) O(1) # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: 阅读全文
posted @ 2019-10-05 19:06 oldby 阅读(87) 评论(0) 推荐(0)
摘要:题目描述: 方法一:双栈 class MyQueue: def __init__(self): """ Initialize your data structure here. """ from collections import deque self.stack = deque() def pu 阅读全文
posted @ 2019-10-05 18:47 oldby 阅读(183) 评论(0) 推荐(0)
摘要:题目描述: 第一次提交: class Solution: def isPowerOfTwo(self, n: int) -> bool: if n==0:return False if n==1: return True s = str(bin(n))[3:] for i in s: if i == 阅读全文
posted @ 2019-10-05 16:40 oldby 阅读(205) 评论(0) 推荐(0)
摘要:题目描述: 方法一:递归: # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None cl 阅读全文
posted @ 2019-10-05 16:16 oldby 阅读(138) 评论(0) 推荐(0)
摘要:题目描述: 方法一:摩尔投票法 class Solution: def majorityElement(self, nums: List[int]) -> List[int]: candiate1 = candiate2 = None cnt1 = cnt2 = 0 for num in nums: 阅读全文
posted @ 2019-10-05 14:28 oldby 阅读(141) 评论(0) 推荐(0)
摘要:题目描述: 第一次提交:双指针 O(N) class Solution: def summaryRanges(self, nums: List[int]) -> List[str]: #first = 0 last = 0 res = [] while last!=len(nums): first 阅读全文
posted @ 2019-10-05 11:33 oldby 阅读(113) 评论(0) 推荐(0)
摘要:题目描述: 方法一:中缀转后缀 #!_*_coding:utf-8_*_ class Solution: def calculate(self, s: str) -> int: def in_to_suffix(s): priority = {'+': 1, '-': 1, '*': 2, '/': 阅读全文
posted @ 2019-10-05 11:03 oldby 阅读(195) 评论(0) 推荐(0)
摘要:题目描述: from collections import deque class MyStack: def __init__(self): """ Initialize your data structure here. """ self.queue = deque() def push(self 阅读全文
posted @ 2019-10-05 09:32 oldby 阅读(223) 评论(0) 推荐(0)
摘要:题目描述: 方法一:中缀表达式转后缀表达式,再用150题方法求解 class Solution: def calculate(self, s: str) -> int: tokens = self.infix_to_suffix(s) result = self.evalRPN(tokens) re 阅读全文
posted @ 2019-10-04 20:27 oldby 阅读(334) 评论(0) 推荐(0)
摘要:题目描述: 方法: class Solution: def computeArea(self, A: int, B: int, C: int, D: int, E: int, F: int, G: int, H: int) -> int: # 调整两个矩形位置, 让第一个矩形靠最左边 if A > 阅读全文
posted @ 2019-10-04 18:25 oldby 阅读(150) 评论(0) 推荐(0)
摘要:题目描述: 方法一:O(N) class Solution: def countNodes(self, root: TreeNode) -> int: if not root: return 0 return 1 + self.countNodes(root.left) + self.countNo 阅读全文
posted @ 2019-10-04 17:11 oldby 阅读(142) 评论(0) 推荐(0)
摘要:题目描述: 方法一:动态规划 class Solution: def maximalSquare(self, matrix: List[List[str]]) -> int: if not matrix: return 0 row = len(matrix) col = len(matrix[0]) 阅读全文
posted @ 2019-10-04 16:16 oldby 阅读(176) 评论(0) 推荐(0)

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