1 Cubic Meter

一立方米

[LeetCode] 179. Largest Number

发布于 # 解题报告

题目 Given a list of non negative integers, arrange them such that they form the largest number. Example 1: Input: [10,2] Output: "210" Example 2: Input: [3,30,34,5,9] Output: "9534330" Note: The result may be very large, so you need to return a string instead of an integer. 解题报告 首先,这是一个贪心问题,也就是说如果数字 a 和数字 b 比较 a 应该放在前面,那么整个字符串中 a 一定是会在 b 之前的;如果 a 比 b 前,b 比 c 前,a 一定会在 c 前面。这一点容易想到但是难以证明,因为这种比较相对于单

[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