Skip to content

Commit 82caaf3

Browse files
author
Shuo
authored
Merge pull request #508 from openset/develop
Add: new
2 parents a76fdc3 + d9246ed commit 82caaf3

File tree

6 files changed

+238
-2
lines changed

6 files changed

+238
-2
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ LeetCode Problems' Solutions
5454

5555
| # | Title | Solution | Difficulty |
5656
| :-: | - | - | :-: |
57+
| <span id="1040">1040</span> | [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 |
58+
| <span id="1039">1039</span> | [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 |
59+
| <span id="1038">1038</span> | [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 |
60+
| <span id="1037">1037</span> | [Valid Boomerang](https://leetcode.com/problems/valid-boomerang "有效的回旋镖") | [Go](https://github.com/openset/leetcode/tree/master/problems/valid-boomerang) | Easy |
5761
| <span id="1036">1036</span> | [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 |
5862
| <span id="1035">1035</span> | [Uncrossed Lines](https://leetcode.com/problems/uncrossed-lines "不相交的线") | [Go](https://github.com/openset/leetcode/tree/master/problems/uncrossed-lines) | Medium |
5963
| <span id="1034">1034</span> | [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
456460
| <span id="637">637</span> | [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 |
457461
| <span id="636">636</span> | [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 |
458462
| <span id="635">635</span> | [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 |
459-
| <span id="634">634</span> | [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 |
463+
| <span id="634">634</span> | [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 |
460464
| <span id="633">633</span> | [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 |
461465
| <span id="632">632</span> | [Smallest Range](https://leetcode.com/problems/smallest-range "最小区间") | [Go](https://github.com/openset/leetcode/tree/master/problems/smallest-range) | Hard |
462466
| <span id="631">631</span> | [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 |
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author Openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](https://github.com/openset/leetcode/tree/master/problems/valid-boomerang "Valid Boomerang")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/minimum-score-triangulation-of-polygon "Minimum Score Triangulation of Polygon")
11+
12+
## 5050. Binary Search Tree to Greater Sum Tree (Medium)
13+
14+
<p>Given the root of a binary <strong>search</strong> tree with distinct values, modify it so that every <code>node</code>&nbsp;has a new value equal to the sum of the values of the original tree that are greater than or equal to <code>node.val</code>.</p>
15+
16+
<p>As a reminder, a&nbsp;<em>binary search tree</em> is a tree that satisfies these constraints:</p>
17+
18+
<ul>
19+
<li>The left subtree of a node contains only nodes with keys&nbsp;<strong>less than</strong>&nbsp;the node&#39;s key.</li>
20+
<li>The right subtree of a node contains only nodes with keys&nbsp;<strong>greater than</strong>&nbsp;the node&#39;s key.</li>
21+
<li>Both the left and right subtrees must also be binary search trees.</li>
22+
</ul>
23+
24+
<p>&nbsp;</p>
25+
26+
<p><strong>Example 1:</strong></p>
27+
28+
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2019/05/02/tree.png" style="width: 280px; height: 191px;" /></strong></p>
29+
30+
<pre>
31+
<strong>Input: </strong><span id="example-input-1-1">[4,1,6,0,2,5,7,null,null,null,3,null,null,null,8]</span>
32+
<strong>Output: </strong><span id="example-output-1">[30,36,21,36,35,26,15,null,null,null,33,null,null,null,8]</span>
33+
</pre>
34+
35+
<div>
36+
<p>&nbsp;</p>
37+
</div>
38+
39+
<p><strong>Note:</strong></p>
40+
41+
<ol>
42+
<li>The number of nodes in the tree is between <code>1</code> and <code>100</code>.</li>
43+
<li>Each node will have value between <code>0</code> and <code>100</code>.</li>
44+
<li>The given tree is a binary search tree.</li>
45+
</ol>
46+
47+
<div>
48+
<div>
49+
<div>&nbsp;</div>
50+
</div>
51+
</div>

problems/escape-a-large-maze/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
[< Previous](https://github.com/openset/leetcode/tree/master/problems/uncrossed-lines "Uncrossed Lines")
99

10-
Next >
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/valid-boomerang "Valid Boomerang")
1111

1212
## 1036. Escape a Large Maze (Hard)
1313

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author Openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](https://github.com/openset/leetcode/tree/master/problems/binary-search-tree-to-greater-sum-tree "Binary Search Tree to Greater Sum Tree")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/moving-stones-until-consecutive-ii "Moving Stones Until Consecutive II")
11+
12+
## 5047. Minimum Score Triangulation of Polygon (Medium)
13+
14+
<p>Given <code>N</code>, consider a convex <code>N</code>-sided polygon with vertices labelled <code>A[0], A[i], ..., A[N-1]</code>&nbsp;in clockwise order.</p>
15+
16+
<p>Suppose you triangulate the polygon into <code>N-2</code> triangles.&nbsp; For each triangle, the value of that triangle is the <strong>product</strong>&nbsp;of the labels of the vertices, and the <em>total score</em> of the triangulation is the sum of these values over all <code>N-2</code> triangles in the triangulation.</p>
17+
18+
<p>Return the smallest possible total score that you can achieve with some triangulation of the polygon.</p>
19+
20+
<p>&nbsp;</p>
21+
22+
<ol>
23+
</ol>
24+
25+
<div>
26+
<p><strong>Example 1:</strong></p>
27+
28+
<pre>
29+
<strong>Input: </strong><span id="example-input-1-1">[1,2,3]</span>
30+
<strong>Output: </strong><span id="example-output-1">6</span>
31+
<strong>Explanation: </strong>The polygon is already triangulated, and the score of the only triangle is 6.
32+
</pre>
33+
34+
<div>
35+
<p><strong>Example 2:</strong></p>
36+
37+
<p><img alt="" src="https://assets.leetcode.com/uploads/2019/05/01/minimum-score-triangulation-of-polygon-1.png" style="width: 253px; height: 150px;" /></p>
38+
39+
<pre>
40+
<strong>Input: </strong><span id="example-input-2-1">[3,7,4,5]</span>
41+
<strong>Output: </strong><span id="example-output-2">144</span>
42+
<strong>Explanation: </strong>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.
43+
</pre>
44+
45+
<div>
46+
<p><strong>Example 3:</strong></p>
47+
48+
<pre>
49+
<strong>Input: </strong><span id="example-input-3-1">[1,3,1,4,1,5]</span>
50+
<strong>Output: </strong><span id="example-output-3">13</span>
51+
<strong>Explanation: </strong>The minimum score triangulation has score 1*1*3 + 1*1*4 + 1*1*5 + 1*1*1 = 13.
52+
</pre>
53+
54+
<p>&nbsp;</p>
55+
56+
<p><strong>Note:</strong></p>
57+
58+
<ol>
59+
<li><code>3 &lt;= A.length &lt;= 50</code></li>
60+
<li><code>1 &lt;= A[i] &lt;= 100</code></li>
61+
</ol>
62+
</div>
63+
</div>
64+
</div>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author Openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](https://github.com/openset/leetcode/tree/master/problems/minimum-score-triangulation-of-polygon "Minimum Score Triangulation of Polygon")
9+
                
10+
Next >
11+
12+
## 5049. Moving Stones Until Consecutive II (Medium)
13+
14+
<p>On an <strong>infinite</strong> number line, the position of the i-th stone is given by&nbsp;<code>stones[i]</code>.&nbsp; Call a stone an <em>endpoint stone</em> if it has the smallest or largest position.</p>
15+
16+
<p>Each turn, you pick up an endpoint stone and move it to an unoccupied position so that it is no longer an endpoint stone.</p>
17+
18+
<p>In particular,&nbsp;if the stones are at say, <code>stones = [1,2,5]</code>, you <strong>cannot</strong> 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.</p>
19+
20+
<p>The game ends when you cannot make any more moves, ie. the stones are in consecutive positions.</p>
21+
22+
<p>When the game ends, what is the minimum and maximum number of moves that you could have made?&nbsp; Return the answer as an length 2 array:&nbsp;<code>answer = [minimum_moves, maximum_moves]</code></p>
23+
24+
<p>&nbsp;</p>
25+
26+
<p><strong>Example 1:</strong></p>
27+
28+
<pre>
29+
<strong>Input: </strong><span id="example-input-1-1">[7,4,9]</span>
30+
<strong>Output: </strong><span id="example-output-1">[1,2]</span>
31+
<strong>Explanation: </strong>
32+
We can move 4 -&gt; 8 for one move to finish the game.
33+
Or, we can move 9 -&gt; 5, 4 -&gt; 6 for two moves to finish the game.
34+
</pre>
35+
36+
<div>
37+
<p><strong>Example 2:</strong></p>
38+
39+
<pre>
40+
<strong>Input: </strong><span id="example-input-2-1">[6,5,4,3,10]</span>
41+
<strong>Output: </strong><span id="example-output-2">[2,3]</span>
42+
We can move 3 -&gt; 8 then 10 -&gt; 7 to finish the game.
43+
Or, we can move 3 -&gt; 7, 4 -&gt; 8, 5 -&gt; 9 to finish the game.
44+
Notice we cannot move 10 -&gt; 2 to finish the game, because that would be an illegal move.
45+
</pre>
46+
47+
<div>
48+
<p><strong>Example 3:</strong></p>
49+
50+
<pre>
51+
<strong>Input: </strong><span id="example-input-3-1">[100,101,104,102,103]</span>
52+
<strong>Output: </strong><span id="example-output-3">[0,0]</span></pre>
53+
54+
<p>&nbsp;</p>
55+
</div>
56+
</div>
57+
58+
<p><strong>Note:</strong></p>
59+
60+
<ol>
61+
<li><code>3 &lt;= stones.length &lt;= 10^4</code></li>
62+
<li><code>1 &lt;= stones[i] &lt;= 10^9</code></li>
63+
<li><code>stones[i]</code> have distinct values.</li>
64+
</ol>
65+
66+
<div>
67+
<div>
68+
<div>&nbsp;</div>
69+
</div>
70+
</div>

problems/valid-boomerang/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author Openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](https://github.com/openset/leetcode/tree/master/problems/escape-a-large-maze "Escape a Large Maze")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/binary-search-tree-to-greater-sum-tree "Binary Search Tree to Greater Sum Tree")
11+
12+
## 5051. Valid Boomerang (Easy)
13+
14+
<p>A <em>boomerang</em> is a set of 3 points that are all distinct and <strong>not</strong> in a straight line.</p>
15+
16+
<p>Given a list&nbsp;of three points in the plane, return whether these points are a boomerang.</p>
17+
18+
<p>&nbsp;</p>
19+
20+
<p><strong>Example 1:</strong></p>
21+
22+
<pre>
23+
<strong>Input: </strong><span id="example-input-1-1">[[1,1],[2,3],[3,2]]</span>
24+
<strong>Output: </strong><span id="example-output-1">true</span>
25+
</pre>
26+
27+
<div>
28+
<p><strong>Example 2:</strong></p>
29+
30+
<pre>
31+
<strong>Input: </strong><span id="example-input-2-1">[[1,1],[2,2],[3,3]]</span>
32+
<strong>Output: </strong><span id="example-output-2">false</span></pre>
33+
</div>
34+
35+
<p>&nbsp;</p>
36+
37+
<p><strong>Note:</strong></p>
38+
39+
<ol>
40+
<li><code>points.length == 3</code></li>
41+
<li><code>points[i].length == 2</code></li>
42+
<li><code>0 &lt;= points[i][j] &lt;= 100</code></li>
43+
</ol>
44+
45+
<div>
46+
<div>&nbsp;</div>
47+
</div>

0 commit comments

Comments
 (0)