mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-04-18 08:39:41 +08:00
update
This commit is contained in:
parent
d928fedff8
commit
e9f28d863c
README.md
leetcode-cn
origin-data.json
originData
[no content]count-strictly-increasing-subarrays.json[no content]employees-with-deductions.json[no content]median-of-a-row-wise-sorted-matrix.jsonfind-subarrays-with-equal-sum.jsonfind-the-index-of-the-first-occurrence-in-a-string.jsonmaximum-number-of-robots-within-budget.jsonmaximum-rows-covered-by-columns.jsonstrictly-palindromic-number.json
problem (Chinese)
严格回文的数字 [strictly-palindromic-number].html和相等的子数组 [find-subarrays-with-equal-sum].html实现 strStr() [find-the-index-of-the-first-occurrence-in-a-string].html被列覆盖的最多行数 [maximum-rows-covered-by-columns].html预算内的最多机器人数目 [maximum-number-of-robots-within-budget].html
problem (English)
严格回文的数字(English) [strictly-palindromic-number].html和相等的子数组(English) [find-subarrays-with-equal-sum].html实现 strStr()(English) [find-the-index-of-the-first-occurrence-in-a-string].html被列覆盖的最多行数(English) [maximum-rows-covered-by-columns].html预算内的最多机器人数目(English) [maximum-number-of-robots-within-budget].html
leetcode
@ -1,6 +1,6 @@
|
||||
# 力扣题库(完整版)
|
||||
|
||||
> 最后更新日期: **2022.08.29**
|
||||
> 最后更新日期: **2022.09.04**
|
||||
>
|
||||
> 使用脚本前请务必仔细完整阅读本 `README.md` 文件
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@ -0,0 +1,58 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2534",
|
||||
"questionFrontendId": "2394",
|
||||
"categoryTitle": "Database",
|
||||
"boundTopicId": 1795924,
|
||||
"title": "Employees With Deductions",
|
||||
"titleSlug": "employees-with-deductions",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Medium",
|
||||
"likes": 0,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"contributors": [],
|
||||
"langToValidPlayground": null,
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"12\", \"totalSubmission\": \"15\", \"totalAcceptedRaw\": 12, \"totalSubmissionRaw\": 15, \"acRate\": \"80.0%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\": {\"Employees\": [\"employee_id\", \"needed_hours\"], \"Logs\": [\"employee_id\", \"in_time\", \"out_time\"]}, \"rows\": {\"Employees\": [[1, 20], [2, 12], [3, 2]], \"Logs\": [[1, \"2022-10-01 09:00:00\", \"2022-10-01 17:00:00\"],[1, \"2022-10-06 09:05:04\", \"2022-10-06 17:09:03\"], [1, \"2022-10-12 23:00:00\", \"2022-10-13 03:00:01\"], [2, \"2022-10-29 12:00:00\", \"2022-10-29 23:58:58\"]]}}",
|
||||
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Employees (employee_id int, needed_hours int)\",\n \"Create table If Not Exists Logs (employee_id int, in_time datetime, out_time datetime)\"\n ],\n \"mssql\": [\n \"Create table Employees (employee_id int, needed_hours int)\",\n \"Create table Logs (employee_id int, in_time datetime, out_time datetime)\"\n ],\n \"oraclesql\": [\n \"Create table Employees (employee_id int, needed_hours int)\",\n \"Create table Logs (employee_id int, in_time date, out_time date)\",\n \"ALTER SESSION SET nls_date_format='YYYY-MM-DD HH24:MI:SS'\"\n ],\n \"database\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Create table If Not Exists Employees (employee_id int, needed_hours int)",
|
||||
"Create table If Not Exists Logs (employee_id int, in_time datetime, out_time datetime)",
|
||||
"Truncate table Employees",
|
||||
"insert into Employees (employee_id, needed_hours) values ('1', '20')",
|
||||
"insert into Employees (employee_id, needed_hours) values ('2', '12')",
|
||||
"insert into Employees (employee_id, needed_hours) values ('3', '2')",
|
||||
"Truncate table Logs",
|
||||
"insert into Logs (employee_id, in_time, out_time) values ('1', '2022-10-01 09:00:00', '2022-10-01 17:00:00')",
|
||||
"insert into Logs (employee_id, in_time, out_time) values ('1', '2022-10-06 09:05:04', '2022-10-06 17:09:03')",
|
||||
"insert into Logs (employee_id, in_time, out_time) values ('1', '2022-10-12 23:00:00', '2022-10-13 03:00:01')",
|
||||
"insert into Logs (employee_id, in_time, out_time) values ('2', '2022-10-29 12:00:00', '2022-10-29 23:58:58')"
|
||||
],
|
||||
"enableRunCode": true,
|
||||
"envInfo": "{\"mysql\":[\"MySQL\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"]}",
|
||||
"book": null,
|
||||
"isSubscribed": false,
|
||||
"isDailyQuestion": false,
|
||||
"dailyRecordStatus": null,
|
||||
"editorType": "CKEDITOR",
|
||||
"ugcQuestionId": null,
|
||||
"style": "LEETCODE",
|
||||
"exampleTestcases": "{\"headers\": {\"Employees\": [\"employee_id\", \"needed_hours\"], \"Logs\": [\"employee_id\", \"in_time\", \"out_time\"]}, \"rows\": {\"Employees\": [[1, 20], [2, 12], [3, 2]], \"Logs\": [[1, \"2022-10-01 09:00:00\", \"2022-10-01 17:00:00\"],[1, \"2022-10-06 09:05:04\", \"2022-10-06 17:09:03\"], [1, \"2022-10-12 23:00:00\", \"2022-10-13 03:00:01\"], [2, \"2022-10-29 12:00:00\", \"2022-10-29 23:58:58\"]]}}",
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
164
leetcode-cn/originData/find-subarrays-with-equal-sum.json
Normal file
164
leetcode-cn/originData/find-subarrays-with-equal-sum.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
165
leetcode-cn/originData/maximum-rows-covered-by-columns.json
Normal file
165
leetcode-cn/originData/maximum-rows-covered-by-columns.json
Normal file
File diff suppressed because one or more lines are too long
164
leetcode-cn/originData/strictly-palindromic-number.json
Normal file
164
leetcode-cn/originData/strictly-palindromic-number.json
Normal file
File diff suppressed because one or more lines are too long
@ -0,0 +1,33 @@
|
||||
<p>如果一个整数 <code>n</code> 在 <code>b</code> 进制下(<code>b</code> 为 <code>2</code> 到 <code>n - 2</code> 之间的所有整数)对应的字符串 <strong>全部</strong> 都是 <strong>回文的</strong> ,那么我们称这个数 <code>n</code> 是 <strong>严格回文</strong> 的。</p>
|
||||
|
||||
<p>给你一个整数 <code>n</code> ,如果 <code>n</code> 是 <strong>严格回文</strong> 的,请返回 <code>true</code> ,否则返回<em> </em><code>false</code> 。</p>
|
||||
|
||||
<p>如果一个字符串从前往后读和从后往前读完全相同,那么这个字符串是 <strong>回文的</strong> 。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>n = 9
|
||||
<b>输出:</b>false
|
||||
<b>解释:</b>在 2 进制下:9 = 1001 ,是回文的。
|
||||
在 3 进制下:9 = 100 ,不是回文的。
|
||||
所以,9 不是严格回文数字,我们返回 false 。
|
||||
注意在 4, 5, 6 和 7 进制下,n = 9 都不是回文的。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>n = 4
|
||||
<b>输出:</b>false
|
||||
<b>解释:</b>我们只考虑 2 进制:4 = 100 ,不是回文的。
|
||||
所以我们返回 false 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>4 <= n <= 10<sup>5</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,38 @@
|
||||
<p>给你一个下标从 <strong>0</strong> 开始的整数数组 <code>nums</code> ,判断是否存在 <strong>两个</strong> 长度为 <code>2</code> 的子数组且它们的 <strong>和</strong> 相等。注意,这两个子数组起始位置的下标必须 <strong>不相同</strong> 。</p>
|
||||
|
||||
<p>如果这样的子数组存在,请返回 <code>true</code>,否则返回 <code>false</code><em> </em>。</p>
|
||||
|
||||
<p><strong>子数组</strong> 是一个数组中一段连续非空的元素组成的序列。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>nums = [4,2,4]
|
||||
<b>输出:</b>true
|
||||
<b>解释:</b>元素为 [4,2] 和 [2,4] 的子数组有相同的和 6 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>nums = [1,2,3,4,5]
|
||||
<b>输出:</b>false
|
||||
<b>解释:</b>没有长度为 2 的两个子数组和相等。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>nums = [0,0,0]
|
||||
<b>输出:</b>true
|
||||
<b>解释:</b>子数组 [nums[0],nums[1]] 和 [nums[1],nums[2]] 的和相等,都为 0 。
|
||||
注意即使子数组的元素相同,这两个子数组也视为不相同的子数组,因为它们在原数组中的起始位置不同。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</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>
|
34
leetcode-cn/problem (Chinese)/实现 strStr() [find-the-index-of-the-first-occurrence-in-a-string].html
Normal file
34
leetcode-cn/problem (Chinese)/实现 strStr() [find-the-index-of-the-first-occurrence-in-a-string].html
Normal file
@ -0,0 +1,34 @@
|
||||
<p>实现 <a href="https://baike.baidu.com/item/strstr/811469" target="_blank">strStr()</a> 函数。</p>
|
||||
|
||||
<p>给你两个字符串 <code>haystack</code> 和 <code>needle</code> ,请你在 <code>haystack</code> 字符串中找出 <code>needle</code> 字符串出现的第一个位置(下标从 0 开始)。如果不存在,则返回 <code>-1</code><strong> </strong>。</p>
|
||||
|
||||
<p><strong>说明:</strong></p>
|
||||
|
||||
<p>当 <code>needle</code> 是空字符串时,我们应当返回什么值呢?这是一个在面试中很好的问题。</p>
|
||||
|
||||
<p>对于本题而言,当 <code>needle</code> 是空字符串时我们应当返回 0 。这与 C 语言的 <a href="https://baike.baidu.com/item/strstr/811469" target="_blank">strstr()</a> 以及 Java 的 <a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#indexOf(java.lang.String)" target="_blank">indexOf()</a> 定义相符。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>haystack = "hello", needle = "ll"
|
||||
<strong>输出:</strong>2
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>haystack = "aaaaa", needle = "bba"
|
||||
<strong>输出:</strong>-1
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= haystack.length, needle.length <= 10<sup>4</sup></code></li>
|
||||
<li><code>haystack</code> 和 <code>needle</code> 仅由小写英文字符组成</li>
|
||||
</ul>
|
@ -0,0 +1,41 @@
|
||||
<p>给你一个下标从 <strong>0</strong> 开始的 <code>m x n</code> 二进制矩阵 <code>mat</code> 和一个整数 <code>cols</code> ,表示你需要选出的列数。</p>
|
||||
|
||||
<p>如果一行中,所有的 <code>1</code> 都被你选中的列所覆盖,那么我们称这一行 <strong>被覆盖</strong> 了。</p>
|
||||
|
||||
<p>请你返回在选择 <code>cols</code> 列的情况下,<strong>被覆盖</strong> 的行数 <strong>最大</strong> 为多少。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2022/07/14/rowscovered.png" style="width: 250px; height: 417px;"></strong></p>
|
||||
|
||||
<pre><b>输入:</b>mat = [[0,0,0],[1,0,1],[0,1,1],[0,0,1]], cols = 2
|
||||
<b>输出:</b>3
|
||||
<strong>解释:</strong>
|
||||
如上图所示,覆盖 3 行的一种可行办法是选择第 0 和第 2 列。
|
||||
可以看出,不存在大于 3 行被覆盖的方案,所以我们返回 3 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2022/07/14/rowscovered2.png" style="width: 83px; height: 247px;"></strong></p>
|
||||
|
||||
<pre><b>输入:</b>mat = [[1],[0]], cols = 1
|
||||
<b>输出:</b>2
|
||||
<strong>解释:</strong>
|
||||
选择唯一的一列,两行都被覆盖了,原因是整个矩阵都被覆盖了。
|
||||
所以我们返回 2 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>m == mat.length</code></li>
|
||||
<li><code>n == mat[i].length</code></li>
|
||||
<li><code>1 <= m, n <= 12</code></li>
|
||||
<li><code>mat[i][j]</code> 要么是 <code>0</code> 要么是 <code>1</code> 。</li>
|
||||
<li><code>1 <= cols <= n</code></li>
|
||||
</ul>
|
37
leetcode-cn/problem (Chinese)/预算内的最多机器人数目 [maximum-number-of-robots-within-budget].html
Normal file
37
leetcode-cn/problem (Chinese)/预算内的最多机器人数目 [maximum-number-of-robots-within-budget].html
Normal file
@ -0,0 +1,37 @@
|
||||
<p>你有 <code>n</code> 个机器人,给你两个下标从 <strong>0</strong> 开始的整数数组 <code>chargeTimes</code> 和 <code>runningCosts</code> ,两者长度都为 <code>n</code> 。第 <code>i</code> 个机器人充电时间为 <code>chargeTimes[i]</code> 单位时间,花费 <code>runningCosts[i]</code> 单位时间运行。再给你一个整数 <code>budget</code> 。</p>
|
||||
|
||||
<p>运行 <code>k</code> 个机器人 <strong>总开销</strong> 是 <code>max(chargeTimes) + k * sum(runningCosts)</code> ,其中 <code>max(chargeTimes)</code> 是这 <code>k</code> 个机器人中最大充电时间,<code>sum(runningCosts)</code> 是这 <code>k</code> 个机器人的运行时间之和。</p>
|
||||
|
||||
<p>请你返回在 <strong>不超过</strong> <code>budget</code> 的前提下,你 <strong>最多</strong> 可以 <strong>连续</strong> 运行的机器人数目为多少。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>chargeTimes = [3,6,1,3,4], runningCosts = [2,1,3,4,5], budget = 25
|
||||
<b>输出:</b>3
|
||||
<b>解释:</b>
|
||||
可以在 budget 以内运行所有单个机器人或者连续运行 2 个机器人。
|
||||
选择前 3 个机器人,可以得到答案最大值 3 。总开销是 max(3,6,1) + 3 * sum(2,1,3) = 6 + 3 * 6 = 24 ,小于 25 。
|
||||
可以看出无法在 budget 以内连续运行超过 3 个机器人,所以我们返回 3 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>chargeTimes = [11,12,19], runningCosts = [10,8,7], budget = 19
|
||||
<b>输出:</b>0
|
||||
<b>解释:</b>即使运行任何一个单个机器人,还是会超出 budget,所以我们返回 0 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</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>
|
@ -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>
|
@ -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>
|
27
leetcode-cn/problem (English)/实现 strStr()(English) [find-the-index-of-the-first-occurrence-in-a-string].html
Normal file
27
leetcode-cn/problem (English)/实现 strStr()(English) [find-the-index-of-the-first-occurrence-in-a-string].html
Normal file
@ -0,0 +1,27 @@
|
||||
<p>Given two strings <code>needle</code> and <code>haystack</code>, return the index of the first occurrence of <code>needle</code> in <code>haystack</code>, or <code>-1</code> if <code>needle</code> is not part of <code>haystack</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> haystack = "sadbutsad", needle = "sad"
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong> "sad" occurs at index 0 and 6.
|
||||
The first occurrence is at index 0, so we return 0.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> haystack = "leetcode", needle = "leeto"
|
||||
<strong>Output:</strong> -1
|
||||
<strong>Explanation:</strong> "leeto" did not occur in "leetcode", so we return -1.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= haystack.length, needle.length <= 10<sup>4</sup></code></li>
|
||||
<li><code>haystack</code> and <code>needle</code> consist of only lowercase English characters.</li>
|
||||
</ul>
|
41
leetcode-cn/problem (English)/被列覆盖的最多行数(English) [maximum-rows-covered-by-columns].html
Normal file
41
leetcode-cn/problem (English)/被列覆盖的最多行数(English) [maximum-rows-covered-by-columns].html
Normal file
@ -0,0 +1,41 @@
|
||||
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>mat</code> and an integer <code>cols</code>, which denotes the number of columns you must choose.</p>
|
||||
|
||||
<p>A row is <strong>covered</strong> by a set of columns if each cell in the row that has a value of <code>1</code> also lies in one of the columns of the chosen set.</p>
|
||||
|
||||
<p>Return <em>the <strong>maximum</strong> number of rows that can be <strong>covered</strong> by a set of </em><code>cols</code><em> columns.</em></p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2022/07/14/rowscovered.png" style="width: 250px; height: 417px;" /></strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> mat = [[0,0,0],[1,0,1],[0,1,1],[0,0,1]], cols = 2
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong>
|
||||
As shown in the diagram above, one possible way of covering 3 rows is by selecting the 0th and 2nd columns.
|
||||
It can be shown that no more than 3 rows can be covered, so we return 3.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2022/07/14/rowscovered2.png" style="width: 83px; height: 247px;" /></strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> mat = [[1],[0]], cols = 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 == mat.length</code></li>
|
||||
<li><code>n == mat[i].length</code></li>
|
||||
<li><code>1 <= m, n <= 12</code></li>
|
||||
<li><code>mat[i][j]</code> is either <code>0</code> or <code>1</code>.</li>
|
||||
<li><code>1 <= cols <= n</code></li>
|
||||
</ul>
|
35
leetcode-cn/problem (English)/预算内的最多机器人数目(English) [maximum-number-of-robots-within-budget].html
Normal file
35
leetcode-cn/problem (English)/预算内的最多机器人数目(English) [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>
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@ -0,0 +1,55 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2534",
|
||||
"questionFrontendId": "2394",
|
||||
"boundTopicId": null,
|
||||
"title": "Employees With Deductions",
|
||||
"titleSlug": "employees-with-deductions",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Medium",
|
||||
"likes": 1,
|
||||
"dislikes": 2,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"exampleTestcases": null,
|
||||
"categoryTitle": "Database",
|
||||
"contributors": [],
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"86\", \"totalSubmission\": \"108\", \"totalAcceptedRaw\": 86, \"totalSubmissionRaw\": 108, \"acRate\": \"79.6%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\": {\"Employees\": [\"employee_id\", \"needed_hours\"], \"Logs\": [\"employee_id\", \"in_time\", \"out_time\"]}, \"rows\": {\"Employees\": [[1, 20], [2, 12], [3, 2]], \"Logs\": [[1, \"2022-10-01 09:00:00\", \"2022-10-01 17:00:00\"],[1, \"2022-10-06 09:05:04\", \"2022-10-06 17:09:03\"], [1, \"2022-10-12 23:00:00\", \"2022-10-13 03:00:01\"], [2, \"2022-10-29 12:00:00\", \"2022-10-29 23:58:58\"]]}}",
|
||||
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Employees (employee_id int, needed_hours int)\",\n \"Create table If Not Exists Logs (employee_id int, in_time datetime, out_time datetime)\"\n ],\n \"mssql\": [\n \"Create table Employees (employee_id int, needed_hours int)\",\n \"Create table Logs (employee_id int, in_time datetime, out_time datetime)\"\n ],\n \"oraclesql\": [\n \"Create table Employees (employee_id int, needed_hours int)\",\n \"Create table Logs (employee_id int, in_time date, out_time date)\",\n \"ALTER SESSION SET nls_date_format='YYYY-MM-DD HH24:MI:SS'\"\n ],\n \"database\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Create table If Not Exists Employees (employee_id int, needed_hours int)",
|
||||
"Create table If Not Exists Logs (employee_id int, in_time datetime, out_time datetime)",
|
||||
"Truncate table Employees",
|
||||
"insert into Employees (employee_id, needed_hours) values ('1', '20')",
|
||||
"insert into Employees (employee_id, needed_hours) values ('2', '12')",
|
||||
"insert into Employees (employee_id, needed_hours) values ('3', '2')",
|
||||
"Truncate table Logs",
|
||||
"insert into Logs (employee_id, in_time, out_time) values ('1', '2022-10-01 09:00:00', '2022-10-01 17:00:00')",
|
||||
"insert into Logs (employee_id, in_time, out_time) values ('1', '2022-10-06 09:05:04', '2022-10-06 17:09:03')",
|
||||
"insert into Logs (employee_id, in_time, out_time) values ('1', '2022-10-12 23:00:00', '2022-10-13 03:00:01')",
|
||||
"insert into Logs (employee_id, in_time, out_time) values ('2', '2022-10-29 12:00:00', '2022-10-29 23:58:58')"
|
||||
],
|
||||
"enableRunCode": true,
|
||||
"enableTestMode": false,
|
||||
"enableDebugger": false,
|
||||
"envInfo": "{\"mysql\": [\"MySQL\", \"<p><code>MySQL 8.0</code>.</p>\"], \"mssql\": [\"MS SQL Server\", \"<p><code>mssql server 2019</code>.</p>\"], \"oraclesql\": [\"Oracle\", \"<p><code>Oracle Sql 11.2</code>.</p>\"]}",
|
||||
"libraryUrl": null,
|
||||
"adminUrl": null,
|
||||
"challengeQuestion": null,
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,27 @@
|
||||
<p>Given two strings <code>needle</code> and <code>haystack</code>, return the index of the first occurrence of <code>needle</code> in <code>haystack</code>, or <code>-1</code> if <code>needle</code> is not part of <code>haystack</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> haystack = "sadbutsad", needle = "sad"
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong> "sad" occurs at index 0 and 6.
|
||||
The first occurrence is at index 0, so we return 0.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> haystack = "leetcode", needle = "leeto"
|
||||
<strong>Output:</strong> -1
|
||||
<strong>Explanation:</strong> "leeto" did not occur in "leetcode", so we return -1.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= haystack.length, needle.length <= 10<sup>4</sup></code></li>
|
||||
<li><code>haystack</code> and <code>needle</code> consist of only lowercase English characters.</li>
|
||||
</ul>
|
Loading…
x
Reference in New Issue
Block a user