1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-04 23:11:41 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

移除零宽空格

This commit is contained in:
2025-05-25 15:06:02 +08:00
parent 59597532bc
commit 3070bed723
272 changed files with 1031 additions and 749 deletions

View File

@@ -16,13 +16,13 @@
<pre>
<strong>Input:</strong> s = &quot;11111222223&quot;, k = 3
<strong>Output:</strong> &quot;135&quot;
<strong>Explanation:</strong>
<strong>Explanation:</strong>
- For the first round, we divide s into groups of size 3: &quot;111&quot;, &quot;112&quot;, &quot;222&quot;, and &quot;23&quot;.
Then we calculate the digit sum of each group: 1 + 1 + 1 = 3, 1 + 1 + 2 = 4, 2 + 2 + 2 = 6, and 2 + 3 = 5.
Then we calculate the digit sum of each group: 1 + 1 + 1 = 3, 1 + 1 + 2 = 4, 2 + 2 + 2 = 6, and 2 + 3 = 5.
&nbsp; So, s becomes &quot;3&quot; + &quot;4&quot; + &quot;6&quot; + &quot;5&quot; = &quot;3465&quot; after the first round.
- For the second round, we divide s into &quot;346&quot; and &quot;5&quot;.
&nbsp; Then we calculate the digit sum of each group: 3 + 4 + 6 = 13, 5 = 5.
&nbsp; So, s becomes &quot;13&quot; + &quot;5&quot; = &quot;135&quot; after second round.
&nbsp; Then we calculate the digit sum of each group: 3 + 4 + 6 = 13, 5 = 5.
&nbsp; So, s becomes &quot;13&quot; + &quot;5&quot; = &quot;135&quot; after second round.
Now, s.length &lt;= k, so we return &quot;135&quot; as the answer.
</pre>
@@ -31,9 +31,9 @@ Now, s.length &lt;= k, so we return &quot;135&quot; as the answer.
<pre>
<strong>Input:</strong> s = &quot;00000000&quot;, k = 3
<strong>Output:</strong> &quot;000&quot;
<strong>Explanation:</strong>
<strong>Explanation:</strong>
We divide s into &quot;000&quot;, &quot;000&quot;, and &quot;00&quot;.
Then we calculate the digit sum of each group: 0 + 0 + 0 = 0, 0 + 0 + 0 = 0, and 0 + 0 = 0.
Then we calculate the digit sum of each group: 0 + 0 + 0 = 0, 0 + 0 + 0 = 0, and 0 + 0 = 0.
s becomes &quot;0&quot; + &quot;0&quot; + &quot;0&quot; = &quot;000&quot;, whose length is equal to k, so we return &quot;000&quot;.
</pre>

View File

@@ -1,4 +1,4 @@
<p>Given a binary string <code>s</code> <strong>without leading zeros</strong>, return <code>true</code> <em>if </em><code>s</code><em> contains <strong>at most one contiguous segment of ones</strong></em>. Otherwise, return <code>false</code>.</p>
<p>Given a binary string <code>s</code> <strong>without leading zeros</strong>, return <code>true</code> <em>if </em><code>s</code><em> contains <strong>at most one contiguous segment of ones</strong></em>. Otherwise, return <code>false</code>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
@@ -20,6 +20,6 @@
<ul>
<li><code>1 &lt;= s.length &lt;= 100</code></li>
<li><code>s[i]</code> is either <code>&#39;0&#39;</code> or <code>&#39;1&#39;</code>.</li>
<li><code>s[i]</code> is either <code>&#39;0&#39;</code> or <code>&#39;1&#39;</code>.</li>
<li><code>s[0]</code> is&nbsp;<code>&#39;1&#39;</code>.</li>
</ul>

View File

@@ -2,7 +2,7 @@
<p>You can pick <strong>any</strong> two different foods to make a good meal.</p>
<p>Given an array of integers <code>deliciousness</code> where <code>deliciousness[i]</code> is the deliciousness of the <code>i<sup>th</sup></code> item of food, return <em>the number of different <strong>good meals</strong> you can make from this list modulo</em> <code>10<sup>9</sup> + 7</code>.</p>
<p>Given an array of integers <code>deliciousness</code> where <code>deliciousness[i]</code> is the deliciousness of the <code>i<sup>th</sup></code> item of food, return <em>the number of different <strong>good meals</strong> you can make from this list modulo</em> <code>10<sup>9</sup> + 7</code>.</p>
<p>Note that items with different indices are considered different even if they have the same deliciousness value.</p>

View File

@@ -1,42 +1,83 @@
<p>Given a <strong>(0-indexed)</strong> integer array <code>nums</code> and two integers <code>low</code> and <code>high</code>, return <em>the number of <strong>nice pairs</strong></em>.</p>
<p>A <strong>nice pair</strong> is a pair <code>(i, j)</code> where <code>0 &lt;= i &lt; j &lt; nums.length</code> and <code>low &lt;= (nums[i] XOR nums[j]) &lt;= high</code>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,4,2,7], low = 2, high = 6
<strong>Output:</strong> 6
<strong>Explanation:</strong> All nice pairs (i, j) are as follows:
- (0, 1): nums[0] XOR nums[1] = 5
- (0, 2): nums[0] XOR nums[2] = 3
- (0, 3): nums[0] XOR nums[3] = 6
- (1, 2): nums[1] XOR nums[2] = 6
- (1, 3): nums[1] XOR nums[3] = 3
- (2, 3): nums[2] XOR nums[3] = 5
</pre>
<p><strong class="example">Example 2:</strong></p>
<p>Given a <strong>(0-indexed)</strong> integer array <code>nums</code> and two integers <code>low</code> and <code>high</code>, return <em>the number of <strong>nice pairs</strong></em>.</p>
<p>A <strong>nice pair</strong> is a pair <code>(i, j)</code> where <code>0 &lt;= i &lt; j &lt; nums.length</code> and <code>low &lt;= (nums[i] XOR nums[j]) &lt;= high</code>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,4,2,7], low = 2, high = 6
<strong>Output:</strong> 6
<strong>Explanation:</strong> All nice pairs (i, j) are as follows:
- (0, 1): nums[0] XOR nums[1] = 5
- (0, 2): nums[0] XOR nums[2] = 3
- (0, 3): nums[0] XOR nums[3] = 6
- (1, 2): nums[1] XOR nums[2] = 6
- (1, 3): nums[1] XOR nums[3] = 3
- (2, 3): nums[2] XOR nums[3] = 5
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> nums = [9,8,4,2,1], low = 5, high = 14
<strong>Output:</strong> 8
<strong>Explanation:</strong> All nice pairs (i, j) are as follows:
- (0, 2): nums[0] XOR nums[2] = 13
&nbsp; - (0, 3): nums[0] XOR nums[3] = 11
&nbsp; - (0, 4): nums[0] XOR nums[4] = 8
&nbsp; - (1, 2): nums[1] XOR nums[2] = 12
&nbsp; - (1, 3): nums[1] XOR nums[3] = 10
&nbsp; - (1, 4): nums[1] XOR nums[4] = 9
&nbsp; - (2, 3): nums[2] XOR nums[3] = 6
&nbsp; - (2, 4): nums[2] XOR nums[4] = 5</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 2 * 10<sup>4</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 2 * 10<sup>4</sup></code></li>
<li><code>1 &lt;= low &lt;= high &lt;= 2 * 10<sup>4</sup></code></li>
</ul>

View File

@@ -21,7 +21,7 @@
(&quot;a<u>b</u>a&quot;, &quot;bab<u>a</u>&quot;)
The underlined portions are the substrings that are chosen from s and t.
</pre>
<strong class="example">Example 2:</strong>
<strong class="example">Example 2:</strong>
<pre>
<strong>Input:</strong> s = &quot;ab&quot;, t = &quot;bb&quot;
@@ -30,7 +30,7 @@ The underlined portions are the substrings that are chosen from s and t.
(&quot;<u>a</u>b&quot;, &quot;<u>b</u>b&quot;)
(&quot;<u>a</u>b&quot;, &quot;b<u>b</u>&quot;)
(&quot;<u>ab</u>&quot;, &quot;<u>bb</u>&quot;)
The underlined portions are the substrings that are chosen from s and t.
The underlined portions are the substrings that are chosen from s and t.
</pre>
<p>&nbsp;</p>

View File

@@ -1,64 +1,127 @@
<p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <strong>cost</strong> of each insertion is the <b>minimum</b> of the following:</p>
<ul>
<li>The number of elements currently in <code>nums</code> that are <strong>strictly less than</strong> <code>instructions[i]</code>.</li>
<li>The number of elements currently in <code>nums</code> that are <strong>strictly greater than</strong> <code>instructions[i]</code>.</li>
</ul>
<p>For example, if inserting element <code>3</code> into <code>nums = [1,2,3,5]</code>, the <strong>cost</strong> of insertion is <code>min(2, 1)</code> (elements <code>1</code> and <code>2</code> are less than <code>3</code>, element <code>5</code> is greater than <code>3</code>) and <code>nums</code> will become <code>[1,2,3,3,5]</code>.</p>
<p>Return <em>the <strong>total cost</strong> to insert all elements from </em><code>instructions</code><em> into </em><code>nums</code>. Since the answer may be large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code></p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> instructions = [1,5,6,2]
<strong>Output:</strong> 1
<strong>Explanation:</strong> Begin with nums = [].
Insert 1 with cost min(0, 0) = 0, now nums = [1].
Insert 5 with cost min(1, 0) = 0, now nums = [1,5].
Insert 6 with cost min(2, 0) = 0, now nums = [1,5,6].
Insert 2 with cost min(1, 2) = 1, now nums = [1,2,5,6].
The total cost is 0 + 0 + 0 + 1 = 1.</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> instructions = [1,2,3,6,5,4]
<strong>Output:</strong> 3
<strong>Explanation:</strong> Begin with nums = [].
Insert 1 with cost min(0, 0) = 0, now nums = [1].
Insert 2 with cost min(1, 0) = 0, now nums = [1,2].
<p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <strong>cost</strong> of each insertion is the <b>minimum</b> of the following:</p>
<ul>
<li>The number of elements currently in <code>nums</code> that are <strong>strictly less than</strong> <code>instructions[i]</code>.</li>
<li>The number of elements currently in <code>nums</code> that are <strong>strictly greater than</strong> <code>instructions[i]</code>.</li>
</ul>
<p>For example, if inserting element <code>3</code> into <code>nums = [1,2,3,5]</code>, the <strong>cost</strong> of insertion is <code>min(2, 1)</code> (elements <code>1</code> and <code>2</code> are less than <code>3</code>, element <code>5</code> is greater than <code>3</code>) and <code>nums</code> will become <code>[1,2,3,3,5]</code>.</p>
<p>Return <em>the <strong>total cost</strong> to insert all elements from </em><code>instructions</code><em> into </em><code>nums</code>. Since the answer may be large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code></p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> instructions = [1,5,6,2]
<strong>Output:</strong> 1
<strong>Explanation:</strong> Begin with nums = [].
Insert 1 with cost min(0, 0) = 0, now nums = [1].
Insert 5 with cost min(1, 0) = 0, now nums = [1,5].
Insert 6 with cost min(2, 0) = 0, now nums = [1,5,6].
Insert 2 with cost min(1, 2) = 1, now nums = [1,2,5,6].
The total cost is 0 + 0 + 0 + 1 = 1.</pre>
<p><strong class="example">Example 2:</strong></p>
<strong>Input:</strong> instructions = [1,2,3,6,5,4]
<strong>Output:</strong> 3
<strong>Explanation:</strong> Begin with nums = [].
Insert 1 with cost min(0, 0) = 0, now nums = [1].
Insert 2 with cost min(1, 0) = 0, now nums = [1,2].
Insert 3 with cost min(2, 0) = 0, now nums = [1,2,3].
Insert 6 with cost min(3, 0) = 0, now nums = [1,2,3,6].
Insert 5 with cost min(3, 1) = 1, now nums = [1,2,3,5,6].
Insert 4 with cost min(3, 2) = 2, now nums = [1,2,3,4,5,6].
The total cost is 0 + 0 + 0 + 0 + 1 + 2 = 3.
</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> instructions = [1,3,3,3,2,4,2,1,2]
<strong>Output:</strong> 4
<strong>Explanation:</strong> Begin with nums = [].
Insert 1 with cost min(0, 0) = 0, now nums = [1].
Insert 3 with cost min(1, 0) = 0, now nums = [1,3].
Insert 3 with cost min(1, 0) = 0, now nums = [1,3,3].
Insert 3 with cost min(1, 0) = 0, now nums = [1,3,3,3].
Insert 2 with cost min(1, 3) = 1, now nums = [1,2,3,3,3].
Insert 4 with cost min(5, 0) = 0, now nums = [1,2,3,3,3,4].
Insert 2 with cost min(1, 4) = 1, now nums = [1,2,2,3,3,3,4].
Insert 1 with cost min(0, 6) = 0, now nums = [1,1,2,2,3,3,3,4].
Insert 2 with cost min(2, 4) = 2, now nums = [1,1,2,2,2,3,3,3,4].
The total cost is 0 + 0 + 0 + 0 + 1 + 0 + 1 + 0 + 2 = 4.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= instructions.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= instructions[i] &lt;= 10<sup>5</sup></code></li>
</ul>

View File

@@ -1,39 +1,77 @@
<p>You are given an <code>m x n</code> integer matrix <code>grid</code>, where <code>m</code> and <code>n</code> are both <strong>even</strong> integers, and an integer <code>k</code>.</p>
<p>The matrix is composed of several layers, which is shown in the below image, where each color is its own layer:</p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2021/06/10/ringofgrid.png" style="width: 231px; height: 258px;" /></p>
<p>A cyclic rotation of the matrix is done by cyclically rotating <strong>each layer</strong> in the matrix. To cyclically rotate a layer once, each element in the layer will take the place of the adjacent element in the <strong>counter-clockwise</strong> direction. An example rotation is shown below:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/06/22/explanation_grid.jpg" style="width: 500px; height: 268px;" />
<p>Return <em>the matrix after applying </em><code>k</code> <em>cyclic rotations to it</em>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/06/19/rod2.png" style="width: 421px; height: 191px;" />
<pre>
<strong>Input:</strong> grid = [[40,10],[30,20]], k = 1
<strong>Output:</strong> [[10,20],[40,30]]
<strong>Explanation:</strong> The figures above represent the grid at every state.
</pre>
<p>You are given an <code>m x n</code> integer matrix <code>grid</code>, where <code>m</code> and <code>n</code> are both <strong>even</strong> integers, and an integer <code>k</code>.</p>
<p>The matrix is composed of several layers, which is shown in the below image, where each color is its own layer:</p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2021/06/10/ringofgrid.png" style="width: 231px; height: 258px;" /></p>
<p>A cyclic rotation of the matrix is done by cyclically rotating <strong>each layer</strong> in the matrix. To cyclically rotate a layer once, each element in the layer will take the place of the adjacent element in the <strong>counter-clockwise</strong> direction. An example rotation is shown below:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/06/22/explanation_grid.jpg" style="width: 500px; height: 268px;" />
<p>Return <em>the matrix after applying </em><code>k</code> <em>cyclic rotations to it</em>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/06/19/rod2.png" style="width: 421px; height: 191px;" />
<pre>
<strong>Input:</strong> grid = [[40,10],[30,20]], k = 1
<strong>Output:</strong> [[10,20],[40,30]]
<strong>Explanation:</strong> The figures above represent the grid at every state.
</pre>
<p><strong class="example">Example 2:</strong></p>
<strong><img alt="" src="https://assets.leetcode.com/uploads/2021/06/10/ringofgrid5.png" style="width: 231px; height: 262px;" /></strong> <strong><img alt="" src="https://assets.leetcode.com/uploads/2021/06/10/ringofgrid6.png" style="width: 231px; height: 262px;" /></strong> <strong><img alt="" src="https://assets.leetcode.com/uploads/2021/06/10/ringofgrid7.png" style="width: 231px; height: 262px;" /></strong>
<pre>
<strong>Input:</strong> grid = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]], k = 2
<strong>Output:</strong> [[3,4,8,12],[2,11,10,16],[1,7,6,15],[5,9,13,14]]
<strong>Explanation:</strong> The figures above represent the grid at every state.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>m == grid.length</code></li>
<li><code>n == grid[i].length</code></li>
<li><code>2 &lt;= m, n &lt;= 50</code></li>
<li>Both <code>m</code> and <code>n</code> are <strong>even</strong> integers.</li>
<li><code>1 &lt;= grid[i][j] &lt;=<sup> </sup>5000</code></li>
<li><code>1 &lt;= k &lt;= 10<sup>9</sup></code></li>
</ul>

View File

@@ -1,9 +1,9 @@
<p>You have the task of delivering some boxes from storage to their ports using only one ship. However, this ship has a <strong>limit</strong> on the <strong>number of boxes</strong> and the <strong>total weight</strong> that it can carry.</p>
<p>You are given an array <code>boxes</code>, where <code>boxes[i] = [ports<sub>i</sub>, weight<sub>i</sub>]</code>, and three integers <code>portsCount</code>, <code>maxBoxes</code>, and <code>maxWeight</code>.</p>
<p>You are given an array <code>boxes</code>, where <code>boxes[i] = [ports<sub>i</sub>, weight<sub>i</sub>]</code>, and three integers <code>portsCount</code>, <code>maxBoxes</code>, and <code>maxWeight</code>.</p>
<ul>
<li><code>ports<sub>i</sub></code> is the port where you need to deliver the <code>i<sup>th</sup></code> box and <code>weights<sub>i</sub></code> is the weight of the <code>i<sup>th</sup></code> box.</li>
<li><code>ports<sub>i</sub></code> is the port where you need to deliver the <code>i<sup>th</sup></code> box and <code>weights<sub>i</sub></code> is the weight of the <code>i<sup>th</sup></code> box.</li>
<li><code>portsCount</code> is the number of ports.</li>
<li><code>maxBoxes</code> and <code>maxWeight</code> are the respective box and weight limits of the ship.</li>
</ul>
@@ -26,7 +26,7 @@
<pre>
<strong>Input:</strong> boxes = [[1,1],[2,1],[1,1]], portsCount = 2, maxBoxes = 3, maxWeight = 3
<strong>Output:</strong> 4
<strong>Explanation:</strong> The optimal strategy is as follows:
<strong>Explanation:</strong> The optimal strategy is as follows:
- The ship takes all the boxes in the queue, goes to port 1, then port 2, then port 1 again, then returns to storage. 4 trips.
So the total number of trips is 4.
Note that the first and third boxes cannot be delivered together because the boxes need to be delivered in order (i.e. the second box needs to be delivered at port 2 before the third box).
@@ -37,7 +37,7 @@ Note that the first and third boxes cannot be delivered together because the box
<pre>
<strong>Input:</strong> boxes = [[1,2],[3,3],[3,1],[3,1],[2,4]], portsCount = 3, maxBoxes = 3, maxWeight = 6
<strong>Output:</strong> 6
<strong>Explanation:</strong> The optimal strategy is as follows:
<strong>Explanation:</strong> The optimal strategy is as follows:
- The ship takes the first box, goes to port 1, then returns to storage. 2 trips.
- The ship takes the second, third and fourth boxes, goes to port 3, then returns to storage. 2 trips.
- The ship takes the fifth box, goes to port 2, then returns to storage. 2 trips.
@@ -62,6 +62,6 @@ So the total number of trips is 2 + 2 + 2 = 6.
<ul>
<li><code>1 &lt;= boxes.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= portsCount, maxBoxes, maxWeight &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= ports<sub>i</sub> &lt;= portsCount</code></li>
<li><code>1 &lt;= ports<sub>i</sub> &lt;= portsCount</code></li>
<li><code>1 &lt;= weights<sub>i</sub> &lt;= maxWeight</code></li>
</ul>

View File

@@ -2,7 +2,7 @@
<p>In one operation, you can change any integer&#39;s value in <strong>any </strong>of the arrays to <strong>any</strong> value between <code>1</code> and <code>6</code>, inclusive.</p>
<p>Return <em>the minimum number of operations required to make the sum of values in </em><code>nums1</code><em> equal to the sum of values in </em><code>nums2</code><em>.</em> Return <code>-1</code> if it is not possible to make the sum of the two arrays equal.</p>
<p>Return <em>the minimum number of operations required to make the sum of values in </em><code>nums1</code><em> equal to the sum of values in </em><code>nums2</code><em>.</em> Return <code>-1</code> if it is not possible to make the sum of the two arrays equal.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
@@ -29,7 +29,7 @@
<pre>
<strong>Input:</strong> nums1 = [6,6], nums2 = [1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> You can make the sums of nums1 and nums2 equal with 3 operations. All indices are 0-indexed.
<strong>Explanation:</strong> You can make the sums of nums1 and nums2 equal with 3 operations. All indices are 0-indexed.
- Change nums1[0] to 2. nums1 = [<strong><u>2</u></strong>,6], nums2 = [1].
- Change nums1[1] to 2. nums1 = [2,<strong><u>2</u></strong>], nums2 = [1].
- Change nums2[0] to 4. nums1 = [2,2], nums2 = [<strong><u>4</u></strong>].

View File

@@ -16,7 +16,7 @@
</strong>At time 0, person 0 shares the secret with person 1.
At time 5, person 1 shares the secret with person 2.
At time 8, person 2 shares the secret with person 3.
At time 10, person 1 shares the secret with person 5.
At time 10, person 1 shares the secret with person 5.
Thus, people 0, 1, 2, 3, and 5 know the secret after all the meetings.
</pre>

View File

@@ -1,6 +1,6 @@
<p>There is a biker going on a road trip. The road trip consists of <code>n + 1</code> points at different altitudes. The biker starts his trip on point <code>0</code> with altitude equal <code>0</code>.</p>
<p>You are given an integer array <code>gain</code> of length <code>n</code> where <code>gain[i]</code> is the <strong>net gain in altitude</strong> between points <code>i</code> and <code>i + 1</code> for all (<code>0 &lt;= i &lt; n)</code>. Return <em>the <strong>highest altitude</strong> of a point.</em></p>
<p>You are given an integer array <code>gain</code> of length <code>n</code> where <code>gain[i]</code> is the <strong>net gain in altitude</strong> between points <code>i</code> and <code>i + 1</code> for all (<code>0 &lt;= i &lt; n)</code>. Return <em>the <strong>highest altitude</strong> of a point.</em></p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

View File

@@ -1,6 +1,6 @@
<p>You are given an <code>m x n</code> integer matrix <code>grid</code>.</p>
<p>You are given an <code>m x n</code> integer matrix <code>grid</code>.</p>
<p>A <strong>rhombus sum</strong> is the sum of the elements that form <strong>the</strong> <strong>border</strong> of a regular rhombus shape in <code>grid</code>. The rhombus must have the shape of a square rotated 45 degrees with each of the corners centered in a grid cell. Below is an image of four valid rhombus shapes with the corresponding colored cells that should be included in each <strong>rhombus sum</strong>:</p>
<p>A <strong>rhombus sum</strong> is the sum of the elements that form <strong>the</strong> <strong>border</strong> of a regular rhombus shape in <code>grid</code>. The rhombus must have the shape of a square rotated 45 degrees with each of the corners centered in a grid cell. Below is an image of four valid rhombus shapes with the corresponding colored cells that should be included in each <strong>rhombus sum</strong>:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/04/23/pc73-q4-desc-2.png" style="width: 385px; height: 385px;" />
<p>Note that the rhombus can have an area of 0, which is depicted by the purple rhombus in the bottom right corner.</p>

View File

@@ -7,7 +7,7 @@
<li><code>nums[2 * i + 1] = nums[i] + nums[i + 1]</code> when <code>2 &lt;= 2 * i + 1 &lt;= n</code></li>
</ul>
<p>Return<strong> </strong><em>the <strong>maximum</strong> integer in the array </em><code>nums</code>.</p>
<p>Return<strong> </strong><em>the <strong>maximum</strong> integer in the array </em><code>nums</code>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

View File

@@ -49,5 +49,5 @@
<ul>
<li><code>destination.length == 2</code></li>
<li><code>1 &lt;= row, column &lt;= 15</code></li>
<li><code>1 &lt;= k &lt;= nCr(row + column, row)</code>, where <code>nCr(a, b)</code> denotes <code>a</code> choose <code>b</code>.</li>
<li><code>1 &lt;= k &lt;= nCr(row + column, row)</code>, where <code>nCr(a, b)</code> denotes <code>a</code> choose <code>b</code>.</li>
</ul>

View File

@@ -26,7 +26,7 @@ Rotate: &quot;5323&quot;
Add: &quot;5222&quot;
Add: &quot;5121&quot;
Rotate: &quot;2151&quot;
Add: &quot;2050&quot;
Add: &quot;2050&quot;
There is no way to obtain a string that is lexicographically smaller than &quot;2050&quot;.
</pre>
@@ -38,8 +38,8 @@ There is no way to obtain a string that is lexicographically smaller than &quot;
<strong>Explanation:</strong> We can apply the following operations:
Start: &quot;74&quot;
Rotate: &quot;47&quot;
Add: &quot;42&quot;
Rotate: &quot;24&quot;
Add: &quot;42&quot;
Rotate: &quot;24&quot;
There is no way to obtain a string that is lexicographically smaller than &quot;24&quot;.
</pre>

View File

@@ -1,6 +1,6 @@
<p>You are given an array <code>nums</code> and an integer <code>k</code>. The <font face="monospace">XOR</font> of a segment <code>[left, right]</code> where <code>left &lt;= right</code> is the <code>XOR</code> of all the elements with indices between <code>left</code> and <code>right</code>, inclusive: <code>nums[left] XOR nums[left+1] XOR ... XOR nums[right]</code>.</p>
<p>You are given an array <code>nums</code> and an integer <code>k</code>. The <font face="monospace">XOR</font> of a segment <code>[left, right]</code> where <code>left &lt;= right</code> is the <code>XOR</code> of all the elements with indices between <code>left</code> and <code>right</code>, inclusive: <code>nums[left] XOR nums[left+1] XOR ... XOR nums[right]</code>.</p>
<p>Return <em>the minimum number of elements to change in the array </em>such that the <code>XOR</code> of all segments of size <code>k</code> is equal to zero.</p>
<p>Return <em>the minimum number of elements to change in the array </em>such that the <code>XOR</code> of all segments of size <code>k</code> is equal to zero.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
@@ -31,5 +31,5 @@
<ul>
<li><code>1 &lt;= k &lt;= nums.length &lt;= 2000</code></li>
<li><code>0 &lt;= nums[i] &lt; 2<sup>10</sup></code></li>
<li><code>0 &lt;= nums[i] &lt; 2<sup>10</sup></code></li>
</ul>

View File

@@ -1,6 +1,6 @@
<p>You are given two <strong>non-increasing 0-indexed </strong>integer arrays <code>nums1</code> and <code>nums2</code>.</p>
<p>You are given two <strong>non-increasing 0-indexed </strong>integer arrays <code>nums1</code> and <code>nums2</code>.</p>
<p>A pair of indices <code>(i, j)</code>, where <code>0 &lt;= i &lt; nums1.length</code> and <code>0 &lt;= j &lt; nums2.length</code>, is <strong>valid</strong> if both <code>i &lt;= j</code> and <code>nums1[i] &lt;= nums2[j]</code>. The <strong>distance</strong> of the pair is <code>j - i</code>.</p>
<p>A pair of indices <code>(i, j)</code>, where <code>0 &lt;= i &lt; nums1.length</code> and <code>0 &lt;= j &lt; nums2.length</code>, is <strong>valid</strong> if both <code>i &lt;= j</code> and <code>nums1[i] &lt;= nums2[j]</code>. The <strong>distance</strong> of the pair is <code>j - i</code>.</p>
<p>Return <em>the <strong>maximum distance</strong> of any <strong>valid</strong> pair </em><code>(i, j)</code><em>. If there are no valid pairs, return </em><code>0</code>.</p>

View File

@@ -18,7 +18,7 @@
<strong>Input:</strong> milestones = [1,2,3]
<strong>Output:</strong> 6
<strong>Explanation:</strong> One possible scenario is:
- During the 1<sup>st</sup> week, you will work on a milestone of project 0.
- During the 1<sup>st</sup> week, you will work on a milestone of project 0.
- During the 2<sup>nd</sup> week, you will work on a milestone of project 2.
- During the 3<sup>rd</sup> week, you will work on a milestone of project 1.
- During the 4<sup>th</sup> week, you will work on a milestone of project 2.

View File

@@ -1,6 +1,6 @@
<p>You are playing a solitaire game with <strong>three piles</strong> of stones of sizes <code>a</code>, <code>b</code>, and <code>c</code> respectively. Each turn you choose two <strong>different non-empty </strong>piles, take one stone from each, and add <code>1</code> point to your score. The game stops when there are <strong>fewer than two non-empty</strong> piles (meaning there are no more available moves).</p>
<p>You are playing a solitaire game with <strong>three piles</strong> of stones of sizes <code>a</code>, <code>b</code>, and <code>c</code> respectively. Each turn you choose two <strong>different non-empty </strong>piles, take one stone from each, and add <code>1</code> point to your score. The game stops when there are <strong>fewer than two non-empty</strong> piles (meaning there are no more available moves).</p>
<p>Given three integers <code>a</code>, <code>b</code>, and <code>c</code>, return <em>the</em> <strong><em>maximum</em> </strong><em><strong>score</strong> you can get.</em></p>
<p>Given three integers <code>a</code>, <code>b</code>, and <code>c</code>, return <em>the</em> <strong><em>maximum</em> </strong><em><strong>score</strong> you can get.</em></p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

View File

@@ -1,4 +1,4 @@
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> representing the score of students in an exam. The teacher would like to form one <strong>non-empty</strong> group of students with maximal <strong>strength</strong>, where the strength of a group of students of indices <code>i<sub>0</sub></code>, <code>i<sub>1</sub></code>, <code>i<sub>2</sub></code>, ... , <code>i<sub>k</sub></code> is defined as <code>nums[i<sub>0</sub>] * nums[i<sub>1</sub>] * nums[i<sub>2</sub>] * ... * nums[i<sub>k</sub>]</code>.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> representing the score of students in an exam. The teacher would like to form one <strong>non-empty</strong> group of students with maximal <strong>strength</strong>, where the strength of a group of students of indices <code>i<sub>0</sub></code>, <code>i<sub>1</sub></code>, <code>i<sub>2</sub></code>, ... , <code>i<sub>k</sub></code> is defined as <code>nums[i<sub>0</sub>] * nums[i<sub>1</sub>] * nums[i<sub>2</sub>] * ... * nums[i<sub>k</sub>]</code>.</p>
<p>Return <em>the maximum strength of a group the teacher can create</em>.</p>

View File

@@ -1,13 +1,13 @@
<p>You are given a very large integer <code>n</code>, represented as a string, and an integer digit <code>x</code>. The digits in <code>n</code> and the digit <code>x</code> are in the <strong>inclusive</strong> range <code>[1, 9]</code>, and <code>n</code> may represent a <b>negative</b> number.</p>
<p>You are given a very large integer <code>n</code>, represented as a string, and an integer digit <code>x</code>. The digits in <code>n</code> and the digit <code>x</code> are in the <strong>inclusive</strong> range <code>[1, 9]</code>, and <code>n</code> may represent a <b>negative</b> number.</p>
<p>You want to <strong>maximize </strong><code>n</code><strong>&#39;s numerical value</strong> by inserting <code>x</code> anywhere in the decimal representation of <code>n</code>. You <strong>cannot</strong> insert <code>x</code> to the left of the negative sign.</p>
<p>You want to <strong>maximize </strong><code>n</code><strong>&#39;s numerical value</strong> by inserting <code>x</code> anywhere in the decimal representation of <code>n</code>. You <strong>cannot</strong> insert <code>x</code> to the left of the negative sign.</p>
<ul>
<li>For example, if <code>n = 73</code> and <code>x = 6</code>, it would be best to insert it between <code>7</code> and <code>3</code>, making <code>n = 763</code>.</li>
<li>If <code>n = -55</code> and <code>x = 2</code>, it would be best to insert it before the first <code>5</code>, making <code>n = -255</code>.</li>
</ul>
<p>Return <em>a string representing the <strong>maximum</strong> value of </em><code>n</code><em> after the insertion</em>.</p>
<p>Return <em>a string representing the <strong>maximum</strong> value of </em><code>n</code><em> after the insertion</em>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
@@ -32,7 +32,7 @@
<ul>
<li><code>1 &lt;= n.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= x &lt;= 9</code></li>
<li>The digits in <code>n</code> are in the range <code>[1, 9]</code>.</li>
<li>The digits in <code>n</code> are in the range <code>[1, 9]</code>.</li>
<li><code>n</code> is a valid representation of an integer.</li>
<li>In the case of a negative <code>n</code>, it will begin with <code>&#39;-&#39;</code>.</li>
<li>In the case of a negative <code>n</code>, it will begin with <code>&#39;-&#39;</code>.</li>
</ul>

View File

@@ -47,5 +47,5 @@
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= maximumBit &lt;= 20</code></li>
<li><code>0 &lt;= nums[i] &lt; 2<sup>maximumBit</sup></code></li>
<li><code>nums</code> is sorted in <strong>ascending</strong> order.</li>
<li><code>nums</code> is sorted in <strong>ascending</strong> order.</li>
</ul>

View File

@@ -1,4 +1,4 @@
<p>You are given a string <code>s</code> consisting only of characters <code>&#39;a&#39;</code> and <code>&#39;b&#39;</code>.</p>
<p>You are given a string <code>s</code> consisting only of characters <code>&#39;a&#39;</code> and <code>&#39;b&#39;</code>.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices <code>(i,j)</code> such that <code>i &lt; j</code> and <code>s[i] = &#39;b&#39;</code> and <code>s[j]= &#39;a&#39;</code>.</p>
@@ -28,5 +28,5 @@ Delete the characters at 0-indexed positions 3 and 6 (&quot;aab<u>a</u>bb<u>a</u
<ul>
<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
<li><code>s[i]</code> is&nbsp;<code>&#39;a&#39;</code> or <code>&#39;b&#39;</code>.</li>
<li><code>s[i]</code> is&nbsp;<code>&#39;a&#39;</code> or <code>&#39;b&#39;</code>.</li>
</ul>

View File

@@ -1,4 +1,4 @@
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>. You are asked to distribute this array into <code>k</code> subsets of <strong>equal size</strong> such that there are no two equal elements in the same subset.</p>
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>. You are asked to distribute this array into <code>k</code> subsets of <strong>equal size</strong> such that there are no two equal elements in the same subset.</p>
<p>A subset&#39;s <strong>incompatibility</strong> is the difference between the maximum and minimum elements in that array.</p>

View File

@@ -57,5 +57,5 @@ Starting with 27 energy, we finish the tasks in the following order:
<ul>
<li><code>1 &lt;= tasks.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= actual<sub>i</sub>&nbsp;&lt;= minimum<sub>i</sub>&nbsp;&lt;= 10<sup>4</sup></code></li>
<li><code>1 &lt;= actual<sub>i</sub>&nbsp;&lt;= minimum<sub>i</sub>&nbsp;&lt;= 10<sup>4</sup></code></li>
</ul>

View File

@@ -1,10 +1,10 @@
<p>You are given a string <code>s</code> (<strong>0-indexed</strong>). You are asked to perform the following operation on <code>s</code> until you get a sorted string:</p>
<p>You are given a string <code>s</code> (<strong>0-indexed</strong>). You are asked to perform the following operation on <code>s</code> until you get a sorted string:</p>
<ol>
<li>Find <strong>the largest index</strong> <code>i</code> such that <code>1 &lt;= i &lt; s.length</code> and <code>s[i] &lt; s[i - 1]</code>.</li>
<li>Find <strong>the largest index</strong> <code>j</code> such that <code>i &lt;= j &lt; s.length</code> and <code>s[k] &lt; s[i - 1]</code> for all the possible values of <code>k</code> in the range <code>[i, j]</code> inclusive.</li>
<li>Swap the two characters at indices <code>i - 1</code> and <code>j</code>.</li>
<li>Reverse the suffix starting at index <code>i</code>.</li>
<li>Swap the two characters at indices <code>i - 1</code> and <code>j</code>.</li>
<li>Reverse the suffix starting at index <code>i</code>.</li>
</ol>
<p>Return <em>the number of operations needed to make the string sorted.</em> Since the answer can be too large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
@@ -38,5 +38,5 @@ Operation 2: i=4, j=4. Swap s[3] and s[4] to get s=&quot;aaaab&quot;, then rever
<ul>
<li><code>1 &lt;= s.length &lt;= 3000</code></li>
<li><code>s</code> consists only of lowercase English letters.</li>
<li><code>s</code> consists only of lowercase English letters.</li>
</ul>

View File

@@ -1,4 +1,4 @@
<p>You are given an <strong>even</strong> integer <code>n</code>. You initially have a permutation <code>perm</code> of size <code>n</code> where <code>perm[i] == i</code> <strong>(0-indexed)</strong>.</p>
<p>You are given an <strong>even</strong> integer <code>n</code>. You initially have a permutation <code>perm</code> of size <code>n</code> where <code>perm[i] == i</code> <strong>(0-indexed)</strong>.</p>
<p>In one operation, you will create a new array <code>arr</code>, and for each <code>i</code>:</p>
@@ -7,7 +7,7 @@
<li>If <code>i % 2 == 1</code>, then <code>arr[i] = perm[n / 2 + (i - 1) / 2]</code>.</li>
</ul>
<p>You will then assign <code>arr</code> to <code>perm</code>.</p>
<p>You will then assign <code>arr</code> to <code>perm</code>.</p>
<p>Return <em>the minimum <strong>non-zero</strong> number of operations you need to perform on </em><code>perm</code><em> to return the permutation to its initial value.</em></p>
@@ -45,5 +45,5 @@ So it takes only 2 operations.
<ul>
<li><code>2 &lt;= n &lt;= 1000</code></li>
<li><code>n</code> is even.</li>
<li><code>n</code> is even.</li>
</ul>

View File

@@ -4,8 +4,8 @@
<ul>
<li>There are <code>n</code> languages numbered <code>1</code> through <code>n</code>,</li>
<li><code>languages[i]</code> is the set of languages the <code>i<sup>th</sup></code> user knows, and</li>
<li><code>friendships[i] = [u<sub>i</sub>, v<sub>i</sub>]</code> denotes a friendship between the users <code>u<sup></sup><sub>i</sub></code> and <code>v<sub>i</sub></code>.</li>
<li><code>languages[i]</code> is the set of languages the <code>i<sup>th</sup></code> user knows, and</li>
<li><code>friendships[i] = [u<sub>i</sub>, v<sub>i</sub>]</code> denotes a friendship between the users <code>u<sup></sup><sub>i</sub></code> and <code>v<sub>i</sub></code>.</li>
</ul>
<p>You can choose <strong>one</strong> language and teach it to some users so that all friends can communicate with each other. Return <i data-stringify-type="italic">the</i> <i><strong>minimum</strong> </i><i data-stringify-type="italic">number of users you need to teach.</i></p>
@@ -36,8 +36,8 @@ Note that friendships are not transitive, meaning if <code>x</code> is a friend
<li><code>1 &lt;= m &lt;= 500</code></li>
<li><code>1 &lt;= languages[i].length &lt;= n</code></li>
<li><code>1 &lt;= languages[i][j] &lt;= n</code></li>
<li><code>1 &lt;= u<sub>i</sub> &lt; v<sub>i</sub> &lt;= languages.length</code></li>
<li><code>1 &lt;= u<sub>i</sub> &lt; v<sub>i</sub> &lt;= languages.length</code></li>
<li><code>1 &lt;= friendships.length &lt;= 500</code></li>
<li>All tuples <code>(u<sub>i, </sub>v<sub>i</sub>)</code> are unique</li>
<li>All tuples <code>(u<sub>i, </sub>v<sub>i</sub>)</code> are unique</li>
<li><code>languages[i]</code> contains only unique values</li>
</ul>

View File

@@ -10,7 +10,7 @@
</li>
</ul>
<p>Given an integer array <code>nums</code>, return <em>the <strong>minimum</strong> number of elements to remove to make </em><code>nums<em></em></code><em> </em><em>a <strong>mountain array</strong>.</em></p>
<p>Given an integer array <code>nums</code>, return <em>the <strong>minimum</strong> number of elements to remove to make </em><code>nums<em></em></code><em> </em><em>a <strong>mountain array</strong>.</em></p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

View File

@@ -12,12 +12,12 @@
<pre>
<strong>Input:</strong> ranks = [4,2,3,1], cars = 10
<strong>Output:</strong> 16
<strong>Explanation:</strong>
<strong>Explanation:</strong>
- The first mechanic will repair two cars. The time required is 4 * 2 * 2 = 16 minutes.
- The second mechanic will repair two cars. The time required is 2 * 2 * 2 = 8 minutes.
- The third mechanic will repair two cars. The time required is 3 * 2 * 2 = 12 minutes.
- The fourth mechanic will repair four cars. The time required is 1 * 4 * 4 = 16 minutes.
It can be proved that the cars cannot be repaired in less than 16 minutes.
It can be proved that the cars cannot be repaired in less than 16 minutes.
</pre>
<p><strong class="example">Example 2:</strong></p>
@@ -25,11 +25,11 @@ It can be proved that the cars cannot be repaired in less than 16 minutes.
<pre>
<strong>Input:</strong> ranks = [5,1,8], cars = 6
<strong>Output:</strong> 16
<strong>Explanation:</strong>
<strong>Explanation:</strong>
- The first mechanic will repair one car. The time required is 5 * 1 * 1 = 5 minutes.
- The second mechanic will repair four cars. The time required is 1 * 4 * 4 = 16 minutes.
- The third mechanic will repair one car. The time required is 8 * 1 * 1 = 8 minutes.
It can be proved that the cars cannot be repaired in less than 16 minutes.
It can be proved that the cars cannot be repaired in less than 16 minutes.
</pre>
<p>&nbsp;</p>

View File

@@ -9,14 +9,14 @@
<p>This continues until none of the queue students want to take the top sandwich and are thus unable to eat.</p>
<p>You are given two integer arrays <code>students</code> and <code>sandwiches</code> where <code>sandwiches[i]</code> is the type of the <code>i<sup>th</sup></code> sandwich in the stack (<code>i = 0</code> is the top of the stack) and <code>students[j]</code> is the preference of the <code>j<sup>th</sup></code> student in the initial queue (<code>j = 0</code> is the front of the queue). Return <em>the number of students that are unable to eat.</em></p>
<p>You are given two integer arrays <code>students</code> and <code>sandwiches</code> where <code>sandwiches[i]</code> is the type of the <code>i<sup>th</sup></code> sandwich in the stack (<code>i = 0</code> is the top of the stack) and <code>students[j]</code> is the preference of the <code>j<sup>th</sup></code> student in the initial queue (<code>j = 0</code> is the front of the queue). Return <em>the number of students that are unable to eat.</em></p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> students = [1,1,0,0], sandwiches = [0,1,0,1]
<strong>Output:</strong> 0<strong>
<strong>Output:</strong> 0<strong>
Explanation:</strong>
- Front student leaves the top sandwich and returns to the end of the line making students = [1,0,0,1].
- Front student leaves the top sandwich and returns to the end of the line making students = [0,0,1,1].

View File

@@ -10,7 +10,7 @@
<p>You must make a <strong>move</strong> for every piece on the board simultaneously. A <strong>move combination</strong> consists of all the <strong>moves</strong> performed on all the given pieces. Every second, each piece will instantaneously travel <strong>one square</strong> towards their destination if they are not already at it. All pieces start traveling at the <code>0<sup>th</sup></code> second. A move combination is <strong>invalid</strong> if, at a given time, <strong>two or more</strong> pieces occupy the same square.</p>
<p>Return <em>the number of <strong>valid</strong> move combinations</em>.</p>
<p>Return <em>the number of <strong>valid</strong> move combinations</em>.</p>
<p><strong>Notes:</strong></p>

View File

@@ -1,4 +1,4 @@
<p>Given a string <code>s</code>, return <code>true</code> <em>if it is possible to split the string</em> <code>s</code> <em>into three <strong>non-empty</strong> palindromic substrings. Otherwise, return </em><code>false</code>.</p>
<p>Given a string <code>s</code>, return <code>true</code> <em>if it is possible to split the string</em> <code>s</code> <em>into three <strong>non-empty</strong> palindromic substrings. Otherwise, return </em><code>false</code>.</p>
<p>A string is said to be palindrome if it the same string when reversed.</p>
@@ -24,5 +24,5 @@
<ul>
<li><code>3 &lt;= s.length &lt;= 2000</code></li>
<li><code>s</code> consists only of lowercase English letters.</li>
<li><code>s</code> consists only of lowercase English letters.</li>
</ul>

View File

@@ -12,14 +12,14 @@
<pre>
<strong>Input:</strong> nums = [2,1,4]
<strong>Output:</strong> 141
<strong>Explanation:</strong>
<strong>Explanation:</strong>
1<sup>st</sup>&nbsp;group: [2] has power = 2<sup>2</sup>&nbsp;* 2 = 8.
2<sup>nd</sup>&nbsp;group: [1] has power = 1<sup>2</sup> * 1 = 1.
3<sup>rd</sup>&nbsp;group: [4] has power = 4<sup>2</sup> * 4 = 64.
4<sup>th</sup>&nbsp;group: [2,1] has power = 2<sup>2</sup> * 1 = 4.
5<sup>th</sup>&nbsp;group: [2,4] has power = 4<sup>2</sup> * 2 = 32.
6<sup>th</sup>&nbsp;group: [1,4] has power = 4<sup>2</sup> * 1 = 16.
7<sup>th</sup>&nbsp;group: [2,1,4] has power = 4<sup>2</sup> * 1 = 16.
2<sup>nd</sup>&nbsp;group: [1] has power = 1<sup>2</sup> * 1 = 1.
3<sup>rd</sup>&nbsp;group: [4] has power = 4<sup>2</sup> * 4 = 64.
4<sup>th</sup>&nbsp;group: [2,1] has power = 2<sup>2</sup> * 1 = 4.
5<sup>th</sup>&nbsp;group: [2,4] has power = 4<sup>2</sup> * 2 = 32.
6<sup>th</sup>&nbsp;group: [1,4] has power = 4<sup>2</sup> * 1 = 16.
7<sup>th</sup>&nbsp;group: [2,1,4] has power = 4<sup>2</sup> * 1 = 16.
The sum of powers of all groups is 8 + 1 + 64 + 4 + 32 + 16 + 16 = 141.
</pre>

View File

@@ -1,4 +1,4 @@
<p>You are given two <strong>0-indexed</strong> integer arrays <code>servers</code> and <code>tasks</code> of lengths <code>n</code> and <code>m</code> respectively. <code>servers[i]</code> is the <strong>weight</strong> of the <code>i<sup>th</sup></code> server, and <code>tasks[j]</code> is the <strong>time needed</strong> to process the <code>j<sup>th</sup></code> task <strong>in seconds</strong>.</p>
<p>You are given two <strong>0-indexed</strong> integer arrays <code>servers</code> and <code>tasks</code> of lengths <code>n</code> and <code>m</code> respectively. <code>servers[i]</code> is the <strong>weight</strong> of the <code>i<sup>th</sup></code> server, and <code>tasks[j]</code> is the <strong>time needed</strong> to process the <code>j<sup>th</sup></code> task <strong>in seconds</strong>.</p>
<p>Tasks are assigned to the servers using a <strong>task queue</strong>. Initially, all servers are free, and the queue is <strong>empty</strong>.</p>
@@ -8,9 +8,9 @@
<p>A server that is assigned task <code>j</code> at second <code>t</code> will be free again at second <code>t + tasks[j]</code>.</p>
<p>Build an array <code>ans</code> of length <code>m</code>, where <code>ans[j]</code> is the <strong>index</strong> of the server the <code>j<sup>th</sup></code> task will be assigned to.</p>
<p>Build an array <code>ans</code> of length <code>m</code>, where <code>ans[j]</code> is the <strong>index</strong> of the server the <code>j<sup>th</sup></code> task will be assigned to.</p>
<p>Return <em>the array </em><code>ans</code>.</p>
<p>Return <em>the array </em><code>ans</code>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
@@ -31,12 +31,12 @@
<pre>
<strong>Input:</strong> servers = [5,1,4,3,2], tasks = [2,1,2,4,5,2,1]
<strong>Output:</strong> [1,4,1,4,1,3,2]
<strong>Explanation: </strong>Events in chronological order go as follows:
<strong>Explanation: </strong>Events in chronological order go as follows:
- At second 0, task 0 is added and processed using server 1 until second 2.
- At second 1, task 1 is added and processed using server 4 until second 2.
- At second 2, servers 1 and 4 become free. Task 2 is added and processed using server 1 until second 4.
- At second 2, servers 1 and 4 become free. Task 2 is added and processed using server 1 until second 4.
- At second 3, task 3 is added and processed using server 4 until second 7.
- At second 4, server 1 becomes free. Task 4 is added and processed using server 1 until second 9.
- At second 4, server 1 becomes free. Task 4 is added and processed using server 1 until second 9.
- At second 5, task 5 is added and processed using server 3 until second 7.
- At second 6, task 6 is added and processed using server 2 until second 7.
</pre>

View File

@@ -11,10 +11,10 @@
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong>
fn = async (n) =&gt; {
&nbsp; await new Promise(res =&gt; setTimeout(res, 100));
&nbsp; return n * n;
<strong>Input:</strong>
fn = async (n) =&gt; {
&nbsp; await new Promise(res =&gt; setTimeout(res, 100));
&nbsp; return n * n;
}
inputs = [5]
t = 50
@@ -37,10 +37,10 @@ The provided function is set to resolve after 100ms. However, the time limit is
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong>
fn = async (n) =&gt; {
&nbsp; await new Promise(res =&gt; setTimeout(res, 100));
&nbsp; return n * n;
<strong>Input:</strong>
fn = async (n) =&gt; {
&nbsp; await new Promise(res =&gt; setTimeout(res, 100));
&nbsp; return n * n;
}
inputs = [5]
t = 150
@@ -52,23 +52,23 @@ The function resolved 5 * 5 = 25 at t=100ms. The time limit is never reached.
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong>
fn = async (a, b) =&gt; {
&nbsp; await new Promise(res =&gt; setTimeout(res, 120));
&nbsp; return a + b;
<strong>Input:</strong>
fn = async (a, b) =&gt; {
&nbsp; await new Promise(res =&gt; setTimeout(res, 120));
&nbsp; return a + b;
}
inputs = [5,10]
t = 150
<strong>Output:</strong> {&quot;resolved&quot;:15,&quot;time&quot;:120}
<strong>Explanation:</strong>
The function resolved 5 + 10 = 15 at t=120ms. The time limit is never reached.
The function resolved 5 + 10 = 15 at t=120ms. The time limit is never reached.
</pre>
<p><strong class="example">Example 4:</strong></p>
<pre>
<strong>Input:</strong>
fn = async () =&gt; {
<strong>Input:</strong>
fn = async () =&gt; {
&nbsp; throw &quot;Error&quot;;
}
inputs = []

View File

@@ -31,7 +31,7 @@ queries[0] is green, queries[1] is red, queries[2] is blue, and queries[3] is pu
<ul>
<li><code>1 &lt;= points.length &lt;= 500</code></li>
<li><code>points[i].length == 2</code></li>
<li><code>0 &lt;= x<sub>i</sub>, y<sub>i</sub> &lt;= 500</code></li>
<li><code>0 &lt;= x<sub>i</sub>, y<sub>i</sub> &lt;= 500</code></li>
<li><code>1 &lt;= queries.length &lt;= 500</code></li>
<li><code>queries[j].length == 3</code></li>
<li><code>0 &lt;= x<sub>j</sub>, y<sub>j</sub> &lt;= 500</code></li>

View File

@@ -1,7 +1,7 @@
<p>Given an input string <code>s</code>&nbsp;and a pattern <code>p</code>, implement regular expression matching with support for <code>&#39;.&#39;</code> and <code>&#39;*&#39;</code> where:</p>
<ul>
<li><code>&#39;.&#39;</code> Matches any single character.</li>
<li><code>&#39;.&#39;</code> Matches any single character.</li>
<li><code>&#39;*&#39;</code> Matches zero or more of the preceding element.</li>
</ul>

View File

@@ -40,5 +40,5 @@ Now s has no occurrences of &quot;xy&quot;.
<ul>
<li><code>1 &lt;= s.length &lt;= 1000</code></li>
<li><code>1 &lt;= part.length &lt;= 1000</code></li>
<li><code>s</code> and <code>part</code> consists of lowercase English letters.</li>
<li><code>s</code> and <code>part</code> consists of lowercase English letters.</li>
</ul>

View File

@@ -1,4 +1,4 @@
<p>Given two strings <code>a</code> and <code>b</code>, return <em>the minimum number of times you should repeat string </em><code>a</code><em> so that string</em> <code>b</code> <em>is a substring of it</em>. If it is impossible for <code>b</code> to be a substring of <code>a</code> after repeating it, return <code>-1</code>.</p>
<p>Given two strings <code>a</code> and <code>b</code>, return <em>the minimum number of times you should repeat string </em><code>a</code><em> so that string</em> <code>b</code> <em>is a substring of it</em>. If it is impossible for <code>b</code> to be a substring of <code>a</code> after repeating it, return <code>-1</code>.</p>
<p><strong>Notice:</strong> string <code>&quot;abc&quot;</code> repeated 0 times is <code>&quot;&quot;</code>, repeated 1 time is <code>&quot;abc&quot;</code> and repeated 2 times is <code>&quot;abcabc&quot;</code>.</p>

View File

@@ -1,4 +1,4 @@
<p>You are given an <code>m x n</code> integer grid <code>accounts</code> where <code>accounts[i][j]</code> is the amount of money the <code>i<sup>th</sup></code> customer has in the <code>j<sup>th</sup></code> bank. Return<em> the <strong>wealth</strong> that the richest customer has.</em></p>
<p>You are given an <code>m x n</code> integer grid <code>accounts</code> where <code>accounts[i][j]</code> is the amount of money the <code>i<sup>th</sup></code> customer has in the <code>j<sup>th</sup></code> bank. Return<em> the <strong>wealth</strong> that the richest customer has.</em></p>
<p>A customer&#39;s <strong>wealth</strong> is the amount of money they have in all their bank accounts. The richest customer is the customer that has the maximum <strong>wealth</strong>.</p>
@@ -19,9 +19,9 @@
<pre>
<strong>Input:</strong> accounts = [[1,5],[7,3],[3,5]]
<strong>Output:</strong> 10
<strong>Explanation</strong>:
<strong>Explanation</strong>:
1st customer has wealth = 6
2nd customer has wealth = 10
2nd customer has wealth = 10
3rd customer has wealth = 8
The 2nd customer is the richest with a wealth of 10.</pre>

View File

@@ -1,4 +1,4 @@
<p>You are given <code>n</code> tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>th</sup></code> task will be available to process at <code>enqueueTime<sub>i</sub></code> and will take <code>processingTime<sub>i</sub></code><sub> </sub>to finish processing.</p>
<p>You are given <code>n</code> tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>th</sup></code> task will be available to process at <code>enqueueTime<sub>i</sub></code> and will take <code>processingTime<sub>i</sub></code><sub> </sub>to finish processing.</p>
<p>You have a single-threaded CPU that can process <strong>at most one</strong> task at a time and will act in the following way:</p>
@@ -17,7 +17,7 @@
<pre>
<strong>Input:</strong> tasks = [[1,2],[2,4],[3,2],[4,1]]
<strong>Output:</strong> [0,2,3,1]
<strong>Explanation: </strong>The events go as follows:
<strong>Explanation: </strong>The events go as follows:
- At time = 1, task 0 is available to process. Available tasks = {0}.
- Also at time = 1, the idle CPU starts processing task 0. Available tasks = {}.
- At time = 2, task 1 is available to process. Available tasks = {1}.

View File

@@ -7,7 +7,7 @@
<li>Another example, the string <code>s = &quot;001&quot;</code> can be split into <code>[&quot;0&quot;, &quot;01&quot;]</code>, <code>[&quot;00&quot;, &quot;1&quot;]</code>, or <code>[&quot;0&quot;, &quot;0&quot;, &quot;1&quot;]</code>. However all the ways are invalid because they have numerical values <code>[0,1]</code>, <code>[0,1]</code>, and <code>[0,0,1]</code> respectively, all of which are not in descending order.</li>
</ul>
<p>Return <code>true</code> <em>if it is possible to split</em> <code>s</code> <em>as described above</em><em>, or </em><code>false</code><em> otherwise.</em></p>
<p>Return <code>true</code> <em>if it is possible to split</em> <code>s</code> <em>as described above</em><em>, or </em><code>false</code><em> otherwise.</em></p>
<p>A <strong>substring</strong> is a contiguous sequence of characters in a string.</p>

View File

@@ -1,6 +1,6 @@
<p>A string is <strong>good</strong> if there are no repeated characters.</p>
<p>Given a string <code>s</code>, return <em>the number of <strong>good substrings</strong> of length <strong>three </strong>in </em><code>s</code>.</p>
<p>Given a string <code>s</code>, return <em>the number of <strong>good substrings</strong> of length <strong>three </strong>in </em><code>s</code>.</p>
<p>Note that if there are multiple occurrences of the same substring, every occurrence should be counted.</p>
@@ -12,7 +12,7 @@
<pre>
<strong>Input:</strong> s = &quot;xyzzaz&quot;
<strong>Output:</strong> 1
<strong>Explanation:</strong> There are 4 substrings of size 3: &quot;xyz&quot;, &quot;yzz&quot;, &quot;zza&quot;, and &quot;zaz&quot;.
<strong>Explanation:</strong> There are 4 substrings of size 3: &quot;xyz&quot;, &quot;yzz&quot;, &quot;zza&quot;, and &quot;zaz&quot;.
The only good substring of length 3 is &quot;xyz&quot;.
</pre>
@@ -30,5 +30,5 @@ The good substrings are &quot;abc&quot;, &quot;bca&quot;, &quot;cab&quot;, and &
<ul>
<li><code>1 &lt;= s.length &lt;= 100</code></li>
<li><code>s</code> consists of lowercase English letters.</li>
<li><code>s</code> consists of lowercase English letters.</li>
</ul>

View File

@@ -67,4 +67,3 @@
</ul>
<p>&nbsp;</p>

View File

@@ -4,7 +4,7 @@
<li>For example, <code>&quot;Hello World&quot;</code>, <code>&quot;HELLO&quot;</code>, and <code>&quot;hello world hello world&quot;</code> are all sentences.</li>
</ul>
<p>You are given a sentence <code>s</code> and an integer <code>k</code>. You want to <strong>truncate</strong> <code>s</code> such that it contains only the <strong>first</strong> <code>k</code> words. Return <code>s</code><em> after <strong>truncating</strong> it.</em></p>
<p>You are given a sentence <code>s</code> and an integer <code>k</code>. You want to <strong>truncate</strong> <code>s</code> such that it contains only the <strong>first</strong> <code>k</code> words. Return <code>s</code><em> after <strong>truncating</strong> it.</em></p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

View File

@@ -6,7 +6,7 @@
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/09/19/points3.png" style="width: 276px; height: 371px;" />
<img alt="" src="https://assets.leetcode.com/uploads/2020/09/19/points3.png" style="width: 276px; height: 371px;" />
<pre>
<strong>Input:</strong> points = [[8,7],[9,9],[7,4],[9,7]]
<strong>Output:</strong> 1