Skip to content

Commit 019bfab

Browse files
author
Openset
committed
Add: new
1 parent 96a23a5 commit 019bfab

File tree

5 files changed

+253
-0
lines changed

5 files changed

+253
-0
lines changed

Diff for: README.md

+4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ LeetCode Problems' Solutions
5353

5454
| # | Title | Solution | Difficulty |
5555
| :-: | - | - | :-: |
56+
| <span id="972">972</span> | [Equal Rational Numbers](https://leetcode.com/problems/equal-rational-numbers "相等的有理数") | [Go](https://github.com/openset/leetcode/tree/master/problems/equal-rational-numbers) | Hard |
57+
| <span id="971">971</span> | [Flip Binary Tree To Match Preorder Traversal](https://leetcode.com/problems/flip-binary-tree-to-match-preorder-traversal "翻转二叉树以匹配先序遍历") | [Go](https://github.com/openset/leetcode/tree/master/problems/flip-binary-tree-to-match-preorder-traversal) | Medium |
58+
| <span id="970">970</span> | [Powerful Integers](https://leetcode.com/problems/powerful-integers "强整数") | [Go](https://github.com/openset/leetcode/tree/master/problems/powerful-integers) | Easy |
59+
| <span id="969">969</span> | [Pancake Sorting](https://leetcode.com/problems/pancake-sorting "煎饼排序") | [Go](https://github.com/openset/leetcode/tree/master/problems/pancake-sorting) | Medium |
5660
| <span id="968">968</span> | [Binary Tree Cameras](https://leetcode.com/problems/binary-tree-cameras "监控二叉树") | [Go](https://github.com/openset/leetcode/tree/master/problems/binary-tree-cameras) | Hard |
5761
| <span id="967">967</span> | [Numbers With Same Consecutive Differences](https://leetcode.com/problems/numbers-with-same-consecutive-differences "连续差相同的数字") | [Go](https://github.com/openset/leetcode/tree/master/problems/numbers-with-same-consecutive-differences) | Medium |
5862
| <span id="966">966</span> | [Vowel Spellchecker](https://leetcode.com/problems/vowel-spellchecker "元音拼写检查器") | [Go](https://github.com/openset/leetcode/tree/master/problems/vowel-spellchecker) | Medium |

Diff for: problems/equal-rational-numbers/README.md

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author Openset <[email protected]> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
## 972. Equal Rational Numbers (Hard)
9+
10+
<p>Given two strings <code>S</code> and <code>T</code>, each of which represents a non-negative rational number, return <strong>True</strong> if and only if they represent the same number. The strings may use parentheses to denote the repeating part of the rational number.</p>
11+
12+
<p>In general a rational number can be represented using up to&nbsp;three parts: an&nbsp;<em>integer part</em>, a&nbsp;<em>non-repeating part,</em> and a&nbsp;<em>repeating part</em>. The number will be represented&nbsp;in one of the following three ways:</p>
13+
14+
<ul>
15+
<li><code>&lt;IntegerPart&gt;</code> (e.g. 0, 12, 123)</li>
16+
<li><code>&lt;IntegerPart&gt;&lt;.&gt;&lt;NonRepeatingPart&gt;</code> &nbsp;(e.g. 0.5, 1., 2.12, 2.0001)</li>
17+
<li><code>&lt;IntegerPart&gt;&lt;.&gt;&lt;NonRepeatingPart&gt;&lt;(&gt;&lt;RepeatingPart&gt;&lt;)&gt;</code> (e.g. 0.1(6), 0.9(9), 0.00(1212))</li>
18+
</ul>
19+
20+
<p>The repeating portion of a decimal expansion is conventionally denoted within a pair of round brackets.&nbsp; For example:</p>
21+
22+
<p>1 / 6 = 0.16666666... = 0.1(6) = 0.1666(6) = 0.166(66)</p>
23+
24+
<p>Both 0.1(6) or 0.1666(6) or 0.166(66) are correct representations of 1 / 6.</p>
25+
26+
<p>&nbsp;</p>
27+
28+
<p><strong>Example 1:</strong></p>
29+
30+
<pre>
31+
<strong>Input: </strong>S = <span id="example-input-1-1">&quot;0.(52)&quot;</span>, T = <span id="example-input-1-2">&quot;0.5(25)&quot;</span>
32+
<strong>Output: </strong><span id="example-output-1">true</span>
33+
<strong>Explanation:
34+
</strong>Because &quot;0.(52)&quot; represents 0.52525252..., and &quot;0.5(25)&quot; represents 0.52525252525..... , the strings represent the same number.
35+
</pre>
36+
37+
<div>
38+
<p><strong>Example 2:</strong></p>
39+
40+
<pre>
41+
<strong>Input: </strong>S = <span id="example-input-2-1">&quot;0.1666(6)&quot;</span>, T = <span id="example-input-2-2">&quot;0.166(66)&quot;</span>
42+
<strong>Output: </strong><span id="example-output-2">true</span>
43+
</pre>
44+
45+
<div>
46+
<p><strong>Example 3:</strong></p>
47+
48+
<pre>
49+
<strong>Input: </strong>S = <span id="example-input-3-1">&quot;0.9(9)&quot;</span>, T = <span id="example-input-3-2">&quot;1.&quot;</span>
50+
<strong>Output: </strong><span id="example-output-3">true</span>
51+
<strong>Explanation: </strong>
52+
&quot;0.9(9)&quot; represents 0.999999999... repeated forever, which equals 1. [<a href="https://en.wikipedia.org/wiki/0.999..." target="_blank">See this link for an explanation.</a>]
53+
&quot;1.&quot; represents the number 1, which is formed correctly: (IntegerPart) = &quot;1&quot; and (NonRepeatingPart) = &quot;&quot;.</pre>
54+
55+
<p>&nbsp;</p>
56+
</div>
57+
</div>
58+
59+
<p><strong>Note:</strong></p>
60+
61+
<ol>
62+
<li>Each part consists only of digits.</li>
63+
<li>The <code>&lt;IntegerPart&gt;</code>&nbsp;will&nbsp;not begin with 2 or more zeros.&nbsp; (There is no other restriction on the digits of each part.)</li>
64+
<li><code>1 &lt;= &lt;IntegerPart&gt;.length &lt;= 4 </code></li>
65+
<li><code>0 &lt;= &lt;NonRepeatingPart&gt;.length &lt;= 4 </code></li>
66+
<li><code>1 &lt;= &lt;RepeatingPart&gt;.length &lt;= 4</code></li>
67+
</ol>
68+
69+
70+
### Related Topics
71+
[[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author Openset <[email protected]> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
## 971. Flip Binary Tree To Match Preorder Traversal (Medium)
9+
10+
<p>Given a binary tree with <code>N</code> nodes, each node has a different value from&nbsp;<code>{1, ..., N}</code>.</p>
11+
12+
<p>A node in this binary tree can be <em>flipped</em>&nbsp;by swapping the left child and the right child of that node.</p>
13+
14+
<p>Consider the sequence of&nbsp;<code>N</code> values reported by a preorder traversal starting from the root.&nbsp; Call such a sequence of <code>N</code> values the&nbsp;<em>voyage</em>&nbsp;of the tree.</p>
15+
16+
<p>(Recall that a <em>preorder traversal</em>&nbsp;of a node means we report the current node&#39;s value, then preorder-traverse the left child, then preorder-traverse the right child.)</p>
17+
18+
<p>Our goal is to flip the <strong>least number</strong> of nodes in the tree so that the voyage of the tree matches the <code>voyage</code> we are given.</p>
19+
20+
<p>If we can do so, then return a&nbsp;list&nbsp;of the values of all nodes flipped.&nbsp; You may return the answer in any order.</p>
21+
22+
<p>If we cannot do so, then return the list <code>[-1]</code>.</p>
23+
24+
<p>&nbsp;</p>
25+
26+
<div>
27+
<p><strong>Example 1:</strong></p>
28+
29+
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2019/01/02/1219-01.png" style="width: 88px; height: 120px;" /></strong></p>
30+
31+
<pre>
32+
<strong>Input: </strong>root = <span id="example-input-1-1">[1,2]</span>, voyage = <span id="example-input-1-2">[2,1]</span>
33+
<strong>Output: </strong><span id="example-output-1">[-1]</span>
34+
</pre>
35+
36+
<div>
37+
<p><strong>Example 2:</strong></p>
38+
39+
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2019/01/02/1219-02.png" style="width: 127px; height: 120px;" /></strong></p>
40+
41+
<pre>
42+
<strong>Input: </strong>root = <span id="example-input-2-1">[1,2,3]</span>, voyage = <span id="example-input-2-2">[1,3,2]</span>
43+
<strong>Output: </strong><span id="example-output-2">[1]</span>
44+
</pre>
45+
46+
<div>
47+
<p><strong>Example 3:</strong></p>
48+
49+
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2019/01/02/1219-02.png" style="width: 127px; height: 120px;" /></strong></p>
50+
51+
<pre>
52+
<strong>Input: </strong>root = <span id="example-input-3-1">[1,2,3]</span>, voyage = <span id="example-input-3-2">[1,2,3]</span>
53+
<strong>Output: </strong><span id="example-output-3">[]</span>
54+
</pre>
55+
56+
<p>&nbsp;</p>
57+
58+
<p><strong><span>Note:</span></strong></p>
59+
60+
<ol>
61+
<li><code>1 &lt;= N &lt;= 100</code></li>
62+
</ol>
63+
</div>
64+
</div>
65+
</div>
66+
67+
### Related Topics
68+
[[Tree](https://github.com/openset/leetcode/tree/master/tag/tree/README.md)]
69+
[[Depth-first Search](https://github.com/openset/leetcode/tree/master/tag/depth-first-search/README.md)]

Diff for: problems/pancake-sorting/README.md

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author Openset <[email protected]> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
## 969. Pancake Sorting (Medium)
9+
10+
<p>Given an array <code>A</code>, we can perform a&nbsp;<em>pancake flip</em>:&nbsp;We choose some positive integer&nbsp;<code><strong>k</strong> &lt;= A.length</code>, then reverse the order of the first <strong>k</strong> elements of <code>A</code>.&nbsp; We want to perform zero or more pancake flips (doing them one after another in succession) to sort the array <code>A</code>.</p>
11+
12+
<p>Return the k-values corresponding to a sequence of pancake flips that sort <code>A</code>.&nbsp; Any&nbsp;valid answer that sorts the array within <code>10 * A.length</code> flips will be judged as correct.</p>
13+
14+
<p>&nbsp;</p>
15+
16+
<p><strong>Example 1:</strong></p>
17+
18+
<pre>
19+
<strong>Input: </strong><span id="example-input-1-1">[3,2,4,1]</span>
20+
<strong>Output: </strong><span id="example-output-1">[4,2,4,3]</span>
21+
<strong>Explanation: </strong>
22+
We perform 4 pancake flips, with k values 4, 2, 4, and 3.
23+
Starting state: A = [3, 2, 4, 1]
24+
After 1st flip (k=4): A = [1, 4, 2, 3]
25+
After 2nd flip (k=2): A = [4, 1, 2, 3]
26+
After 3rd flip (k=4): A = [3, 2, 1, 4]
27+
After 4th flip (k=3): A = [1, 2, 3, 4], which is sorted.
28+
</pre>
29+
30+
<div>
31+
<p><strong>Example 2:</strong></p>
32+
33+
<pre>
34+
<strong>Input: </strong><span id="example-input-2-1">[1,2,3]</span>
35+
<strong>Output: </strong><span id="example-output-2">[]</span>
36+
<strong>Explanation: </strong>The input is already sorted, so there is no need to flip anything.
37+
Note that other answers, such as [3, 3], would also be accepted.
38+
</pre>
39+
40+
<p>&nbsp;</p>
41+
</div>
42+
43+
<p><strong>Note:</strong></p>
44+
45+
<ol>
46+
<li><code>1 &lt;= A.length &lt;= 100</code></li>
47+
<li><code>A[i]</code> is a permutation of <code>[1, 2, ..., A.length]</code></li>
48+
</ol>
49+
50+
51+
### Related Topics
52+
[[Sort](https://github.com/openset/leetcode/tree/master/tag/sort/README.md)]
53+
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]

Diff for: problems/powerful-integers/README.md

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author Openset <[email protected]> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
## 970. Powerful Integers (Easy)
9+
10+
<p>Given two non-negative integers <code>x</code> and <code>y</code>, an integer is <em>powerful</em>&nbsp;if it is equal to <code>x^i + y^j</code>&nbsp;for&nbsp;some integers <code>i &gt;= 0</code> and <code>j &gt;= 0</code>.</p>
11+
12+
<p>Return a list of all <em>powerful</em> integers that have value less than or equal to <code>bound</code>.</p>
13+
14+
<p>You may return the answer in any order.&nbsp; In your answer, each value should occur at most once.</p>
15+
16+
<p>&nbsp;</p>
17+
18+
<div>
19+
<p><strong>Example 1:</strong></p>
20+
21+
<pre>
22+
<strong>Input: </strong>x = <span id="example-input-1-1">2</span>, y = <span id="example-input-1-2">3</span>, bound = <span id="example-input-1-3">10</span>
23+
<strong>Output: </strong><span id="example-output-1">[2,3,4,5,7,9,10]</span>
24+
<strong>Explanation: </strong>
25+
2 = 2^0 + 3^0
26+
3 = 2^1 + 3^0
27+
4 = 2^0 + 3^1
28+
5 = 2^1 + 3^1
29+
7 = 2^2 + 3^1
30+
9 = 2^3 + 3^0
31+
10 = 2^0 + 3^2
32+
</pre>
33+
34+
<div>
35+
<p><strong>Example 2:</strong></p>
36+
37+
<pre>
38+
<strong>Input: </strong>x = <span id="example-input-2-1">3</span>, y = <span id="example-input-2-2">5</span>, bound = <span id="example-input-2-3">15</span>
39+
<strong>Output: </strong><span id="example-output-2">[2,4,6,8,10,14]</span>
40+
</pre>
41+
</div>
42+
</div>
43+
44+
<p>&nbsp;</p>
45+
46+
<p><strong>Note:</strong></p>
47+
48+
<ul>
49+
<li><code>1 &lt;= x &lt;= 100</code></li>
50+
<li><code>1 &lt;= y&nbsp;&lt;= 100</code></li>
51+
<li><code>0 &lt;= bound&nbsp;&lt;= 10^6</code></li>
52+
</ul>
53+
54+
55+
### Related Topics
56+
[[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)]

0 commit comments

Comments
 (0)