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
ee13c73307
commit
a38bcc80d1
@ -1,6 +1,6 @@
|
|||||||
# 力扣题库(完整版)
|
# 力扣题库(完整版)
|
||||||
|
|
||||||
> 最后更新日期: **2022.10.07**
|
> 最后更新日期: **2022.10.15**
|
||||||
>
|
>
|
||||||
> 使用脚本前请务必仔细完整阅读本 `README.md` 文件
|
> 使用脚本前请务必仔细完整阅读本 `README.md` 文件
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
174
leetcode-cn/originData/coin-change-ii.json
Normal file
174
leetcode-cn/originData/coin-change-ii.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,50 @@
|
|||||||
|
<p>给你一个字符串 <code>s</code> 和一个机器人,机器人当前有一个空字符串 <code>t</code> 。执行以下操作之一,直到 <code>s</code> 和 <code>t</code> <strong>都变成空字符串:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>删除字符串 <code>s</code> 的 <strong>第一个</strong> 字符,并将该字符给机器人。机器人把这个字符添加到 <code>t</code> 的尾部。</li>
|
||||||
|
<li>删除字符串 <code>t</code> 的 <strong>最后一个</strong> 字符,并将该字符给机器人。机器人将该字符写到纸上。</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>请你返回纸上能写出的字典序最小的字符串。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre><b>输入:</b>s = "zza"
|
||||||
|
<b>输出:</b>"azz"
|
||||||
|
<b>解释:</b>用 p 表示写出来的字符串。
|
||||||
|
一开始,p="" ,s="zza" ,t="" 。
|
||||||
|
执行第一个操作三次,得到 p="" ,s="" ,t="zza" 。
|
||||||
|
执行第二个操作三次,得到 p="azz" ,s="" ,t="" 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre><b>输入:</b>s = "bac"
|
||||||
|
<b>输出:</b>"abc"
|
||||||
|
<b>解释:</b>用 p 表示写出来的字符串。
|
||||||
|
执行第一个操作两次,得到 p="" ,s="c" ,t="ba" 。
|
||||||
|
执行第二个操作两次,得到 p="ab" ,s="c" ,t="" 。
|
||||||
|
执行第一个操作,得到 p="ab" ,s="" ,t="c" 。
|
||||||
|
执行第二个操作,得到 p="abc" ,s="" ,t="" 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 3:</strong></p>
|
||||||
|
|
||||||
|
<pre><b>输入:</b>s = "bdda"
|
||||||
|
<b>输出:</b>"addb"
|
||||||
|
<b>解释:</b>用 p 表示写出来的字符串。
|
||||||
|
一开始,p="" ,s="bdda" ,t="" 。
|
||||||
|
执行第一个操作四次,得到 p="" ,s="" ,t="bdda" 。
|
||||||
|
执行第二个操作四次,得到 p="addb" ,s="" ,t="" 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= s.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>s</code> 只包含小写英文字母。</li>
|
||||||
|
</ul>
|
@ -0,0 +1,65 @@
|
|||||||
|
<p>共有 <code>n</code> 位员工,每位员工都有一个从 <code>0</code> 到 <code>n - 1</code> 的唯一 id 。</p>
|
||||||
|
|
||||||
|
<p>给你一个二维整数数组 <code>logs</code> ,其中 <code>logs[i] = [id<sub>i</sub>, leaveTime<sub>i</sub>]</code> :</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>id<sub>i</sub></code> 是处理第 <code>i</code> 个任务的员工的 id ,且</li>
|
||||||
|
<li><code>leaveTime<sub>i</sub></code> 是员工完成第 <code>i</code> 个任务的时刻。所有 <code>leaveTime<sub>i</sub></code> 的值都是 <strong>唯一</strong> 的。</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>注意,第 <code>i</code> 个任务在第 <code>(i - 1)</code> 个任务结束后立即开始,且第 <code>0</code> 个任务从时刻 <code>0</code> 开始。</p>
|
||||||
|
|
||||||
|
<p>返回处理用时最长的那个任务的员工的 id 。如果存在两个或多个员工同时满足,则返回几人中 <strong>最小</strong> 的 id 。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>输入:</strong>n = 10, logs = [[0,3],[2,5],[0,9],[1,15]]
|
||||||
|
<strong>输出:</strong>1
|
||||||
|
<strong>解释:</strong>
|
||||||
|
任务 0 于时刻 0 开始,且在时刻 3 结束,共计 3 个单位时间。
|
||||||
|
任务 1 于时刻 3 开始,且在时刻 5 结束,共计 2 个单位时间。
|
||||||
|
任务 2 于时刻 5 开始,且在时刻 9 结束,共计 4 个单位时间。
|
||||||
|
任务 3 于时刻 9 开始,且在时刻 15 结束,共计 6 个单位时间。
|
||||||
|
时间最长的任务是任务 3 ,而 id 为 1 的员工是处理此任务的员工,所以返回 1 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>输入:</strong>n = 26, logs = [[1,1],[3,7],[2,12],[7,17]]
|
||||||
|
<strong>输出:</strong>3
|
||||||
|
<strong>解释:</strong>
|
||||||
|
任务 0 于时刻 0 开始,且在时刻 1 结束,共计 1 个单位时间。
|
||||||
|
任务 1 于时刻 1 开始,且在时刻 7 结束,共计 6 个单位时间。
|
||||||
|
任务 2 于时刻 7 开始,且在时刻 12 结束,共计 5 个单位时间。
|
||||||
|
任务 3 于时刻 12 开始,且在时刻 17 结束,共计 5 个单位时间。
|
||||||
|
时间最长的任务是任务 1 ,而 id 为 3 的员工是处理此任务的员工,所以返回 3 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 3:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>输入:</strong>n = 2, logs = [[0,10],[1,20]]
|
||||||
|
<strong>输出:</strong>0
|
||||||
|
<strong>解释:</strong>
|
||||||
|
任务 0 于时刻 0 开始,且在时刻 10 结束,共计 10 个单位时间。
|
||||||
|
任务 1 于时刻 10 开始,且在时刻 20 结束,共计 10 个单位时间。
|
||||||
|
时间最长的任务是任务 0 和 1 ,处理这两个任务的员工的 id 分别是 0 和 1 ,所以返回最小的 0 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>2 <= n <= 500</code></li>
|
||||||
|
<li><code>1 <= logs.length <= 500</code></li>
|
||||||
|
<li><code>logs[i].length == 2</code></li>
|
||||||
|
<li><code>0 <= id<sub>i</sub> <= n - 1</code></li>
|
||||||
|
<li><code>1 <= leaveTime<sub>i</sub> <= 500</code></li>
|
||||||
|
<li><code>id<sub>i</sub> != id<sub>i + 1</sub></code></li>
|
||||||
|
<li><code>leaveTime<sub>i</sub></code> 按严格递增顺序排列</li>
|
||||||
|
</ul>
|
@ -0,0 +1,39 @@
|
|||||||
|
<p>给你一个长度为 <code>n</code> 的 <strong>整数</strong> 数组 <code>pref</code> 。找出并返回满足下述条件且长度为 <code>n</code> 的数组<em> </em><code>arr</code> :</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>pref[i] = arr[0] ^ arr[1] ^ ... ^ arr[i]</code>.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>注意 <code>^</code> 表示 <strong>按位异或</strong>(bitwise-xor)运算。</p>
|
||||||
|
|
||||||
|
<p>可以证明答案是 <strong>唯一</strong> 的。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre><strong>输入:</strong>pref = [5,2,0,3,1]
|
||||||
|
<strong>输出:</strong>[5,7,2,3,2]
|
||||||
|
<strong>解释:</strong>从数组 [5,7,2,3,2] 可以得到如下结果:
|
||||||
|
- pref[0] = 5
|
||||||
|
- pref[1] = 5 ^ 7 = 2
|
||||||
|
- pref[2] = 5 ^ 7 ^ 2 = 0
|
||||||
|
- pref[3] = 5 ^ 7 ^ 2 ^ 3 = 3
|
||||||
|
- pref[4] = 5 ^ 7 ^ 2 ^ 3 ^ 2 = 1
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre><strong>输入:</strong>pref = [13]
|
||||||
|
<strong>输出:</strong>[13]
|
||||||
|
<strong>解释:</strong>pref[0] = arr[0] = 13
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= pref.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>0 <= pref[i] <= 10<sup>6</sup></code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,43 @@
|
|||||||
|
<p>给你一个下标从 <strong>0</strong> 开始的 <code>m x n</code> 整数矩阵 <code>grid</code> 和一个整数 <code>k</code> 。你从起点 <code>(0, 0)</code> 出发,每一步只能往 <strong>下</strong> 或者往 <strong>右</strong> ,你想要到达终点 <code>(m - 1, n - 1)</code> 。</p>
|
||||||
|
|
||||||
|
<p>请你返回路径和能被 <code>k</code> 整除的路径数目,由于答案可能很大,返回答案对 <code>10<sup>9</sup> + 7</code> <strong>取余</strong> 的结果。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<p><img src="https://assets.leetcode.com/uploads/2022/08/13/image-20220813183124-1.png" style="width: 437px; height: 200px;"></p>
|
||||||
|
|
||||||
|
<pre><b>输入:</b>grid = [[5,2,4],[3,0,5],[0,7,2]], k = 3
|
||||||
|
<b>输出:</b>2
|
||||||
|
<b>解释:</b>有两条路径满足路径上元素的和能被 k 整除。
|
||||||
|
第一条路径为上图中用红色标注的路径,和为 5 + 2 + 4 + 5 + 2 = 18 ,能被 3 整除。
|
||||||
|
第二条路径为上图中用蓝色标注的路径,和为 5 + 3 + 0 + 5 + 2 = 15 ,能被 3 整除。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
<img src="https://assets.leetcode.com/uploads/2022/08/17/image-20220817112930-3.png" style="height: 85px; width: 132px;">
|
||||||
|
<pre><b>输入:</b>grid = [[0,0]], k = 5
|
||||||
|
<b>输出:</b>1
|
||||||
|
<b>解释:</b>红色标注的路径和为 0 + 0 = 0 ,能被 5 整除。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 3:</strong></p>
|
||||||
|
<img src="https://assets.leetcode.com/uploads/2022/08/12/image-20220812224605-3.png" style="width: 257px; height: 200px;">
|
||||||
|
<pre><b>输入:</b>grid = [[7,3,4,9],[2,3,6,2],[2,3,7,0]], k = 1
|
||||||
|
<b>输出:</b>10
|
||||||
|
<b>解释:</b>每个数字都能被 1 整除,所以每一条路径的和都能被 k 整除。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>m == grid.length</code></li>
|
||||||
|
<li><code>n == grid[i].length</code></li>
|
||||||
|
<li><code>1 <= m, n <= 5 * 10<sup>4</sup></code></li>
|
||||||
|
<li><code>1 <= m * n <= 5 * 10<sup>4</sup></code></li>
|
||||||
|
<li><code>0 <= grid[i][j] <= 100</code></li>
|
||||||
|
<li><code>1 <= k <= 50</code></li>
|
||||||
|
</ul>
|
50
leetcode-cn/problem (Chinese)/零钱兑换 II [coin-change-ii].html
Normal file
50
leetcode-cn/problem (Chinese)/零钱兑换 II [coin-change-ii].html
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<p>给你一个整数数组 <code>coins</code> 表示不同面额的硬币,另给一个整数 <code>amount</code> 表示总金额。</p>
|
||||||
|
|
||||||
|
<p>请你计算并返回可以凑成总金额的硬币组合数。如果任何硬币组合都无法凑出总金额,返回 <code>0</code> 。</p>
|
||||||
|
|
||||||
|
<p>假设每一种面额的硬币有无限个。 </p>
|
||||||
|
|
||||||
|
<p>题目数据保证结果符合 32 位带符号整数。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>输入:</strong>amount = 5, coins = [1, 2, 5]
|
||||||
|
<strong>输出:</strong>4
|
||||||
|
<strong>解释:</strong>有四种方式可以凑成总金额:
|
||||||
|
5=5
|
||||||
|
5=2+2+1
|
||||||
|
5=2+1+1+1
|
||||||
|
5=1+1+1+1+1
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>输入:</strong>amount = 3, coins = [2]
|
||||||
|
<strong>输出:</strong>0
|
||||||
|
<strong>解释:</strong>只用面额 2 的硬币不能凑成总金额 3 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 3:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>输入:</strong>amount = 10, coins = [10]
|
||||||
|
<strong>输出:</strong>1
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= coins.length <= 300</code></li>
|
||||||
|
<li><code>1 <= coins[i] <= 5000</code></li>
|
||||||
|
<li><code>coins</code> 中的所有值 <strong>互不相同</strong></li>
|
||||||
|
<li><code>0 <= amount <= 5000</code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,51 @@
|
|||||||
|
<p>You are given a string <code>s</code> and a robot that currently holds an empty string <code>t</code>. Apply one of the following operations until <code>s</code> and <code>t</code> <strong>are both empty</strong>:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>Remove the <strong>first</strong> character of a string <code>s</code> and give it to the robot. The robot will append this character to the string <code>t</code>.</li>
|
||||||
|
<li>Remove the <strong>last</strong> character of a string <code>t</code> and give it to the robot. The robot will write this character on paper.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Return <em>the lexicographically smallest string that can be written on the paper.</em></p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> s = "zza"
|
||||||
|
<strong>Output:</strong> "azz"
|
||||||
|
<strong>Explanation:</strong> Let p denote the written string.
|
||||||
|
Initially p="", s="zza", t="".
|
||||||
|
Perform first operation three times p="", s="", t="zza".
|
||||||
|
Perform second operation three times p="azz", s="", t="".
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> s = "bac"
|
||||||
|
<strong>Output:</strong> "abc"
|
||||||
|
<strong>Explanation:</strong> Let p denote the written string.
|
||||||
|
Perform first operation twice p="", s="c", t="ba".
|
||||||
|
Perform second operation twice p="ab", s="c", t="".
|
||||||
|
Perform first operation p="ab", s="", t="c".
|
||||||
|
Perform second operation p="abc", s="", t="".
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 3:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> s = "bdda"
|
||||||
|
<strong>Output:</strong> "addb"
|
||||||
|
<strong>Explanation:</strong> Let p denote the written string.
|
||||||
|
Initially p="", s="bdda", t="".
|
||||||
|
Perform first operation four times p="", s="", t="bdda".
|
||||||
|
Perform second operation four times p="addb", s="", t="".
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= s.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>s</code> consists of only English lowercase letters.</li>
|
||||||
|
</ul>
|
@ -0,0 +1,63 @@
|
|||||||
|
<p>There are <code>n</code> employees, each with a unique id from <code>0</code> to <code>n - 1</code>.</p>
|
||||||
|
|
||||||
|
<p>You are given a 2D integer array <code>logs</code> where <code>logs[i] = [id<sub>i</sub>, leaveTime<sub>i</sub>]</code> where:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>id<sub>i</sub></code> is the id of the employee that worked on the <code>i<sup>th</sup></code> task, and</li>
|
||||||
|
<li><code>leaveTime<sub>i</sub></code> is the time at which the employee finished the <code>i<sup>th</sup></code> task. All the values <code>leaveTime<sub>i</sub></code> are <strong>unique</strong>.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Note that the <code>i<sup>th</sup></code> task starts the moment right after the <code>(i - 1)<sup>th</sup></code> task ends, and the <code>0<sup>th</sup></code> task starts at time <code>0</code>.</p>
|
||||||
|
|
||||||
|
<p>Return <em>the id of the employee that worked the task with the longest time.</em> If there is a tie between two or more employees, return<em> the <strong>smallest</strong> id among them</em>.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> n = 10, logs = [[0,3],[2,5],[0,9],[1,15]]
|
||||||
|
<strong>Output:</strong> 1
|
||||||
|
<strong>Explanation:</strong>
|
||||||
|
Task 0 started at 0 and ended at 3 with 3 units of times.
|
||||||
|
Task 1 started at 3 and ended at 5 with 2 units of times.
|
||||||
|
Task 2 started at 5 and ended at 9 with 4 units of times.
|
||||||
|
Task 3 started at 9 and ended at 15 with 6 units of times.
|
||||||
|
The task with the longest time is task 3 and the employee with id 1 is the one that worked on it, so we return 1.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> n = 26, logs = [[1,1],[3,7],[2,12],[7,17]]
|
||||||
|
<strong>Output:</strong> 3
|
||||||
|
<strong>Explanation:</strong>
|
||||||
|
Task 0 started at 0 and ended at 1 with 1 unit of times.
|
||||||
|
Task 1 started at 1 and ended at 7 with 6 units of times.
|
||||||
|
Task 2 started at 7 and ended at 12 with 5 units of times.
|
||||||
|
Task 3 started at 12 and ended at 17 with 5 units of times.
|
||||||
|
The tasks with the longest time is task 1. The employees that worked on it is 3, so we return 3.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 3:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> n = 2, logs = [[0,10],[1,20]]
|
||||||
|
<strong>Output:</strong> 0
|
||||||
|
<strong>Explanation:</strong>
|
||||||
|
Task 0 started at 0 and ended at 10 with 10 units of times.
|
||||||
|
Task 1 started at 10 and ended at 20 with 10 units of times.
|
||||||
|
The tasks with the longest time are tasks 0 and 1. The employees that worked on them are 0 and 1, so we return the smallest id 0.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>2 <= n <= 500</code></li>
|
||||||
|
<li><code>1 <= logs.length <= 500</code></li>
|
||||||
|
<li><code>logs[i].length == 2</code></li>
|
||||||
|
<li><code>0 <= id<sub>i</sub> <= n - 1</code></li>
|
||||||
|
<li><code>1 <= leaveTime<sub>i</sub> <= 500</code></li>
|
||||||
|
<li><code>id<sub>i</sub> != id<sub>i+1</sub></code></li>
|
||||||
|
<li><code>leaveTime<sub>i</sub></code> are sorted in a strictly increasing order.</li>
|
||||||
|
</ul>
|
@ -0,0 +1,39 @@
|
|||||||
|
<p>You are given an <strong>integer</strong> array <code>pref</code> of size <code>n</code>. Find and return <em>the array </em><code>arr</code><em> of size </em><code>n</code><em> that satisfies</em>:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>pref[i] = arr[0] ^ arr[1] ^ ... ^ arr[i]</code>.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Note that <code>^</code> denotes the <strong>bitwise-xor</strong> operation.</p>
|
||||||
|
|
||||||
|
<p>It can be proven that the answer is <strong>unique</strong>.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> pref = [5,2,0,3,1]
|
||||||
|
<strong>Output:</strong> [5,7,2,3,2]
|
||||||
|
<strong>Explanation:</strong> From the array [5,7,2,3,2] we have the following:
|
||||||
|
- pref[0] = 5.
|
||||||
|
- pref[1] = 5 ^ 7 = 2.
|
||||||
|
- pref[2] = 5 ^ 7 ^ 2 = 0.
|
||||||
|
- pref[3] = 5 ^ 7 ^ 2 ^ 3 = 3.
|
||||||
|
- pref[4] = 5 ^ 7 ^ 2 ^ 3 ^ 2 = 1.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> pref = [13]
|
||||||
|
<strong>Output:</strong> [13]
|
||||||
|
<strong>Explanation:</strong> We have pref[0] = arr[0] = 13.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= pref.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>0 <= pref[i] <= 10<sup>6</sup></code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,42 @@
|
|||||||
|
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> integer matrix <code>grid</code> and an integer <code>k</code>. You are currently at position <code>(0, 0)</code> and you want to reach position <code>(m - 1, n - 1)</code> moving only <strong>down</strong> or <strong>right</strong>.</p>
|
||||||
|
|
||||||
|
<p>Return<em> the number of paths where the sum of the elements on the path is divisible by </em><code>k</code>. Since the answer may be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
<img src="https://assets.leetcode.com/uploads/2022/08/13/image-20220813183124-1.png" style="width: 437px; height: 200px;" />
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> grid = [[5,2,4],[3,0,5],[0,7,2]], k = 3
|
||||||
|
<strong>Output:</strong> 2
|
||||||
|
<strong>Explanation:</strong> There are two paths where the sum of the elements on the path is divisible by k.
|
||||||
|
The first path highlighted in red has a sum of 5 + 2 + 4 + 5 + 2 = 18 which is divisible by 3.
|
||||||
|
The second path highlighted in blue has a sum of 5 + 3 + 0 + 5 + 2 = 15 which is divisible by 3.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
<img src="https://assets.leetcode.com/uploads/2022/08/17/image-20220817112930-3.png" style="height: 85px; width: 132px;" />
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> grid = [[0,0]], k = 5
|
||||||
|
<strong>Output:</strong> 1
|
||||||
|
<strong>Explanation:</strong> The path highlighted in red has a sum of 0 + 0 = 0 which is divisible by 5.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 3:</strong></p>
|
||||||
|
<img src="https://assets.leetcode.com/uploads/2022/08/12/image-20220812224605-3.png" style="width: 257px; height: 200px;" />
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> grid = [[7,3,4,9],[2,3,6,2],[2,3,7,0]], k = 1
|
||||||
|
<strong>Output:</strong> 10
|
||||||
|
<strong>Explanation:</strong> Every integer is divisible by 1 so the sum of the elements on every possible path is divisible by k.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>m == grid.length</code></li>
|
||||||
|
<li><code>n == grid[i].length</code></li>
|
||||||
|
<li><code>1 <= m, n <= 5 * 10<sup>4</sup></code></li>
|
||||||
|
<li><code>1 <= m * n <= 5 * 10<sup>4</sup></code></li>
|
||||||
|
<li><code>0 <= grid[i][j] <= 100</code></li>
|
||||||
|
<li><code>1 <= k <= 50</code></li>
|
||||||
|
</ul>
|
@ -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 class="example">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 class="example">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 class="example">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>
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
174
leetcode/originData/find-the-original-array-of-prefix-xor.json
Normal file
174
leetcode/originData/find-the-original-array-of-prefix-xor.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
39
leetcode/problem/find-the-original-array-of-prefix-xor.html
Normal file
39
leetcode/problem/find-the-original-array-of-prefix-xor.html
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<p>You are given an <strong>integer</strong> array <code>pref</code> of size <code>n</code>. Find and return <em>the array </em><code>arr</code><em> of size </em><code>n</code><em> that satisfies</em>:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>pref[i] = arr[0] ^ arr[1] ^ ... ^ arr[i]</code>.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Note that <code>^</code> denotes the <strong>bitwise-xor</strong> operation.</p>
|
||||||
|
|
||||||
|
<p>It can be proven that the answer is <strong>unique</strong>.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> pref = [5,2,0,3,1]
|
||||||
|
<strong>Output:</strong> [5,7,2,3,2]
|
||||||
|
<strong>Explanation:</strong> From the array [5,7,2,3,2] we have the following:
|
||||||
|
- pref[0] = 5.
|
||||||
|
- pref[1] = 5 ^ 7 = 2.
|
||||||
|
- pref[2] = 5 ^ 7 ^ 2 = 0.
|
||||||
|
- pref[3] = 5 ^ 7 ^ 2 ^ 3 = 3.
|
||||||
|
- pref[4] = 5 ^ 7 ^ 2 ^ 3 ^ 2 = 1.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> pref = [13]
|
||||||
|
<strong>Output:</strong> [13]
|
||||||
|
<strong>Explanation:</strong> We have pref[0] = arr[0] = 13.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= pref.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>0 <= pref[i] <= 10<sup>6</sup></code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,42 @@
|
|||||||
|
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> integer matrix <code>grid</code> and an integer <code>k</code>. You are currently at position <code>(0, 0)</code> and you want to reach position <code>(m - 1, n - 1)</code> moving only <strong>down</strong> or <strong>right</strong>.</p>
|
||||||
|
|
||||||
|
<p>Return<em> the number of paths where the sum of the elements on the path is divisible by </em><code>k</code>. Since the answer may be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
<img src="https://assets.leetcode.com/uploads/2022/08/13/image-20220813183124-1.png" style="width: 437px; height: 200px;" />
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> grid = [[5,2,4],[3,0,5],[0,7,2]], k = 3
|
||||||
|
<strong>Output:</strong> 2
|
||||||
|
<strong>Explanation:</strong> There are two paths where the sum of the elements on the path is divisible by k.
|
||||||
|
The first path highlighted in red has a sum of 5 + 2 + 4 + 5 + 2 = 18 which is divisible by 3.
|
||||||
|
The second path highlighted in blue has a sum of 5 + 3 + 0 + 5 + 2 = 15 which is divisible by 3.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
<img src="https://assets.leetcode.com/uploads/2022/08/17/image-20220817112930-3.png" style="height: 85px; width: 132px;" />
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> grid = [[0,0]], k = 5
|
||||||
|
<strong>Output:</strong> 1
|
||||||
|
<strong>Explanation:</strong> The path highlighted in red has a sum of 0 + 0 = 0 which is divisible by 5.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 3:</strong></p>
|
||||||
|
<img src="https://assets.leetcode.com/uploads/2022/08/12/image-20220812224605-3.png" style="width: 257px; height: 200px;" />
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> grid = [[7,3,4,9],[2,3,6,2],[2,3,7,0]], k = 1
|
||||||
|
<strong>Output:</strong> 10
|
||||||
|
<strong>Explanation:</strong> Every integer is divisible by 1 so the sum of the elements on every possible path is divisible by k.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>m == grid.length</code></li>
|
||||||
|
<li><code>n == grid[i].length</code></li>
|
||||||
|
<li><code>1 <= m, n <= 5 * 10<sup>4</sup></code></li>
|
||||||
|
<li><code>1 <= m * n <= 5 * 10<sup>4</sup></code></li>
|
||||||
|
<li><code>0 <= grid[i][j] <= 100</code></li>
|
||||||
|
<li><code>1 <= k <= 50</code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,63 @@
|
|||||||
|
<p>There are <code>n</code> employees, each with a unique id from <code>0</code> to <code>n - 1</code>.</p>
|
||||||
|
|
||||||
|
<p>You are given a 2D integer array <code>logs</code> where <code>logs[i] = [id<sub>i</sub>, leaveTime<sub>i</sub>]</code> where:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>id<sub>i</sub></code> is the id of the employee that worked on the <code>i<sup>th</sup></code> task, and</li>
|
||||||
|
<li><code>leaveTime<sub>i</sub></code> is the time at which the employee finished the <code>i<sup>th</sup></code> task. All the values <code>leaveTime<sub>i</sub></code> are <strong>unique</strong>.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Note that the <code>i<sup>th</sup></code> task starts the moment right after the <code>(i - 1)<sup>th</sup></code> task ends, and the <code>0<sup>th</sup></code> task starts at time <code>0</code>.</p>
|
||||||
|
|
||||||
|
<p>Return <em>the id of the employee that worked the task with the longest time.</em> If there is a tie between two or more employees, return<em> the <strong>smallest</strong> id among them</em>.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> n = 10, logs = [[0,3],[2,5],[0,9],[1,15]]
|
||||||
|
<strong>Output:</strong> 1
|
||||||
|
<strong>Explanation:</strong>
|
||||||
|
Task 0 started at 0 and ended at 3 with 3 units of times.
|
||||||
|
Task 1 started at 3 and ended at 5 with 2 units of times.
|
||||||
|
Task 2 started at 5 and ended at 9 with 4 units of times.
|
||||||
|
Task 3 started at 9 and ended at 15 with 6 units of times.
|
||||||
|
The task with the longest time is task 3 and the employee with id 1 is the one that worked on it, so we return 1.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> n = 26, logs = [[1,1],[3,7],[2,12],[7,17]]
|
||||||
|
<strong>Output:</strong> 3
|
||||||
|
<strong>Explanation:</strong>
|
||||||
|
Task 0 started at 0 and ended at 1 with 1 unit of times.
|
||||||
|
Task 1 started at 1 and ended at 7 with 6 units of times.
|
||||||
|
Task 2 started at 7 and ended at 12 with 5 units of times.
|
||||||
|
Task 3 started at 12 and ended at 17 with 5 units of times.
|
||||||
|
The tasks with the longest time is task 1. The employees that worked on it is 3, so we return 3.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 3:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> n = 2, logs = [[0,10],[1,20]]
|
||||||
|
<strong>Output:</strong> 0
|
||||||
|
<strong>Explanation:</strong>
|
||||||
|
Task 0 started at 0 and ended at 10 with 10 units of times.
|
||||||
|
Task 1 started at 10 and ended at 20 with 10 units of times.
|
||||||
|
The tasks with the longest time are tasks 0 and 1. The employees that worked on them are 0 and 1, so we return the smallest id 0.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>2 <= n <= 500</code></li>
|
||||||
|
<li><code>1 <= logs.length <= 500</code></li>
|
||||||
|
<li><code>logs[i].length == 2</code></li>
|
||||||
|
<li><code>0 <= id<sub>i</sub> <= n - 1</code></li>
|
||||||
|
<li><code>1 <= leaveTime<sub>i</sub> <= 500</code></li>
|
||||||
|
<li><code>id<sub>i</sub> != id<sub>i+1</sub></code></li>
|
||||||
|
<li><code>leaveTime<sub>i</sub></code> are sorted in a strictly increasing order.</li>
|
||||||
|
</ul>
|
@ -0,0 +1,51 @@
|
|||||||
|
<p>You are given a string <code>s</code> and a robot that currently holds an empty string <code>t</code>. Apply one of the following operations until <code>s</code> and <code>t</code> <strong>are both empty</strong>:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>Remove the <strong>first</strong> character of a string <code>s</code> and give it to the robot. The robot will append this character to the string <code>t</code>.</li>
|
||||||
|
<li>Remove the <strong>last</strong> character of a string <code>t</code> and give it to the robot. The robot will write this character on paper.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Return <em>the lexicographically smallest string that can be written on the paper.</em></p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> s = "zza"
|
||||||
|
<strong>Output:</strong> "azz"
|
||||||
|
<strong>Explanation:</strong> Let p denote the written string.
|
||||||
|
Initially p="", s="zza", t="".
|
||||||
|
Perform first operation three times p="", s="", t="zza".
|
||||||
|
Perform second operation three times p="azz", s="", t="".
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> s = "bac"
|
||||||
|
<strong>Output:</strong> "abc"
|
||||||
|
<strong>Explanation:</strong> Let p denote the written string.
|
||||||
|
Perform first operation twice p="", s="c", t="ba".
|
||||||
|
Perform second operation twice p="ab", s="c", t="".
|
||||||
|
Perform first operation p="ab", s="", t="c".
|
||||||
|
Perform second operation p="abc", s="", t="".
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 3:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> s = "bdda"
|
||||||
|
<strong>Output:</strong> "addb"
|
||||||
|
<strong>Explanation:</strong> Let p denote the written string.
|
||||||
|
Initially p="", s="bdda", t="".
|
||||||
|
Perform first operation four times p="", s="", t="bdda".
|
||||||
|
Perform second operation four times p="addb", s="", t="".
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= s.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>s</code> consists of only English lowercase letters.</li>
|
||||||
|
</ul>
|
Loading…
Reference in New Issue
Block a user