自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

魔豆(Magicbean)的博客

分享计算机专业的相关知识

  • 博客(33)
  • 收藏
  • 关注

原创 [Leetcode] 121. Best Time to Buy and Sell Stock 解题报告

题目:Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of th

2017-04-28 10:53:17 387

原创 [Leetcode] 120. Triangle 解题报告

题目:Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3

2017-04-28 10:43:02 324

原创 [Leetcode] 119. Pascal's Triangle II 解题报告

题目:Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space?思路:

2017-04-28 10:17:32 304

原创 [Leetcode] 118. Pascal's Triangle 解题报告

题目:Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]思路:Easy级别的题目,逐层添加

2017-04-28 09:41:56 266

原创 [Leetcode] 117. Populating Next Right Pointers in Each Node II 解题报告

题目:Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use

2017-04-28 09:32:14 540

原创 [Leetcode] 116. Populating Next Right Pointers in Each Node 解题报告

题目:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next rig

2017-04-27 11:17:59 268

原创 [Leetcode] 115. Distinct Subsequences 解题报告

题目:Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (c

2017-04-27 10:54:46 415

原创 [Leetcode] 114. Flatten Binary Tree to Linked List 解题报告

题目:Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like:

2017-04-26 11:11:04 302

原创 [Leetcode] 113. Path Sum II 解题报告

题目:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5

2017-04-26 10:39:17 330

原创 [Leetcode] 112. Path Sum 解题报告

题目: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.For example:Given the below binary

2017-04-26 10:24:57 280

原创 [Leetcode] 111. Minimum Depth of Binary Tree 解题报告

题目:Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.思路:1、深度优先搜索:分别计算左子树的最小高度和

2017-04-26 10:00:46 437

原创 [Leetcode] 110. Balanced Binary Tree 解题报告

题目:Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node ne

2017-04-26 09:10:15 379

原创 [Leetcode] 109. Convert Sorted List to Binary Search Tree 解题报告

题目:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.思路:1、预先计算长度:我们可以采用线性扫描的方法获得链表长度,然后采用中序构造的方法来生成BST:即首先生成左子树,然后生成根节点,最后生成右子树。这是因为采

2017-04-25 10:41:59 398

原创 [Leetcode] 108. Convert Sorted Array to Binary Search Tree 解题报告

题目:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.思路:也是很简单的一道题目:首先选取数组的中位数作为根节点,然后递归地构造左子树和右子树,最后合成并返回结果。算法的时间复杂度是O(n),空间复杂度是O(1),因为没有开辟额外的空间。

2017-04-25 10:11:18 307

原创 [Leetcode] 107. Binary Tree Level Order Traversal II 解题报告

题目:Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree [3,9,20,nu

2017-04-25 10:02:01 263

原创 [Leetcode] 106. Construct Binary Tree from Inorder and Postorder Traversal 解题报告

题目:Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.思路:这道题目和Leetcode 105十分类似,唯一的区别就在于后续遍历中,根节点处于最

2017-04-25 09:48:27 369

原创 [Leetcode] 105. Construct Binary Tree from Preorder and Inorder Traversal 解题报告

题目:Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.思路:1、无预处理的递归:在先序序列中的第一个元素为根节点,这个节点在中序序列中会将节点分为

2017-04-24 10:42:23 384 1

原创 [Leetcode] 104. Maximum Depth of Binary Tree 解题报告

题目:Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.思路:太直观的一道题目了,可以用来愉悦心情!代

2017-04-24 09:44:25 340

原创 [Leetcode] 103. Binary Tree Zigzag Level Order Traversal 解题报告

题目:Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Give

2017-04-24 09:39:20 458

原创 [Leetcode] 102. Binary Tree Level Order Traversal 解题报告

题目: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,9,20,null,null,15,7], 3 /

2017-04-21 11:09:16 280

原创 [Leetcode] 101. Symmetric Tree 解题报告

题目:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3

2017-04-21 10:55:58 343

原创 [Leetcode] 100. Same Tree 解题报告

题目:Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.思路:

2017-04-21 10:27:38 311

原创 [Leetcode] 99. Recover Binary Search Tree 解题报告

题目:Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is pretty straight forward. Could

2017-04-21 10:20:46 460

原创 [Leetcode] 98. Validate Binary Search Tree 解题报告

题目:Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node

2017-04-21 09:33:45 444

原创 [Leetcode] 97. Interleaving String 解题报告

题目:Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aadbbba

2017-04-20 11:15:35 525

原创 [Leetcode] 96. Unique Binary Search Trees 解题报告

题目:Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2

2017-04-20 10:53:22 358

原创 [Leetcode] 95. Unique Binary Search Trees II 解题报告

题目:Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all 5 unique BST's shown bel

2017-04-20 10:34:09 1504

原创 [Leetcode] 94. Binary Tree Inorder Traversal 解题报告

题目:Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree [1,null,2,3], 1 \ 2 / 3return [1,3,2].Note: Recur

2017-04-19 10:40:56 296

原创 [Leetcode] 93. Restore IP Addresses 解题报告

题目:Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]

2017-04-19 10:06:17 321

原创 [Leetcode] 92. Reverse Linked List II 解题报告

题目:Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given m, n sa

2017-04-19 09:17:55 330

原创 [Leetcode] 91. Decode Ways 解题报告

题目:A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the

2017-04-18 21:42:50 396

原创 [Leetcode] 90. Subsets II 解题报告

题目:Given a collection of integers that might contain duplicates, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example,If nums = [1,2,

2017-04-18 21:14:35 286

原创 [Leetcode] 89. Gray Code 解题报告

题目:The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the seq

2017-04-18 19:41:42 407

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除