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

更新国内版力扣题目描述变更

This commit is contained in:
程序员小墨 2022-05-02 23:42:43 +08:00
parent 74598d1cf8
commit 7ea03594b3
198 changed files with 11378 additions and 11118 deletions
leetcode-cn
origin-data.json
problem (Chinese)
problem (English)
字母与数字(English) [find-longest-subarray-lcci].html2出现的次数(English) [number-of-2s-in-range-lcci].htmlBiNode(English) [binode-lcci].htmlLRU 缓存(English) [lru-cache-lcci].htmlT9键盘(English) [t9-lcci].htmlURL化(English) [string-to-url-lcci].htmlUTF-8 编码验证(English) [utf-8-validation].html一次编辑(English) [one-away-lcci].html三合一(English) [three-in-one-lcci].html三数之和的多种可能(English) [3sum-with-multiplicity].html三步问题(English) [three-steps-problem-lcci].html下一个数(English) [closed-number-lcci].html不同路径 II(English) [unique-paths-ii].html不用加号的加法(English) [add-without-plus-lcci].html两个数对之间的最大乘积差(English) [maximum-product-difference-between-two-pairs].html主要元素(English) [find-majority-element-lcci].html二叉搜索树序列(English) [bst-sequences-lcci].html二叉搜索树的最近公共祖先(English) [er-cha-sou-suo-shu-de-zui-jin-gong-gong-zu-xian-lcof].html二叉树的最近公共祖先(English) [er-cha-shu-de-zui-jin-gong-gong-zu-xian-lcof].html二叉树的深度(English) [er-cha-shu-de-shen-du-lcof].html二维数组中的查找(English) [er-wei-shu-zu-zhong-de-cha-zhao-lcof].html二进制数转字符串(English) [bianry-number-to-string-lcci].html井字游戏(English) [tic-tac-toe-lcci].html交换和(English) [sum-swap-lcci].html交换数字(English) [swap-numbers-lcci].html交替合并字符串(English) [merge-strings-alternately].html交点(English) [intersection-lcci].html八皇后(English) [eight-queens-lcci].html兰顿蚂蚁(English) [langtons-ant-lcci].html分割链表(English) [partition-list-lcci].html分式化简(English) [deep-dark-fraction].html删除中间节点(English) [delete-middle-node-lcci].html判定字符是否唯一(English) [is-unique-lcci].html判定是否互为字符重排(English) [check-permutation-lcci].html加密解密字符串(English) [encrypt-and-decrypt-strings].html动物收容所(English) [animal-shelter-lcci].html化栈为队(English) [implement-queue-using-stacks-lcci].html单词矩阵(English) [word-rectangle-lcci].html单词距离(English) [find-closest-lcci].html单词转换(English) [word-transformer-lcci].html单词频率(English) [words-frequency-lcci].html发 LeetCoin(English) [coin-bonus].html变位词组(English) [group-anagrams-lcci].html只有两个键的键盘(English) [2-keys-keyboard].html可以到达所有点的最少点数目(English) [minimum-number-of-vertices-to-reach-all-nodes].html可以形成最大正方形的矩形数目(English) [number-of-rectangles-that-can-form-the-largest-square].html合并排序的数组(English) [sorted-merge-lcci].html合法二叉搜索树(English) [legal-binary-search-tree-lcci].html后继者(English) [successor-lcci].html和为s的两个数字(English) [he-wei-sde-liang-ge-shu-zi-lcof].html和为s的连续正数序列(English) [he-wei-sde-lian-xu-zheng-shu-xu-lie-lcof].html回文排列(English) [palindrome-permutation-lcci].html回文链表(English) [palindrome-linked-list-lcci].html圆圈中最后剩下的数字(English) [yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof].html坏了的计算器(English) [broken-calculator].html堆盘子(English) [stack-of-plates-lcci].html堆箱子(English) [pile-box-lcci].html多次搜索(English) [multi-search-lcci].html好因子的最大数目(English) [maximize-number-of-nice-divisors].html婴儿名字(English) [baby-names-lcci].html字符串压缩(English) [compress-string-lcci].html字符串轮转(English) [string-rotation-lcci].html实现 strStr()(English) [implement-strstr].html将句子排序(English) [sorting-the-sentence].html将数组分成三个子数组的方案数(English) [ways-to-split-array-into-three-subarrays].html峰与谷(English) [peaks-and-valleys-lcci].html左旋转字符串(English) [zuo-xuan-zhuan-zi-fu-chuan-lcof].html布尔运算(English) [boolean-evaluation-lcci].html幂集(English) [power-set-lcci].html

File diff suppressed because it is too large Load Diff

@ -2,14 +2,14 @@
<p>&nbsp;</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> ,每&nbsp;<code>k</code><em>&nbsp;</em>个节点一组进行翻转,请你返回修改后的链表。</p>
<p><em>k </em>是一个正整数,它的值小于或等于链表的长度。</p>
<p><code>k</code> 是一个正整数,它的值小于或等于链表的长度。如果节点总数不是&nbsp;<code>k</code><em>&nbsp;</em>的整数倍,那么请将最后剩余的节点保持原有顺序</p>
<p>如果节点总数不是 <em>k </em>的整数倍,那么请将最后剩余的节点保持原有顺序</p>
<p>你不能只是单纯的改变节点内部的值,而是需要实际进行节点交换</p>
<p><strong>进阶:</strong></p>
<ul>
<li>你可以设计一个只使用常数额外空间的算法来解决此问题吗?</li>
<li><strong>你不能只是单纯的改变节点内部的值</strong>,而是需要实际进行节点交换。</li>
</ul>
<p> </p>
<p>&nbsp;</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>&nbsp;</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 &lt;= k &lt;= n &lt;= 5000</code></li>
<li><code>0 &lt;= Node.val &lt;= 1000</code></li>
</ul>
<p><strong>示例 4</strong></p>
<p>&nbsp;</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 @@
小扣打算给自己的 **VS code** 安装使用插件,初始状态下带宽每分钟可以完成 `1` 个插件的下载。假定每分钟选择以下两种策略之一:
- 使用当前带宽下载插件
- 将带宽加倍(下载插件数量随之加倍)
请返回小扣完成下载 `n` 个插件最少需要多少分钟。
注意:实际的下载的插件数量可以超过 `n`
**示例 1**
>输入:`n = 2`
>
>输出:`2`
>
>解释:
> 以下两个方案,都能实现 2 分钟内下载 2 个插件
>- 方案一:第一分钟带宽加倍,带宽可每分钟下载 2 个插件;第二分钟下载 2 个插件
>- 方案二:第一分钟下载 1 个插件,第二分钟下载 1 个插件
**示例 2**
>输入:`n = 4`
>
>输出:`3`
>
>解释:
> 最少需要 3 分钟可完成 4 个插件的下载,以下是其中一种方案:
> 第一分钟带宽加倍,带宽可每分钟下载 2 个插件;
> 第二分钟下载 2 个插件;
> 第三分钟下载 2 个插件。
**提示:**
- `1 <= n <= 10^5`
小扣打算给自己的 **VS code** 安装使用插件,初始状态下带宽每分钟可以完成 `1` 个插件的下载。假定每分钟选择以下两种策略之一:
- 使用当前带宽下载插件
- 将带宽加倍(下载插件数量随之加倍)
请返回小扣完成下载 `n` 个插件最少需要多少分钟。
注意:实际的下载的插件数量可以超过 `n`
**示例 1**
>输入:`n = 2`
>
>输出:`2`
>
>解释:
> 以下两个方案,都能实现 2 分钟内下载 2 个插件
>- 方案一:第一分钟带宽加倍,带宽可每分钟下载 2 个插件;第二分钟下载 2 个插件
>- 方案二:第一分钟下载 1 个插件,第二分钟下载 1 个插件
**示例 2**
>输入:`n = 4`
>
>输出:`3`
>
>解释:
> 最少需要 3 分钟可完成 4 个插件的下载,以下是其中一种方案:
> 第一分钟带宽加倍,带宽可每分钟下载 2 个插件;
> 第二分钟下载 2 个插件;
> 第三分钟下载 2 个插件。
**提示:**
- `1 <= n <= 10^5`

@ -1,34 +1,34 @@
<p>定一个数组 <code>prices</code> ,其中&nbsp;<code>prices[i]</code> 表示股票第 <code>i</code> 天的价格。</p>
<p>你一个整数数组 <code>prices</code> ,其中&nbsp;<code>prices[i]</code> 表示某支股票第 <code>i</code> 天的价格。</p>
<p>在每一天,你可能会决定购买和/或出售股票。你在任何时候&nbsp;<strong>最多</strong>&nbsp;只能持有 <strong>一股</strong> 股票。你也可以购买它,然后在 <strong>同一天</strong> 出售。<br />
返回 <em>你能获得的 <strong>最大</strong> 利润</em>&nbsp;</p>
<p>在每一天,你可以决定是否购买和/或出售股票。你在任何时候&nbsp;<strong>最多</strong>&nbsp;只能持有 <strong>一股</strong> 股票。你也可以先购买,然后在 <strong>同一天</strong> 出售。</p>
<p>返回 <em>你能获得的 <strong>最大</strong> 利润</em>&nbsp;</p>
<p>&nbsp;</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 。
&nbsp; 随后,在第 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 。
&nbsp; 随后,在第 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 。
&nbsp; 注意你不能在第 1 天和第 2 天接连购买股票,之后再将它们卖出。因为这样属于同时参与了多笔交易,你必须在再次购买前出售掉之前的股票。
</pre>
<strong>输入:</strong>prices = [1,2,3,4,5]
<strong>输出:</strong>4
<strong>解释:</strong>在第 1 天(股票价格 = 1的时候买入在第 5 天 (股票价格 = 5的时候卖出, 这笔交易所能获得利润 = 5 - 1 = 4 。
&nbsp; 总利润为 4 。</pre>
<p><strong>示例&nbsp;3:</strong></p>
<p><strong>示例&nbsp;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>&nbsp;</p>

@ -1,18 +1,20 @@
<p>给定两个大小相等的数组&nbsp;<code>A</code>&nbsp;&nbsp;<code>B</code>A 相对于 B <em>优势</em>可以用满足&nbsp;<code>A[i] &gt; B[i]</code>&nbsp;的索引 <code>i</code>&nbsp;的数目来描述。</p>
<p>给定两个大小相等的数组&nbsp;<code>nums1</code>&nbsp;&nbsp;<code>nums2</code><code>nums1</code>&nbsp;相对于 <code>nums</code>&nbsp;<em>优势</em>可以用满足&nbsp;<code>nums1[i] &gt; nums2[i]</code>&nbsp;的索引 <code>i</code>&nbsp;的数目来描述。</p>
<p>返回&nbsp;<code>A</code>&nbsp;<strong>任意</strong>排列,使其相对于 <code>B</code>&nbsp;的优势最大化。</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>&nbsp;<strong>任意</strong>排列,使其相对于 <code>nums2</code>&nbsp;的优势最大化。</p>
<p>&nbsp;</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 &lt;= A.length = B.length &lt;= 10000</code></li>
<li><code>0 &lt;= A[i] &lt;= 10^9</code></li>
<li><code>0 &lt;= B[i] &lt;= 10^9</code></li>
</ol>
<ul>
<li><code>1 &lt;= nums1.length &lt;= 10<sup>5</sup></code></li>
<li><code>nums2.length == nums1.length</code></li>
<li><code>0 &lt;= nums1[i], nums2[i] &lt;= 10<sup>9</sup></code></li>
</ul>

@ -13,14 +13,16 @@ id是该表的主键列。
<p>&nbsp;</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>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>示例 1:</strong></p>
<pre>

@ -41,5 +41,5 @@ numArray.sumRange(0, 2); // 返回 1 + 2 + 5 = 8
<li><code>0 &lt;= index &lt; nums.length</code></li>
<li><code>-100 &lt;= val &lt;= 100</code></li>
<li><code>0 &lt;= left &lt;= right &lt; nums.length</code></li>
<li>调用 <code>pdate</code><code>sumRange</code> 方法次数不大于&nbsp;<code>3 * 10<sup>4</sup></code>&nbsp;</li>
<li>调用 <code>update</code><code>sumRange</code> 方法次数不大于&nbsp;<code>3 * 10<sup>4</sup></code>&nbsp;</li>
</ul>

@ -1,8 +1,9 @@
<p>有个内含单词的超大文本文件,给定任意两个单词,找出在这个文件中这两个单词的最短距离(相隔单词数)。如果寻找过程在这个文件中会重复多次,而每次寻找的单词不同,你能对此优化吗?</p>
<p>有个内含单词的超大文本文件,给定任意两个<code>不同的</code>单词,找出在这个文件中这两个单词的最短距离(相隔单词数)。如果寻找过程在这个文件中会重复多次,而每次寻找的单词不同,你能对此优化吗?</p>
<p><strong>示例:</strong></p>
<pre><strong>输入:</strong>words = [&quot;I&quot;,&quot;am&quot;,&quot;a&quot;,&quot;student&quot;,&quot;from&quot;,&quot;a&quot;,&quot;university&quot;,&quot;in&quot;,&quot;a&quot;,&quot;city&quot;], word1 = &quot;a&quot;, word2 = &quot;student&quot;
<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>&nbsp;</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&nbsp;:</strong></p>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>nums = [1,2,3], k = 3

@ -4,7 +4,7 @@
<p>&nbsp;</p>
<p><strong>示例&nbsp;1:</strong></p>
<p><strong>示例&nbsp;1</strong></p>
<pre>
<strong>输入: </strong>s = &quot;cbaebabacd&quot;, p = &quot;abc&quot;
@ -14,7 +14,7 @@
起始索引等于 6 的子串是 &quot;bac&quot;, 它是 &quot;abc&quot; 的变位词。
</pre>
<p><strong>&nbsp;示例 2:</strong></p>
<p><strong>&nbsp;示例 2</strong></p>
<pre>
<strong>输入: </strong>s = &quot;abab&quot;, p = &quot;ab&quot;

@ -1,27 +1,27 @@
`N` 位扣友参加了微软与力扣举办了「以扣会友」线下活动。主办方提供了 `2*N` 道题目,整型数组 `questions` 中每个数字对应了每道题目所涉及的知识点类型。
若每位扣友选择不同的一题,请返回被选的 `N` 道题目至少包含多少种知识点类型。
**示例 1**
>输入:`questions = [2,1,6,2]`
>
>输出:`1`
>
>解释:有 2 位扣友在 4 道题目中选择 2 题。
> 可选择完成知识点类型为 2 的题目时,此时仅一种知识点类型
> 因此至少包含 1 种知识点类型。
**示例 2**
>输入:`questions = [1,5,1,3,4,5,2,5,3,3,8,6]`
>
>输出:`2`
>
>解释:有 6 位扣友在 12 道题目中选择题目,需要选择 6 题。
> 选择完成知识点类型为 3、5 的题目,因此至少包含 2 种知识点类型。
**提示:**
- `questions.length == 2*n`
- `2 <= questions.length <= 10^5`
`N` 位扣友参加了微软与力扣举办了「以扣会友」线下活动。主办方提供了 `2*N` 道题目,整型数组 `questions` 中每个数字对应了每道题目所涉及的知识点类型。
若每位扣友选择不同的一题,请返回被选的 `N` 道题目至少包含多少种知识点类型。
**示例 1**
>输入:`questions = [2,1,6,2]`
>
>输出:`1`
>
>解释:有 2 位扣友在 4 道题目中选择 2 题。
> 可选择完成知识点类型为 2 的题目时,此时仅一种知识点类型
> 因此至少包含 1 种知识点类型。
**示例 2**
>输入:`questions = [1,5,1,3,4,5,2,5,3,3,8,6]`
>
>输出:`2`
>
>解释:有 6 位扣友在 12 道题目中选择题目,需要选择 6 题。
> 选择完成知识点类型为 3、5 的题目,因此至少包含 2 种知识点类型。
**提示:**
- `questions.length == 2*n`
- `2 <= questions.length <= 10^5`
- `1 <= questions[i] <= 1000`

@ -1,16 +1,16 @@
<p>实现 <a href="https://baike.baidu.com/item/strstr/811469" target="_blank">strStr()</a> 函数。</p>
<p>实现&nbsp;<a href="https://baike.baidu.com/item/strstr/811469" target="_blank">strStr()</a>&nbsp;函数。</p>
<p>给你两个字符串 <code>haystack</code><code>needle</code> ,请你在 <code>haystack</code> 字符串中找出 <code>needle</code> 字符串出现的第一个位置(下标从 0 开始)。如果不存在,则返回  <code>-1</code><strong> </strong></p>
<p>给你两个字符串&nbsp;<code>haystack</code><code>needle</code> ,请你在 <code>haystack</code> 字符串中找出 <code>needle</code> 字符串出现的第一个位置(下标从 0 开始)。如果不存在,则返回&nbsp; <code>-1</code><strong> </strong></p>
<p> </p>
<p>&nbsp;</p>
<p><strong>说明:</strong></p>
<p> <code>needle</code> 是空字符串时,我们应当返回什么值呢?这是一个在面试中很好的问题。</p>
<p>&nbsp;<code>needle</code>&nbsp;是空字符串时,我们应当返回什么值呢?这是一个在面试中很好的问题。</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>对于本题而言,当&nbsp;<code>needle</code>&nbsp;是空字符串时我们应当返回 0 。这与 C 语言的&nbsp;<a href="https://baike.baidu.com/item/strstr/811469" target="_blank">strstr()</a>&nbsp;以及 Java 的&nbsp;<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#indexOf(java.lang.String)" target="_blank">indexOf()</a>&nbsp;定义相符。</p>
<p> </p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
@ -33,11 +33,11 @@
<strong>输出:</strong>0
</pre>
<p> </p>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>0 <= haystack.length, needle.length <= 5 * 10<sup>4</sup></code></li>
<li><code>1 &lt;= haystack.length, needle.length &lt;= 10<sup>4</sup></code></li>
<li><code>haystack</code><code>needle</code> 仅由小写英文字符组成</li>
</ul>

@ -1,29 +1,29 @@
小扣参加的秋日市集景区共有 $N$ 个景点,景点编号为 $1$~$N$。景点内设有 $N-1$ 条双向道路,使所有景点形成了一个二叉树结构,根结点记为 `root`,景点编号即为节点值。
由于秋日市集景区的结构特殊,游客很容易迷路,主办方决定在景区的若干个景点设置导航装置,按照所在景点编号升序排列后定义装置编号为 1 ~ M。导航装置向游客发送数据数据内容为列表 `[游客与装置 1 的相对距离,游客与装置 2 的相对距离,...,游客与装置 M 的相对距离]`。由于游客根据导航装置发送的信息来确认位置,因此主办方需保证游客在每个景点接收的数据信息皆不相同。请返回主办方最少需要设置多少个导航装置。
**示例 1**
>输入:`root = [1,2,null,3,4]`
>
>输出:`2`
>
>解释:在景点 1、3 或景点 1、4 或景点 3、4 设置导航装置。
>
>![image.png](https://pic.leetcode-cn.com/1597996812-tqrgwu-image.png){:height="250px"}
**示例 2**
>输入:`root = [1,2,3,4]`
>
>输出:`1`
>
>解释:在景点 3、4 设置导航装置皆可。
>
>![image.png](https://pic.leetcode-cn.com/1597996826-EUQRyz-image.png){:height="200px"}
**提示:**
- `2 <= N <= 50000`
- 二叉树的非空节点值为 `1~N` 的一个排列。
小扣参加的秋日市集景区共有 $N$ 个景点,景点编号为 $1$~$N$。景点内设有 $N-1$ 条双向道路,使所有景点形成了一个二叉树结构,根结点记为 `root`,景点编号即为节点值。
由于秋日市集景区的结构特殊,游客很容易迷路,主办方决定在景区的若干个景点设置导航装置,按照所在景点编号升序排列后定义装置编号为 1 ~ M。导航装置向游客发送数据数据内容为列表 `[游客与装置 1 的相对距离,游客与装置 2 的相对距离,...,游客与装置 M 的相对距离]`。由于游客根据导航装置发送的信息来确认位置,因此主办方需保证游客在每个景点接收的数据信息皆不相同。请返回主办方最少需要设置多少个导航装置。
**示例 1**
>输入:`root = [1,2,null,3,4]`
>
>输出:`2`
>
>解释:在景点 1、3 或景点 1、4 或景点 3、4 设置导航装置。
>
>![image.png](https://pic.leetcode-cn.com/1597996812-tqrgwu-image.png){:height="250px"}
**示例 2**
>输入:`root = [1,2,3,4]`
>
>输出:`1`
>
>解释:在景点 3、4 设置导航装置皆可。
>
>![image.png](https://pic.leetcode-cn.com/1597996826-EUQRyz-image.png){:height="200px"}
**提示:**
- `2 <= N <= 50000`
- 二叉树的非空节点值为 `1~N` 的一个排列。

@ -1,8 +1,8 @@
<p>如果一个&nbsp;<code>'0'</code><code>'1'</code>&nbsp;组成的字符串,是以一些 <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>&nbsp;组成的字符串&nbsp;<code>S</code>,我们可以将任何&nbsp;<code>'0'</code> 翻转为&nbsp;<code>'1'</code>&nbsp;或者将&nbsp;<code>'1'</code>&nbsp;翻转为&nbsp;<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>&nbsp;</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>&nbsp;</p>
@ -36,5 +36,5 @@
<ul>
<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
<li><code>S</code> 中只包含字符&nbsp;<code>'0'</code>&nbsp;&nbsp;<code>'1'</code></li>
<li><code>s[i]</code><code>'0'</code><code>'1'</code></li>
</ul>

@ -1,39 +1,51 @@
<p>定一个由空格分割单词的句子&nbsp;<code>S</code>。每个单词只包含大写或小写字母</p>
<p>你一个由若干单词组成的句子&nbsp;<code>sentence</code> ,单词间由空格分隔。每个单词仅由大写和小写英文字母组成</p>
<p>我们要将句子转换为&nbsp;<em>&ldquo;Goat Latin&rdquo;</em>(一种类似于 猪拉丁文&nbsp;- Pig Latin 的虚构语言)。</p>
<p>山羊拉丁文的规则如下:</p>
<p>请你将句子转换为 <em></em>山羊拉丁文(<em>Goat Latin</em><em></em>(一种类似于 猪拉丁文&nbsp;- Pig Latin 的虚构语言)。山羊拉丁文的规则如下:</p>
<ul>
<li>如果单词以元音开头a, e, i, o, u在单词后添加<code>&quot;ma&quot;</code><br />
例如,单词<code>&quot;apple&quot;</code>变为<code>&quot;applema&quot;</code></li>
<br />
<li>如果单词以辅音字母开头(即非元音字母),移除第一个字符并将它放到末尾,之后再添加<code>&quot;ma&quot;</code><br />
例如,单词<code>&quot;goat&quot;</code>变为<code>&quot;oatgma&quot;</code></li>
<br />
<li>根据单词在句子中的索引,在单词最后添加与索引相同数量的字母<code>&#39;a&#39;</code>索引从1开始。<br />
例如,在第一个单词后添加<code>&quot;a&quot;</code>,在第二个单词后添加<code>&quot;aa&quot;</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>返回将&nbsp;<code>S</code>&nbsp;转换为山羊拉丁文后的句子。</p>
<p>返回将 <code>sentence</code> 转换为山羊拉丁文后的句子。</p>
<p><strong>示例 1:</strong></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入: </strong>&quot;I speak Goat Latin&quot;
<strong>输出: </strong>&quot;Imaa peaksmaaa oatGmaaaa atinLmaaaaa&quot;
<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>&quot;The quick brown fox jumped over the lazy dog&quot;
<strong>输出: </strong>&quot;heTmaa uickqmaaa rownbmaaaa oxfmaaaaa umpedjmaaaaaa overmaaaaaaa hetmaaaaaaaa azylmaaaaaaaaa ogdmaaaaaaaaaa&quot;
<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>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>S</code>&nbsp;中仅包含大小写字母和空格。单词间有且仅有一个空格。</li>
<li><code>1 &lt;= S.length &lt;= 150</code></li>
<li><code>1 &lt;= sentence.length &lt;= 150</code></li>
<li><code>sentence</code> 由英文字母和空格组成</li>
<li><code>sentence</code> 不含前导或尾随空格</li>
<li><code>sentence</code> 中的所有单词由单个空格分隔</li>
</ul>

@ -1,44 +1,44 @@
小扣打算去秋日市集,由于游客较多,小扣的移动速度受到了人流影响:
- 小扣从 `x` 号站点移动至 `x + 1` 号站点需要花费的时间为 `inc`
- 小扣从 `x` 号站点移动至 `x - 1` 号站点需要花费的时间为 `dec`
现有 `m` 辆公交车,编号为 `0``m-1`。小扣也可以通过搭乘编号为 `i` 的公交车,从 `x` 号站点移动至 `jump[i]*x` 号站点,耗时仅为 `cost[i]`。小扣可以搭乘任意编号的公交车且搭乘公交次数不限。
假定小扣起始站点记作 `0`,秋日市集站点记作 `target`,请返回小扣抵达秋日市集最少需要花费多少时间。由于数字较大,最终答案需要对 1000000007 (1e9 + 7) 取模。
注意:小扣可在移动过程中到达编号大于 `target` 的站点。
**示例 1**
>输入:`target = 31, inc = 5, dec = 3, jump = [6], cost = [10]`
>
>输出:`33`
>
>解释:
>小扣步行至 1 号站点,花费时间为 5
>小扣从 1 号站台搭乘 0 号公交至 6 * 1 = 6 站台,花费时间为 10
>小扣从 6 号站台步行至 5 号站台,花费时间为 3
>小扣从 5 号站台搭乘 0 号公交至 6 * 5 = 30 站台,花费时间为 10
>小扣从 30 号站台步行至 31 号站台,花费时间为 5
>最终小扣花费总时间为 33。
**示例 2**
>输入:`target = 612, inc = 4, dec = 5, jump = [3,6,8,11,5,10,4], cost = [4,7,6,3,7,6,4]`
>
>输出:`26`
>
>解释:
>小扣步行至 1 号站点,花费时间为 4
>小扣从 1 号站台搭乘 0 号公交至 3 * 1 = 3 站台,花费时间为 4
>小扣从 3 号站台搭乘 3 号公交至 11 * 3 = 33 站台,花费时间为 3
>小扣从 33 号站台步行至 34 站台,花费时间为 4
>小扣从 34 号站台搭乘 0 号公交至 3 * 34 = 102 站台,花费时间为 4
>小扣从 102 号站台搭乘 1 号公交至 6 * 102 = 612 站台,花费时间为 7
>最终小扣花费总时间为 26。
**提示:**
- `1 <= target <= 10^9`
- `1 <= jump.length, cost.length <= 10`
- `2 <= jump[i] <= 10^6`
小扣打算去秋日市集,由于游客较多,小扣的移动速度受到了人流影响:
- 小扣从 `x` 号站点移动至 `x + 1` 号站点需要花费的时间为 `inc`
- 小扣从 `x` 号站点移动至 `x - 1` 号站点需要花费的时间为 `dec`
现有 `m` 辆公交车,编号为 `0``m-1`。小扣也可以通过搭乘编号为 `i` 的公交车,从 `x` 号站点移动至 `jump[i]*x` 号站点,耗时仅为 `cost[i]`。小扣可以搭乘任意编号的公交车且搭乘公交次数不限。
假定小扣起始站点记作 `0`,秋日市集站点记作 `target`,请返回小扣抵达秋日市集最少需要花费多少时间。由于数字较大,最终答案需要对 1000000007 (1e9 + 7) 取模。
注意:小扣可在移动过程中到达编号大于 `target` 的站点。
**示例 1**
>输入:`target = 31, inc = 5, dec = 3, jump = [6], cost = [10]`
>
>输出:`33`
>
>解释:
>小扣步行至 1 号站点,花费时间为 5
>小扣从 1 号站台搭乘 0 号公交至 6 * 1 = 6 站台,花费时间为 10
>小扣从 6 号站台步行至 5 号站台,花费时间为 3
>小扣从 5 号站台搭乘 0 号公交至 6 * 5 = 30 站台,花费时间为 10
>小扣从 30 号站台步行至 31 号站台,花费时间为 5
>最终小扣花费总时间为 33。
**示例 2**
>输入:`target = 612, inc = 4, dec = 5, jump = [3,6,8,11,5,10,4], cost = [4,7,6,3,7,6,4]`
>
>输出:`26`
>
>解释:
>小扣步行至 1 号站点,花费时间为 4
>小扣从 1 号站台搭乘 0 号公交至 3 * 1 = 3 站台,花费时间为 4
>小扣从 3 号站台搭乘 3 号公交至 11 * 3 = 33 站台,花费时间为 3
>小扣从 33 号站台步行至 34 站台,花费时间为 4
>小扣从 34 号站台搭乘 0 号公交至 3 * 34 = 102 站台,花费时间为 4
>小扣从 102 号站台搭乘 1 号公交至 6 * 102 = 612 站台,花费时间为 7
>最终小扣花费总时间为 26。
**提示:**
- `1 <= target <= 10^9`
- `1 <= jump.length, cost.length <= 10`
- `2 <= jump[i] <= 10^6`
- `1 <= inc, dec, cost[i] <= 10^6`

@ -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>,每个气球上都标有一个数字,这些数字存在数组&nbsp;<code>nums</code>&nbsp;中。</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> 个气球,你可以获得&nbsp;<code>nums[i - 1] * nums[i] * nums[i + 1]</code> 枚硬币。&nbsp;这里的 <code>i - 1</code><code>i + 1</code> 代表和&nbsp;<code>i</code>&nbsp;相邻的两个气球的序号。如果 <code>i - 1</code><code>i + 1</code> 超出了数组的边界,那么就当它是一个数字为 <code>1</code> 的气球。</p>
<p>求所能获得硬币的最大数量。</p>
<p> </p>
<p>&nbsp;</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] --&gt; [3,5,8] --&gt; [3,8] --&gt; [8] --&gt; []
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>&nbsp;</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 &lt;= n &lt;= 300</code></li>
<li><code>0 &lt;= nums[i] &lt;= 100</code></li>
</ul>

@ -31,8 +31,8 @@ solution.shuffle(); // 随机返回数组 [1, 2, 3] 打乱后的结果。例
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 200</code></li>
<li><code>1 &lt;= nums.length &lt;= 50</code></li>
<li><code>-10<sup>6</sup> &lt;= nums[i] &lt;= 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>&nbsp;个服务器,编号为 <code>0</code>&nbsp;<code>k-1</code>&nbsp;,它们可以同时处理多个请求组。每个服务器有无穷的计算能力但是 <strong>不能同时处理超过一个请求</strong>&nbsp;。请求分配到服务器的规则如下:</p>
<ul>
<li> <code>i</code> (序号从 0 开始)个请求到达。</li>
<li>&nbsp;<code>i</code>&nbsp;(序号从 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>如果第&nbsp;<code>(i % k)</code>&nbsp;个服务器空闲,那么对应服务器会处理该请求。</li>
<li>否则,将请求安排给下一个空闲的服务器(服务器构成一个环,必要的话可能从第 0 个服务器开始继续找下一个空闲的服务器)。比方说,如果第 <code>i</code>&nbsp;个服务器在忙,那么会查看第 <code>(i+1)</code>&nbsp;个服务器,第 <code>(i+2)</code>&nbsp;个服务器等等。</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>&nbsp;的正整数数组&nbsp;<code>arrival</code>&nbsp;,表示第&nbsp;<code>i</code>&nbsp;个任务的到达时间,和另一个数组&nbsp;<code>load</code>&nbsp;,其中&nbsp;<code>load[i]</code>&nbsp;表示第&nbsp;<code>i</code>&nbsp;个请求的工作量(也就是服务器完成它所需要的时间)。你的任务是找到 <strong>最繁忙的服务器</strong>&nbsp;。最繁忙定义为一个服务器处理的请求数是所有服务器里最多的。</p>
<p>请你返回包含所有 <strong>最繁忙服务器</strong> 序号的列表,你可以以任意顺序返回这个列表。</p>
<p>请你返回包含所有&nbsp;<strong>最繁忙服务器</strong>&nbsp;序号的列表,你可以以任意顺序返回这个列表。</p>
<p> </p>
<p>&nbsp;</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>&nbsp;</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 &lt;= k &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= arrival.length, load.length &lt;= 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 &lt;= arrival[i], load[i] &lt;= 10<sup>9</sup></code></li>
<li><code>arrival</code>&nbsp;保证 <strong>严格递增</strong>&nbsp;</li>
</ul>

@ -1,6 +1,6 @@
<p>有一个有 <code>n</code> 个节点的有向图,节点按 <code>0</code><code>n - 1</code> 编号。图由一个 <strong>索引从 0 开始</strong> 的 2D 整数数组&nbsp;<code>graph</code>表示,&nbsp;<code>graph[i]</code>是与节点 <code>i</code> 相邻的节点的整数数组,这意味着从节点 <code>i</code>&nbsp;<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>&nbsp;</p>
@ -35,6 +35,7 @@
<li><code>n == graph.length</code></li>
<li><code>1 &lt;= n &lt;= 10<sup>4</sup></code></li>
<li><code>0 &lt;= graph[i].length &lt;= n</code></li>
<li><code>0 &lt;= graph[i][j] &lt;= 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>,返回一个数组,在该数组中,&nbsp;<code>A</code> 的所有偶数元素之后跟着所有奇数元素。</p>
<p>你一个整数数组 <code>nums</code>,将 <code>nums</code> 中的的所有偶数元素移动到数组的前面,后跟所有奇数元素。</p>
<p>你可以返回满足此条件的任何数组作为答案。</p>
<p>返回满足此条件的 <strong>任一数组</strong> 作为答案。</p>
<p>&nbsp;</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>&nbsp;</p>
<p><strong>提示:</strong></p>
<ol>
<li><code>1 &lt;= A.length &lt;= 5000</code></li>
<li><code>0 &lt;= A[i] &lt;= 5000</code></li>
</ol>
<ul>
<li><code>1 &lt;= nums.length &lt;= 5000</code></li>
<li><code>0 &lt;= nums[i] &lt;= 5000</code></li>
</ul>

@ -1,37 +1,37 @@
小扣在秋日市集选择了一家早餐摊位,一维整型数组 `staple` 中记录了每种主食的价格,一维整型数组 `drinks` 中记录了每种饮料的价格。小扣的计划选择一份主食和一款饮料,且花费不超过 `x` 元。请返回小扣共有多少种购买方案。
注意:答案需要以 `1e9 + 7 (1000000007)` 为底取模,如:计算初始结果为:`1000000008`,请返回 `1`
**示例 1**
>输入:`staple = [10,20,5], drinks = [5,5,2], x = 15`
>
>输出:`6`
>
>解释:小扣有 6 种购买方案,所选主食与所选饮料在数组中对应的下标分别是:
>第 1 种方案staple[0] + drinks[0] = 10 + 5 = 15
>第 2 种方案staple[0] + drinks[1] = 10 + 5 = 15
>第 3 种方案staple[0] + drinks[2] = 10 + 2 = 12
>第 4 种方案staple[2] + drinks[0] = 5 + 5 = 10
>第 5 种方案staple[2] + drinks[1] = 5 + 5 = 10
>第 6 种方案staple[2] + drinks[2] = 5 + 2 = 7。
**示例 2**
>输入:`staple = [2,1,1], drinks = [8,9,5,1], x = 9`
>
>输出:`8`
>
>解释:小扣有 8 种购买方案,所选主食与所选饮料在数组中对应的下标分别是:
>第 1 种方案staple[0] + drinks[2] = 2 + 5 = 7
>第 2 种方案staple[0] + drinks[3] = 2 + 1 = 3
>第 3 种方案staple[1] + drinks[0] = 1 + 8 = 9
>第 4 种方案staple[1] + drinks[2] = 1 + 5 = 6
>第 5 种方案staple[1] + drinks[3] = 1 + 1 = 2
>第 6 种方案staple[2] + drinks[0] = 1 + 8 = 9
>第 7 种方案staple[2] + drinks[2] = 1 + 5 = 6
>第 8 种方案staple[2] + drinks[3] = 1 + 1 = 2
**提示:**
+ `1 <= staple.length <= 10^5`
+ `1 <= drinks.length <= 10^5`
+ `1 <= staple[i],drinks[i] <= 10^5`
小扣在秋日市集选择了一家早餐摊位,一维整型数组 `staple` 中记录了每种主食的价格,一维整型数组 `drinks` 中记录了每种饮料的价格。小扣的计划选择一份主食和一款饮料,且花费不超过 `x` 元。请返回小扣共有多少种购买方案。
注意:答案需要以 `1e9 + 7 (1000000007)` 为底取模,如:计算初始结果为:`1000000008`,请返回 `1`
**示例 1**
>输入:`staple = [10,20,5], drinks = [5,5,2], x = 15`
>
>输出:`6`
>
>解释:小扣有 6 种购买方案,所选主食与所选饮料在数组中对应的下标分别是:
>第 1 种方案staple[0] + drinks[0] = 10 + 5 = 15
>第 2 种方案staple[0] + drinks[1] = 10 + 5 = 15
>第 3 种方案staple[0] + drinks[2] = 10 + 2 = 12
>第 4 种方案staple[2] + drinks[0] = 5 + 5 = 10
>第 5 种方案staple[2] + drinks[1] = 5 + 5 = 10
>第 6 种方案staple[2] + drinks[2] = 5 + 2 = 7。
**示例 2**
>输入:`staple = [2,1,1], drinks = [8,9,5,1], x = 9`
>
>输出:`8`
>
>解释:小扣有 8 种购买方案,所选主食与所选饮料在数组中对应的下标分别是:
>第 1 种方案staple[0] + drinks[2] = 2 + 5 = 7
>第 2 种方案staple[0] + drinks[3] = 2 + 1 = 3
>第 3 种方案staple[1] + drinks[0] = 1 + 8 = 9
>第 4 种方案staple[1] + drinks[2] = 1 + 5 = 6
>第 5 种方案staple[1] + drinks[3] = 1 + 1 = 2
>第 6 种方案staple[2] + drinks[0] = 1 + 8 = 9
>第 7 种方案staple[2] + drinks[2] = 1 + 5 = 6
>第 8 种方案staple[2] + drinks[3] = 1 + 1 = 2
**提示:**
+ `1 <= staple.length <= 10^5`
+ `1 <= drinks.length <= 10^5`
+ `1 <= staple[i],drinks[i] <= 10^5`
+ `1 <= x <= 2*10^5`

@ -1,10 +1,10 @@
<p>给你一个整数数组 <code>nums</code>,和一个整数 <code>k</code></p>
<p>在一个操作中,您可以选择 <code>0 &lt;= i &lt; 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 &lt;= i &lt; 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>&nbsp;&nbsp;<strong>分数&nbsp;</strong>&nbsp;<code>nums</code>&nbsp;中最大和最小元素的差值。&nbsp;</p>
<p><em>在对nums中的每个索引最多应用一次上述操作后返回&nbsp;<code>nums</code> 的最低 <strong>分数</strong></em></p>
<p><em>在对&nbsp; <code>nums</code> 中的每个索引最多应用一次上述操作后,返回&nbsp;<code>nums</code> 的最低 <strong>分数</strong></em></p>
<p>&nbsp;</p>

@ -1,36 +1,33 @@
<p>你需要采用前序遍历的方式,将一个二叉树转换成一个由括号和整数组成的字符串。</p>
<p>给你二叉树的根节点 <code>root</code> ,请你采用前序遍历的方式,将二叉树转化为一个由括号和整数组成的字符串,返回构造出的字符串。</p>
<p>空节点则用一对空括号 &quot;()&quot; 表示。而且你需要省略所有不影响字符串与原始二叉树之间的一对一映射关系的空括号对。</p>
<p>空节点使用一对空括号对 <code>"()"</code> 表示,转化后需要省略所有不影响字符串与原始二叉树之间的一对一映射关系的空括号对。</p>
<p><strong>示例 1:</strong></p>
<div class="original__bRMd">
<div>
<p>&nbsp;</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> &quot;1(2(4))(3)&quot;
<strong>解释:</strong> 原本将是&ldquo;1(2(4)())(3())&rdquo;
在你省略所有不必要的空括号对之后,
它将是&ldquo;1(2(4))(3)&rdquo;
<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> &quot;1(2()(4))(3)&quot;
<p>&nbsp;</p>
<strong>解释:</strong> 和第一个示例相似,
除了我们不能省略第一个对括号来中断输入和输出之间的一对一映射关系。
</pre>
<p><strong>提示:</strong></p>
<ul>
<li>树中节点的数目范围是 <code>[1, 10<sup>4</sup>]</code></li>
<li><code>-1000 &lt;= Node.val &lt;= 1000</code></li>
</ul>
</div>
</div>

@ -1,10 +1,10 @@
<p>珂珂喜欢吃香蕉。这里有&nbsp;<code>N</code>&nbsp;堆香蕉,第 <code>i</code> 堆中有&nbsp;<code>piles[i]</code>&nbsp;根香蕉。警卫已经离开了,将在&nbsp;<code>H</code>&nbsp;小时后回来。</p>
<p>珂珂喜欢吃香蕉。这里有 <code>n</code> 堆香蕉,第 <code>i</code> 堆中有&nbsp;<code>piles[i]</code>&nbsp;根香蕉。警卫已经离开了,将在 <code>h</code> 小时后回来。</p>
<p>珂珂可以决定她吃香蕉的速度&nbsp;<code>K</code>&nbsp;(单位:根/小时)。每个小时,她将会选择一堆香蕉,从中吃掉 <code>K</code> 根。如果这堆香蕉少于 <code>K</code> 根,她将吃掉这堆的所有香蕉,然后这一小时内不会再吃更多的香蕉。&nbsp;&nbsp;</p>
<p>珂珂可以决定她吃香蕉的速度 <code>k</code> (单位:根/小时)。每个小时,她将会选择一堆香蕉,从中吃掉 <code>k</code> 根。如果这堆香蕉少于 <code>k</code> 根,她将吃掉这堆的所有香蕉,然后这一小时内不会再吃更多的香蕉。&nbsp;&nbsp;</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>&nbsp;</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>示例&nbsp;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>示例&nbsp;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>&nbsp;</p>
@ -34,7 +37,7 @@
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= piles.length &lt;= 10^4</code></li>
<li><code>piles.length &lt;= H &lt;= 10^9</code></li>
<li><code>1 &lt;= piles[i] &lt;= 10^9</code></li>
<li><code>1 &lt;= piles.length &lt;= 10<sup>4</sup></code></li>
<li><code>piles.length &lt;= h &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= piles[i] &lt;= 10<sup>9</sup></code></li>
</ul>

@ -1,10 +1,10 @@
<p>狒狒喜欢吃香蕉。这里有&nbsp;<code>N</code>&nbsp;堆香蕉,第 <code>i</code> 堆中有&nbsp;<code>piles[i]</code>&nbsp;根香蕉。警卫已经离开了,将在&nbsp;<code>H</code>&nbsp;小时后回来。</p>
<p>狒狒喜欢吃香蕉。这里有 <code>n</code> 堆香蕉,第 <code>i</code> 堆中有&nbsp;<code>piles[i]</code>&nbsp;根香蕉。警卫已经离开了,将在 <code>h</code> 小时后回来。</p>
<p>狒狒可以决定她吃香蕉的速度&nbsp;<code>K</code>&nbsp;(单位:根/小时)。每个小时,她将会选择一堆香蕉,从中吃掉 <code>K</code> 根。如果这堆香蕉少于 <code>K</code> 根,她将吃掉这堆的所有香蕉,然后这一小时内不会再吃更多的香蕉,下一个小时才会开始吃另一堆的香蕉。&nbsp;&nbsp;</p>
<p>狒狒可以决定她吃香蕉的速度 <code>k</code> (单位:根/小时)。每个小时,她将会选择一堆香蕉,从中吃掉 <code>k</code> 根。如果这堆香蕉少于 <code>k</code> 根,她将吃掉这堆的所有香蕉,然后这一小时内不会再吃更多的香蕉,下一个小时才会开始吃另一堆的香蕉。&nbsp;&nbsp;</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>&nbsp;</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>示例&nbsp;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>示例&nbsp;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>&nbsp;</p>
@ -37,11 +37,11 @@
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= piles.length &lt;= 10^4</code></li>
<li><code>piles.length &lt;= H &lt;= 10^9</code></li>
<li><code>1 &lt;= piles[i] &lt;= 10^9</code></li>
<li><code>1 &lt;= piles.length &lt;= 10<sup>4</sup></code></li>
<li><code>piles.length &lt;= h &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= piles[i] &lt;= 10<sup>9</sup></code></li>
</ul>
<p>&nbsp;</p>
<p><meta charset="UTF-8" />注意:本题与主站 875&nbsp;题相同:&nbsp;<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&nbsp;题相同:&nbsp;<a href="https://leetcode-cn.com/problems/koko-eating-bananas/">https://leetcode-cn.com/problems/koko-eating-bananas/</a></p>

@ -1,20 +1,20 @@
小扣出去秋游,途中收集了一些红叶和黄叶,他利用这些叶子初步整理了一份秋叶收藏集 `leaves` 字符串 `leaves` 仅包含小写字符 `r``y` 其中字符 `r` 表示一片红叶,字符 `y` 表示一片黄叶。
出于美观整齐的考虑,小扣想要将收藏集中树叶的排列调整成「红、黄、红」三部分。每部分树叶数量可以不相等,但均需大于等于 1。每次调整操作小扣可以将一片红叶替换成黄叶或者将一片黄叶替换成红叶。请问小扣最少需要多少次调整操作才能将秋叶收藏集调整完毕。
**示例 1**
>输入:`leaves = "rrryyyrryyyrr"`
>
>输出:`2`
>
>解释:调整两次,将中间的两片红叶替换成黄叶,得到 "rrryyyyyyyyrr"
**示例 2**
>输入:`leaves = "ryr"`
>
>输出:`0`
>
>解释:已符合要求,不需要额外操作
**提示:**
- `3 <= leaves.length <= 10^5`
小扣出去秋游,途中收集了一些红叶和黄叶,他利用这些叶子初步整理了一份秋叶收藏集 `leaves` 字符串 `leaves` 仅包含小写字符 `r``y` 其中字符 `r` 表示一片红叶,字符 `y` 表示一片黄叶。
出于美观整齐的考虑,小扣想要将收藏集中树叶的排列调整成「红、黄、红」三部分。每部分树叶数量可以不相等,但均需大于等于 1。每次调整操作小扣可以将一片红叶替换成黄叶或者将一片黄叶替换成红叶。请问小扣最少需要多少次调整操作才能将秋叶收藏集调整完毕。
**示例 1**
>输入:`leaves = "rrryyyrryyyrr"`
>
>输出:`2`
>
>解释:调整两次,将中间的两片红叶替换成黄叶,得到 "rrryyyyyyyyrr"
**示例 2**
>输入:`leaves = "ryr"`
>
>输出:`0`
>
>解释:已符合要求,不需要额外操作
**提示:**
- `3 <= leaves.length <= 10^5`
- `leaves` 中只包含字符 `'r'` 和字符 `'y'`

@ -1,39 +1,39 @@
秋游中的小力和小扣设计了一个追逐游戏。他们选了秋日市集景区中的 N 个景点,景点编号为 1~N。此外他们还选择了 N 条小路,满足任意两个景点之间都可以通过小路互相到达,且不存在两条连接景点相同的小路。整个游戏场景可视作一个无向连通图,记作二维数组 `edges`,数组中以 `[a,b]` 形式表示景点 a 与景点 b 之间有一条小路连通。
小力和小扣只能沿景点间的小路移动。小力的目标是在最快时间内追到小扣,小扣的目标是尽可能延后被小力追到的时间。游戏开始前,两人分别站在两个不同的景点 `startA``startB`。每一回合,小力先行动,小扣观察到小力的行动后再行动。小力和小扣在每回合可选择以下行动之一:
- 移动至相邻景点
- 留在原地
如果小力追到小扣(即两人于某一时刻出现在同一位置),则游戏结束。若小力可以追到小扣,请返回最少需要多少回合;若小力无法追到小扣,请返回 -1。
注意:小力和小扣一定会采取最优移动策略。
**示例 1**
>输入:`edges = [[1,2],[2,3],[3,4],[4,1],[2,5],[5,6]], startA = 3, startB = 5`
>
>输出:`3`
>
>解释:
>![image.png](https://pic.leetcode-cn.com/1597991318-goeHHr-image.png){:height="250px"}
>
>第一回合,小力移动至 2 号点,小扣观察到小力的行动后移动至 6 号点;
>第二回合,小力移动至 5 号点,小扣无法移动,留在原地;
>第三回合,小力移动至 6 号点,小力追到小扣。返回 3。
**示例 2**
>输入:`edges = [[1,2],[2,3],[3,4],[4,1]], startA = 1, startB = 3`
>
>输出:`-1`
>
>解释:
>![image.png](https://pic.leetcode-cn.com/1597991157-QfeakF-image.png){:height="250px"}
>
>小力如果不动,则小扣也不动;否则小扣移动到小力的对角线位置。这样小力无法追到小扣。
**提示:**
- `edges` 的长度等于图中节点个数
- `3 <= edges.length <= 10^5`
- `1 <= edges[i][0], edges[i][1] <= edges.length 且 edges[i][0] != edges[i][1]`
- `1 <= startA, startB <= edges.length 且 startA != startB`
秋游中的小力和小扣设计了一个追逐游戏。他们选了秋日市集景区中的 N 个景点,景点编号为 1~N。此外他们还选择了 N 条小路,满足任意两个景点之间都可以通过小路互相到达,且不存在两条连接景点相同的小路。整个游戏场景可视作一个无向连通图,记作二维数组 `edges`,数组中以 `[a,b]` 形式表示景点 a 与景点 b 之间有一条小路连通。
小力和小扣只能沿景点间的小路移动。小力的目标是在最快时间内追到小扣,小扣的目标是尽可能延后被小力追到的时间。游戏开始前,两人分别站在两个不同的景点 `startA``startB`。每一回合,小力先行动,小扣观察到小力的行动后再行动。小力和小扣在每回合可选择以下行动之一:
- 移动至相邻景点
- 留在原地
如果小力追到小扣(即两人于某一时刻出现在同一位置),则游戏结束。若小力可以追到小扣,请返回最少需要多少回合;若小力无法追到小扣,请返回 -1。
注意:小力和小扣一定会采取最优移动策略。
**示例 1**
>输入:`edges = [[1,2],[2,3],[3,4],[4,1],[2,5],[5,6]], startA = 3, startB = 5`
>
>输出:`3`
>
>解释:
>![image.png](https://pic.leetcode-cn.com/1597991318-goeHHr-image.png){:height="250px"}
>
>第一回合,小力移动至 2 号点,小扣观察到小力的行动后移动至 6 号点;
>第二回合,小力移动至 5 号点,小扣无法移动,留在原地;
>第三回合,小力移动至 6 号点,小力追到小扣。返回 3。
**示例 2**
>输入:`edges = [[1,2],[2,3],[3,4],[4,1]], startA = 1, startB = 3`
>
>输出:`-1`
>
>解释:
>![image.png](https://pic.leetcode-cn.com/1597991157-QfeakF-image.png){:height="250px"}
>
>小力如果不动,则小扣也不动;否则小扣移动到小力的对角线位置。这样小力无法追到小扣。
**提示:**
- `edges` 的长度等于图中节点个数
- `3 <= edges.length <= 10^5`
- `1 <= edges[i][0], edges[i][1] <= edges.length 且 edges[i][0] != edges[i][1]`
- `1 <= startA, startB <= edges.length 且 startA != startB`

@ -1,21 +1,21 @@
小扣在秋日市集发现了一款速算机器人。店家对机器人说出两个数字(记作 `x``y`),请小扣说出计算指令:
- `"A"` 运算:使 `x = 2 * x + y`
- `"B"` 运算:使 `y = 2 * y + x`
在本次游戏中,店家说出的数字为 `x = 1``y = 0`,小扣说出的计算指令记作仅由大写字母 `A``B` 组成的字符串 `s`,字符串中字符的顺序表示计算顺序,请返回最终 `x``y` 的和为多少。
**示例 1**
>输入:`s = "AB"`
>
>输出:`4`
>
>解释:
>经过一次 A 运算后x = 2, y = 0。
>再经过一次 B 运算x = 2, y = 2。
>最终 x 与 y 之和为 4。
**提示:**
- `0 <= s.length <= 10`
- `s``'A'``'B'` 组成
小扣在秋日市集发现了一款速算机器人。店家对机器人说出两个数字(记作 `x``y`),请小扣说出计算指令:
- `"A"` 运算:使 `x = 2 * x + y`
- `"B"` 运算:使 `y = 2 * y + x`
在本次游戏中,店家说出的数字为 `x = 1``y = 0`,小扣说出的计算指令记作仅由大写字母 `A``B` 组成的字符串 `s`,字符串中字符的顺序表示计算顺序,请返回最终 `x``y` 的和为多少。
**示例 1**
>输入:`s = "AB"`
>
>输出:`4`
>
>解释:
>经过一次 A 运算后x = 2, y = 0。
>再经过一次 B 运算x = 2, y = 2。
>最终 x 与 y 之和为 4。
**提示:**
- `0 <= s.length <= 10`
- `s``'A'``'B'` 组成

@ -10,8 +10,8 @@
| commission_rate | int |
| hire_date | date |
+-----------------+---------+
Sales_id是该表的主键列。
该表的每一行都显示了销售人员的姓名和ID以及他们的工资、佣金率和雇佣日期。
sales_id 是该表的主键列。
该表的每一行都显示了销售人员的姓名和 ID ,以及他们的工资、佣金率和雇佣日期。
</pre>
<p>&nbsp;</p>
@ -26,8 +26,8 @@ Sales_id是该表的主键列。
| name | varchar |
| city | varchar |
+-------------+---------+
Com_id是该表的主键列。
该表的每一行都表示公司的名称和ID以及公司所在的城市。
com_id 是该表的主键列。
该表的每一行都表示公司的名称和 ID ,以及公司所在的城市。
</pre>
<p>&nbsp;</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>&nbsp;</p>
@ -60,10 +60,10 @@ sales_id是来自销售员表com_id的外键。
<p>&nbsp;</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>
根据表&nbsp;<code>orders</code>&nbsp;中的订单 '3' 和 '4' ,容易看出只有 'John' 和 'Pam' 两个销售员曾经向公司 'RED' 销售过。
所以我们需要输出表&nbsp;<code>salesperson</code>&nbsp;中所有其他人的名字。</pre>

@ -1,25 +1,25 @@
<p>Given an array filled with letters and numbers, find the longest subarray with an equal number of letters and numbers.</p>
<p>Return the subarray. If there are more than one answer, return the one which has the smallest&nbsp;index of its left endpoint. If there is no answer, return an empty arrary.</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input: </strong>[&quot;A&quot;,&quot;1&quot;,&quot;B&quot;,&quot;C&quot;,&quot;D&quot;,&quot;2&quot;,&quot;3&quot;,&quot;4&quot;,&quot;E&quot;,&quot;5&quot;,&quot;F&quot;,&quot;G&quot;,&quot;6&quot;,&quot;7&quot;,&quot;H&quot;,&quot;I&quot;,&quot;J&quot;,&quot;K&quot;,&quot;L&quot;,&quot;M&quot;]
<strong>Output: </strong>[&quot;A&quot;,&quot;1&quot;,&quot;B&quot;,&quot;C&quot;,&quot;D&quot;,&quot;2&quot;,&quot;3&quot;,&quot;4&quot;,&quot;E&quot;,&quot;5&quot;,&quot;F&quot;,&quot;G&quot;,&quot;6&quot;,&quot;7&quot;]
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input: </strong>[&quot;A&quot;,&quot;A&quot;]
<strong>Output: </strong>[]
</pre>
<p><strong>Note: </strong></p>
<ul>
<li><code>array.length &lt;= 100000</code></li>
</ul>
<p>Given an array filled with letters and numbers, find the longest subarray with an equal number of letters and numbers.</p>
<p>Return the subarray. If there are more than one answer, return the one which has the smallest&nbsp;index of its left endpoint. If there is no answer, return an empty arrary.</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input: </strong>[&quot;A&quot;,&quot;1&quot;,&quot;B&quot;,&quot;C&quot;,&quot;D&quot;,&quot;2&quot;,&quot;3&quot;,&quot;4&quot;,&quot;E&quot;,&quot;5&quot;,&quot;F&quot;,&quot;G&quot;,&quot;6&quot;,&quot;7&quot;,&quot;H&quot;,&quot;I&quot;,&quot;J&quot;,&quot;K&quot;,&quot;L&quot;,&quot;M&quot;]
<strong>Output: </strong>[&quot;A&quot;,&quot;1&quot;,&quot;B&quot;,&quot;C&quot;,&quot;D&quot;,&quot;2&quot;,&quot;3&quot;,&quot;4&quot;,&quot;E&quot;,&quot;5&quot;,&quot;F&quot;,&quot;G&quot;,&quot;6&quot;,&quot;7&quot;]
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input: </strong>[&quot;A&quot;,&quot;A&quot;]
<strong>Output: </strong>[]
</pre>
<p><strong>Note: </strong></p>
<ul>
<li><code>array.length &lt;= 100000</code></li>
</ul>

@ -1,14 +1,14 @@
<p>Write a method to count the number of 2s that appear in all the numbers between 0&nbsp;and n (inclusive).</p>
<p><strong>Example:</strong></p>
<pre>
<strong>Input: </strong>25
<strong>Output: </strong>9
<strong>Explanation: </strong>(2, 12, 20, 21, 22, 23, 24, 25)(Note that 22 counts for two 2s.)</pre>
<p>Note:</p>
<ul>
<li><code>n &lt;= 10^9</code></li>
</ul>
<p>Write a method to count the number of 2s that appear in all the numbers between 0&nbsp;and n (inclusive).</p>
<p><strong>Example:</strong></p>
<pre>
<strong>Input: </strong>25
<strong>Output: </strong>9
<strong>Explanation: </strong>(2, 12, 20, 21, 22, 23, 24, 25)(Note that 22 counts for two 2s.)</pre>
<p>Note:</p>
<ul>
<li><code>n &lt;= 10^9</code></li>
</ul>

@ -1,20 +1,20 @@
<p>The data structure&nbsp;<code>TreeNode</code>&nbsp;is used for binary tree, but it can also used to represent a single linked list (where left is null, and right is the next node in the list). Implement a method to convert a binary search tree (implemented with <code>TreeNode</code>) into a single&nbsp;linked list. The values should be kept in order and the operation should be performed in place (that is, on the original data structure).</p>
<p>Return the head node of the linked list after converting.</p>
<p><b>Note:&nbsp;</b>This problem is slightly different from the original one in the book.</p>
<p>&nbsp;</p>
<p><strong>Example: </strong></p>
<pre>
<strong>Input: </strong> [4,2,5,1,3,null,6,0]
<strong>Output: </strong> [0,null,1,null,2,null,3,null,4,null,5,null,6]
</pre>
<p><strong>Note: </strong></p>
<ul>
<li>The number of nodes will not exceed&nbsp;100000.</li>
</ul>
<p>The data structure&nbsp;<code>TreeNode</code>&nbsp;is used for binary tree, but it can also used to represent a single linked list (where left is null, and right is the next node in the list). Implement a method to convert a binary search tree (implemented with <code>TreeNode</code>) into a single&nbsp;linked list. The values should be kept in order and the operation should be performed in place (that is, on the original data structure).</p>
<p>Return the head node of the linked list after converting.</p>
<p><b>Note:&nbsp;</b>This problem is slightly different from the original one in the book.</p>
<p>&nbsp;</p>
<p><strong>Example: </strong></p>
<pre>
<strong>Input: </strong> [4,2,5,1,3,null,6,0]
<strong>Output: </strong> [0,null,1,null,2,null,3,null,4,null,5,null,6]
</pre>
<p><strong>Note: </strong></p>
<ul>
<li>The number of nodes will not exceed&nbsp;100000.</li>
</ul>

@ -1,22 +1,22 @@
<p>Design and build a &quot;least recently used&quot; cache, which evicts the least recently used item. The cache should map from keys to values (allowing you to insert and retrieve a value associ&shy;ated with a particular key) and be initialized with a max size. When it is full, it should evict the least recently used item.</p>
<p>You should implement following operations:&nbsp;&nbsp;<code>get</code>&nbsp;and <code>put</code>.</p>
<p>Get a value by key:&nbsp;<code>get(key)</code> - If key is in the cache, return the value, otherwise return -1.<br />
Write a key-value pair to the cache:&nbsp;<code>put(key, value)</code> - If the key is not in the cache, then write its value to the cache. Evict the least recently used item before writing if necessary.</p>
<p><strong>Example:</strong></p>
<pre>
LRUCache cache = new LRUCache( 2 /* capacity */ );
cache.put(1, 1);
cache.put(2, 2);
cache.get(1); // returns 1
cache.put(3, 3); // evicts key 2
cache.get(2); // returns -1 (not found)
cache.put(4, 4); // evicts key 1
cache.get(1); // returns -1 (not found)
cache.get(3); // returns 3
cache.get(4); // returns 4
</pre>
<p>Design and build a &quot;least recently used&quot; cache, which evicts the least recently used item. The cache should map from keys to values (allowing you to insert and retrieve a value associ&shy;ated with a particular key) and be initialized with a max size. When it is full, it should evict the least recently used item.</p>
<p>You should implement following operations:&nbsp;&nbsp;<code>get</code>&nbsp;and <code>put</code>.</p>
<p>Get a value by key:&nbsp;<code>get(key)</code> - If key is in the cache, return the value, otherwise return -1.<br />
Write a key-value pair to the cache:&nbsp;<code>put(key, value)</code> - If the key is not in the cache, then write its value to the cache. Evict the least recently used item before writing if necessary.</p>
<p><strong>Example:</strong></p>
<pre>
LRUCache cache = new LRUCache( 2 /* capacity */ );
cache.put(1, 1);
cache.put(2, 2);
cache.get(1); // returns 1
cache.put(3, 3); // evicts key 2
cache.get(2); // returns -1 (not found)
cache.put(4, 4); // evicts key 1
cache.get(1); // returns -1 (not found)
cache.get(3); // returns 3
cache.get(4); // returns 4
</pre>

@ -1,25 +1,25 @@
<p>On old cell phones, users typed on a numeric keypad and the phone would provide a list of words that matched these numbers. Each digit mapped to a set of 0&nbsp;- 4 letters. Implement an algo&shy;rithm to return a list of matching words, given a sequence of digits. You are provided a list of valid words. The mapping is shown in the diagram below:</p>
<p><img src="https://assets.leetcode-cn.com/aliyun-lc-upload/original_images/17_telephone_keypad.png" style="width: 200px;" /></p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> num = &quot;8733&quot;, words = [&quot;tree&quot;, &quot;used&quot;]
<strong>Output:</strong> [&quot;tree&quot;, &quot;used&quot;]
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> num = &quot;2&quot;, words = [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;]
<strong>Output:</strong> [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;]</pre>
<p>Note:</p>
<ul>
<li><code>num.length &lt;= 1000</code></li>
<li><code>words.length &lt;= 500</code></li>
<li><code>words[i].length == num.length</code></li>
<li><code>There are no number 0 and 1 in num</code>.</li>
</ul>
<p>On old cell phones, users typed on a numeric keypad and the phone would provide a list of words that matched these numbers. Each digit mapped to a set of 0&nbsp;- 4 letters. Implement an algo&shy;rithm to return a list of matching words, given a sequence of digits. You are provided a list of valid words. The mapping is shown in the diagram below:</p>
<p><img src="https://assets.leetcode-cn.com/aliyun-lc-upload/original_images/17_telephone_keypad.png" style="width: 200px;" /></p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> num = &quot;8733&quot;, words = [&quot;tree&quot;, &quot;used&quot;]
<strong>Output:</strong> [&quot;tree&quot;, &quot;used&quot;]
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> num = &quot;2&quot;, words = [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;]
<strong>Output:</strong> [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;]</pre>
<p>Note:</p>
<ul>
<li><code>num.length &lt;= 1000</code></li>
<li><code>words.length &lt;= 500</code></li>
<li><code>words[i].length == num.length</code></li>
<li><code>There are no number 0 and 1 in num</code>.</li>
</ul>

@ -1,23 +1,23 @@
<p>Write a method to replace all spaces in a string with &#39;%20&#39;. You may assume that the string has sufficient space at the end to hold the additional characters,and that you are given the &quot;true&quot; length of the string. (Note: If implementing in Java,please use a character array so that you can perform this operation in place.)</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input: </strong>&quot;Mr John Smith &quot;, 13
<strong>Output: </strong>&quot;Mr%20John%20Smith&quot;
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input: </strong>&quot; &quot;, 5
<strong>Output: </strong>&quot;%20%20%20%20%20&quot;
</pre>
<p>&nbsp;</p>
<p><strong>Note:</strong></p>
<ol>
<li><code>0 &lt;= S.length &lt;= 500000</code></li>
</ol>
<p>Write a method to replace all spaces in a string with &#39;%20&#39;. You may assume that the string has sufficient space at the end to hold the additional characters,and that you are given the &quot;true&quot; length of the string. (Note: If implementing in Java,please use a character array so that you can perform this operation in place.)</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input: </strong>&quot;Mr John Smith &quot;, 13
<strong>Output: </strong>&quot;Mr%20John%20Smith&quot;
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input: </strong>&quot; &quot;, 5
<strong>Output: </strong>&quot;%20%20%20%20%20&quot;
</pre>
<p>&nbsp;</p>
<p><strong>Note:</strong></p>
<ol>
<li><code>0 &lt;= S.length &lt;= 500000</code></li>
</ol>

@ -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>&nbsp;</p>
<p><strong>Example 1:</strong></p>

@ -1,21 +1,21 @@
<p>There are three types of edits that can be performed on strings: insert a character, remove a character, or replace a character. Given two strings, write a function to check if they are one edit (or zero edits) away.</p>
<p>&nbsp;</p>
<p><strong>Example&nbsp;1:</strong></p>
<pre>
<strong>Input:</strong>
first = &quot;pale&quot;
second = &quot;ple&quot;
<strong>Output:</strong> True
</pre>
<p><strong>Example&nbsp;2:</strong></p>
<pre>
<strong>Input:</strong>
first = &quot;pales&quot;
second = &quot;pal&quot;
<strong>Output:</strong> False
</pre>
<p>There are three types of edits that can be performed on strings: insert a character, remove a character, or replace a character. Given two strings, write a function to check if they are one edit (or zero edits) away.</p>
<p>&nbsp;</p>
<p><strong>Example&nbsp;1:</strong></p>
<pre>
<strong>Input:</strong>
first = &quot;pale&quot;
second = &quot;ple&quot;
<strong>Output:</strong> True
</pre>
<p><strong>Example&nbsp;2:</strong></p>
<pre>
<strong>Input:</strong>
first = &quot;pales&quot;
second = &quot;pal&quot;
<strong>Output:</strong> False
</pre>

@ -1,26 +1,26 @@
<p>Describe how you could use a single array to implement three stacks.</p>
<p>You&nbsp;should implement&nbsp;<code>push(stackNum, value)</code><code>pop(stackNum)</code><code>isEmpty(stackNum)</code><code>peek(stackNum)</code>&nbsp;methods.&nbsp;<code>stackNum<font face="sans-serif, Arial, Verdana, Trebuchet MS">&nbsp;</font></code><font face="sans-serif, Arial, Verdana, Trebuchet MS">is the index of the stack.&nbsp;</font><code>value</code>&nbsp;is the value that pushed to the stack.</p>
<p>The constructor requires a&nbsp;<code>stackSize</code>&nbsp;parameter, which represents the size of each stack.</p>
<p><strong>Example1:</strong></p>
<pre>
<strong> Input</strong>:
[&quot;TripleInOne&quot;, &quot;push&quot;, &quot;push&quot;, &quot;pop&quot;, &quot;pop&quot;, &quot;pop&quot;, &quot;isEmpty&quot;]
[[1], [0, 1], [0, 2], [0], [0], [0], [0]]
<strong> Output</strong>:
[null, null, null, 1, -1, -1, true]
<b>Explanation</b>: When the stack is empty, `pop, peek` return -1. When the stack is full, `push` does nothing.
</pre>
<p><strong>Example2:</strong></p>
<pre>
<strong> Input</strong>:
[&quot;TripleInOne&quot;, &quot;push&quot;, &quot;push&quot;, &quot;push&quot;, &quot;pop&quot;, &quot;pop&quot;, &quot;pop&quot;, &quot;peek&quot;]
[[2], [0, 1], [0, 2], [0, 3], [0], [0], [0], [0]]
<strong> Output</strong>:
[null, null, null, null, 2, 1, -1, -1]
</pre>
<p>Describe how you could use a single array to implement three stacks.</p>
<p>You&nbsp;should implement&nbsp;<code>push(stackNum, value)</code><code>pop(stackNum)</code><code>isEmpty(stackNum)</code><code>peek(stackNum)</code>&nbsp;methods.&nbsp;<code>stackNum<font face="sans-serif, Arial, Verdana, Trebuchet MS">&nbsp;</font></code><font face="sans-serif, Arial, Verdana, Trebuchet MS">is the index of the stack.&nbsp;</font><code>value</code>&nbsp;is the value that pushed to the stack.</p>
<p>The constructor requires a&nbsp;<code>stackSize</code>&nbsp;parameter, which represents the size of each stack.</p>
<p><strong>Example1:</strong></p>
<pre>
<strong> Input</strong>:
[&quot;TripleInOne&quot;, &quot;push&quot;, &quot;push&quot;, &quot;pop&quot;, &quot;pop&quot;, &quot;pop&quot;, &quot;isEmpty&quot;]
[[1], [0, 1], [0, 2], [0], [0], [0], [0]]
<strong> Output</strong>:
[null, null, null, 1, -1, -1, true]
<b>Explanation</b>: When the stack is empty, `pop, peek` return -1. When the stack is full, `push` does nothing.
</pre>
<p><strong>Example2:</strong></p>
<pre>
<strong> Input</strong>:
[&quot;TripleInOne&quot;, &quot;push&quot;, &quot;push&quot;, &quot;push&quot;, &quot;pop&quot;, &quot;pop&quot;, &quot;pop&quot;, &quot;peek&quot;]
[[2], [0, 1], [0, 2], [0, 3], [0], [0], [0], [0]]
<strong> Output</strong>:
[null, null, null, null, 2, 1, -1, -1]
</pre>

@ -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>&nbsp;</p>
<p><strong>Constraints:</strong></p>

@ -1,21 +1,21 @@
<p>A child is running up a staircase with n steps and can hop either 1 step, 2 steps, or 3 steps at a time. Implement a method to count how many possible ways the child can run up the stairs.&nbsp;The result may be large, so return it modulo 1000000007.</p>
<p><strong>Example1:</strong></p>
<pre>
<strong> Input</strong>: n = 3
<strong> Output</strong>: 4
</pre>
<p><strong>Example2:</strong></p>
<pre>
<strong> Input</strong>: n = 5
<strong> Output</strong>: 13
</pre>
<p><strong>Note:</strong></p>
<ol>
<li><code>1 &lt;= n &lt;= 1000000</code></li>
</ol>
<p>A child is running up a staircase with n steps and can hop either 1 step, 2 steps, or 3 steps at a time. Implement a method to count how many possible ways the child can run up the stairs.&nbsp;The result may be large, so return it modulo 1000000007.</p>
<p><strong>Example1:</strong></p>
<pre>
<strong> Input</strong>: n = 3
<strong> Output</strong>: 4
</pre>
<p><strong>Example2:</strong></p>
<pre>
<strong> Input</strong>: n = 5
<strong> Output</strong>: 13
</pre>
<p><strong>Note:</strong></p>
<ol>
<li><code>1 &lt;= n &lt;= 1000000</code></li>
</ol>

@ -1,22 +1,22 @@
<p>Given a positive integer, print the next smallest and the next largest number that have the same number of 1 bits in their binary representation.</p>
<p><strong>Example1:</strong></p>
<pre>
<strong> Input</strong>: num = 2 (0b10)
<strong> Output</strong>: [4, 1] ([0b100, 0b1])
</pre>
<p><strong>Example2:</strong></p>
<pre>
<strong> Input</strong>: num = 1
<strong> Output</strong>: [2, -1]
</pre>
<p><strong>Note:</strong></p>
<ol>
<li><code>1 &lt;= num &lt;=&nbsp;2147483647</code></li>
<li>If there is no next smallest or next largest number, output -1.</li>
</ol>
<p>Given a positive integer, print the next smallest and the next largest number that have the same number of 1 bits in their binary representation.</p>
<p><strong>Example1:</strong></p>
<pre>
<strong> Input</strong>: num = 2 (0b10)
<strong> Output</strong>: [4, 1] ([0b100, 0b1])
</pre>
<p><strong>Example2:</strong></p>
<pre>
<strong> Input</strong>: num = 1
<strong> Output</strong>: [2, -1]
</pre>
<p><strong>Note:</strong></p>
<ol>
<li><code>1 &lt;= num &lt;=&nbsp;2147483647</code></li>
<li>If there is no next smallest or next largest number, output -1.</li>
</ol>

@ -1,10 +1,10 @@
<p>A robot is located at the top-left corner of a <code>m x n</code> grid (marked &#39;Start&#39; 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 &#39;Finish&#39; 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>&nbsp;</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 ==&nbsp;obstacleGrid.length</code></li>
<li><code>n ==&nbsp;obstacleGrid[i].length</code></li>
<li><code>m == obstacleGrid.length</code></li>
<li><code>n == obstacleGrid[i].length</code></li>
<li><code>1 &lt;= m, n &lt;= 100</code></li>
<li><code>obstacleGrid[i][j]</code> is <code>0</code> or <code>1</code>.</li>
</ul>

@ -1,16 +1,16 @@
<p>Write a function that adds two numbers. You should not use + or any arithmetic operators.</p>
<p><strong>Example:</strong></p>
<pre>
<strong>Input:</strong> a = 1, b = 1
<strong>Output:</strong> 2</pre>
<p>&nbsp;</p>
<p><strong>Note: </strong></p>
<ul>
<li><code>a</code>&nbsp;and&nbsp;<code>b</code>&nbsp;may be 0 or negative.</li>
<li>The result fits in 32-bit integer.</li>
</ul>
<p>Write a function that adds two numbers. You should not use + or any arithmetic operators.</p>
<p><strong>Example:</strong></p>
<pre>
<strong>Input:</strong> a = 1, b = 1
<strong>Output:</strong> 2</pre>
<p>&nbsp;</p>
<p><strong>Note: </strong></p>
<ul>
<li><code>a</code>&nbsp;and&nbsp;<code>b</code>&nbsp;may be 0 or negative.</li>
<li>The result fits in 32-bit integer.</li>
</ul>

@ -1,36 +1,36 @@
<p>The <strong>product difference</strong> between two pairs <code>(a, b)</code> and <code>(c, d)</code> is defined as <code>(a * b) - (c * d)</code>.</p>
<ul>
<li>For example, the product difference between <code>(5, 6)</code> and <code>(2, 7)</code> is <code>(5 * 6) - (2 * 7) = 16</code>.</li>
</ul>
<p>Given an integer array <code>nums</code>, choose four <strong>distinct</strong> indices <code>w</code>, <code>x</code>, <code>y</code>, and <code>z</code> such that the <strong>product difference</strong> between pairs <code>(nums[w], nums[x])</code> and <code>(nums[y], nums[z])</code> is <strong>maximized</strong>.</p>
<p>Return <em>the <strong>maximum</strong> such product difference</em>.</p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [5,6,2,7,4]
<strong>Output:</strong> 34
<strong>Explanation:</strong> We can choose indices 1 and 3 for the first pair (6, 7) and indices 2 and 4 for the second pair (2, 4).
The product difference is (6 * 7) - (2 * 4) = 34.
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> nums = [4,2,5,9,7,4,8]
<strong>Output:</strong> 64
<strong>Explanation:</strong> We can choose indices 3 and 6 for the first pair (9, 8) and indices 1 and 5 for the second pair (2, 4).
The product difference is (9 * 8) - (2 * 4) = 64.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>4 &lt;= nums.length &lt;= 10<sup>4</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
<p>The <strong>product difference</strong> between two pairs <code>(a, b)</code> and <code>(c, d)</code> is defined as <code>(a * b) - (c * d)</code>.</p>
<ul>
<li>For example, the product difference between <code>(5, 6)</code> and <code>(2, 7)</code> is <code>(5 * 6) - (2 * 7) = 16</code>.</li>
</ul>
<p>Given an integer array <code>nums</code>, choose four <strong>distinct</strong> indices <code>w</code>, <code>x</code>, <code>y</code>, and <code>z</code> such that the <strong>product difference</strong> between pairs <code>(nums[w], nums[x])</code> and <code>(nums[y], nums[z])</code> is <strong>maximized</strong>.</p>
<p>Return <em>the <strong>maximum</strong> such product difference</em>.</p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [5,6,2,7,4]
<strong>Output:</strong> 34
<strong>Explanation:</strong> We can choose indices 1 and 3 for the first pair (6, 7) and indices 2 and 4 for the second pair (2, 4).
The product difference is (6 * 7) - (2 * 4) = 34.
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> nums = [4,2,5,9,7,4,8]
<strong>Output:</strong> 64
<strong>Explanation:</strong> We can choose indices 3 and 6 for the first pair (9, 8) and indices 1 and 5 for the second pair (2, 4).
The product difference is (9 * 8) - (2 * 4) = 64.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>4 &lt;= nums.length &lt;= 10<sup>4</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
</ul>

@ -1,24 +1,24 @@
<p>A majority element is an element that makes up more than half of the items in an array. Given a&nbsp;integers array, find the majority element. If there is no majority element, return -1. Do this in O(N) time and O(1) space.</p>
<p><strong>Example 1: </strong></p>
<pre>
<strong>Input: </strong>[1,2,5,9,5,9,5,5,5]
<strong>Output: </strong>5</pre>
<p>&nbsp;</p>
<p><strong>Example 2: </strong></p>
<pre>
<strong>Input: </strong>[3,2]
<strong>Output: </strong>-1</pre>
<p>&nbsp;</p>
<p><strong>Example 3: </strong></p>
<pre>
<strong>Input: </strong>[2,2,1,1,1,2,2]
<strong>Output: </strong>2
</pre>
<p>A majority element is an element that makes up more than half of the items in an array. Given a&nbsp;integers array, find the majority element. If there is no majority element, return -1. Do this in O(N) time and O(1) space.</p>
<p><strong>Example 1: </strong></p>
<pre>
<strong>Input: </strong>[1,2,5,9,5,9,5,5,5]
<strong>Output: </strong>5</pre>
<p>&nbsp;</p>
<p><strong>Example 2: </strong></p>
<pre>
<strong>Input: </strong>[3,2]
<strong>Output: </strong>-1</pre>
<p>&nbsp;</p>
<p><strong>Example 3: </strong></p>
<pre>
<strong>Input: </strong>[2,2,1,1,1,2,2]
<strong>Output: </strong>2
</pre>

@ -1,19 +1,19 @@
<p>A binary search tree was created by traversing through an array from left to right and inserting each element. Given a binary search tree with distinct elements, print all possible arrays that could have led to this tree.</p>
<p><strong>Example:</strong><br />
Given the following tree:</p>
<pre>
2
/ \
1 3
</pre>
<p>Output:</p>
<pre>
[
[2,1,3],
[2,3,1]
]
</pre>
<p>A binary search tree was created by traversing through an array from left to right and inserting each element. Given a binary search tree with distinct elements, print all possible arrays that could have led to this tree.</p>
<p><strong>Example:</strong><br />
Given the following tree:</p>
<pre>
2
/ \
1 3
</pre>
<p>Output:</p>
<pre>
[
[2,1,3],
[2,3,1]
]
</pre>

@ -1 +1 @@
<p>English description is not available for the problem. Please switch to Chinese.</p>
<p>English description is not available for the problem. Please switch to Chinese.</p>

@ -1 +1 @@
<p>English description is not available for the problem. Please switch to Chinese.</p>
<p>English description is not available for the problem. Please switch to Chinese.</p>

@ -1 +1 @@
<p>English description is not available for the problem. Please switch to Chinese.</p>
<p>English description is not available for the problem. Please switch to Chinese.</p>

@ -1 +1 @@
<p>English description is not available for the problem. Please switch to Chinese.</p>
<p>English description is not available for the problem. Please switch to Chinese.</p>

@ -1,22 +1,23 @@
<p>Given a real number between 0 and 1 (e.g., 0.72) that is passed in as a double, print the binary representation. If the number cannot be represented accurately in binary with at most 32 characters, print &quot;ERROR&quot;.</p>
<p><strong>Example1:</strong></p>
<pre>
<strong> Input</strong>: 0.625
<strong> Output</strong>: &quot;0.101&quot;
</pre>
<p><strong>Example2:</strong></p>
<pre>
<strong> Input</strong>: 0.1
<strong> Output</strong>: &quot;ERROR&quot;
<strong> Note</strong>: 0.1 cannot be represented accurately in binary.
</pre>
<p><strong>Note: </strong></p>
<ol>
<li>This two charaters &quot;0.&quot; should be counted into 32 characters.</li>
</ol>
<p>Given a real number between 0 and 1 (e.g., 0.72) that is passed in as a double, print the binary representation. If the number cannot be represented accurately in binary with at most 32 characters, print &quot;ERROR&quot;.</p>
<p><strong>Example1:</strong></p>
<pre>
<strong> Input</strong>: 0.625
<strong> Output</strong>: &quot;0.101&quot;
</pre>
<p><strong>Example2:</strong></p>
<pre>
<strong> Input</strong>: 0.1
<strong> Output</strong>: &quot;ERROR&quot;
<strong> Note</strong>: 0.1 cannot be represented accurately in binary.
</pre>
<p><strong>Note: </strong></p>
<ul>
<li>This two charaters &quot;0.&quot; should be counted into 32 characters.</li>
<li>The number of decimal places for <code>num</code> is at most 6 digits</li>
</ul>

@ -1,44 +1,44 @@
<p>Design an algorithm to figure out if someone has won a game of tic-tac-toe.&nbsp;Input is a string array&nbsp;of size N x N, including characters &quot; &quot;, &quot;X&quot; and &quot;O&quot;, where &quot; &quot; represents a empty grid.</p>
<p>The rules of tic-tac-toe are as follows:</p>
<ul>
<li>Players place characters into an empty grid(&quot; &quot;) in turn.</li>
<li>The first player always place character &quot;O&quot;, and the second one place &quot;X&quot;.</li>
<li>Players are only allowed to place characters in empty grid. Replacing a character is not allowed.</li>
<li>If there is any row, column or diagonal filled with N&nbsp;same characters, the game ends. The player who place the last charater wins.</li>
<li>When there is no empty grid, the game ends.</li>
<li>If the game ends, players cannot place any character further.</li>
</ul>
<p>If there is any winner, return the character that the winner used. If there&#39;s a draw, return &quot;Draw&quot;. If the game doesn&#39;t end and there is no winner, return &quot;Pending&quot;.</p>
<p><strong>Example 1: </strong></p>
<pre>
<strong>Input: </strong> board = [&quot;O X&quot;,&quot; XO&quot;,&quot;X O&quot;]
<strong>Output: </strong> &quot;X&quot;
</pre>
<p><strong>Example 2: </strong></p>
<pre>
<strong>Input: </strong> board = [&quot;OOX&quot;,&quot;XXO&quot;,&quot;OXO&quot;]
<strong>Output: </strong> &quot;Draw&quot;
<strong>Explanation: </strong> no player wins and no empty grid left
</pre>
<p><strong>Example 3: </strong></p>
<pre>
<strong>Input: </strong> board = [&quot;OOX&quot;,&quot;XXO&quot;,&quot;OX &quot;]
<strong>Output: </strong> &quot;Pending&quot;
<strong>Explanation: </strong> no player wins but there is still a empty grid
</pre>
<p><strong>Note: </strong></p>
<ul>
<li><code>1 &lt;= board.length == board[i].length &lt;= 100</code></li>
<li>Input follows the rules.</li>
</ul>
<p>Design an algorithm to figure out if someone has won a game of tic-tac-toe.&nbsp;Input is a string array&nbsp;of size N x N, including characters &quot; &quot;, &quot;X&quot; and &quot;O&quot;, where &quot; &quot; represents a empty grid.</p>
<p>The rules of tic-tac-toe are as follows:</p>
<ul>
<li>Players place characters into an empty grid(&quot; &quot;) in turn.</li>
<li>The first player always place character &quot;O&quot;, and the second one place &quot;X&quot;.</li>
<li>Players are only allowed to place characters in empty grid. Replacing a character is not allowed.</li>
<li>If there is any row, column or diagonal filled with N&nbsp;same characters, the game ends. The player who place the last charater wins.</li>
<li>When there is no empty grid, the game ends.</li>
<li>If the game ends, players cannot place any character further.</li>
</ul>
<p>If there is any winner, return the character that the winner used. If there&#39;s a draw, return &quot;Draw&quot;. If the game doesn&#39;t end and there is no winner, return &quot;Pending&quot;.</p>
<p><strong>Example 1: </strong></p>
<pre>
<strong>Input: </strong> board = [&quot;O X&quot;,&quot; XO&quot;,&quot;X O&quot;]
<strong>Output: </strong> &quot;X&quot;
</pre>
<p><strong>Example 2: </strong></p>
<pre>
<strong>Input: </strong> board = [&quot;OOX&quot;,&quot;XXO&quot;,&quot;OXO&quot;]
<strong>Output: </strong> &quot;Draw&quot;
<strong>Explanation: </strong> no player wins and no empty grid left
</pre>
<p><strong>Example 3: </strong></p>
<pre>
<strong>Input: </strong> board = [&quot;OOX&quot;,&quot;XXO&quot;,&quot;OX &quot;]
<strong>Output: </strong> &quot;Pending&quot;
<strong>Explanation: </strong> no player wins but there is still a empty grid
</pre>
<p><strong>Note: </strong></p>
<ul>
<li><code>1 &lt;= board.length == board[i].length &lt;= 100</code></li>
<li>Input follows the rules.</li>
</ul>

@ -1,22 +1,22 @@
<p>Given two arrays of integers, find a pair of values (one value from each array) that you can swap to give the two arrays the same sum.</p>
<p>Return an array, where the first element is the element in the first array that will be swapped, and the second element is another one in the second array. If there are more than one answers, return any one of them. If there is no answer, return an empty array.</p>
<p><strong>Example:</strong></p>
<pre>
<strong>Input:</strong> array1 = [4, 1, 2, 1, 1, 2], array2 = [3, 6, 3, 3]
<strong>Output:</strong> [1, 3]
</pre>
<p><strong>Example:</strong></p>
<pre>
<strong>Input:</strong> array1 = <code>[1, 2, 3], array2 = [4, 5, 6]</code>
<strong>Output: </strong>[]</pre>
<p><strong>Note: </strong></p>
<ul>
<li><code>1 &lt;= array1.length, array2.length &lt;= 100000</code></li>
</ul>
<p>Given two arrays of integers, find a pair of values (one value from each array) that you can swap to give the two arrays the same sum.</p>
<p>Return an array, where the first element is the element in the first array that will be swapped, and the second element is another one in the second array. If there are more than one answers, return any one of them. If there is no answer, return an empty array.</p>
<p><strong>Example:</strong></p>
<pre>
<strong>Input:</strong> array1 = [4, 1, 2, 1, 1, 2], array2 = [3, 6, 3, 3]
<strong>Output:</strong> [1, 3]
</pre>
<p><strong>Example:</strong></p>
<pre>
<strong>Input:</strong> array1 = <code>[1, 2, 3], array2 = [4, 5, 6]</code>
<strong>Output: </strong>[]</pre>
<p><strong>Note: </strong></p>
<ul>
<li><code>1 &lt;= array1.length, array2.length &lt;= 100000</code></li>
</ul>

@ -1,15 +1,15 @@
<p>Write a function to swap a number in place (that is, without temporary variables).</p>
<p><strong>Example: </strong></p>
<pre>
<strong>Input:</strong> numbers = [1,2]
<strong>Output:</strong> [2,1]
</pre>
<p><strong>Note: </strong></p>
<ul>
<li><code>numbers.length == 2</code></li>
<li><code>-2147483647 &lt;= numbers[i] &lt;=&nbsp;2147483647</code></li>
</ul>
<p>Write a function to swap a number in place (that is, without temporary variables).</p>
<p><strong>Example: </strong></p>
<pre>
<strong>Input:</strong> numbers = [1,2]
<strong>Output:</strong> [2,1]
</pre>
<p><strong>Note: </strong></p>
<ul>
<li><code>numbers.length == 2</code></li>
<li><code>-2147483647 &lt;= numbers[i] &lt;=&nbsp;2147483647</code></li>
</ul>

@ -1,45 +1,45 @@
<p>You are given two strings <code>word1</code> and <code>word2</code>. Merge the strings by adding letters in alternating order, starting with <code>word1</code>. If a string is longer than the other, append the additional letters onto the end of the merged string.</p>
<p>Return <em>the merged string.</em></p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> word1 = &quot;abc&quot;, word2 = &quot;pqr&quot;
<strong>Output:</strong> &quot;apbqcr&quot;
<strong>Explanation:</strong>&nbsp;The merged string will be merged as so:
word1: a b c
word2: p q r
merged: a p b q c r
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> word1 = &quot;ab&quot;, word2 = &quot;pqrs&quot;
<strong>Output:</strong> &quot;apbqrs&quot;
<strong>Explanation:</strong>&nbsp;Notice that as word2 is longer, &quot;rs&quot; is appended to the end.
word1: a b
word2: p q r s
merged: a p b q r s
</pre>
<p><strong>Example 3:</strong></p>
<pre>
<strong>Input:</strong> word1 = &quot;abcd&quot;, word2 = &quot;pq&quot;
<strong>Output:</strong> &quot;apbqcd&quot;
<strong>Explanation:</strong>&nbsp;Notice that as word1 is longer, &quot;cd&quot; is appended to the end.
word1: a b c d
word2: p q
merged: a p b q c d
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= word1.length, word2.length &lt;= 100</code></li>
<li><code>word1</code> and <code>word2</code> consist of lowercase English letters.</li>
<p>You are given two strings <code>word1</code> and <code>word2</code>. Merge the strings by adding letters in alternating order, starting with <code>word1</code>. If a string is longer than the other, append the additional letters onto the end of the merged string.</p>
<p>Return <em>the merged string.</em></p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> word1 = &quot;abc&quot;, word2 = &quot;pqr&quot;
<strong>Output:</strong> &quot;apbqcr&quot;
<strong>Explanation:</strong>&nbsp;The merged string will be merged as so:
word1: a b c
word2: p q r
merged: a p b q c r
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> word1 = &quot;ab&quot;, word2 = &quot;pqrs&quot;
<strong>Output:</strong> &quot;apbqrs&quot;
<strong>Explanation:</strong>&nbsp;Notice that as word2 is longer, &quot;rs&quot; is appended to the end.
word1: a b
word2: p q r s
merged: a p b q r s
</pre>
<p><strong>Example 3:</strong></p>
<pre>
<strong>Input:</strong> word1 = &quot;abcd&quot;, word2 = &quot;pq&quot;
<strong>Output:</strong> &quot;apbqcd&quot;
<strong>Explanation:</strong>&nbsp;Notice that as word1 is longer, &quot;cd&quot; is appended to the end.
word1: a b c d
word2: p q
merged: a p b q c d
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= word1.length, word2.length &lt;= 100</code></li>
<li><code>word1</code> and <code>word2</code> consist of lowercase English letters.</li>
</ul>

@ -1,36 +1,36 @@
<p>Given two straight line segments (represented as a start point and an end point), compute the point of intersection, if any. If there&#39;s no intersection, return an empty array.</p>
The absolute error should not exceed 10^-6. If there are more than one intersections, return the one with smallest X axis value. If there are more than one intersections that have same X axis value, return the one with smallest Y axis value.
<p><strong>Example 1: </strong></p>
<pre>
<strong>Input: </strong>
line1 = {0, 0}, {1, 0}
line2 = {1, 1}, {0, -1}
<strong>Output: </strong> {0.5, 0}
</pre>
<p><strong>Example 2: </strong></p>
<pre>
<strong>Input: </strong>
line1 = {0, 0}, {3, 3}
line2 = {1, 1}, {2, 2}
<strong>Output: </strong> {1, 1}
</pre>
<p><strong>Example 3: </strong></p>
<pre>
<strong>Input: </strong>
line1 = {0, 0}, {1, 1}
line2 = {1, 0}, {2, 1}
<strong>Output: </strong> {} (no intersection)
</pre>
<p><strong>Note: </strong></p>
<ul>
<li>The absolute value of coordinate value will not exceed 2^7.</li>
<li>All coordinates are valid 2D coordinates.</li>
</ul>
<p>Given two straight line segments (represented as a start point and an end point), compute the point of intersection, if any. If there&#39;s no intersection, return an empty array.</p>
The absolute error should not exceed 10^-6. If there are more than one intersections, return the one with smallest X axis value. If there are more than one intersections that have same X axis value, return the one with smallest Y axis value.
<p><strong>Example 1: </strong></p>
<pre>
<strong>Input: </strong>
line1 = {0, 0}, {1, 0}
line2 = {1, 1}, {0, -1}
<strong>Output: </strong> {0.5, 0}
</pre>
<p><strong>Example 2: </strong></p>
<pre>
<strong>Input: </strong>
line1 = {0, 0}, {3, 3}
line2 = {1, 1}, {2, 2}
<strong>Output: </strong> {1, 1}
</pre>
<p><strong>Example 3: </strong></p>
<pre>
<strong>Input: </strong>
line1 = {0, 0}, {1, 1}
line2 = {1, 0}, {2, 1}
<strong>Output: </strong> {} (no intersection)
</pre>
<p><strong>Note: </strong></p>
<ul>
<li>The absolute value of coordinate value will not exceed 2^7.</li>
<li>All coordinates are valid 2D coordinates.</li>
</ul>

@ -1,22 +1,22 @@
<p>Write an algorithm to print all ways of arranging n queens on an n x n&nbsp;chess board so that none of them share the same row, column, or diagonal. In this case, &quot;diagonal&quot; means all diagonals, not just the two that bisect the board.</p>
<p><strong>Notes: </strong>This&nbsp;problem is a generalization of the original one in the book.</p>
<p><strong>Example:</strong></p>
<pre>
<strong> Input</strong>: 4
<strong> Output</strong>: [[&quot;.Q..&quot;,&quot;...Q&quot;,&quot;Q...&quot;,&quot;..Q.&quot;],[&quot;..Q.&quot;,&quot;Q...&quot;,&quot;...Q&quot;,&quot;.Q..&quot;]]
<strong> Explanation</strong>: 4 queens has following two solutions
[
&nbsp;[&quot;.Q..&quot;, &nbsp;// solution 1
&nbsp; &quot;...Q&quot;,
&nbsp; &quot;Q...&quot;,
&nbsp; &quot;..Q.&quot;],
&nbsp;[&quot;..Q.&quot;, &nbsp;// solution 2
&nbsp; &quot;Q...&quot;,
&nbsp; &quot;...Q&quot;,
&nbsp; &quot;.Q..&quot;]
]
</pre>
<p>Write an algorithm to print all ways of arranging n queens on an n x n&nbsp;chess board so that none of them share the same row, column, or diagonal. In this case, &quot;diagonal&quot; means all diagonals, not just the two that bisect the board.</p>
<p><strong>Notes: </strong>This&nbsp;problem is a generalization of the original one in the book.</p>
<p><strong>Example:</strong></p>
<pre>
<strong> Input</strong>: 4
<strong> Output</strong>: [[&quot;.Q..&quot;,&quot;...Q&quot;,&quot;Q...&quot;,&quot;..Q.&quot;],[&quot;..Q.&quot;,&quot;Q...&quot;,&quot;...Q&quot;,&quot;.Q..&quot;]]
<strong> Explanation</strong>: 4 queens has following two solutions
[
&nbsp;[&quot;.Q..&quot;, &nbsp;// solution 1
&nbsp; &quot;...Q&quot;,
&nbsp; &quot;Q...&quot;,
&nbsp; &quot;..Q.&quot;],
&nbsp;[&quot;..Q.&quot;, &nbsp;// solution 2
&nbsp; &quot;Q...&quot;,
&nbsp; &quot;...Q&quot;,
&nbsp; &quot;.Q..&quot;]
]
</pre>

@ -1,47 +1,47 @@
<p>An ant is sitting on an infinite grid of white and black squares. It initially faces right. All squares are white initially.</p>
<p>At each step, it does the following:</p>
<p>(1) At a white square, flip the color of the square, turn 90 degrees right (clockwise), and move forward one unit.</p>
<p>(2) At a black square, flip the color of the square, turn 90 degrees left (counter-clockwise), and move forward one unit.</p>
<p>Write a program to simulate the first K moves that the ant makes and print the final board as a grid.</p>
<p>The grid should be represented as an array of strings, where each element represents one row in the grid. The black square is represented as <code>&#39;X&#39;</code>, and the white square is represented as <code>&#39;_&#39;</code>, the square which is occupied by the ant is represented as <code>&#39;L&#39;</code>, <code>&#39;U&#39;</code>, <code>&#39;R&#39;</code>, <code>&#39;D&#39;</code>, which means the left, up, right and down orientations respectively. You only need to return the minimum matrix that is able to contain all squares that are passed through by the ant.</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> 0
<strong>Output: </strong>[&quot;R&quot;]
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> 2
<strong>Output:
</strong>[
&nbsp; &quot;_X&quot;,
&nbsp; &quot;LX&quot;
]
</pre>
<p><strong>Example 3:</strong></p>
<pre>
<strong>Input:</strong> 5
<strong>Output:
</strong>[
&nbsp; &quot;_U&quot;,
&nbsp; &quot;X_&quot;,
&nbsp; &quot;XX&quot;
]
</pre>
<p><strong>Note: </strong></p>
<ul>
<li><code>K &lt;= 100000</code></li>
</ul>
<p>An ant is sitting on an infinite grid of white and black squares. It initially faces right. All squares are white initially.</p>
<p>At each step, it does the following:</p>
<p>(1) At a white square, flip the color of the square, turn 90 degrees right (clockwise), and move forward one unit.</p>
<p>(2) At a black square, flip the color of the square, turn 90 degrees left (counter-clockwise), and move forward one unit.</p>
<p>Write a program to simulate the first K moves that the ant makes and print the final board as a grid.</p>
<p>The grid should be represented as an array of strings, where each element represents one row in the grid. The black square is represented as <code>&#39;X&#39;</code>, and the white square is represented as <code>&#39;_&#39;</code>, the square which is occupied by the ant is represented as <code>&#39;L&#39;</code>, <code>&#39;U&#39;</code>, <code>&#39;R&#39;</code>, <code>&#39;D&#39;</code>, which means the left, up, right and down orientations respectively. You only need to return the minimum matrix that is able to contain all squares that are passed through by the ant.</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> 0
<strong>Output: </strong>[&quot;R&quot;]
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> 2
<strong>Output:
</strong>[
&nbsp; &quot;_X&quot;,
&nbsp; &quot;LX&quot;
]
</pre>
<p><strong>Example 3:</strong></p>
<pre>
<strong>Input:</strong> 5
<strong>Output:
</strong>[
&nbsp; &quot;_U&quot;,
&nbsp; &quot;X_&quot;,
&nbsp; &quot;XX&quot;
]
</pre>
<p><strong>Note: </strong></p>
<ul>
<li><code>K &lt;= 100000</code></li>
</ul>

@ -1,8 +1,8 @@
<p>Write code to partition a linked list around a value x, such that all nodes less than x come before all nodes greater than or equal to x. If x is contained within the list, the values of x only need to be after the elements less than x (see below). The partition element x can appear anywhere in the &quot;right partition&quot;; it does not need to appear between the left and right partitions.</p>
<p><strong>Example:</strong></p>
<pre>
<strong>Input:</strong> head = 3-&gt;5-&gt;8-&gt;5-&gt;10-&gt;2-&gt;1, <em>x</em> = 5
<strong>Output:</strong> 3-&gt;1-&gt;2-&gt;10-&gt;5-&gt;5-&gt;8
</pre>
<p>Write code to partition a linked list around a value x, such that all nodes less than x come before all nodes greater than or equal to x. If x is contained within the list, the values of x only need to be after the elements less than x (see below). The partition element x can appear anywhere in the &quot;right partition&quot;; it does not need to appear between the left and right partitions.</p>
<p><strong>Example:</strong></p>
<pre>
<strong>Input:</strong> head = 3-&gt;5-&gt;8-&gt;5-&gt;10-&gt;2-&gt;1, <em>x</em> = 5
<strong>Output:</strong> 3-&gt;1-&gt;2-&gt;10-&gt;5-&gt;5-&gt;8
</pre>

@ -1,2 +1,2 @@
<p>English description is not available for the problem. Please switch to Chinese.<br />
&nbsp;</p>
<p>English description is not available for the problem. Please switch to Chinese.<br />
&nbsp;</p>

@ -1,10 +1,10 @@
<p>Implement an algorithm to delete a node in the middle (i.e., any node but the first and last node, not necessarily the exact middle) of a singly linked list, given only access to that node.</p>
<p>&nbsp;</p>
<p><strong>Example: </strong></p>
<pre>
<strong>Input: </strong>the node c from the linked list a-&gt;b-&gt;c-&gt;d-&gt;e-&gt;f
<strong>Output: </strong>nothing is returned, but the new linked list looks like a-&gt;b-&gt;d-&gt;e-&gt;f
</pre>
<p>Implement an algorithm to delete a node in the middle (i.e., any node but the first and last node, not necessarily the exact middle) of a singly linked list, given only access to that node.</p>
<p>&nbsp;</p>
<p><strong>Example: </strong></p>
<pre>
<strong>Input: </strong>the node c from the linked list a-&gt;b-&gt;c-&gt;d-&gt;e-&gt;f
<strong>Output: </strong>nothing is returned, but the new linked list looks like a-&gt;b-&gt;d-&gt;e-&gt;f
</pre>

@ -1,23 +1,23 @@
<p>Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structures?</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input: </strong><code>s</code> = &quot;leetcode&quot;
<strong>Output: </strong>false
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input: </strong><code>s</code> = &quot;abc&quot;
<strong>Output: </strong>true
</pre>
<p>&nbsp;</p>
<p><strong>Note:</strong></p>
<ul>
<li><code>0 &lt;= len(s) &lt;= 100 </code></li>
</ul>
<p>Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structures?</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input: </strong><code>s</code> = &quot;leetcode&quot;
<strong>Output: </strong>false
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input: </strong><code>s</code> = &quot;abc&quot;
<strong>Output: </strong>true
</pre>
<p>&nbsp;</p>
<p><strong>Note:</strong></p>
<ul>
<li><code>0 &lt;= len(s) &lt;= 100 </code></li>
</ul>

@ -1,22 +1,22 @@
<p>Given two strings,write a method to decide if one is a permutation of the other.</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input: </strong><code>s1</code> = &quot;abc&quot;, <code>s2</code> = &quot;bca&quot;
<strong>Output: </strong>true
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input: </strong><code>s1</code> = &quot;abc&quot;, <code>s2</code> = &quot;bad&quot;
<strong>Output: </strong>false
</pre>
<p><strong>Note:</strong></p>
<ol>
<li><code>0 &lt;= len(s1) &lt;= 100 </code></li>
<li><code>0 &lt;= len(s2) &lt;= 100</code></li>
</ol>
<p>Given two strings,write a method to decide if one is a permutation of the other.</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input: </strong><code>s1</code> = &quot;abc&quot;, <code>s2</code> = &quot;bca&quot;
<strong>Output: </strong>true
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input: </strong><code>s1</code> = &quot;abc&quot;, <code>s2</code> = &quot;bad&quot;
<strong>Output: </strong>false
</pre>
<p><strong>Note:</strong></p>
<ol>
<li><code>0 &lt;= len(s1) &lt;= 100 </code></li>
<li><code>0 &lt;= len(s2) &lt;= 100</code></li>
</ol>

@ -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>&quot;&quot;</code> is returned.</p>
<p>A string is <strong>decrypted</strong> with the following process:</p>
<ol>

@ -1,31 +1,31 @@
<p>An animal shelter, which holds only dogs and cats, operates on a strictly&quot;first in, first out&quot; basis. People must adopt either the&quot;oldest&quot; (based on arrival time) of all animals at the shelter, or they can select whether they would prefer a dog or a cat (and will receive the oldest animal of that type). They cannot select which specific animal they would like. Create the data structures to maintain this system and implement operations such as <code>enqueue</code>, <code>dequeueAny</code>, <code>dequeueDog</code>, and <code>dequeueCat</code>. You may use the built-in Linked list data structure.</p>
<p><code>enqueue</code> method has a <code>animal</code> parameter, <code>animal[0]</code> represents the number of the animal, <code>animal[1]</code> represents the type of the animal, 0 for cat and 1 for dog.</p>
<p><code>dequeue*</code> method returns <code>[animal number, animal type]</code>, if there&#39;s no animal that can be adopted, return <code>[-1, -1]</code>.</p>
<p><strong>Example1:</strong></p>
<pre>
<strong> Input</strong>:
[&quot;AnimalShelf&quot;, &quot;enqueue&quot;, &quot;enqueue&quot;, &quot;dequeueCat&quot;, &quot;dequeueDog&quot;, &quot;dequeueAny&quot;]
[[], [[0, 0]], [[1, 0]], [], [], []]
<strong> Output</strong>:
[null,null,null,[0,0],[-1,-1],[1,0]]
</pre>
<p><strong>Example2:</strong></p>
<pre>
<strong> Input</strong>:
[&quot;AnimalShelf&quot;, &quot;enqueue&quot;, &quot;enqueue&quot;, &quot;enqueue&quot;, &quot;dequeueDog&quot;, &quot;dequeueCat&quot;, &quot;dequeueAny&quot;]
[[], [[0, 0]], [[1, 0]], [[2, 1]], [], [], []]
<strong> Output</strong>:
[null,null,null,null,[2,1],[0,0],[1,0]]
</pre>
<p><strong>Note:</strong></p>
<ol>
<li>The number of animals in the shelter will not exceed 20000.</li>
</ol>
<p>An animal shelter, which holds only dogs and cats, operates on a strictly&quot;first in, first out&quot; basis. People must adopt either the&quot;oldest&quot; (based on arrival time) of all animals at the shelter, or they can select whether they would prefer a dog or a cat (and will receive the oldest animal of that type). They cannot select which specific animal they would like. Create the data structures to maintain this system and implement operations such as <code>enqueue</code>, <code>dequeueAny</code>, <code>dequeueDog</code>, and <code>dequeueCat</code>. You may use the built-in Linked list data structure.</p>
<p><code>enqueue</code> method has a <code>animal</code> parameter, <code>animal[0]</code> represents the number of the animal, <code>animal[1]</code> represents the type of the animal, 0 for cat and 1 for dog.</p>
<p><code>dequeue*</code> method returns <code>[animal number, animal type]</code>, if there&#39;s no animal that can be adopted, return <code>[-1, -1]</code>.</p>
<p><strong>Example1:</strong></p>
<pre>
<strong> Input</strong>:
[&quot;AnimalShelf&quot;, &quot;enqueue&quot;, &quot;enqueue&quot;, &quot;dequeueCat&quot;, &quot;dequeueDog&quot;, &quot;dequeueAny&quot;]
[[], [[0, 0]], [[1, 0]], [], [], []]
<strong> Output</strong>:
[null,null,null,[0,0],[-1,-1],[1,0]]
</pre>
<p><strong>Example2:</strong></p>
<pre>
<strong> Input</strong>:
[&quot;AnimalShelf&quot;, &quot;enqueue&quot;, &quot;enqueue&quot;, &quot;enqueue&quot;, &quot;dequeueDog&quot;, &quot;dequeueCat&quot;, &quot;dequeueAny&quot;]
[[], [[0, 0]], [[1, 0]], [[2, 1]], [], [], []]
<strong> Output</strong>:
[null,null,null,null,[2,1],[0,0],[1,0]]
</pre>
<p><strong>Note:</strong></p>
<ol>
<li>The number of animals in the shelter will not exceed 20000.</li>
</ol>

@ -1,25 +1,25 @@
<p>Implement a MyQueue class which implements a queue using two stacks.</p>
&nbsp;
<p><strong>Example: </strong></p>
<pre>
MyQueue queue = new MyQueue();
queue.push(1);
queue.push(2);
queue.peek(); // return 1
queue.pop(); // return 1
queue.empty(); // return false</pre>
<p>&nbsp;</p>
<p><b>Notes:</b></p>
<ul>
<li>You must use&nbsp;<i>only</i>&nbsp;standard operations of a stack -- which means only&nbsp;<code>push to top</code>,&nbsp;<code>peek/pop from top</code>,&nbsp;<code>size</code>, and&nbsp;<code>is empty</code>&nbsp;operations are valid.</li>
<li>Depending on your language, stack may not be supported natively. You may simulate a stack by using a list or deque (double-ended queue), as long as you use only standard operations of a stack.</li>
<li>You may assume that all operations are valid (for example, no pop or peek operations will be called on an empty queue).</li>
</ul>
<p>&nbsp;</p>
<p>Implement a MyQueue class which implements a queue using two stacks.</p>
&nbsp;
<p><strong>Example: </strong></p>
<pre>
MyQueue queue = new MyQueue();
queue.push(1);
queue.push(2);
queue.peek(); // return 1
queue.pop(); // return 1
queue.empty(); // return false</pre>
<p>&nbsp;</p>
<p><b>Notes:</b></p>
<ul>
<li>You must use&nbsp;<i>only</i>&nbsp;standard operations of a stack -- which means only&nbsp;<code>push to top</code>,&nbsp;<code>peek/pop from top</code>,&nbsp;<code>size</code>, and&nbsp;<code>is empty</code>&nbsp;operations are valid.</li>
<li>Depending on your language, stack may not be supported natively. You may simulate a stack by using a list or deque (double-ended queue), as long as you use only standard operations of a stack.</li>
<li>You may assume that all operations are valid (for example, no pop or peek operations will be called on an empty queue).</li>
</ul>
<p>&nbsp;</p>

@ -1,28 +1,28 @@
<p>Given a list of millions of words, design an algorithm to create the largest possible rectangle of letters such that every row forms a word (reading left to right) and every column forms a word (reading top to bottom). The words need not be chosen consecutively from the list but all rows must be the same length and all columns must be the same height.</p>
<p>If there are more than one answer, return any one of them. A word can be used more than once.</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> <code>[&quot;this&quot;, &quot;real&quot;, &quot;hard&quot;, &quot;trh&quot;, &quot;hea&quot;, &quot;iar&quot;, &quot;sld&quot;]</code>
<strong>Output:
</strong><code>[
&nbsp; &quot;this&quot;,
&nbsp; &quot;real&quot;,
&nbsp; &quot;hard&quot;</code>
]</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> <code>[&quot;aa&quot;]</code>
<strong>Output: </strong>[&quot;aa&quot;,&quot;aa&quot;]</pre>
<p><strong>Notes: </strong></p>
<ul>
<li><code>words.length &lt;= 1000</code></li>
<li><code>words[i].length &lt;= 100</code></li>
<li>It&#39;s guaranteed that&nbsp;all the words are randomly generated.</li>
</ul>
<p>Given a list of millions of words, design an algorithm to create the largest possible rectangle of letters such that every row forms a word (reading left to right) and every column forms a word (reading top to bottom). The words need not be chosen consecutively from the list but all rows must be the same length and all columns must be the same height.</p>
<p>If there are more than one answer, return any one of them. A word can be used more than once.</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> <code>[&quot;this&quot;, &quot;real&quot;, &quot;hard&quot;, &quot;trh&quot;, &quot;hea&quot;, &quot;iar&quot;, &quot;sld&quot;]</code>
<strong>Output:
</strong><code>[
&nbsp; &quot;this&quot;,
&nbsp; &quot;real&quot;,
&nbsp; &quot;hard&quot;</code>
]</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> <code>[&quot;aa&quot;]</code>
<strong>Output: </strong>[&quot;aa&quot;,&quot;aa&quot;]</pre>
<p><strong>Notes: </strong></p>
<ul>
<li><code>words.length &lt;= 1000</code></li>
<li><code>words[i].length &lt;= 100</code></li>
<li>It&#39;s guaranteed that&nbsp;all the words are randomly generated.</li>
</ul>

@ -1,13 +1,13 @@
<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><strong>Example: </strong></p>
<pre>
<strong>Input: </strong>words = [&quot;I&quot;,&quot;am&quot;,&quot;a&quot;,&quot;student&quot;,&quot;from&quot;,&quot;a&quot;,&quot;university&quot;,&quot;in&quot;,&quot;a&quot;,&quot;city&quot;], word1 = &quot;a&quot;, word2 = &quot;student&quot;
<strong>Output: </strong>1</pre>
<p>Note:</p>
<ul>
<li><code>words.length &lt;= 100000</code></li>
</ul>
<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>
<p><strong>Example: </strong></p>
<pre>
<strong>Input: </strong>words = [&quot;I&quot;,&quot;am&quot;,&quot;a&quot;,&quot;student&quot;,&quot;from&quot;,&quot;a&quot;,&quot;university&quot;,&quot;in&quot;,&quot;a&quot;,&quot;city&quot;], word1 = &quot;a&quot;, word2 = &quot;student&quot;
<strong>Output: </strong>1</pre>
<p>Note:</p>
<ul>
<li><code>words.length &lt;= 100000</code></li>
</ul>

@ -1,27 +1,27 @@
<p>Given two words of equal length that are in a dictionary, write a method to transform one word into another word by changing only one letter at a time. The new word you get in each step must be in the dictionary.</p>
<p>Write code to return a possible transforming sequence. If there is more than one sequence, return any of them.</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong>
beginWord = &quot;hit&quot;,
endWord = &quot;cog&quot;,
wordList = [&quot;hot&quot;,&quot;dot&quot;,&quot;dog&quot;,&quot;lot&quot;,&quot;log&quot;,&quot;cog&quot;]
<strong>Output:</strong>
[&quot;hit&quot;,&quot;hot&quot;,&quot;dot&quot;,&quot;lot&quot;,&quot;log&quot;,&quot;cog&quot;]
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong>
beginWord = &quot;hit&quot;
endWord = &quot;cog&quot;
wordList = [&quot;hot&quot;,&quot;dot&quot;,&quot;dog&quot;,&quot;lot&quot;,&quot;log&quot;]
<strong>Output: </strong>[]
<strong>Explanation:</strong>&nbsp;<em>endWord</em> &quot;cog&quot; is not in the dictionary, so there&#39;s no possible transforming sequence.</pre>
<p>Given two words of equal length that are in a dictionary, write a method to transform one word into another word by changing only one letter at a time. The new word you get in each step must be in the dictionary.</p>
<p>Write code to return a possible transforming sequence. If there is more than one sequence, return any of them.</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong>
beginWord = &quot;hit&quot;,
endWord = &quot;cog&quot;,
wordList = [&quot;hot&quot;,&quot;dot&quot;,&quot;dog&quot;,&quot;lot&quot;,&quot;log&quot;,&quot;cog&quot;]
<strong>Output:</strong>
[&quot;hit&quot;,&quot;hot&quot;,&quot;dot&quot;,&quot;lot&quot;,&quot;log&quot;,&quot;cog&quot;]
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong>
beginWord = &quot;hit&quot;
endWord = &quot;cog&quot;
wordList = [&quot;hot&quot;,&quot;dot&quot;,&quot;dog&quot;,&quot;lot&quot;,&quot;log&quot;]
<strong>Output: </strong>[]
<strong>Explanation:</strong>&nbsp;<em>endWord</em> &quot;cog&quot; is not in the dictionary, so there&#39;s no possible transforming sequence.</pre>

@ -1,28 +1,28 @@
<p>Design a method to find the frequency of occurrences of any given word in a book. What if we were running this algorithm multiple times?</p>
<p>You should implement following methods:</p>
<ul>
<li><code>WordsFrequency(book)</code> constructor, parameter is a array of strings, representing the book.</li>
<li><code>get(word)</code>&nbsp;get the frequency of <code>word</code> in the book.&nbsp;</li>
</ul>
<p><strong>Example: </strong></p>
<pre>
WordsFrequency wordsFrequency = new WordsFrequency({&quot;i&quot;, &quot;have&quot;, &quot;an&quot;, &quot;apple&quot;, &quot;he&quot;, &quot;have&quot;, &quot;a&quot;, &quot;pen&quot;});
wordsFrequency.get(&quot;you&quot;); //returns 0&quot;you&quot; is not in the book
wordsFrequency.get(&quot;have&quot;); //returns 2&quot;have&quot; occurs twice in the book
wordsFrequency.get(&quot;an&quot;); //returns 1
wordsFrequency.get(&quot;apple&quot;); //returns 1
wordsFrequency.get(&quot;pen&quot;); //returns 1
</pre>
<p><strong>Note: </strong></p>
<ul>
<li><code>There are only lowercase letters in book[i].</code></li>
<li><code>1 &lt;= book.length &lt;= 100000</code></li>
<li><code>1 &lt;= book[i].length &lt;= 10</code></li>
<li><code>get</code>&nbsp;function will not be called more than&nbsp;100000 times.</li>
</ul>
<p>Design a method to find the frequency of occurrences of any given word in a book. What if we were running this algorithm multiple times?</p>
<p>You should implement following methods:</p>
<ul>
<li><code>WordsFrequency(book)</code> constructor, parameter is a array of strings, representing the book.</li>
<li><code>get(word)</code>&nbsp;get the frequency of <code>word</code> in the book.&nbsp;</li>
</ul>
<p><strong>Example: </strong></p>
<pre>
WordsFrequency wordsFrequency = new WordsFrequency({&quot;i&quot;, &quot;have&quot;, &quot;an&quot;, &quot;apple&quot;, &quot;he&quot;, &quot;have&quot;, &quot;a&quot;, &quot;pen&quot;});
wordsFrequency.get(&quot;you&quot;); //returns 0&quot;you&quot; is not in the book
wordsFrequency.get(&quot;have&quot;); //returns 2&quot;have&quot; occurs twice in the book
wordsFrequency.get(&quot;an&quot;); //returns 1
wordsFrequency.get(&quot;apple&quot;); //returns 1
wordsFrequency.get(&quot;pen&quot;); //returns 1
</pre>
<p><strong>Note: </strong></p>
<ul>
<li><code>There are only lowercase letters in book[i].</code></li>
<li><code>1 &lt;= book.length &lt;= 100000</code></li>
<li><code>1 &lt;= book[i].length &lt;= 10</code></li>
<li><code>get</code>&nbsp;function will not be called more than&nbsp;100000 times.</li>
</ul>

@ -1 +1 @@
<p>English description is not available for the problem. Please switch to Chinese.</p>
<p>English description is not available for the problem. Please switch to Chinese.</p>

@ -1,21 +1,21 @@
<p>Write a method to sort an array of strings so that all the anagrams are in the same group.</p>
<p><b>Note:&nbsp;</b>This problem is slightly different from the original one the book.</p>
<p><strong>Example:</strong></p>
<pre>
<strong>Input:</strong> <code>[&quot;eat&quot;, &quot;tea&quot;, &quot;tan&quot;, &quot;ate&quot;, &quot;nat&quot;, &quot;bat&quot;]</code>,
<strong>Output:</strong>
[
[&quot;ate&quot;,&quot;eat&quot;,&quot;tea&quot;],
[&quot;nat&quot;,&quot;tan&quot;],
[&quot;bat&quot;]
]</pre>
<p><strong>Notes: </strong></p>
<ul>
<li>All inputs will be in lowercase.</li>
<li>The order of your output does not&nbsp;matter.</li>
</ul>
<p>Write a method to sort an array of strings so that all the anagrams are in the same group.</p>
<p><b>Note:&nbsp;</b>This problem is slightly different from the original one the book.</p>
<p><strong>Example:</strong></p>
<pre>
<strong>Input:</strong> <code>[&quot;eat&quot;, &quot;tea&quot;, &quot;tan&quot;, &quot;ate&quot;, &quot;nat&quot;, &quot;bat&quot;]</code>,
<strong>Output:</strong>
[
[&quot;ate&quot;,&quot;eat&quot;,&quot;tea&quot;],
[&quot;nat&quot;,&quot;tan&quot;],
[&quot;bat&quot;]
]</pre>
<p><strong>Notes: </strong></p>
<ul>
<li>All inputs will be in lowercase.</li>
<li>The order of your output does not&nbsp;matter.</li>
</ul>

@ -1,4 +1,4 @@
<p>There is only one character <code>&#39;A&#39;</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>&#39;A&#39;</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 &#39;A&#39;.
<strong>Explanation:</strong> Initially, we have one character &#39;A&#39;.
In step 1, we use Copy All operation.
In step 2, we use Paste operation to get &#39;AA&#39;.
In step 3, we use Paste operation to get &#39;AAA&#39;.

@ -1,36 +1,36 @@
<p>Given a<strong>&nbsp;directed acyclic graph</strong>,&nbsp;with&nbsp;<code>n</code>&nbsp;vertices numbered from&nbsp;<code>0</code>&nbsp;to&nbsp;<code>n-1</code>,&nbsp;and an array&nbsp;<code>edges</code>&nbsp;where&nbsp;<code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>]</code>&nbsp;represents a directed edge from node&nbsp;<code>from<sub>i</sub></code>&nbsp;to node&nbsp;<code>to<sub>i</sub></code>.</p>
<p>Find <em>the smallest set of vertices from which all nodes in the graph are reachable</em>. It&#39;s guaranteed that a unique solution exists.</p>
<p>Notice that you can return the vertices in any order.</p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2020/07/07/untitled22.png" style="width: 231px; height: 181px;" /></p>
<pre>
<strong>Input:</strong> n = 6, edges = [[0,1],[0,2],[2,5],[3,4],[4,2]]
<strong>Output:</strong> [0,3]
<b>Explanation: </b>It&#39;s not possible to reach all the nodes from a single vertex. From 0 we can reach [0,1,2,5]. From 3 we can reach [3,4,2,5]. So we output [0,3].</pre>
<p><strong>Example 2:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2020/07/07/untitled.png" style="width: 201px; height: 201px;" /></p>
<pre>
<strong>Input:</strong> n = 5, edges = [[0,1],[2,1],[3,1],[1,4],[2,4]]
<strong>Output:</strong> [0,2,3]
<strong>Explanation: </strong>Notice that vertices 0, 3 and 2 are not reachable from any other node, so we must include them. Also any of these vertices can reach nodes 1 and 4.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>2 &lt;= n &lt;= 10^5</code></li>
<li><code>1 &lt;= edges.length &lt;= min(10^5, n * (n - 1) / 2)</code></li>
<li><code>edges[i].length == 2</code></li>
<li><code>0 &lt;= from<sub>i,</sub>&nbsp;to<sub>i</sub> &lt; n</code></li>
<li>All pairs <code>(from<sub>i</sub>, to<sub>i</sub>)</code> are distinct.</li>
<p>Given a<strong>&nbsp;directed acyclic graph</strong>,&nbsp;with&nbsp;<code>n</code>&nbsp;vertices numbered from&nbsp;<code>0</code>&nbsp;to&nbsp;<code>n-1</code>,&nbsp;and an array&nbsp;<code>edges</code>&nbsp;where&nbsp;<code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>]</code>&nbsp;represents a directed edge from node&nbsp;<code>from<sub>i</sub></code>&nbsp;to node&nbsp;<code>to<sub>i</sub></code>.</p>
<p>Find <em>the smallest set of vertices from which all nodes in the graph are reachable</em>. It&#39;s guaranteed that a unique solution exists.</p>
<p>Notice that you can return the vertices in any order.</p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2020/07/07/untitled22.png" style="width: 231px; height: 181px;" /></p>
<pre>
<strong>Input:</strong> n = 6, edges = [[0,1],[0,2],[2,5],[3,4],[4,2]]
<strong>Output:</strong> [0,3]
<b>Explanation: </b>It&#39;s not possible to reach all the nodes from a single vertex. From 0 we can reach [0,1,2,5]. From 3 we can reach [3,4,2,5]. So we output [0,3].</pre>
<p><strong>Example 2:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2020/07/07/untitled.png" style="width: 201px; height: 201px;" /></p>
<pre>
<strong>Input:</strong> n = 5, edges = [[0,1],[2,1],[3,1],[1,4],[2,4]]
<strong>Output:</strong> [0,2,3]
<strong>Explanation: </strong>Notice that vertices 0, 3 and 2 are not reachable from any other node, so we must include them. Also any of these vertices can reach nodes 1 and 4.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>2 &lt;= n &lt;= 10^5</code></li>
<li><code>1 &lt;= edges.length &lt;= min(10^5, n * (n - 1) / 2)</code></li>
<li><code>edges[i].length == 2</code></li>
<li><code>0 &lt;= from<sub>i,</sub>&nbsp;to<sub>i</sub> &lt; n</code></li>
<li>All pairs <code>(from<sub>i</sub>, to<sub>i</sub>)</code> are distinct.</li>
</ul>

@ -1,34 +1,34 @@
<p>You are given an array <code>rectangles</code> where <code>rectangles[i] = [l<sub>i</sub>, w<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> rectangle of length <code>l<sub>i</sub></code> and width <code>w<sub>i</sub></code>.</p>
<p>You can cut the <code>i<sup>th</sup></code> rectangle to form a square with a side length of <code>k</code> if both <code>k &lt;= l<sub>i</sub></code> and <code>k &lt;= w<sub>i</sub></code>. For example, if you have a rectangle <code>[4,6]</code>, you can cut it to get a square with a side length of at most <code>4</code>.</p>
<p>Let <code>maxLen</code> be the side length of the <strong>largest</strong> square you can obtain from any of the given rectangles.</p>
<p>Return <em>the <strong>number</strong> of rectangles that can make a square with a side length of </em><code>maxLen</code>.</p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> rectangles = [[5,8],[3,9],[5,12],[16,5]]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The largest squares you can get from each rectangle are of lengths [5,3,5,5].
The largest possible square is of length 5, and you can get it out of 3 rectangles.
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> rectangles = [[2,3],[3,7],[4,3],[3,7]]
<strong>Output:</strong> 3
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= rectangles.length &lt;= 1000</code></li>
<li><code>rectangles[i].length == 2</code></li>
<li><code>1 &lt;= l<sub>i</sub>, w<sub>i</sub> &lt;= 10<sup>9</sup></code></li>
<li><code>l<sub>i</sub> != w<sub>i</sub></code></li>
<p>You are given an array <code>rectangles</code> where <code>rectangles[i] = [l<sub>i</sub>, w<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> rectangle of length <code>l<sub>i</sub></code> and width <code>w<sub>i</sub></code>.</p>
<p>You can cut the <code>i<sup>th</sup></code> rectangle to form a square with a side length of <code>k</code> if both <code>k &lt;= l<sub>i</sub></code> and <code>k &lt;= w<sub>i</sub></code>. For example, if you have a rectangle <code>[4,6]</code>, you can cut it to get a square with a side length of at most <code>4</code>.</p>
<p>Let <code>maxLen</code> be the side length of the <strong>largest</strong> square you can obtain from any of the given rectangles.</p>
<p>Return <em>the <strong>number</strong> of rectangles that can make a square with a side length of </em><code>maxLen</code>.</p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> rectangles = [[5,8],[3,9],[5,12],[16,5]]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The largest squares you can get from each rectangle are of lengths [5,3,5,5].
The largest possible square is of length 5, and you can get it out of 3 rectangles.
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> rectangles = [[2,3],[3,7],[4,3],[3,7]]
<strong>Output:</strong> 3
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= rectangles.length &lt;= 1000</code></li>
<li><code>rectangles[i].length == 2</code></li>
<li><code>1 &lt;= l<sub>i</sub>, w<sub>i</sub> &lt;= 10<sup>9</sup></code></li>
<li><code>l<sub>i</sub> != w<sub>i</sub></code></li>
</ul>

@ -1,18 +1,18 @@
<p>You are given two sorted arrays, A and B, where A has a large enough buffer at the end to hold B. Write a method to merge B into A in sorted order.</p>
<p>Initially the number of elements in A and B are&nbsp;<em>m</em>&nbsp;and&nbsp;<em>n</em> respectively.</p>
<p><strong>Example:</strong></p>
<pre>
<strong>Input:</strong>
A = [1,2,3,0,0,0], m = 3
B = [2,5,6], n = 3
<strong>Output:</strong>&nbsp;[1,2,2,3,5,6]</pre>
<p><strong>Note:</strong></p>
<ul>
<li><code>A.length == n + m</code></li>
</ul>
<p>You are given two sorted arrays, A and B, where A has a large enough buffer at the end to hold B. Write a method to merge B into A in sorted order.</p>
<p>Initially the number of elements in A and B are&nbsp;<em>m</em>&nbsp;and&nbsp;<em>n</em> respectively.</p>
<p><strong>Example:</strong></p>
<pre>
<strong>Input:</strong>
A = [1,2,3,0,0,0], m = 3
B = [2,5,6], n = 3
<strong>Output:</strong>&nbsp;[1,2,2,3,5,6]</pre>
<p><strong>Note:</strong></p>
<ul>
<li><code>A.length == n + m</code></li>
</ul>

@ -1,24 +1,24 @@
<p>Implement a function to check if a binary tree is a binary search tree.</p>
<p><strong>Example&nbsp;1:</strong></p>
<pre>
<strong>Input:</strong>
2
/ \
1 3
<strong>Output:</strong> true
</pre>
<p><strong>Example&nbsp;2:</strong></p>
<pre>
<strong>Input:</strong>
5
/ \
1 4
&nbsp; / \
&nbsp; 3 6
<strong>Output:</strong> false
<strong>Explanation:</strong> Input: [5,1,4,null,null,3,6].
&nbsp; the value of root node is 5, but its right child has value 4.</pre>
<p>Implement a function to check if a binary tree is a binary search tree.</p>
<p><strong>Example&nbsp;1:</strong></p>
<pre>
<strong>Input:</strong>
2
/ \
1 3
<strong>Output:</strong> true
</pre>
<p><strong>Example&nbsp;2:</strong></p>
<pre>
<strong>Input:</strong>
5
/ \
1 4
&nbsp; / \
&nbsp; 3 6
<strong>Output:</strong> false
<strong>Explanation:</strong> Input: [5,1,4,null,null,3,6].
&nbsp; the value of root node is 5, but its right child has value 4.</pre>

@ -1,29 +1,29 @@
<p>Write an algorithm to find the &quot;next&quot; node (i.e., in-order successor) of a given node in a binary search tree.</p>
<p>Return <code>null</code> if there&#39;s no &quot;next&quot; node for the given node.</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> root = <code>[2,1,3], p = 1
2
/ \
1 3
</code>
<strong>Output:</strong> 2</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> root = <code>[5,3,6,2,4,null,null,1], p = 6
5
/ \
3 6
/ \
2 4
/
1
</code>
<strong>Output:</strong> null</pre>
<p>Write an algorithm to find the &quot;next&quot; node (i.e., in-order successor) of a given node in a binary search tree.</p>
<p>Return <code>null</code> if there&#39;s no &quot;next&quot; node for the given node.</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> root = <code>[2,1,3], p = 1
2
/ \
1 3
</code>
<strong>Output:</strong> 2</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> root = <code>[5,3,6,2,4,null,null,1], p = 6
5
/ \
3 6
/ \
2 4
/
1
</code>
<strong>Output:</strong> null</pre>

@ -1 +1 @@
<p>English description is not available for the problem. Please switch to Chinese.</p>
<p>English description is not available for the problem. Please switch to Chinese.</p>

@ -1 +1 @@
<p>English description is not available for the problem. Please switch to Chinese.</p>
<p>English description is not available for the problem. Please switch to Chinese.</p>

@ -1,12 +1,12 @@
<p>Given a string, write a function to check if it is a permutation of a palindrome. A palindrome is a word or phrase that is the same forwards and backwards. A permutation is a rearrangement of letters. The palindrome does not need to be limited to just dictionary words.</p>
<p>&nbsp;</p>
<p><strong>Example1: </strong></p>
<pre>
<strong>Input: &quot;</strong>tactcoa&quot;
<strong>Output: </strong>truepermutations: &quot;tacocat&quot;&quot;atcocta&quot;, etc.
</pre>
<p>&nbsp;</p>
<p>Given a string, write a function to check if it is a permutation of a palindrome. A palindrome is a word or phrase that is the same forwards and backwards. A permutation is a rearrangement of letters. The palindrome does not need to be limited to just dictionary words.</p>
<p>&nbsp;</p>
<p><strong>Example1: </strong></p>
<pre>
<strong>Input: &quot;</strong>tactcoa&quot;
<strong>Output: </strong>truepermutations: &quot;tacocat&quot;&quot;atcocta&quot;, etc.
</pre>
<p>&nbsp;</p>

@ -1,22 +1,22 @@
<p>Implement a function to check if a linked list is a palindrome.</p>
<p>&nbsp;</p>
<p><strong>Example 1: </strong></p>
<pre>
<strong>Input: </strong>1-&gt;2
<strong>Output: </strong> false
</pre>
<p><strong>Example 2: </strong></p>
<pre>
<strong>Input: </strong>1-&gt;2-&gt;2-&gt;1
<strong>Output: </strong> true
</pre>
<p>&nbsp;</p>
<p><b>Follow up:</b><br />
Could you do it in O(n) time and O(1) space?</p>
<p>Implement a function to check if a linked list is a palindrome.</p>
<p>&nbsp;</p>
<p><strong>Example 1: </strong></p>
<pre>
<strong>Input: </strong>1-&gt;2
<strong>Output: </strong> false
</pre>
<p><strong>Example 2: </strong></p>
<pre>
<strong>Input: </strong>1-&gt;2-&gt;2-&gt;1
<strong>Output: </strong> true
</pre>
<p>&nbsp;</p>
<p><b>Follow up:</b><br />
Could you do it in O(n) time and O(1) space?</p>

@ -1 +1 @@
<p>English description is not available for the problem. Please switch to Chinese.</p>
<p>English description is not available for the problem. Please switch to Chinese.</p>

@ -36,5 +36,5 @@
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= x, y &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= startValue, target &lt;= 10<sup>9</sup></code></li>
</ul>

@ -1,24 +1,24 @@
<p>Imagine a (literal) stack of plates. If the stack gets too high, it might topple. Therefore, in real life, we would likely start a new stack when the previous stack exceeds some threshold. Implement a data structure <code>SetOfStacks</code> that mimics this.&nbsp;<code>SetOfStacks</code> should be composed of several stacks and should create a new stack once the previous one exceeds capacity. <code>SetOfStacks.push()</code> and <code>SetOfStacks.pop()</code> should behave identically to a single stack (that is, <code>pop()</code> should return the same values as it would if there were just a single stack). Follow Up: Implement a function <code>popAt(int index)</code> which performs a pop operation on a specific sub-stack.</p>
<p>You should delete the sub-stack when it becomes empty. <code>pop</code>, <code>popAt</code> should return -1 when there&#39;s no element to pop.</p>
<p><strong>Example1:</strong></p>
<pre>
<strong> Input</strong>:
[&quot;StackOfPlates&quot;, &quot;push&quot;, &quot;push&quot;, &quot;popAt&quot;, &quot;pop&quot;, &quot;pop&quot;]
[[1], [1], [2], [1], [], []]
<strong> Output</strong>:
[null, null, null, 2, 1, -1]
<strong> Explanation</strong>:
</pre>
<p><strong>Example2:</strong></p>
<pre>
<strong> Input</strong>:
[&quot;StackOfPlates&quot;, &quot;push&quot;, &quot;push&quot;, &quot;push&quot;, &quot;popAt&quot;, &quot;popAt&quot;, &quot;popAt&quot;]
[[2], [1], [2], [3], [0], [0], [0]]
<strong> Output</strong>:
[null, null, null, null, 2, 1, 3]
</pre>
<p>Imagine a (literal) stack of plates. If the stack gets too high, it might topple. Therefore, in real life, we would likely start a new stack when the previous stack exceeds some threshold. Implement a data structure <code>SetOfStacks</code> that mimics this.&nbsp;<code>SetOfStacks</code> should be composed of several stacks and should create a new stack once the previous one exceeds capacity. <code>SetOfStacks.push()</code> and <code>SetOfStacks.pop()</code> should behave identically to a single stack (that is, <code>pop()</code> should return the same values as it would if there were just a single stack). Follow Up: Implement a function <code>popAt(int index)</code> which performs a pop operation on a specific sub-stack.</p>
<p>You should delete the sub-stack when it becomes empty. <code>pop</code>, <code>popAt</code> should return -1 when there&#39;s no element to pop.</p>
<p><strong>Example1:</strong></p>
<pre>
<strong> Input</strong>:
[&quot;StackOfPlates&quot;, &quot;push&quot;, &quot;push&quot;, &quot;popAt&quot;, &quot;pop&quot;, &quot;pop&quot;]
[[1], [1], [2], [1], [], []]
<strong> Output</strong>:
[null, null, null, 2, 1, -1]
<strong> Explanation</strong>:
</pre>
<p><strong>Example2:</strong></p>
<pre>
<strong> Input</strong>:
[&quot;StackOfPlates&quot;, &quot;push&quot;, &quot;push&quot;, &quot;push&quot;, &quot;popAt&quot;, &quot;popAt&quot;, &quot;popAt&quot;]
[[2], [1], [2], [3], [0], [0], [0]]
<strong> Output</strong>:
[null, null, null, null, 2, 1, 3]
</pre>

@ -1,23 +1,23 @@
<p>You have a stack of n boxes, with widths wi, depths di, and heights hi. The boxes cannot be rotated and can only be stacked on top of one another if each box in the stack is strictly larger than the box above it in width, height, and depth. Implement a method to compute the height of the tallest possible stack. The height of a stack is the sum of the heights of each box.</p>
<p>The input use <code>[wi, di, hi]</code>&nbsp;to represents each box.</p>
<p><strong>Example1:</strong></p>
<pre>
<strong> Input</strong>: box = [[1, 1, 1], [2, 2, 2], [3, 3, 3]]
<strong> Output</strong>: 6
</pre>
<p><strong>Example2:</strong></p>
<pre>
<strong> Input</strong>: box = [[1, 1, 1], [2, 3, 4], [2, 6, 7], [3, 4, 5]]
<strong> Output</strong>: 10
</pre>
<p><strong>Note:</strong></p>
<ol>
<li><code>box.length &lt;= 3000</code></li>
</ol>
<p>You have a stack of n boxes, with widths wi, depths di, and heights hi. The boxes cannot be rotated and can only be stacked on top of one another if each box in the stack is strictly larger than the box above it in width, height, and depth. Implement a method to compute the height of the tallest possible stack. The height of a stack is the sum of the heights of each box.</p>
<p>The input use <code>[wi, di, hi]</code>&nbsp;to represents each box.</p>
<p><strong>Example1:</strong></p>
<pre>
<strong> Input</strong>: box = [[1, 1, 1], [2, 2, 2], [3, 3, 3]]
<strong> Output</strong>: 6
</pre>
<p><strong>Example2:</strong></p>
<pre>
<strong> Input</strong>: box = [[1, 1, 1], [2, 3, 4], [2, 6, 7], [3, 4, 5]]
<strong> Output</strong>: 10
</pre>
<p><strong>Note:</strong></p>
<ol>
<li><code>box.length &lt;= 3000</code></li>
</ol>

@ -1,20 +1,20 @@
<p>Given a string band an array of smaller strings T, design a method to search b for each small string in T. Output&nbsp;<code>positions</code> of all strings in&nbsp;<code>smalls</code>&nbsp;that appear in <code>big</code>,&nbsp;where <code>positions[i]</code> is all positions of <code>smalls[i]</code>.</p>
<p><strong>Example: </strong></p>
<pre>
<strong>Input: </strong>
big = &quot;mississippi&quot;
smalls = [&quot;is&quot;,&quot;ppi&quot;,&quot;hi&quot;,&quot;sis&quot;,&quot;i&quot;,&quot;ssippi&quot;]
<strong>Output: </strong> [[1,4],[8],[],[3],[1,4,7,10],[5]]
</pre>
<p><strong>Note: </strong></p>
<ul>
<li><code>0 &lt;= len(big) &lt;= 1000</code></li>
<li><code>0 &lt;= len(smalls[i]) &lt;= 1000</code></li>
<li>The total number of characters in&nbsp;<code>smalls</code>&nbsp;will not exceed 100000.</li>
<li>No duplicated strings in&nbsp;<code>smalls</code>.</li>
<li>All characters are lowercase letters.</li>
</ul>
<p>Given a string band an array of smaller strings T, design a method to search b for each small string in T. Output&nbsp;<code>positions</code> of all strings in&nbsp;<code>smalls</code>&nbsp;that appear in <code>big</code>,&nbsp;where <code>positions[i]</code> is all positions of <code>smalls[i]</code>.</p>
<p><strong>Example: </strong></p>
<pre>
<strong>Input: </strong>
big = &quot;mississippi&quot;
smalls = [&quot;is&quot;,&quot;ppi&quot;,&quot;hi&quot;,&quot;sis&quot;,&quot;i&quot;,&quot;ssippi&quot;]
<strong>Output: </strong> [[1,4],[8],[],[3],[1,4,7,10],[5]]
</pre>
<p><strong>Note: </strong></p>
<ul>
<li><code>0 &lt;= len(big) &lt;= 1000</code></li>
<li><code>0 &lt;= len(smalls[i]) &lt;= 1000</code></li>
<li>The total number of characters in&nbsp;<code>smalls</code>&nbsp;will not exceed 100000.</li>
<li>No duplicated strings in&nbsp;<code>smalls</code>.</li>
<li>All characters are lowercase letters.</li>
</ul>

@ -1,35 +1,35 @@
<p>You are given a positive integer <code>primeFactors</code>. You are asked to construct a positive integer <code>n</code> that satisfies the following conditions:</p>
<ul>
<li>The number of prime factors of <code>n</code> (not necessarily distinct) is <strong>at most</strong> <code>primeFactors</code>.</li>
<li>The number of nice divisors of <code>n</code> is maximized. Note that a divisor of <code>n</code> is <strong>nice</strong> if it is divisible by every prime factor of <code>n</code>. For example, if <code>n = 12</code>, then its prime factors are <code>[2,2,3]</code>, then <code>6</code> and <code>12</code> are nice divisors, while <code>3</code> and <code>4</code> are not.</li>
</ul>
<p>Return <em>the number of nice divisors of</em> <code>n</code>. Since that number can be too large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
<p>Note that a prime number is a natural number greater than <code>1</code> that is not a product of two smaller natural numbers. The prime factors of a number <code>n</code> is a list of prime numbers such that their product equals <code>n</code>.</p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> primeFactors = 5
<strong>Output:</strong> 6
<strong>Explanation:</strong> 200 is a valid value of n.
It has 5 prime factors: [2,2,2,5,5], and it has 6 nice divisors: [10,20,40,50,100,200].
There is not other value of n that has at most 5 prime factors and more nice divisors.
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> primeFactors = 8
<strong>Output:</strong> 18
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= primeFactors &lt;= 10<sup>9</sup></code></li>
<p>You are given a positive integer <code>primeFactors</code>. You are asked to construct a positive integer <code>n</code> that satisfies the following conditions:</p>
<ul>
<li>The number of prime factors of <code>n</code> (not necessarily distinct) is <strong>at most</strong> <code>primeFactors</code>.</li>
<li>The number of nice divisors of <code>n</code> is maximized. Note that a divisor of <code>n</code> is <strong>nice</strong> if it is divisible by every prime factor of <code>n</code>. For example, if <code>n = 12</code>, then its prime factors are <code>[2,2,3]</code>, then <code>6</code> and <code>12</code> are nice divisors, while <code>3</code> and <code>4</code> are not.</li>
</ul>
<p>Return <em>the number of nice divisors of</em> <code>n</code>. Since that number can be too large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
<p>Note that a prime number is a natural number greater than <code>1</code> that is not a product of two smaller natural numbers. The prime factors of a number <code>n</code> is a list of prime numbers such that their product equals <code>n</code>.</p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> primeFactors = 5
<strong>Output:</strong> 6
<strong>Explanation:</strong> 200 is a valid value of n.
It has 5 prime factors: [2,2,2,5,5], and it has 6 nice divisors: [10,20,40,50,100,200].
There is not other value of n that has at most 5 prime factors and more nice divisors.
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> primeFactors = 8
<strong>Output:</strong> 18
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= primeFactors &lt;= 10<sup>9</sup></code></li>
</ul>

@ -1,13 +1,13 @@
<p>Each year, the government releases a list of the 10000 most common baby names and their frequencies (the number of babies with that name). The only problem with this is that some names have multiple spellings. For example,&quot;John&quot; and &#39;&#39;Jon&quot; are essentially the same name but would be listed separately in the list. Given two lists, one of names/frequencies and the other of pairs of equivalent names, write an algorithm to print a new list of the true frequency of each name. Note that if John and Jon are synonyms, and Jon and Johnny are synonyms, then John and Johnny are synonyms. (It is both transitive and symmetric.) In the final list, choose the name that are <strong>lexicographically smallest</strong> as the &quot;real&quot; name.</p>
<p><strong>Example: </strong></p>
<pre>
<strong>Input: </strong>names = [&quot;John(15)&quot;,&quot;Jon(12)&quot;,&quot;Chris(13)&quot;,&quot;Kris(4)&quot;,&quot;Christopher(19)&quot;], synonyms = [&quot;(Jon,John)&quot;,&quot;(John,Johnny)&quot;,&quot;(Chris,Kris)&quot;,&quot;(Chris,Christopher)&quot;]
<strong>Output: </strong>[&quot;John(27)&quot;,&quot;Chris(36)&quot;]</pre>
<p>Note:</p>
<ul>
<li><code>names.length &lt;= 100000</code></li>
</ul>
<p>Each year, the government releases a list of the 10000 most common baby names and their frequencies (the number of babies with that name). The only problem with this is that some names have multiple spellings. For example,&quot;John&quot; and &#39;&#39;Jon&quot; are essentially the same name but would be listed separately in the list. Given two lists, one of names/frequencies and the other of pairs of equivalent names, write an algorithm to print a new list of the true frequency of each name. Note that if John and Jon are synonyms, and Jon and Johnny are synonyms, then John and Johnny are synonyms. (It is both transitive and symmetric.) In the final list, choose the name that are <strong>lexicographically smallest</strong> as the &quot;real&quot; name.</p>
<p><strong>Example: </strong></p>
<pre>
<strong>Input: </strong>names = [&quot;John(15)&quot;,&quot;Jon(12)&quot;,&quot;Chris(13)&quot;,&quot;Kris(4)&quot;,&quot;Christopher(19)&quot;], synonyms = [&quot;(Jon,John)&quot;,&quot;(John,Johnny)&quot;,&quot;(Chris,Kris)&quot;,&quot;(Chris,Christopher)&quot;]
<strong>Output: </strong>[&quot;John(27)&quot;,&quot;Chris(36)&quot;]</pre>
<p>Note:</p>
<ul>
<li><code>names.length &lt;= 100000</code></li>
</ul>

@ -1,25 +1,25 @@
<p>Implement a method to perform basic string compression using the counts of repeated characters. For example, the string aabcccccaaa would become a2blc5a3. If the &quot;compressed&quot; string would not become smaller than the original string, your method should return the original string. You can assume the string has only uppercase and lowercase letters (a - z).</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input: </strong>&quot;aabcccccaaa&quot;
<strong>Output: </strong>&quot;a2b1c5a3&quot;
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input: </strong>&quot;abbccd&quot;
<strong>Output: </strong>&quot;abbccd&quot;
<strong>Explanation: </strong>
The compressed string is &quot;a1b2c2d1&quot;, which is longer than the original string.
</pre>
<p>&nbsp;</p>
<p><strong>Note:</strong></p>
<ol>
<li><code>0 &lt;= S.length &lt;= 50000</code></li>
</ol>
<p>Implement a method to perform basic string compression using the counts of repeated characters. For example, the string aabcccccaaa would become a2blc5a3. If the &quot;compressed&quot; string would not become smaller than the original string, your method should return the original string. You can assume the string has only uppercase and lowercase letters (a - z).</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input: </strong>&quot;aabcccccaaa&quot;
<strong>Output: </strong>&quot;a2b1c5a3&quot;
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input: </strong>&quot;abbccd&quot;
<strong>Output: </strong>&quot;abbccd&quot;
<strong>Explanation: </strong>
The compressed string is &quot;a1b2c2d1&quot;, which is longer than the original string.
</pre>
<p>&nbsp;</p>
<p><strong>Note:</strong></p>
<ol>
<li><code>0 &lt;= S.length &lt;= 50000</code></li>
</ol>

@ -1,23 +1,23 @@
<p>Given two strings, <code>s1</code>&nbsp;and <code>s2</code>, write code to check if <code>s2</code> is a rotation of <code>s1</code> (e.g.,&quot;waterbottle&quot; is a rotation of&quot;erbottlewat&quot;).&nbsp;Can you use&nbsp;only one call to the method that&nbsp;checks if one word is a substring of another?</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input: </strong>s1 = <span id="example-input-1-1">&quot;waterbottle&quot;</span>, s2 = <span id="example-input-1-2">&quot;</span>erbottlewat<span>&quot;</span>
<strong>Output: </strong><span id="example-output-1">True</span>
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input: </strong>s1 = &quot;aa&quot;, s2 = &quot;aba&quot;
<strong>Output: </strong>False
</pre>
<p>&nbsp;</p>
<p><strong>Note:</strong></p>
<ol>
<li><code><font face="monospace">0 &lt;= s1.length, s2.length &lt;=&nbsp;</font>100000</code></li>
</ol>
<p>Given two strings, <code>s1</code>&nbsp;and <code>s2</code>, write code to check if <code>s2</code> is a rotation of <code>s1</code> (e.g.,&quot;waterbottle&quot; is a rotation of&quot;erbottlewat&quot;).&nbsp;Can you use&nbsp;only one call to the method that&nbsp;checks if one word is a substring of another?</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input: </strong>s1 = <span id="example-input-1-1">&quot;waterbottle&quot;</span>, s2 = <span id="example-input-1-2">&quot;</span>erbottlewat<span>&quot;</span>
<strong>Output: </strong><span id="example-output-1">True</span>
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input: </strong>s1 = &quot;aa&quot;, s2 = &quot;aba&quot;
<strong>Output: </strong>False
</pre>
<p>&nbsp;</p>
<p><strong>Note:</strong></p>
<ol>
<li><code><font face="monospace">0 &lt;= s1.length, s2.length &lt;=&nbsp;</font>100000</code></li>
</ol>

@ -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&#39;s&nbsp;<a href="http://www.cplusplus.com/reference/cstring/strstr/" target="_blank">strstr()</a> and Java&#39;s&nbsp;<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&#39;s <a href="http://www.cplusplus.com/reference/cstring/strstr/" target="_blank">strstr()</a> and Java&#39;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>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre><strong>Input:</strong> haystack = "hello", needle = "ll"
<pre>
<strong>Input:</strong> haystack = &quot;hello&quot;, needle = &quot;ll&quot;
<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 = &quot;aaaaa&quot;, needle = &quot;bba&quot;
<strong>Output:</strong> -1
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>0 &lt;= haystack.length, needle.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>haystack</code> and&nbsp;<code>needle</code> consist of only lower-case English characters.</li>
<li><code>1 &lt;= haystack.length, needle.length &lt;= 10<sup>4</sup></code></li>
<li><code>haystack</code> and <code>needle</code> consist of only lowercase English characters.</li>
</ul>

@ -1,37 +1,37 @@
<p>A <strong>sentence</strong> is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of lowercase and uppercase English letters.</p>
<p>A sentence can be <strong>shuffled</strong> by appending the <strong>1-indexed word position</strong> to each word then rearranging the words in the sentence.</p>
<ul>
<li>For example, the sentence <code>&quot;This is a sentence&quot;</code> can be shuffled as <code>&quot;sentence4 a3 is2 This1&quot;</code> or <code>&quot;is2 sentence4 This1 a3&quot;</code>.</li>
</ul>
<p>Given a <strong>shuffled sentence</strong> <code>s</code> containing no more than <code>9</code> words, reconstruct and return <em>the original sentence</em>.</p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = &quot;is2 sentence4 This1 a3&quot;
<strong>Output:</strong> &quot;This is a sentence&quot;
<strong>Explanation:</strong> Sort the words in s to their original positions &quot;This1 is2 a3 sentence4&quot;, then remove the numbers.
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> s = &quot;Myself2 Me1 I4 and3&quot;
<strong>Output:</strong> &quot;Me Myself and I&quot;
<strong>Explanation:</strong> Sort the words in s to their original positions &quot;Me1 Myself2 and3 I4&quot;, then remove the numbers.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>2 &lt;= s.length &lt;= 200</code></li>
<li><code>s</code> consists of lowercase and uppercase English letters, spaces, and digits from <code>1</code> to <code>9</code>.</li>
<li>The number of words in <code>s</code> is between <code>1</code> and <code>9</code>.</li>
<li>The words in <code>s</code> are separated by a single space.</li>
<li><code>s</code> contains no leading or trailing spaces.</li>
<p>A <strong>sentence</strong> is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of lowercase and uppercase English letters.</p>
<p>A sentence can be <strong>shuffled</strong> by appending the <strong>1-indexed word position</strong> to each word then rearranging the words in the sentence.</p>
<ul>
<li>For example, the sentence <code>&quot;This is a sentence&quot;</code> can be shuffled as <code>&quot;sentence4 a3 is2 This1&quot;</code> or <code>&quot;is2 sentence4 This1 a3&quot;</code>.</li>
</ul>
<p>Given a <strong>shuffled sentence</strong> <code>s</code> containing no more than <code>9</code> words, reconstruct and return <em>the original sentence</em>.</p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = &quot;is2 sentence4 This1 a3&quot;
<strong>Output:</strong> &quot;This is a sentence&quot;
<strong>Explanation:</strong> Sort the words in s to their original positions &quot;This1 is2 a3 sentence4&quot;, then remove the numbers.
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> s = &quot;Myself2 Me1 I4 and3&quot;
<strong>Output:</strong> &quot;Me Myself and I&quot;
<strong>Explanation:</strong> Sort the words in s to their original positions &quot;Me1 Myself2 and3 I4&quot;, then remove the numbers.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>2 &lt;= s.length &lt;= 200</code></li>
<li><code>s</code> consists of lowercase and uppercase English letters, spaces, and digits from <code>1</code> to <code>9</code>.</li>
<li>The number of words in <code>s</code> is between <code>1</code> and <code>9</code>.</li>
<li>The words in <code>s</code> are separated by a single space.</li>
<li><code>s</code> contains no leading or trailing spaces.</li>
</ul>

@ -1,42 +1,42 @@
<p>A split of an integer array is <strong>good</strong> if:</p>
<ul>
<li>The array is split into three <strong>non-empty</strong> contiguous subarrays - named <code>left</code>, <code>mid</code>, <code>right</code> respectively from left to right.</li>
<li>The sum of the elements in <code>left</code> is less than or equal to the sum of the elements in <code>mid</code>, and the sum of the elements in <code>mid</code> is less than or equal to the sum of the elements in <code>right</code>.</li>
</ul>
<p>Given <code>nums</code>, an array of <strong>non-negative</strong> integers, return <em>the number of <strong>good</strong> ways to split</em> <code>nums</code>. As the number may be too large, return it <strong>modulo</strong> <code>10<sup>9 </sup>+ 7</code>.</p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,1]
<strong>Output:</strong> 1
<strong>Explanation:</strong> The only good way to split nums is [1] [1] [1].</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,2,2,2,5,0]
<strong>Output:</strong> 3
<strong>Explanation:</strong> There are three good ways of splitting nums:
[1] [2] [2,2,5,0]
[1] [2,2] [2,5,0]
[1,2] [2,2] [5,0]
</pre>
<p><strong>Example 3:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,2,1]
<strong>Output:</strong> 0
<strong>Explanation:</strong> There is no good way to split nums.</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>3 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>0 &lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
<p>A split of an integer array is <strong>good</strong> if:</p>
<ul>
<li>The array is split into three <strong>non-empty</strong> contiguous subarrays - named <code>left</code>, <code>mid</code>, <code>right</code> respectively from left to right.</li>
<li>The sum of the elements in <code>left</code> is less than or equal to the sum of the elements in <code>mid</code>, and the sum of the elements in <code>mid</code> is less than or equal to the sum of the elements in <code>right</code>.</li>
</ul>
<p>Given <code>nums</code>, an array of <strong>non-negative</strong> integers, return <em>the number of <strong>good</strong> ways to split</em> <code>nums</code>. As the number may be too large, return it <strong>modulo</strong> <code>10<sup>9 </sup>+ 7</code>.</p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,1]
<strong>Output:</strong> 1
<strong>Explanation:</strong> The only good way to split nums is [1] [1] [1].</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,2,2,2,5,0]
<strong>Output:</strong> 3
<strong>Explanation:</strong> There are three good ways of splitting nums:
[1] [2] [2,2,5,0]
[1] [2,2] [2,5,0]
[1,2] [2,2] [5,0]
</pre>
<p><strong>Example 3:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,2,1]
<strong>Output:</strong> 0
<strong>Explanation:</strong> There is no good way to split nums.</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>3 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>0 &lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
</ul>

@ -1,14 +1,14 @@
<p>In an array of integers, a &quot;peak&quot; is an element which is greater than or equal to the adjacent integers and a &quot;valley&quot; is an element which is less than or equal to the adjacent inte&shy;gers. For example, in the array {5, 8, 4, 2, 3, 4, 6}, {8, 6} are peaks and {5, 2} are valleys. Given an array of integers, sort the array into an alternating sequence of peaks and valleys.</p>
<p><strong>Example:</strong></p>
<pre>
<strong>Input: </strong>[5, 3, 1, 2, 3]
<strong>Output:</strong>&nbsp;[5, 1, 3, 2, 3]
</pre>
<p><strong>Note: </strong></p>
<ul>
<li><code>nums.length &lt;= 10000</code></li>
</ul>
<p>In an array of integers, a &quot;peak&quot; is an element which is greater than or equal to the adjacent integers and a &quot;valley&quot; is an element which is less than or equal to the adjacent inte&shy;gers. For example, in the array {5, 8, 4, 2, 3, 4, 6}, {8, 6} are peaks and {5, 2} are valleys. Given an array of integers, sort the array into an alternating sequence of peaks and valleys.</p>
<p><strong>Example:</strong></p>
<pre>
<strong>Input: </strong>[5, 3, 1, 2, 3]
<strong>Output:</strong>&nbsp;[5, 1, 3, 2, 3]
</pre>
<p><strong>Note: </strong></p>
<ul>
<li><code>nums.length &lt;= 10000</code></li>
</ul>

@ -1 +1 @@
<p>English description is not available for the problem. Please switch to Chinese.</p>
<p>English description is not available for the problem. Please switch to Chinese.</p>

@ -1,25 +1,25 @@
<p>Given a boolean expression consisting of the symbols <code>0</code> (false), <code>1</code> (true), <code>&amp;</code> (AND), <code>|</code> (OR), and <code>^</code>&nbsp;(XOR), and a desired boolean result value result, implement a function to count the number of ways of parenthesizing the expression such that it evaluates to result.</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input: </strong>s = &quot;1^0|0|1&quot;, result = 0
<strong>Output: </strong>2
<strong>Explanation:</strong>&nbsp;Two possible parenthesizing ways are:
1^(0|(0|1))
1^((0|0)|1)
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input: </strong>s = &quot;0&amp;0&amp;0&amp;1^1|0&quot;, result = 1
<strong>Output: </strong>10</pre>
<p><strong>Note: </strong></p>
<ul>
<li>There are no more than&nbsp;19 operators in <code>s</code>.</li>
</ul>
<p>Given a boolean expression consisting of the symbols <code>0</code> (false), <code>1</code> (true), <code>&amp;</code> (AND), <code>|</code> (OR), and <code>^</code>&nbsp;(XOR), and a desired boolean result value result, implement a function to count the number of ways of parenthesizing the expression such that it evaluates to result.</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input: </strong>s = &quot;1^0|0|1&quot;, result = 0
<strong>Output: </strong>2
<strong>Explanation:</strong>&nbsp;Two possible parenthesizing ways are:
1^(0|(0|1))
1^((0|0)|1)
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input: </strong>s = &quot;0&amp;0&amp;0&amp;1^1|0&quot;, result = 1
<strong>Output: </strong>10</pre>
<p><strong>Note: </strong></p>
<ul>
<li>There are no more than&nbsp;19 operators in <code>s</code>.</li>
</ul>

@ -1,20 +1,20 @@
<p>Write a method to return all subsets of a set. The elements in a set are&nbsp;pairwise distinct.</p>
<p>Note: The result set should not contain duplicated subsets.</p>
<p><strong>Example:</strong></p>
<pre>
<strong> Input</strong>: nums = [1,2,3]
<strong> Output</strong>:
[
[3],
&nbsp; [1],
&nbsp; [2],
&nbsp; [1,2,3],
&nbsp; [1,3],
&nbsp; [2,3],
&nbsp; [1,2],
&nbsp; []
]
</pre>
<p>Write a method to return all subsets of a set. The elements in a set are&nbsp;pairwise distinct.</p>
<p>Note: The result set should not contain duplicated subsets.</p>
<p><strong>Example:</strong></p>
<pre>
<strong> Input</strong>: nums = [1,2,3]
<strong> Output</strong>:
[
[3],
&nbsp; [1],
&nbsp; [2],
&nbsp; [1,2,3],
&nbsp; [1,3],
&nbsp; [2,3],
&nbsp; [1,2],
&nbsp; []
]
</pre>

Some files were not shown because too many files have changed in this diff Show More