摘要: 题目描述: 最佳方法:O(m+n) O(1) class Solution: def searchMatrix(self, matrix, target): if not matrix : return False row = len(matrix) col = len(matrix[0]) i = 阅读全文
posted @ 2019-10-07 21:04 oldby 阅读(175) 评论(0) 推荐(0) 编辑
摘要: 方法: class Solution: def productExceptSelf(self, nums: [int]) -> [int]: res, p, q = [1], 1, 1 for i in range(len(nums) - 1): # top triangle p *= nums[i 阅读全文
posted @ 2019-10-07 19:33 oldby 阅读(112) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法: class Solution: def deleteNode(self, node): """ :type node: ListNode :rtype: void Do not return anything, modify node in-place instead. """ 阅读全文
posted @ 2019-10-07 19:08 oldby 阅读(158) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一: # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class 阅读全文
posted @ 2019-10-07 17:28 oldby 阅读(160) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法:动态规划 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 阅读(107) 评论(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 阅读(132) 评论(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 阅读(418) 评论(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 阅读(262) 评论(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 阅读(260) 评论(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 阅读(178) 评论(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 阅读(127) 评论(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 阅读(163) 评论(0) 推荐(0) 编辑