mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
update
This commit is contained in:
parent
f5bf94d67e
commit
f1a542154c
@ -1,6 +1,6 @@
|
||||
# 力扣题库(完整版)
|
||||
|
||||
> 最后更新日期: **2022.05.13**
|
||||
> 最后更新日期: **2022.05.24**
|
||||
>
|
||||
> 使用脚本前请务必仔细完整阅读本 `README.md` 文件
|
||||
|
||||
|
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
165
leetcode-cn/originData/percentage-of-letter-in-string.json
Normal file
165
leetcode-cn/originData/percentage-of-letter-in-string.json
Normal file
File diff suppressed because one or more lines are too long
184
leetcode-cn/originData/sum-of-total-strength-of-wizards.json
Normal file
184
leetcode-cn/originData/sum-of-total-strength-of-wizards.json
Normal file
File diff suppressed because one or more lines are too long
@ -0,0 +1,30 @@
|
||||
<p>给你一个字符串 <code>s</code> 和一个字符 <code>letter</code> ,返回在 <code>s</code> 中等于 <code>letter</code> 字符所占的 <strong>百分比</strong> ,向下取整到最接近的百分比。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>s = "foobar", letter = "o"
|
||||
<strong>输出:</strong>33
|
||||
<strong>解释:</strong>
|
||||
等于字母 'o' 的字符在 s 中占到的百分比是 2 / 6 * 100% = 33% ,向下取整,所以返回 33 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>s = "jjjj", letter = "k"
|
||||
<strong>输出:</strong>0
|
||||
<strong>解释:</strong>
|
||||
等于字母 'k' 的字符在 s 中占到的百分比是 0% ,所以返回 0 。</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= s.length <= 100</code></li>
|
||||
<li><code>s</code> 由小写英文字母组成</li>
|
||||
<li><code>letter</code> 是一个小写英文字母</li>
|
||||
</ul>
|
@ -0,0 +1,55 @@
|
||||
<p>作为国王的统治者,你有一支巫师军队听你指挥。</p>
|
||||
|
||||
<p>给你一个下标从 <strong>0</strong> 开始的整数数组 <code>strength</code> ,其中 <code>strength[i]</code> 表示第 <code>i</code> 位巫师的力量值。对于连续的一组巫师(也就是这些巫师的力量值是 <code>strength</code> 的 <strong>子数组</strong>),<strong>总力量</strong> 定义为以下两个值的 <strong>乘积</strong> :</p>
|
||||
|
||||
<ul>
|
||||
<li>巫师中 <strong>最弱</strong> 的能力值。</li>
|
||||
<li>组中所有巫师的个人力量值 <strong>之和</strong> 。</li>
|
||||
</ul>
|
||||
|
||||
<p>请你返回 <strong>所有</strong> 巫师组的 <strong>总</strong> 力量之和。由于答案可能很大,请将答案对 <code>10<sup>9</sup> + 7</code> <strong>取余</strong> 后返回。</p>
|
||||
|
||||
<p><strong>子数组</strong> 是一个数组里 <strong>非空</strong> 连续子序列。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>strength = [1,3,1,2]
|
||||
<b>输出:</b>44
|
||||
<b>解释:</b>以下是所有连续巫师组:
|
||||
- [<em><strong>1</strong></em>,3,1,2] 中 [1] ,总力量值为 min([1]) * sum([1]) = 1 * 1 = 1
|
||||
- [1,<em><strong>3</strong></em>,1,2] 中 [3] ,总力量值为 min([3]) * sum([3]) = 3 * 3 = 9
|
||||
- [1,3,<em><strong>1</strong></em>,2] 中 [1] ,总力量值为 min([1]) * sum([1]) = 1 * 1 = 1
|
||||
- [1,3,1,<em><strong>2</strong></em>] 中 [2] ,总力量值为 min([2]) * sum([2]) = 2 * 2 = 4
|
||||
- [<em><strong>1,3</strong></em>,1,2] 中 [1,3] ,总力量值为 min([1,3]) * sum([1,3]) = 1 * 4 = 4
|
||||
- [1,<em><strong>3,1</strong></em>,2] 中 [3,1] ,总力量值为 min([3,1]) * sum([3,1]) = 1 * 4 = 4
|
||||
- [1,3,<em><strong>1,2</strong></em>] 中 [1,2] ,总力量值为 min([1,2]) * sum([1,2]) = 1 * 3 = 3
|
||||
- [<em><strong>1,3,1</strong></em>,2] 中 [1,3,1] ,总力量值为 min([1,3,1]) * sum([1,3,1]) = 1 * 5 = 5
|
||||
- [1,<em><strong>3,1,2</strong></em>] 中 [3,1,2] ,总力量值为 min([3,1,2]) * sum([3,1,2]) = 1 * 6 = 6
|
||||
- [<em><strong>1,3,1,2</strong></em>] 中 [1,3,1,2] ,总力量值为 min([1,3,1,2]) * sum([1,3,1,2]) = 1 * 7 = 7
|
||||
所有力量值之和为 1 + 9 + 1 + 4 + 4 + 4 + 3 + 5 + 6 + 7 = 44 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>strength = [5,4,6]
|
||||
<b>输出:</b>213
|
||||
<b>解释:</b>以下是所有连续巫师组:
|
||||
- [<em><strong>5</strong></em>,4,6] 中 [5] ,总力量值为 min([5]) * sum([5]) = 5 * 5 = 25
|
||||
- [5,<em><strong>4</strong></em>,6] 中 [4] ,总力量值为 min([4]) * sum([4]) = 4 * 4 = 16
|
||||
- [5,4,<em><strong>6</strong></em>] 中 [6] ,总力量值为 min([6]) * sum([6]) = 6 * 6 = 36
|
||||
- [<em><strong>5,4</strong></em>,6] 中 [5,4] ,总力量值为 min([5,4]) * sum([5,4]) = 4 * 9 = 36
|
||||
- [5,<em><strong>4,6</strong></em>] 中 [4,6] ,总力量值为 min([4,6]) * sum([4,6]) = 4 * 10 = 40
|
||||
- [<em><strong>5,4,6</strong></em>] 中 [5,4,6] ,总力量值为 min([5,4,6]) * sum([5,4,6]) = 4 * 15 = 60
|
||||
所有力量值之和为 25 + 16 + 36 + 36 + 40 + 60 = 213 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= strength.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= strength[i] <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,41 @@
|
||||
<p>给你一个二维整数数组 <code>stockPrices</code> ,其中 <code>stockPrices[i] = [day<sub>i</sub>, price<sub>i</sub>]</code> 表示股票在 <code>day<sub>i</sub></code> 的价格为 <code>price<sub>i</sub></code> 。<strong>折线图</strong> 是一个二维平面上的若干个点组成的图,横坐标表示日期,纵坐标表示价格,折线图由相邻的点连接而成。比方说下图是一个例子:</p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/30/1920px-pushkin_population_historysvg.png" style="width: 500px; height: 313px;">
|
||||
<p>请你返回要表示一个折线图所需要的 <strong>最少线段数</strong> 。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/03/30/ex0.png" style="width: 400px; height: 400px;"></p>
|
||||
|
||||
<pre><b>输入:</b>stockPrices = [[1,7],[2,6],[3,5],[4,4],[5,4],[6,3],[7,2],[8,1]]
|
||||
<b>输出:</b>3
|
||||
<strong>解释:</strong>
|
||||
上图为输入对应的图,横坐标表示日期,纵坐标表示价格。
|
||||
以下 3 个线段可以表示折线图:
|
||||
- 线段 1 (红色)从 (1,7) 到 (4,4) ,经过 (1,7) ,(2,6) ,(3,5) 和 (4,4) 。
|
||||
- 线段 2 (蓝色)从 (4,4) 到 (5,4) 。
|
||||
- 线段 3 (绿色)从 (5,4) 到 (8,1) ,经过 (5,4) ,(6,3) ,(7,2) 和 (8,1) 。
|
||||
可以证明,无法用少于 3 条线段表示这个折线图。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/03/30/ex1.png" style="width: 325px; height: 325px;"></p>
|
||||
|
||||
<pre><b>输入:</b>stockPrices = [[3,4],[1,2],[7,8],[2,3]]
|
||||
<b>输出:</b>1
|
||||
<strong>解释:</strong>
|
||||
如上图所示,折线图可以用一条线段表示。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= stockPrices.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>stockPrices[i].length == 2</code></li>
|
||||
<li><code>1 <= day<sub>i</sub>, price<sub>i</sub> <= 10<sup>9</sup></code></li>
|
||||
<li>所有 <code>day<sub>i</sub></code> <strong>互不相同</strong> 。</li>
|
||||
</ul>
|
@ -0,0 +1,45 @@
|
||||
<p>现有编号从 <code>0</code> 到 <code>n - 1</code> 的 <code>n</code> 个背包。给你两个下标从 <strong>0</strong> 开始的整数数组 <code>capacity</code> 和 <code>rocks</code> 。第 <code>i</code> 个背包最大可以装 <code>capacity[i]</code> 块石头,当前已经装了 <code>rocks[i]</code> 块石头。另给你一个整数 <code>additionalRocks</code> ,表示<span class="text-only" data-eleid="10" style="white-space: pre;">你可以放置的额外石头数量,石头可以往 </span><strong><span class="text-only" data-eleid="11" style="white-space: pre;">任意</span></strong><span class="text-only" data-eleid="12" style="white-space: pre;"> 背包中放置。</span></p>
|
||||
|
||||
<p>请你将额外的石头放入一些背包中,并返回放置后装满石头的背包的 <strong>最大 </strong>数量<em>。</em></p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>capacity = [2,3,4,5], rocks = [1,2,4,4], additionalRocks = 2
|
||||
<strong>输出:</strong>3
|
||||
<strong>解释:</strong>
|
||||
1 块石头放入背包 0 ,1 块石头放入背包 1 。
|
||||
每个背包中的石头总数是 [2,3,4,4] 。
|
||||
背包 0 、背包 1 和 背包 2 都装满石头。
|
||||
总计 3 个背包装满石头,所以返回 3 。
|
||||
可以证明不存在超过 3 个背包装满石头的情况。
|
||||
注意,可能存在其他放置石头的方案同样能够得到 3 这个结果。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>capacity = [10,2,2], rocks = [2,2,0], additionalRocks = 100
|
||||
<strong>输出:</strong>3
|
||||
<strong>解释:</strong>
|
||||
8 块石头放入背包 0 ,2 块石头放入背包 2 。
|
||||
每个背包中的石头总数是 [10,2,2] 。
|
||||
背包 0 、背包 1 和背包 2 都装满石头。
|
||||
总计 3 个背包装满石头,所以返回 3 。
|
||||
可以证明不存在超过 3 个背包装满石头的情况。
|
||||
注意,不必用完所有的额外石头。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>n == capacity.length == rocks.length</code></li>
|
||||
<li><code>1 <= n <= 5 * 10<sup>4</sup></code></li>
|
||||
<li><code>1 <= capacity[i] <= 10<sup>9</sup></code></li>
|
||||
<li><code>0 <= rocks[i] <= capacity[i]</code></li>
|
||||
<li><code>1 <= additionalRocks <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,28 @@
|
||||
<p>Given a string <code>s</code> and a character <code>letter</code>, return<em> the <strong>percentage</strong> of characters in </em><code>s</code><em> that equal </em><code>letter</code><em> <strong>rounded down</strong> to the nearest whole percent.</em></p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "foobar", letter = "o"
|
||||
<strong>Output:</strong> 33
|
||||
<strong>Explanation:</strong>
|
||||
The percentage of characters in s that equal the letter 'o' is 2 / 6 * 100% = 33% when rounded down, so we return 33.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "jjjj", letter = "k"
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong>
|
||||
The percentage of characters in s that equal the letter 'k' is 0%, so we return 0.</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= s.length <= 100</code></li>
|
||||
<li><code>s</code> consists of lowercase English letters.</li>
|
||||
<li><code>letter</code> is a lowercase English letter.</li>
|
||||
</ul>
|
@ -0,0 +1,55 @@
|
||||
<p>As the ruler of a kingdom, you have an army of wizards at your command.</p>
|
||||
|
||||
<p>You are given a <strong>0-indexed</strong> integer array <code>strength</code>, where <code>strength[i]</code> denotes the strength of the <code>i<sup>th</sup></code> wizard. For a <strong>contiguous</strong> group of wizards (i.e. the wizards' strengths form a <strong>subarray</strong> of <code>strength</code>), the <strong>total strength</strong> is defined as the <strong>product</strong> of the following two values:</p>
|
||||
|
||||
<ul>
|
||||
<li>The strength of the <strong>weakest</strong> wizard in the group.</li>
|
||||
<li>The <strong>total</strong> of all the individual strengths of the wizards in the group.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the <strong>sum</strong> of the total strengths of <strong>all</strong> contiguous groups of wizards</em>. Since the answer may be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
|
||||
|
||||
<p>A <strong>subarray</strong> is a contiguous <strong>non-empty</strong> sequence of elements within an array.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> strength = [1,3,1,2]
|
||||
<strong>Output:</strong> 44
|
||||
<strong>Explanation:</strong> The following are all the contiguous groups of wizards:
|
||||
- [1] from [<u><strong>1</strong></u>,3,1,2] has a total strength of min([1]) * sum([1]) = 1 * 1 = 1
|
||||
- [3] from [1,<u><strong>3</strong></u>,1,2] has a total strength of min([3]) * sum([3]) = 3 * 3 = 9
|
||||
- [1] from [1,3,<u><strong>1</strong></u>,2] has a total strength of min([1]) * sum([1]) = 1 * 1 = 1
|
||||
- [2] from [1,3,1,<u><strong>2</strong></u>] has a total strength of min([2]) * sum([2]) = 2 * 2 = 4
|
||||
- [1,3] from [<u><strong>1,3</strong></u>,1,2] has a total strength of min([1,3]) * sum([1,3]) = 1 * 4 = 4
|
||||
- [3,1] from [1,<u><strong>3,1</strong></u>,2] has a total strength of min([3,1]) * sum([3,1]) = 1 * 4 = 4
|
||||
- [1,2] from [1,3,<u><strong>1,2</strong></u>] has a total strength of min([1,2]) * sum([1,2]) = 1 * 3 = 3
|
||||
- [1,3,1] from [<u><strong>1,3,1</strong></u>,2] has a total strength of min([1,3,1]) * sum([1,3,1]) = 1 * 5 = 5
|
||||
- [3,1,2] from [1,<u><strong>3,1,2</strong></u>] has a total strength of min([3,1,2]) * sum([3,1,2]) = 1 * 6 = 6
|
||||
- [1,3,1,2] from [<u><strong>1,3,1,2</strong></u>] has a total strength of min([1,3,1,2]) * sum([1,3,1,2]) = 1 * 7 = 7
|
||||
The sum of all the total strengths is 1 + 9 + 1 + 4 + 4 + 4 + 3 + 5 + 6 + 7 = 44.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> strength = [5,4,6]
|
||||
<strong>Output:</strong> 213
|
||||
<strong>Explanation:</strong> The following are all the contiguous groups of wizards:
|
||||
- [5] from [<u><strong>5</strong></u>,4,6] has a total strength of min([5]) * sum([5]) = 5 * 5 = 25
|
||||
- [4] from [5,<u><strong>4</strong></u>,6] has a total strength of min([4]) * sum([4]) = 4 * 4 = 16
|
||||
- [6] from [5,4,<u><strong>6</strong></u>] has a total strength of min([6]) * sum([6]) = 6 * 6 = 36
|
||||
- [5,4] from [<u><strong>5,4</strong></u>,6] has a total strength of min([5,4]) * sum([5,4]) = 4 * 9 = 36
|
||||
- [4,6] from [5,<u><strong>4,6</strong></u>] has a total strength of min([4,6]) * sum([4,6]) = 4 * 10 = 40
|
||||
- [5,4,6] from [<u><strong>5,4,6</strong></u>] has a total strength of min([5,4,6]) * sum([5,4,6]) = 4 * 15 = 60
|
||||
The sum of all the total strengths is 25 + 16 + 36 + 36 + 40 + 60 = 213.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= strength.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= strength[i] <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,37 @@
|
||||
<p>You are given a 2D integer array <code>stockPrices</code> where <code>stockPrices[i] = [day<sub>i</sub>, price<sub>i</sub>]</code> indicates the price of the stock on day <code>day<sub>i</sub></code> is <code>price<sub>i</sub></code>. A <strong>line chart</strong> is created from the array by plotting the points on an XY plane with the X-axis representing the day and the Y-axis representing the price and connecting adjacent points. One such example is shown below:</p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/30/1920px-pushkin_population_historysvg.png" style="width: 500px; height: 313px;" />
|
||||
<p>Return <em>the <strong>minimum number of lines</strong> needed to represent the line chart</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/30/ex0.png" style="width: 400px; height: 400px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> stockPrices = [[1,7],[2,6],[3,5],[4,4],[5,4],[6,3],[7,2],[8,1]]
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong>
|
||||
The diagram above represents the input, with the X-axis representing the day and Y-axis representing the price.
|
||||
The following 3 lines can be drawn to represent the line chart:
|
||||
- Line 1 (in red) from (1,7) to (4,4) passing through (1,7), (2,6), (3,5), and (4,4).
|
||||
- Line 2 (in blue) from (4,4) to (5,4).
|
||||
- Line 3 (in green) from (5,4) to (8,1) passing through (5,4), (6,3), (7,2), and (8,1).
|
||||
It can be shown that it is not possible to represent the line chart using less than 3 lines.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/30/ex1.png" style="width: 325px; height: 325px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> stockPrices = [[3,4],[1,2],[7,8],[2,3]]
|
||||
<strong>Output:</strong> 1
|
||||
<strong>Explanation:</strong>
|
||||
As shown in the diagram above, the line chart can be represented with a single line.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= stockPrices.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>stockPrices[i].length == 2</code></li>
|
||||
<li><code>1 <= day<sub>i</sub>, price<sub>i</sub> <= 10<sup>9</sup></code></li>
|
||||
<li>All <code>day<sub>i</sub></code> are <strong>distinct</strong>.</li>
|
||||
</ul>
|
@ -0,0 +1,43 @@
|
||||
<p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</code> rocks. You are also given an integer <code>additionalRocks</code>, the number of additional rocks you can place in <strong>any</strong> of the bags.</p>
|
||||
|
||||
<p>Return<em> the <strong>maximum</strong> number of bags that could have full capacity after placing the additional rocks in some bags.</em></p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> capacity = [2,3,4,5], rocks = [1,2,4,4], additionalRocks = 2
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong>
|
||||
Place 1 rock in bag 0 and 1 rock in bag 1.
|
||||
The number of rocks in each bag are now [2,3,4,4].
|
||||
Bags 0, 1, and 2 have full capacity.
|
||||
There are 3 bags at full capacity, so we return 3.
|
||||
It can be shown that it is not possible to have more than 3 bags at full capacity.
|
||||
Note that there may be other ways of placing the rocks that result in an answer of 3.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> capacity = [10,2,2], rocks = [2,2,0], additionalRocks = 100
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong>
|
||||
Place 8 rocks in bag 0 and 2 rocks in bag 2.
|
||||
The number of rocks in each bag are now [10,2,2].
|
||||
Bags 0, 1, and 2 have full capacity.
|
||||
There are 3 bags at full capacity, so we return 3.
|
||||
It can be shown that it is not possible to have more than 3 bags at full capacity.
|
||||
Note that we did not use all of the additional rocks.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>n == capacity.length == rocks.length</code></li>
|
||||
<li><code>1 <= n <= 5 * 10<sup>4</sup></code></li>
|
||||
<li><code>1 <= capacity[i] <= 10<sup>9</sup></code></li>
|
||||
<li><code>0 <= rocks[i] <= capacity[i]</code></li>
|
||||
<li><code>1 <= additionalRocks <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
186
leetcode/originData/minimum-lines-to-represent-a-line-chart.json
Normal file
186
leetcode/originData/minimum-lines-to-represent-a-line-chart.json
Normal file
File diff suppressed because one or more lines are too long
162
leetcode/originData/percentage-of-letter-in-string.json
Normal file
162
leetcode/originData/percentage-of-letter-in-string.json
Normal file
File diff suppressed because one or more lines are too long
181
leetcode/originData/sum-of-total-strength-of-wizards.json
Normal file
181
leetcode/originData/sum-of-total-strength-of-wizards.json
Normal file
File diff suppressed because one or more lines are too long
@ -0,0 +1,43 @@
|
||||
<p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</code> rocks. You are also given an integer <code>additionalRocks</code>, the number of additional rocks you can place in <strong>any</strong> of the bags.</p>
|
||||
|
||||
<p>Return<em> the <strong>maximum</strong> number of bags that could have full capacity after placing the additional rocks in some bags.</em></p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> capacity = [2,3,4,5], rocks = [1,2,4,4], additionalRocks = 2
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong>
|
||||
Place 1 rock in bag 0 and 1 rock in bag 1.
|
||||
The number of rocks in each bag are now [2,3,4,4].
|
||||
Bags 0, 1, and 2 have full capacity.
|
||||
There are 3 bags at full capacity, so we return 3.
|
||||
It can be shown that it is not possible to have more than 3 bags at full capacity.
|
||||
Note that there may be other ways of placing the rocks that result in an answer of 3.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> capacity = [10,2,2], rocks = [2,2,0], additionalRocks = 100
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong>
|
||||
Place 8 rocks in bag 0 and 2 rocks in bag 2.
|
||||
The number of rocks in each bag are now [10,2,2].
|
||||
Bags 0, 1, and 2 have full capacity.
|
||||
There are 3 bags at full capacity, so we return 3.
|
||||
It can be shown that it is not possible to have more than 3 bags at full capacity.
|
||||
Note that we did not use all of the additional rocks.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>n == capacity.length == rocks.length</code></li>
|
||||
<li><code>1 <= n <= 5 * 10<sup>4</sup></code></li>
|
||||
<li><code>1 <= capacity[i] <= 10<sup>9</sup></code></li>
|
||||
<li><code>0 <= rocks[i] <= capacity[i]</code></li>
|
||||
<li><code>1 <= additionalRocks <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,37 @@
|
||||
<p>You are given a 2D integer array <code>stockPrices</code> where <code>stockPrices[i] = [day<sub>i</sub>, price<sub>i</sub>]</code> indicates the price of the stock on day <code>day<sub>i</sub></code> is <code>price<sub>i</sub></code>. A <strong>line chart</strong> is created from the array by plotting the points on an XY plane with the X-axis representing the day and the Y-axis representing the price and connecting adjacent points. One such example is shown below:</p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/30/1920px-pushkin_population_historysvg.png" style="width: 500px; height: 313px;" />
|
||||
<p>Return <em>the <strong>minimum number of lines</strong> needed to represent the line chart</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/30/ex0.png" style="width: 400px; height: 400px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> stockPrices = [[1,7],[2,6],[3,5],[4,4],[5,4],[6,3],[7,2],[8,1]]
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong>
|
||||
The diagram above represents the input, with the X-axis representing the day and Y-axis representing the price.
|
||||
The following 3 lines can be drawn to represent the line chart:
|
||||
- Line 1 (in red) from (1,7) to (4,4) passing through (1,7), (2,6), (3,5), and (4,4).
|
||||
- Line 2 (in blue) from (4,4) to (5,4).
|
||||
- Line 3 (in green) from (5,4) to (8,1) passing through (5,4), (6,3), (7,2), and (8,1).
|
||||
It can be shown that it is not possible to represent the line chart using less than 3 lines.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/30/ex1.png" style="width: 325px; height: 325px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> stockPrices = [[3,4],[1,2],[7,8],[2,3]]
|
||||
<strong>Output:</strong> 1
|
||||
<strong>Explanation:</strong>
|
||||
As shown in the diagram above, the line chart can be represented with a single line.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= stockPrices.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>stockPrices[i].length == 2</code></li>
|
||||
<li><code>1 <= day<sub>i</sub>, price<sub>i</sub> <= 10<sup>9</sup></code></li>
|
||||
<li>All <code>day<sub>i</sub></code> are <strong>distinct</strong>.</li>
|
||||
</ul>
|
28
leetcode/problem/percentage-of-letter-in-string.html
Normal file
28
leetcode/problem/percentage-of-letter-in-string.html
Normal file
@ -0,0 +1,28 @@
|
||||
<p>Given a string <code>s</code> and a character <code>letter</code>, return<em> the <strong>percentage</strong> of characters in </em><code>s</code><em> that equal </em><code>letter</code><em> <strong>rounded down</strong> to the nearest whole percent.</em></p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "foobar", letter = "o"
|
||||
<strong>Output:</strong> 33
|
||||
<strong>Explanation:</strong>
|
||||
The percentage of characters in s that equal the letter 'o' is 2 / 6 * 100% = 33% when rounded down, so we return 33.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "jjjj", letter = "k"
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong>
|
||||
The percentage of characters in s that equal the letter 'k' is 0%, so we return 0.</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= s.length <= 100</code></li>
|
||||
<li><code>s</code> consists of lowercase English letters.</li>
|
||||
<li><code>letter</code> is a lowercase English letter.</li>
|
||||
</ul>
|
55
leetcode/problem/sum-of-total-strength-of-wizards.html
Normal file
55
leetcode/problem/sum-of-total-strength-of-wizards.html
Normal file
@ -0,0 +1,55 @@
|
||||
<p>As the ruler of a kingdom, you have an army of wizards at your command.</p>
|
||||
|
||||
<p>You are given a <strong>0-indexed</strong> integer array <code>strength</code>, where <code>strength[i]</code> denotes the strength of the <code>i<sup>th</sup></code> wizard. For a <strong>contiguous</strong> group of wizards (i.e. the wizards' strengths form a <strong>subarray</strong> of <code>strength</code>), the <strong>total strength</strong> is defined as the <strong>product</strong> of the following two values:</p>
|
||||
|
||||
<ul>
|
||||
<li>The strength of the <strong>weakest</strong> wizard in the group.</li>
|
||||
<li>The <strong>total</strong> of all the individual strengths of the wizards in the group.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the <strong>sum</strong> of the total strengths of <strong>all</strong> contiguous groups of wizards</em>. Since the answer may be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
|
||||
|
||||
<p>A <strong>subarray</strong> is a contiguous <strong>non-empty</strong> sequence of elements within an array.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> strength = [1,3,1,2]
|
||||
<strong>Output:</strong> 44
|
||||
<strong>Explanation:</strong> The following are all the contiguous groups of wizards:
|
||||
- [1] from [<u><strong>1</strong></u>,3,1,2] has a total strength of min([1]) * sum([1]) = 1 * 1 = 1
|
||||
- [3] from [1,<u><strong>3</strong></u>,1,2] has a total strength of min([3]) * sum([3]) = 3 * 3 = 9
|
||||
- [1] from [1,3,<u><strong>1</strong></u>,2] has a total strength of min([1]) * sum([1]) = 1 * 1 = 1
|
||||
- [2] from [1,3,1,<u><strong>2</strong></u>] has a total strength of min([2]) * sum([2]) = 2 * 2 = 4
|
||||
- [1,3] from [<u><strong>1,3</strong></u>,1,2] has a total strength of min([1,3]) * sum([1,3]) = 1 * 4 = 4
|
||||
- [3,1] from [1,<u><strong>3,1</strong></u>,2] has a total strength of min([3,1]) * sum([3,1]) = 1 * 4 = 4
|
||||
- [1,2] from [1,3,<u><strong>1,2</strong></u>] has a total strength of min([1,2]) * sum([1,2]) = 1 * 3 = 3
|
||||
- [1,3,1] from [<u><strong>1,3,1</strong></u>,2] has a total strength of min([1,3,1]) * sum([1,3,1]) = 1 * 5 = 5
|
||||
- [3,1,2] from [1,<u><strong>3,1,2</strong></u>] has a total strength of min([3,1,2]) * sum([3,1,2]) = 1 * 6 = 6
|
||||
- [1,3,1,2] from [<u><strong>1,3,1,2</strong></u>] has a total strength of min([1,3,1,2]) * sum([1,3,1,2]) = 1 * 7 = 7
|
||||
The sum of all the total strengths is 1 + 9 + 1 + 4 + 4 + 4 + 3 + 5 + 6 + 7 = 44.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> strength = [5,4,6]
|
||||
<strong>Output:</strong> 213
|
||||
<strong>Explanation:</strong> The following are all the contiguous groups of wizards:
|
||||
- [5] from [<u><strong>5</strong></u>,4,6] has a total strength of min([5]) * sum([5]) = 5 * 5 = 25
|
||||
- [4] from [5,<u><strong>4</strong></u>,6] has a total strength of min([4]) * sum([4]) = 4 * 4 = 16
|
||||
- [6] from [5,4,<u><strong>6</strong></u>] has a total strength of min([6]) * sum([6]) = 6 * 6 = 36
|
||||
- [5,4] from [<u><strong>5,4</strong></u>,6] has a total strength of min([5,4]) * sum([5,4]) = 4 * 9 = 36
|
||||
- [4,6] from [5,<u><strong>4,6</strong></u>] has a total strength of min([4,6]) * sum([4,6]) = 4 * 10 = 40
|
||||
- [5,4,6] from [<u><strong>5,4,6</strong></u>] has a total strength of min([5,4,6]) * sum([5,4,6]) = 4 * 15 = 60
|
||||
The sum of all the total strengths is 25 + 16 + 36 + 36 + 40 + 60 = 213.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= strength.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= strength[i] <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
Loading…
Reference in New Issue
Block a user