Skip to content

Commit ce6b544

Browse files
author
Shuo
committed
A:new
1 parent caa9a98 commit ce6b544

File tree

783 files changed

+10343
-5686
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

783 files changed

+10343
-5686
lines changed

README.md

+169-372
Large diffs are not rendered by default.

problems/01-matrix/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
22
<!--+----------------------------------------------------------------------+-->
3-
<!--|@author openset <[email protected]> |-->
4-
<!--|@link https://github.com/openset |-->
5-
<!--|@home https://github.com/openset/leetcode |-->
3+
<!--|@author awesee <[email protected]> |-->
4+
<!--|@link https://github.com/awesee |-->
5+
<!--|@home https://github.com/awesee/leetcode |-->
66
<!--+----------------------------------------------------------------------+-->
77

88
[< Previous](../reverse-string-ii "Reverse String II")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author awesee <[email protected]> |-->
4+
<!--|@link https://github.com/awesee |-->
5+
<!--|@home https://github.com/awesee/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../build-the-equation "Build the Equation")
9+
                
10+
[Next >](../execution-of-all-suffix-instructions-staying-in-a-grid "Execution of All Suffix Instructions Staying in a Grid")
11+
12+
## [2119. A Number After a Double Reversal (Easy)](https://leetcode.com/problems/a-number-after-a-double-reversal "反转两次的数字")
13+
14+
<p><strong>Reversing</strong> an integer means to reverse all its digits.</p>
15+
16+
<ul>
17+
<li>For example, reversing <code>2021</code> gives <code>1202</code>. Reversing <code>12300</code> gives <code>321</code> as the <strong>leading zeros are not retained</strong>.</li>
18+
</ul>
19+
20+
<p>Given an integer <code>num</code>, <strong>reverse</strong> <code>num</code> to get <code>reversed1</code>, <strong>then reverse</strong> <code>reversed1</code> to get <code>reversed2</code>. Return <code>true</code> <em>if</em> <code>reversed2</code> <em>equals</em> <code>num</code>. Otherwise return <code>false</code>.</p>
21+
22+
<p>&nbsp;</p>
23+
<p><strong>Example 1:</strong></p>
24+
25+
<pre>
26+
<strong>Input:</strong> num = 526
27+
<strong>Output:</strong> true
28+
<strong>Explanation:</strong> Reverse num to get 625, then reverse 625 to get 526, which equals num.
29+
</pre>
30+
31+
<p><strong>Example 2:</strong></p>
32+
33+
<pre>
34+
<strong>Input:</strong> num = 1800
35+
<strong>Output:</strong> false
36+
<strong>Explanation:</strong> Reverse num to get 81, then reverse 81 to get 18, which does not equal num.
37+
</pre>
38+
39+
<p><strong>Example 3:</strong></p>
40+
41+
<pre>
42+
<strong>Input:</strong> num = 0
43+
<strong>Output:</strong> true
44+
<strong>Explanation:</strong> Reverse num to get 0, then reverse 0 to get 0, which equals num.
45+
</pre>
46+
47+
<p>&nbsp;</p>
48+
<p><strong>Constraints:</strong></p>
49+
50+
<ul>
51+
<li><code>0 &lt;= num &lt;= 10<sup>6</sup></code></li>
52+
</ul>
53+
54+
### Related Topics
55+
[[Math](../../tag/math/README.md)]
56+
57+
### Hints
58+
<details>
59+
<summary>Hint 1</summary>
60+
Other than the number 0 itself, any number that ends with 0 would lose some digits permanently when reversed.
61+
</details>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author awesee <[email protected]> |-->
4+
<!--|@link https://github.com/awesee |-->
5+
<!--|@home https://github.com/awesee/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../check-if-a-parentheses-string-can-be-valid "Check if a Parentheses String Can Be Valid")
9+
                
10+
[Next >](../build-the-equation "Build the Equation")
11+
12+
## [2117. Abbreviating the Product of a Range (Hard)](https://leetcode.com/problems/abbreviating-the-product-of-a-range "一个区间内所有数乘积的缩写")
13+
14+
<p>You are given two positive integers <code>left</code> and <code>right</code> with <code>left &lt;= right</code>. Calculate the <strong>product</strong> of all integers in the <strong>inclusive</strong> range <code>[left, right]</code>.</p>
15+
16+
<p>Since the product may be very large, you will <strong>abbreviate</strong> it following these steps:</p>
17+
18+
<ol>
19+
<li>Count all <strong>trailing</strong> zeros in the product and <strong>remove</strong> them. Let us denote this count as <code>C</code>.
20+
<ul>
21+
<li>For example, there are <code>3</code> trailing zeros in <code>1000</code>, and there are <code>0</code> trailing zeros in <code>546</code>.</li>
22+
</ul>
23+
</li>
24+
<li>Denote the remaining number of digits in the product as <code>d</code>. If <code>d &gt; 10</code>, then express the product as <code>&lt;pre&gt;...&lt;suf&gt;</code> where <code>&lt;pre&gt;</code> denotes the <strong>first</strong> <code>5</code> digits of the product, and <code>&lt;suf&gt;</code> denotes the <strong>last</strong> <code>5</code> digits of the product <strong>after</strong> removing all trailing zeros. If <code>d &lt;= 10</code>, we keep it unchanged.
25+
<ul>
26+
<li>For example, we express <code>1234567654321</code> as <code>12345...54321</code>, but <code>1234567</code> is represented as <code>1234567</code>.</li>
27+
</ul>
28+
</li>
29+
<li>Finally, represent the product as a <strong>string</strong> <code>&quot;&lt;pre&gt;...&lt;suf&gt;eC&quot;</code>.
30+
<ul>
31+
<li>For example, <code>12345678987600000</code> will be represented as <code>&quot;12345...89876e5&quot;</code>.</li>
32+
</ul>
33+
</li>
34+
</ol>
35+
36+
<p>Return <em>a string denoting the <strong>abbreviated product</strong> of all integers in the <strong>inclusive</strong> range</em> <code>[left, right]</code>.</p>
37+
38+
<p>&nbsp;</p>
39+
<p><strong>Example 1:</strong></p>
40+
41+
<pre>
42+
<strong>Input:</strong> left = 1, right = 4
43+
<strong>Output:</strong> &quot;24e0&quot;
44+
<strong>Explanation:</strong> The product is 1 &times; 2 &times; 3 &times; 4 = 24.
45+
There are no trailing zeros, so 24 remains the same. The abbreviation will end with &quot;e0&quot;.
46+
Since the number of digits is 2, which is less than 10, we do not have to abbreviate it further.
47+
Thus, the final representation is &quot;24e0&quot;.
48+
</pre>
49+
50+
<p><strong>Example 2:</strong></p>
51+
52+
<pre>
53+
<strong>Input:</strong> left = 2, right = 11
54+
<strong>Output:</strong> &quot;399168e2&quot;
55+
<strong>Explanation:</strong> The product is 39916800.
56+
There are 2 trailing zeros, which we remove to get 399168. The abbreviation will end with &quot;e2&quot;.
57+
The number of digits after removing the trailing zeros is 6, so we do not abbreviate it further.
58+
Hence, the abbreviated product is &quot;399168e2&quot;.
59+
</pre>
60+
61+
<p><strong>Example 3:</strong></p>
62+
63+
<pre>
64+
<strong>Input:</strong> left = 371, right = 375
65+
<strong>Output:</strong> &quot;7219856259e3&quot;
66+
<strong>Explanation:</strong> The product is 7219856259000.
67+
</pre>
68+
69+
<p>&nbsp;</p>
70+
<p><strong>Constraints:</strong></p>
71+
72+
<ul>
73+
<li><code>1 &lt;= left &lt;= right &lt;= 10<sup>4</sup></code></li>
74+
</ul>
75+
76+
### Related Topics
77+
[[Math](../../tag/math/README.md)]
78+
79+
### Hints
80+
<details>
81+
<summary>Hint 1</summary>
82+
Calculating the number of trailing zeros, the last five digits, and the first five digits can all be done separately.
83+
</details>
84+
85+
<details>
86+
<summary>Hint 2</summary>
87+
Use a prime factorization property to find the number of trailing zeros. Use modulo to find the last 5 digits. Use a logarithm property to find the first 5 digits.
88+
</details>
89+
90+
<details>
91+
<summary>Hint 3</summary>
92+
The number of trailing zeros C is nothing but the number of times the product is completely divisible by 10. Since 2 and 5 are the only prime factors of 10, C will be equal to the minimum number of times 2 or 5 appear in the prime factorization of the product.
93+
</details>
94+
95+
<details>
96+
<summary>Hint 4</summary>
97+
Iterate through the integers from left to right. For every integer, keep dividing it by 2 as long as it is divisible by 2 and C occurrences of 2 haven't been removed in total. Repeat this process for 5. Finally, multiply the integer under modulo of 10^5 with the product obtained till now to obtain the last five digits.
98+
</details>
99+
100+
<details>
101+
<summary>Hint 5</summary>
102+
The product P can be represented as P=10^(x+y) where x is the integral part and y is the fractional part of x+y. Using the property "if S = A * B, then log(S) = log(A) + log(B)", we can write x+y = log_10(P) = sum(log_10(i)) for each integer i in [left, right]. Once we obtain the sum, the first five digits can be represented as floor(10^(y+4)).
103+
</details>

problems/accepted-candidates-from-the-interviews/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
[Next >](../check-if-numbers-are-ascending-in-a-sentence "Check if Numbers Are Ascending in a Sentence")
1111

12-
## [2041. Accepted Candidates From the Interviews (Medium)](https://leetcode.com/problems/accepted-candidates-from-the-interviews "")
12+
## [2041. Accepted Candidates From the Interviews (Medium)](https://leetcode.com/problems/accepted-candidates-from-the-interviews "面试中被录取的候选人")
1313

1414

1515

problems/account-balance/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
[Next >](../number-of-equal-count-substrings "Number of Equal Count Substrings")
1111

12-
## [2066. Account Balance (Medium)](https://leetcode.com/problems/account-balance "")
12+
## [2066. Account Balance (Medium)](https://leetcode.com/problems/account-balance "账户余额")
1313

1414

1515

problems/active-users/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
22
<!--+----------------------------------------------------------------------+-->
3-
<!--|@author openset <[email protected]> |-->
4-
<!--|@link https://github.com/openset |-->
5-
<!--|@home https://github.com/openset/leetcode |-->
3+
<!--|@author awesee <[email protected]> |-->
4+
<!--|@link https://github.com/awesee |-->
5+
<!--|@home https://github.com/awesee/leetcode |-->
66
<!--+----------------------------------------------------------------------+-->
77

88
[< Previous](../maximum-number-of-darts-inside-of-a-circular-dartboard "Maximum Number of Darts Inside of a Circular Dartboard")

problems/add-minimum-number-of-rungs/README.md

+4-9
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,6 @@ Add a rung at height 1 to climb this ladder.
4949
The ladder will now have rungs at [<u>1</u>,3,4,6,7].
5050
</pre>
5151

52-
<p><strong>Example 4:</strong></p>
53-
54-
<pre>
55-
<strong>Input:</strong> rungs = [5], dist = 10
56-
<strong>Output:</strong> 0
57-
<strong>Explanation:</strong>
58-
This ladder can be climbed without adding additional rungs.
59-
</pre>
60-
6152
<p>&nbsp;</p>
6253
<p><strong>Constraints:</strong></p>
6354

@@ -68,6 +59,10 @@ This ladder can be climbed without adding additional rungs.
6859
<li><code>rungs</code> is <strong>strictly increasing</strong>.</li>
6960
</ul>
7061

62+
### Related Topics
63+
[[Greedy](../../tag/greedy/README.md)]
64+
[[Array](../../tag/array/README.md)]
65+
7166
### Hints
7267
<details>
7368
<summary>Hint 1</summary>

problems/add-two-numbers/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
22
<!--+----------------------------------------------------------------------+-->
3-
<!--|@author openset <[email protected]> |-->
4-
<!--|@link https://github.com/openset |-->
5-
<!--|@home https://github.com/openset/leetcode |-->
3+
<!--|@author awesee <[email protected]> |-->
4+
<!--|@link https://github.com/awesee |-->
5+
<!--|@home https://github.com/awesee/leetcode |-->
66
<!--+----------------------------------------------------------------------+-->
77

88
[< Previous](../two-sum "Two Sum")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author awesee <[email protected]> |-->
4+
<!--|@link https://github.com/awesee |-->
5+
<!--|@home https://github.com/awesee/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../find-first-palindromic-string-in-the-array "Find First Palindromic String in the Array")
9+
                
10+
[Next >](../number-of-smooth-descent-periods-of-a-stock "Number of Smooth Descent Periods of a Stock")
11+
12+
## [2109. Adding Spaces to a String (Medium)](https://leetcode.com/problems/adding-spaces-to-a-string "向字符串添加空格")
13+
14+
<p>You are given a <strong>0-indexed</strong> string <code>s</code> and a <strong>0-indexed</strong> integer array <code>spaces</code> that describes the indices in the original string where spaces will be added. Each space should be inserted <strong>before</strong> the character at the given index.</p>
15+
16+
<ul>
17+
<li>For example, given <code>s = &quot;EnjoyYourCoffee&quot;</code> and <code>spaces = [5, 9]</code>, we place spaces before <code>&#39;Y&#39;</code> and <code>&#39;C&#39;</code>, which are at indices <code>5</code> and <code>9</code> respectively. Thus, we obtain <code>&quot;Enjoy <strong><u>Y</u></strong>our <u><strong>C</strong></u>offee&quot;</code>.</li>
18+
</ul>
19+
20+
<p>Return<strong> </strong><em>the modified string <strong>after</strong> the spaces have been added.</em></p>
21+
22+
<p>&nbsp;</p>
23+
<p><strong>Example 1:</strong></p>
24+
25+
<pre>
26+
<strong>Input:</strong> s = &quot;LeetcodeHelpsMeLearn&quot;, spaces = [8,13,15]
27+
<strong>Output:</strong> &quot;Leetcode Helps Me Learn&quot;
28+
<strong>Explanation:</strong>
29+
The indices 8, 13, and 15 correspond to the underlined characters in &quot;Leetcode<u><strong>H</strong></u>elps<u><strong>M</strong></u>e<u><strong>L</strong></u>earn&quot;.
30+
We then place spaces before those characters.
31+
</pre>
32+
33+
<p><strong>Example 2:</strong></p>
34+
35+
<pre>
36+
<strong>Input:</strong> s = &quot;icodeinpython&quot;, spaces = [1,5,7,9]
37+
<strong>Output:</strong> &quot;i code in py thon&quot;
38+
<strong>Explanation:</strong>
39+
The indices 1, 5, 7, and 9 correspond to the underlined characters in &quot;i<u><strong>c</strong></u>ode<u><strong>i</strong></u>n<u><strong>p</strong></u>y<u><strong>t</strong></u>hon&quot;.
40+
We then place spaces before those characters.
41+
</pre>
42+
43+
<p><strong>Example 3:</strong></p>
44+
45+
<pre>
46+
<strong>Input:</strong> s = &quot;spacing&quot;, spaces = [0,1,2,3,4,5,6]
47+
<strong>Output:</strong> &quot; s p a c i n g&quot;
48+
<strong>Explanation:</strong>
49+
We are also able to place spaces before the first character of the string.
50+
</pre>
51+
52+
<p>&nbsp;</p>
53+
<p><strong>Constraints:</strong></p>
54+
55+
<ul>
56+
<li><code>1 &lt;= s.length &lt;= 3 * 10<sup>5</sup></code></li>
57+
<li><code>s</code> consists only of lowercase and uppercase English letters.</li>
58+
<li><code>1 &lt;= spaces.length &lt;= 3 * 10<sup>5</sup></code></li>
59+
<li><code>0 &lt;= spaces[i] &lt;= s.length - 1</code></li>
60+
<li>All the values of <code>spaces</code> are <strong>strictly increasing</strong>.</li>
61+
</ul>
62+
63+
### Related Topics
64+
[[Array](../../tag/array/README.md)]
65+
[[String](../../tag/string/README.md)]
66+
[[Simulation](../../tag/simulation/README.md)]
67+
68+
### Hints
69+
<details>
70+
<summary>Hint 1</summary>
71+
Create a new string, initially empty, as the modified string. Iterate through the original string and append each character of the original string to the new string. However, each time you reach a character that requires a space before it, append a space before appending the character.
72+
</details>
73+
74+
<details>
75+
<summary>Hint 2</summary>
76+
Since the array of indices for the space locations is sorted, use a pointer to keep track of the next index to place a space. Only increment the pointer once a space has been appended.
77+
</details>
78+
79+
<details>
80+
<summary>Hint 3</summary>
81+
Ensure that your append operation can be done in O(1).
82+
</details>

problems/ads-performance/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
22
<!--+----------------------------------------------------------------------+-->
3-
<!--|@author openset <[email protected]> |-->
4-
<!--|@link https://github.com/openset |-->
5-
<!--|@home https://github.com/openset/leetcode |-->
3+
<!--|@author awesee <[email protected]> |-->
4+
<!--|@link https://github.com/awesee |-->
5+
<!--|@home https://github.com/awesee/leetcode |-->
66
<!--+----------------------------------------------------------------------+-->
77

88
[< Previous](../restaurant-growth "Restaurant Growth")

problems/alert-using-same-key-card-three-or-more-times-in-a-one-hour-period/README.md

+1-15
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,13 @@
3838
<strong>Explanation:</strong> &quot;bob&quot; used the keycard 3 times in a one-hour period (&quot;21:00&quot;,&quot;21:20&quot;, &quot;21:30&quot;).
3939
</pre>
4040

41-
<p><strong>Example 3:</strong></p>
42-
43-
<pre>
44-
<strong>Input:</strong> keyName = [&quot;john&quot;,&quot;john&quot;,&quot;john&quot;], keyTime = [&quot;23:58&quot;,&quot;23:59&quot;,&quot;00:01&quot;]
45-
<strong>Output:</strong> []
46-
</pre>
47-
48-
<p><strong>Example 4:</strong></p>
49-
50-
<pre>
51-
<strong>Input:</strong> keyName = [&quot;leslie&quot;,&quot;leslie&quot;,&quot;leslie&quot;,&quot;clare&quot;,&quot;clare&quot;,&quot;clare&quot;,&quot;clare&quot;], keyTime = [&quot;13:00&quot;,&quot;13:20&quot;,&quot;14:00&quot;,&quot;18:00&quot;,&quot;18:51&quot;,&quot;19:30&quot;,&quot;19:49&quot;]
52-
<strong>Output:</strong> [&quot;clare&quot;,&quot;leslie&quot;]
53-
</pre>
54-
5541
<p>&nbsp;</p>
5642
<p><strong>Constraints:</strong></p>
5743

5844
<ul>
5945
<li><code>1 &lt;= keyName.length, keyTime.length &lt;= 10<sup>5</sup></code></li>
6046
<li><code>keyName.length == keyTime.length</code></li>
61-
<li><code>keyTime[i]</code>&nbsp;is in the format <strong>&quot;HH:MM&quot;</strong>.</li>
47+
<li><code>keyTime[i]</code> is in the format <strong>&quot;HH:MM&quot;</strong>.</li>
6248
<li><code>[keyName[i], keyTime[i]]</code> is <strong>unique</strong>.</li>
6349
<li><code>1 &lt;= keyName[i].length &lt;= 10</code></li>
6450
<li><code>keyName[i] contains only lowercase English letters.</code></li>

0 commit comments

Comments
 (0)