mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-03 14:32:54 +08:00
update
This commit is contained in:
180
leetcode/originData/check-distances-between-same-letters.json
Normal file
180
leetcode/originData/check-distances-between-same-letters.json
Normal file
File diff suppressed because one or more lines are too long
178
leetcode/originData/coin-change-ii.json
Normal file
178
leetcode/originData/coin-change-ii.json
Normal file
File diff suppressed because one or more lines are too long
174
leetcode/originData/find-subarrays-with-equal-sum.json
Normal file
174
leetcode/originData/find-subarrays-with-equal-sum.json
Normal file
File diff suppressed because one or more lines are too long
199
leetcode/originData/maximum-number-of-robots-within-budget.json
Normal file
199
leetcode/originData/maximum-number-of-robots-within-budget.json
Normal file
File diff suppressed because one or more lines are too long
42
leetcode/problem/check-distances-between-same-letters.html
Normal file
42
leetcode/problem/check-distances-between-same-letters.html
Normal file
@@ -0,0 +1,42 @@
|
||||
<p>You are given a <strong>0-indexed</strong> string <code>s</code> consisting of only lowercase English letters, where each letter in <code>s</code> appears <strong>exactly</strong> <strong>twice</strong>. You are also given a <strong>0-indexed</strong> integer array <code>distance</code> of length <code>26</code>.</p>
|
||||
|
||||
<p>Each letter in the alphabet is numbered from <code>0</code> to <code>25</code> (i.e. <code>'a' -> 0</code>, <code>'b' -> 1</code>, <code>'c' -> 2</code>, ... , <code>'z' -> 25</code>).</p>
|
||||
|
||||
<p>In a <strong>well-spaced</strong> string, the number of letters between the two occurrences of the <code>i<sup>th</sup></code> letter is <code>distance[i]</code>. If the <code>i<sup>th</sup></code> letter does not appear in <code>s</code>, then <code>distance[i]</code> can be <strong>ignored</strong>.</p>
|
||||
|
||||
<p>Return <code>true</code><em> if </em><code>s</code><em> is a <strong>well-spaced</strong> string, otherwise return </em><code>false</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "abaccb", distance = [1,3,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong>
|
||||
- 'a' appears at indices 0 and 2 so it satisfies distance[0] = 1.
|
||||
- 'b' appears at indices 1 and 5 so it satisfies distance[1] = 3.
|
||||
- 'c' appears at indices 3 and 4 so it satisfies distance[2] = 0.
|
||||
Note that distance[3] = 5, but since 'd' does not appear in s, it can be ignored.
|
||||
Return true because s is a well-spaced string.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "aa", distance = [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation:</strong>
|
||||
- 'a' appears at indices 0 and 1 so there are zero letters between them.
|
||||
Because distance[0] = 1, s is not a well-spaced string.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= s.length <= 52</code></li>
|
||||
<li><code>s</code> consists only of lowercase English letters.</li>
|
||||
<li>Each letter appears in <code>s</code> exactly twice.</li>
|
||||
<li><code>distance.length == 26</code></li>
|
||||
<li><code>0 <= distance[i] <= 50</code></li>
|
||||
</ul>
|
45
leetcode/problem/coin-change-ii.html
Normal file
45
leetcode/problem/coin-change-ii.html
Normal file
@@ -0,0 +1,45 @@
|
||||
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
|
||||
|
||||
<p>Return <em>the number of combinations that make up that amount</em>. If that amount of money cannot be made up by any combination of the coins, return <code>0</code>.</p>
|
||||
|
||||
<p>You may assume that you have an infinite number of each kind of coin.</p>
|
||||
|
||||
<p>The answer is <strong>guaranteed</strong> to fit into a signed <strong>32-bit</strong> integer.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> amount = 5, coins = [1,2,5]
|
||||
<strong>Output:</strong> 4
|
||||
<strong>Explanation:</strong> there are four ways to make up the amount:
|
||||
5=5
|
||||
5=2+2+1
|
||||
5=2+1+1+1
|
||||
5=1+1+1+1+1
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> amount = 3, coins = [2]
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong> the amount of 3 cannot be made up just with coins of 2.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> amount = 10, coins = [10]
|
||||
<strong>Output:</strong> 1
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= coins.length <= 300</code></li>
|
||||
<li><code>1 <= coins[i] <= 5000</code></li>
|
||||
<li>All the values of <code>coins</code> are <strong>unique</strong>.</li>
|
||||
<li><code>0 <= amount <= 5000</code></li>
|
||||
</ul>
|
39
leetcode/problem/find-subarrays-with-equal-sum.html
Normal file
39
leetcode/problem/find-subarrays-with-equal-sum.html
Normal file
@@ -0,0 +1,39 @@
|
||||
<p>Given a <strong>0-indexed</strong> integer array <code>nums</code>, determine whether there exist <strong>two</strong> subarrays of length <code>2</code> with <strong>equal</strong> sum. Note that the two subarrays must begin at <strong>different</strong> indices.</p>
|
||||
|
||||
<p>Return <code>true</code><em> if these subarrays exist, and </em><code>false</code><em> otherwise.</em></p>
|
||||
|
||||
<p>A <b>subarray</b> is a contiguous non-empty sequence of elements within an array.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [4,2,4]
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong> The subarrays with elements [4,2] and [2,4] have the same sum of 6.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,2,3,4,5]
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation:</strong> No two subarrays of size 2 have the same sum.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [0,0,0]
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong> The subarrays [nums[0],nums[1]] and [nums[1],nums[2]] have the same sum of 0.
|
||||
Note that even though the subarrays have the same content, the two subarrays are considered different because they are in different positions in the original array.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= nums.length <= 1000</code></li>
|
||||
<li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
35
leetcode/problem/maximum-number-of-robots-within-budget.html
Normal file
35
leetcode/problem/maximum-number-of-robots-within-budget.html
Normal file
@@ -0,0 +1,35 @@
|
||||
<p>You have <code>n</code> robots. You are given two <strong>0-indexed</strong> integer arrays, <code>chargeTimes</code> and <code>runningCosts</code>, both of length <code>n</code>. The <code>i<sup>th</sup></code> robot costs <code>chargeTimes[i]</code> units to charge and costs <code>runningCosts[i]</code> units to run. You are also given an integer <code>budget</code>.</p>
|
||||
|
||||
<p>The <strong>total cost</strong> of running <code>k</code> chosen robots is equal to <code>max(chargeTimes) + k * sum(runningCosts)</code>, where <code>max(chargeTimes)</code> is the largest charge cost among the <code>k</code> robots and <code>sum(runningCosts)</code> is the sum of running costs among the <code>k</code> robots.</p>
|
||||
|
||||
<p>Return<em> the <strong>maximum</strong> number of <strong>consecutive</strong> robots you can run such that the total cost <strong>does not</strong> exceed </em><code>budget</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> chargeTimes = [3,6,1,3,4], runningCosts = [2,1,3,4,5], budget = 25
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong>
|
||||
It is possible to run all individual and consecutive pairs of robots within budget.
|
||||
To obtain answer 3, consider the first 3 robots. The total cost will be max(3,6,1) + 3 * sum(2,1,3) = 6 + 3 * 6 = 24 which is less than 25.
|
||||
It can be shown that it is not possible to run more than 3 consecutive robots within budget, so we return 3.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> chargeTimes = [11,12,19], runningCosts = [10,8,7], budget = 19
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong> No robot can be run that does not exceed the budget, so we return 0.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>chargeTimes.length == runningCosts.length == n</code></li>
|
||||
<li><code>1 <= n <= 5 * 10<sup>4</sup></code></li>
|
||||
<li><code>1 <= chargeTimes[i], runningCosts[i] <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= budget <= 10<sup>15</sup></code></li>
|
||||
</ul>
|
Reference in New Issue
Block a user