mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-05 07:21:40 +08:00
update
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<p>给你一个下标从 <strong>0</strong> 开始的 <strong>环形</strong> 字符串数组 <code>words</code> 和一个字符串 <code>target</code> 。<strong>环形数组</strong> 意味着数组首尾相连。</p>
|
||||
|
||||
<ul>
|
||||
<li>形式上, <code>words[i]</code> 的下一个元素是 <code>words[(i + 1) % n]</code> ,而 <code>words[i]</code> 的前一个元素是 <code>words[(i - 1 + n) % n]</code> ,其中 <code>n</code> 是 <code>words</code> 的长度。</li>
|
||||
</ul>
|
||||
|
||||
<p>从 <code>startIndex</code> 开始,你一次可以用 <code>1</code> 步移动到下一个或者前一个单词。</p>
|
||||
|
||||
<p>返回到达目标字符串 <code>target</code> 所需的最短距离。如果 <code>words</code> 中不存在字符串 <code>target</code> ,返回 <code>-1</code> 。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>words = ["hello","i","am","leetcode","hello"], target = "hello", startIndex = 1
|
||||
<strong>输出:</strong>1
|
||||
<strong>解释:</strong>从下标 1 开始,可以经由以下步骤到达 "hello" :
|
||||
- 向右移动 3 个单位,到达下标 4 。
|
||||
- 向左移动 2 个单位,到达下标 4 。
|
||||
- 向右移动 4 个单位,到达下标 0 。
|
||||
- 向左移动 1 个单位,到达下标 0 。
|
||||
到达 "hello" 的最短距离是 1 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>words = ["a","b","leetcode"], target = "leetcode", startIndex = 0
|
||||
<strong>输出:</strong>1
|
||||
<strong>解释:</strong>从下标 0 开始,可以经由以下步骤到达 "leetcode" :
|
||||
- 向右移动 2 个单位,到达下标 3 。
|
||||
- 向左移动 1 个单位,到达下标 3 。
|
||||
到达 "leetcode" 的最短距离是 1 。</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>words = ["i","eat","leetcode"], target = "ate", startIndex = 0
|
||||
<strong>输出:</strong>-1
|
||||
<strong>解释:</strong>因为 words 中不存在字符串 "ate" ,所以返回 -1 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= words.length <= 100</code></li>
|
||||
<li><code>1 <= words[i].length <= 100</code></li>
|
||||
<li><code>words[i]</code> 和 <code>target</code> 仅由小写英文字母组成</li>
|
||||
<li><code>0 <= startIndex < words.length</code></li>
|
||||
</ul>
|
@@ -0,0 +1,46 @@
|
||||
<p>给你两个字符串数组 <code>positive_feedback</code> 和 <code>negative_feedback</code> ,分别包含表示正面的和负面的词汇。<strong>不会</strong> 有单词同时是正面的和负面的。</p>
|
||||
|
||||
<p>一开始,每位学生分数为 <code>0</code> 。每个正面的单词会给学生的分数 <strong>加 </strong><code>3</code> 分,每个负面的词会给学生的分数 <strong>减 </strong> <code>1</code> 分。</p>
|
||||
|
||||
<p>给你 <code>n</code> 个学生的评语,用一个下标从 <strong>0</strong> 开始的字符串数组 <code>report</code> 和一个下标从 <strong>0</strong> 开始的整数数组 <code>student_id</code> 表示,其中 <code>student_id[i]</code> 表示这名学生的 ID ,这名学生的评语是 <code>report[i]</code> 。每名学生的 ID <strong>互不相同</strong>。</p>
|
||||
|
||||
<p>给你一个整数 <code>k</code> ,请你返回按照得分 <strong>从高到低</strong> 最顶尖的<em> </em><code>k</code> 名学生。如果有多名学生分数相同,ID 越小排名越前。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>positive_feedback = ["smart","brilliant","studious"], negative_feedback = ["not"], report = ["this student is studious","the student is smart"], student_id = [1,2], k = 2
|
||||
<b>输出:</b>[1,2]
|
||||
<b>解释:</b>
|
||||
两名学生都有 1 个正面词汇,都得到 3 分,学生 1 的 ID 更小所以排名更前。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>positive_feedback = ["smart","brilliant","studious"], negative_feedback = ["not"], report = ["this student is not studious","the student is smart"], student_id = [1,2], k = 2
|
||||
<b>输出:</b>[2,1]
|
||||
<b>解释:</b>
|
||||
- ID 为 1 的学生有 1 个正面词汇和 1 个负面词汇,所以得分为 3-1=2 分。
|
||||
- ID 为 2 的学生有 1 个正面词汇,得分为 3 分。
|
||||
学生 2 分数更高,所以返回 [2,1] 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= positive_feedback.length, negative_feedback.length <= 10<sup>4</sup></code></li>
|
||||
<li><code>1 <= positive_feedback[i].length, negative_feedback[j].length <= 100</code></li>
|
||||
<li><code>positive_feedback[i]</code> 和 <code>negative_feedback[j]</code> 都只包含小写英文字母。</li>
|
||||
<li><code>positive_feedback</code> 和 <code>negative_feedback</code> 中不会有相同单词。</li>
|
||||
<li><code>n == report.length == student_id.length</code></li>
|
||||
<li><code>1 <= n <= 10<sup>4</sup></code></li>
|
||||
<li><code>report[i]</code> 只包含小写英文字母和空格 <code>' '</code> 。</li>
|
||||
<li><code>report[i]</code> 中连续单词之间有单个空格隔开。</li>
|
||||
<li><code>1 <= report[i].length <= 100</code></li>
|
||||
<li><code>1 <= student_id[i] <= 10<sup>9</sup></code></li>
|
||||
<li><code>student_id[i]</code> 的值 <strong>互不相同</strong> 。</li>
|
||||
<li><code>1 <= k <= n</code></li>
|
||||
</ul>
|
@@ -0,0 +1,43 @@
|
||||
<p>给你一个正整数数组 <code>nums</code> 和一个整数 <code>k</code> 。</p>
|
||||
|
||||
<p><strong>分区</strong> 的定义是:将数组划分成两个有序的 <strong>组</strong> ,并满足每个元素 <strong>恰好</strong> 存在于 <strong>某一个</strong> 组中。如果分区中每个组的元素和都大于等于 <code>k</code> ,则认为分区是一个好分区。</p>
|
||||
|
||||
<p>返回 <strong>不同</strong> 的好分区的数目。由于答案可能很大,请返回对 <code>10<sup>9</sup> + 7</code> <strong>取余</strong> 后的结果。</p>
|
||||
|
||||
<p>如果在两个分区中,存在某个元素 <code>nums[i]</code> 被分在不同的组中,则认为这两个分区不同。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>nums = [1,2,3,4], k = 4
|
||||
<strong>输出:</strong>6
|
||||
<strong>解释:</strong>好分区的情况是 ([1,2,3], [4]), ([1,3], [2,4]), ([1,4], [2,3]), ([2,3], [1,4]), ([2,4], [1,3]) 和 ([4], [1,2,3]) 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>nums = [3,3,3], k = 4
|
||||
<strong>输出:</strong>0
|
||||
<strong>解释:</strong>数组中不存在好分区。
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">示例 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>nums = [6,6], k = 2
|
||||
<strong>输出:</strong>2
|
||||
<strong>解释:</strong>可以将 nums[0] 放入第一个分区或第二个分区中。
|
||||
好分区的情况是 ([6], [6]) 和 ([6], [6]) 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length, k <= 1000</code></li>
|
||||
<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
@@ -0,0 +1,46 @@
|
||||
<p>给你一个字符串 <code>s</code> ,它每一位都是 <code>1</code> 到 <code>9</code> 之间的数字组成,同时给你一个整数 <code>k</code> 。</p>
|
||||
|
||||
<p>如果一个字符串 <code>s</code> 的分割满足以下条件,我们称它是一个 <strong>好</strong> 分割:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>s</code> 中每个数位 <strong>恰好</strong> 属于一个子字符串。</li>
|
||||
<li>每个子字符串的值都小于等于 <code>k</code> 。</li>
|
||||
</ul>
|
||||
|
||||
<p>请你返回 <code>s</code> 所有的 <strong>好</strong> 分割中,子字符串的 <strong>最少</strong> 数目。如果不存在 <code>s</code> 的<strong> 好</strong> 分割,返回 <code>-1</code> 。</p>
|
||||
|
||||
<p><b>注意:</b></p>
|
||||
|
||||
<ul>
|
||||
<li>一个字符串的 <strong>值</strong> 是这个字符串对应的整数。比方说,<code>"123"</code> 的值为 <code>123</code> ,<code>"1"</code> 的值是 <code>1</code> 。</li>
|
||||
<li><strong>子字符串</strong> 是字符串中一段连续的字符序列。</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>s = "165462", k = 60
|
||||
<b>输出:</b>4
|
||||
<b>解释:</b>我们将字符串分割成子字符串 "16" ,"54" ,"6" 和 "2" 。每个子字符串的值都小于等于 k = 60 。
|
||||
不存在小于 4 个子字符串的好分割。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>s = "238182", k = 5
|
||||
<b>输出:</b>-1
|
||||
<strong>解释:</strong>这个字符串不存在好分割。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= s.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>s[i]</code> 是 <code>'1'</code> 到 <code>'9'</code> 之间的数字。</li>
|
||||
<li><code>1 <= k <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
@@ -0,0 +1,36 @@
|
||||
<p>给你一个正整数数组 <code>nums</code> ,对 <code>nums</code> 所有元素求积之后,找出并返回乘积中 <strong>不同质因数</strong> 的数目。</p>
|
||||
|
||||
<p><strong>注意:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><strong>质数</strong> 是指大于 <code>1</code> 且仅能被 <code>1</code> 及自身整除的数字。</li>
|
||||
<li>如果 <code>val2 / val1</code> 是一个整数,则整数 <code>val1</code> 是另一个整数 <code>val2</code> 的一个因数。</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>nums = [2,4,3,7,10,6]
|
||||
<strong>输出:</strong>4
|
||||
<strong>解释:</strong>
|
||||
nums 中所有元素的乘积是:2 * 4 * 3 * 7 * 10 * 6 = 10080 = 2<sup>5</sup> * 3<sup>2</sup> * 5 * 7 。
|
||||
共有 4 个不同的质因数,所以返回 4 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>nums = [2,4,8,16]
|
||||
<strong>输出:</strong>1
|
||||
<strong>解释:</strong>
|
||||
nums 中所有元素的乘积是:2 * 4 * 8 * 16 = 1024 = 2<sup>10</sup> 。
|
||||
共有 1 个不同的质因数,所以返回 1 。</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 10<sup>4</sup></code></li>
|
||||
<li><code>2 <= nums[i] <= 1000</code></li>
|
||||
</ul>
|
@@ -0,0 +1,46 @@
|
||||
<p>给你一个长度为 <code>n</code> ,下标从 <strong>0</strong> 开始的整数数组 <code>forts</code> ,表示一些城堡。<code>forts[i]</code> 可以是 <code>-1</code> ,<code>0</code> 或者 <code>1</code> ,其中:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>-1</code> 表示第 <code>i</code> 个位置 <strong>没有</strong> 城堡。</li>
|
||||
<li><code>0</code> 表示第 <code>i</code> 个位置有一个 <strong>敌人</strong> 的城堡。</li>
|
||||
<li><code>1</code> 表示第 <code>i</code> 个位置有一个你控制的城堡。</li>
|
||||
</ul>
|
||||
|
||||
<p>现在,你需要决定,将你的军队从某个你控制的城堡位置 <code>i</code> 移动到一个空的位置 <code>j</code> ,满足:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= i, j <= n - 1</code></li>
|
||||
<li>军队经过的位置 <strong>只有</strong> 敌人的城堡。正式的,对于所有 <code>min(i,j) < k < max(i,j)</code> 的 <code>k</code> ,都满足 <code>forts[k] == 0</code> 。</li>
|
||||
</ul>
|
||||
|
||||
<p>当军队移动时,所有途中经过的敌人城堡都会被 <strong>摧毁</strong> 。</p>
|
||||
|
||||
<p>请你返回 <strong>最多</strong> 可以摧毁的敌人城堡数目。如果 <strong>无法</strong> 移动你的军队,或者没有你控制的城堡,请返回 <code>0</code> 。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>forts = [1,0,0,-1,0,0,0,0,1]
|
||||
<b>输出:</b>4
|
||||
<strong>解释:</strong>
|
||||
- 将军队从位置 0 移动到位置 3 ,摧毁 2 个敌人城堡,位置分别在 1 和 2 。
|
||||
- 将军队从位置 8 移动到位置 3 ,摧毁 4 个敌人城堡。
|
||||
4 是最多可以摧毁的敌人城堡数目,所以我们返回 4 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>forts = [0,0,1,-1]
|
||||
<b>输出:</b>0
|
||||
<b>解释:</b>由于无法摧毁敌人的城堡,所以返回 0 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= forts.length <= 1000</code></li>
|
||||
<li><code>-1 <= forts[i] <= 1</code></li>
|
||||
</ul>
|
@@ -0,0 +1,52 @@
|
||||
<p>给你两个数组 <code>arr1</code> 和 <code>arr2</code> ,它们一开始都是空的。你需要往它们中添加正整数,使它们满足以下条件:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>arr1</code> 包含 <code>uniqueCnt1</code> 个<strong> 互不相同</strong> 的正整数,每个整数都 <strong>不能 </strong>被 <code>divisor1</code> <strong>整除</strong> 。</li>
|
||||
<li><code>arr2</code> 包含 <code>uniqueCnt2</code> 个<strong> 互不相同</strong> 的正整数,每个整数都 <strong>不能</strong> 被 <code>divisor2</code> <strong>整除</strong> 。</li>
|
||||
<li><code>arr1</code> 和 <code>arr2</code> 中的元素 <strong>互不相同</strong> 。</li>
|
||||
</ul>
|
||||
|
||||
<p>给你 <code>divisor1</code> ,<code>divisor2</code> ,<code>uniqueCnt1</code> 和 <code>uniqueCnt2</code> ,请你返回两个数组中 <strong>最大元素</strong> 的 <strong>最小值</strong> 。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>divisor1 = 2, divisor2 = 7, uniqueCnt1 = 1, uniqueCnt2 = 3
|
||||
<b>输出:</b>4
|
||||
<b>解释:</b>
|
||||
我们可以把前 4 个自然数划分到 arr1 和 arr2 中。
|
||||
arr1 = [1] 和 arr2 = [2,3,4] 。
|
||||
可以看出两个数组都满足条件。
|
||||
最大值是 4 ,所以返回 4 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>divisor1 = 3, divisor2 = 5, uniqueCnt1 = 2, uniqueCnt2 = 1
|
||||
<b>输出:</b>3
|
||||
<b>解释:</b>
|
||||
arr1 = [1,2] 和 arr2 = [3] 满足所有条件。
|
||||
最大值是 3 ,所以返回 3 。</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>divisor1 = 2, divisor2 = 4, uniqueCnt1 = 8, uniqueCnt2 = 2
|
||||
<b>输出:</b>15
|
||||
<b>解释:</b>
|
||||
最终数组为 arr1 = [1,3,5,7,9,11,13,15] 和 arr2 = [2,6] 。
|
||||
上述方案是满足所有条件的最优解。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= divisor1, divisor2 <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= uniqueCnt1, uniqueCnt2 < 10<sup>9</sup></code></li>
|
||||
<li><code>2 <= uniqueCnt1 + uniqueCnt2 <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
@@ -0,0 +1,35 @@
|
||||
<p>给你一个由字符 <code>'a'</code>、<code>'b'</code>、<code>'c'</code> 组成的字符串 <code>s</code> 和一个非负整数 <code>k</code> 。每分钟,你可以选择取走 <code>s</code> <strong>最左侧</strong> 还是 <strong>最右侧</strong> 的那个字符。</p>
|
||||
|
||||
<p>你必须取走每种字符 <strong>至少</strong> <code>k</code> 个,返回需要的 <strong>最少</strong> 分钟数;如果无法取到,则返回<em> </em><code>-1</code> 。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>s = "aabaaaacaabc", k = 2
|
||||
<strong>输出:</strong>8
|
||||
<strong>解释:</strong>
|
||||
从 s 的左侧取三个字符,现在共取到两个字符 'a' 、一个字符 'b' 。
|
||||
从 s 的右侧取五个字符,现在共取到四个字符 'a' 、两个字符 'b' 和两个字符 'c' 。
|
||||
共需要 3 + 5 = 8 分钟。
|
||||
可以证明需要的最少分钟数是 8 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>s = "a", k = 1
|
||||
<strong>输出:</strong>-1
|
||||
<strong>解释:</strong>无法取到一个字符 'b' 或者 'c',所以返回 -1 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= s.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>s</code> 仅由字母 <code>'a'</code>、<code>'b'</code>、<code>'c'</code> 组成</li>
|
||||
<li><code>0 <= k <= s.length</code></li>
|
||||
</ul>
|
@@ -0,0 +1,45 @@
|
||||
<p>给你一个正整数数组 <code>price</code> ,其中 <code>price[i]</code> 表示第 <code>i</code> 类糖果的价格,另给你一个正整数 <code>k</code> 。</p>
|
||||
|
||||
<p>商店组合 <code>k</code> 类 <strong>不同</strong> 糖果打包成礼盒出售。礼盒的 <strong>甜蜜度</strong> 是礼盒中任意两种糖果 <strong>价格</strong> 绝对差的最小值。</p>
|
||||
|
||||
<p>返回礼盒的 <strong>最大 </strong>甜蜜度<em>。</em></p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>price = [13,5,1,8,21,2], k = 3
|
||||
<strong>输出:</strong>8
|
||||
<strong>解释:</strong>选出价格分别为 [13,5,21] 的三类糖果。
|
||||
礼盒的甜蜜度为 min(|13 - 5|, |13 - 21|, |5 - 21|) = min(8, 8, 16) = 8 。
|
||||
可以证明能够取得的最大甜蜜度就是 8 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>price = [1,3,1], k = 2
|
||||
<strong>输出:</strong>2
|
||||
<strong>解释:</strong>选出价格分别为 [1,3] 的两类糖果。
|
||||
礼盒的甜蜜度为 min(|1 - 3|) = min(2) = 2 。
|
||||
可以证明能够取得的最大甜蜜度就是 2 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>price = [7,7,7,7], k = 2
|
||||
<strong>输出:</strong>0
|
||||
<strong>解释:</strong>从现有的糖果中任选两类糖果,甜蜜度都会是 0 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= price.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= price[i] <= 10<sup>9</sup></code></li>
|
||||
<li><code>2 <= k <= price.length</code></li>
|
||||
</ul>
|
@@ -0,0 +1,34 @@
|
||||
<p>给你一个字符串 <code>s</code> ,它包含一个或者多个单词。单词之间用单个空格 <code>' '</code> 隔开。</p>
|
||||
|
||||
<p>如果字符串 <code>t</code> 中第 <code>i</code> 个单词是 <code>s</code> 中第 <code>i</code> 个单词的一个 <strong>排列</strong> ,那么我们称字符串 <code>t</code> 是字符串 <code>s</code> 的同位异构字符串。</p>
|
||||
|
||||
<ul>
|
||||
<li>比方说,<code>"acb dfe"</code> 是 <code>"abc def"</code> 的同位异构字符串,但是 <code>"def cab"</code> 和 <code>"adc bef"</code> 不是。</li>
|
||||
</ul>
|
||||
|
||||
<p>请你返回<em> </em><code>s</code> 的同位异构字符串的数目,由于答案可能很大,请你将它对 <code>10<sup>9</sup> + 7</code> <strong>取余</strong> 后返回。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>s = "too hot"
|
||||
<b>输出:</b>18
|
||||
<b>解释:</b>输入字符串的一些同位异构字符串为 "too hot" ,"oot hot" ,"oto toh" ,"too toh" 以及 "too oht" 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>s = "aa"
|
||||
<b>输出:</b>1
|
||||
<strong>解释:</strong>输入字符串只有一个同位异构字符串。</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= s.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>s</code> 只包含小写英文字母和空格 <code>' '</code> 。</li>
|
||||
<li>相邻单词之间由单个空格隔开。</li>
|
||||
</ul>
|
@@ -0,0 +1,35 @@
|
||||
<p>给你一个整数 <code>num</code> ,返回 <code>num</code> 中能整除 <code>num</code> 的数位的数目。</p>
|
||||
|
||||
<p>如果满足 <code>nums % val == 0</code> ,则认为整数 <code>val</code> 可以整除 <code>nums</code> 。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>num = 7
|
||||
<strong>输出:</strong>1
|
||||
<strong>解释:</strong>7 被自己整除,因此答案是 1 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>num = 121
|
||||
<strong>输出:</strong>2
|
||||
<strong>解释:</strong>121 可以被 1 整除,但无法被 2 整除。由于 1 出现两次,所以返回 2 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>num = 1248
|
||||
<strong>输出:</strong>4
|
||||
<strong>解释:</strong>1248 可以被它每一位上的数字整除,因此答案是 4 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= num <= 10<sup>9</sup></code></li>
|
||||
<li><code>num</code> 的数位中不含 <code>0</code></li>
|
||||
</ul>
|
@@ -0,0 +1,39 @@
|
||||
<p>给你两个正整数 <code>left</code> 和 <code>right</code> ,请你找到两个整数 <code>num1</code> 和 <code>num2</code> ,它们满足:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>left <= nums1 < nums2 <= right </code> 。</li>
|
||||
<li><code>nums1</code> 和 <code>nums2</code> 都是 <strong>质数</strong> 。</li>
|
||||
<li><code>nums2 - nums1</code> 是满足上述条件的质数对中的 <strong>最小值</strong> 。</li>
|
||||
</ul>
|
||||
|
||||
<p>请你返回正整数数组 <code>ans = [nums1, nums2]</code> 。如果有多个整数对满足上述条件,请你返回 <code>nums1</code> 最小的质数对。如果不存在符合题意的质数对,请你返回 <code>[-1, -1]</code> 。</p>
|
||||
|
||||
<p>如果一个整数大于 <code>1</code> ,且只能被 <code>1</code> 和它自己整除,那么它是一个质数。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>left = 10, right = 19
|
||||
<b>输出:</b>[11,13]
|
||||
<b>解释:</b>10 到 19 之间的质数为 11 ,13 ,17 和 19 。
|
||||
质数对的最小差值是 2 ,[11,13] 和 [17,19] 都可以得到最小差值。
|
||||
由于 11 比 17 小,我们返回第一个质数对。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>left = 4, right = 6
|
||||
<b>输出:</b>[-1,-1]
|
||||
<b>解释:</b>给定范围内只有一个质数,所以题目条件无法被满足。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= left <= right <= 10<sup>6</sup></code></li>
|
||||
</ul>
|
Reference in New Issue
Block a user