随笔分类 -  leetcode

摘要:Given a binary tree, return the preorder traversal of its nodes' values. Example: Input: [1,null,2,3] 1 \ 2 / 3 Output: [1,2,3] Follow up: Recursive s 阅读全文
posted @ 2020-03-08 11:05 米开朗菠萝 阅读(91) 评论(0) 推荐(0)
摘要:Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 whic 阅读全文
posted @ 2020-03-08 10:53 米开朗菠萝 阅读(128) 评论(0) 推荐(0)
摘要:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. Note: A leaf is a node with no children. Exampl 阅读全文
posted @ 2020-03-08 10:35 米开朗菠萝 阅读(125) 评论(0) 推荐(0)
摘要:Given a binary tree, flatten it to a linked list in-place. For example, given the following tree: 1 / \ 2 5 / \ \ 3 4 6 The flattened tree should look 阅读全文
posted @ 2020-03-07 16:07 米开朗菠萝 阅读(84) 评论(0) 推荐(0)
摘要:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. N 阅读全文
posted @ 2020-03-07 15:19 米开朗菠萝 阅读(145) 评论(0) 推荐(0)
摘要:Given two binary trees, write a function to check if they are the same or not. Two binary trees are considered the same if they are structurally ident 阅读全文
posted @ 2020-03-06 14:44 米开朗菠萝 阅读(117) 评论(0) 推荐(0)
摘要:Given an unsorted array of integers, find the length of longest increasing subsequence. Example: Input: [10,9,2,5,3,7,101,18] Output: 4 Explanation: T 阅读全文
posted @ 2020-03-05 21:51 米开朗菠萝 阅读(130) 评论(0) 推荐(0)
摘要:Given two words word1 and word2, find the minimum number of operations required to convert word1 to word2. You have the following 3 operations permitt 阅读全文
posted @ 2020-03-05 19:52 米开朗菠萝 阅读(138) 评论(0) 推荐(0)
摘要:Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. 阅读全文
posted @ 2020-03-05 17:14 米开朗菠萝 阅读(126) 评论(0) 推荐(0)
摘要:A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any p 阅读全文
posted @ 2020-03-05 13:59 米开朗菠萝 阅读(117) 评论(0) 推荐(0)
摘要: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: 阅读全文
posted @ 2020-03-05 11:41 米开朗菠萝 阅读(93) 评论(0) 推荐(0)
摘要:Invert a binary tree. Example: Input: 4 / \ 2 7 / \ / \ 1 3 6 9 Output: 4 / \ 7 2 / \ / \ 9 6 3 1 # Definition for a binary tree node. # class TreeNod 阅读全文
posted @ 2020-03-01 16:02 米开朗菠萝 阅读(74) 评论(0) 推荐(0)
摘要:Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that duplicates do not exist in the tree. For example, 阅读全文
posted @ 2020-03-01 11:26 米开朗菠萝 阅读(133) 评论(0) 推荐(0)
摘要:Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example:Given binary tree [3 阅读全文
posted @ 2020-03-01 10:23 米开朗菠萝 阅读(136) 评论(0) 推荐(0)
摘要:"""解题思路:1.荷兰分区问题,我们把数组分成四类:red, white, 未分类, blue。初始的时候都在未分类组里,只要白色指针小于蓝色指针,我们遍历数组2.当白色指针是是红色的时候nums[white]==0,我们交换红色指针,并且两个指针同时+13.当白色指针是白色的时候,位置在正确位置 阅读全文
posted @ 2020-02-28 09:30 米开朗菠萝 阅读(148) 评论(0) 推荐(0)
摘要:“”“解题思路:遍历数组,每次遍历记录数组最小值,并且用计算当前值和最小值之差为利润,记录最大的利润”“”class Solution(object): def maxProfit(self, prices): """ :type prices: List[int] :rtype: int """ 阅读全文
posted @ 2020-02-28 08:18 米开朗菠萝 阅读(114) 评论(0) 推荐(0)
摘要:# Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = x # self.left = None # self.right = None # 递归,中序遍 阅读全文
posted @ 2020-02-18 11:13 米开朗菠萝 阅读(88) 评论(0) 推荐(0)
摘要:#用二分查找法class Solution(object): def searchRange(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[int] """ first = 0 last = 阅读全文
posted @ 2020-02-11 17:13 米开朗菠萝 阅读(104) 评论(0) 推荐(0)
摘要:# 递归方法解决class Solution(object): def letterCombinations(self, digits): """ :type digits: str :rtype: List[str] """ d = {"2":"abc", "3":"def", "4":"ghi" 阅读全文
posted @ 2020-02-11 16:16 米开朗菠萝 阅读(90) 评论(0) 推荐(0)
摘要:class Solution(object): def isValid(self, s): """ :type s: str :rtype: bool """ stack = [] #存放符号 d = {"]": "[", ")":"(", "}":"{"} “”“ 判断符号是否是结束符号,如果是, 阅读全文
posted @ 2020-02-11 13:53 米开朗菠萝 阅读(73) 评论(0) 推荐(0)