mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-10-18 03:26:45 +08:00
更新国内版力扣题目描述变更
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -2,14 +2,14 @@
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong> nums = [0,1]
|
||||
<strong>输出:</strong> 2
|
||||
<strong>说明:</strong> [0, 1] 是具有相同数量 0 和 1 的最长连续子数组。</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong> nums = [0,1,0]
|
||||
|
@@ -1,17 +1,10 @@
|
||||
<p>给你一个链表,每 <em>k </em>个节点一组进行翻转,请你返回翻转后的链表。</p>
|
||||
<p>给你链表的头节点 <code>head</code> ,每 <code>k</code><em> </em>个节点一组进行翻转,请你返回修改后的链表。</p>
|
||||
|
||||
<p><em>k </em>是一个正整数,它的值小于或等于链表的长度。</p>
|
||||
<p><code>k</code> 是一个正整数,它的值小于或等于链表的长度。如果节点总数不是 <code>k</code><em> </em>的整数倍,那么请将最后剩余的节点保持原有顺序。</p>
|
||||
|
||||
<p>如果节点总数不是 <em>k </em>的整数倍,那么请将最后剩余的节点保持原有顺序。</p>
|
||||
<p>你不能只是单纯的改变节点内部的值,而是需要实际进行节点交换。</p>
|
||||
|
||||
<p><strong>进阶:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>你可以设计一个只使用常数额外空间的算法来解决此问题吗?</li>
|
||||
<li><strong>你不能只是单纯的改变节点内部的值</strong>,而是需要实际进行节点交换。</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2020/10/03/reverse_ex1.jpg" style="width: 542px; height: 222px;" />
|
||||
@@ -21,34 +14,26 @@
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2020/10/03/reverse_ex2.jpg" style="width: 542px; height: 222px;" />
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2020/10/03/reverse_ex2.jpg" style="width: 542px; height: 222px;" /></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>head = [1,2,3,4,5], k = 3
|
||||
<strong>输出:</strong>[3,2,1,4,5]
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
<p> </p>
|
||||
<strong>提示:</strong>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>head = [1,2,3,4,5], k = 1
|
||||
<strong>输出:</strong>[1,2,3,4,5]
|
||||
</pre>
|
||||
<ul>
|
||||
<li>链表中的节点数目为 <code>n</code></li>
|
||||
<li><code>1 <= k <= n <= 5000</code></li>
|
||||
<li><code>0 <= Node.val <= 1000</code></li>
|
||||
</ul>
|
||||
|
||||
<p><strong>示例 4:</strong></p>
|
||||
<p> </p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>head = [1], k = 1
|
||||
<strong>输出:</strong>[1]
|
||||
</pre>
|
||||
<p><strong>进阶:</strong>你可以设计一个只用 <code>O(1)</code> 额外内存空间的算法解决此问题吗?</p>
|
||||
|
||||
<ul>
|
||||
</ul>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>列表中节点的数量在范围 <code>sz</code> 内</li>
|
||||
<li><code>1 <= sz <= 5000</code></li>
|
||||
<li><code>0 <= Node.val <= 1000</code></li>
|
||||
<li><code>1 <= k <= sz</code></li>
|
||||
</ul>
|
||||
|
@@ -1,34 +1,34 @@
|
||||
<p>给定一个数组 <code>prices</code> ,其中 <code>prices[i]</code> 表示股票第 <code>i</code> 天的价格。</p>
|
||||
<p>给你一个整数数组 <code>prices</code> ,其中 <code>prices[i]</code> 表示某支股票第 <code>i</code> 天的价格。</p>
|
||||
|
||||
<p>在每一天,你可能会决定购买和/或出售股票。你在任何时候 <strong>最多</strong> 只能持有 <strong>一股</strong> 股票。你也可以购买它,然后在 <strong>同一天</strong> 出售。<br />
|
||||
返回 <em>你能获得的 <strong>最大</strong> 利润</em> 。</p>
|
||||
<p>在每一天,你可以决定是否购买和/或出售股票。你在任何时候 <strong>最多</strong> 只能持有 <strong>一股</strong> 股票。你也可以先购买,然后在 <strong>同一天</strong> 出售。</p>
|
||||
|
||||
<p>返回 <em>你能获得的 <strong>最大</strong> 利润</em> 。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong> prices = [7,1,5,3,6,4]
|
||||
<strong>输出:</strong> 7
|
||||
<strong>解释:</strong> 在第 2 天(股票价格 = 1)的时候买入,在第 3 天(股票价格 = 5)的时候卖出, 这笔交易所能获得利润 = 5-1 = 4 。
|
||||
随后,在第 4 天(股票价格 = 3)的时候买入,在第 5 天(股票价格 = 6)的时候卖出, 这笔交易所能获得利润 = 6-3 = 3 。
|
||||
</pre>
|
||||
<strong>输入:</strong>prices = [7,1,5,3,6,4]
|
||||
<strong>输出:</strong>7
|
||||
<strong>解释:</strong>在第 2 天(股票价格 = 1)的时候买入,在第 3 天(股票价格 = 5)的时候卖出, 这笔交易所能获得利润 = 5 - 1 = 4 。
|
||||
随后,在第 4 天(股票价格 = 3)的时候买入,在第 5 天(股票价格 = 6)的时候卖出, 这笔交易所能获得利润 = 6 - 3 = 3 。
|
||||
总利润为 4 + 3 = 7 。</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong> prices = [1,2,3,4,5]
|
||||
<strong>输出:</strong> 4
|
||||
<strong>解释:</strong> 在第 1 天(股票价格 = 1)的时候买入,在第 5 天 (股票价格 = 5)的时候卖出, 这笔交易所能获得利润 = 5-1 = 4 。
|
||||
注意你不能在第 1 天和第 2 天接连购买股票,之后再将它们卖出。因为这样属于同时参与了多笔交易,你必须在再次购买前出售掉之前的股票。
|
||||
</pre>
|
||||
<strong>输入:</strong>prices = [1,2,3,4,5]
|
||||
<strong>输出:</strong>4
|
||||
<strong>解释:</strong>在第 1 天(股票价格 = 1)的时候买入,在第 5 天 (股票价格 = 5)的时候卖出, 这笔交易所能获得利润 = 5 - 1 = 4 。
|
||||
总利润为 4 。</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong> prices = [7,6,4,3,1]
|
||||
<strong>输出:</strong> 0
|
||||
<strong>解释:</strong> 在这种情况下, 没有交易完成, 所以最大利润为 0。</pre>
|
||||
<strong>输入:</strong>prices = [7,6,4,3,1]
|
||||
<strong>输出:</strong>0
|
||||
<strong>解释:</strong>在这种情况下, 交易无法获得正利润,所以不参与交易可以获得最大利润,最大利润为 0 。</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
|
@@ -1,18 +1,20 @@
|
||||
<p>给定两个大小相等的数组 <code>A</code> 和 <code>B</code>,A 相对于 B 的<em>优势</em>可以用满足 <code>A[i] > B[i]</code> 的索引 <code>i</code> 的数目来描述。</p>
|
||||
<p>给定两个大小相等的数组 <code>nums1</code> 和 <code>nums2</code>,<code>nums1</code> 相对于 <code>nums</code> 的<em>优势</em>可以用满足 <code>nums1[i] > nums2[i]</code> 的索引 <code>i</code> 的数目来描述。</p>
|
||||
|
||||
<p>返回 <code>A</code> 的<strong>任意</strong>排列,使其相对于 <code>B</code> 的优势最大化。</p>
|
||||
<p>返回 <font color="#c7254e" face="Menlo, Monaco, Consolas, Courier New, monospace" size="1"><span style="background-color: rgb(249, 242, 244);">nums1</span></font> 的<strong>任意</strong>排列,使其相对于 <code>nums2</code> 的优势最大化。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>A = [2,7,11,15], B = [1,10,4,11]
|
||||
<pre>
|
||||
<strong>输入:</strong>nums1 = [2,7,11,15], nums2 = [1,10,4,11]
|
||||
<strong>输出:</strong>[2,11,7,15]
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>A = [12,24,8,32], B = [13,25,32,11]
|
||||
<pre>
|
||||
<strong>输入:</strong>nums1 = [12,24,8,32], nums2 = [13,25,32,11]
|
||||
<strong>输出:</strong>[24,32,8,12]
|
||||
</pre>
|
||||
|
||||
@@ -20,8 +22,8 @@
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ol>
|
||||
<li><code>1 <= A.length = B.length <= 10000</code></li>
|
||||
<li><code>0 <= A[i] <= 10^9</code></li>
|
||||
<li><code>0 <= B[i] <= 10^9</code></li>
|
||||
</ol>
|
||||
<ul>
|
||||
<li><code>1 <= nums1.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>nums2.length == nums1.length</code></li>
|
||||
<li><code>0 <= nums1[i], nums2[i] <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
||||
|
@@ -13,14 +13,16 @@ id是该表的主键列。
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p>编写一个SQL查询来 <strong>删除</strong> 所有重复的电子邮件,只保留一个id最小的唯一电子邮件。</p>
|
||||
<p>编写一个 SQL <strong>删除语句</strong>来 <strong>删除</strong> 所有重复的电子邮件,只保留一个id最小的唯一电子邮件。</p>
|
||||
|
||||
<p>以 <strong>任意顺序</strong> 返回结果表。</p>
|
||||
<p>以 <strong>任意顺序</strong> 返回结果表。 (<strong>注意</strong>: 仅需要写删除语句,将自动对剩余结果进行查询)</p>
|
||||
|
||||
<p>查询结果格式如下所示。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
@@ -41,5 +41,5 @@ numArray.sumRange(0, 2); // 返回 1 + 2 + 5 = 8
|
||||
<li><code>0 <= index < nums.length</code></li>
|
||||
<li><code>-100 <= val <= 100</code></li>
|
||||
<li><code>0 <= left <= right < nums.length</code></li>
|
||||
<li>调用 <code>pdate</code> 和 <code>sumRange</code> 方法次数不大于 <code>3 * 10<sup>4</sup></code> </li>
|
||||
<li>调用 <code>update</code> 和 <code>sumRange</code> 方法次数不大于 <code>3 * 10<sup>4</sup></code> </li>
|
||||
</ul>
|
||||
|
@@ -1,8 +1,9 @@
|
||||
<p>有个内含单词的超大文本文件,给定任意两个单词,找出在这个文件中这两个单词的最短距离(相隔单词数)。如果寻找过程在这个文件中会重复多次,而每次寻找的单词不同,你能对此优化吗?</p>
|
||||
<p>有个内含单词的超大文本文件,给定任意两个<code>不同的</code>单词,找出在这个文件中这两个单词的最短距离(相隔单词数)。如果寻找过程在这个文件中会重复多次,而每次寻找的单词不同,你能对此优化吗?</p>
|
||||
|
||||
<p><strong>示例:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>words = ["I","am","a","student","from","a","university","in","a","city"], word1 = "a", word2 = "student"
|
||||
<pre>
|
||||
<strong>输入:</strong>words = ["I","am","a","student","from","a","university","in","a","city"], word1 = "a", word2 = "student"
|
||||
<strong>输出:</strong>1</pre>
|
||||
|
||||
<p>提示:</p>
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1 :</strong></p>
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>nums = [1,1,1], k = 2
|
||||
@@ -10,7 +10,7 @@
|
||||
<strong>解释:</strong> 此题 [1,1] 与 [1,1] 为两种不同的情况
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2 :</strong></p>
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>nums = [1,2,3], k = 3
|
||||
|
@@ -4,7 +4,7 @@
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入: </strong>s = "cbaebabacd", p = "abc"
|
||||
@@ -14,7 +14,7 @@
|
||||
起始索引等于 6 的子串是 "bac", 它是 "abc" 的变位词。
|
||||
</pre>
|
||||
|
||||
<p><strong> 示例 2:</strong></p>
|
||||
<p><strong> 示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入: </strong>s = "abab", p = "ab"
|
||||
|
@@ -1,16 +1,16 @@
|
||||
<p>实现 <a href="https://baike.baidu.com/item/strstr/811469" target="_blank">strStr()</a> 函数。</p>
|
||||
<p>实现 <a href="https://baike.baidu.com/item/strstr/811469" target="_blank">strStr()</a> 函数。</p>
|
||||
|
||||
<p>给你两个字符串 <code>haystack</code> 和 <code>needle</code> ,请你在 <code>haystack</code> 字符串中找出 <code>needle</code> 字符串出现的第一个位置(下标从 0 开始)。如果不存在,则返回 <code>-1</code><strong> </strong>。</p>
|
||||
<p>给你两个字符串 <code>haystack</code> 和 <code>needle</code> ,请你在 <code>haystack</code> 字符串中找出 <code>needle</code> 字符串出现的第一个位置(下标从 0 开始)。如果不存在,则返回 <code>-1</code><strong> </strong>。</p>
|
||||
|
||||
<p> </p>
|
||||
<p> </p>
|
||||
|
||||
<p><strong>说明:</strong></p>
|
||||
|
||||
<p>当 <code>needle</code> 是空字符串时,我们应当返回什么值呢?这是一个在面试中很好的问题。</p>
|
||||
<p>当 <code>needle</code> 是空字符串时,我们应当返回什么值呢?这是一个在面试中很好的问题。</p>
|
||||
|
||||
<p>对于本题而言,当 <code>needle</code> 是空字符串时我们应当返回 0 。这与 C 语言的 <a href="https://baike.baidu.com/item/strstr/811469" target="_blank">strstr()</a> 以及 Java 的 <a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#indexOf(java.lang.String)" target="_blank">indexOf()</a> 定义相符。</p>
|
||||
<p>对于本题而言,当 <code>needle</code> 是空字符串时我们应当返回 0 。这与 C 语言的 <a href="https://baike.baidu.com/item/strstr/811469" target="_blank">strstr()</a> 以及 Java 的 <a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#indexOf(java.lang.String)" target="_blank">indexOf()</a> 定义相符。</p>
|
||||
|
||||
<p> </p>
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
@@ -33,11 +33,11 @@
|
||||
<strong>输出:</strong>0
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= haystack.length, needle.length <= 5 * 10<sup>4</sup></code></li>
|
||||
<li><code>1 <= haystack.length, needle.length <= 10<sup>4</sup></code></li>
|
||||
<li><code>haystack</code> 和 <code>needle</code> 仅由小写英文字符组成</li>
|
||||
</ul>
|
||||
|
@@ -1,8 +1,8 @@
|
||||
<p>如果一个由 <code>'0'</code> 和 <code>'1'</code> 组成的字符串,是以一些 <code>'0'</code>(可能没有 <code>'0'</code>)后面跟着一些 <code>'1'</code>(也可能没有 <code>'1'</code>)的形式组成的,那么该字符串是<em>单调递增</em>的。</p>
|
||||
<p>如果一个二进制字符串,是以一些 <code>0</code>(可能没有 <code>0</code>)后面跟着一些 <code>1</code>(也可能没有 <code>1</code>)的形式组成的,那么该字符串是 <strong>单调递增 </strong>的。</p>
|
||||
|
||||
<p>我们给出一个由字符 <code>'0'</code> 和 <code>'1'</code> 组成的字符串 <code>S</code>,我们可以将任何 <code>'0'</code> 翻转为 <code>'1'</code> 或者将 <code>'1'</code> 翻转为 <code>'0'</code>。</p>
|
||||
<p>给你一个二进制字符串 <code>s</code>,你可以将任何 <code>0</code> 翻转为 <code>1</code> 或者将 <code>1</code> 翻转为 <code>0</code> 。</p>
|
||||
|
||||
<p>返回使 <code>S</code> 单调递增的最小翻转次数。</p>
|
||||
<p>返回使 <code>s</code> 单调递增的最小翻转次数。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<pre>
|
||||
<strong>输入:</strong>s = "00110"
|
||||
<strong>输出:</strong>1
|
||||
<strong>解释:</strong>我们翻转最后一位得到 00111.
|
||||
<strong>解释:</strong>翻转最后一位得到 00111.
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
@@ -19,7 +19,7 @@
|
||||
<pre>
|
||||
<strong>输入:</strong>s = "010110"
|
||||
<strong>输出:</strong>2
|
||||
<strong>解释:</strong>我们翻转得到 011111,或者是 000111。
|
||||
<strong>解释:</strong>翻转得到 011111,或者是 000111。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
@@ -27,7 +27,7 @@
|
||||
<pre>
|
||||
<strong>输入:</strong>s = "00011000"
|
||||
<strong>输出:</strong>2
|
||||
<strong>解释:</strong>我们翻转得到 00000000。
|
||||
<strong>解释:</strong>翻转得到 00000000。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
@@ -36,5 +36,5 @@
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= s.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>S</code> 中只包含字符 <code>'0'</code> 和 <code>'1'</code></li>
|
||||
<li><code>s[i]</code> 为 <code>'0'</code> 或 <code>'1'</code></li>
|
||||
</ul>
|
||||
|
@@ -1,39 +1,51 @@
|
||||
<p>给定一个由空格分割单词的句子 <code>S</code>。每个单词只包含大写或小写字母。</p>
|
||||
<p>给你一个由若干单词组成的句子 <code>sentence</code> ,单词间由空格分隔。每个单词仅由大写和小写英文字母组成。</p>
|
||||
|
||||
<p>我们要将句子转换为 <em>“Goat Latin”</em>(一种类似于 猪拉丁文 - Pig Latin 的虚构语言)。</p>
|
||||
|
||||
<p>山羊拉丁文的规则如下:</p>
|
||||
<p>请你将句子转换为 <em>“</em>山羊拉丁文(<em>Goat Latin</em>)<em>”</em>(一种类似于 猪拉丁文 - Pig Latin 的虚构语言)。山羊拉丁文的规则如下:</p>
|
||||
|
||||
<ul>
|
||||
<li>如果单词以元音开头(a, e, i, o, u),在单词后添加<code>"ma"</code>。<br />
|
||||
例如,单词<code>"apple"</code>变为<code>"applema"</code>。</li>
|
||||
<br />
|
||||
<li>如果单词以辅音字母开头(即非元音字母),移除第一个字符并将它放到末尾,之后再添加<code>"ma"</code>。<br />
|
||||
例如,单词<code>"goat"</code>变为<code>"oatgma"</code>。</li>
|
||||
<br />
|
||||
<li>根据单词在句子中的索引,在单词最后添加与索引相同数量的字母<code>'a'</code>,索引从1开始。<br />
|
||||
例如,在第一个单词后添加<code>"a"</code>,在第二个单词后添加<code>"aa"</code>,以此类推。</li>
|
||||
<li>如果单词以元音开头(<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'</code>),在单词后添加<code>"ma"</code>。
|
||||
|
||||
<ul>
|
||||
<li>例如,单词 <code>"apple"</code> 变为 <code>"applema"</code> 。</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>如果单词以辅音字母开头(即,非元音字母),移除第一个字符并将它放到末尾,之后再添加<code>"ma"</code>。
|
||||
<ul>
|
||||
<li>例如,单词 <code>"goat"</code> 变为 <code>"oatgma"</code> 。</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>根据单词在句子中的索引,在单词最后添加与索引相同数量的字母<code>'a'</code>,索引从 <code>1</code> 开始。
|
||||
<ul>
|
||||
<li>例如,在第一个单词后添加 <code>"a"</code> ,在第二个单词后添加 <code>"aa"</code> ,以此类推。</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<p>返回将 <code>S</code> 转换为山羊拉丁文后的句子。</p>
|
||||
<p>返回将 <code>sentence</code> 转换为山羊拉丁文后的句子。</p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入: </strong>"I speak Goat Latin"
|
||||
<strong>输出: </strong>"Imaa peaksmaaa oatGmaaaa atinLmaaaaa"
|
||||
<strong>输入:</strong>sentence = "I speak Goat Latin"
|
||||
<strong>输出:</strong>"Imaa peaksmaaa oatGmaaaa atinLmaaaaa"
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入: </strong>"The quick brown fox jumped over the lazy dog"
|
||||
<strong>输出: </strong>"heTmaa uickqmaaa rownbmaaaa oxfmaaaaa umpedjmaaaaaa overmaaaaaaa hetmaaaaaaaa azylmaaaaaaaaa ogdmaaaaaaaaaa"
|
||||
<strong>输入:</strong>sentence = "The quick brown fox jumped over the lazy dog"
|
||||
<strong>输出:</strong>"heTmaa uickqmaaa rownbmaaaa oxfmaaaaa umpedjmaaaaaa overmaaaaaaa hetmaaaaaaaa azylmaaaaaaaaa ogdmaaaaaaaaaa"
|
||||
</pre>
|
||||
|
||||
<p><strong>说明:</strong></p>
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>S</code> 中仅包含大小写字母和空格。单词间有且仅有一个空格。</li>
|
||||
<li><code>1 <= S.length <= 150</code>。</li>
|
||||
<li><code>1 <= sentence.length <= 150</code></li>
|
||||
<li><code>sentence</code> 由英文字母和空格组成</li>
|
||||
<li><code>sentence</code> 不含前导或尾随空格</li>
|
||||
<li><code>sentence</code> 中的所有单词由单个空格分隔</li>
|
||||
</ul>
|
||||
|
@@ -1,17 +1,17 @@
|
||||
<p>有 <code>n</code> 个气球,编号为<code>0</code> 到 <code>n - 1</code>,每个气球上都标有一个数字,这些数字存在数组 <code>nums</code> 中。</p>
|
||||
<p>有 <code>n</code> 个气球,编号为<code>0</code> 到 <code>n - 1</code>,每个气球上都标有一个数字,这些数字存在数组 <code>nums</code> 中。</p>
|
||||
|
||||
<p>现在要求你戳破所有的气球。戳破第 <code>i</code> 个气球,你可以获得 <code>nums[i - 1] * nums[i] * nums[i + 1]</code> 枚硬币。 这里的 <code>i - 1</code> 和 <code>i + 1</code> 代表和 <code>i</code> 相邻的两个气球的序号。如果 <code>i - 1</code>或 <code>i + 1</code> 超出了数组的边界,那么就当它是一个数字为 <code>1</code> 的气球。</p>
|
||||
<p>现在要求你戳破所有的气球。戳破第 <code>i</code> 个气球,你可以获得 <code>nums[i - 1] * nums[i] * nums[i + 1]</code> 枚硬币。 这里的 <code>i - 1</code> 和 <code>i + 1</code> 代表和 <code>i</code> 相邻的两个气球的序号。如果 <code>i - 1</code>或 <code>i + 1</code> 超出了数组的边界,那么就当它是一个数字为 <code>1</code> 的气球。</p>
|
||||
|
||||
<p>求所能获得硬币的最大数量。</p>
|
||||
|
||||
<p> </p>
|
||||
<p> </p>
|
||||
<strong>示例 1:</strong>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>nums = [3,1,5,8]
|
||||
<strong>输出:</strong>167
|
||||
<strong>解释:</strong>
|
||||
nums = [3,1,5,8] --> [3,5,8] --> [3,8] --> [8] --> []
|
||||
nums = [3,1,5,8] --> [3,5,8] --> [3,8] --> [8] --> []
|
||||
coins = 3*1*5 + 3*5*8 + 1*3*8 + 1*8*1 = 167</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
@@ -21,12 +21,12 @@ coins = 3*1*5 + 3*5*8 + 1*3*8 + 1*8*1 = 167</pre>
|
||||
<strong>输出:</strong>10
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>n == nums.length</code></li>
|
||||
<li><code>1 <= n <= 500</code></li>
|
||||
<li><code>0 <= nums[i] <= 100</code></li>
|
||||
<li><code>1 <= n <= 300</code></li>
|
||||
<li><code>0 <= nums[i] <= 100</code></li>
|
||||
</ul>
|
||||
|
@@ -31,8 +31,8 @@ solution.shuffle(); // 随机返回数组 [1, 2, 3] 打乱后的结果。例
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 200</code></li>
|
||||
<li><code>1 <= nums.length <= 50</code></li>
|
||||
<li><code>-10<sup>6</sup> <= nums[i] <= 10<sup>6</sup></code></li>
|
||||
<li><code>nums</code> 中的所有元素都是 <strong>唯一的</strong></li>
|
||||
<li>最多可以调用 <code>5 * 10<sup>4</sup></code> 次 <code>reset</code> 和 <code>shuffle</code></li>
|
||||
<li>最多可以调用 <code>10<sup>4</sup></code> 次 <code>reset</code> 和 <code>shuffle</code></li>
|
||||
</ul>
|
||||
|
@@ -1,17 +1,17 @@
|
||||
<p>你有 <code>k</code> 个服务器,编号为 <code>0</code> 到 <code>k-1</code> ,它们可以同时处理多个请求组。每个服务器有无穷的计算能力但是 <strong>不能同时处理超过一个请求</strong> 。请求分配到服务器的规则如下:</p>
|
||||
<p>你有 <code>k</code> 个服务器,编号为 <code>0</code> 到 <code>k-1</code> ,它们可以同时处理多个请求组。每个服务器有无穷的计算能力但是 <strong>不能同时处理超过一个请求</strong> 。请求分配到服务器的规则如下:</p>
|
||||
|
||||
<ul>
|
||||
<li>第 <code>i</code> (序号从 0 开始)个请求到达。</li>
|
||||
<li>第 <code>i</code> (序号从 0 开始)个请求到达。</li>
|
||||
<li>如果所有服务器都已被占据,那么该请求被舍弃(完全不处理)。</li>
|
||||
<li>如果第 <code>(i % k)</code> 个服务器空闲,那么对应服务器会处理该请求。</li>
|
||||
<li>否则,将请求安排给下一个空闲的服务器(服务器构成一个环,必要的话可能从第 0 个服务器开始继续找下一个空闲的服务器)。比方说,如果第 <code>i</code> 个服务器在忙,那么会查看第 <code>(i+1)</code> 个服务器,第 <code>(i+2)</code> 个服务器等等。</li>
|
||||
<li>如果第 <code>(i % k)</code> 个服务器空闲,那么对应服务器会处理该请求。</li>
|
||||
<li>否则,将请求安排给下一个空闲的服务器(服务器构成一个环,必要的话可能从第 0 个服务器开始继续找下一个空闲的服务器)。比方说,如果第 <code>i</code> 个服务器在忙,那么会查看第 <code>(i+1)</code> 个服务器,第 <code>(i+2)</code> 个服务器等等。</li>
|
||||
</ul>
|
||||
|
||||
<p>给你一个 <strong>严格递增</strong> 的正整数数组 <code>arrival</code> ,表示第 <code>i</code> 个任务的到达时间,和另一个数组 <code>load</code> ,其中 <code>load[i]</code> 表示第 <code>i</code> 个请求的工作量(也就是服务器完成它所需要的时间)。你的任务是找到 <strong>最繁忙的服务器</strong> 。最繁忙定义为一个服务器处理的请求数是所有服务器里最多的。</p>
|
||||
<p>给你一个 <strong>严格递增</strong> 的正整数数组 <code>arrival</code> ,表示第 <code>i</code> 个任务的到达时间,和另一个数组 <code>load</code> ,其中 <code>load[i]</code> 表示第 <code>i</code> 个请求的工作量(也就是服务器完成它所需要的时间)。你的任务是找到 <strong>最繁忙的服务器</strong> 。最繁忙定义为一个服务器处理的请求数是所有服务器里最多的。</p>
|
||||
|
||||
<p>请你返回包含所有 <strong>最繁忙服务器</strong> 序号的列表,你可以以任意顺序返回这个列表。</p>
|
||||
<p>请你返回包含所有 <strong>最繁忙服务器</strong> 序号的列表,你可以以任意顺序返回这个列表。</p>
|
||||
|
||||
<p> </p>
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
<strong>解释:</strong>
|
||||
所有服务器一开始都是空闲的。
|
||||
前 3 个请求分别由前 3 台服务器依次处理。
|
||||
请求 3 进来的时候,服务器 0 被占据,所以它呗安排到下一台空闲的服务器,也就是服务器 1 。
|
||||
请求 3 进来的时候,服务器 0 被占据,所以它被安排到下一台空闲的服务器,也就是服务器 1 。
|
||||
请求 4 进来的时候,由于所有服务器都被占据,该请求被舍弃。
|
||||
服务器 0 和 2 分别都处理了一个请求,服务器 1 处理了两个请求。所以服务器 1 是最忙的服务器。
|
||||
</pre>
|
||||
@@ -61,14 +61,14 @@
|
||||
<strong>输出:</strong>[0]
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= k <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= arrival.length, load.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= k <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= arrival.length, load.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>arrival.length == load.length</code></li>
|
||||
<li><code>1 <= arrival[i], load[i] <= 10<sup>9</sup></code></li>
|
||||
<li><code>arrival</code> 保证 <strong>严格递增</strong> 。</li>
|
||||
<li><code>1 <= arrival[i], load[i] <= 10<sup>9</sup></code></li>
|
||||
<li><code>arrival</code> 保证 <strong>严格递增</strong> 。</li>
|
||||
</ul>
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<p>有一个有 <code>n</code> 个节点的有向图,节点按 <code>0</code> 到 <code>n - 1</code> 编号。图由一个 <strong>索引从 0 开始</strong> 的 2D 整数数组 <code>graph</code>表示, <code>graph[i]</code>是与节点 <code>i</code> 相邻的节点的整数数组,这意味着从节点 <code>i</code> 到 <code>graph[i]</code>中的每个节点都有一条边。</p>
|
||||
|
||||
<p>如果一个节点没有连出的有向边,则它是 <strong>终端节点</strong> 。如果没有出边,则节点为终端节点。如果从该节点开始的所有可能路径都通向一个 <strong>终端节点</strong> ,则该节点为 <strong>安全节点</strong> 。</p>
|
||||
<p>如果一个节点没有连出的有向边,则它是 <strong>终端节点</strong> 。如果没有出边,则节点为终端节点。如果从该节点开始的所有可能路径都通向 <strong>终端节点</strong> ,则该节点为 <strong>安全节点</strong> 。</p>
|
||||
|
||||
<p>返回一个由图中所有 <strong>安全节点</strong> 组成的数组作为答案。答案数组中的元素应当按 <strong>升序</strong> 排列。</p>
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
<strong>输入:</strong>graph = [[1,2],[2,3],[5],[0],[5],[],[]]
|
||||
<strong>输出:</strong>[2,4,5,6]
|
||||
<strong>解释:</strong>示意图如上。
|
||||
节点5和节点6是终端节点,因为它们都没有出边。
|
||||
从节点2、4、5和6开始的所有路径都指向节点5或6。
|
||||
节点 5 和节点 6 是终端节点,因为它们都没有出边。
|
||||
从节点 2、4、5 和 6 开始的所有路径都指向节点 5 或 6 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
@@ -24,7 +24,7 @@
|
||||
<strong>输入:</strong>graph = [[1,2,3,4],[1,2],[3,4],[0,4],[]]
|
||||
<strong>输出:</strong>[4]
|
||||
<strong>解释:</strong>
|
||||
只有节点4是终端节点,从节点4开始的所有路径都通向节点4。
|
||||
只有节点 4 是终端节点,从节点 4 开始的所有路径都通向节点 4 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
@@ -35,6 +35,7 @@
|
||||
<li><code>n == graph.length</code></li>
|
||||
<li><code>1 <= n <= 10<sup>4</sup></code></li>
|
||||
<li><code>0 <= graph[i].length <= n</code></li>
|
||||
<li><code>0 <= graph[i][j] <= n - 1</code></li>
|
||||
<li><code>graph[i]</code> 按严格递增顺序排列。</li>
|
||||
<li>图中可能包含自环。</li>
|
||||
<li>图中边的数目在范围 <code>[1, 4 * 10<sup>4</sup>]</code> 内。</li>
|
||||
|
@@ -1,21 +1,29 @@
|
||||
<p>给定一个非负整数数组 <code>A</code>,返回一个数组,在该数组中, <code>A</code> 的所有偶数元素之后跟着所有奇数元素。</p>
|
||||
<p>给你一个整数数组 <code>nums</code>,将 <code>nums</code> 中的的所有偶数元素移动到数组的前面,后跟所有奇数元素。</p>
|
||||
|
||||
<p>你可以返回满足此条件的任何数组作为答案。</p>
|
||||
<p>返回满足此条件的 <strong>任一数组</strong> 作为答案。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例:</strong></p>
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>[3,1,2,4]
|
||||
<pre>
|
||||
<strong>输入:</strong>nums = [3,1,2,4]
|
||||
<strong>输出:</strong>[2,4,3,1]
|
||||
输出 [4,2,3,1],[2,4,1,3] 和 [4,2,1,3] 也会被接受。
|
||||
<strong>解释:</strong>[4,2,3,1]、[2,4,1,3] 和 [4,2,1,3] 也会被视作正确答案。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>nums = [0]
|
||||
<strong>输出:</strong>[0]
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ol>
|
||||
<li><code>1 <= A.length <= 5000</code></li>
|
||||
<li><code>0 <= A[i] <= 5000</code></li>
|
||||
</ol>
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 5000</code></li>
|
||||
<li><code>0 <= nums[i] <= 5000</code></li>
|
||||
</ul>
|
||||
|
@@ -1,10 +1,10 @@
|
||||
<p>给你一个整数数组 <code>nums</code>,和一个整数 <code>k</code> 。</p>
|
||||
|
||||
<p>在一个操作中,您可以选择 <code>0 <= i < nums</code> 的任何索引 <code>i</code> 。将 <code>nums[i]</code> 改为 <code>nums[i] + x</code> ,其中 <code>x</code> 是一个范围为 <code>[-k, k]</code> 的整数。对于每个索引 <code>i</code> ,最多 <strong>只能 </strong>应用 <strong>一次</strong> 此操作。</p>
|
||||
<p>在一个操作中,您可以选择 <code>0 <= i < nums.length</code> 的任何索引 <code>i</code> 。将 <code>nums[i]</code> 改为 <code>nums[i] + x</code> ,其中 <code>x</code> 是一个范围为 <code>[-k, k]</code> 的整数。对于每个索引 <code>i</code> ,最多 <strong>只能 </strong>应用 <strong>一次</strong> 此操作。</p>
|
||||
|
||||
<p><code>nums</code> 的 <strong>分数 </strong>是 <code>nums</code> 中最大和最小元素的差值。 </p>
|
||||
|
||||
<p><em>在对nums中的每个索引最多应用一次上述操作后,返回 <code>nums</code> 的最低 <strong>分数</strong></em> 。</p>
|
||||
<p><em>在对 <code>nums</code> 中的每个索引最多应用一次上述操作后,返回 <code>nums</code> 的最低 <strong>分数</strong></em> 。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
|
@@ -1,36 +1,33 @@
|
||||
<p>你需要采用前序遍历的方式,将一个二叉树转换成一个由括号和整数组成的字符串。</p>
|
||||
<p>给你二叉树的根节点 <code>root</code> ,请你采用前序遍历的方式,将二叉树转化为一个由括号和整数组成的字符串,返回构造出的字符串。</p>
|
||||
|
||||
<p>空节点则用一对空括号 "()" 表示。而且你需要省略所有不影响字符串与原始二叉树之间的一对一映射关系的空括号对。</p>
|
||||
<p>空节点使用一对空括号对 <code>"()"</code> 表示,转化后需要省略所有不影响字符串与原始二叉树之间的一对一映射关系的空括号对。</p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
<div class="original__bRMd">
|
||||
<div>
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2021/05/03/cons1-tree.jpg" style="width: 292px; height: 301px;" />
|
||||
<pre>
|
||||
<strong>输入:</strong> 二叉树: [1,2,3,4]
|
||||
1
|
||||
/ \
|
||||
2 3
|
||||
/
|
||||
4
|
||||
|
||||
<strong>输出:</strong> "1(2(4))(3)"
|
||||
|
||||
<strong>解释:</strong> 原本将是“1(2(4)())(3())”,
|
||||
在你省略所有不必要的空括号对之后,
|
||||
它将是“1(2(4))(3)”。
|
||||
<strong>输入:</strong>root = [1,2,3,4]
|
||||
<strong>输出:</strong>"1(2(4))(3)"
|
||||
<strong>解释:</strong>初步转化后得到 "1(2(4)())(3()())" ,但省略所有不必要的空括号对后,字符串应该是"1(2(4))(3)" 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2021/05/03/cons2-tree.jpg" style="width: 207px; height: 293px;" />
|
||||
<pre>
|
||||
<strong>输入:</strong> 二叉树: [1,2,3,null,4]
|
||||
1
|
||||
/ \
|
||||
2 3
|
||||
\
|
||||
4
|
||||
<strong>输入:</strong>root = [1,2,3,null,4]
|
||||
<strong>输出:</strong>"1(2()(4))(3)"
|
||||
<strong>解释:</strong>和第一个示例类似,但是无法省略第一个空括号对,否则会破坏输入与输出一一映射的关系。</pre>
|
||||
|
||||
<strong>输出:</strong> "1(2()(4))(3)"
|
||||
<p> </p>
|
||||
|
||||
<strong>解释:</strong> 和第一个示例相似,
|
||||
除了我们不能省略第一个对括号来中断输入和输出之间的一对一映射关系。
|
||||
</pre>
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>树中节点的数目范围是 <code>[1, 10<sup>4</sup>]</code></li>
|
||||
<li><code>-1000 <= Node.val <= 1000</code></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -1,10 +1,10 @@
|
||||
<p>珂珂喜欢吃香蕉。这里有 <code>N</code> 堆香蕉,第 <code>i</code> 堆中有 <code>piles[i]</code> 根香蕉。警卫已经离开了,将在 <code>H</code> 小时后回来。</p>
|
||||
<p>珂珂喜欢吃香蕉。这里有 <code>n</code> 堆香蕉,第 <code>i</code> 堆中有 <code>piles[i]</code> 根香蕉。警卫已经离开了,将在 <code>h</code> 小时后回来。</p>
|
||||
|
||||
<p>珂珂可以决定她吃香蕉的速度 <code>K</code> (单位:根/小时)。每个小时,她将会选择一堆香蕉,从中吃掉 <code>K</code> 根。如果这堆香蕉少于 <code>K</code> 根,她将吃掉这堆的所有香蕉,然后这一小时内不会再吃更多的香蕉。 </p>
|
||||
<p>珂珂可以决定她吃香蕉的速度 <code>k</code> (单位:根/小时)。每个小时,她将会选择一堆香蕉,从中吃掉 <code>k</code> 根。如果这堆香蕉少于 <code>k</code> 根,她将吃掉这堆的所有香蕉,然后这一小时内不会再吃更多的香蕉。 </p>
|
||||
|
||||
<p>珂珂喜欢慢慢吃,但仍然想在警卫回来前吃掉所有的香蕉。</p>
|
||||
|
||||
<p>返回她可以在 <code>H</code> 小时内吃掉所有香蕉的最小速度 <code>K</code>(<code>K</code> 为整数)。</p>
|
||||
<p>返回她可以在 <code>h</code> 小时内吃掉所有香蕉的最小速度 <code>k</code>(<code>k</code> 为整数)。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
@@ -13,20 +13,23 @@
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><strong>输入: </strong>piles = [3,6,7,11], H = 8
|
||||
<strong>输出: </strong>4
|
||||
<pre>
|
||||
<strong>输入:</strong>piles = [3,6,7,11], h = 8
|
||||
<strong>输出:</strong>4
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><strong>输入: </strong>piles = [30,11,23,4,20], H = 5
|
||||
<strong>输出: </strong>30
|
||||
<pre>
|
||||
<strong>输入:</strong>piles = [30,11,23,4,20], h = 5
|
||||
<strong>输出:</strong>30
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<pre><strong>输入: </strong>piles = [30,11,23,4,20], H = 6
|
||||
<strong>输出: </strong>23
|
||||
<pre>
|
||||
<strong>输入:</strong>piles = [30,11,23,4,20], h = 6
|
||||
<strong>输出:</strong>23
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
@@ -34,7 +37,7 @@
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= piles.length <= 10^4</code></li>
|
||||
<li><code>piles.length <= H <= 10^9</code></li>
|
||||
<li><code>1 <= piles[i] <= 10^9</code></li>
|
||||
<li><code>1 <= piles.length <= 10<sup>4</sup></code></li>
|
||||
<li><code>piles.length <= h <= 10<sup>9</sup></code></li>
|
||||
<li><code>1 <= piles[i] <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
||||
|
@@ -1,10 +1,10 @@
|
||||
<p>狒狒喜欢吃香蕉。这里有 <code>N</code> 堆香蕉,第 <code>i</code> 堆中有 <code>piles[i]</code> 根香蕉。警卫已经离开了,将在 <code>H</code> 小时后回来。</p>
|
||||
<p>狒狒喜欢吃香蕉。这里有 <code>n</code> 堆香蕉,第 <code>i</code> 堆中有 <code>piles[i]</code> 根香蕉。警卫已经离开了,将在 <code>h</code> 小时后回来。</p>
|
||||
|
||||
<p>狒狒可以决定她吃香蕉的速度 <code>K</code> (单位:根/小时)。每个小时,她将会选择一堆香蕉,从中吃掉 <code>K</code> 根。如果这堆香蕉少于 <code>K</code> 根,她将吃掉这堆的所有香蕉,然后这一小时内不会再吃更多的香蕉,下一个小时才会开始吃另一堆的香蕉。 </p>
|
||||
<p>狒狒可以决定她吃香蕉的速度 <code>k</code> (单位:根/小时)。每个小时,她将会选择一堆香蕉,从中吃掉 <code>k</code> 根。如果这堆香蕉少于 <code>k</code> 根,她将吃掉这堆的所有香蕉,然后这一小时内不会再吃更多的香蕉,下一个小时才会开始吃另一堆的香蕉。 </p>
|
||||
|
||||
<p>狒狒喜欢慢慢吃,但仍然想在警卫回来前吃掉所有的香蕉。</p>
|
||||
|
||||
<p>返回她可以在 <code>H</code> 小时内吃掉所有香蕉的最小速度 <code>K</code>(<code>K</code> 为整数)。</p>
|
||||
<p>返回她可以在 <code>h</code> 小时内吃掉所有香蕉的最小速度 <code>k</code>(<code>k</code> 为整数)。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
@@ -14,22 +14,22 @@
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入: </strong>piles = [3,6,7,11], H = 8
|
||||
<strong>输出: </strong>4
|
||||
<strong>输入:</strong>piles = [3,6,7,11], h = 8
|
||||
<strong>输出:</strong>4
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入: </strong>piles = [30,11,23,4,20], H = 5
|
||||
<strong>输出: </strong>30
|
||||
<strong>输入:</strong>piles = [30,11,23,4,20], h = 5
|
||||
<strong>输出:</strong>30
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入: </strong>piles = [30,11,23,4,20], H = 6
|
||||
<strong>输出: </strong>23
|
||||
<strong>输入:</strong>piles = [30,11,23,4,20], h = 6
|
||||
<strong>输出:</strong>23
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
@@ -37,11 +37,11 @@
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= piles.length <= 10^4</code></li>
|
||||
<li><code>piles.length <= H <= 10^9</code></li>
|
||||
<li><code>1 <= piles[i] <= 10^9</code></li>
|
||||
<li><code>1 <= piles.length <= 10<sup>4</sup></code></li>
|
||||
<li><code>piles.length <= h <= 10<sup>9</sup></code></li>
|
||||
<li><code>1 <= piles[i] <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><meta charset="UTF-8" />注意:本题与主站 875 题相同: <a href="https://leetcode-cn.com/problems/koko-eating-bananas/">https://leetcode-cn.com/problems/koko-eating-bananas/</a></p>
|
||||
<p><meta charset="UTF-8" /><strong>注意:</strong>本题与主站 875 题相同: <a href="https://leetcode-cn.com/problems/koko-eating-bananas/">https://leetcode-cn.com/problems/koko-eating-bananas/</a></p>
|
||||
|
@@ -10,8 +10,8 @@
|
||||
| commission_rate | int |
|
||||
| hire_date | date |
|
||||
+-----------------+---------+
|
||||
Sales_id是该表的主键列。
|
||||
该表的每一行都显示了销售人员的姓名和ID,以及他们的工资、佣金率和雇佣日期。
|
||||
sales_id 是该表的主键列。
|
||||
该表的每一行都显示了销售人员的姓名和 ID ,以及他们的工资、佣金率和雇佣日期。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
@@ -26,8 +26,8 @@ Sales_id是该表的主键列。
|
||||
| name | varchar |
|
||||
| city | varchar |
|
||||
+-------------+---------+
|
||||
Com_id是该表的主键列。
|
||||
该表的每一行都表示公司的名称和ID,以及公司所在的城市。
|
||||
com_id 是该表的主键列。
|
||||
该表的每一行都表示公司的名称和 ID ,以及公司所在的城市。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
@@ -44,10 +44,10 @@ Com_id是该表的主键列。
|
||||
| sales_id | int |
|
||||
| amount | int |
|
||||
+-------------+------+
|
||||
Order_id是该表的主键列。
|
||||
com_id是Company表中com_id的外键。
|
||||
sales_id是来自销售员表com_id的外键。
|
||||
该表的每一行包含一个订单的信息。这包括公司的ID、销售人员的ID、订单日期和支付的金额。
|
||||
order_id 是该表的主键列。
|
||||
com_id 是 Company 表中 com_id 的外键。
|
||||
sales_id 是来自销售员表 sales_id 的外键。
|
||||
该表的每一行包含一个订单的信息。这包括公司的 ID 、销售人员的 ID 、订单日期和支付的金额。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
@@ -60,10 +60,10 @@ sales_id是来自销售员表com_id的外键。
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
<p><strong>示例:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>
|
||||
<strong>输入:</strong>
|
||||
SalesPerson 表:
|
||||
+----------+------+--------+-----------------+------------+
|
||||
| sales_id | name | salary | commission_rate | hire_date |
|
||||
@@ -92,7 +92,7 @@ Orders 表:
|
||||
| 3 | 3/1/2014 | 1 | 1 | 50000 |
|
||||
| 4 | 4/1/2014 | 1 | 4 | 25000 |
|
||||
+----------+------------+--------+----------+--------+
|
||||
<strong>输出:</strong>
|
||||
<strong>输出:</strong>
|
||||
+------+
|
||||
| name |
|
||||
+------+
|
||||
@@ -100,6 +100,6 @@ Orders 表:
|
||||
| Mark |
|
||||
| Alex |
|
||||
+------+
|
||||
<strong>解释:</strong>
|
||||
<strong>解释:</strong>
|
||||
根据表 <code>orders</code> 中的订单 '3' 和 '4' ,容易看出只有 'John' 和 'Pam' 两个销售员曾经向公司 'RED' 销售过。
|
||||
所以我们需要输出表 <code>salesperson</code> 中所有其他人的名字。</pre>
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<p>Given an integer array <code>data</code> representing the data, return whether it is a valid <strong>UTF-8</strong> encoding.</p>
|
||||
<p>Given an integer array <code>data</code> representing the data, return whether it is a valid <strong>UTF-8</strong> encoding (i.e. it translates to a sequence of valid UTF-8 encoded characters).</p>
|
||||
|
||||
<p>A character in <strong>UTF8</strong> can be from <b>1 to 4 bytes</b> long, subjected to the following rules:</p>
|
||||
<p>A character in <strong>UTF8</strong> can be from <strong>1 to 4 bytes</strong> long, subjected to the following rules:</p>
|
||||
|
||||
<ol>
|
||||
<li>For a <strong>1-byte</strong> character, the first bit is a <code>0</code>, followed by its Unicode code.</li>
|
||||
@@ -10,16 +10,18 @@
|
||||
<p>This is how the UTF-8 encoding would work:</p>
|
||||
|
||||
<pre>
|
||||
<code> Char. number range | UTF-8 octet sequence
|
||||
(hexadecimal) | (binary)
|
||||
--------------------+---------------------------------------------
|
||||
0000 0000-0000 007F | 0xxxxxxx
|
||||
0000 0080-0000 07FF | 110xxxxx 10xxxxxx
|
||||
0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
|
||||
0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx</code>
|
||||
Number of Bytes | UTF-8 Octet Sequence
|
||||
| (binary)
|
||||
--------------------+-----------------------------------------
|
||||
1 | 0xxxxxxx
|
||||
2 | 110xxxxx 10xxxxxx
|
||||
3 | 1110xxxx 10xxxxxx 10xxxxxx
|
||||
4 | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||
</pre>
|
||||
|
||||
<p><b>Note: </b>The input is an array of integers. Only the <b>least significant 8 bits</b> of each integer is used to store the data. This means each integer represents only 1 byte of data.</p>
|
||||
<p><code>x</code> denotes a bit in the binary form of a byte that may be either <code>0</code> or <code>1</code>.</p>
|
||||
|
||||
<p><strong>Note: </strong>The input is an array of integers. Only the <strong>least significant 8 bits</strong> of each integer is used to store the data. This means each integer represents only 1 byte of data.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
@@ -27,6 +27,14 @@ We choose one 1 from [1,1] in 2 ways,
|
||||
and two 2s from [2,2,2,2] in 6 ways.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> arr = [2,1,3], target = 6
|
||||
<strong>Output:</strong> 1
|
||||
<strong>Explanation:</strong> (1, 2, 3) occured one time in the array so we return 1.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
|
@@ -1,10 +1,10 @@
|
||||
<p>A robot is located at the top-left corner of a <code>m x n</code> grid (marked 'Start' in the diagram below).</p>
|
||||
<p>You are given an <code>m x n</code> integer array <code>grid</code>. There is a robot initially located at the <b>top-left corner</b> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m-1][n-1]</code>). The robot can only move either down or right at any point in time.</p>
|
||||
|
||||
<p>The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).</p>
|
||||
<p>An obstacle and space are marked as <code>1</code> or <code>0</code> respectively in <code>grid</code>. A path that the robot takes cannot include <strong>any</strong> square that is an obstacle.</p>
|
||||
|
||||
<p>Now consider if some obstacles are added to the grids. How many unique paths would there be?</p>
|
||||
<p>Return <em>the number of possible unique paths that the robot can take to reach the bottom-right corner</em>.</p>
|
||||
|
||||
<p>An obstacle and space is marked as <code>1</code> and <code>0</code> respectively in the grid.</p>
|
||||
<p>The testcases are generated so that the answer will be less than or equal to <code>2 * 10<sup>9</sup></code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
@@ -29,8 +29,8 @@ There are two ways to reach the bottom-right corner:
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>m == obstacleGrid.length</code></li>
|
||||
<li><code>n == obstacleGrid[i].length</code></li>
|
||||
<li><code>m == obstacleGrid.length</code></li>
|
||||
<li><code>n == obstacleGrid[i].length</code></li>
|
||||
<li><code>1 <= m, n <= 100</code></li>
|
||||
<li><code>obstacleGrid[i][j]</code> is <code>0</code> or <code>1</code>.</li>
|
||||
</ul>
|
||||
|
@@ -17,6 +17,7 @@
|
||||
|
||||
|
||||
<p><strong>Example2:</strong></p>
|
||||
<ol>
|
||||
|
||||
|
||||
</ol>
|
||||
|
||||
<pre>
|
||||
|
@@ -7,6 +7,8 @@
|
||||
<li>Replace <code>c</code> with <code>values[i]</code> in the string.</li>
|
||||
</ol>
|
||||
|
||||
<p>Note that in case a character of the string is <strong>not present</strong> in <code>keys</code>, the encryption process cannot be carried out, and an empty string <code>""</code> is returned.</p>
|
||||
|
||||
<p>A string is <strong>decrypted</strong> with the following process:</p>
|
||||
|
||||
<ol>
|
||||
|
@@ -1,4 +1,4 @@
|
||||
<p>You have a large text file containing words. Given any two words, find the shortest distance (in terms of number of words) between them in the file. If the operation will be repeated many times for the same file (but different pairs of words), can you optimize your solution?</p>
|
||||
<p>You have a large text file containing words. Given any two different words, find the shortest distance (in terms of number of words) between them in the file. If the operation will be repeated many times for the same file (but different pairs of words), can you optimize your solution?</p>
|
||||
|
||||
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
<p>There is only one character <code>'A'</code> on the screen of a notepad. You can perform two operations on this notepad for each step:</p>
|
||||
<p>There is only one character <code>'A'</code> on the screen of a notepad. You can perform one of two operations on this notepad for each step:</p>
|
||||
|
||||
<ul>
|
||||
<li>Copy All: You can copy all the characters present on the screen (a partial copy is not allowed).</li>
|
||||
@@ -13,7 +13,7 @@
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 3
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> Intitally, we have one character 'A'.
|
||||
<strong>Explanation:</strong> Initially, we have one character 'A'.
|
||||
In step 1, we use Copy All operation.
|
||||
In step 2, we use Paste operation to get 'AA'.
|
||||
In step 3, we use Paste operation to get 'AAA'.
|
||||
|
@@ -36,5 +36,5 @@
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= x, y <= 10<sup>9</sup></code></li>
|
||||
<li><code>1 <= startValue, target <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
||||
|
@@ -1,28 +1,32 @@
|
||||
<p>Implement <a href="http://www.cplusplus.com/reference/cstring/strstr/" target="_blank">strStr()</a>.</p>
|
||||
|
||||
<p>Return the index of the first occurrence of needle in haystack, or <code>-1</code> if <code>needle</code> is not part of <code>haystack</code>.</p>
|
||||
<p>Given two strings <code>needle</code> and <code>haystack</code>, return the index of the first occurrence of <code>needle</code> in <code>haystack</code>, or <code>-1</code> if <code>needle</code> is not part of <code>haystack</code>.</p>
|
||||
|
||||
<p><strong>Clarification:</strong></p>
|
||||
|
||||
<p>What should we return when <code>needle</code> is an empty string? This is a great question to ask during an interview.</p>
|
||||
|
||||
<p>For the purpose of this problem, we will return 0 when <code>needle</code> is an empty string. This is consistent to C's <a href="http://www.cplusplus.com/reference/cstring/strstr/" target="_blank">strstr()</a> and Java's <a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#indexOf(java.lang.String)" target="_blank">indexOf()</a>.</p>
|
||||
<p>For the purpose of this problem, we will return 0 when <code>needle</code> is an empty string. This is consistent to C's <a href="http://www.cplusplus.com/reference/cstring/strstr/" target="_blank">strstr()</a> and Java's <a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#indexOf(java.lang.String)" target="_blank">indexOf()</a>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<pre><strong>Input:</strong> haystack = "hello", needle = "ll"
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> haystack = "hello", needle = "ll"
|
||||
<strong>Output:</strong> 2
|
||||
</pre><p><strong>Example 2:</strong></p>
|
||||
<pre><strong>Input:</strong> haystack = "aaaaa", needle = "bba"
|
||||
<strong>Output:</strong> -1
|
||||
</pre><p><strong>Example 3:</strong></p>
|
||||
<pre><strong>Input:</strong> haystack = "", needle = ""
|
||||
<strong>Output:</strong> 0
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> haystack = "aaaaa", needle = "bba"
|
||||
<strong>Output:</strong> -1
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= haystack.length, needle.length <= 5 * 10<sup>4</sup></code></li>
|
||||
<li><code>haystack</code> and <code>needle</code> consist of only lower-case English characters.</li>
|
||||
<li><code>1 <= haystack.length, needle.length <= 10<sup>4</sup></code></li>
|
||||
<li><code>haystack</code> and <code>needle</code> consist of only lowercase English characters.</li>
|
||||
</ul>
|
||||
|
@@ -32,8 +32,8 @@ solution.shuffle(); // Returns the random shuffling of array [1,2,3]. Example
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 200</code></li>
|
||||
<li><code>1 <= nums.length <= 50</code></li>
|
||||
<li><code>-10<sup>6</sup> <= nums[i] <= 10<sup>6</sup></code></li>
|
||||
<li>All the elements of <code>nums</code> are <strong>unique</strong>.</li>
|
||||
<li>At most <code>5 * 10<sup>4</sup></code> calls <strong>in total</strong> will be made to <code>reset</code> and <code>shuffle</code>.</li>
|
||||
<li>At most <code>10<sup>4</sup></code> calls <strong>in total</strong> will be made to <code>reset</code> and <code>shuffle</code>.</li>
|
||||
</ul>
|
||||
|
@@ -10,7 +10,7 @@
|
||||
<strong>Output:</strong> [101,111,121,131,141,999]
|
||||
<strong>Explanation:</strong>
|
||||
The first few palindromes of length 3 are:
|
||||
101, 111, 121, 131, 141, 151, 161, 171, 181, 191, 201, ...
|
||||
101, 111, 121, 131, 141, 151, 161, 171, 181, 191, 202, ...
|
||||
The 90<sup>th</sup> palindrome of length 3 is 999.
|
||||
</pre>
|
||||
|
||||
|
@@ -9,7 +9,7 @@
|
||||
<li><code>"C"</code> - Invalidate the previous score, removing it from the record. It is guaranteed there will always be a previous score.</li>
|
||||
</ol>
|
||||
|
||||
<p>Return <em>the sum of all the scores on the record</em>.</p>
|
||||
<p>Return <em>the sum of all the scores on the record</em>. The test cases are generated so that the answer fits in a 32-bit integer.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
@@ -15,7 +15,7 @@
|
||||
<strong>Input:</strong> s = "ABC"
|
||||
<strong>Output:</strong> 10
|
||||
<strong>Explanation: </strong>All possible substrings are: "A","B","C","AB","BC" and "ABC".
|
||||
Evey substring is composed with only unique letters.
|
||||
Every substring is composed with only unique letters.
|
||||
Sum of lengths of all substring is 1 + 1 + 1 + 2 + 2 + 3 = 10
|
||||
</pre>
|
||||
|
||||
|
@@ -8,6 +8,7 @@
|
||||
| num | varchar |
|
||||
+-------------+---------+
|
||||
id is the primary key for this table.
|
||||
id is an autoincrement column.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
@@ -1,4 +1,4 @@
|
||||
<p>Your country has an infinite number of lakes. Initially, all the lakes are empty, but when it rains over the <code>nth</code> lake, the <code>nth</code> lake becomes full of water. If it rains over a lake which is <strong>full of water</strong>, there will be a <strong>flood</strong>. Your goal is to avoid the flood in any lake.</p>
|
||||
<p>Your country has an infinite number of lakes. Initially, all the lakes are empty, but when it rains over the <code>nth</code> lake, the <code>nth</code> lake becomes full of water. If it rains over a lake that is <strong>full of water</strong>, there will be a <strong>flood</strong>. Your goal is to avoid floods in any lake.</p>
|
||||
|
||||
<p>Given an integer array <code>rains</code> where:</p>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
<p>If there are multiple valid answers return <strong>any</strong> of them. If it is impossible to avoid flood return <strong>an empty array</strong>.</p>
|
||||
|
||||
<p>Notice that if you chose to dry a full lake, it becomes empty, but if you chose to dry an empty lake, nothing changes. (see example 4)</p>
|
||||
<p>Notice that if you chose to dry a full lake, it becomes empty, but if you chose to dry an empty lake, nothing changes.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
Reference in New Issue
Block a user