From d9246ed64f5176888e605e46c717dc1210a995de Mon Sep 17 00:00:00 2001 From: openset Date: Mon, 6 May 2019 10:31:49 +0800 Subject: [PATCH] Add: new --- README.md | 6 +- .../README.md | 51 ++++++++++++++ problems/escape-a-large-maze/README.md | 2 +- .../README.md | 64 +++++++++++++++++ .../README.md | 70 +++++++++++++++++++ problems/valid-boomerang/README.md | 47 +++++++++++++ 6 files changed, 238 insertions(+), 2 deletions(-) create mode 100644 problems/binary-search-tree-to-greater-sum-tree/README.md create mode 100644 problems/minimum-score-triangulation-of-polygon/README.md create mode 100644 problems/moving-stones-until-consecutive-ii/README.md create mode 100644 problems/valid-boomerang/README.md diff --git a/README.md b/README.md index 8fd098c0e..ea7e622af 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,10 @@ LeetCode Problems' Solutions | # | Title | Solution | Difficulty | | :-: | - | - | :-: | +| 1040 | [Moving Stones Until Consecutive II](https://leetcode.com/problems/moving-stones-until-consecutive-ii "移动石子直到连续 II") | [Go](https://github.com/openset/leetcode/tree/master/problems/moving-stones-until-consecutive-ii) | Medium | +| 1039 | [Minimum Score Triangulation of Polygon](https://leetcode.com/problems/minimum-score-triangulation-of-polygon "多边形三角剖分的最低得分") | [Go](https://github.com/openset/leetcode/tree/master/problems/minimum-score-triangulation-of-polygon) | Medium | +| 1038 | [Binary Search Tree to Greater Sum Tree](https://leetcode.com/problems/binary-search-tree-to-greater-sum-tree "从二叉搜索树到更大和树") | [Go](https://github.com/openset/leetcode/tree/master/problems/binary-search-tree-to-greater-sum-tree) | Medium | +| 1037 | [Valid Boomerang](https://leetcode.com/problems/valid-boomerang "有效的回旋镖") | [Go](https://github.com/openset/leetcode/tree/master/problems/valid-boomerang) | Easy | | 1036 | [Escape a Large Maze](https://leetcode.com/problems/escape-a-large-maze "逃离大迷宫") | [Go](https://github.com/openset/leetcode/tree/master/problems/escape-a-large-maze) | Hard | | 1035 | [Uncrossed Lines](https://leetcode.com/problems/uncrossed-lines "不相交的线") | [Go](https://github.com/openset/leetcode/tree/master/problems/uncrossed-lines) | Medium | | 1034 | [Coloring A Border](https://leetcode.com/problems/coloring-a-border "边框着色") | [Go](https://github.com/openset/leetcode/tree/master/problems/coloring-a-border) | Medium | @@ -456,7 +460,7 @@ LeetCode Problems' Solutions | 637 | [Average of Levels in Binary Tree](https://leetcode.com/problems/average-of-levels-in-binary-tree "二叉树的层平均值") | [Go](https://github.com/openset/leetcode/tree/master/problems/average-of-levels-in-binary-tree) | Easy | | 636 | [Exclusive Time of Functions](https://leetcode.com/problems/exclusive-time-of-functions "函数的独占时间") | [Go](https://github.com/openset/leetcode/tree/master/problems/exclusive-time-of-functions) | Medium | | 635 | [Design Log Storage System](https://leetcode.com/problems/design-log-storage-system) 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/design-log-storage-system) | Medium | -| 634 | [Find the Derangement of An Array](https://leetcode.com/problems/find-the-derangement-of-an-array) 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/find-the-derangement-of-an-array) | Medium | +| 634 | [Find the Derangement of An Array](https://leetcode.com/problems/find-the-derangement-of-an-array "寻找数组的错位排列") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/find-the-derangement-of-an-array) | Medium | | 633 | [Sum of Square Numbers](https://leetcode.com/problems/sum-of-square-numbers "平方数之和") | [Go](https://github.com/openset/leetcode/tree/master/problems/sum-of-square-numbers) | Easy | | 632 | [Smallest Range](https://leetcode.com/problems/smallest-range "最小区间") | [Go](https://github.com/openset/leetcode/tree/master/problems/smallest-range) | Hard | | 631 | [Design Excel Sum Formula](https://leetcode.com/problems/design-excel-sum-formula) 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/design-excel-sum-formula) | Hard | diff --git a/problems/binary-search-tree-to-greater-sum-tree/README.md b/problems/binary-search-tree-to-greater-sum-tree/README.md new file mode 100644 index 000000000..63c24a8e1 --- /dev/null +++ b/problems/binary-search-tree-to-greater-sum-tree/README.md @@ -0,0 +1,51 @@ + + + + + + + +[< Previous](https://github.com/openset/leetcode/tree/master/problems/valid-boomerang "Valid Boomerang") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/minimum-score-triangulation-of-polygon "Minimum Score Triangulation of Polygon") + +## 5050. Binary Search Tree to Greater Sum Tree (Medium) + +

Given the root of a binary search tree with distinct values, modify it so that every node has a new value equal to the sum of the values of the original tree that are greater than or equal to node.val.

+ +

As a reminder, a binary search tree is a tree that satisfies these constraints:

+ + + +

 

+ +

Example 1:

+ +

+ +
+Input: [4,1,6,0,2,5,7,null,null,null,3,null,null,null,8]
+Output: [30,36,21,36,35,26,15,null,null,null,33,null,null,null,8]
+
+ +
+

 

+
+ +

Note:

+ +
    +
  1. The number of nodes in the tree is between 1 and 100.
  2. +
  3. Each node will have value between 0 and 100.
  4. +
  5. The given tree is a binary search tree.
  6. +
+ +
+
+
 
+
+
diff --git a/problems/escape-a-large-maze/README.md b/problems/escape-a-large-maze/README.md index 1ee29979a..c99db6e84 100644 --- a/problems/escape-a-large-maze/README.md +++ b/problems/escape-a-large-maze/README.md @@ -7,7 +7,7 @@ [< Previous](https://github.com/openset/leetcode/tree/master/problems/uncrossed-lines "Uncrossed Lines")                  -Next > +[Next >](https://github.com/openset/leetcode/tree/master/problems/valid-boomerang "Valid Boomerang") ## 1036. Escape a Large Maze (Hard) diff --git a/problems/minimum-score-triangulation-of-polygon/README.md b/problems/minimum-score-triangulation-of-polygon/README.md new file mode 100644 index 000000000..8eb54ab48 --- /dev/null +++ b/problems/minimum-score-triangulation-of-polygon/README.md @@ -0,0 +1,64 @@ + + + + + + + +[< Previous](https://github.com/openset/leetcode/tree/master/problems/binary-search-tree-to-greater-sum-tree "Binary Search Tree to Greater Sum Tree") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/moving-stones-until-consecutive-ii "Moving Stones Until Consecutive II") + +## 5047. Minimum Score Triangulation of Polygon (Medium) + +

Given N, consider a convex N-sided polygon with vertices labelled A[0], A[i], ..., A[N-1] in clockwise order.

+ +

Suppose you triangulate the polygon into N-2 triangles.  For each triangle, the value of that triangle is the product of the labels of the vertices, and the total score of the triangulation is the sum of these values over all N-2 triangles in the triangulation.

+ +

Return the smallest possible total score that you can achieve with some triangulation of the polygon.

+ +

 

+ +
    +
+ +
+

Example 1:

+ +
+Input: [1,2,3]
+Output: 6
+Explanation: The polygon is already triangulated, and the score of the only triangle is 6.
+
+ +
+

Example 2:

+ +

+ +
+Input: [3,7,4,5]
+Output: 144
+Explanation: There are two triangulations, with possible scores: 3*7*5 + 4*5*7 = 245, or 3*4*5 + 3*4*7 = 144.  The minimum score is 144.
+
+ +
+

Example 3:

+ +
+Input: [1,3,1,4,1,5]
+Output: 13
+Explanation: The minimum score triangulation has score 1*1*3 + 1*1*4 + 1*1*5 + 1*1*1 = 13.
+
+ +

 

+ +

Note:

+ +
    +
  1. 3 <= A.length <= 50
  2. +
  3. 1 <= A[i] <= 100
  4. +
+
+
+
diff --git a/problems/moving-stones-until-consecutive-ii/README.md b/problems/moving-stones-until-consecutive-ii/README.md new file mode 100644 index 000000000..247cab73b --- /dev/null +++ b/problems/moving-stones-until-consecutive-ii/README.md @@ -0,0 +1,70 @@ + + + + + + + +[< Previous](https://github.com/openset/leetcode/tree/master/problems/minimum-score-triangulation-of-polygon "Minimum Score Triangulation of Polygon") +                 +Next > + +## 5049. Moving Stones Until Consecutive II (Medium) + +

On an infinite number line, the position of the i-th stone is given by stones[i].  Call a stone an endpoint stone if it has the smallest or largest position.

+ +

Each turn, you pick up an endpoint stone and move it to an unoccupied position so that it is no longer an endpoint stone.

+ +

In particular, if the stones are at say, stones = [1,2,5], you cannot move the endpoint stone at position 5, since moving it to any position (such as 0, or 3) will still keep that stone as an endpoint stone.

+ +

The game ends when you cannot make any more moves, ie. the stones are in consecutive positions.

+ +

When the game ends, what is the minimum and maximum number of moves that you could have made?  Return the answer as an length 2 array: answer = [minimum_moves, maximum_moves]

+ +

 

+ +

Example 1:

+ +
+Input: [7,4,9]
+Output: [1,2]
+Explanation: 
+We can move 4 -> 8 for one move to finish the game.
+Or, we can move 9 -> 5, 4 -> 6 for two moves to finish the game.
+
+ +
+

Example 2:

+ +
+Input: [6,5,4,3,10]
+Output: [2,3]
+We can move 3 -> 8 then 10 -> 7 to finish the game.
+Or, we can move 3 -> 7, 4 -> 8, 5 -> 9 to finish the game.
+Notice we cannot move 10 -> 2 to finish the game, because that would be an illegal move.
+
+ +
+

Example 3:

+ +
+Input: [100,101,104,102,103]
+Output: [0,0]
+ +

 

+
+
+ +

Note:

+ +
    +
  1. 3 <= stones.length <= 10^4
  2. +
  3. 1 <= stones[i] <= 10^9
  4. +
  5. stones[i] have distinct values.
  6. +
+ +
+
+
 
+
+
diff --git a/problems/valid-boomerang/README.md b/problems/valid-boomerang/README.md new file mode 100644 index 000000000..2a23ba128 --- /dev/null +++ b/problems/valid-boomerang/README.md @@ -0,0 +1,47 @@ + + + + + + + +[< Previous](https://github.com/openset/leetcode/tree/master/problems/escape-a-large-maze "Escape a Large Maze") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/binary-search-tree-to-greater-sum-tree "Binary Search Tree to Greater Sum Tree") + +## 5051. Valid Boomerang (Easy) + +

A boomerang is a set of 3 points that are all distinct and not in a straight line.

+ +

Given a list of three points in the plane, return whether these points are a boomerang.

+ +

 

+ +

Example 1:

+ +
+Input: [[1,1],[2,3],[3,2]]
+Output: true
+
+ +
+

Example 2:

+ +
+Input: [[1,1],[2,2],[3,3]]
+Output: false
+
+ +

 

+ +

Note:

+ +
    +
  1. points.length == 3
  2. +
  3. points[i].length == 2
  4. +
  5. 0 <= points[i][j] <= 100
  6. +
+ +
+
 
+