mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 10:38:13 +08:00
update
This commit is contained in:
parent
e9f28d863c
commit
96aa5b0ba0
@ -1,6 +1,6 @@
|
||||
# 力扣题库(完整版)
|
||||
|
||||
> 最后更新日期: **2022.09.04**
|
||||
> 最后更新日期: **2022.09.10**
|
||||
>
|
||||
> 使用脚本前请务必仔细完整阅读本 `README.md` 文件
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
180
leetcode/originData/longest-nice-subarray.json
Normal file
180
leetcode/originData/longest-nice-subarray.json
Normal file
File diff suppressed because one or more lines are too long
193
leetcode/originData/maximum-rows-covered-by-columns.json
Normal file
193
leetcode/originData/maximum-rows-covered-by-columns.json
Normal file
File diff suppressed because one or more lines are too long
182
leetcode/originData/meeting-rooms-iii.json
Normal file
182
leetcode/originData/meeting-rooms-iii.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
180
leetcode/originData/strictly-palindromic-number.json
Normal file
180
leetcode/originData/strictly-palindromic-number.json
Normal file
File diff suppressed because one or more lines are too long
37
leetcode/problem/longest-nice-subarray.html
Normal file
37
leetcode/problem/longest-nice-subarray.html
Normal file
@ -0,0 +1,37 @@
|
||||
<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers.</p>
|
||||
|
||||
<p>We call a subarray of <code>nums</code> <strong>nice</strong> if the bitwise <strong>AND</strong> of every pair of elements that are in <strong>different</strong> positions in the subarray is equal to <code>0</code>.</p>
|
||||
|
||||
<p>Return <em>the length of the <strong>longest</strong> nice subarray</em>.</p>
|
||||
|
||||
<p>A <strong>subarray</strong> is a <strong>contiguous</strong> part of an array.</p>
|
||||
|
||||
<p><strong>Note</strong> that subarrays of length <code>1</code> are always considered nice.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,3,8,48,10]
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> The longest nice subarray is [3,8,48]. This subarray satisfies the conditions:
|
||||
- 3 AND 8 = 0.
|
||||
- 3 AND 48 = 0.
|
||||
- 8 AND 48 = 0.
|
||||
It can be proven that no longer nice subarray can be obtained, so we return 3.</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [3,1,5,11,13]
|
||||
<strong>Output:</strong> 1
|
||||
<strong>Explanation:</strong> The length of the longest nice subarray is 1. Any subarray of length 1 can be chosen.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
48
leetcode/problem/maximum-rows-covered-by-columns.html
Normal file
48
leetcode/problem/maximum-rows-covered-by-columns.html
Normal file
@ -0,0 +1,48 @@
|
||||
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>matrix</code> and an integer <code>numSelect</code>, which denotes the number of <strong>distinct</strong> columns you must select from <code>matrix</code>.</p>
|
||||
|
||||
<p>Let us consider <code>s = {c<sub>1</sub>, c<sub>2</sub>, ...., c<sub>numSelect</sub>}</code> as the set of columns selected by you. A row <code>row</code> is <strong>covered</strong> by <code>s</code> if:</p>
|
||||
|
||||
<ul>
|
||||
<li>For each cell <code>matrix[row][col]</code> (<code>0 <= col <= n - 1</code>) where <code>matrix[row][col] == 1</code>, <code>col</code> is present in <code>s</code> or,</li>
|
||||
<li><strong>No cell</strong> in <code>row</code> has a value of <code>1</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>You need to choose <code>numSelect</code> columns such that the number of rows that are covered is <strong>maximized</strong>.</p>
|
||||
|
||||
<p>Return <em>the <strong>maximum</strong> number of rows that can be <strong>covered</strong> by a set of </em><code>numSelect</code><em> columns.</em></p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/07/14/rowscovered.png" style="width: 240px; height: 400px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> matrix = [[0,0,0],[1,0,1],[0,1,1],[0,0,1]], numSelect = 2
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> One possible way to cover 3 rows is shown in the diagram above.
|
||||
We choose s = {0, 2}.
|
||||
- Row 0 is covered because it has no occurrences of 1.
|
||||
- Row 1 is covered because the columns with value 1, i.e. 0 and 2 are present in s.
|
||||
- Row 2 is not covered because matrix[2][1] == 1 but 1 is not present in s.
|
||||
- Row 3 is covered because matrix[2][2] == 1 and 2 is present in s.
|
||||
Thus, we can cover three rows.
|
||||
Note that s = {1, 2} will also cover 3 rows, but it can be shown that no more than three rows can be covered.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/07/14/rowscovered2.png" style="height: 250px; width: 84px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> matrix = [[1],[0]], numSelect = 1
|
||||
<strong>Output:</strong> 2
|
||||
<strong>Explanation:</strong> Selecting the only column will result in both rows being covered since the entire matrix is selected.
|
||||
Therefore, we return 2.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>m == matrix.length</code></li>
|
||||
<li><code>n == matrix[i].length</code></li>
|
||||
<li><code>1 <= m, n <= 12</code></li>
|
||||
<li><code>matrix[i][j]</code> is either <code>0</code> or <code>1</code>.</li>
|
||||
<li><code>1 <= numSelect <= n</code></li>
|
||||
</ul>
|
58
leetcode/problem/meeting-rooms-iii.html
Normal file
58
leetcode/problem/meeting-rooms-iii.html
Normal file
@ -0,0 +1,58 @@
|
||||
<p>You are given an integer <code>n</code>. There are <code>n</code> rooms numbered from <code>0</code> to <code>n - 1</code>.</p>
|
||||
|
||||
<p>You are given a 2D integer array <code>meetings</code> where <code>meetings[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means that a meeting will be held during the <strong>half-closed</strong> time interval <code>[start<sub>i</sub>, end<sub>i</sub>)</code>. All the values of <code>start<sub>i</sub></code> are <strong>unique</strong>.</p>
|
||||
|
||||
<p>Meetings are allocated to rooms in the following manner:</p>
|
||||
|
||||
<ol>
|
||||
<li>Each meeting will take place in the unused room with the <strong>lowest</strong> number.</li>
|
||||
<li>If there are no available rooms, the meeting will be delayed until a room becomes free. The delayed meeting should have the <strong>same</strong> duration as the original meeting.</li>
|
||||
<li>When a room becomes unused, meetings that have an earlier original <strong>start</strong> time should be given the room.</li>
|
||||
</ol>
|
||||
|
||||
<p>Return<em> the <strong>number</strong> of the room that held the most meetings. </em>If there are multiple rooms, return<em> the room with the <strong>lowest</strong> number.</em></p>
|
||||
|
||||
<p>A <strong>half-closed interval</strong> <code>[a, b)</code> is the interval between <code>a</code> and <code>b</code> <strong>including</strong> <code>a</code> and <strong>not including</strong> <code>b</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 2, meetings = [[0,10],[1,5],[2,7],[3,4]]
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong>
|
||||
- At time 0, both rooms are not being used. The first meeting starts in room 0.
|
||||
- At time 1, only room 1 is not being used. The second meeting starts in room 1.
|
||||
- At time 2, both rooms are being used. The third meeting is delayed.
|
||||
- At time 3, both rooms are being used. The fourth meeting is delayed.
|
||||
- At time 5, the meeting in room 1 finishes. The third meeting starts in room 1 for the time period [5,10).
|
||||
- At time 10, the meetings in both rooms finish. The fourth meeting starts in room 0 for the time period [10,11).
|
||||
Both rooms 0 and 1 held 2 meetings, so we return 0.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 3, meetings = [[1,20],[2,10],[3,5],[4,9],[6,8]]
|
||||
<strong>Output:</strong> 1
|
||||
<strong>Explanation:</strong>
|
||||
- At time 1, all three rooms are not being used. The first meeting starts in room 0.
|
||||
- At time 2, rooms 1 and 2 are not being used. The second meeting starts in room 1.
|
||||
- At time 3, only room 2 is not being used. The third meeting starts in room 2.
|
||||
- At time 4, all three rooms are being used. The fourth meeting is delayed.
|
||||
- At time 5, the meeting in room 2 finishes. The fourth meeting starts in room 2 for the time period [5,10).
|
||||
- At time 6, all three rooms are being used. The fifth meeting is delayed.
|
||||
- At time 10, the meetings in rooms 1 and 2 finish. The fifth meeting starts in room 1 for the time period [10,12).
|
||||
Room 0 held 1 meeting while rooms 1 and 2 each held 2 meetings, so we return 1.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n <= 100</code></li>
|
||||
<li><code>1 <= meetings.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>meetings[i].length == 2</code></li>
|
||||
<li><code>0 <= start<sub>i</sub> < end<sub>i</sub> <= 5 * 10<sup>5</sup></code></li>
|
||||
<li>All the values of <code>start<sub>i</sub></code> are <strong>unique</strong>.</li>
|
||||
</ul>
|
@ -0,0 +1,34 @@
|
||||
<p>You are given two <strong>positive</strong> integers <code>startPos</code> and <code>endPos</code>. Initially, you are standing at position <code>startPos</code> on an <strong>infinite</strong> number line. With one step, you can move either one position to the left, or one position to the right.</p>
|
||||
|
||||
<p>Given a positive integer <code>k</code>, return <em>the number of <strong>different</strong> ways to reach the position </em><code>endPos</code><em> starting from </em><code>startPos</code><em>, such that you perform <strong>exactly</strong> </em><code>k</code><em> steps</em>. Since the answer may be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
|
||||
|
||||
<p>Two ways are considered different if the order of the steps made is not exactly the same.</p>
|
||||
|
||||
<p><strong>Note</strong> that the number line includes negative integers.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> startPos = 1, endPos = 2, k = 3
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> We can reach position 2 from 1 in exactly 3 steps in three ways:
|
||||
- 1 -> 2 -> 3 -> 2.
|
||||
- 1 -> 2 -> 1 -> 2.
|
||||
- 1 -> 0 -> 1 -> 2.
|
||||
It can be proven that no other way is possible, so we return 3.</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> startPos = 2, endPos = 5, k = 10
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong> It is impossible to reach position 5 from position 2 in exactly 10 steps.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= startPos, endPos, k <= 1000</code></li>
|
||||
</ul>
|
34
leetcode/problem/strictly-palindromic-number.html
Normal file
34
leetcode/problem/strictly-palindromic-number.html
Normal file
@ -0,0 +1,34 @@
|
||||
<p>An integer <code>n</code> is <strong>strictly palindromic</strong> if, for <strong>every</strong> base <code>b</code> between <code>2</code> and <code>n - 2</code> (<strong>inclusive</strong>), the string representation of the integer <code>n</code> in base <code>b</code> is <strong>palindromic</strong>.</p>
|
||||
|
||||
<p>Given an integer <code>n</code>, return <code>true</code> <em>if </em><code>n</code><em> is <strong>strictly palindromic</strong> and </em><code>false</code><em> otherwise</em>.</p>
|
||||
|
||||
<p>A string is <strong>palindromic</strong> if it reads the same forward and backward.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 9
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation:</strong> In base 2: 9 = 1001 (base 2), which is palindromic.
|
||||
In base 3: 9 = 100 (base 3), which is not palindromic.
|
||||
Therefore, 9 is not strictly palindromic so we return false.
|
||||
Note that in bases 4, 5, 6, and 7, n = 9 is also not palindromic.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 4
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation:</strong> We only consider base 2: 4 = 100 (base 2), which is not palindromic.
|
||||
Therefore, we return false.
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>4 <= n <= 10<sup>5</sup></code></li>
|
||||
</ul>
|
Loading…
Reference in New Issue
Block a user