mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
update
This commit is contained in:
parent
96aa5b0ba0
commit
8f6be18759
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
183
leetcode-cn/originData/check-distances-between-same-letters.json
Normal file
183
leetcode-cn/originData/check-distances-between-same-letters.json
Normal file
File diff suppressed because one or more lines are too long
183
leetcode-cn/originData/longest-nice-subarray.json
Normal file
183
leetcode-cn/originData/longest-nice-subarray.json
Normal file
File diff suppressed because one or more lines are too long
185
leetcode-cn/originData/meeting-rooms-iii.json
Normal file
185
leetcode-cn/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
@ -0,0 +1,58 @@
|
||||
<p>给你一个整数 <code>n</code> ,共有编号从 <code>0</code> 到 <code>n - 1</code> 的 <code>n</code> 个会议室。</p>
|
||||
|
||||
<p>给你一个二维整数数组 <code>meetings</code> ,其中 <code>meetings[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> 表示一场会议将会在 <strong>半闭</strong> 时间区间 <code>[start<sub>i</sub>, end<sub>i</sub>)</code> 举办。所有 <code>start<sub>i</sub></code> 的值 <strong>互不相同</strong> 。</p>
|
||||
|
||||
<p>会议将会按以下方式分配给会议室:</p>
|
||||
|
||||
<ol>
|
||||
<li>每场会议都会在未占用且编号 <strong>最小</strong> 的会议室举办。</li>
|
||||
<li>如果没有可用的会议室,会议将会延期,直到存在空闲的会议室。延期会议的持续时间和原会议持续时间 <strong>相同</strong> 。</li>
|
||||
<li>当会议室处于未占用状态时,将会优先提供给原 <strong>开始</strong> 时间更早的会议。</li>
|
||||
</ol>
|
||||
|
||||
<p>返回举办最多次会议的房间 <strong>编号</strong> 。如果存在多个房间满足此条件,则返回编号 <strong>最小</strong> 的房间。</p>
|
||||
|
||||
<p><strong>半闭区间 </strong><code>[a, b)</code> 是 <code>a</code> 和 <code>b</code> 之间的区间,<strong>包括</strong> <code>a</code> 但<strong> 不包括</strong> <code>b</code> 。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>n = 2, meetings = [[0,10],[1,5],[2,7],[3,4]]
|
||||
<strong>输出:</strong>0
|
||||
<strong>解释:</strong>
|
||||
- 在时间 0 ,两个会议室都未占用,第一场会议在会议室 0 举办。
|
||||
- 在时间 1 ,只有会议室 1 未占用,第二场会议在会议室 1 举办。
|
||||
- 在时间 2 ,两个会议室都被占用,第三场会议延期举办。
|
||||
- 在时间 3 ,两个会议室都被占用,第四场会议延期举办。
|
||||
- 在时间 5 ,会议室 1 的会议结束。第三场会议在会议室 1 举办,时间周期为 [5,10) 。
|
||||
- 在时间 10 ,两个会议室的会议都结束。第四场会议在会议室 0 举办,时间周期为 [10,11) 。
|
||||
会议室 0 和会议室 1 都举办了 2 场会议,所以返回 0 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>n = 3, meetings = [[1,20],[2,10],[3,5],[4,9],[6,8]]
|
||||
<strong>输出:</strong>1
|
||||
<strong>解释:</strong>
|
||||
- 在时间 1 ,所有三个会议室都未占用,第一场会议在会议室 0 举办。
|
||||
- 在时间 2 ,会议室 1 和 2 未占用,第二场会议在会议室 1 举办。
|
||||
- 在时间 3 ,只有会议室 2 未占用,第三场会议在会议室 2 举办。
|
||||
- 在时间 4 ,所有三个会议室都被占用,第四场会议延期举办。
|
||||
- 在时间 5 ,会议室 2 的会议结束。第四场会议在会议室 2 举办,时间周期为 [5,10) 。
|
||||
- 在时间 6 ,所有三个会议室都被占用,第五场会议延期举办。
|
||||
- 在时间 10 ,会议室 1 和 2 的会议结束。第五场会议在会议室 1 举办,时间周期为 [10,12) 。
|
||||
会议室 1 和会议室 2 都举办了 2 场会议,所以返回 1 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</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><code>start<sub>i</sub></code> 的所有值 <strong>互不相同</strong></li>
|
||||
</ul>
|
@ -0,0 +1,33 @@
|
||||
<p>给你两个 <strong>正</strong> 整数 <code>startPos</code> 和 <code>endPos</code> 。最初,你站在 <strong>无限</strong> 数轴上位置 <code>startPos</code> 处。在一步移动中,你可以向左或者向右移动一个位置。</p>
|
||||
|
||||
<p>给你一个正整数 <code>k</code> ,返回从 <code>startPos</code> 出发、<strong>恰好</strong> 移动 <code>k</code> 步并到达 <code>endPos</code> 的 <strong>不同</strong> 方法数目。由于答案可能会很大,返回对 <code>10<sup>9</sup> + 7</code> <strong>取余</strong> 的结果。</p>
|
||||
|
||||
<p>如果所执行移动的顺序不完全相同,则认为两种方法不同。</p>
|
||||
|
||||
<p><strong>注意:</strong>数轴包含负整数<strong>。</strong></p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>startPos = 1, endPos = 2, k = 3
|
||||
<strong>输出:</strong>3
|
||||
<strong>解释:</strong>存在 3 种从 1 到 2 且恰好移动 3 步的方法:
|
||||
- 1 -> 2 -> 3 -> 2.
|
||||
- 1 -> 2 -> 1 -> 2.
|
||||
- 1 -> 0 -> 1 -> 2.
|
||||
可以证明不存在其他方法,所以返回 3 。</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>startPos = 2, endPos = 5, k = 10
|
||||
<strong>输出:</strong>0
|
||||
<strong>解释:</strong>不存在从 2 到 5 且恰好移动 10 步的方法。</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= startPos, endPos, k <= 1000</code></li>
|
||||
</ul>
|
@ -0,0 +1,37 @@
|
||||
<p>给你一个由 <strong>正</strong> 整数组成的数组 <code>nums</code> 。</p>
|
||||
|
||||
<p>如果 <code>nums</code> 的子数组中位于 <strong>不同</strong> 位置的每对元素按位 <strong>与(AND)</strong>运算的结果等于 <code>0</code> ,则称该子数组为 <strong>优雅</strong> 子数组。</p>
|
||||
|
||||
<p>返回 <strong>最长</strong> 的优雅子数组的长度。</p>
|
||||
|
||||
<p><strong>子数组</strong> 是数组中的一个 <strong>连续</strong> 部分。</p>
|
||||
|
||||
<p><strong>注意:</strong>长度为 <code>1</code> 的子数组始终视作优雅子数组。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>nums = [1,3,8,48,10]
|
||||
<strong>输出:</strong>3
|
||||
<strong>解释:</strong>最长的优雅子数组是 [3,8,48] 。子数组满足题目条件:
|
||||
- 3 AND 8 = 0
|
||||
- 3 AND 48 = 0
|
||||
- 8 AND 48 = 0
|
||||
可以证明不存在更长的优雅子数组,所以返回 3 。</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>nums = [3,1,5,11,13]
|
||||
<strong>输出:</strong>1
|
||||
<strong>解释:</strong>最长的优雅子数组长度为 1 ,任何长度为 1 的子数组都满足题目条件。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</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>
|
@ -0,0 +1,42 @@
|
||||
<p>给你一个下标从 <strong>0</strong> 开始的字符串 <code>s</code> ,该字符串仅由小写英文字母组成,<code>s</code> 中的每个字母都 <strong>恰好</strong> 出现 <strong>两次</strong> 。另给你一个下标从 <strong>0</strong> 开始、长度为 <code>26</code> 的的整数数组 <code>distance</code> 。</p>
|
||||
|
||||
<p>字母表中的每个字母按从 <code>0</code> 到 <code>25</code> 依次编号(即,<code>'a' -> 0</code>, <code>'b' -> 1</code>, <code>'c' -> 2</code>, ... , <code>'z' -> 25</code>)。</p>
|
||||
|
||||
<p>在一个 <strong>匀整</strong> 字符串中,第 <code>i</code> 个字母的两次出现之间的字母数量是 <code>distance[i]</code> 。如果第 <code>i</code> 个字母没有在 <code>s</code> 中出现,那么 <code>distance[i]</code> 可以 <strong>忽略</strong> 。</p>
|
||||
|
||||
<p>如果 <code>s</code> 是一个 <strong>匀整</strong> 字符串,返回 <code>true</code> ;否则,返回 <code>false</code> 。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>s = "abaccb", distance = [1,3,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
|
||||
<strong>输出:</strong>true
|
||||
<strong>解释:</strong>
|
||||
- 'a' 在下标 0 和下标 2 处出现,所以满足 distance[0] = 1 。
|
||||
- 'b' 在下标 1 和下标 5 处出现,所以满足 distance[1] = 3 。
|
||||
- 'c' 在下标 3 和下标 4 处出现,所以满足 distance[2] = 0 。
|
||||
注意 distance[3] = 5 ,但是由于 'd' 没有在 s 中出现,可以忽略。
|
||||
因为 s 是一个匀整字符串,返回 true 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>s = "aa", distance = [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
|
||||
<strong>输出:</strong>false
|
||||
<strong>解释:</strong>
|
||||
- 'a' 在下标 0 和 1 处出现,所以两次出现之间的字母数量为 0 。
|
||||
但是 distance[0] = 1 ,s 不是一个匀整字符串。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= s.length <= 52</code></li>
|
||||
<li><code>s</code> 仅由小写英文字母组成</li>
|
||||
<li><code>s</code> 中的每个字母恰好出现两次</li>
|
||||
<li><code>distance.length == 26</code></li>
|
||||
<li><code>0 <= distance[i] <= 50</code></li>
|
||||
</ul>
|
@ -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>
|
@ -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>
|
@ -0,0 +1,42 @@
|
||||
<p>You are given a <strong>0-indexed</strong> string <code>s</code> consisting of only lowercase English letters, where each letter in <code>s</code> appears <strong>exactly</strong> <strong>twice</strong>. You are also given a <strong>0-indexed</strong> integer array <code>distance</code> of length <code>26</code>.</p>
|
||||
|
||||
<p>Each letter in the alphabet is numbered from <code>0</code> to <code>25</code> (i.e. <code>'a' -> 0</code>, <code>'b' -> 1</code>, <code>'c' -> 2</code>, ... , <code>'z' -> 25</code>).</p>
|
||||
|
||||
<p>In a <strong>well-spaced</strong> string, the number of letters between the two occurrences of the <code>i<sup>th</sup></code> letter is <code>distance[i]</code>. If the <code>i<sup>th</sup></code> letter does not appear in <code>s</code>, then <code>distance[i]</code> can be <strong>ignored</strong>.</p>
|
||||
|
||||
<p>Return <code>true</code><em> if </em><code>s</code><em> is a <strong>well-spaced</strong> string, otherwise return </em><code>false</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "abaccb", distance = [1,3,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong>
|
||||
- 'a' appears at indices 0 and 2 so it satisfies distance[0] = 1.
|
||||
- 'b' appears at indices 1 and 5 so it satisfies distance[1] = 3.
|
||||
- 'c' appears at indices 3 and 4 so it satisfies distance[2] = 0.
|
||||
Note that distance[3] = 5, but since 'd' does not appear in s, it can be ignored.
|
||||
Return true because s is a well-spaced string.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "aa", distance = [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation:</strong>
|
||||
- 'a' appears at indices 0 and 1 so there are zero letters between them.
|
||||
Because distance[0] = 1, s is not a well-spaced string.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= s.length <= 52</code></li>
|
||||
<li><code>s</code> consists only of lowercase English letters.</li>
|
||||
<li>Each letter appears in <code>s</code> exactly twice.</li>
|
||||
<li><code>distance.length == 26</code></li>
|
||||
<li><code>0 <= distance[i] <= 50</code></li>
|
||||
</ul>
|
250
leetcode.py
250
leetcode.py
@ -1,126 +1,126 @@
|
||||
# coding:utf-8
|
||||
import re
|
||||
import json
|
||||
import os
|
||||
import threading
|
||||
import time
|
||||
import requests
|
||||
from requests.exceptions import RequestException
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
def get_proble_set(url):
|
||||
try:
|
||||
response = requests.get(url, headers = {
|
||||
'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.41 Safari/537.36 Edg/101.0.1210.32"
|
||||
})
|
||||
if response.status_code == 200:
|
||||
return response.text
|
||||
return None
|
||||
except RequestException:
|
||||
return None
|
||||
|
||||
def parse_proble_set(problemSet):
|
||||
# print(len(problemSet)) # 2218
|
||||
for i in range(len(problemSet)):
|
||||
# for i in range(930, len(problemSet)):
|
||||
title = problemSet[i]["stat"]["question__title_slug"]
|
||||
if os.path.exists("originData/[no content]{}.json".format(title)) or os.path.exists("originData/{}.json".format(title)):
|
||||
print(i, "has been parsed.")
|
||||
# print("The question has been parsed: {}".format(title))
|
||||
continue
|
||||
#construct_url(title)
|
||||
# time.sleep(0.5)
|
||||
time.sleep(1)
|
||||
t =threading.Thread(target=construct_url,args=(title,))
|
||||
t.start()
|
||||
print(i, "is done.")
|
||||
continue
|
||||
|
||||
def construct_url(problemTitle):
|
||||
url = "https://leetcode.com/problems/"+ problemTitle + "/description/"
|
||||
# print(url)
|
||||
get_proble_content(url,problemTitle)
|
||||
|
||||
def save_problem(title,content):
|
||||
#content = bytes(content,encoding = 'utf8')
|
||||
filename = title + ".html"
|
||||
with open(filename,'w+',encoding="utf-8")as f:
|
||||
f.write(content)
|
||||
|
||||
def get_proble_content(problemUrl,title):
|
||||
response = requests.get(problemUrl, headers = {
|
||||
'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.67 Safari/537.36"
|
||||
})
|
||||
setCookie = response.headers["Set-Cookie"]
|
||||
'''
|
||||
print(setCookie)
|
||||
setCookie = json.loads(setCookie)
|
||||
print(type(setCookie))
|
||||
'''
|
||||
try:
|
||||
pattern = re.compile("csrftoken=(.*?);.*?",re.S)
|
||||
csrftoken = re.search(pattern, setCookie)
|
||||
url = "https://leetcode.com/graphql"
|
||||
data = {
|
||||
#"operationName":"getQuestionDetail",
|
||||
"operationName":"questionData",
|
||||
"variables":{"titleSlug":title},
|
||||
# "query":"query getQuestionDetail($titleSlug: String!) {\n isCurrentUserAuthenticated\n question(titleSlug: $titleSlug) {\n questionId\n questionFrontendId\n questionTitle\n translatedTitle\n questionTitleSlug\n content\n translatedContent\n difficulty\n stats\n allowDiscuss\n contributors\n similarQuestions\n mysqlSchemas\n randomQuestionUrl\n sessionId\n categoryTitle\n submitUrl\n interpretUrl\n codeDefinition\n sampleTestCase\n enableTestMode\n metaData\n enableRunCode\n enableSubmit\n judgerAvailable\n infoVerified\n envInfo\n urlManager\n article\n questionDetailUrl\n libraryUrl\n companyTags {\n name\n slug\n translatedName\n __typename\n }\n companyTagStats\n topicTags {\n name\n slug\n translatedName\n __typename\n }\n __typename\n }\n interviewed {\n interviewedUrl\n companies {\n id\n name\n slug\n __typename\n }\n timeOptions {\n id\n name\n __typename\n }\n stageOptions {\n id\n name\n __typename\n }\n __typename\n }\n subscribeUrl\n isPremium\n loginUrl\n}\n"
|
||||
"query": "query questionData($titleSlug: String!) {\n question(titleSlug: $titleSlug) {\n questionId\n questionFrontendId\n boundTopicId\n title\n titleSlug\n content\n translatedTitle\n translatedContent\n isPaidOnly\n difficulty\n likes\n dislikes\n isLiked\n similarQuestions\n exampleTestcases\n categoryTitle\n contributors {\n username\n profileUrl\n avatarUrl\n __typename\n }\n topicTags {\n name\n slug\n translatedName\n __typename\n }\n companyTagStats\n codeSnippets {\n lang\n langSlug\n code\n __typename\n }\n stats\n hints\n solution {\n id\n canSeeDetail\n paidOnly\n hasVideoSolution\n paidOnlyVideo\n __typename\n }\n status\n sampleTestCase\n metaData\n judgerAvailable\n judgeType\n mysqlSchemas\n enableRunCode\n enableTestMode\n enableDebugger\n envInfo\n libraryUrl\n adminUrl\n challengeQuestion {\n id\n date\n incompleteChallengeCount\n streakCount\n type\n __typename\n }\n __typename\n }\n}\n"
|
||||
}
|
||||
headers = {
|
||||
'x-csrftoken': csrftoken.group(1),
|
||||
'referer':problemUrl,
|
||||
'content-type':'application/json',
|
||||
'origin':'https://leetcode.com',
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36'
|
||||
}
|
||||
cookies = {
|
||||
'__cfduid':'d9ce37537c705e759f6bea15fffc9c58b1525271602',
|
||||
'_ga':'GA1.2.5783653.1525271604',
|
||||
'_gid':'GA1.2.344320119.1533189808',
|
||||
'csrftoken':csrftoken.group(1),
|
||||
' _gat':'1'
|
||||
}
|
||||
#payload表单为json格式
|
||||
|
||||
dumpJsonData = json.dumps(data)
|
||||
response = requests.post(url,data = dumpJsonData, headers = headers,cookies = cookies)
|
||||
dictInfo = json.loads(response.text)
|
||||
if dictInfo["data"]["question"].get("content") is not None:
|
||||
saveJSON(dictInfo, "originData/" + title + ".json")
|
||||
content = dictInfo["data"]["question"]["content"]
|
||||
save_problem("problem/" + title, content)
|
||||
# soup = BeautifulSoup(content, 'lxml')
|
||||
# save_problem(title,soup.prettify())
|
||||
else:
|
||||
saveJSON(dictInfo, "originData/[no content]" + title + ".json")
|
||||
# print("no content")
|
||||
except Exception as e:
|
||||
print("[error] ", e, problemUrl)
|
||||
|
||||
def saveJSON(data, filename):
|
||||
with open(filename, 'w', encoding='utf-8') as f:
|
||||
json.dump(data, f, ensure_ascii=False, indent=4)
|
||||
|
||||
def main():
|
||||
url = "https://leetcode.com/api/problems/all/"
|
||||
html = json.loads(get_proble_set(url))
|
||||
saveJSON(html, "origin-data.json")
|
||||
|
||||
# html = json.load(open("origin-data.json", 'r', encoding='utf-8'))
|
||||
|
||||
problemset = html["stat_status_pairs"]
|
||||
parse_proble_set(problemset)
|
||||
|
||||
|
||||
if __name__=='__main__':
|
||||
folderName = "leetcode"
|
||||
if not os.path.exists(folderName):
|
||||
os.mkdir(folderName)
|
||||
if not os.path.exists(folderName + "/originData"):
|
||||
os.mkdir(folderName + "/originData")
|
||||
if not os.path.exists(folderName + "/problem"):
|
||||
os.mkdir(folderName + "/problem")
|
||||
os.chdir(folderName)
|
||||
# coding:utf-8
|
||||
import re
|
||||
import json
|
||||
import os
|
||||
import threading
|
||||
import time
|
||||
import requests
|
||||
from requests.exceptions import RequestException
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
def get_proble_set(url):
|
||||
try:
|
||||
response = requests.get(url, headers = {
|
||||
'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.41 Safari/537.36 Edg/101.0.1210.32"
|
||||
}, verify=False)
|
||||
if response.status_code == 200:
|
||||
return response.text
|
||||
return None
|
||||
except RequestException:
|
||||
return None
|
||||
|
||||
def parse_proble_set(problemSet):
|
||||
# print(len(problemSet)) # 2218
|
||||
for i in range(len(problemSet)):
|
||||
# for i in range(930, len(problemSet)):
|
||||
title = problemSet[i]["stat"]["question__title_slug"]
|
||||
if os.path.exists("originData/[no content]{}.json".format(title)) or os.path.exists("originData/{}.json".format(title)):
|
||||
print(i, "has been parsed.")
|
||||
# print("The question has been parsed: {}".format(title))
|
||||
continue
|
||||
#construct_url(title)
|
||||
# time.sleep(0.5)
|
||||
time.sleep(1)
|
||||
t =threading.Thread(target=construct_url,args=(title,))
|
||||
t.start()
|
||||
print(i, "is done.")
|
||||
continue
|
||||
|
||||
def construct_url(problemTitle):
|
||||
url = "https://leetcode.com/problems/"+ problemTitle + "/description/"
|
||||
# print(url)
|
||||
get_proble_content(url,problemTitle)
|
||||
|
||||
def save_problem(title,content):
|
||||
#content = bytes(content,encoding = 'utf8')
|
||||
filename = title + ".html"
|
||||
with open(filename,'w+',encoding="utf-8")as f:
|
||||
f.write(content)
|
||||
|
||||
def get_proble_content(problemUrl,title):
|
||||
response = requests.get(problemUrl, headers = {
|
||||
'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.67 Safari/537.36"
|
||||
})
|
||||
setCookie = response.headers["Set-Cookie"]
|
||||
'''
|
||||
print(setCookie)
|
||||
setCookie = json.loads(setCookie)
|
||||
print(type(setCookie))
|
||||
'''
|
||||
try:
|
||||
pattern = re.compile("csrftoken=(.*?);.*?",re.S)
|
||||
csrftoken = re.search(pattern, setCookie)
|
||||
url = "https://leetcode.com/graphql"
|
||||
data = {
|
||||
#"operationName":"getQuestionDetail",
|
||||
"operationName":"questionData",
|
||||
"variables":{"titleSlug":title},
|
||||
# "query":"query getQuestionDetail($titleSlug: String!) {\n isCurrentUserAuthenticated\n question(titleSlug: $titleSlug) {\n questionId\n questionFrontendId\n questionTitle\n translatedTitle\n questionTitleSlug\n content\n translatedContent\n difficulty\n stats\n allowDiscuss\n contributors\n similarQuestions\n mysqlSchemas\n randomQuestionUrl\n sessionId\n categoryTitle\n submitUrl\n interpretUrl\n codeDefinition\n sampleTestCase\n enableTestMode\n metaData\n enableRunCode\n enableSubmit\n judgerAvailable\n infoVerified\n envInfo\n urlManager\n article\n questionDetailUrl\n libraryUrl\n companyTags {\n name\n slug\n translatedName\n __typename\n }\n companyTagStats\n topicTags {\n name\n slug\n translatedName\n __typename\n }\n __typename\n }\n interviewed {\n interviewedUrl\n companies {\n id\n name\n slug\n __typename\n }\n timeOptions {\n id\n name\n __typename\n }\n stageOptions {\n id\n name\n __typename\n }\n __typename\n }\n subscribeUrl\n isPremium\n loginUrl\n}\n"
|
||||
"query": "query questionData($titleSlug: String!) {\n question(titleSlug: $titleSlug) {\n questionId\n questionFrontendId\n boundTopicId\n title\n titleSlug\n content\n translatedTitle\n translatedContent\n isPaidOnly\n difficulty\n likes\n dislikes\n isLiked\n similarQuestions\n exampleTestcases\n categoryTitle\n contributors {\n username\n profileUrl\n avatarUrl\n __typename\n }\n topicTags {\n name\n slug\n translatedName\n __typename\n }\n companyTagStats\n codeSnippets {\n lang\n langSlug\n code\n __typename\n }\n stats\n hints\n solution {\n id\n canSeeDetail\n paidOnly\n hasVideoSolution\n paidOnlyVideo\n __typename\n }\n status\n sampleTestCase\n metaData\n judgerAvailable\n judgeType\n mysqlSchemas\n enableRunCode\n enableTestMode\n enableDebugger\n envInfo\n libraryUrl\n adminUrl\n challengeQuestion {\n id\n date\n incompleteChallengeCount\n streakCount\n type\n __typename\n }\n __typename\n }\n}\n"
|
||||
}
|
||||
headers = {
|
||||
'x-csrftoken': csrftoken.group(1),
|
||||
'referer':problemUrl,
|
||||
'content-type':'application/json',
|
||||
'origin':'https://leetcode.com',
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36'
|
||||
}
|
||||
cookies = {
|
||||
'__cfduid':'d9ce37537c705e759f6bea15fffc9c58b1525271602',
|
||||
'_ga':'GA1.2.5783653.1525271604',
|
||||
'_gid':'GA1.2.344320119.1533189808',
|
||||
'csrftoken':csrftoken.group(1),
|
||||
' _gat':'1'
|
||||
}
|
||||
#payload表单为json格式
|
||||
|
||||
dumpJsonData = json.dumps(data)
|
||||
response = requests.post(url,data = dumpJsonData, headers = headers,cookies = cookies)
|
||||
dictInfo = json.loads(response.text)
|
||||
if dictInfo["data"]["question"].get("content") is not None:
|
||||
saveJSON(dictInfo, "originData/" + title + ".json")
|
||||
content = dictInfo["data"]["question"]["content"]
|
||||
save_problem("problem/" + title, content)
|
||||
# soup = BeautifulSoup(content, 'lxml')
|
||||
# save_problem(title,soup.prettify())
|
||||
else:
|
||||
saveJSON(dictInfo, "originData/[no content]" + title + ".json")
|
||||
# print("no content")
|
||||
except Exception as e:
|
||||
print("[error] ", e, problemUrl)
|
||||
|
||||
def saveJSON(data, filename):
|
||||
with open(filename, 'w', encoding='utf-8') as f:
|
||||
json.dump(data, f, ensure_ascii=False, indent=4)
|
||||
|
||||
def main():
|
||||
url = "https://leetcode.com/api/problems/all/"
|
||||
html = json.loads(get_proble_set(url))
|
||||
saveJSON(html, "origin-data.json")
|
||||
|
||||
# html = json.load(open("origin-data.json", 'r', encoding='utf-8'))
|
||||
|
||||
problemset = html["stat_status_pairs"]
|
||||
parse_proble_set(problemset)
|
||||
|
||||
|
||||
if __name__=='__main__':
|
||||
folderName = "leetcode"
|
||||
if not os.path.exists(folderName):
|
||||
os.mkdir(folderName)
|
||||
if not os.path.exists(folderName + "/originData"):
|
||||
os.mkdir(folderName + "/originData")
|
||||
if not os.path.exists(folderName + "/problem"):
|
||||
os.mkdir(folderName + "/problem")
|
||||
os.chdir(folderName)
|
||||
main()
|
180
leetcode/originData/check-distances-between-same-letters.json
Normal file
180
leetcode/originData/check-distances-between-same-letters.json
Normal file
File diff suppressed because one or more lines are too long
178
leetcode/originData/coin-change-ii.json
Normal file
178
leetcode/originData/coin-change-ii.json
Normal file
File diff suppressed because one or more lines are too long
174
leetcode/originData/find-subarrays-with-equal-sum.json
Normal file
174
leetcode/originData/find-subarrays-with-equal-sum.json
Normal file
File diff suppressed because one or more lines are too long
199
leetcode/originData/maximum-number-of-robots-within-budget.json
Normal file
199
leetcode/originData/maximum-number-of-robots-within-budget.json
Normal file
File diff suppressed because one or more lines are too long
42
leetcode/problem/check-distances-between-same-letters.html
Normal file
42
leetcode/problem/check-distances-between-same-letters.html
Normal file
@ -0,0 +1,42 @@
|
||||
<p>You are given a <strong>0-indexed</strong> string <code>s</code> consisting of only lowercase English letters, where each letter in <code>s</code> appears <strong>exactly</strong> <strong>twice</strong>. You are also given a <strong>0-indexed</strong> integer array <code>distance</code> of length <code>26</code>.</p>
|
||||
|
||||
<p>Each letter in the alphabet is numbered from <code>0</code> to <code>25</code> (i.e. <code>'a' -> 0</code>, <code>'b' -> 1</code>, <code>'c' -> 2</code>, ... , <code>'z' -> 25</code>).</p>
|
||||
|
||||
<p>In a <strong>well-spaced</strong> string, the number of letters between the two occurrences of the <code>i<sup>th</sup></code> letter is <code>distance[i]</code>. If the <code>i<sup>th</sup></code> letter does not appear in <code>s</code>, then <code>distance[i]</code> can be <strong>ignored</strong>.</p>
|
||||
|
||||
<p>Return <code>true</code><em> if </em><code>s</code><em> is a <strong>well-spaced</strong> string, otherwise return </em><code>false</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "abaccb", distance = [1,3,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong>
|
||||
- 'a' appears at indices 0 and 2 so it satisfies distance[0] = 1.
|
||||
- 'b' appears at indices 1 and 5 so it satisfies distance[1] = 3.
|
||||
- 'c' appears at indices 3 and 4 so it satisfies distance[2] = 0.
|
||||
Note that distance[3] = 5, but since 'd' does not appear in s, it can be ignored.
|
||||
Return true because s is a well-spaced string.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "aa", distance = [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation:</strong>
|
||||
- 'a' appears at indices 0 and 1 so there are zero letters between them.
|
||||
Because distance[0] = 1, s is not a well-spaced string.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= s.length <= 52</code></li>
|
||||
<li><code>s</code> consists only of lowercase English letters.</li>
|
||||
<li>Each letter appears in <code>s</code> exactly twice.</li>
|
||||
<li><code>distance.length == 26</code></li>
|
||||
<li><code>0 <= distance[i] <= 50</code></li>
|
||||
</ul>
|
45
leetcode/problem/coin-change-ii.html
Normal file
45
leetcode/problem/coin-change-ii.html
Normal file
@ -0,0 +1,45 @@
|
||||
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
|
||||
|
||||
<p>Return <em>the number of combinations that make up that amount</em>. If that amount of money cannot be made up by any combination of the coins, return <code>0</code>.</p>
|
||||
|
||||
<p>You may assume that you have an infinite number of each kind of coin.</p>
|
||||
|
||||
<p>The answer is <strong>guaranteed</strong> to fit into a signed <strong>32-bit</strong> integer.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> amount = 5, coins = [1,2,5]
|
||||
<strong>Output:</strong> 4
|
||||
<strong>Explanation:</strong> there are four ways to make up the amount:
|
||||
5=5
|
||||
5=2+2+1
|
||||
5=2+1+1+1
|
||||
5=1+1+1+1+1
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> amount = 3, coins = [2]
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong> the amount of 3 cannot be made up just with coins of 2.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> amount = 10, coins = [10]
|
||||
<strong>Output:</strong> 1
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= coins.length <= 300</code></li>
|
||||
<li><code>1 <= coins[i] <= 5000</code></li>
|
||||
<li>All the values of <code>coins</code> are <strong>unique</strong>.</li>
|
||||
<li><code>0 <= amount <= 5000</code></li>
|
||||
</ul>
|
39
leetcode/problem/find-subarrays-with-equal-sum.html
Normal file
39
leetcode/problem/find-subarrays-with-equal-sum.html
Normal file
@ -0,0 +1,39 @@
|
||||
<p>Given a <strong>0-indexed</strong> integer array <code>nums</code>, determine whether there exist <strong>two</strong> subarrays of length <code>2</code> with <strong>equal</strong> sum. Note that the two subarrays must begin at <strong>different</strong> indices.</p>
|
||||
|
||||
<p>Return <code>true</code><em> if these subarrays exist, and </em><code>false</code><em> otherwise.</em></p>
|
||||
|
||||
<p>A <b>subarray</b> is a contiguous non-empty sequence of elements within an array.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [4,2,4]
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong> The subarrays with elements [4,2] and [2,4] have the same sum of 6.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,2,3,4,5]
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation:</strong> No two subarrays of size 2 have the same sum.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [0,0,0]
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong> The subarrays [nums[0],nums[1]] and [nums[1],nums[2]] have the same sum of 0.
|
||||
Note that even though the subarrays have the same content, the two subarrays are considered different because they are in different positions in the original array.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= nums.length <= 1000</code></li>
|
||||
<li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
35
leetcode/problem/maximum-number-of-robots-within-budget.html
Normal file
35
leetcode/problem/maximum-number-of-robots-within-budget.html
Normal file
@ -0,0 +1,35 @@
|
||||
<p>You have <code>n</code> robots. You are given two <strong>0-indexed</strong> integer arrays, <code>chargeTimes</code> and <code>runningCosts</code>, both of length <code>n</code>. The <code>i<sup>th</sup></code> robot costs <code>chargeTimes[i]</code> units to charge and costs <code>runningCosts[i]</code> units to run. You are also given an integer <code>budget</code>.</p>
|
||||
|
||||
<p>The <strong>total cost</strong> of running <code>k</code> chosen robots is equal to <code>max(chargeTimes) + k * sum(runningCosts)</code>, where <code>max(chargeTimes)</code> is the largest charge cost among the <code>k</code> robots and <code>sum(runningCosts)</code> is the sum of running costs among the <code>k</code> robots.</p>
|
||||
|
||||
<p>Return<em> the <strong>maximum</strong> number of <strong>consecutive</strong> robots you can run such that the total cost <strong>does not</strong> exceed </em><code>budget</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> chargeTimes = [3,6,1,3,4], runningCosts = [2,1,3,4,5], budget = 25
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong>
|
||||
It is possible to run all individual and consecutive pairs of robots within budget.
|
||||
To obtain answer 3, consider the first 3 robots. The total cost will be max(3,6,1) + 3 * sum(2,1,3) = 6 + 3 * 6 = 24 which is less than 25.
|
||||
It can be shown that it is not possible to run more than 3 consecutive robots within budget, so we return 3.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> chargeTimes = [11,12,19], runningCosts = [10,8,7], budget = 19
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong> No robot can be run that does not exceed the budget, so we return 0.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>chargeTimes.length == runningCosts.length == n</code></li>
|
||||
<li><code>1 <= n <= 5 * 10<sup>4</sup></code></li>
|
||||
<li><code>1 <= chargeTimes[i], runningCosts[i] <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= budget <= 10<sup>15</sup></code></li>
|
||||
</ul>
|
Loading…
Reference in New Issue
Block a user