mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-03 14:32:54 +08:00
update
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
155
leetcode/originData/count-nodes-equal-to-average-of-subtree.json
Normal file
155
leetcode/originData/count-nodes-equal-to-average-of-subtree.json
Normal file
File diff suppressed because one or more lines are too long
155
leetcode/originData/count-number-of-texts.json
Normal file
155
leetcode/originData/count-number-of-texts.json
Normal file
File diff suppressed because one or more lines are too long
155
leetcode/originData/largest-3-same-digit-number-in-string.json
Normal file
155
leetcode/originData/largest-3-same-digit-number-in-string.json
Normal file
File diff suppressed because one or more lines are too long
@@ -0,0 +1,48 @@
|
||||
<p>A parentheses string is a <strong>non-empty</strong> string consisting only of <code>'('</code> and <code>')'</code>. It is <strong>valid</strong> if <strong>any</strong> of the following conditions is <strong>true</strong>:</p>
|
||||
|
||||
<ul>
|
||||
<li>It is <code>()</code>.</li>
|
||||
<li>It can be written as <code>AB</code> (<code>A</code> concatenated with <code>B</code>), where <code>A</code> and <code>B</code> are valid parentheses strings.</li>
|
||||
<li>It can be written as <code>(A)</code>, where <code>A</code> is a valid parentheses string.</li>
|
||||
</ul>
|
||||
|
||||
<p>You are given an <code>m x n</code> matrix of parentheses <code>grid</code>. A <strong>valid parentheses string path</strong> in the grid is a path satisfying <strong>all</strong> of the following conditions:</p>
|
||||
|
||||
<ul>
|
||||
<li>The path starts from the upper left cell <code>(0, 0)</code>.</li>
|
||||
<li>The path ends at the bottom-right cell <code>(m - 1, n - 1)</code>.</li>
|
||||
<li>The path only ever moves <strong>down</strong> or <strong>right</strong>.</li>
|
||||
<li>The resulting parentheses string formed by the path is <strong>valid</strong>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return <code>true</code> <em>if there exists a <strong>valid parentheses string path</strong> in the grid.</em> Otherwise, return <code>false</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/15/example1drawio.png" style="width: 521px; height: 300px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> grid = [["(","(","("],[")","(",")"],["(","(",")"],["(","(",")"]]
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong> The above diagram shows two possible paths that form valid parentheses strings.
|
||||
The first path shown results in the valid parentheses string "()(())".
|
||||
The second path shown results in the valid parentheses string "((()))".
|
||||
Note that there may be other valid parentheses string paths.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/15/example2drawio.png" style="width: 165px; height: 165px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> grid = [[")",")"],["(","("]]
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation:</strong> The two possible paths form the parentheses strings "))(" and ")((". Since neither of them are valid parentheses strings, we return false.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>m == grid.length</code></li>
|
||||
<li><code>n == grid[i].length</code></li>
|
||||
<li><code>1 <= m, n <= 100</code></li>
|
||||
<li><code>grid[i][j]</code> is either <code>'('</code> or <code>')'</code>.</li>
|
||||
</ul>
|
@@ -0,0 +1,38 @@
|
||||
<p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
|
||||
|
||||
<p><strong>Note:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>sum</strong> of the <code>n</code> elements divided by <code>n</code> and <strong>rounded down</strong> to the nearest integer.</li>
|
||||
<li>A <strong>subtree</strong> of <code>root</code> is a tree consisting of <code>root</code> and all of its descendants.</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<img src="https://assets.leetcode.com/uploads/2022/03/15/image-20220315203925-1.png" style="width: 300px; height: 212px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> root = [4,8,5,0,1,null,6]
|
||||
<strong>Output:</strong> 5
|
||||
<strong>Explanation:</strong>
|
||||
For the node with value 4: The average of its subtree is (4 + 8 + 5 + 0 + 1 + 6) / 6 = 24 / 6 = 4.
|
||||
For the node with value 5: The average of its subtree is (5 + 6) / 2 = 11 / 2 = 5.
|
||||
For the node with value 0: The average of its subtree is 0 / 1 = 0.
|
||||
For the node with value 1: The average of its subtree is 1 / 1 = 1.
|
||||
For the node with value 6: The average of its subtree is 6 / 1 = 6.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<img src="https://assets.leetcode.com/uploads/2022/03/26/image-20220326133920-1.png" style="width: 80px; height: 76px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> root = [1]
|
||||
<strong>Output:</strong> 1
|
||||
<strong>Explanation:</strong> For the node with value 1: The average of its subtree is 1 / 1 = 1.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>The number of nodes in the tree is in the range <code>[1, 1000]</code>.</li>
|
||||
<li><code>0 <= Node.val <= 1000</code></li>
|
||||
</ul>
|
48
leetcode/problem/count-number-of-texts.html
Normal file
48
leetcode/problem/count-number-of-texts.html
Normal file
@@ -0,0 +1,48 @@
|
||||
<p>Alice is texting Bob using her phone. The <strong>mapping</strong> of digits to letters is shown in the figure below.</p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/15/1200px-telephone-keypad2svg.png" style="width: 200px; height: 162px;" />
|
||||
<p>In order to <strong>add</strong> a letter, Alice has to <strong>press</strong> the key of the corresponding digit <code>i</code> times, where <code>i</code> is the position of the letter in the key.</p>
|
||||
|
||||
<ul>
|
||||
<li>For example, to add the letter <code>'s'</code>, Alice has to press <code>'7'</code> four times. Similarly, to add the letter <code>'k'</code>, Alice has to press <code>'5'</code> twice.</li>
|
||||
<li>Note that the digits <code>'0'</code> and <code>'1'</code> do not map to any letters, so Alice <strong>does not</strong> use them.</li>
|
||||
</ul>
|
||||
|
||||
<p>However, due to an error in transmission, Bob did not receive Alice's text message but received a <strong>string of pressed keys</strong> instead.</p>
|
||||
|
||||
<ul>
|
||||
<li>For example, when Alice sent the message <code>"bob"</code>, Bob received the string <code>"2266622"</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Given a string <code>pressedKeys</code> representing the string received by Bob, return <em>the <strong>total number of possible text messages</strong> Alice could have sent</em>.</p>
|
||||
|
||||
<p>Since the answer may be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> pressedKeys = "22233"
|
||||
<strong>Output:</strong> 8
|
||||
<strong>Explanation:</strong>
|
||||
The possible text messages Alice could have sent are:
|
||||
"aaadd", "abdd", "badd", "cdd", "aaae", "abe", "bae", and "ce".
|
||||
Since there are 8 possible messages, we return 8.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> pressedKeys = "222222222222222222222222222222222222"
|
||||
<strong>Output:</strong> 82876089
|
||||
<strong>Explanation:</strong>
|
||||
There are 2082876103 possible text messages Alice could have sent.
|
||||
Since we need to return the answer modulo 10<sup>9</sup> + 7, we return 2082876103 % (10<sup>9</sup> + 7) = 82876089.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= pressedKeys.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>pressedKeys</code> only consists of digits from <code>'2'</code> - <code>'9'</code>.</li>
|
||||
</ul>
|
49
leetcode/problem/largest-3-same-digit-number-in-string.html
Normal file
49
leetcode/problem/largest-3-same-digit-number-in-string.html
Normal file
@@ -0,0 +1,49 @@
|
||||
<p>You are given a string <code>num</code> representing a large integer. An integer is <strong>good</strong> if it meets the following conditions:</p>
|
||||
|
||||
<ul>
|
||||
<li>It is a <strong>substring</strong> of <code>num</code> with length <code>3</code>.</li>
|
||||
<li>It consists of only one unique digit.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the <strong>maximum good </strong>integer as a <strong>string</strong> or an empty string </em><code>""</code><em> if no such integer exists</em>.</p>
|
||||
|
||||
<p>Note:</p>
|
||||
|
||||
<ul>
|
||||
<li>A <strong>substring</strong> is a contiguous sequence of characters within a string.</li>
|
||||
<li>There may be <strong>leading zeroes</strong> in <code>num</code> or a good integer.</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> num = "6<strong><u>777</u></strong>133339"
|
||||
<strong>Output:</strong> "777"
|
||||
<strong>Explanation:</strong> There are two distinct good integers: "777" and "333".
|
||||
"777" is the largest, so we return "777".
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> num = "23<strong><u>000</u></strong>19"
|
||||
<strong>Output:</strong> "000"
|
||||
<strong>Explanation:</strong> "000" is the only good integer.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> num = "42352338"
|
||||
<strong>Output:</strong> ""
|
||||
<strong>Explanation:</strong> No substring of length 3 consists of only one unique digit. Therefore, there are no good integers.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>3 <= num.length <= 1000</code></li>
|
||||
<li><code>num</code> only consists of digits.</li>
|
||||
</ul>
|
Reference in New Issue
Block a user