mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-05 23:41:41 +08:00
update
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<p>给你一个整数 <code>k</code> 和一个整数 <code>x</code> 。</p>
|
||||
|
||||
<p>令 <code>s</code> 为整数 <code>num</code> 的下标从 <strong>1</strong> 开始的二进制表示。我们说一个整数 <code>num</code> 的 <strong>价值</strong> 是满足 <code>i % x == 0</code> 且 <code><font face="monospace">s[i]</font></code> 是 <strong>设置位</strong> 的 <code>i</code> 的数目。</p>
|
||||
|
||||
<p>请你返回<strong> 最大</strong> 整数<em> </em><code>num</code> ,满足从 <code>1</code> 到 <code>num</code> 的所有整数的 <strong>价值</strong> 和小于等于 <code>k</code> 。</p>
|
||||
|
||||
<p><b>注意:</b></p>
|
||||
|
||||
<ul>
|
||||
<li>一个整数二进制表示下 <strong>设置位</strong> 是值为 <code>1</code> 的数位。</li>
|
||||
<li>一个整数的二进制表示下标从右到左编号,比方说如果 <code>s == 11100</code> ,那么 <code>s[4] == 1</code> 且 <code>s[2] == 0</code> 。</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>k = 9, x = 1
|
||||
<b>输出:</b>6
|
||||
<b>解释:</b>数字 1 ,2 ,3 ,4 ,5 和 6 二进制表示分别为 "1" ,"10" ,"11" ,"100" ,"101" 和 "110" 。
|
||||
由于 x 等于 1 ,每个数字的价值分别为所有设置位的数目。
|
||||
这些数字的所有设置位数目总数是 9 ,所以前 6 个数字的价值和为 9 。
|
||||
所以答案为 6 。</pre>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>k = 7, x = 2
|
||||
<b>输出:</b>9
|
||||
<b>解释:</b>由于 x 等于 2 ,我们检查每个数字的偶数位。
|
||||
2 和 3 在二进制表示下的第二个数位为设置位,所以它们的价值和为 2 。
|
||||
6 和 7 在二进制表示下的第二个数位为设置位,所以它们的价值和为 2 。
|
||||
8 和 9 在二进制表示下的第四个数位为设置位但第二个数位不是设置位,所以它们的价值和为 2 。
|
||||
数字 1 ,4 和 5 在二进制下偶数位都不是设置位,所以它们的价值和为 0 。
|
||||
10 在二进制表示下的第二个数位和第四个数位都是设置位,所以它的价值为 2 。
|
||||
前 9 个数字的价值和为 6 。
|
||||
前 10 个数字的价值和为 8,超过了 k = 7 ,所以答案为 9 。</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= k <= 10<sup>15</sup></code></li>
|
||||
<li><code>1 <= x <= 8</code></li>
|
||||
</ul>
|
@@ -0,0 +1,50 @@
|
||||
<p>给你一个下标从 <strong>0</strong> 开始的字符串 <code>s</code> 、字符串 <code>a</code> 、字符串 <code>b</code> 和一个整数 <code>k</code> 。</p>
|
||||
|
||||
<p>如果下标 <code>i</code> 满足以下条件,则认为它是一个 <strong>美丽下标</strong>:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= i <= s.length - a.length</code></li>
|
||||
<li><code>s[i..(i + a.length - 1)] == a</code></li>
|
||||
<li>存在下标 <code>j</code> 使得:
|
||||
<ul>
|
||||
<li><code>0 <= j <= s.length - b.length</code></li>
|
||||
<li><code>s[j..(j + b.length - 1)] == b</code></li>
|
||||
<li><code>|j - i| <= k</code></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<p>以数组形式按<strong> 从小到大排序 </strong>返回美丽下标。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>s = "isawsquirrelnearmysquirrelhouseohmy", a = "my", b = "squirrel", k = 15
|
||||
<strong>输出:</strong>[16,33]
|
||||
<strong>解释:</strong>存在 2 个美丽下标:[16,33]。
|
||||
- 下标 16 是美丽下标,因为 s[16..17] == "my" ,且存在下标 4 ,满足 s[4..11] == "squirrel" 且 |16 - 4| <= 15 。
|
||||
- 下标 33 是美丽下标,因为 s[33..34] == "my" ,且存在下标 18 ,满足 s[18..25] == "squirrel" 且 |33 - 18| <= 15 。
|
||||
因此返回 [16,33] 作为结果。
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>s = "abcd", a = "a", b = "a", k = 4
|
||||
<strong>输出:</strong>[0]
|
||||
<strong>解释:</strong>存在 1 个美丽下标:[0]。
|
||||
- 下标 0 是美丽下标,因为 s[0..0] == "a" ,且存在下标 0 ,满足 s[0..0] == "a" 且 |0 - 0| <= 4 。
|
||||
因此返回 [0] 作为结果。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= k <= s.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= a.length, b.length <= 10</code></li>
|
||||
<li><code>s</code>、<code>a</code>、和 <code>b</code> 只包含小写英文字母。</li>
|
||||
</ul>
|
@@ -0,0 +1,48 @@
|
||||
<p>给你一个下标从 <strong>0</strong> 开始的字符串 <code>s</code> 、字符串 <code>a</code> 、字符串 <code>b</code> 和一个整数 <code>k</code> 。</p>
|
||||
|
||||
<p>如果下标 <code>i</code> 满足以下条件,则认为它是一个 <strong>美丽下标</strong> :</p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= i <= s.length - a.length</code></li>
|
||||
<li><code>s[i..(i + a.length - 1)] == a</code></li>
|
||||
<li>存在下标 <code>j</code> 使得:
|
||||
<ul>
|
||||
<li><code>0 <= j <= s.length - b.length</code></li>
|
||||
<li><code>s[j..(j + b.length - 1)] == b</code></li>
|
||||
<li><code>|j - i| <= k</code></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<p>以数组形式按<strong> 从小到大排序 </strong>返回美丽下标。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>s = "isawsquirrelnearmysquirrelhouseohmy", a = "my", b = "squirrel", k = 15
|
||||
<strong>输出:</strong>[16,33]
|
||||
<strong>解释:</strong>存在 2 个美丽下标:[16,33]。
|
||||
- 下标 16 是美丽下标,因为 s[16..17] == "my" ,且存在下标 4 ,满足 s[4..11] == "squirrel" 且 |16 - 4| <= 15 。
|
||||
- 下标 33 是美丽下标,因为 s[33..34] == "my" ,且存在下标 18 ,满足 s[18..25] == "squirrel" 且 |33 - 18| <= 15 。
|
||||
因此返回 [16,33] 作为结果。</pre>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>s = "abcd", a = "a", b = "a", k = 4
|
||||
<b>输出:</b>[0]
|
||||
<strong>解释:</strong>存在 1 个美丽下标:[0]。
|
||||
- 下标 0 是美丽下标,因为 s[0..0] == "a" ,且存在下标 0 ,满足 s[0..0] == "a" 且 |0 - 0| <= 4 。
|
||||
因此返回 [0] 作为结果。</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= k <= s.length <= 5 * 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= a.length, b.length <= 5 * 10<sup>5</sup></code></li>
|
||||
<li><code>s</code>、<code>a</code>、和 <code>b</code> 只包含小写英文字母。</li>
|
||||
</ul>
|
@@ -0,0 +1,34 @@
|
||||
<p>给你一个由 <strong>正整数 </strong>组成的数组 <code>nums</code> 。</p>
|
||||
|
||||
<p>返回数组 <code>nums</code> 中所有具有 <strong>最大 </strong>频率的元素的 <strong>总频率 </strong>。</p>
|
||||
|
||||
<p>元素的 <strong>频率 </strong>是指该元素在数组中出现的次数。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>nums = [1,2,2,3,1,4]
|
||||
<strong>输出:</strong>4
|
||||
<strong>解释:</strong>元素 1 和 2 的频率为 2 ,是数组中的最大频率。
|
||||
因此具有最大频率的元素在数组中的数量是 4 。
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>nums = [1,2,3,4,5]
|
||||
<strong>输出:</strong>5
|
||||
<strong>解释:</strong>数组中的所有元素的频率都为 1 ,是最大频率。
|
||||
因此具有最大频率的元素在数组中的数量是 5 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 100</code></li>
|
||||
<li><code>1 <= nums[i] <= 100</code></li>
|
||||
</ul>
|
Reference in New Issue
Block a user