摘要: 题目描述: 方法一:中缀表达式转后缀表达式,再用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 阅读(320) 评论(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 阅读(145) 评论(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 阅读(134) 评论(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 阅读(170) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:二叉搜索树+滑动窗口 方法二:桶排序 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 阅读(297) 评论(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 阅读(122) 评论(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 阅读(103) 评论(0) 推荐(0) 编辑