1 Cubic Meter

一立方米

[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's key. The right subtree of a node contains only nodes with keys greater than the node's key. Both the left and right subtrees must also be binary search trees. Example 1: Input: 2 / \ 1 3 Output: t

[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. Note: A leaf is a node with no children. Example: Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 return its minimum depth = 2. 解题报告 思路 反正就是,有叶子就往下找,没叶子就完事儿了嘛~ 方法一:递归 在处理一颗树的时候递归往往是很容易想到的方法,对于每个节点只要检查左

[LeetCode] 207. Course Schedule

发布于 # 解题报告

题目 LeetCode 链接 There are a total of n courses you have to take, labeled from 0 to n-1. Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pair: [0,1] Given the total number of courses and a list of prerequisite pairs, is it possible for you to finish all courses? Example 1: Input: 2, [[1,0]] Output: true Explanation: There are

[TopCoder-SRM 726] Unpacking

发布于 # 解题报告

题目 TopCoder链接 Problem Statement The holidays are near. Hero would like to buy some candies, so he went to the store. In the store he found some boxes. Each box has a label with three positive integers a[i], b[i], and cost[i]. Their meaning is as follows: Obviously, cost[i] is the amount Hero has to pay to buy this box. The other two numbers promise that the box will contain exactly a[i] red candie

[LeetCode] 3. Longest Substring Without Repeating Characters

发布于 # 解题报告

题目 LeetCode链接 Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "abc", which the length is 3. Given "bbbbb", the answer is "b", with the length of 1. Given "pwwkew", the answer is "wke", with the length of 3. Note that the answer must be a substring, "pwke" is a subsequenceand not a substring. 解题报告 思路 乍一想可能是动态规划的一道题,实际上