mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-03 14:32:54 +08:00
update
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
180
leetcode/originData/count-elements-with-maximum-frequency.json
Normal file
180
leetcode/originData/count-elements-with-maximum-frequency.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
32
leetcode/problem/count-elements-with-maximum-frequency.html
Normal file
32
leetcode/problem/count-elements-with-maximum-frequency.html
Normal file
@@ -0,0 +1,32 @@
|
||||
<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers.</p>
|
||||
|
||||
<p>Return <em>the <strong>total frequencies</strong> of elements in</em><em> </em><code>nums</code> <em>such that those elements all have the <strong>maximum</strong> frequency</em>.</p>
|
||||
|
||||
<p>The <strong>frequency</strong> of an element is the number of occurrences of that element in the array.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,2,2,3,1,4]
|
||||
<strong>Output:</strong> 4
|
||||
<strong>Explanation:</strong> The elements 1 and 2 have a frequency of 2 which is the maximum frequency in the array.
|
||||
So the number of elements in the array with maximum frequency is 4.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,2,3,4,5]
|
||||
<strong>Output:</strong> 5
|
||||
<strong>Explanation:</strong> All elements of the array have a frequency of 1 which is the maximum.
|
||||
So the number of elements in the array with maximum frequency is 5.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 100</code></li>
|
||||
<li><code>1 <= nums[i] <= 100</code></li>
|
||||
</ul>
|
@@ -0,0 +1,48 @@
|
||||
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p>
|
||||
|
||||
<p>An index <code>i</code> is <strong>beautiful</strong> if:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= i <= s.length - a.length</code></li>
|
||||
<li><code>s[i..(i + a.length - 1)] == a</code></li>
|
||||
<li>There exists an index <code>j</code> such that:
|
||||
<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>Return <em>the array that contains beautiful indices in <strong>sorted order from smallest to largest</strong></em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "isawsquirrelnearmysquirrelhouseohmy", a = "my", b = "squirrel", k = 15
|
||||
<strong>Output:</strong> [16,33]
|
||||
<strong>Explanation:</strong> There are 2 beautiful indices: [16,33].
|
||||
- The index 16 is beautiful as s[16..17] == "my" and there exists an index 4 with s[4..11] == "squirrel" and |16 - 4| <= 15.
|
||||
- The index 33 is beautiful as s[33..34] == "my" and there exists an index 18 with s[18..25] == "squirrel" and |33 - 18| <= 15.
|
||||
Thus we return [16,33] as the result.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "abcd", a = "a", b = "a", k = 4
|
||||
<strong>Output:</strong> [0]
|
||||
<strong>Explanation:</strong> There is 1 beautiful index: [0].
|
||||
- The index 0 is beautiful as s[0..0] == "a" and there exists an index 0 with s[0..0] == "a" and |0 - 0| <= 4.
|
||||
Thus we return [0] as the result.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</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>, and <code>b</code> contain only lowercase English letters.</li>
|
||||
</ul>
|
@@ -0,0 +1,48 @@
|
||||
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p>
|
||||
|
||||
<p>An index <code>i</code> is <strong>beautiful</strong> if:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= i <= s.length - a.length</code></li>
|
||||
<li><code>s[i..(i + a.length - 1)] == a</code></li>
|
||||
<li>There exists an index <code>j</code> such that:
|
||||
<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>Return <em>the array that contains beautiful indices in <strong>sorted order from smallest to largest</strong></em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "isawsquirrelnearmysquirrelhouseohmy", a = "my", b = "squirrel", k = 15
|
||||
<strong>Output:</strong> [16,33]
|
||||
<strong>Explanation:</strong> There are 2 beautiful indices: [16,33].
|
||||
- The index 16 is beautiful as s[16..17] == "my" and there exists an index 4 with s[4..11] == "squirrel" and |16 - 4| <= 15.
|
||||
- The index 33 is beautiful as s[33..34] == "my" and there exists an index 18 with s[18..25] == "squirrel" and |33 - 18| <= 15.
|
||||
Thus we return [16,33] as the result.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "abcd", a = "a", b = "a", k = 4
|
||||
<strong>Output:</strong> [0]
|
||||
<strong>Explanation:</strong> There is 1 beautiful index: [0].
|
||||
- The index 0 is beautiful as s[0..0] == "a" and there exists an index 0 with s[0..0] == "a" and |0 - 0| <= 4.
|
||||
Thus we return [0] as the result.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</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>, and <code>b</code> contain only lowercase English letters.</li>
|
||||
</ul>
|
@@ -0,0 +1,45 @@
|
||||
<p>You are given an integer <code>k</code> and an integer <code>x</code>.</p>
|
||||
|
||||
<p>Consider <code>s</code> is the <strong>1-indexed </strong>binary representation of an integer <code>num</code>. The <strong>price</strong> of a number <code>num</code> is the number of <code>i</code>'s such that <code>i % x == 0</code> and <code><font face="monospace">s[i]</font></code> is a <strong>set bit</strong>.</p>
|
||||
|
||||
<p>Return <em>the <b>greatest</b> integer </em><code>num</code><em> such that the sum of <strong>prices</strong> of all numbers from </em><code>1</code><em> to </em><code>num</code><em> is less than or equal to </em><code>k</code><em>.</em></p>
|
||||
|
||||
<p><strong>Note</strong>:</p>
|
||||
|
||||
<ul>
|
||||
<li>In the binary representation of a number <strong>set bit</strong> is a bit of value <code>1</code>.</li>
|
||||
<li>The binary representation of a number will be indexed from right to left. For example, if <code>s == 11100</code>, <code>s[4] == 1</code> and <code>s[2] == 0</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> k = 9, x = 1
|
||||
<strong>Output:</strong> 6
|
||||
<strong>Explanation:</strong> The numbers 1, 2, 3, 4, 5, and 6 can be written in binary representation as "1", "10", "11", "100", "101", and "110" respectively.
|
||||
Since x is equal to 1, the price of each number is the number of its set bits.
|
||||
The number of set bits in these numbers is 9. So the sum of the prices of the first 6 numbers is 9.
|
||||
So the answer is 6.</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> k = 7, x = 2
|
||||
<strong>Output:</strong> 9
|
||||
<strong>Explanation:</strong> Since x is equal to 2, we should just check even<sup>th</sup> bits.
|
||||
The second bit of binary representation of numbers 2 and 3 is a set bit. So the sum of their prices is 2.
|
||||
The second bit of binary representation of numbers 6 and 7 is a set bit. So the sum of their prices is 2.
|
||||
The fourth bit of binary representation of numbers 8 and 9 is a set bit but their second bit is not. So the sum of their prices is 2.
|
||||
Numbers 1, 4, and 5 don't have set bits in their even<sup>th</sup> bits in their binary representation. So the sum of their prices is 0.
|
||||
The second and the fourth bit of the binary representation of the number 10 are a set bit. So its price is 2.
|
||||
The sum of the prices of the first 9 numbers is 6.
|
||||
Because the sum of the prices of the first 10 numbers is 8, the answer is 9.</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= k <= 10<sup>15</sup></code></li>
|
||||
<li><code>1 <= x <= 8</code></li>
|
||||
</ul>
|
Reference in New Issue
Block a user