leecode
仝笛
这个作者很懒,什么都没留下…
展开
-
leecode105. Construct Binary Tree from Preorder and Inorder Traversal先序中序重建树
leecode105. Construct Binary Tree from Preorder and Inorder Traversal先序中序重建树For example, givenpreorder = [3,9,20,15,7]inorder = [9,3,15,20,7]Return the following binary tree:3/ \9 20** / ...原创 2019-07-07 16:06:56 · 89 阅读 · 0 评论 -
leecode10. Regular Expression Matching字符串匹配
leecode10. Regular Expression Matching字符串匹配‘.’ Matches any single character.‘*’ Matches zero or more of the preceding element.Example 1:Input:s = “aa”p = “a”Output: falseExplanation: “a” does ...原创 2019-07-06 23:50:54 · 129 阅读 · 0 评论 -
leecode104. Maximum Depth of Binary Tree树高
leecode104. Maximum Depth of Binary Tree树高Example:Given binary tree [3,9,20,null,null,15,7],*** 3*** / \** 9 20**** / \** 15 7return its depth = 3.#迭代class Solution: def maxDep...原创 2019-07-07 15:07:51 · 97 阅读 · 0 评论 -
leecode70. 爬楼梯
leecode 70. 爬楼梯题目描述:假设你正在爬楼梯。需要 n 阶你才能到达楼顶。每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢?注意:给定 n 是一个正整数。示例 1:输入: 2输出: 2解释: 有两种方法可以爬到楼顶。1 阶 + 1 阶2 阶示例 2:输入: 3输出: 3解释: 有三种方法可以爬到楼顶。1 阶 + 1 阶 + 1 阶...原创 2019-08-24 12:00:18 · 131 阅读 · 0 评论 -
LeetCode122:卖股票的最佳时机 II
LeetCode122:卖股票的最佳时机 II题目描述:给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格。设计一个算法来计算你所能获取的最大利润。你可以尽可能地完成更多的交易(多次买卖一支股票)。注意:你不能同时参与多笔交易(你必须在再次购买前出售掉之前的股票)。示例 1:输入: [7,1,5,3,6,4]输出: 7解释: 在第 2 天(股票价格 = 1)的时候买入,...原创 2019-09-01 18:36:48 · 107 阅读 · 0 评论 -
leetcode 53. 最大子序和
leetcode 53. 最大子序和给定一个整数数组 nums ,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。示例:输入: [-2,1,-3,4,-1,2,1,-5,4],输出: 6解释: 连续子数组 [4,-1,2,1] 的和最大,为 6class Solution: def maxSubArray(self, nums: List[int]) -...原创 2019-09-01 18:45:48 · 72 阅读 · 0 评论 -
Leetcode 121:买卖股票的最佳时机
Leetcode 121:买卖股票的最佳时机题目描述:给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格。如果你最多只允许完成一笔交易(即买入和卖出一支股票),设计一个算法来计算你所能获取的最大利润。注意你不能在买入股票前卖出股票。示例 1:输入: [7,1,5,3,6,4]输出: 5解释: 在第 2 天(股票价格 = 1)的时候买入,在第 5 天(股票价格 = 6)的...原创 2019-09-03 16:03:29 · 82 阅读 · 0 评论 -
leetCode303 数组范围求和
leetCode303 数组范围求和题目描述:给定一个数组,求出数组范围 i 到 j (i ≤ j) 的元素总和,包含 i, j 两点。例如:给定nums = [-2, 0, 3, -5, 2, -1],?求和函数为sumRange()sumRange(0, 2) -> 1sumRange(2, 5) -> -1sumRange(0, 5) -> -3#简单,但...原创 2019-09-03 16:59:58 · 253 阅读 · 0 评论 -
leecode13. Roman to Integer
leecode13. Roman to Integer题目描述罗马数字包含以下七种字符: I, V, X, L,C,D 和 M。字符 数值I 1V 5X 10L 50C 100D 500M 10...原创 2019-09-04 10:51:08 · 91 阅读 · 0 评论 -
leecode103. Binary Tree Zigzag Level Order Traversal二叉树 之字形 层次遍历
Binary Tree Zigzag Level Order TraversalFor example:Given binary tree [3,9,20,null,null,15,7],3/ \9 20** / \15 7return its zigzag level order traversal as:[[3],[20,9],[15,7]]class...原创 2019-07-06 19:18:25 · 125 阅读 · 0 评论 -
leecode102. Binary Tree Level Order Traversal二叉树层次遍历
leecode102. Binary Tree Level Order Traversal二叉树层次遍历For example:Given binary tree [3,9,20,null,null,15,7],3/ \9 20** / \*15 7return its level order traversal as:[[3],[9,20],[15,7]]# ...原创 2019-07-06 18:09:51 · 231 阅读 · 0 评论 -
leecode 101. Symmetric Tree对称树
leecode 101. Symmetric Tree对称树For example, this binary tree [1,2,2,3,4,4,3] is symmetric:***1** / \** 2 2** / \ / \*3 4 4 3But the following [1,2,2,null,3,null,3] is not:1/ \2 2\ ...原创 2019-07-06 17:51:04 · 119 阅读 · 0 评论 -
leecode106. Construct Binary Tree from Inorder and Postorder Traversal中序后序重建树
leecode106. Construct Binary Tree from Inorder and Postorder Traversal中序后序重建树For example, giveninorder = [9,3,15,20,7]postorder = [9,15,7,20,3]Return the following binary tree:*** 3*** / \...原创 2019-07-07 16:53:52 · 85 阅读 · 0 评论 -
leecode107. Binary Tree Level Order Traversal II二叉树层次遍历 自底向上
leecode107. Binary Tree Level Order Traversal II二叉树层次遍历 自底向上For example:Given binary tree [3,9,20,null,null,15,7],*** 3*** / \** 9 20**** / \** 15 7return its bottom-up level or...原创 2019-07-07 17:12:24 · 102 阅读 · 0 评论 -
leecode108. Convert Sorted Array to Binary Search Tree有序数组转化为二叉搜索树
leecode108. Convert Sorted Array to Binary Search Tree有序数组转化为二叉搜索树Example:Given the sorted array: [-10,-3,0,5,9],One possible answer is: [0,-3,9,-10,null,5], which represents the following height...原创 2019-07-07 17:49:17 · 134 阅读 · 0 评论 -
leecode 94. 二叉树的中序遍历
leecode 94. 二叉树的中序遍历94. Binary Tree Inorder TraversalExample:Input: [1,null,2,3]1\ 2/3Output: [1,3,2]# Definition for a binary tree node.# class TreeNode:# def __init__(self, x):# ...原创 2019-06-29 15:38:07 · 131 阅读 · 0 评论 -
leecode 11. Container With Most Water
Container With Most WaterGiven n non-negative integers a1, a2, …, an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i...原创 2019-06-30 12:06:54 · 113 阅读 · 0 评论 -
leecode 5. Longest Palindromic Substring最长回文子串
leecode 5. Longest Palindromic Substring最长回文子串Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example 1:Input: “babad”Output: “ba...原创 2019-06-30 15:19:06 · 142 阅读 · 0 评论 -
leecode98. Validate Binary Search Tree验证搜索二叉树
Example 1:2/ \1 3Input: [2,1,3]Output: trueExample 2:5/ \1 4– / \*3 6Input: [5,1,4,null,null,3,6]Output: false# Definition for a binary tree node.# class TreeNode:# def _...原创 2019-07-06 16:33:51 · 87 阅读 · 0 评论 -
leecode 100. Same Tree
Same TreeExample 1:Input: 1 1------- / \ / \*****2 3 2 3 [1,2,3], [1,2,3]Output: trueExample 2:Input: 1 ***1------- / \ ** / \******2 ...原创 2019-07-06 17:30:16 · 82 阅读 · 0 评论 -
LeetCode56. 合并区间
LeetCode56. 合并区间Given a collection of intervals, merge all overlapping intervals.Example 1:Input: [[1,3],[2,6],[8,10],[15,18]]Output: [[1,6],[8,10],[15,18]]Explanation: Since intervals [1,3] and ...原创 2019-09-04 22:04:32 · 176 阅读 · 0 评论