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
45399227fb
commit
59e97714b1
README.md
leetcode-cn
origin-data.json
originData
[no content]find-longest-calls.json[no content]find-the-index-of-permutation.json[no content]friday-purchase-iii.json[no content]maximum-number-of-potholes-that-can-be-fixed.json[no content]maximum-number-that-makes-result-of-bitwise-and-zero.jsoncount-the-number-of-special-characters-i.jsoncount-the-number-of-special-characters-ii.jsonfind-all-possible-stable-binary-arrays-i.jsonfind-all-possible-stable-binary-arrays-ii.jsonfind-edges-in-shortest-paths.jsonfind-the-integer-added-to-array-i.jsonfind-the-integer-added-to-array-ii.jsonfind-the-median-of-the-uniqueness-array.jsonfind-the-number-of-subarrays-where-boundary-elements-are-maximum.jsonkth-smallest-amount-with-single-denomination-combination.jsonlatest-time-you-can-obtain-after-replacing-characters.jsonmake-a-square-with-the-same-color.jsonmaximum-prime-difference.jsonminimum-array-end.jsonminimum-number-of-operations-to-satisfy-conditions.jsonminimum-rectangles-to-cover-points.jsonminimum-sum-of-values-by-dividing-array.jsonminimum-time-to-visit-disappearing-nodes.jsonright-triangles.jsonscore-of-a-string.jsonserver-utilization-time.json
problem (Chinese)
使矩阵满足条件的最少操作次数 [minimum-number-of-operations-to-satisfy-conditions].html划分数组得到最小的值之和 [minimum-sum-of-values-by-dividing-array].html单面值组合的第 K 小金额 [kth-smallest-amount-with-single-denomination-combination].html字符串的分数 [score-of-a-string].html找出与数组相加的整数 I [find-the-integer-added-to-array-i].html找出与数组相加的整数 II [find-the-integer-added-to-array-ii].html找出唯一性数组的中位数 [find-the-median-of-the-uniqueness-array].html找出所有稳定的二进制数组 I [find-all-possible-stable-binary-arrays-i].html找出所有稳定的二进制数组 II [find-all-possible-stable-binary-arrays-ii].html数组最后一个元素的最小值 [minimum-array-end].html替换字符可以得到的最晚时间 [latest-time-you-can-obtain-after-replacing-characters].html最短路径中的边 [find-edges-in-shortest-paths].html构造相同颜色的正方形 [make-a-square-with-the-same-color].html直角三角形 [right-triangles].html统计特殊字母的数量 I [count-the-number-of-special-characters-i].html统计特殊字母的数量 II [count-the-number-of-special-characters-ii].html覆盖所有点的最少矩形数目 [minimum-rectangles-to-cover-points].html访问消失节点的最少时间 [minimum-time-to-visit-disappearing-nodes].html质数的最大距离 [maximum-prime-difference].html边界元素是最大值的子数组数目 [find-the-number-of-subarrays-where-boundary-elements-are-maximum].html
problem (English)
使矩阵满足条件的最少操作次数(English) [minimum-number-of-operations-to-satisfy-conditions].html划分数组得到最小的值之和(English) [minimum-sum-of-values-by-dividing-array].html单面值组合的第 K 小金额(English) [kth-smallest-amount-with-single-denomination-combination].html字符串的分数(English) [score-of-a-string].html找出与数组相加的整数 I(English) [find-the-integer-added-to-array-i].html找出与数组相加的整数 II(English) [find-the-integer-added-to-array-ii].html找出唯一性数组的中位数(English) [find-the-median-of-the-uniqueness-array].html找出所有稳定的二进制数组 I(English) [find-all-possible-stable-binary-arrays-i].html找出所有稳定的二进制数组 II(English) [find-all-possible-stable-binary-arrays-ii].html数组最后一个元素的最小值(English) [minimum-array-end].html替换字符可以得到的最晚时间(English) [latest-time-you-can-obtain-after-replacing-characters].html最短路径中的边(English) [find-edges-in-shortest-paths].html构造相同颜色的正方形(English) [make-a-square-with-the-same-color].html直角三角形(English) [right-triangles].html统计特殊字母的数量 I(English) [count-the-number-of-special-characters-i].html统计特殊字母的数量 II(English) [count-the-number-of-special-characters-ii].html覆盖所有点的最少矩形数目(English) [minimum-rectangles-to-cover-points].html访问消失节点的最少时间(English) [minimum-time-to-visit-disappearing-nodes].html质数的最大距离(English) [maximum-prime-difference].html边界元素是最大值的子数组数目(English) [find-the-number-of-subarrays-where-boundary-elements-are-maximum].html
leetcode
origin-data.json
originData
[no content]find-longest-calls.json[no content]find-the-index-of-permutation.json[no content]friday-purchase-iii.json[no content]maximum-number-of-potholes-that-can-be-fixed.json[no content]maximum-number-that-makes-result-of-bitwise-and-zero.jsoncount-the-number-of-special-characters-i.jsoncount-the-number-of-special-characters-ii.jsondistribute-elements-into-two-arrays-i.jsonfind-all-possible-stable-binary-arrays-i.jsonfind-all-possible-stable-binary-arrays-ii.jsonfind-edges-in-shortest-paths.jsonfind-the-integer-added-to-array-i.jsonfind-the-integer-added-to-array-ii.jsonfind-the-number-of-subarrays-where-boundary-elements-are-maximum.jsonkth-smallest-amount-with-single-denomination-combination.jsonlatest-time-you-can-obtain-after-replacing-characters.jsonmake-a-square-with-the-same-color.jsonminimum-array-end.jsonminimum-number-of-operations-to-satisfy-conditions.jsonminimum-rectangles-to-cover-points.jsonminimum-sum-of-values-by-dividing-array.jsonminimum-time-to-visit-disappearing-nodes.jsonright-triangles.jsonscore-of-a-string.json
problem
@ -1,6 +1,6 @@
|
||||
# 力扣题库(完整版)
|
||||
|
||||
> 最后更新日期: **2024.04.07**
|
||||
> 最后更新日期: **2024.04.30**
|
||||
>
|
||||
> 使用脚本前请务必仔细完整阅读本 `README.md` 文件
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
73
leetcode-cn/originData/[no content]find-longest-calls.json
Normal file
73
leetcode-cn/originData/[no content]find-longest-calls.json
Normal file
@ -0,0 +1,73 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "3432",
|
||||
"questionFrontendId": "3124",
|
||||
"categoryTitle": "Database",
|
||||
"boundTopicId": 2750525,
|
||||
"title": "Find Longest Calls",
|
||||
"titleSlug": "find-longest-calls",
|
||||
"content": null,
|
||||
"translatedTitle": "查找最长的电话",
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Medium",
|
||||
"likes": 0,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"contributors": [],
|
||||
"langToValidPlayground": null,
|
||||
"topicTags": [
|
||||
{
|
||||
"name": "Database",
|
||||
"slug": "database",
|
||||
"translatedName": "数据库",
|
||||
"__typename": "TopicTagNode"
|
||||
}
|
||||
],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"50\", \"totalSubmission\": \"83\", \"totalAcceptedRaw\": 50, \"totalSubmissionRaw\": 83, \"acRate\": \"60.2%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\":{\"Contacts\":[\"id\",\"first_name\",\"last_name\"],\"Calls\":[\"contact_id\",\"type\",\"duration\"]},\"rows\":{\"Contacts\":[[1,\"John\",\"Doe\"],[2,\"Jane\",\"Smith\"],[3,\"Alice\",\"Johnson\"],[4,\"Michael\",\"Brown\"],[5,\"Emily\",\"Davis\"]],\"Calls\":[[1,\"incoming\",120],[1,\"outgoing\",180],[2,\"incoming\",300],[2,\"outgoing\",240],[3,\"incoming\",150],[3,\"outgoing\",360],[4,\"incoming\",420],[4,\"outgoing\",200],[5,\"incoming\",180],[5,\"outgoing\",280]]}}",
|
||||
"metaData": "{\"mysql\":[\"Create table if Not Exists Contacts(id int, first_name varchar(20), last_name varchar(20))\",\"Create table if Not Exists Calls(contact_id int, type ENUM('incoming', 'outgoing'), duration int)\"],\"mssql\":[\"Create table Contacts(id int, first_name varchar(20), last_name varchar(20))\",\"Create table Calls(contact_id int, type varchar(20) NOT NULL CHECK (type in ('incoming' , 'outgoing')), duration int)\"],\"oraclesql\":[\"Create table Contacts(id int, first_name varchar(20), last_name varchar(20))\",\"Create table Calls(contact_id int, type varchar(20) NOT NULL CHECK (type in ('incoming' , 'outgoing')), duration int)\"],\"database\":true,\"name\":\"find_longest_calls\",\"pythondata\":[\"Contacts = pd.DataFrame([], columns=['id', 'first_name', 'last_name']).astype({'id':'Int64', 'first_name':'object', 'last_name':'object'})\\n\",\"Calls = pd.DataFrame([], columns=['contact_id', 'type', 'duration']).astype({'contact_id': 'Int64', 'type': 'category', 'duration': 'Int64'})\\n\"],\"postgresql\":[\"CREATE TABLE Contacts (\\n id SERIAL PRIMARY KEY,\\n first_name VARCHAR(20),\\n last_name VARCHAR(20)\\n);\\n\",\"CREATE TABLE Calls (\\n contact_id INT,\\n type VARCHAR(20) NOT NULL CHECK (type IN ('incoming', 'outgoing')),\\n duration INT\\n);\\n\"],\"manual\":true,\"database_schema\":{\"Contacts\":{\"id\":\"INT\",\"first_name\":\"VARCHAR(20)\",\"last_name\":\"VARCHAR(20)\"},\"Calls\":{\"contact_id\":\"INT\",\"type\":\"ENUM('incoming', 'outgoing')\",\"duration\":\"INT\"}}}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Create table if Not Exists Contacts(id int, first_name varchar(20), last_name varchar(20))",
|
||||
"Create table if Not Exists Calls(contact_id int, type ENUM('incoming', 'outgoing'), duration int)",
|
||||
"Truncate table Contacts",
|
||||
"insert into Contacts (id, first_name, last_name) values ('1', 'John', 'Doe')",
|
||||
"insert into Contacts (id, first_name, last_name) values ('2', 'Jane', 'Smith')",
|
||||
"insert into Contacts (id, first_name, last_name) values ('3', 'Alice', 'Johnson')",
|
||||
"insert into Contacts (id, first_name, last_name) values ('4', 'Michael', 'Brown')",
|
||||
"insert into Contacts (id, first_name, last_name) values ('5', 'Emily', 'Davis')",
|
||||
"Truncate table Calls",
|
||||
"insert into Calls (contact_id, type, duration) values ('1', 'incoming', '120')",
|
||||
"insert into Calls (contact_id, type, duration) values ('1', 'outgoing', '180')",
|
||||
"insert into Calls (contact_id, type, duration) values ('2', 'incoming', '300')",
|
||||
"insert into Calls (contact_id, type, duration) values ('2', 'outgoing', '240')",
|
||||
"insert into Calls (contact_id, type, duration) values ('3', 'incoming', '150')",
|
||||
"insert into Calls (contact_id, type, duration) values ('3', 'outgoing', '360')",
|
||||
"insert into Calls (contact_id, type, duration) values ('4', 'incoming', '420')",
|
||||
"insert into Calls (contact_id, type, duration) values ('4', 'outgoing', '200')",
|
||||
"insert into Calls (contact_id, type, duration) values ('5', 'incoming', '180')",
|
||||
"insert into Calls (contact_id, type, duration) values ('5', 'outgoing', '280')"
|
||||
],
|
||||
"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>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>PostgreSQL 16<\\/p>\"]}",
|
||||
"book": null,
|
||||
"isSubscribed": false,
|
||||
"isDailyQuestion": false,
|
||||
"dailyRecordStatus": null,
|
||||
"editorType": "CKEDITOR",
|
||||
"ugcQuestionId": null,
|
||||
"style": "LEETCODE",
|
||||
"exampleTestcases": "{\"headers\":{\"Contacts\":[\"id\",\"first_name\",\"last_name\"],\"Calls\":[\"contact_id\",\"type\",\"duration\"]},\"rows\":{\"Contacts\":[[1,\"John\",\"Doe\"],[2,\"Jane\",\"Smith\"],[3,\"Alice\",\"Johnson\"],[4,\"Michael\",\"Brown\"],[5,\"Emily\",\"Davis\"]],\"Calls\":[[1,\"incoming\",120],[1,\"outgoing\",180],[2,\"incoming\",300],[2,\"outgoing\",240],[3,\"incoming\",150],[3,\"outgoing\",360],[4,\"incoming\",420],[4,\"outgoing\",200],[5,\"incoming\",180],[5,\"outgoing\",280]]}}",
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
74
leetcode-cn/originData/[no content]friday-purchase-iii.json
Normal file
74
leetcode-cn/originData/[no content]friday-purchase-iii.json
Normal file
@ -0,0 +1,74 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "3424",
|
||||
"questionFrontendId": "3118",
|
||||
"categoryTitle": "Database",
|
||||
"boundTopicId": 2740389,
|
||||
"title": "Friday Purchase III ",
|
||||
"titleSlug": "friday-purchase-iii",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Medium",
|
||||
"likes": 0,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"contributors": [],
|
||||
"langToValidPlayground": null,
|
||||
"topicTags": [
|
||||
{
|
||||
"name": "Database",
|
||||
"slug": "database",
|
||||
"translatedName": "数据库",
|
||||
"__typename": "TopicTagNode"
|
||||
}
|
||||
],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"33\", \"totalSubmission\": \"58\", \"totalAcceptedRaw\": 33, \"totalSubmissionRaw\": 58, \"acRate\": \"56.9%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\":{\"Purchases\":[\"user_id\",\"purchase_date\",\"amount_spend\"],\"Users\":[\"user_id\",\"membership\"]},\"rows\":{\"Purchases\":[[11,\"2023-11-03\",1126],[15,\"2023-11-10\",7473],[17,\"2023-11-17\",2414],[12,\"2023-11-24\",9692],[8,\"2023-11-24\",5117],[1,\"2023-11-24\",5241],[10,\"2023-11-22\",8266],[13,\"2023-11-21\",12000]],\"Users\":[[11,\"Premium\"],[15,\"VIP\"],[17,\"Standard\"],[12,\"VIP\"],[8,\"Premium\"],[1,\"VIP\"],[10,\"Standard\"],[13,\"Premium\"]]}}",
|
||||
"metaData": "{\"mysql\":[\"Create Table if Not Exists Purchases( user_id int, purchase_date date, amount_spend int)\",\"Create Table if Not Exists Users (user_id int, membership enum('Standard', 'Premium', 'VIP'))\"],\"mssql\":[\"Create Table Purchases( user_id int, purchase_date date, amount_spend int)\",\"Create Table Users (user_id int, membership varchar(30) NOT NULL CHECK ( membership in ('Standard', 'Premium', 'VIP')))\"],\"oraclesql\":[\"Create Table Purchases( user_id int, purchase_date date, amount_spend int)\",\"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\",\"Create Table Users (user_id int, membership varchar(30) NOT NULL CHECK ( membership in ('Standard', 'Premium', 'VIP')))\"],\"database\":true,\"name\":\"friday_purchases\",\"postgresql\":[\"CREATE TABLE Purchases (\\n user_id int,\\n purchase_date date,\\n amount_spend int\\n);\",\"SET datestyle = 'ISO, MDY'; \\n\",\"CREATE TABLE Users (\\n user_id int,\\n membership varchar(30) NOT NULL CHECK (membership IN ('Standard', 'Premium', 'VIP'))\\n);\"],\"pythondata\":[\"Purchases = pd.DataFrame([], columns=['user_id', 'purchase_date', 'amount_spend']).astype({'user_id':'Int64', 'purchase_date':'datetime64[ns]', 'amount_spend':'Int64'})\\n\",\"Users = pd.DataFrame([], columns=['user_id', 'membership']).astype({\\n 'user_id': 'Int64',\\n 'membership': pd.CategoricalDtype(categories=['Standard', 'Premium', 'VIP'])\\n})\"],\"database_schema\":{\"Purchases\":{\"user_id\":\"INT\",\"purchase_date\":\"DATE\",\"amount_spend\":\"INT\"},\"Users\":{\"user_id\":\"INT\",\"membership\":\"ENUM('Standard', 'Premium', 'VIP')\"}}}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Create Table if Not Exists Purchases( user_id int, purchase_date date, amount_spend int)",
|
||||
"Create Table if Not Exists Users (user_id int, membership enum('Standard', 'Premium', 'VIP'))",
|
||||
"Truncate table Purchases",
|
||||
"insert into Purchases (user_id, purchase_date, amount_spend) values ('11', '2023-11-03', '1126')",
|
||||
"insert into Purchases (user_id, purchase_date, amount_spend) values ('15', '2023-11-10', '7473')",
|
||||
"insert into Purchases (user_id, purchase_date, amount_spend) values ('17', '2023-11-17', '2414')",
|
||||
"insert into Purchases (user_id, purchase_date, amount_spend) values ('12', '2023-11-24', '9692')",
|
||||
"insert into Purchases (user_id, purchase_date, amount_spend) values ('8', '2023-11-24', '5117')",
|
||||
"insert into Purchases (user_id, purchase_date, amount_spend) values ('1', '2023-11-24', '5241')",
|
||||
"insert into Purchases (user_id, purchase_date, amount_spend) values ('10', '2023-11-22', '8266')",
|
||||
"insert into Purchases (user_id, purchase_date, amount_spend) values ('13', '2023-11-21', '12000')",
|
||||
"Truncate table Users",
|
||||
"insert into Users (user_id, membership) values ('11', 'Premium')",
|
||||
"insert into Users (user_id, membership) values ('15', 'VIP')",
|
||||
"insert into Users (user_id, membership) values ('17', 'Standard')",
|
||||
"insert into Users (user_id, membership) values ('12', 'VIP')",
|
||||
"insert into Users (user_id, membership) values ('8', 'Premium')",
|
||||
"insert into Users (user_id, membership) values ('1', 'VIP')",
|
||||
"insert into Users (user_id, membership) values ('10', 'Standard')",
|
||||
"insert into Users (user_id, membership) values ('13', 'Premium')"
|
||||
],
|
||||
"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>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>PostgreSQL 16<\\/p>\"]}",
|
||||
"book": null,
|
||||
"isSubscribed": false,
|
||||
"isDailyQuestion": false,
|
||||
"dailyRecordStatus": null,
|
||||
"editorType": "CKEDITOR",
|
||||
"ugcQuestionId": null,
|
||||
"style": "LEETCODE",
|
||||
"exampleTestcases": "{\"headers\":{\"Purchases\":[\"user_id\",\"purchase_date\",\"amount_spend\"],\"Users\":[\"user_id\",\"membership\"]},\"rows\":{\"Purchases\":[[11,\"2023-11-03\",1126],[15,\"2023-11-10\",7473],[17,\"2023-11-17\",2414],[12,\"2023-11-24\",9692],[8,\"2023-11-24\",5117],[1,\"2023-11-24\",5241],[10,\"2023-11-22\",8266],[13,\"2023-11-21\",12000]],\"Users\":[[11,\"Premium\"],[15,\"VIP\"],[17,\"Standard\"],[12,\"VIP\"],[8,\"Premium\"],[1,\"VIP\"],[10,\"Standard\"],[13,\"Premium\"]]}}",
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
50
leetcode-cn/originData/[no content]maximum-number-that-makes-result-of-bitwise-and-zero.json
Normal file
50
leetcode-cn/originData/[no content]maximum-number-that-makes-result-of-bitwise-and-zero.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
File diff suppressed because one or more lines are too long
195
leetcode-cn/originData/find-edges-in-shortest-paths.json
Normal file
195
leetcode-cn/originData/find-edges-in-shortest-paths.json
Normal file
File diff suppressed because one or more lines are too long
164
leetcode-cn/originData/find-the-integer-added-to-array-i.json
Normal file
164
leetcode-cn/originData/find-the-integer-added-to-array-i.json
Normal file
File diff suppressed because one or more lines are too long
164
leetcode-cn/originData/find-the-integer-added-to-array-ii.json
Normal file
164
leetcode-cn/originData/find-the-integer-added-to-array-ii.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
192
leetcode-cn/originData/find-the-number-of-subarrays-where-boundary-elements-are-maximum.json
Normal file
192
leetcode-cn/originData/find-the-number-of-subarrays-where-boundary-elements-are-maximum.json
Normal file
File diff suppressed because one or more lines are too long
201
leetcode-cn/originData/kth-smallest-amount-with-single-denomination-combination.json
Normal file
201
leetcode-cn/originData/kth-smallest-amount-with-single-denomination-combination.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
163
leetcode-cn/originData/make-a-square-with-the-same-color.json
Normal file
163
leetcode-cn/originData/make-a-square-with-the-same-color.json
Normal file
File diff suppressed because one or more lines are too long
183
leetcode-cn/originData/maximum-prime-difference.json
Normal file
183
leetcode-cn/originData/maximum-prime-difference.json
Normal file
File diff suppressed because one or more lines are too long
165
leetcode-cn/originData/minimum-array-end.json
Normal file
165
leetcode-cn/originData/minimum-array-end.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
184
leetcode-cn/originData/minimum-rectangles-to-cover-points.json
Normal file
184
leetcode-cn/originData/minimum-rectangles-to-cover-points.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/right-triangles.json
Normal file
165
leetcode-cn/originData/right-triangles.json
Normal file
File diff suppressed because one or more lines are too long
170
leetcode-cn/originData/score-of-a-string.json
Normal file
170
leetcode-cn/originData/score-of-a-string.json
Normal file
File diff suppressed because one or more lines are too long
196
leetcode-cn/originData/server-utilization-time.json
Normal file
196
leetcode-cn/originData/server-utilization-time.json
Normal file
@ -0,0 +1,196 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "3440",
|
||||
"questionFrontendId": "3126",
|
||||
"categoryTitle": "Database",
|
||||
"boundTopicId": 2758487,
|
||||
"title": "Server Utilization Time",
|
||||
"titleSlug": "server-utilization-time",
|
||||
"content": "<p>Table: <code>Servers</code></p>\n\n<pre>\n+----------------+----------+\n| Column Name | Type |\n+----------------+----------+\n| server_id | int |\n| status_time | datetime |\n| session_status | enum |\n+----------------+----------+\n(server_id, status_time, session_status) is the primary key (combination of columns with unique values) for this table.\nsession_status is an ENUM (category) type of ('start', 'stop').\nEach row of this table contains server_id, status_time, and session_status.\n</pre>\n\n<p>Write a solution to find the <strong>total time</strong> when servers were <strong>running</strong>. The output should be rounded down to the nearest number of <strong>full days</strong>.</p>\n\n<p>Return <em>the result table in <strong>any</strong></em><em> order.</em></p>\n\n<p>The result format is in the following example.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example:</strong></p>\n\n<div class=\"example-block\">\n<p><strong>Input:</strong></p>\n\n<p>Servers table:</p>\n\n<pre class=\"example-io\">\n+-----------+---------------------+----------------+\n| server_id | status_time | session_status |\n+-----------+---------------------+----------------+\n| 3 | 2023-11-04 16:29:47 | start |\n| 3 | 2023-11-05 01:49:47 | stop |\n| 3 | 2023-11-25 01:37:08 | start |\n| 3 | 2023-11-25 03:50:08 | stop |\n| 1 | 2023-11-13 03:05:31 | start |\n| 1 | 2023-11-13 11:10:31 | stop |\n| 4 | 2023-11-29 15:11:17 | start |\n| 4 | 2023-11-29 15:42:17 | stop |\n| 4 | 2023-11-20 00:31:44 | start |\n| 4 | 2023-11-20 07:03:44 | stop |\n| 1 | 2023-11-20 00:27:11 | start |\n| 1 | 2023-11-20 01:41:11 | stop |\n| 3 | 2023-11-04 23:16:48 | start |\n| 3 | 2023-11-05 01:15:48 | stop |\n| 4 | 2023-11-30 15:09:18 | start |\n| 4 | 2023-11-30 20:48:18 | stop |\n| 4 | 2023-11-25 21:09:06 | start |\n| 4 | 2023-11-26 04:58:06 | stop |\n| 5 | 2023-11-16 19:42:22 | start |\n| 5 | 2023-11-16 21:08:22 | stop |\n+-----------+---------------------+----------------+\n</pre>\n\n<p><strong>Output:</strong></p>\n\n<pre class=\"example-io\">\n+-------------------+\n| total_uptime_days |\n+-------------------+\n| 1 |\n+-------------------+\n</pre>\n\n<p><strong>Explanation:</strong></p>\n\n<ul>\n\t<li>For server ID 3:\n\t<ul>\n\t\t<li>From 2023-11-04 16:29:47 to 2023-11-05 01:49:47: ~9.3 hours</li>\n\t\t<li>From 2023-11-25 01:37:08 to 2023-11-25 03:50:08: ~2.2 hours</li>\n\t\t<li>From 2023-11-04 23:16:48 to 2023-11-05 01:15:48: ~1.98 hours</li>\n\t</ul>\n\tTotal for server 3: ~13.48 hours</li>\n\t<li>For server ID 1:\n\t<ul>\n\t\t<li>From 2023-11-13 03:05:31 to 2023-11-13 11:10:31: ~8 hours</li>\n\t\t<li>From 2023-11-20 00:27:11 to 2023-11-20 01:41:11: ~1.23 hours</li>\n\t</ul>\n\tTotal for server 1: ~9.23 hours</li>\n\t<li>For server ID 4:\n\t<ul>\n\t\t<li>From 2023-11-29 15:11:17 to 2023-11-29 15:42:17: ~0.52 hours</li>\n\t\t<li>From 2023-11-20 00:31:44 to 2023-11-20 07:03:44: ~6.53 hours</li>\n\t\t<li>From 2023-11-30 15:09:18 to 2023-11-30 20:48:18: ~5.65 hours</li>\n\t\t<li>From 2023-11-25 21:09:06 to 2023-11-26 04:58:06: ~7.82 hours</li>\n\t</ul>\n\tTotal for server 4: ~20.52 hours</li>\n\t<li>For server ID 5:\n\t<ul>\n\t\t<li>From 2023-11-16 19:42:22 to 2023-11-16 21:08:22: ~1.43 hours</li>\n\t</ul>\n\tTotal for server 5: ~1.43 hours</li>\n</ul>\nThe accumulated runtime for all servers totals approximately 44.46 hours, equivalent to one full day plus some additional hours. However, since we consider only full days, the final output is rounded to 1 full day.</div>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Medium",
|
||||
"likes": 0,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"contributors": [],
|
||||
"langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}",
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": [
|
||||
{
|
||||
"lang": "MySQL",
|
||||
"langSlug": "mysql",
|
||||
"code": "# Write your MySQL query statement below",
|
||||
"__typename": "CodeSnippetNode"
|
||||
},
|
||||
{
|
||||
"lang": "MS SQL Server",
|
||||
"langSlug": "mssql",
|
||||
"code": "/* Write your T-SQL query statement below */",
|
||||
"__typename": "CodeSnippetNode"
|
||||
},
|
||||
{
|
||||
"lang": "Oracle",
|
||||
"langSlug": "oraclesql",
|
||||
"code": "/* Write your PL/SQL query statement below */",
|
||||
"__typename": "CodeSnippetNode"
|
||||
},
|
||||
{
|
||||
"lang": "Pandas",
|
||||
"langSlug": "pythondata",
|
||||
"code": "import pandas as pd\n\ndef server_utilization_time(servers: pd.DataFrame) -> pd.DataFrame:\n ",
|
||||
"__typename": "CodeSnippetNode"
|
||||
},
|
||||
{
|
||||
"lang": "PostgreSQL",
|
||||
"langSlug": "postgresql",
|
||||
"code": "-- Write your PostgreSQL query statement below",
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"16\", \"totalSubmission\": \"62\", \"totalAcceptedRaw\": 16, \"totalSubmissionRaw\": 62, \"acRate\": \"25.8%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\": {\"Servers\": [\"server_id\", \"status_time\", \"session_status\"]}, \"rows\": {\"Servers\": [[4, \"2023-11-29 20:22:50\", \"start\"], [4, \"2023-11-30 04:19:50\", \"stop\"], [2, \"2023-11-18 21:23:09\", \"start\"], [2, \"2023-11-19 00:38:09\", \"stop\"], [5, \"2023-11-27 18:38:16\", \"start\"], [5, \"2023-11-28 02:46:16\", \"stop\"], [4, \"2023-11-27 06:46:42\", \"start\"], [4, \"2023-11-27 08:23:42\", \"stop\"], [5, \"2023-11-11 05:09:45\", \"start\"], [5, \"2023-11-11 06:42:45\", \"stop\"], [5, \"2023-11-27 23:05:58\", \"start\"], [5, \"2023-11-27 23:48:58\", \"stop\"], [5, \"2023-11-14 16:29:34\", \"start\"], [5, \"2023-11-14 19:11:34\", \"stop\"], [1, \"2023-11-02 19:14:15\", \"start\"], [1, \"2023-11-02 20:19:15\", \"stop\"], [5, \"2023-11-03 06:55:30\", \"start\"], [5, \"2023-11-03 11:03:30\", \"stop\"], [4, \"2023-11-02 16:53:28\", \"start\"], [4, \"2023-11-02 22:28:28\", \"stop\"], [2, \"2023-11-20 07:06:41\", \"start\"], [2, \"2023-11-20 15:58:41\", \"stop\"], [1, \"2023-11-22 10:42:35\", \"start\"], [1, \"2023-11-22 19:14:35\", \"stop\"], [3, \"2023-11-23 03:05:39\", \"start\"], [3, \"2023-11-23 10:54:39\", \"stop\"], [3, \"2023-11-15 20:04:15\", \"start\"], [3, \"2023-11-15 21:30:15\", \"stop\"], [3, \"2023-11-12 08:21:42\", \"start\"], [3, \"2023-11-12 17:07:42\", \"stop\"], [1, \"2023-11-02 02:33:24\", \"start\"], [1, \"2023-11-02 12:10:24\", \"stop\"], [4, \"2023-11-14 03:55:29\", \"start\"], [4, \"2023-11-14 08:53:29\", \"stop\"], [2, \"2023-11-04 00:36:53\", \"start\"], [2, \"2023-11-04 00:37:53\", \"stop\"], [4, \"2023-11-08 01:54:18\", \"start\"], [4, \"2023-11-08 09:56:18\", \"stop\"], [1, \"2023-11-24 14:28:11\", \"start\"], [1, \"2023-11-24 21:38:11\", \"stop\"], [3, \"2023-11-20 22:55:03\", \"start\"], [3, \"2023-11-21 02:19:03\", \"stop\"], [3, \"2023-11-12 03:10:22\", \"start\"], [3, \"2023-11-12 08:29:22\", \"stop\"], [2, \"2023-11-02 14:55:46\", \"start\"], [2, \"2023-11-02 16:56:46\", \"stop\"], [1, \"2023-11-09 03:40:44\", \"start\"], [1, \"2023-11-09 03:52:44\", \"stop\"], [5, \"2023-11-16 17:43:28\", \"start\"], [5, \"2023-11-16 20:45:28\", \"stop\"], [2, \"2023-11-08 16:17:24\", \"start\"], [2, \"2023-11-09 00:59:24\", \"stop\"], [4, \"2023-11-25 04:46:06\", \"start\"], [4, \"2023-11-25 11:56:06\", \"stop\"], [2, \"2023-11-05 14:22:34\", \"start\"], [2, \"2023-11-05 21:33:34\", \"stop\"], [1, \"2023-11-02 09:49:22\", \"start\"], [1, \"2023-11-02 15:01:22\", \"stop\"], [5, \"2023-11-08 06:49:10\", \"start\"], [5, \"2023-11-08 13:33:10\", \"stop\"], [1, \"2023-11-22 21:00:23\", \"start\"], [1, \"2023-11-22 22:43:23\", \"stop\"], [3, \"2023-11-06 07:45:50\", \"start\"], [3, \"2023-11-06 15:18:50\", \"stop\"], [3, \"2023-11-02 22:13:17\", \"start\"], [3, \"2023-11-03 03:50:17\", \"stop\"], [1, \"2023-11-14 02:40:20\", \"start\"], [1, \"2023-11-14 03:57:20\", \"stop\"], [1, \"2023-11-08 21:13:00\", \"start\"], [1, \"2023-11-09 01:22:00\", \"stop\"], [5, \"2023-11-21 13:25:22\", \"start\"], [5, \"2023-11-21 19:46:22\", \"stop\"], [5, \"2023-11-16 04:37:55\", \"start\"], [5, \"2023-11-16 12:53:55\", \"stop\"], [2, \"2023-11-06 14:03:26\", \"start\"], [2, \"2023-11-06 17:11:26\", \"stop\"], [2, \"2023-11-11 08:18:54\", \"start\"], [2, \"2023-11-11 12:34:54\", \"stop\"], [2, \"2023-11-07 22:54:01\", \"start\"], [2, \"2023-11-08 08:22:01\", \"stop\"], [5, \"2023-11-23 14:08:03\", \"start\"], [5, \"2023-11-23 22:23:03\", \"stop\"], [1, \"2023-11-04 15:20:41\", \"start\"], [1, \"2023-11-04 16:09:41\", \"stop\"], [3, \"2023-11-05 01:24:32\", \"start\"], [3, \"2023-11-05 10:09:32\", \"stop\"], [4, \"2023-11-09 14:15:29\", \"start\"], [4, \"2023-11-09 18:39:29\", \"stop\"], [3, \"2023-11-28 21:43:00\", \"start\"], [3, \"2023-11-29 06:06:00\", \"stop\"], [2, \"2023-11-18 06:23:14\", \"start\"], [2, \"2023-11-18 07:34:14\", \"stop\"], [5, \"2023-11-09 17:27:02\", \"start\"], [5, \"2023-11-10 03:00:02\", \"stop\"], [2, \"2023-11-21 02:41:57\", \"start\"], [2, \"2023-11-21 07:28:57\", \"stop\"], [3, \"2023-11-08 00:36:12\", \"start\"], [3, \"2023-11-08 01:47:12\", \"stop\"], [1, \"2023-11-15 16:13:39\", \"start\"], [1, \"2023-11-15 20:29:39\", \"stop\"], [3, \"2023-11-03 06:25:01\", \"start\"], [3, \"2023-11-03 11:14:01\", \"stop\"], [1, \"2023-11-18 20:49:55\", \"start\"], [1, \"2023-11-18 23:04:55\", \"stop\"], [3, \"2023-11-13 05:02:21\", \"start\"], [3, \"2023-11-13 12:44:21\", \"stop\"], [2, \"2023-11-23 19:00:11\", \"start\"], [2, \"2023-11-24 04:59:11\", \"stop\"], [4, \"2023-11-20 01:16:38\", \"start\"], [4, \"2023-11-20 01:35:38\", \"stop\"], [1, \"2023-11-13 11:21:08\", \"start\"], [1, \"2023-11-13 11:56:08\", \"stop\"], [4, \"2023-11-21 23:09:45\", \"start\"], [4, \"2023-11-22 00:26:45\", \"stop\"], [2, \"2023-11-04 11:19:31\", \"start\"], [2, \"2023-11-04 16:46:31\", \"stop\"]]}}",
|
||||
"metaData": "{\"mysql\":[\"Create table if not exists Servers ( server_id int, status_time timestamp, session_status ENUM ('start','stop'))\"],\"mssql\":[\"Create table Servers (server_id int, status_time datetime, session_status varchar(20) NOT NULL CHECK (session_status in ('start','stop')))\"],\"oraclesql\":[\"Create table Servers (server_id int, status_time date, session_status varchar(20) NOT NULL CHECK (session_status in ('start','stop')))\",\"ALTER SESSION SET nls_date_format='YYYY-MM-DD HH24:MI:SS'\"],\"database\":true,\"name\":\"server_utilization_time\",\"postgresql\":[\"Create table Servers (server_id int, status_time timestamp, session_status varchar(20) NOT NULL CHECK (session_status in ('start','stop')))\"],\"pythondata\":[\"Servers = pd.DataFrame(columns=['server_id', 'status_time', 'session_status'], dtype={'server_id': 'int', 'status_time': 'datetime64[ns]', 'session_status': pd.CategoricalDtype(categories=['start', 'stop'])})\\n\"],\"database_schema\":{\"Servers\":{\"server_id\":\"INT\",\"status_time\":\"TIMESTAMP\",\"session_status\":\"ENUM('start', 'stop')\"}}}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Create table if not exists Servers ( server_id int, status_time timestamp, session_status ENUM ('start','stop'))",
|
||||
"Truncate table Servers",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('4', '2023-11-29 20:22:50', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('4', '2023-11-30 04:19:50', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('2', '2023-11-18 21:23:09', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('2', '2023-11-19 00:38:09', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('5', '2023-11-27 18:38:16', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('5', '2023-11-28 02:46:16', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('4', '2023-11-27 06:46:42', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('4', '2023-11-27 08:23:42', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('5', '2023-11-11 05:09:45', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('5', '2023-11-11 06:42:45', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('5', '2023-11-27 23:05:58', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('5', '2023-11-27 23:48:58', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('5', '2023-11-14 16:29:34', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('5', '2023-11-14 19:11:34', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('1', '2023-11-02 19:14:15', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('1', '2023-11-02 20:19:15', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('5', '2023-11-03 06:55:30', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('5', '2023-11-03 11:03:30', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('4', '2023-11-02 16:53:28', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('4', '2023-11-02 22:28:28', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('2', '2023-11-20 07:06:41', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('2', '2023-11-20 15:58:41', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('1', '2023-11-22 10:42:35', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('1', '2023-11-22 19:14:35', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('3', '2023-11-23 03:05:39', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('3', '2023-11-23 10:54:39', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('3', '2023-11-15 20:04:15', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('3', '2023-11-15 21:30:15', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('3', '2023-11-12 08:21:42', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('3', '2023-11-12 17:07:42', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('1', '2023-11-02 02:33:24', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('1', '2023-11-02 12:10:24', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('4', '2023-11-14 03:55:29', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('4', '2023-11-14 08:53:29', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('2', '2023-11-04 00:36:53', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('2', '2023-11-04 00:37:53', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('4', '2023-11-08 01:54:18', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('4', '2023-11-08 09:56:18', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('1', '2023-11-24 14:28:11', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('1', '2023-11-24 21:38:11', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('3', '2023-11-20 22:55:03', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('3', '2023-11-21 02:19:03', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('3', '2023-11-12 03:10:22', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('3', '2023-11-12 08:29:22', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('2', '2023-11-02 14:55:46', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('2', '2023-11-02 16:56:46', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('1', '2023-11-09 03:40:44', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('1', '2023-11-09 03:52:44', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('5', '2023-11-16 17:43:28', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('5', '2023-11-16 20:45:28', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('2', '2023-11-08 16:17:24', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('2', '2023-11-09 00:59:24', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('4', '2023-11-25 04:46:06', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('4', '2023-11-25 11:56:06', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('2', '2023-11-05 14:22:34', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('2', '2023-11-05 21:33:34', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('1', '2023-11-02 09:49:22', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('1', '2023-11-02 15:01:22', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('5', '2023-11-08 06:49:10', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('5', '2023-11-08 13:33:10', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('1', '2023-11-22 21:00:23', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('1', '2023-11-22 22:43:23', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('3', '2023-11-06 07:45:50', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('3', '2023-11-06 15:18:50', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('3', '2023-11-02 22:13:17', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('3', '2023-11-03 03:50:17', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('1', '2023-11-14 02:40:20', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('1', '2023-11-14 03:57:20', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('1', '2023-11-08 21:13:00', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('1', '2023-11-09 01:22:00', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('5', '2023-11-21 13:25:22', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('5', '2023-11-21 19:46:22', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('5', '2023-11-16 04:37:55', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('5', '2023-11-16 12:53:55', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('2', '2023-11-06 14:03:26', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('2', '2023-11-06 17:11:26', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('2', '2023-11-11 08:18:54', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('2', '2023-11-11 12:34:54', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('2', '2023-11-07 22:54:01', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('2', '2023-11-08 08:22:01', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('5', '2023-11-23 14:08:03', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('5', '2023-11-23 22:23:03', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('1', '2023-11-04 15:20:41', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('1', '2023-11-04 16:09:41', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('3', '2023-11-05 01:24:32', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('3', '2023-11-05 10:09:32', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('4', '2023-11-09 14:15:29', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('4', '2023-11-09 18:39:29', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('3', '2023-11-28 21:43:00', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('3', '2023-11-29 06:06:00', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('2', '2023-11-18 06:23:14', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('2', '2023-11-18 07:34:14', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('5', '2023-11-09 17:27:02', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('5', '2023-11-10 03:00:02', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('2', '2023-11-21 02:41:57', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('2', '2023-11-21 07:28:57', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('3', '2023-11-08 00:36:12', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('3', '2023-11-08 01:47:12', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('1', '2023-11-15 16:13:39', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('1', '2023-11-15 20:29:39', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('3', '2023-11-03 06:25:01', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('3', '2023-11-03 11:14:01', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('1', '2023-11-18 20:49:55', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('1', '2023-11-18 23:04:55', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('3', '2023-11-13 05:02:21', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('3', '2023-11-13 12:44:21', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('2', '2023-11-23 19:00:11', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('2', '2023-11-24 04:59:11', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('4', '2023-11-20 01:16:38', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('4', '2023-11-20 01:35:38', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('1', '2023-11-13 11:21:08', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('1', '2023-11-13 11:56:08', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('4', '2023-11-21 23:09:45', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('4', '2023-11-22 00:26:45', 'stop')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('2', '2023-11-04 11:19:31', 'start')",
|
||||
"insert into Servers (server_id, status_time, session_status) values ('2', '2023-11-04 16:46:31', 'stop')"
|
||||
],
|
||||
"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>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>PostgreSQL 16<\\/p>\"]}",
|
||||
"book": null,
|
||||
"isSubscribed": false,
|
||||
"isDailyQuestion": false,
|
||||
"dailyRecordStatus": null,
|
||||
"editorType": "CKEDITOR",
|
||||
"ugcQuestionId": null,
|
||||
"style": "LEETCODE",
|
||||
"exampleTestcases": "{\"headers\": {\"Servers\": [\"server_id\", \"status_time\", \"session_status\"]}, \"rows\": {\"Servers\": [[4, \"2023-11-29 20:22:50\", \"start\"], [4, \"2023-11-30 04:19:50\", \"stop\"], [2, \"2023-11-18 21:23:09\", \"start\"], [2, \"2023-11-19 00:38:09\", \"stop\"], [5, \"2023-11-27 18:38:16\", \"start\"], [5, \"2023-11-28 02:46:16\", \"stop\"], [4, \"2023-11-27 06:46:42\", \"start\"], [4, \"2023-11-27 08:23:42\", \"stop\"], [5, \"2023-11-11 05:09:45\", \"start\"], [5, \"2023-11-11 06:42:45\", \"stop\"], [5, \"2023-11-27 23:05:58\", \"start\"], [5, \"2023-11-27 23:48:58\", \"stop\"], [5, \"2023-11-14 16:29:34\", \"start\"], [5, \"2023-11-14 19:11:34\", \"stop\"], [1, \"2023-11-02 19:14:15\", \"start\"], [1, \"2023-11-02 20:19:15\", \"stop\"], [5, \"2023-11-03 06:55:30\", \"start\"], [5, \"2023-11-03 11:03:30\", \"stop\"], [4, \"2023-11-02 16:53:28\", \"start\"], [4, \"2023-11-02 22:28:28\", \"stop\"], [2, \"2023-11-20 07:06:41\", \"start\"], [2, \"2023-11-20 15:58:41\", \"stop\"], [1, \"2023-11-22 10:42:35\", \"start\"], [1, \"2023-11-22 19:14:35\", \"stop\"], [3, \"2023-11-23 03:05:39\", \"start\"], [3, \"2023-11-23 10:54:39\", \"stop\"], [3, \"2023-11-15 20:04:15\", \"start\"], [3, \"2023-11-15 21:30:15\", \"stop\"], [3, \"2023-11-12 08:21:42\", \"start\"], [3, \"2023-11-12 17:07:42\", \"stop\"], [1, \"2023-11-02 02:33:24\", \"start\"], [1, \"2023-11-02 12:10:24\", \"stop\"], [4, \"2023-11-14 03:55:29\", \"start\"], [4, \"2023-11-14 08:53:29\", \"stop\"], [2, \"2023-11-04 00:36:53\", \"start\"], [2, \"2023-11-04 00:37:53\", \"stop\"], [4, \"2023-11-08 01:54:18\", \"start\"], [4, \"2023-11-08 09:56:18\", \"stop\"], [1, \"2023-11-24 14:28:11\", \"start\"], [1, \"2023-11-24 21:38:11\", \"stop\"], [3, \"2023-11-20 22:55:03\", \"start\"], [3, \"2023-11-21 02:19:03\", \"stop\"], [3, \"2023-11-12 03:10:22\", \"start\"], [3, \"2023-11-12 08:29:22\", \"stop\"], [2, \"2023-11-02 14:55:46\", \"start\"], [2, \"2023-11-02 16:56:46\", \"stop\"], [1, \"2023-11-09 03:40:44\", \"start\"], [1, \"2023-11-09 03:52:44\", \"stop\"], [5, \"2023-11-16 17:43:28\", \"start\"], [5, \"2023-11-16 20:45:28\", \"stop\"], [2, \"2023-11-08 16:17:24\", \"start\"], [2, \"2023-11-09 00:59:24\", \"stop\"], [4, \"2023-11-25 04:46:06\", \"start\"], [4, \"2023-11-25 11:56:06\", \"stop\"], [2, \"2023-11-05 14:22:34\", \"start\"], [2, \"2023-11-05 21:33:34\", \"stop\"], [1, \"2023-11-02 09:49:22\", \"start\"], [1, \"2023-11-02 15:01:22\", \"stop\"], [5, \"2023-11-08 06:49:10\", \"start\"], [5, \"2023-11-08 13:33:10\", \"stop\"], [1, \"2023-11-22 21:00:23\", \"start\"], [1, \"2023-11-22 22:43:23\", \"stop\"], [3, \"2023-11-06 07:45:50\", \"start\"], [3, \"2023-11-06 15:18:50\", \"stop\"], [3, \"2023-11-02 22:13:17\", \"start\"], [3, \"2023-11-03 03:50:17\", \"stop\"], [1, \"2023-11-14 02:40:20\", \"start\"], [1, \"2023-11-14 03:57:20\", \"stop\"], [1, \"2023-11-08 21:13:00\", \"start\"], [1, \"2023-11-09 01:22:00\", \"stop\"], [5, \"2023-11-21 13:25:22\", \"start\"], [5, \"2023-11-21 19:46:22\", \"stop\"], [5, \"2023-11-16 04:37:55\", \"start\"], [5, \"2023-11-16 12:53:55\", \"stop\"], [2, \"2023-11-06 14:03:26\", \"start\"], [2, \"2023-11-06 17:11:26\", \"stop\"], [2, \"2023-11-11 08:18:54\", \"start\"], [2, \"2023-11-11 12:34:54\", \"stop\"], [2, \"2023-11-07 22:54:01\", \"start\"], [2, \"2023-11-08 08:22:01\", \"stop\"], [5, \"2023-11-23 14:08:03\", \"start\"], [5, \"2023-11-23 22:23:03\", \"stop\"], [1, \"2023-11-04 15:20:41\", \"start\"], [1, \"2023-11-04 16:09:41\", \"stop\"], [3, \"2023-11-05 01:24:32\", \"start\"], [3, \"2023-11-05 10:09:32\", \"stop\"], [4, \"2023-11-09 14:15:29\", \"start\"], [4, \"2023-11-09 18:39:29\", \"stop\"], [3, \"2023-11-28 21:43:00\", \"start\"], [3, \"2023-11-29 06:06:00\", \"stop\"], [2, \"2023-11-18 06:23:14\", \"start\"], [2, \"2023-11-18 07:34:14\", \"stop\"], [5, \"2023-11-09 17:27:02\", \"start\"], [5, \"2023-11-10 03:00:02\", \"stop\"], [2, \"2023-11-21 02:41:57\", \"start\"], [2, \"2023-11-21 07:28:57\", \"stop\"], [3, \"2023-11-08 00:36:12\", \"start\"], [3, \"2023-11-08 01:47:12\", \"stop\"], [1, \"2023-11-15 16:13:39\", \"start\"], [1, \"2023-11-15 20:29:39\", \"stop\"], [3, \"2023-11-03 06:25:01\", \"start\"], [3, \"2023-11-03 11:14:01\", \"stop\"], [1, \"2023-11-18 20:49:55\", \"start\"], [1, \"2023-11-18 23:04:55\", \"stop\"], [3, \"2023-11-13 05:02:21\", \"start\"], [3, \"2023-11-13 12:44:21\", \"stop\"], [2, \"2023-11-23 19:00:11\", \"start\"], [2, \"2023-11-24 04:59:11\", \"stop\"], [4, \"2023-11-20 01:16:38\", \"start\"], [4, \"2023-11-20 01:35:38\", \"stop\"], [1, \"2023-11-13 11:21:08\", \"start\"], [1, \"2023-11-13 11:56:08\", \"stop\"], [4, \"2023-11-21 23:09:45\", \"start\"], [4, \"2023-11-22 00:26:45\", \"stop\"], [2, \"2023-11-04 11:19:31\", \"start\"], [2, \"2023-11-04 16:46:31\", \"stop\"]]}}",
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
67
leetcode-cn/problem (Chinese)/使矩阵满足条件的最少操作次数 [minimum-number-of-operations-to-satisfy-conditions].html
Normal file
67
leetcode-cn/problem (Chinese)/使矩阵满足条件的最少操作次数 [minimum-number-of-operations-to-satisfy-conditions].html
Normal file
@ -0,0 +1,67 @@
|
||||
<p>给你一个大小为 <code>m x n</code> 的二维矩形 <code>grid</code> 。每次 <strong>操作</strong> 中,你可以将 <strong>任一</strong> 格子的值修改为 <strong>任意</strong> 非负整数。完成所有操作后,你需要确保每个格子 <code>grid[i][j]</code> 的值满足:</p>
|
||||
|
||||
<ul>
|
||||
<li>如果下面相邻格子存在的话,它们的值相等,也就是 <code>grid[i][j] == grid[i + 1][j]</code>(如果存在)。</li>
|
||||
<li>如果右边相邻格子存在的话,它们的值不相等,也就是 <code>grid[i][j] != grid[i][j + 1]</code>(如果存在)。</li>
|
||||
</ul>
|
||||
|
||||
<p>请你返回需要的 <strong>最少</strong> 操作数目。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><span class="example-io"><b>输入:</b>grid = [[1,0,2],[1,0,2]]</span></p>
|
||||
|
||||
<p><b>输出:</b>0</p>
|
||||
|
||||
<p><b>解释:</b></p>
|
||||
|
||||
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/04/15/examplechanged.png" style="width: 254px; height: 186px;padding: 10px; background: #fff; border-radius: .5rem;" /></strong></p>
|
||||
|
||||
<p>矩阵中所有格子已经满足要求。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><span class="example-io"><b>输入:</b>grid = [[1,1,1],[0,0,0]]</span></p>
|
||||
|
||||
<p><b>输出:</b>3</p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/03/27/example21.png" style="width: 254px; height: 186px;padding: 10px; background: #fff; border-radius: .5rem;" /></strong></p>
|
||||
|
||||
<p>将矩阵变成 <code>[[1,0,1],[1,0,1]]</code> ,它满足所有要求,需要 3 次操作:</p>
|
||||
|
||||
<ul>
|
||||
<li>将 <code>grid[1][0]</code> 变为 1 。</li>
|
||||
<li>将 <code>grid[0][1]</code> 变为 0 。</li>
|
||||
<li>将 <code>grid[1][2]</code> 变为 1 。</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><span class="example-io"><b>输入:</b>grid = [[1],[2],[3]]</span></p>
|
||||
|
||||
<p><b>输出:</b>2</p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/03/31/changed.png" style="width: 86px; height: 277px;padding: 10px; background: #fff; border-radius: .5rem;" /></p>
|
||||
|
||||
<p>这个矩阵只有一列,我们可以通过 2 次操作将所有格子里的值变为 1 。</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n, m <= 1000</code></li>
|
||||
<li><code>0 <= grid[i][j] <= 9</code></li>
|
||||
</ul>
|
73
leetcode-cn/problem (Chinese)/划分数组得到最小的值之和 [minimum-sum-of-values-by-dividing-array].html
Normal file
73
leetcode-cn/problem (Chinese)/划分数组得到最小的值之和 [minimum-sum-of-values-by-dividing-array].html
Normal file
@ -0,0 +1,73 @@
|
||||
<p>给你两个数组 <code>nums</code> 和 <code>andValues</code>,长度分别为 <code>n</code> 和 <code>m</code>。</p>
|
||||
|
||||
<p>数组的 <strong>值 </strong>等于该数组的 <strong>最后一个 </strong>元素。</p>
|
||||
|
||||
<p>你需要将 <code>nums</code> 划分为 <code>m</code> 个 <strong>不相交的连续 </strong>子数组,对于第 <code>i<sup>th</sup></code> 个子数组 <code>[l<sub>i</sub>, r<sub>i</sub>]</code>,子数组元素的按位<code>AND</code>运算结果等于 <code>andValues[i]</code>,换句话说,对所有的 <code>1 <= i <= m</code>,<code>nums[l<sub>i</sub>] & nums[l<sub>i</sub> + 1] & ... & nums[r<sub>i</sub>] == andValues[i]</code> ,其中 <code>&</code> 表示按位<code>AND</code>运算符。</p>
|
||||
|
||||
<p>返回将 <code>nums</code> 划分为 <code>m</code> 个子数组所能得到的可能的 <strong>最小 </strong>子数组 <strong>值</strong> 之和。如果无法完成这样的划分,则返回 <code>-1</code> 。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong> <span class="example-io">nums = [1,4,3,3,2], andValues = [0,3,3,2]</span></p>
|
||||
|
||||
<p><strong>输出:</strong> <span class="example-io">12</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>唯一可能的划分方法为:</p>
|
||||
|
||||
<ol>
|
||||
<li><code>[1,4]</code> 因为 <code>1 & 4 == 0</code></li>
|
||||
<li><code>[3]</code> 因为单元素子数组的按位 <code>AND</code> 结果就是该元素本身</li>
|
||||
<li><code>[3]</code> 因为单元素子数组的按位 <code>AND</code> 结果就是该元素本身</li>
|
||||
<li><code>[2]</code> 因为单元素子数组的按位 <code>AND</code> 结果就是该元素本身</li>
|
||||
</ol>
|
||||
|
||||
<p>这些子数组的值之和为 <code>4 + 3 + 3 + 2 = 12</code></p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong> <span class="example-io">nums = [2,3,5,7,7,7,5], andValues = [0,7,5]</span></p>
|
||||
|
||||
<p><strong>输出:</strong> <span class="example-io">17</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>划分 <code>nums</code> 的三种方式为:</p>
|
||||
|
||||
<ol>
|
||||
<li><code>[[2,3,5],[7,7,7],[5]]</code> 其中子数组的值之和为 <code>5 + 7 + 5 = 17</code></li>
|
||||
<li><code>[[2,3,5,7],[7,7],[5]]</code> 其中子数组的值之和为 <code>7 + 7 + 5 = 19</code></li>
|
||||
<li><code>[[2,3,5,7,7],[7],[5]]</code> 其中子数组的值之和为 <code>7 + 7 + 5 = 19</code></li>
|
||||
</ol>
|
||||
|
||||
<p>子数组值之和的最小可能值为 <code>17</code></p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong> <span class="example-io">nums = [1,2,3,4], andValues = [2]</span></p>
|
||||
|
||||
<p><strong>输出:</strong> <span class="example-io">-1</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>整个数组 <code>nums</code> 的按位 <code>AND</code> 结果为 <code>0</code>。由于无法将 <code>nums</code> 划分为单个子数组使得元素的按位 <code>AND</code> 结果为 <code>2</code>,因此返回 <code>-1</code>。</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n == nums.length <= 10<sup>4</sup></code></li>
|
||||
<li><code>1 <= m == andValues.length <= min(n, 10)</code></li>
|
||||
<li><code>1 <= nums[i] < 10<sup>5</sup></code></li>
|
||||
<li><code>0 <= andValues[j] < 10<sup>5</sup></code></li>
|
||||
</ul>
|
69
leetcode-cn/problem (Chinese)/单面值组合的第 K 小金额 [kth-smallest-amount-with-single-denomination-combination].html
Normal file
69
leetcode-cn/problem (Chinese)/单面值组合的第 K 小金额 [kth-smallest-amount-with-single-denomination-combination].html
Normal file
@ -0,0 +1,69 @@
|
||||
<p>给你一个整数数组 <code>coins</code> 表示不同面额的硬币,另给你一个整数 <code>k</code> 。</p>
|
||||
|
||||
<p>你有无限量的每种面额的硬币。但是,你<strong> 不能 </strong>组合使用不同面额的硬币。</p>
|
||||
|
||||
<p>返回使用这些硬币能制造的<strong> 第 </strong><code>k<sup>th</sup></code><strong> 小</strong> 金额。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<div class="example-block" style="
|
||||
border-color: var(--border-tertiary);
|
||||
border-left-width: 2px;
|
||||
color: var(--text-secondary);
|
||||
font-size: .875rem;
|
||||
margin-bottom: 1rem;
|
||||
margin-top: 1rem;
|
||||
overflow: visible;
|
||||
padding-left: 1rem;">
|
||||
<p><strong>输入:</strong> <span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;">coins = [3,6,9], k = 3</span></p>
|
||||
|
||||
<p><strong>输出:</strong> <span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;">9</span></p>
|
||||
|
||||
<p><strong>解释:</strong>给定的硬币可以制造以下金额:<br />
|
||||
3元硬币产生3的倍数:3, 6, 9, 12, 15等。<br />
|
||||
6元硬币产生6的倍数:6, 12, 18, 24等。<br />
|
||||
9元硬币产生9的倍数:9, 18, 27, 36等。<br />
|
||||
所有硬币合起来可以产生:3, 6, <u><strong>9</strong></u>, 12, 15等。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<div class="example-block" style="
|
||||
border-color: var(--border-tertiary);
|
||||
border-left-width: 2px;
|
||||
color: var(--text-secondary);
|
||||
font-size: .875rem;
|
||||
margin-bottom: 1rem;
|
||||
margin-top: 1rem;
|
||||
overflow: visible;
|
||||
padding-left: 1rem;">
|
||||
<p><strong>输入:</strong><span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;">coins = [5,2], k = 7</span></p>
|
||||
|
||||
<p><strong>输出:</strong><span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;">12</span></p>
|
||||
|
||||
<p><strong>解释:</strong>给定的硬币可以制造以下金额:<br />
|
||||
5元硬币产生5的倍数:5, 10, 15, 20等。<br />
|
||||
2元硬币产生2的倍数:2, 4, 6, 8, 10, 12等。<br />
|
||||
所有硬币合起来可以产生:2, 4, 5, 6, 8, 10, <u><strong>12</strong></u>, 14, 15等。</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= coins.length <= 15</code></li>
|
||||
<li><code>1 <= coins[i] <= 25</code></li>
|
||||
<li><code>1 <= k <= 2 * 10<sup>9</sup></code></li>
|
||||
<li><code>coins</code> 包含两两不同的整数。</li>
|
||||
</ul>
|
@ -0,0 +1,38 @@
|
||||
<p>给你一个字符串 <code>s</code> 。一个字符串的 <strong>分数</strong> 定义为相邻字符 <strong>ASCII</strong> 码差值绝对值的和。</p>
|
||||
|
||||
<p>请你返回 <code>s</code> 的 <strong>分数</strong> 。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><span class="example-io"><b>输入:</b>s = "hello"</span></p>
|
||||
|
||||
<p><span class="example-io"><b>输出:</b>13</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p><code>s</code> 中字符的 <strong>ASCII </strong>码分别为:<code>'h' = 104</code> ,<code>'e' = 101</code> ,<code>'l' = 108</code> ,<code>'o' = 111</code> 。所以 <code>s</code> 的分数为 <code>|104 - 101| + |101 - 108| + |108 - 108| + |108 - 111| = 3 + 7 + 0 + 3 = 13</code> 。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><span class="example-io"><b>输入:</b>s = "zaz"</span></p>
|
||||
|
||||
<p><span class="example-io"><b>输出:</b>50</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p><code>s</code> 中字符的 <strong>ASCII </strong>码分别为:<code>'z' = 122</code> ,<code>'a' = 97</code> 。所以 <code>s</code> 的分数为 <code>|122 - 97| + |97 - 122| = 25 + 25 = 50</code> 。</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= s.length <= 100</code></li>
|
||||
<li><code>s</code> 只包含小写英文字母。</li>
|
||||
</ul>
|
@ -0,0 +1,73 @@
|
||||
<p>给你两个长度相等的数组 <code>nums1</code> 和 <code>nums2</code>。</p>
|
||||
|
||||
<p>数组 <code>nums1</code> 中的每个元素都与变量 <code>x</code> 所表示的整数相加。如果 <code>x</code> 为负数,则表现为元素值的减少。</p>
|
||||
|
||||
<p>在与 <code>x</code> 相加后,<code>nums1</code> 和 <code>nums2</code> <strong>相等</strong> 。当两个数组中包含相同的整数,并且这些整数出现的频次相同时,两个数组 <strong>相等</strong> 。</p>
|
||||
|
||||
<p>返回整数 <code>x</code> 。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong><span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">nums1 = [2,6,4], nums2 = [9,7,5]</span></p>
|
||||
|
||||
<p><strong>输出:</strong><span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">3</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>与 3 相加后,<code>nums1</code> 和 <code>nums2</code> 相等。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong><span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">nums1 = [10], nums2 = [5]</span></p>
|
||||
|
||||
<p><strong>输出:</strong><span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">-5</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>与 <code>-5</code> 相加后,<code>nums1</code> 和 <code>nums2</code> 相等。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong><span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">nums1 = [1,1,1,1], nums2 = [1,1,1,1]</span></p>
|
||||
|
||||
<p><strong>输出:</strong><span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">0</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>与 0 相加后,<code>nums1</code> 和 <code>nums2</code> 相等。</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums1.length == nums2.length <= 100</code></li>
|
||||
<li><code>0 <= nums1[i], nums2[i] <= 1000</code></li>
|
||||
<li>测试用例以这样的方式生成:存在一个整数 <code>x</code>,使得 <code>nums1</code> 中的每个元素都与 <code>x</code> 相加后,<code>nums1</code> 与 <code>nums2</code> 相等。</li>
|
||||
</ul>
|
56
leetcode-cn/problem (Chinese)/找出与数组相加的整数 II [find-the-integer-added-to-array-ii].html
Normal file
56
leetcode-cn/problem (Chinese)/找出与数组相加的整数 II [find-the-integer-added-to-array-ii].html
Normal file
@ -0,0 +1,56 @@
|
||||
<p>给你两个整数数组 <code>nums1</code> 和 <code>nums2</code>。</p>
|
||||
|
||||
<p>从 <code>nums1</code> 中移除两个元素,并且所有其他元素都与变量 <code>x</code> 所表示的整数相加。如果 <code>x</code> 为负数,则表现为元素值的减少。</p>
|
||||
|
||||
<p>执行上述操作后,<code>nums1</code> 和 <code>nums2</code> <strong>相等</strong> 。当两个数组中包含相同的整数,并且这些整数出现的频次相同时,两个数组 <strong>相等</strong> 。</p>
|
||||
|
||||
<p>返回能够实现数组相等的 <strong>最小 </strong>整数<em> </em><code>x</code><em> </em>。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong><span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">nums1 = [4,20,16,12,8], nums2 = [14,18,10]</span></p>
|
||||
|
||||
<p><strong>输出:</strong><span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">-2</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>移除 <code>nums1</code> 中下标为 <code>[0,4]</code> 的两个元素,并且每个元素与 <code>-2</code> 相加后,<code>nums1</code> 变为 <code>[18,14,10]</code> ,与 <code>nums2</code> 相等。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong><span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">nums1 = [3,5,5,3], nums2 = [7,7]</span></p>
|
||||
|
||||
<p><strong>输出:</strong><span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">2</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>移除 <code>nums1</code> 中下标为 <code>[0,3]</code> 的两个元素,并且每个元素与 <code>2</code> 相加后,<code>nums1</code> 变为 <code>[7,7]</code> ,与 <code>nums2</code> 相等。</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>3 <= nums1.length <= 200</code></li>
|
||||
<li><code>nums2.length == nums1.length - 2</code></li>
|
||||
<li><code>0 <= nums1[i], nums2[i] <= 1000</code></li>
|
||||
<li>测试用例以这样的方式生成:存在一个整数 <code>x</code>,<code>nums1</code> 中的每个元素都与 <code>x</code> 相加后,再移除两个元素,<code>nums1</code> 可以与 <code>nums2</code> 相等。</li>
|
||||
</ul>
|
56
leetcode-cn/problem (Chinese)/找出唯一性数组的中位数 [find-the-median-of-the-uniqueness-array].html
Normal file
56
leetcode-cn/problem (Chinese)/找出唯一性数组的中位数 [find-the-median-of-the-uniqueness-array].html
Normal file
@ -0,0 +1,56 @@
|
||||
<p>给你一个整数数组 <code>nums</code> 。数组 <code>nums</code> 的<strong> 唯一性数组</strong> 是一个按元素从小到大排序的数组,包含了 <code>nums</code> 的所有<span data-keyword="subarray-nonempty">非空子数组中</span>不同元素的个数。</p>
|
||||
|
||||
<p>换句话说,这是由所有 <code>0 <= i <= j < nums.length</code> 的 <code>distinct(nums[i..j])</code> 组成的递增数组。</p>
|
||||
|
||||
<p>其中,<code>distinct(nums[i..j])</code> 表示从下标 <code>i</code> 到下标 <code>j</code> 的子数组中不同元素的数量。</p>
|
||||
|
||||
<p>返回 <code>nums</code> <strong>唯一性数组 </strong>的 <strong>中位数 </strong>。</p>
|
||||
|
||||
<p><strong>注意</strong>,数组的 <strong>中位数 </strong>定义为有序数组的中间元素。如果有两个中间元素,则取值较小的那个。<!-- notionvc: 7e0f5178-4273-4a82-95ce-3395297921dc --></p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong><span class="example-io">nums = [1,2,3]</span></p>
|
||||
|
||||
<p><strong>输出:</strong><span class="example-io">1</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p><code>nums</code> 的唯一性数组为 <code>[distinct(nums[0..0]), distinct(nums[1..1]), distinct(nums[2..2]), distinct(nums[0..1]), distinct(nums[1..2]), distinct(nums[0..2])]</code>,即 <code>[1, 1, 1, 2, 2, 3]</code> 。唯一性数组的中位数为 1 ,因此答案是 1 。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong><span class="example-io">nums = [3,4,3,4,5]</span></p>
|
||||
|
||||
<p><strong>输出:</strong><span class="example-io">2</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p><code>nums</code> 的唯一性数组为 <code>[1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3]</code> 。唯一性数组的中位数为 2 ,因此答案是 2 。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong><span class="example-io">nums = [4,3,5,4]</span></p>
|
||||
|
||||
<p><strong>输出:</strong><span class="example-io">2</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p><code>nums</code> 的唯一性数组为 <code>[1, 1, 1, 1, 2, 2, 2, 3, 3, 3]</code> 。唯一性数组的中位数为 2 ,因此答案是 2 。</p>
|
||||
</div>
|
||||
|
||||
<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>5</sup></code></li>
|
||||
</ul>
|
61
leetcode-cn/problem (Chinese)/找出所有稳定的二进制数组 I [find-all-possible-stable-binary-arrays-i].html
Normal file
61
leetcode-cn/problem (Chinese)/找出所有稳定的二进制数组 I [find-all-possible-stable-binary-arrays-i].html
Normal file
@ -0,0 +1,61 @@
|
||||
<p>给你 3 个正整数 <code>zero</code> ,<code>one</code> 和 <code>limit</code> 。</p>
|
||||
|
||||
<p>一个 <span data-keyword="binary-array">二进制数组</span> <code>arr</code> 如果满足以下条件,那么我们称它是 <strong>稳定的</strong> :</p>
|
||||
|
||||
<ul>
|
||||
<li>0 在 <code>arr</code> 中出现次数 <strong>恰好</strong> 为<strong> </strong><code>zero</code> 。</li>
|
||||
<li>1 在 <code>arr</code> 中出现次数 <strong>恰好</strong> 为 <code>one</code> 。</li>
|
||||
<li><code>arr</code> 中每个长度超过 <code>limit</code> 的 <span data-keyword="subarray-nonempty">子数组</span> 都 <strong>同时</strong> 包含 0 和 1 。</li>
|
||||
</ul>
|
||||
|
||||
<p>请你返回 <strong>稳定</strong> 二进制数组的 <em>总</em> 数目。</p>
|
||||
|
||||
<p>由于答案可能很大,将它对 <code>10<sup>9</sup> + 7</code> <b>取余</b> 后返回。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><span class="example-io"><b>输入:</b>zero = 1, one = 1, limit = 2</span></p>
|
||||
|
||||
<p><span class="example-io"><b>输出:</b>2</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>两个稳定的二进制数组为 <code>[1,0]</code> 和 <code>[0,1]</code> ,两个数组都有一个 0 和一个 1 ,且没有子数组长度大于 2 。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong><span class="example-io">zero = 1, one = 2, limit = 1</span></p>
|
||||
|
||||
<p><span class="example-io"><b>输出:</b>1</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>唯一稳定的二进制数组是 <code>[1,0,1]</code> 。</p>
|
||||
|
||||
<p>二进制数组 <code>[1,1,0]</code> 和 <code>[0,1,1]</code> 都有长度为 2 且元素全都相同的子数组,所以它们不稳定。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><span class="example-io"><b>输入:</b>zero = 3, one = 3, limit = 2</span></p>
|
||||
|
||||
<p><span class="example-io"><b>输出:</b>14</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>所有稳定的二进制数组包括 <code>[0,0,1,0,1,1]</code> ,<code>[0,0,1,1,0,1]</code> ,<code>[0,1,0,0,1,1]</code> ,<code>[0,1,0,1,0,1]</code> ,<code>[0,1,0,1,1,0]</code> ,<code>[0,1,1,0,0,1]</code> ,<code>[0,1,1,0,1,0]</code> ,<code>[1,0,0,1,0,1]</code> ,<code>[1,0,0,1,1,0]</code> ,<code>[1,0,1,0,0,1]</code> ,<code>[1,0,1,0,1,0]</code> ,<code>[1,0,1,1,0,0]</code> ,<code>[1,1,0,0,1,0]</code> 和 <code>[1,1,0,1,0,0]</code> 。</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= zero, one, limit <= 200</code></li>
|
||||
</ul>
|
61
leetcode-cn/problem (Chinese)/找出所有稳定的二进制数组 II [find-all-possible-stable-binary-arrays-ii].html
Normal file
61
leetcode-cn/problem (Chinese)/找出所有稳定的二进制数组 II [find-all-possible-stable-binary-arrays-ii].html
Normal file
@ -0,0 +1,61 @@
|
||||
<p>给你 3 个正整数 <code>zero</code> ,<code>one</code> 和 <code>limit</code> 。</p>
|
||||
|
||||
<p>一个 <span data-keyword="binary-array">二进制数组</span> <code>arr</code> 如果满足以下条件,那么我们称它是 <strong>稳定的</strong> :</p>
|
||||
|
||||
<ul>
|
||||
<li>0 在 <code>arr</code> 中出现次数 <strong>恰好</strong> 为<strong> </strong><code>zero</code> 。</li>
|
||||
<li>1 在 <code>arr</code> 中出现次数 <strong>恰好</strong> 为 <code>one</code> 。</li>
|
||||
<li><code>arr</code> 中每个长度超过 <code>limit</code> 的 <span data-keyword="subarray-nonempty">子数组</span> 都 <strong>同时</strong> 包含 0 和 1 。</li>
|
||||
</ul>
|
||||
|
||||
<p>请你返回 <strong>稳定</strong> 二进制数组的 <em>总</em> 数目。</p>
|
||||
|
||||
<p>由于答案可能很大,将它对 <code>10<sup>9</sup> + 7</code> <b>取余</b> 后返回。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><span class="example-io"><b>输入:</b>zero = 1, one = 1, limit = 2</span></p>
|
||||
|
||||
<p><span class="example-io"><b>输出:</b>2</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>两个稳定的二进制数组为 <code>[1,0]</code> 和 <code>[0,1]</code> ,两个数组都有一个 0 和一个 1 ,且没有子数组长度大于 2 。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong><span class="example-io">zero = 1, one = 2, limit = 1</span></p>
|
||||
|
||||
<p><span class="example-io"><b>输出:</b>1</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>唯一稳定的二进制数组是 <code>[1,0,1]</code> 。</p>
|
||||
|
||||
<p>二进制数组 <code>[1,1,0]</code> 和 <code>[0,1,1]</code> 都有长度为 2 且元素全都相同的子数组,所以它们不稳定。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><span class="example-io"><b>输入:</b>zero = 3, one = 3, limit = 2</span></p>
|
||||
|
||||
<p><span class="example-io"><b>输出:</b>14</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>所有稳定的二进制数组包括 <code>[0,0,1,0,1,1]</code> ,<code>[0,0,1,1,0,1]</code> ,<code>[0,1,0,0,1,1]</code> ,<code>[0,1,0,1,0,1]</code> ,<code>[0,1,0,1,1,0]</code> ,<code>[0,1,1,0,0,1]</code> ,<code>[0,1,1,0,1,0]</code> ,<code>[1,0,0,1,0,1]</code> ,<code>[1,0,0,1,1,0]</code> ,<code>[1,0,1,0,0,1]</code> ,<code>[1,0,1,0,1,0]</code> ,<code>[1,0,1,1,0,0]</code> ,<code>[1,1,0,0,1,0]</code> 和 <code>[1,1,0,1,0,0]</code> 。</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= zero, one, limit <= 1000</code></li>
|
||||
</ul>
|
@ -0,0 +1,37 @@
|
||||
<p>给你两个整数 <code>n</code> 和 <code>x</code> 。你需要构造一个长度为 <code>n</code> 的 <strong>正整数 </strong>数组 <code>nums</code> ,对于所有 <code>0 <= i < n - 1</code> ,满足 <code>nums[i + 1]</code><strong> 大于 </strong><code>nums[i]</code> ,并且数组 <code>nums</code> 中所有元素的按位 <code>AND</code> 运算结果为 <code>x</code> 。</p>
|
||||
|
||||
<p>返回 <code>nums[n - 1]</code> 可能的<strong> 最小 </strong>值。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong><span class="example-io">n = 3, x = 4</span></p>
|
||||
|
||||
<p><strong>输出:</strong><span class="example-io">6</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>数组 <code>nums</code> 可以是 <code>[4,5,6]</code> ,最后一个元素为 <code>6</code> 。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong><span class="example-io">n = 2, x = 7</span></p>
|
||||
|
||||
<p><strong>输出:</strong><span class="example-io">15</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>数组 <code>nums</code> 可以是 <code>[7,15]</code> ,最后一个元素为 <code>15</code> 。</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n, x <= 10<sup>8</sup></code></li>
|
||||
</ul>
|
40
leetcode-cn/problem (Chinese)/替换字符可以得到的最晚时间 [latest-time-you-can-obtain-after-replacing-characters].html
Normal file
40
leetcode-cn/problem (Chinese)/替换字符可以得到的最晚时间 [latest-time-you-can-obtain-after-replacing-characters].html
Normal file
@ -0,0 +1,40 @@
|
||||
<p>给你一个字符串 <code>s</code>,表示一个 12 小时制的时间格式,其中一些数字(可能没有)被 <code>"?"</code> 替换。</p>
|
||||
|
||||
<p>12 小时制时间格式为 <code>"HH:MM"</code> ,其中 <code>HH</code> 的取值范围为 <code>00</code> 至 <code>11</code>,<code>MM</code> 的取值范围为 <code>00</code> 至 <code>59</code>。最早的时间为 <code>00:00</code>,最晚的时间为 <code>11:59</code>。</p>
|
||||
|
||||
<p>你需要将 <code>s</code> 中的<strong> 所有</strong> <code>"?"</code> 字符替换为数字,使得结果字符串代表的时间是一个<strong> 有效 </strong>的 12 小时制时间,并且是可能的 <strong>最晚 </strong>时间。</p>
|
||||
|
||||
<p>返回结果字符串。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong> <span class="example-io">s = "1?:?4"</span></p>
|
||||
|
||||
<p><strong>输出:</strong> <span class="example-io">"11:54"</span></p>
|
||||
|
||||
<p><strong>解释:</strong> 通过替换 <code>"?"</code> 字符,可以得到的最晚12小时制时间是 <code>"11:54"</code>。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong> <span class="example-io">s = "0?:5?"</span></p>
|
||||
|
||||
<p><strong>输出:</strong> <span class="example-io">"09:59"</span></p>
|
||||
|
||||
<p><strong>解释:</strong> 通过替换 <code>"?"</code> 字符,可以得到的最晚12小时制时间是 <code>"09:59"</code>。</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>s.length == 5</code></li>
|
||||
<li><code>s[2]</code> 是字符 <code>":"</code></li>
|
||||
<li>除 <code>s[2]</code> 外,其他字符都是数字或 <code>"?"</code></li>
|
||||
<li>输入保证在替换 <code>"?"</code> 字符后至少存在一个介于 <code>"00:00"</code> 和 <code>"11:59"</code> 之间的时间。</li>
|
||||
</ul>
|
@ -0,0 +1,57 @@
|
||||
<p>给你一个 <code>n</code> 个节点的无向带权图,节点编号为 <code>0</code> 到 <code>n - 1</code> 。图中总共有 <code>m</code> 条边,用二维数组 <code>edges</code> 表示,其中 <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> 表示节点 <code>a<sub>i</sub></code> 和 <code>b<sub>i</sub></code> 之间有一条边权为 <code>w<sub>i</sub></code> 的边。</p>
|
||||
|
||||
<p>对于节点 <code>0</code> 为出发点,节点 <code>n - 1</code> 为结束点的所有最短路,你需要返回一个长度为 <code>m</code> 的 <strong>boolean</strong> 数组 <code>answer</code> ,如果 <code>edges[i]</code> <strong>至少</strong> 在其中一条最短路上,那么 <code>answer[i]</code> 为 <code>true</code> ,否则 <code>answer[i]</code> 为 <code>false</code> 。</p>
|
||||
|
||||
<p>请你返回数组 <code>answer</code> 。</p>
|
||||
|
||||
<p><b>注意</b>,图可能不连通。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/03/05/graph35drawio-1.png" style="height: 129px; width: 250px;" /></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><span class="example-io"><b>输入:</b>n = 6, edges = [[0,1,4],[0,2,1],[1,3,2],[1,4,3],[1,5,1],[2,3,1],[3,5,3],[4,5,2]]</span></p>
|
||||
|
||||
<p><span class="example-io"><b>输出:</b>[true,true,true,false,true,true,true,false]</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>以下为节点 0 出发到达节点 5 的 <strong>所有</strong> 最短路:</p>
|
||||
|
||||
<ul>
|
||||
<li>路径 <code>0 -> 1 -> 5</code> :边权和为 <code>4 + 1 = 5</code> 。</li>
|
||||
<li>路径 <code>0 -> 2 -> 3 -> 5</code> :边权和为 <code>1 + 1 + 3 = 5</code> 。</li>
|
||||
<li>路径 <code>0 -> 2 -> 3 -> 1 -> 5</code> :边权和为 <code>1 + 1 + 2 + 1 = 5</code> 。</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/03/05/graphhhh.png" style="width: 185px; height: 136px;" /></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><span class="example-io"><b>输入:</b>n = 4, edges = [[2,0,1],[0,1,1],[0,3,4],[3,2,2]]</span></p>
|
||||
|
||||
<p><span class="example-io"><b>输出:</b>[true,false,false,true]</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>只有一条从节点 0 出发到达节点 3 的最短路 <code>0 -> 2 -> 3</code> ,边权和为 <code>1 + 2 = 3</code> 。</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= n <= 5 * 10<sup>4</sup></code></li>
|
||||
<li><code>m == edges.length</code></li>
|
||||
<li><code>1 <= m <= min(5 * 10<sup>4</sup>, n * (n - 1) / 2)</code></li>
|
||||
<li><code>0 <= a<sub>i</sub>, b<sub>i</sub> < n</code></li>
|
||||
<li><code>a<sub>i</sub> != b<sub>i</sub></code></li>
|
||||
<li><code>1 <= w<sub>i</sub> <= 10<sup>5</sup></code></li>
|
||||
<li>图中没有重边。</li>
|
||||
</ul>
|
@ -0,0 +1,130 @@
|
||||
<p>给你一个二维 <code>3 x 3</code> 的矩阵 <code>grid</code> ,每个格子都是一个字符,要么是 <code>'B'</code> ,要么是 <code>'W'</code> 。字符 <code>'W'</code> 表示白色,字符 <code>'B'</code> 表示黑色。</p>
|
||||
|
||||
<p>你的任务是改变 <strong>至多一个</strong> 格子的颜色,使得矩阵中存在一个 <code>2 x 2</code> 颜色完全相同的正方形。<!-- notionvc: adf957e1-fa0f-40e5-9a2e-933b95e276a7 --></p>
|
||||
|
||||
<p>如果可以得到一个相同颜色的 <code>2 x 2</code> 正方形,那么返回 <code>true</code> ,否则返回 <code>false</code> 。</p>
|
||||
|
||||
<p> </p>
|
||||
<style type="text/css">.grid-container {
|
||||
display: grid;
|
||||
grid-template-columns: 30px 30px 30px;
|
||||
padding: 10px;
|
||||
}
|
||||
.grid-item {
|
||||
background-color: black;
|
||||
border: 1px solid gray;
|
||||
height: 30px;
|
||||
font-size: 30px;
|
||||
text-align: center;
|
||||
}
|
||||
.grid-item-white {
|
||||
background-color: white;
|
||||
}
|
||||
</style>
|
||||
<style class="darkreader darkreader--sync" media="screen" type="text/css">
|
||||
</style>
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<div class="grid-container">
|
||||
<div class="grid-item"> </div>
|
||||
|
||||
<div class="grid-item grid-item-white"> </div>
|
||||
|
||||
<div class="grid-item"> </div>
|
||||
|
||||
<div class="grid-item"> </div>
|
||||
|
||||
<div class="grid-item grid-item-white"> </div>
|
||||
|
||||
<div class="grid-item grid-item-white"> </div>
|
||||
|
||||
<div class="grid-item"> </div>
|
||||
|
||||
<div class="grid-item grid-item-white"> </div>
|
||||
|
||||
<div class="grid-item"> </div>
|
||||
</div>
|
||||
|
||||
<div class="example-block">
|
||||
<p><span class="example-io"><b>输入:</b>grid = [["B","W","B"],["B","W","W"],["B","W","B"]]</span></p>
|
||||
|
||||
<p><span class="example-io"><b>输出:</b>true</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>修改 <code>grid[0][2]</code> 的颜色,可以满足要求。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<div class="grid-container">
|
||||
<div class="grid-item"> </div>
|
||||
|
||||
<div class="grid-item grid-item-white"> </div>
|
||||
|
||||
<div class="grid-item"> </div>
|
||||
|
||||
<div class="grid-item grid-item-white"> </div>
|
||||
|
||||
<div class="grid-item"> </div>
|
||||
|
||||
<div class="grid-item grid-item-white"> </div>
|
||||
|
||||
<div class="grid-item"> </div>
|
||||
|
||||
<div class="grid-item grid-item-white"> </div>
|
||||
|
||||
<div class="grid-item"> </div>
|
||||
</div>
|
||||
|
||||
<div class="example-block">
|
||||
<p><span class="example-io"><b>输入:</b>grid = [["B","W","B"],["W","B","W"],["B","W","B"]]</span></p>
|
||||
|
||||
<p><span class="example-io"><b>输出:</b>false</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>只改变一个格子颜色无法满足要求。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 3:</strong></p>
|
||||
|
||||
<div class="grid-container">
|
||||
<div class="grid-item"> </div>
|
||||
|
||||
<div class="grid-item grid-item-white"> </div>
|
||||
|
||||
<div class="grid-item"> </div>
|
||||
|
||||
<div class="grid-item"> </div>
|
||||
|
||||
<div class="grid-item grid-item-white"> </div>
|
||||
|
||||
<div class="grid-item grid-item-white"> </div>
|
||||
|
||||
<div class="grid-item"> </div>
|
||||
|
||||
<div class="grid-item grid-item-white"> </div>
|
||||
|
||||
<div class="grid-item grid-item-white"> </div>
|
||||
</div>
|
||||
|
||||
<div class="example-block">
|
||||
<p><span class="example-io"><b>输入:</b>grid = [["B","W","B"],["B","W","W"],["B","W","W"]]</span></p>
|
||||
|
||||
<p><span class="example-io"><b>输出:</b>true</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p><code>grid</code> 已经包含一个 <code>2 x 2</code> 颜色相同的正方形了。<!-- notionvc: 9a8b2d3d-1e73-457a-abe0-c16af51ad5c2 --></p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>grid.length == 3</code></li>
|
||||
<li><code>grid[i].length == 3</code></li>
|
||||
<li><code>grid[i][j]</code> 要么是 <code>'W'</code> ,要么是 <code>'B'</code> 。</li>
|
||||
</ul>
|
166
leetcode-cn/problem (Chinese)/直角三角形 [right-triangles].html
Normal file
166
leetcode-cn/problem (Chinese)/直角三角形 [right-triangles].html
Normal file
@ -0,0 +1,166 @@
|
||||
<p>给你一个二维 boolean 矩阵 <code>grid</code> 。</p>
|
||||
|
||||
<p>请你返回使用 <code>grid</code> 中的 3 个元素可以构建的 <strong>直角三角形</strong> 数目,且满足 3 个元素值 <strong>都</strong> 为 1 。</p>
|
||||
|
||||
<p><b>注意:</b></p>
|
||||
|
||||
<ul>
|
||||
<li>如果 <code>grid</code> 中 3 个元素满足:一个元素与另一个元素在 <strong>同一行</strong>,同时与第三个元素在 <strong>同一列</strong> ,那么这 3 个元素称为一个 <strong>直角三角形</strong> 。这 3 个元素互相之间不需要相邻。</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<div style="display:flex; gap: 12px;">
|
||||
<table border="1" cellspacing="3" style="border-collapse: separate; text-align: center;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid red; --darkreader-inline-border-top: #b30000; --darkreader-inline-border-right: #b30000; --darkreader-inline-border-bottom: #b30000; --darkreader-inline-border-left: #b30000;">1</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid red; --darkreader-inline-border-top: #b30000; --darkreader-inline-border-right: #b30000; --darkreader-inline-border-bottom: #b30000; --darkreader-inline-border-left: #b30000;">1</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid red; --darkreader-inline-border-top: #b30000; --darkreader-inline-border-right: #b30000; --darkreader-inline-border-bottom: #b30000; --darkreader-inline-border-left: #b30000;">1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">1</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<table border="1" cellspacing="3" style="border-collapse: separate; text-align: center;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">1</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid red; --darkreader-inline-border-top: #b30000; --darkreader-inline-border-right: #b30000; --darkreader-inline-border-bottom: #b30000; --darkreader-inline-border-left: #b30000;">1</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid red; --darkreader-inline-border-top: #b30000; --darkreader-inline-border-right: #b30000; --darkreader-inline-border-bottom: #b30000; --darkreader-inline-border-left: #b30000;">1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid red; --darkreader-inline-border-top: #b30000; --darkreader-inline-border-right: #b30000; --darkreader-inline-border-bottom: #b30000; --darkreader-inline-border-left: #b30000;">1</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="example-block">
|
||||
<p><span class="example-io"><b>输入:</b>grid = [[0,1,0],[0,1,1],[0,1,0]]</span></p>
|
||||
|
||||
<p><span class="example-io"><b>输出:</b>2</span></p>
|
||||
|
||||
<p><b>解释:</b></p>
|
||||
|
||||
<p>有 2 个直角三角形。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<div style="display:flex; gap: 12px;">
|
||||
<table border="1" cellspacing="3" style="border-collapse: separate; text-align: center;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">1</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">1</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">1</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="example-block">
|
||||
<p><span class="example-io"><b>输入:</b>grid = [[1,0,0,0],[0,1,0,1],[1,0,0,0]]</span></p>
|
||||
|
||||
<p><span class="example-io"><b>输出:</b>0</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>没有直角三角形。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 3:</strong></p>
|
||||
|
||||
<div style="display:flex; gap: 12px;">
|
||||
<table border="1" cellspacing="3" style="border-collapse: separate; text-align: center;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid red; --darkreader-inline-border-top: #b30000; --darkreader-inline-border-right: #b30000; --darkreader-inline-border-bottom: #b30000; --darkreader-inline-border-left: #b30000;">1</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid red; --darkreader-inline-border-top: #b30000; --darkreader-inline-border-right: #b30000; --darkreader-inline-border-bottom: #b30000; --darkreader-inline-border-left: #b30000;">1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid red; --darkreader-inline-border-top: #b30000; --darkreader-inline-border-right: #b30000; --darkreader-inline-border-bottom: #b30000; --darkreader-inline-border-left: #b30000;">1</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">1</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<table border="1" cellspacing="3" style="border-collapse: separate; text-align: center;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid red; --darkreader-inline-border-top: #b30000; --darkreader-inline-border-right: #b30000; --darkreader-inline-border-bottom: #b30000; --darkreader-inline-border-left: #b30000;">1</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid red; --darkreader-inline-border-top: #b30000; --darkreader-inline-border-right: #b30000; --darkreader-inline-border-bottom: #b30000; --darkreader-inline-border-left: #b30000;">1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">1</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid red; --darkreader-inline-border-top: #b30000; --darkreader-inline-border-right: #b30000; --darkreader-inline-border-bottom: #b30000; --darkreader-inline-border-left: #b30000;">1</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="example-block">
|
||||
<p><span class="example-io"><b>输入:</b>grid = [[1,0,1],[1,0,0],[1,0,0]]</span></p>
|
||||
|
||||
<p><strong>输出:</strong>2</p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>有两个直角三角形。</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= grid.length <= 1000</code></li>
|
||||
<li><code>1 <= grid[i].length <= 1000</code></li>
|
||||
<li><code>0 <= grid[i][j] <= 1</code></li>
|
||||
</ul>
|
50
leetcode-cn/problem (Chinese)/统计特殊字母的数量 I [count-the-number-of-special-characters-i].html
Normal file
50
leetcode-cn/problem (Chinese)/统计特殊字母的数量 I [count-the-number-of-special-characters-i].html
Normal file
@ -0,0 +1,50 @@
|
||||
<p>给你一个字符串 <code>word</code>。如果 <code>word</code> 中同时存在某个字母的小写形式和大写形式,则称这个字母为 <strong>特殊字母</strong> 。</p>
|
||||
|
||||
<p>返回 <code>word</code> 中<strong> </strong><strong>特殊字母 </strong>的数量。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong><span class="example-io">word = "aaAbcBC"</span></p>
|
||||
|
||||
<p><strong>输出:</strong><span class="example-io">3</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p><code>word</code> 中的特殊字母是 <code>'a'</code>、<code>'b'</code> 和 <code>'c'</code>。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong><span class="example-io">word = "abc"</span></p>
|
||||
|
||||
<p><strong>输出:</strong><span class="example-io">0</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p><code>word</code> 中不存在大小写形式同时出现的字母。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong><span class="example-io">word = "abBCab"</span></p>
|
||||
|
||||
<p><strong>输出:</strong>1</p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p><code>word</code> 中唯一的特殊字母是 <code>'b'</code>。</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= word.length <= 50</code></li>
|
||||
<li><code>word</code> 仅由小写和大写英文字母组成。</li>
|
||||
</ul>
|
50
leetcode-cn/problem (Chinese)/统计特殊字母的数量 II [count-the-number-of-special-characters-ii].html
Normal file
50
leetcode-cn/problem (Chinese)/统计特殊字母的数量 II [count-the-number-of-special-characters-ii].html
Normal file
@ -0,0 +1,50 @@
|
||||
<p>给你一个字符串 <code>word</code>。如果 <code>word</code> 中同时出现某个字母 <code>c</code> 的小写形式和大写形式,并且<strong> 每个 </strong>小写形式的 <code>c</code> 都出现在第一个大写形式的 <code>c</code> 之前,则称字母 <code>c</code> 是一个 <strong>特殊字母</strong> 。</p>
|
||||
|
||||
<p>返回 <code>word</code> 中 <strong>特殊字母</strong> 的数量。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong><span class="example-io">word = "aaAbcBC"</span></p>
|
||||
|
||||
<p><strong>输出:</strong><span class="example-io">3</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>特殊字母是 <code>'a'</code>、<code>'b'</code> 和 <code>'c'</code>。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong><span class="example-io">word = "abc"</span></p>
|
||||
|
||||
<p><strong>输出:</strong><span class="example-io">0</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p><code>word</code> 中不存在特殊字母。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong><span class="example-io">word = "AbBCab"</span></p>
|
||||
|
||||
<p><strong>输出:</strong><span class="example-io">0</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p><code>word</code> 中不存在特殊字母。</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= word.length <= 2 * 10<sup>5</sup></code></li>
|
||||
<li><code>word</code> 仅由小写和大写英文字母组成。</li>
|
||||
</ul>
|
@ -0,0 +1,82 @@
|
||||
<p>给你一个二维整数数组 <code>point</code> ,其中 <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> 表示二维平面内的一个点。同时给你一个整数 <code>w</code> 。你需要用矩形 <strong>覆盖所有</strong> 点。</p>
|
||||
|
||||
<p>每个矩形的左下角在某个点 <code>(x<sub>1</sub>, 0)</code> 处,且右上角在某个点 <code>(x<sub>2</sub>, y<sub>2</sub>)</code> 处,其中 <code>x<sub>1</sub> <= x<sub>2</sub></code> 且 <code>y<sub>2</sub> >= 0</code> ,同时对于每个矩形都 <strong>必须</strong> 满足 <code>x<sub>2</sub> - x<sub>1</sub> <= w</code> 。</p>
|
||||
|
||||
<p>如果一个点在矩形内或者在边上,我们说这个点被矩形覆盖了。</p>
|
||||
|
||||
<p>请你在确保每个点都 <strong>至少</strong> 被一个矩形覆盖的前提下,<strong>最少</strong> 需要多少个矩形。</p>
|
||||
|
||||
<p><strong>注意:</strong>一个点可以被多个矩形覆盖。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/03/04/screenshot-from-2024-03-04-20-33-05.png" style="width: 205px; height: 300px;" /></p>
|
||||
|
||||
<div class="example-block" style="border-color: var(--border-tertiary); border-left-width: 2px; color: var(--text-secondary); margin-bottom: 1rem; margin-top: 1rem; overflow: visible; padding-left: 1rem;">
|
||||
<p style=""><span class="example-io" style="font-size: 8.75px;"><b>输入:</b></span><span class="example-io" style="font-size: 0.85rem; font-family: Menlo, sans-serif;">points = [[2,1],[1,0],[1,4],[1,8],[3,5],[4,6]], w = 1</span></p>
|
||||
|
||||
<p style=""><span class="example-io" style="font-size: 8.75px;"><b>输出:</b></span><span class="example-io" style="font-size: 0.85rem; font-family: Menlo, sans-serif;">2</span></p>
|
||||
|
||||
<p style="font-size: 0.875rem;"><strong>解释:</strong></p>
|
||||
|
||||
<p style="font-size: 0.875rem;">上图展示了一种可行的矩形放置方案:</p>
|
||||
|
||||
<ul style="font-size: 0.875rem;">
|
||||
<li>一个矩形的左下角在 <code>(1, 0)</code> ,右上角在 <code>(2, 8)</code> 。</li>
|
||||
<li>一个矩形的左下角在 <code>(3, 0)</code> ,右上角在 <code>(4, 8)</code> 。</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/03/04/screenshot-from-2024-03-04-18-59-12.png" style="width: 260px; height: 250px;" /></p>
|
||||
|
||||
<div class="example-block" style="border-color: var(--border-tertiary); border-left-width: 2px; color: var(--text-secondary); margin-bottom: 1rem; margin-top: 1rem; overflow: visible; padding-left: 1rem;">
|
||||
<p style=""><span class="example-io" style="font-size: 8.75px;"><b>输入:</b></span><span class="example-io" style="font-size: 0.85rem; font-family: Menlo, sans-serif;">points = [[0,0],[1,1],[2,2],[3,3],[4,4],[5,5],[6,6]], w = 2</span></p>
|
||||
|
||||
<p style=""><span class="example-io" style="font-size: 8.75px;"><b>输出:</b></span><span class="example-io" style="font-size: 0.85rem; font-family: Menlo, sans-serif;">3</span></p>
|
||||
|
||||
<p style="font-size: 0.875rem;"><b>解释:</b></p>
|
||||
|
||||
<p style="font-size: 0.875rem;">上图展示了一种可行的矩形放置方案:</p>
|
||||
|
||||
<ul style="font-size: 0.875rem;">
|
||||
<li>一个矩形的左下角在 <code>(0, 0)</code> ,右上角在 <code>(2, 2)</code> 。</li>
|
||||
<li>一个矩形的左下角在 <code>(3, 0)</code> ,右上角在 <code>(5, 5)</code> 。</li>
|
||||
<li>一个矩形的左下角在 <code>(6, 0)</code> ,右上角在 <code>(6, 6)</code> 。</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 3:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/03/04/screenshot-from-2024-03-04-20-24-03.png" style="height: 150px; width: 127px;" /></p>
|
||||
|
||||
<div class="example-block" style="border-color: var(--border-tertiary); border-left-width: 2px; color: var(--text-secondary); margin-bottom: 1rem; margin-top: 1rem; overflow: visible; padding-left: 1rem;">
|
||||
<p style=""><span class="example-io" style="font-size: 8.75px;"><b>输入:</b></span><span class="example-io" style="font-size: 0.85rem; font-family: Menlo, sans-serif;">points = [[2,3],[1,2]], w = 0</span></p>
|
||||
|
||||
<p style=""><span class="example-io" style="font-size: 8.75px;"><b>输出:</b></span><span class="example-io" style="font-size: 0.85rem; font-family: Menlo, sans-serif;">2</span></p>
|
||||
|
||||
<p style="font-size: 0.875rem;"><strong>解释:</strong></p>
|
||||
|
||||
<p style="font-size: 0.875rem;">上图展示了一种可行的矩形放置方案:</p>
|
||||
|
||||
<ul style="font-size: 0.875rem;">
|
||||
<li>一个矩形的左下角在 <code>(1, 0)</code> ,右上角在 <code>(1, 2)</code> 。</li>
|
||||
<li>一个矩形的左下角在 <code>(2, 0)</code> ,右上角在 <code>(2, 3)</code> 。</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= points.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>points[i].length == 2</code></li>
|
||||
<li><code>0 <= x<sub>i</sub> == points[i][0] <= 10<sup>9</sup></code></li>
|
||||
<li><code>0 <= y<sub>i</sub> == points[i][1] <= 10<sup>9</sup></code></li>
|
||||
<li><code>0 <= w <= 10<sup>9</sup></code></li>
|
||||
<li>所有点坐标 <code>(x<sub>i</sub>, y<sub>i</sub>)</code> 互不相同。</li>
|
||||
</ul>
|
75
leetcode-cn/problem (Chinese)/访问消失节点的最少时间 [minimum-time-to-visit-disappearing-nodes].html
Normal file
75
leetcode-cn/problem (Chinese)/访问消失节点的最少时间 [minimum-time-to-visit-disappearing-nodes].html
Normal file
@ -0,0 +1,75 @@
|
||||
<p>给你一个二维数组 <code>edges</code> 表示一个 <code>n</code> 个点的无向图,其中 <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub>, length<sub>i</sub>]</code> 表示节点 <code>u<sub>i</sub></code> 和节点 <code>v<sub>i</sub></code> 之间有一条需要 <code>length<sub>i</sub></code> 单位时间通过的无向边。</p>
|
||||
|
||||
<p>同时给你一个数组 <code>disappear</code> ,其中 <code>disappear[i]</code> 表示节点 <code>i</code> 从图中消失的时间点,在那一刻及以后,你无法再访问这个节点。</p>
|
||||
|
||||
<p><strong>注意</strong>,图有可能一开始是不连通的,两个节点之间也可能有多条边。</p>
|
||||
|
||||
<p>请你返回数组 <code>answer</code> ,<code>answer[i]</code> 表示从节点 <code>0</code> 到节点 <code>i</code> 需要的 <strong>最少</strong> 单位时间。如果从节点 <code>0</code> 出发 <strong>无法</strong> 到达节点 <code>i</code> ,那么 <code>answer[i]</code> 为 <code>-1</code> 。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<p><img 10px="" alt="" padding:="" src="https://assets.leetcode.com/uploads/2024/03/09/example1.png" style="width: 350px; height: 210px;" /></p>
|
||||
|
||||
<div class="example-block" style="border-color: var(--border-tertiary); border-left-width: 2px; color: var(--text-secondary); margin-bottom: 1rem; margin-top: 1rem; overflow: visible; padding-left: 1rem;">
|
||||
<p style=""><span class="example-io" style="font-size: 8.75px;"><b>输入:</b></span><span class="example-io" style="font-size: 0.85rem; font-family: Menlo, sans-serif;">n = 3, edges = [[0,1,2],[1,2,1],[0,2,4]], disappear = [1,1,5]</span></p>
|
||||
|
||||
<p style=""><span class="example-io" style="font-size: 8.75px;"><b>输出:</b></span><span class="example-io" style="font-size: 0.85rem; font-family: Menlo, sans-serif;">[0,-1,4]</span></p>
|
||||
|
||||
<p style="font-size: 0.875rem;"><strong>解释:</strong></p>
|
||||
|
||||
<p style="font-size: 0.875rem;">我们从节点 0 出发,目的是用最少的时间在其他节点消失之前到达它们。</p>
|
||||
|
||||
<ul style="font-size: 0.875rem;">
|
||||
<li>对于节点 0 ,我们不需要任何时间,因为它就是我们的起点。</li>
|
||||
<li>对于节点 1 ,我们需要至少 2 单位时间,通过 <code>edges[0]</code> 到达。但当我们到达的时候,它已经消失了,所以我们无法到达它。</li>
|
||||
<li>对于节点 2 ,我们需要至少 4 单位时间,通过 <code>edges[2]</code> 到达。</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<p><img 10px="" alt="" padding:="" src="https://assets.leetcode.com/uploads/2024/03/09/example2.png" style="width: 350px; height: 210px;" /></p>
|
||||
|
||||
<div class="example-block" style="border-color: var(--border-tertiary); border-left-width: 2px; color: var(--text-secondary); margin-bottom: 1rem; margin-top: 1rem; overflow: visible; padding-left: 1rem;">
|
||||
<p style=""><span class="example-io" style="font-size: 8.75px;"><b>输入:</b></span><span class="example-io" style="font-size: 0.85rem; font-family: Menlo, sans-serif;">n = 3, edges = [[0,1,2],[1,2,1],[0,2,4]], disappear = [1,3,5]</span></p>
|
||||
|
||||
<p style=""><span class="example-io" style="font-size: 8.75px;"><b>输出:</b></span><span class="example-io" style="font-size: 0.85rem; font-family: Menlo, sans-serif;">[0,2,3]</span></p>
|
||||
|
||||
<p style="font-size: 0.875rem;"><strong>解释:</strong></p>
|
||||
|
||||
<p style="font-size: 0.875rem;">我们从节点 0 出发,目的是用最少的时间在其他节点消失之前到达它们。</p>
|
||||
|
||||
<ul style="font-size: 0.875rem;">
|
||||
<li>对于节点 0 ,我们不需要任何时间,因为它就是我们的起点。</li>
|
||||
<li>对于节点 1 ,我们需要至少 2 单位时间,通过 <code>edges[0]</code> 到达。</li>
|
||||
<li>对于节点 2 ,我们需要至少 3 单位时间,通过 <code>edges[0]</code> 和 <code>edges[1]</code> 到达。</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 3:</strong></p>
|
||||
|
||||
<div class="example-block" style="border-color: var(--border-tertiary); border-left-width: 2px; color: var(--text-secondary); margin-bottom: 1rem; margin-top: 1rem; overflow: visible; padding-left: 1rem;">
|
||||
<p><span class="example-io"><b>输入:</b>n = 2, edges = [[0,1,1]], disappear = [1,1]</span></p>
|
||||
|
||||
<p><span class="example-io"><b>输出:</b>[0,-1]</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>当我们到达节点 1 的时候,它恰好消失,所以我们无法到达节点 1 。</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n <= 5 * 10<sup>4</sup></code></li>
|
||||
<li><code>0 <= edges.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>edges[i] == [u<sub>i</sub>, v<sub>i</sub>, length<sub>i</sub>]</code></li>
|
||||
<li><code>0 <= u<sub>i</sub>, v<sub>i</sub> <= n - 1</code></li>
|
||||
<li><code>1 <= length<sub>i</sub> <= 10<sup>5</sup></code></li>
|
||||
<li><code>disappear.length == n</code></li>
|
||||
<li><code>1 <= disappear[i] <= 10<sup>5</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,35 @@
|
||||
<p>给你一个整数数组 <code>nums</code>。</p>
|
||||
|
||||
<p>返回两个(不一定不同的)质数在 <code>nums</code> 中 <strong>下标</strong> 的 <strong>最大距离</strong>。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong> <span class="example-io">nums = [4,2,9,5,3]</span></p>
|
||||
|
||||
<p><strong>输出:</strong> <span class="example-io">3</span></p>
|
||||
|
||||
<p><strong>解释:</strong> <code>nums[1]</code>、<code>nums[3]</code> 和 <code>nums[4]</code> 是质数。因此答案是 <code>|4 - 1| = 3</code>。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong> <span class="example-io">nums = [4,8,2,8]</span></p>
|
||||
|
||||
<p><strong>输出:</strong> <span class="example-io">0</span></p>
|
||||
|
||||
<p><strong>解释:</strong> <code>nums[2]</code> 是质数。因为只有一个质数,所以答案是 <code>|2 - 2| = 0</code>。</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 3 * 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= nums[i] <= 100</code></li>
|
||||
<li>输入保证 <code>nums</code> 中至少有一个质数。</li>
|
||||
</ul>
|
74
leetcode-cn/problem (Chinese)/边界元素是最大值的子数组数目 [find-the-number-of-subarrays-where-boundary-elements-are-maximum].html
Normal file
74
leetcode-cn/problem (Chinese)/边界元素是最大值的子数组数目 [find-the-number-of-subarrays-where-boundary-elements-are-maximum].html
Normal file
@ -0,0 +1,74 @@
|
||||
<p>给你一个 <strong>正</strong> 整数数组 <code>nums</code> 。</p>
|
||||
|
||||
<p>请你求出 <code>nums</code> 中有多少个子数组,满足子数组中 <strong>第一个</strong> 和 <strong>最后一个</strong> 元素都是这个子数组中的 <strong>最大</strong> 值。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><span class="example-io"><b>输入:</b>nums = [1,4,3,3,2]</span></p>
|
||||
|
||||
<p><span class="example-io"><b>输出:</b>6</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>总共有 6 个子数组满足第一个元素和最后一个元素都是子数组中的最大值:</p>
|
||||
|
||||
<ul>
|
||||
<li>子数组 <code>[<u><em><strong>1</strong></em></u>,4,3,3,2]</code> ,最大元素为 1 ,第一个和最后一个元素都是 1 。</li>
|
||||
<li>子数组 <code>[1,<u><em><strong>4</strong></em></u>,3,3,2]</code> ,最大元素为 4 ,第一个和最后一个元素都是 4 。</li>
|
||||
<li>子数组 <code>[1,4,<u><em><strong>3</strong></em></u>,3,2]</code> ,最大元素为 3 ,第一个和最后一个元素都是 3 。</li>
|
||||
<li>子数组 <code>[1,4,3,<u><em><strong>3</strong></em></u>,2]</code> ,最大元素为 3 ,第一个和最后一个元素都是 3 。</li>
|
||||
<li>子数组 <code>[1,4,3,3,<u><em><strong>2</strong></em></u>]</code> ,最大元素为 2 ,第一个和最后一个元素都是 2 。</li>
|
||||
<li>子数组 <code>[1,4,<u><em><strong>3,3</strong></em></u>,2]</code> ,最大元素为 3 ,第一个和最后一个元素都是 3 。</li>
|
||||
</ul>
|
||||
|
||||
<p>所以我们返回 6 。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><span class="example-io"><b>输入:</b>nums = [3,3,3]</span></p>
|
||||
|
||||
<p><span class="example-io"><b>输出:</b>6</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>总共有 6 个子数组满足第一个元素和最后一个元素都是子数组中的最大值:</p>
|
||||
|
||||
<ul>
|
||||
<li>子数组 <code>[<u><em><strong>3</strong></em></u>,3,3]</code> ,最大元素为 3 ,第一个和最后一个元素都是 3 。</li>
|
||||
<li>子数组 <code>[3,<u><em><strong>3</strong></em></u>,3]</code> ,最大元素为 3 ,第一个和最后一个元素都是 3 。</li>
|
||||
<li>子数组 <code>[3,3,<u><em><strong>3</strong></em></u>]</code> ,最大元素为 3 ,第一个和最后一个元素都是 3 。</li>
|
||||
<li>子数组 <code>[<u><em><strong>3,3</strong></em></u>,3]</code> ,最大元素为 3 ,第一个和最后一个元素都是 3 。</li>
|
||||
<li>子数组 <code>[3,<u><em><strong>3,3</strong></em></u>]</code> ,最大元素为 3 ,第一个和最后一个元素都是 3 。</li>
|
||||
<li>子数组 <code>[<u><em><strong>3,3,3</strong></em></u>]</code> ,最大元素为 3 ,第一个和最后一个元素都是 3 。</li>
|
||||
</ul>
|
||||
|
||||
<p>所以我们返回 6 。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><span class="example-io"><b>输入:</b>nums = [1]</span></p>
|
||||
|
||||
<p><span class="example-io"><b>输出:</b>1</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p><code>nums</code> 中只有一个子数组 <code>[<em><strong>1</strong></em>]</code> ,最大元素为 1 ,第一个和最后一个元素都是 1 。</p>
|
||||
|
||||
<p>所以我们返回 1 。</p>
|
||||
</div>
|
||||
|
||||
<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>
|
65
leetcode-cn/problem (English)/使矩阵满足条件的最少操作次数(English) [minimum-number-of-operations-to-satisfy-conditions].html
Normal file
65
leetcode-cn/problem (English)/使矩阵满足条件的最少操作次数(English) [minimum-number-of-operations-to-satisfy-conditions].html
Normal file
@ -0,0 +1,65 @@
|
||||
<p>You are given a 2D matrix <code>grid</code> of size <code>m x n</code>. In one <strong>operation</strong>, you can change the value of <strong>any</strong> cell to <strong>any</strong> non-negative number. You need to perform some <strong>operations</strong> such that each cell <code>grid[i][j]</code> is:</p>
|
||||
|
||||
<ul>
|
||||
<li>Equal to the cell below it, i.e. <code>grid[i][j] == grid[i + 1][j]</code> (if it exists).</li>
|
||||
<li>Different from the cell to its right, i.e. <code>grid[i][j] != grid[i][j + 1]</code> (if it exists).</li>
|
||||
</ul>
|
||||
|
||||
<p>Return the <strong>minimum</strong> number of operations needed.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">grid = [[1,0,2],[1,0,2]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> 0</p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/04/15/examplechanged.png" style="width: 254px; height: 186px;padding: 10px; background: #fff; border-radius: .5rem;" /></strong></p>
|
||||
|
||||
<p>All the cells in the matrix already satisfy the properties.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">grid = [[1,1,1],[0,0,0]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> 3</p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/03/27/example21.png" style="width: 254px; height: 186px;padding: 10px; background: #fff; border-radius: .5rem;" /></strong></p>
|
||||
|
||||
<p>The matrix becomes <code>[[1,0,1],[1,0,1]]</code> which satisfies the properties, by doing these 3 operations:</p>
|
||||
|
||||
<ul>
|
||||
<li>Change <code>grid[1][0]</code> to 1.</li>
|
||||
<li>Change <code>grid[0][1]</code> to 0.</li>
|
||||
<li>Change <code>grid[1][2]</code> to 1.</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">grid = [[1],[2],[3]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> 2</p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/03/31/changed.png" style="width: 86px; height: 277px;padding: 10px; background: #fff; border-radius: .5rem;" /></p>
|
||||
|
||||
<p>There is a single column. We can change the value to 1 in each cell using 2 operations.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n, m <= 1000</code></li>
|
||||
<li><code>0 <= grid[i][j] <= 9</code></li>
|
||||
</ul>
|
71
leetcode-cn/problem (English)/划分数组得到最小的值之和(English) [minimum-sum-of-values-by-dividing-array].html
Normal file
71
leetcode-cn/problem (English)/划分数组得到最小的值之和(English) [minimum-sum-of-values-by-dividing-array].html
Normal file
@ -0,0 +1,71 @@
|
||||
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p>
|
||||
|
||||
<p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p>
|
||||
|
||||
<p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint contiguous</strong> <span data-keyword="subarray-nonempty">subarrays</span> such that for the <code>i<sup>th</sup></code> subarray <code>[l<sub>i</sub>, r<sub>i</sub>]</code>, the bitwise <code>AND</code> of the subarray elements is equal to <code>andValues[i]</code>, in other words, <code>nums[l<sub>i</sub>] & nums[l<sub>i</sub> + 1] & ... & nums[r<sub>i</sub>] == andValues[i]</code> for all <code>1 <= i <= m</code>, where <code>&</code> represents the bitwise <code>AND</code> operator.</p>
|
||||
|
||||
<p>Return <em>the <strong>minimum</strong> possible sum of the <strong>values</strong> of the </em><code>m</code><em> subarrays </em><code>nums</code><em> is divided into</em>. <em>If it is not possible to divide </em><code>nums</code><em> into </em><code>m</code><em> subarrays satisfying these conditions, return</em> <code>-1</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [1,4,3,3,2], andValues = [0,3,3,2]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">12</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The only possible way to divide <code>nums</code> is:</p>
|
||||
|
||||
<ol>
|
||||
<li><code>[1,4]</code> as <code>1 & 4 == 0</code>.</li>
|
||||
<li><code>[3]</code> as the bitwise <code>AND</code> of a single element subarray is that element itself.</li>
|
||||
<li><code>[3]</code> as the bitwise <code>AND</code> of a single element subarray is that element itself.</li>
|
||||
<li><code>[2]</code> as the bitwise <code>AND</code> of a single element subarray is that element itself.</li>
|
||||
</ol>
|
||||
|
||||
<p>The sum of the values for these subarrays is <code>4 + 3 + 3 + 2 = 12</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [2,3,5,7,7,7,5], andValues = [0,7,5]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">17</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>There are three ways to divide <code>nums</code>:</p>
|
||||
|
||||
<ol>
|
||||
<li><code>[[2,3,5],[7,7,7],[5]]</code> with the sum of the values <code>5 + 7 + 5 == 17</code>.</li>
|
||||
<li><code>[[2,3,5,7],[7,7],[5]]</code> with the sum of the values <code>7 + 7 + 5 == 19</code>.</li>
|
||||
<li><code>[[2,3,5,7,7],[7],[5]]</code> with the sum of the values <code>7 + 7 + 5 == 19</code>.</li>
|
||||
</ol>
|
||||
|
||||
<p>The minimum possible sum of the values is <code>17</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,3,4], andValues = [2]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">-1</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The bitwise <code>AND</code> of the entire array <code>nums</code> is <code>0</code>. As there is no possible way to divide <code>nums</code> into a single subarray to have the bitwise <code>AND</code> of elements <code>2</code>, return <code>-1</code>.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n == nums.length <= 10<sup>4</sup></code></li>
|
||||
<li><code>1 <= m == andValues.length <= min(n, 10)</code></li>
|
||||
<li><code>1 <= nums[i] < 10<sup>5</sup></code></li>
|
||||
<li><code>0 <= andValues[j] < 10<sup>5</sup></code></li>
|
||||
</ul>
|
73
leetcode-cn/problem (English)/单面值组合的第 K 小金额(English) [kth-smallest-amount-with-single-denomination-combination].html
Normal file
73
leetcode-cn/problem (English)/单面值组合的第 K 小金额(English) [kth-smallest-amount-with-single-denomination-combination].html
Normal file
@ -0,0 +1,73 @@
|
||||
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
|
||||
|
||||
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
|
||||
|
||||
<p>Return the <code>k<sup>th</sup></code> <strong>smallest</strong> amount that can be made using these coins.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block" style="
|
||||
border-color: var(--border-tertiary);
|
||||
border-left-width: 2px;
|
||||
color: var(--text-secondary);
|
||||
font-size: .875rem;
|
||||
margin-bottom: 1rem;
|
||||
margin-top: 1rem;
|
||||
overflow: visible;
|
||||
padding-left: 1rem;
|
||||
">
|
||||
<p><strong>Input:</strong> <span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">coins = [3,6,9], k = 3</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
"> 9</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong> The given coins can make the following amounts:<br />
|
||||
Coin 3 produces multiples of 3: 3, 6, 9, 12, 15, etc.<br />
|
||||
Coin 6 produces multiples of 6: 6, 12, 18, 24, etc.<br />
|
||||
Coin 9 produces multiples of 9: 9, 18, 27, 36, etc.<br />
|
||||
All of the coins combined produce: 3, 6, <u><strong>9</strong></u>, 12, 15, etc.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block" style="
|
||||
border-color: var(--border-tertiary);
|
||||
border-left-width: 2px;
|
||||
color: var(--text-secondary);
|
||||
font-size: .875rem;
|
||||
margin-bottom: 1rem;
|
||||
margin-top: 1rem;
|
||||
overflow: visible;
|
||||
padding-left: 1rem;
|
||||
">
|
||||
<p><strong>Input:</strong><span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
"> coins = [5,2], k = 7</span></p>
|
||||
|
||||
<p><strong>Output:</strong><span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
"> 12 </span></p>
|
||||
|
||||
<p><strong>Explanation:</strong> The given coins can make the following amounts:<br />
|
||||
Coin 5 produces multiples of 5: 5, 10, 15, 20, etc.<br />
|
||||
Coin 2 produces multiples of 2: 2, 4, 6, 8, 10, 12, etc.<br />
|
||||
All of the coins combined produce: 2, 4, 5, 6, 8, 10, <u><strong>12</strong></u>, 14, 15, etc.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= coins.length <= 15</code></li>
|
||||
<li><code>1 <= coins[i] <= 25</code></li>
|
||||
<li><code>1 <= k <= 2 * 10<sup>9</sup></code></li>
|
||||
<li><code>coins</code> contains pairwise distinct integers.</li>
|
||||
</ul>
|
@ -0,0 +1,36 @@
|
||||
<p>You are given a string <code>s</code>. The <strong>score</strong> of a string is defined as the sum of the absolute difference between the <strong>ASCII</strong> values of adjacent characters.</p>
|
||||
|
||||
<p>Return the <strong>score</strong> of<em> </em><code>s</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">s = "hello"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">13</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The <strong>ASCII</strong> values of the characters in <code>s</code> are: <code>'h' = 104</code>, <code>'e' = 101</code>, <code>'l' = 108</code>, <code>'o' = 111</code>. So, the score of <code>s</code> would be <code>|104 - 101| + |101 - 108| + |108 - 108| + |108 - 111| = 3 + 7 + 0 + 3 = 13</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">s = "zaz"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">50</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The <strong>ASCII</strong> values of the characters in <code>s</code> are: <code>'z' = 122</code>, <code>'a' = 97</code>. So, the score of <code>s</code> would be <code>|122 - 97| + |97 - 122| = 25 + 25 = 50</code>.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= s.length <= 100</code></li>
|
||||
<li><code>s</code> consists only of lowercase English letters.</li>
|
||||
</ul>
|
71
leetcode-cn/problem (English)/找出与数组相加的整数 I(English) [find-the-integer-added-to-array-i].html
Normal file
71
leetcode-cn/problem (English)/找出与数组相加的整数 I(English) [find-the-integer-added-to-array-i].html
Normal file
@ -0,0 +1,71 @@
|
||||
<p>You are given two arrays of equal length, <code>nums1</code> and <code>nums2</code>.</p>
|
||||
|
||||
<p>Each element in <code>nums1</code> has been increased (or decreased in the case of negative) by an integer, represented by the variable <code>x</code>.</p>
|
||||
|
||||
<p>As a result, <code>nums1</code> becomes <strong>equal</strong> to <code>nums2</code>. Two arrays are considered <strong>equal</strong> when they contain the same integers with the same frequencies.</p>
|
||||
|
||||
<p>Return the integer <code>x</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">nums1 = [2,6,4], nums2 = [9,7,5]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">3</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The integer added to each element of <code>nums1</code> is 3.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">nums1 = [10], nums2 = [5]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">-5</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The integer added to each element of <code>nums1</code> is -5.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">nums1 = [1,1,1,1], nums2 = [1,1,1,1]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">0</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The integer added to each element of <code>nums1</code> is 0.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums1.length == nums2.length <= 100</code></li>
|
||||
<li><code>0 <= nums1[i], nums2[i] <= 1000</code></li>
|
||||
<li>The test cases are generated in a way that there is an integer <code>x</code> such that <code>nums1</code> can become equal to <code>nums2</code> by adding <code>x</code> to each element of <code>nums1</code>.</li>
|
||||
</ul>
|
54
leetcode-cn/problem (English)/找出与数组相加的整数 II(English) [find-the-integer-added-to-array-ii].html
Normal file
54
leetcode-cn/problem (English)/找出与数组相加的整数 II(English) [find-the-integer-added-to-array-ii].html
Normal file
@ -0,0 +1,54 @@
|
||||
<p>You are given two integer arrays <code>nums1</code> and <code>nums2</code>.</p>
|
||||
|
||||
<p>From <code>nums1</code> two elements have been removed, and all other elements have been increased (or decreased in the case of negative) by an integer, represented by the variable <code>x</code>.</p>
|
||||
|
||||
<p>As a result, <code>nums1</code> becomes <strong>equal</strong> to <code>nums2</code>. Two arrays are considered <strong>equal</strong> when they contain the same integers with the same frequencies.</p>
|
||||
|
||||
<p>Return the <strong>minimum</strong> possible integer<em> </em><code>x</code><em> </em>that achieves this equivalence.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">nums1 = [4,20,16,12,8], nums2 = [14,18,10]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">-2</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>After removing elements at indices <code>[0,4]</code> and adding -2, <code>nums1</code> becomes <code>[18,14,10]</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">nums1 = [3,5,5,3], nums2 = [7,7]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">2</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>After removing elements at indices <code>[0,3]</code> and adding 2, <code>nums1</code> becomes <code>[7,7]</code>.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>3 <= nums1.length <= 200</code></li>
|
||||
<li><code>nums2.length == nums1.length - 2</code></li>
|
||||
<li><code>0 <= nums1[i], nums2[i] <= 1000</code></li>
|
||||
<li>The test cases are generated in a way that there is an integer <code>x</code> such that <code>nums1</code> can become equal to <code>nums2</code> by removing two elements and adding <code>x</code> to each element of <code>nums1</code>.</li>
|
||||
</ul>
|
52
leetcode-cn/problem (English)/找出唯一性数组的中位数(English) [find-the-median-of-the-uniqueness-array].html
Normal file
52
leetcode-cn/problem (English)/找出唯一性数组的中位数(English) [find-the-median-of-the-uniqueness-array].html
Normal file
@ -0,0 +1,52 @@
|
||||
<p>You are given an integer array <code>nums</code>. The <strong>uniqueness array</strong> of <code>nums</code> is the sorted array that contains the number of distinct elements of all the <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>. In other words, it is a sorted array consisting of <code>distinct(nums[i..j])</code>, for all <code>0 <= i <= j < nums.length</code>.</p>
|
||||
|
||||
<p>Here, <code>distinct(nums[i..j])</code> denotes the number of distinct elements in the subarray that starts at index <code>i</code> and ends at index <code>j</code>.</p>
|
||||
|
||||
<p>Return the <strong>median</strong> of the <strong>uniqueness array</strong> of <code>nums</code>.</p>
|
||||
|
||||
<p><strong>Note</strong> that the <strong>median</strong> of an array is defined as the middle element of the array when it is sorted in non-decreasing order. If there are two choices for a median, the <strong>smaller</strong> of the two values is taken.<!-- notionvc: 7e0f5178-4273-4a82-95ce-3395297921dc --></p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,3]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">1</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The uniqueness array of <code>nums</code> is <code>[distinct(nums[0..0]), distinct(nums[1..1]), distinct(nums[2..2]), distinct(nums[0..1]), distinct(nums[1..2]), distinct(nums[0..2])]</code> which is equal to <code>[1, 1, 1, 2, 2, 3]</code>. The uniqueness array has a median of 1. Therefore, the answer is 1.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [3,4,3,4,5]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">2</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The uniqueness array of <code>nums</code> is <code>[1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3]</code>. The uniqueness array has a median of 2. Therefore, the answer is 2.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [4,3,5,4]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">2</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The uniqueness array of <code>nums</code> is <code>[1, 1, 1, 1, 2, 2, 2, 3, 3, 3]</code>. The uniqueness array has a median of 2. Therefore, the answer is 2.</p>
|
||||
</div>
|
||||
|
||||
<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>5</sup></code></li>
|
||||
</ul>
|
59
leetcode-cn/problem (English)/找出所有稳定的二进制数组 I(English) [find-all-possible-stable-binary-arrays-i].html
Normal file
59
leetcode-cn/problem (English)/找出所有稳定的二进制数组 I(English) [find-all-possible-stable-binary-arrays-i].html
Normal file
@ -0,0 +1,59 @@
|
||||
<p>You are given 3 positive integers <code>zero</code>, <code>one</code>, and <code>limit</code>.</p>
|
||||
|
||||
<p>A <span data-keyword="binary-array">binary array</span> <code>arr</code> is called <strong>stable</strong> if:</p>
|
||||
|
||||
<ul>
|
||||
<li>The number of occurrences of 0 in <code>arr</code> is <strong>exactly </strong><code>zero</code>.</li>
|
||||
<li>The number of occurrences of 1 in <code>arr</code> is <strong>exactly</strong> <code>one</code>.</li>
|
||||
<li>Each <span data-keyword="subarray-nonempty">subarray</span> of <code>arr</code> with a size greater than <code>limit</code> must contain <strong>both </strong>0 and 1.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return the <em>total</em> number of <strong>stable</strong> binary arrays.</p>
|
||||
|
||||
<p>Since the answer may be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">zero = 1, one = 1, limit = 2</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">2</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The two possible stable binary arrays are <code>[1,0]</code> and <code>[0,1]</code>, as both arrays have a single 0 and a single 1, and no subarray has a length greater than 2.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">zero = 1, one = 2, limit = 1</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">1</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The only possible stable binary array is <code>[1,0,1]</code>.</p>
|
||||
|
||||
<p>Note that the binary arrays <code>[1,1,0]</code> and <code>[0,1,1]</code> have subarrays of length 2 with identical elements, hence, they are not stable.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">zero = 3, one = 3, limit = 2</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">14</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>All the possible stable binary arrays are <code>[0,0,1,0,1,1]</code>, <code>[0,0,1,1,0,1]</code>, <code>[0,1,0,0,1,1]</code>, <code>[0,1,0,1,0,1]</code>, <code>[0,1,0,1,1,0]</code>, <code>[0,1,1,0,0,1]</code>, <code>[0,1,1,0,1,0]</code>, <code>[1,0,0,1,0,1]</code>, <code>[1,0,0,1,1,0]</code>, <code>[1,0,1,0,0,1]</code>, <code>[1,0,1,0,1,0]</code>, <code>[1,0,1,1,0,0]</code>, <code>[1,1,0,0,1,0]</code>, and <code>[1,1,0,1,0,0]</code>.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= zero, one, limit <= 200</code></li>
|
||||
</ul>
|
57
leetcode-cn/problem (English)/找出所有稳定的二进制数组 II(English) [find-all-possible-stable-binary-arrays-ii].html
Normal file
57
leetcode-cn/problem (English)/找出所有稳定的二进制数组 II(English) [find-all-possible-stable-binary-arrays-ii].html
Normal file
@ -0,0 +1,57 @@
|
||||
<p>You are given 3 positive integers <code>zero</code>, <code>one</code>, and <code>limit</code>.</p>
|
||||
|
||||
<p>A <span data-keyword="binary-array">binary array</span> <code>arr</code> is called <strong>stable</strong> if:</p>
|
||||
|
||||
<ul>
|
||||
<li>The number of occurrences of 0 in <code>arr</code> is <strong>exactly </strong><code>zero</code>.</li>
|
||||
<li>The number of occurrences of 1 in <code>arr</code> is <strong>exactly</strong> <code>one</code>.</li>
|
||||
<li>Each <span data-keyword="subarray-nonempty">subarray</span> of <code>arr</code> with a size greater than <code>limit</code> must contain <strong>both </strong>0 and 1.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return the <em>total</em> number of <strong>stable</strong> binary arrays.</p>
|
||||
|
||||
<p>Since the answer may be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">zero = 1, one = 1, limit = 2</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">2</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The two possible stable binary arrays are <code>[1,0]</code> and <code>[0,1]</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">zero = 1, one = 2, limit = 1</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">1</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The only possible stable binary array is <code>[1,0,1]</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">zero = 3, one = 3, limit = 2</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">14</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>All the possible stable binary arrays are <code>[0,0,1,0,1,1]</code>, <code>[0,0,1,1,0,1]</code>, <code>[0,1,0,0,1,1]</code>, <code>[0,1,0,1,0,1]</code>, <code>[0,1,0,1,1,0]</code>, <code>[0,1,1,0,0,1]</code>, <code>[0,1,1,0,1,0]</code>, <code>[1,0,0,1,0,1]</code>, <code>[1,0,0,1,1,0]</code>, <code>[1,0,1,0,0,1]</code>, <code>[1,0,1,0,1,0]</code>, <code>[1,0,1,1,0,0]</code>, <code>[1,1,0,0,1,0]</code>, and <code>[1,1,0,1,0,0]</code>.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= zero, one, limit <= 1000</code></li>
|
||||
</ul>
|
@ -0,0 +1,35 @@
|
||||
<p>You are given two integers <code>n</code> and <code>x</code>. You have to construct an array of <strong>positive</strong> integers <code>nums</code> of size <code>n</code> where for every <code>0 <= i < n - 1</code>, <code>nums[i + 1]</code> is <strong>greater than</strong> <code>nums[i]</code>, and the result of the bitwise <code>AND</code> operation between all elements of <code>nums</code> is <code>x</code>.</p>
|
||||
|
||||
<p>Return the <strong>minimum</strong> possible value of <code>nums[n - 1]</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">n = 3, x = 4</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">6</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p><code>nums</code> can be <code>[4,5,6]</code> and its last element is 6.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">n = 2, x = 7</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">15</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p><code>nums</code> can be <code>[7,15]</code> and its last element is 15.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n, x <= 10<sup>8</sup></code></li>
|
||||
</ul>
|
38
leetcode-cn/problem (English)/替换字符可以得到的最晚时间(English) [latest-time-you-can-obtain-after-replacing-characters].html
Normal file
38
leetcode-cn/problem (English)/替换字符可以得到的最晚时间(English) [latest-time-you-can-obtain-after-replacing-characters].html
Normal file
@ -0,0 +1,38 @@
|
||||
<p>You are given a string <code>s</code> representing a 12-hour format time where some of the digits (possibly none) are replaced with a <code>"?"</code>.</p>
|
||||
|
||||
<p>12-hour times are formatted as <code>"HH:MM"</code>, where <code>HH</code> is between <code>00</code> and <code>11</code>, and <code>MM</code> is between <code>00</code> and <code>59</code>. The earliest 12-hour time is <code>00:00</code>, and the latest is <code>11:59</code>.</p>
|
||||
|
||||
<p>You have to replace <strong>all</strong> the <code>"?"</code> characters in <code>s</code> with digits such that the time we obtain by the resulting string is a <strong>valid</strong> 12-hour format time and is the <strong>latest</strong> possible.</p>
|
||||
|
||||
<p>Return <em>the resulting string</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">s = "1?:?4"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">"11:54"</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong> The latest 12-hour format time we can achieve by replacing <code>"?"</code> characters is <code>"11:54"</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">s = "0?:5?"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">"09:59"</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong> The latest 12-hour format time we can achieve by replacing <code>"?"</code> characters is <code>"09:59"</code>.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>s.length == 5</code></li>
|
||||
<li><code>s[2]</code> is equal to the character <code>":"</code>.</li>
|
||||
<li>All characters except <code>s[2]</code> are digits or <code>"?"</code> characters.</li>
|
||||
<li>The input is generated such that there is <strong>at least</strong> one time between <code>"00:00"</code> and <code>"11:59"</code> that you can obtain after replacing the <code>"?"</code> characters.</li>
|
||||
</ul>
|
@ -0,0 +1,51 @@
|
||||
<p>You are given an undirected weighted graph of <code>n</code> nodes numbered from 0 to <code>n - 1</code>. The graph consists of <code>m</code> edges represented by a 2D array <code>edges</code>, where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge between nodes <code>a<sub>i</sub></code> and <code>b<sub>i</sub></code> with weight <code>w<sub>i</sub></code>.</p>
|
||||
|
||||
<p>Consider all the shortest paths from node 0 to node <code>n - 1</code> in the graph. You need to find a <strong>boolean</strong> array <code>answer</code> where <code>answer[i]</code> is <code>true</code> if the edge <code>edges[i]</code> is part of <strong>at least</strong> one shortest path. Otherwise, <code>answer[i]</code> is <code>false</code>.</p>
|
||||
|
||||
<p>Return the array <code>answer</code>.</p>
|
||||
|
||||
<p><strong>Note</strong> that the graph may not be connected.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2024/03/05/graph35drawio-1.png" style="height: 129px; width: 250px;" />
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">n = 6, edges = [[0,1,4],[0,2,1],[1,3,2],[1,4,3],[1,5,1],[2,3,1],[3,5,3],[4,5,2]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">[true,true,true,false,true,true,true,false]</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The following are <strong>all</strong> the shortest paths between nodes 0 and 5:</p>
|
||||
|
||||
<ul>
|
||||
<li>The path <code>0 -> 1 -> 5</code>: The sum of weights is <code>4 + 1 = 5</code>.</li>
|
||||
<li>The path <code>0 -> 2 -> 3 -> 5</code>: The sum of weights is <code>1 + 1 + 3 = 5</code>.</li>
|
||||
<li>The path <code>0 -> 2 -> 3 -> 1 -> 5</code>: The sum of weights is <code>1 + 1 + 2 + 1 = 5</code>.</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2024/03/05/graphhhh.png" style="width: 185px; height: 136px;" />
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">n = 4, edges = [[2,0,1],[0,1,1],[0,3,4],[3,2,2]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">[true,false,false,true]</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>There is one shortest path between nodes 0 and 3, which is the path <code>0 -> 2 -> 3</code> with the sum of weights <code>1 + 2 = 3</code>.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= n <= 5 * 10<sup>4</sup></code></li>
|
||||
<li><code>m == edges.length</code></li>
|
||||
<li><code>1 <= m <= min(5 * 10<sup>4</sup>, n * (n - 1) / 2)</code></li>
|
||||
<li><code>0 <= a<sub>i</sub>, b<sub>i</sub> < n</code></li>
|
||||
<li><code>a<sub>i</sub> != b<sub>i</sub></code></li>
|
||||
<li><code>1 <= w<sub>i</sub> <= 10<sup>5</sup></code></li>
|
||||
<li>There are no repeated edges.</li>
|
||||
</ul>
|
129
leetcode-cn/problem (English)/构造相同颜色的正方形(English) [make-a-square-with-the-same-color].html
Normal file
129
leetcode-cn/problem (English)/构造相同颜色的正方形(English) [make-a-square-with-the-same-color].html
Normal file
@ -0,0 +1,129 @@
|
||||
<p>You are given a 2D matrix <code>grid</code> of size <code>3 x 3</code> consisting only of characters <code>'B'</code> and <code>'W'</code>. Character <code>'W'</code> represents the white color<!-- notionvc: 06a49cc0-a296-4bd2-9bfe-c8818edeb53a -->, and character <code>'B'</code> represents the black color<!-- notionvc: 06a49cc0-a296-4bd2-9bfe-c8818edeb53a -->.</p>
|
||||
|
||||
<p>Your task is to change the color of <strong>at most one</strong> cell<!-- notionvc: c04cb478-8dd5-49b1-80bb-727c6b1e0232 --> so that the matrix has a <code>2 x 2</code> square where all cells are of the same color.<!-- notionvc: adf957e1-fa0f-40e5-9a2e-933b95e276a7 --></p>
|
||||
|
||||
<p>Return <code>true</code> if it is possible to create a <code>2 x 2</code> square of the same color, otherwise, return <code>false</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<style type="text/css">.grid-container {
|
||||
display: grid;
|
||||
grid-template-columns: 30px 30px 30px;
|
||||
padding: 10px;
|
||||
}
|
||||
.grid-item {
|
||||
background-color: black;
|
||||
border: 1px solid gray;
|
||||
height: 30px;
|
||||
font-size: 30px;
|
||||
text-align: center;
|
||||
}
|
||||
.grid-item-white {
|
||||
background-color: white;
|
||||
}
|
||||
</style>
|
||||
<style class="darkreader darkreader--sync" media="screen" type="text/css">
|
||||
</style>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="grid-container">
|
||||
<div class="grid-item"> </div>
|
||||
|
||||
<div class="grid-item grid-item-white"> </div>
|
||||
|
||||
<div class="grid-item"> </div>
|
||||
|
||||
<div class="grid-item"> </div>
|
||||
|
||||
<div class="grid-item grid-item-white"> </div>
|
||||
|
||||
<div class="grid-item grid-item-white"> </div>
|
||||
|
||||
<div class="grid-item"> </div>
|
||||
|
||||
<div class="grid-item grid-item-white"> </div>
|
||||
|
||||
<div class="grid-item"> </div>
|
||||
</div>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">grid = [["B","W","B"],["B","W","W"],["B","W","B"]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">true</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>It can be done by changing the color of the <code>grid[0][2]</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="grid-container">
|
||||
<div class="grid-item"> </div>
|
||||
|
||||
<div class="grid-item grid-item-white"> </div>
|
||||
|
||||
<div class="grid-item"> </div>
|
||||
|
||||
<div class="grid-item grid-item-white"> </div>
|
||||
|
||||
<div class="grid-item"> </div>
|
||||
|
||||
<div class="grid-item grid-item-white"> </div>
|
||||
|
||||
<div class="grid-item"> </div>
|
||||
|
||||
<div class="grid-item grid-item-white"> </div>
|
||||
|
||||
<div class="grid-item"> </div>
|
||||
</div>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">grid = [["B","W","B"],["W","B","W"],["B","W","B"]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">false</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>It cannot be done by changing at most one cell.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="grid-container">
|
||||
<div class="grid-item"> </div>
|
||||
|
||||
<div class="grid-item grid-item-white"> </div>
|
||||
|
||||
<div class="grid-item"> </div>
|
||||
|
||||
<div class="grid-item"> </div>
|
||||
|
||||
<div class="grid-item grid-item-white"> </div>
|
||||
|
||||
<div class="grid-item grid-item-white"> </div>
|
||||
|
||||
<div class="grid-item"> </div>
|
||||
|
||||
<div class="grid-item grid-item-white"> </div>
|
||||
|
||||
<div class="grid-item grid-item-white"> </div>
|
||||
</div>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">grid = [["B","W","B"],["B","W","W"],["B","W","W"]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">true</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The <code>grid</code> already contains a <code>2 x 2</code> square of the same color.<!-- notionvc: 9a8b2d3d-1e73-457a-abe0-c16af51ad5c2 --></p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>grid.length == 3</code></li>
|
||||
<li><code>grid[i].length == 3</code></li>
|
||||
<li><code>grid[i][j]</code> is either <code>'W'</code> or <code>'B'</code>.</li>
|
||||
</ul>
|
@ -0,0 +1,164 @@
|
||||
<p>You are given a 2D boolean matrix <code>grid</code>.</p>
|
||||
|
||||
<p>Return an integer that is the number of <strong>right triangles</strong> that can be made with the 3 elements of <code>grid</code> such that <strong>all</strong> of them have a value of 1.</p>
|
||||
|
||||
<p><strong>Note:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>A collection of 3 elements of <code>grid</code> is a <strong>right triangle</strong> if one of its elements is in the <strong>same row</strong> with another<!-- notionvc: 6133ebe2-45aa-4346-9c28-03193b794c49 --> element and in the <strong>same column</strong> with the third element. The 3 elements do not have to be next to each other.</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div style="display:flex; gap: 12px;">
|
||||
<table border="1" cellspacing="3" style="border-collapse: separate; text-align: center;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid red; --darkreader-inline-border-top: #b30000; --darkreader-inline-border-right: #b30000; --darkreader-inline-border-bottom: #b30000; --darkreader-inline-border-left: #b30000;">1</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid red; --darkreader-inline-border-top: #b30000; --darkreader-inline-border-right: #b30000; --darkreader-inline-border-bottom: #b30000; --darkreader-inline-border-left: #b30000;">1</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid red; --darkreader-inline-border-top: #b30000; --darkreader-inline-border-right: #b30000; --darkreader-inline-border-bottom: #b30000; --darkreader-inline-border-left: #b30000;">1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">1</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<table border="1" cellspacing="3" style="border-collapse: separate; text-align: center;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">1</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid red; --darkreader-inline-border-top: #b30000; --darkreader-inline-border-right: #b30000; --darkreader-inline-border-bottom: #b30000; --darkreader-inline-border-left: #b30000;">1</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid red; --darkreader-inline-border-top: #b30000; --darkreader-inline-border-right: #b30000; --darkreader-inline-border-bottom: #b30000; --darkreader-inline-border-left: #b30000;">1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid red; --darkreader-inline-border-top: #b30000; --darkreader-inline-border-right: #b30000; --darkreader-inline-border-bottom: #b30000; --darkreader-inline-border-left: #b30000;">1</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">grid = [[0,1,0],[0,1,1],[0,1,0]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">2</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>There are two right triangles.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div style="display:flex; gap: 12px;">
|
||||
<table border="1" cellspacing="3" style="border-collapse: separate; text-align: center;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">1</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">1</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">1</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">grid = [[1,0,0,0],[0,1,0,1],[1,0,0,0]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">0</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>There are no right triangles.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div style="display:flex; gap: 12px;">
|
||||
<table border="1" cellspacing="3" style="border-collapse: separate; text-align: center;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid red; --darkreader-inline-border-top: #b30000; --darkreader-inline-border-right: #b30000; --darkreader-inline-border-bottom: #b30000; --darkreader-inline-border-left: #b30000;">1</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid red; --darkreader-inline-border-top: #b30000; --darkreader-inline-border-right: #b30000; --darkreader-inline-border-bottom: #b30000; --darkreader-inline-border-left: #b30000;">1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid red; --darkreader-inline-border-top: #b30000; --darkreader-inline-border-right: #b30000; --darkreader-inline-border-bottom: #b30000; --darkreader-inline-border-left: #b30000;">1</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">1</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<table border="1" cellspacing="3" style="border-collapse: separate; text-align: center;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid red; --darkreader-inline-border-top: #b30000; --darkreader-inline-border-right: #b30000; --darkreader-inline-border-bottom: #b30000; --darkreader-inline-border-left: #b30000;">1</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid red; --darkreader-inline-border-top: #b30000; --darkreader-inline-border-right: #b30000; --darkreader-inline-border-bottom: #b30000; --darkreader-inline-border-left: #b30000;">1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">1</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid red; --darkreader-inline-border-top: #b30000; --darkreader-inline-border-right: #b30000; --darkreader-inline-border-bottom: #b30000; --darkreader-inline-border-left: #b30000;">1</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
<td data-darkreader-inline-border-bottom="" data-darkreader-inline-border-left="" data-darkreader-inline-border-right="" data-darkreader-inline-border-top="" style="padding: 5px 10px; border: 1px solid black; --darkreader-inline-border-top: #8c8273; --darkreader-inline-border-right: #8c8273; --darkreader-inline-border-bottom: #8c8273; --darkreader-inline-border-left: #8c8273;">0</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">grid = [[1,0,1],[1,0,0],[1,0,0]]</span></p>
|
||||
|
||||
<p><strong>Output: </strong>2</p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>There are two right triangles.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= grid.length <= 1000</code></li>
|
||||
<li><code>1 <= grid[i].length <= 1000</code></li>
|
||||
<li><code>0 <= grid[i][j] <= 1</code></li>
|
||||
</ul>
|
48
leetcode-cn/problem (English)/统计特殊字母的数量 I(English) [count-the-number-of-special-characters-i].html
Normal file
48
leetcode-cn/problem (English)/统计特殊字母的数量 I(English) [count-the-number-of-special-characters-i].html
Normal file
@ -0,0 +1,48 @@
|
||||
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p>
|
||||
|
||||
<p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">word = "aaAbcBC"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">3</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The special characters in <code>word</code> are <code>'a'</code>, <code>'b'</code>, and <code>'c'</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">word = "abc"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">0</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>No character in <code>word</code> appears in uppercase.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">word = "abBCab"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> 1</p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The only special character in <code>word</code> is <code>'b'</code>.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= word.length <= 50</code></li>
|
||||
<li><code>word</code> consists of only lowercase and uppercase English letters.</li>
|
||||
</ul>
|
48
leetcode-cn/problem (English)/统计特殊字母的数量 II(English) [count-the-number-of-special-characters-ii].html
Normal file
48
leetcode-cn/problem (English)/统计特殊字母的数量 II(English) [count-the-number-of-special-characters-ii].html
Normal file
@ -0,0 +1,48 @@
|
||||
<p>You are given a string <code>word</code>. A letter <code>c</code> is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>, and <strong>every</strong> lowercase occurrence of <code>c</code> appears before the <strong>first</strong> uppercase occurrence of <code>c</code>.</p>
|
||||
|
||||
<p>Return the number of<em> </em><strong>special</strong> letters<em> </em>in<em> </em><code>word</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">word = "aaAbcBC"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">3</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The special characters are <code>'a'</code>, <code>'b'</code>, and <code>'c'</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">word = "abc"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">0</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>There are no special characters in <code>word</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">word = "AbBCab"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">0</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>There are no special characters in <code>word</code>.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= word.length <= 2 * 10<sup>5</sup></code></li>
|
||||
<li><code>word</code> consists of only lowercase and uppercase English letters.</li>
|
||||
</ul>
|
125
leetcode-cn/problem (English)/覆盖所有点的最少矩形数目(English) [minimum-rectangles-to-cover-points].html
Normal file
125
leetcode-cn/problem (English)/覆盖所有点的最少矩形数目(English) [minimum-rectangles-to-cover-points].html
Normal file
@ -0,0 +1,125 @@
|
||||
<p>You are given a 2D integer array <code>points</code>, where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>. You are also given an integer <code>w</code>. Your task is to <strong>cover</strong> <strong>all</strong> the given points with rectangles.</p>
|
||||
|
||||
<p>Each rectangle has its lower end at some point <code>(x<sub>1</sub>, 0)</code> and its upper end at some point <code>(x<sub>2</sub>, y<sub>2</sub>)</code>, where <code>x<sub>1</sub> <= x<sub>2</sub></code>, <code>y<sub>2</sub> >= 0</code>, and the condition <code>x<sub>2</sub> - x<sub>1</sub> <= w</code> <strong>must</strong> be satisfied for each rectangle.</p>
|
||||
|
||||
<p>A point is considered covered by a rectangle if it lies within or on the boundary of the rectangle.</p>
|
||||
|
||||
<p>Return an integer denoting the <strong>minimum</strong> number of rectangles needed so that each point is covered by <strong>at least one</strong> rectangle<em>.</em></p>
|
||||
|
||||
<p><strong>Note:</strong> A point may be covered by more than one rectangle.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/03/04/screenshot-from-2024-03-04-20-33-05.png" style="width: 205px; height: 300px;" /></p>
|
||||
|
||||
<div class="example-block" style="
|
||||
border-color: var(--border-tertiary);
|
||||
border-left-width: 2px;
|
||||
color: var(--text-secondary);
|
||||
font-size: .875rem;
|
||||
margin-bottom: 1rem;
|
||||
margin-top: 1rem;
|
||||
overflow: visible;
|
||||
padding-left: 1rem;
|
||||
">
|
||||
<p><strong>Input:</strong> <span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">points = [[2,1],[1,0],[1,4],[1,8],[3,5],[4,6]], w = 1</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">2</span></p>
|
||||
|
||||
<p><strong>Explanation: </strong></p>
|
||||
|
||||
<p>The image above shows one possible placement of rectangles to cover the points:</p>
|
||||
|
||||
<ul>
|
||||
<li>A rectangle with a lower end at <code>(1, 0)</code> and its upper end at <code>(2, 8)</code></li>
|
||||
<li>A rectangle with a lower end at <code>(3, 0)</code> and its upper end at <code>(4, 8)</code></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/03/04/screenshot-from-2024-03-04-18-59-12.png" style="width: 260px; height: 250px;" /></p>
|
||||
|
||||
<div class="example-block" style="
|
||||
border-color: var(--border-tertiary);
|
||||
border-left-width: 2px;
|
||||
color: var(--text-secondary);
|
||||
font-size: .875rem;
|
||||
margin-bottom: 1rem;
|
||||
margin-top: 1rem;
|
||||
overflow: visible;
|
||||
padding-left: 1rem;
|
||||
">
|
||||
<p><strong>Input:</strong> <span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">points = [[0,0],[1,1],[2,2],[3,3],[4,4],[5,5],[6,6]], w = 2</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">3</span></p>
|
||||
|
||||
<p><strong>Explanation: </strong></p>
|
||||
|
||||
<p>The image above shows one possible placement of rectangles to cover the points:</p>
|
||||
|
||||
<ul>
|
||||
<li>A rectangle with a lower end at <code>(0, 0)</code> and its upper end at <code>(2, 2)</code></li>
|
||||
<li>A rectangle with a lower end at <code>(3, 0)</code> and its upper end at <code>(5, 5)</code></li>
|
||||
<li>A rectangle with a lower end at <code>(6, 0)</code> and its upper end at <code>(6, 6)</code></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/03/04/screenshot-from-2024-03-04-20-24-03.png" style="height: 150px; width: 127px;" /></p>
|
||||
|
||||
<div class="example-block" style="
|
||||
border-color: var(--border-tertiary);
|
||||
border-left-width: 2px;
|
||||
color: var(--text-secondary);
|
||||
font-size: .875rem;
|
||||
margin-bottom: 1rem;
|
||||
margin-top: 1rem;
|
||||
overflow: visible;
|
||||
padding-left: 1rem;
|
||||
">
|
||||
<p><strong>Input:</strong> <span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">points = [[2,3],[1,2]], w = 0</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">2</span></p>
|
||||
|
||||
<p><strong>Explanation: </strong></p>
|
||||
|
||||
<p>The image above shows one possible placement of rectangles to cover the points:</p>
|
||||
|
||||
<ul>
|
||||
<li>A rectangle with a lower end at <code>(1, 0)</code> and its upper end at <code>(1, 2)</code></li>
|
||||
<li>A rectangle with a lower end at <code>(2, 0)</code> and its upper end at <code>(2, 3)</code></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= points.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>points[i].length == 2</code></li>
|
||||
<li><code>0 <= x<sub>i</sub> == points[i][0] <= 10<sup>9</sup></code></li>
|
||||
<li><code>0 <= y<sub>i</sub> == points[i][1] <= 10<sup>9</sup></code></li>
|
||||
<li><code>0 <= w <= 10<sup>9</sup></code></li>
|
||||
<li>All pairs <code>(x<sub>i</sub>, y<sub>i</sub>)</code> are distinct.</li>
|
||||
</ul>
|
73
leetcode-cn/problem (English)/访问消失节点的最少时间(English) [minimum-time-to-visit-disappearing-nodes].html
Normal file
73
leetcode-cn/problem (English)/访问消失节点的最少时间(English) [minimum-time-to-visit-disappearing-nodes].html
Normal file
@ -0,0 +1,73 @@
|
||||
<p>There is an undirected graph of <code>n</code> nodes. You are given a 2D array <code>edges</code>, where <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub>, length<sub>i</sub>]</code> describes an edge between node <code>u<sub>i</sub></code> and node <code>v<sub>i</sub></code> with a traversal time of <code>length<sub>i</sub></code> units.</p>
|
||||
|
||||
<p>Additionally, you are given an array <code>disappear</code>, where <code>disappear[i]</code> denotes the time when the node <code>i</code> disappears from the graph and you won't be able to visit it.</p>
|
||||
|
||||
<p><strong>Notice</strong> that the graph might be disconnected and might contain multiple edges.</p>
|
||||
|
||||
<p>Return the array <code>answer</code>, with <code>answer[i]</code> denoting the <strong>minimum</strong> units of time required to reach node <code>i</code> from node 0. If node <code>i</code> is <strong>unreachable</strong> from node 0 then <code>answer[i]</code> is <code>-1</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<p><img 10px="" alt="" padding:="" src="https://assets.leetcode.com/uploads/2024/03/09/example1.png" style="width: 350px; height: 210px;" /></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io"> n = 3, edges = [[0,1,2],[1,2,1],[0,2,4]], disappear = [1,1,5]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io"> [0,-1,4]</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>We are starting our journey from node 0, and our goal is to find the minimum time required to reach each node before it disappears.</p>
|
||||
|
||||
<ul>
|
||||
<li>For node 0, we don't need any time as it is our starting point.</li>
|
||||
<li>For node 1, we need at least 2 units of time to traverse <code>edges[0]</code>. Unfortunately, it disappears at that moment, so we won't be able to visit it.</li>
|
||||
<li>For node 2, we need at least 4 units of time to traverse <code>edges[2]</code>.</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<p><img 10px="" alt="" padding:="" src="https://assets.leetcode.com/uploads/2024/03/09/example2.png" style="width: 350px; height: 210px;" /></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io"> n = 3, edges = [[0,1,2],[1,2,1],[0,2,4]], disappear = [1,3,5]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io"> [0,2,3]</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>We are starting our journey from node 0, and our goal is to find the minimum time required to reach each node before it disappears.</p>
|
||||
|
||||
<ul>
|
||||
<li>For node 0, we don't need any time as it is the starting point.</li>
|
||||
<li>For node 1, we need at least 2 units of time to traverse <code>edges[0]</code>.</li>
|
||||
<li>For node 2, we need at least 3 units of time to traverse <code>edges[0]</code> and <code>edges[1]</code>.</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">n = 2, edges = [[0,1,1]], disappear = [1,1]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">[0,-1]</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>Exactly when we reach node 1, it disappears.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n <= 5 * 10<sup>4</sup></code></li>
|
||||
<li><code>0 <= edges.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>edges[i] == [u<sub>i</sub>, v<sub>i</sub>, length<sub>i</sub>]</code></li>
|
||||
<li><code>0 <= u<sub>i</sub>, v<sub>i</sub> <= n - 1</code></li>
|
||||
<li><code>1 <= length<sub>i</sub> <= 10<sup>5</sup></code></li>
|
||||
<li><code>disappear.length == n</code></li>
|
||||
<li><code>1 <= disappear[i] <= 10<sup>5</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,33 @@
|
||||
<p>You are given an integer array <code>nums</code>.</p>
|
||||
|
||||
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [4,2,9,5,3]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">3</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong> <code>nums[1]</code>, <code>nums[3]</code>, and <code>nums[4]</code> are prime. So the answer is <code>|4 - 1| = 3</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [4,8,2,8]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">0</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong> <code>nums[2]</code> is prime. Because there is just one prime number, the answer is <code>|2 - 2| = 0</code>.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 3 * 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= nums[i] <= 100</code></li>
|
||||
<li>The input is generated such that the number of prime numbers in the <code>nums</code> is at least one.</li>
|
||||
</ul>
|
72
leetcode-cn/problem (English)/边界元素是最大值的子数组数目(English) [find-the-number-of-subarrays-where-boundary-elements-are-maximum].html
Normal file
72
leetcode-cn/problem (English)/边界元素是最大值的子数组数目(English) [find-the-number-of-subarrays-where-boundary-elements-are-maximum].html
Normal file
@ -0,0 +1,72 @@
|
||||
<p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
|
||||
|
||||
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest</strong> element in the subarray.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [1,4,3,3,2]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">6</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>There are 6 subarrays which have the first and the last elements equal to the largest element of the subarray:</p>
|
||||
|
||||
<ul>
|
||||
<li>subarray <code>[<strong><u>1</u></strong>,4,3,3,2]</code>, with its largest element 1. The first element is 1 and the last element is also 1.</li>
|
||||
<li>subarray <code>[1,<u><strong>4</strong></u>,3,3,2]</code>, with its largest element 4. The first element is 4 and the last element is also 4.</li>
|
||||
<li>subarray <code>[1,4,<u><strong>3</strong></u>,3,2]</code>, with its largest element 3. The first element is 3 and the last element is also 3.</li>
|
||||
<li>subarray <code>[1,4,3,<u><strong>3</strong></u>,2]</code>, with its largest element 3. The first element is 3 and the last element is also 3.</li>
|
||||
<li>subarray <code>[1,4,3,3,<u><strong>2</strong></u>]</code>, with its largest element 2. The first element is 2 and the last element is also 2.</li>
|
||||
<li>subarray <code>[1,4,<u><strong>3,3</strong></u>,2]</code>, with its largest element 3. The first element is 3 and the last element is also 3.</li>
|
||||
</ul>
|
||||
|
||||
<p>Hence, we return 6.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [3,3,3]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">6</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>There are 6 subarrays which have the first and the last elements equal to the largest element of the subarray:</p>
|
||||
|
||||
<ul>
|
||||
<li>subarray <code>[<u><strong>3</strong></u>,3,3]</code>, with its largest element 3. The first element is 3 and the last element is also 3.</li>
|
||||
<li>subarray <code>[3,<strong><u>3</u></strong>,3]</code>, with its largest element 3. The first element is 3 and the last element is also 3.</li>
|
||||
<li>subarray <code>[3,3,<u><strong>3</strong></u>]</code>, with its largest element 3. The first element is 3 and the last element is also 3.</li>
|
||||
<li>subarray <code>[<strong><u>3,3</u></strong>,3]</code>, with its largest element 3. The first element is 3 and the last element is also 3.</li>
|
||||
<li>subarray <code>[3,<u><strong>3,3</strong></u>]</code>, with its largest element 3. The first element is 3 and the last element is also 3.</li>
|
||||
<li>subarray <code>[<u><strong>3,3,3</strong></u>]</code>, with its largest element 3. The first element is 3 and the last element is also 3.</li>
|
||||
</ul>
|
||||
|
||||
<p>Hence, we return 6.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [1]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">1</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>There is a single subarray of <code>nums</code> which is <code>[<strong><u>1</u></strong>]</code>, with its largest element 1. The first element is 1 and the last element is also 1.</p>
|
||||
|
||||
<p>Hence, we return 1.</p>
|
||||
</div>
|
||||
|
||||
<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>
|
File diff suppressed because it is too large
Load Diff
70
leetcode/originData/[no content]find-longest-calls.json
Normal file
70
leetcode/originData/[no content]find-longest-calls.json
Normal file
@ -0,0 +1,70 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "3432",
|
||||
"questionFrontendId": "3124",
|
||||
"boundTopicId": null,
|
||||
"title": "Find Longest Calls",
|
||||
"titleSlug": "find-longest-calls",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Medium",
|
||||
"likes": 3,
|
||||
"dislikes": 1,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"exampleTestcases": "{\"headers\":{\"Contacts\":[\"id\",\"first_name\",\"last_name\"],\"Calls\":[\"contact_id\",\"type\",\"duration\"]},\"rows\":{\"Contacts\":[[1,\"John\",\"Doe\"],[2,\"Jane\",\"Smith\"],[3,\"Alice\",\"Johnson\"],[4,\"Michael\",\"Brown\"],[5,\"Emily\",\"Davis\"]],\"Calls\":[[1,\"incoming\",120],[1,\"outgoing\",180],[2,\"incoming\",300],[2,\"outgoing\",240],[3,\"incoming\",150],[3,\"outgoing\",360],[4,\"incoming\",420],[4,\"outgoing\",200],[5,\"incoming\",180],[5,\"outgoing\",280]]}}",
|
||||
"categoryTitle": "Database",
|
||||
"contributors": [],
|
||||
"topicTags": [
|
||||
{
|
||||
"name": "Database",
|
||||
"slug": "database",
|
||||
"translatedName": null,
|
||||
"__typename": "TopicTagNode"
|
||||
}
|
||||
],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"217\", \"totalSubmission\": \"266\", \"totalAcceptedRaw\": 217, \"totalSubmissionRaw\": 266, \"acRate\": \"81.6%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\":{\"Contacts\":[\"id\",\"first_name\",\"last_name\"],\"Calls\":[\"contact_id\",\"type\",\"duration\"]},\"rows\":{\"Contacts\":[[1,\"John\",\"Doe\"],[2,\"Jane\",\"Smith\"],[3,\"Alice\",\"Johnson\"],[4,\"Michael\",\"Brown\"],[5,\"Emily\",\"Davis\"]],\"Calls\":[[1,\"incoming\",120],[1,\"outgoing\",180],[2,\"incoming\",300],[2,\"outgoing\",240],[3,\"incoming\",150],[3,\"outgoing\",360],[4,\"incoming\",420],[4,\"outgoing\",200],[5,\"incoming\",180],[5,\"outgoing\",280]]}}",
|
||||
"metaData": "{\"mysql\": [\"Create table if Not Exists Contacts(id int, first_name varchar(20), last_name varchar(20))\", \"Create table if Not Exists Calls(contact_id int, type ENUM('incoming', 'outgoing'), duration int)\"], \"mssql\": [\"Create table Contacts(id int, first_name varchar(20), last_name varchar(20))\", \"Create table Calls(contact_id int, type varchar(20) NOT NULL CHECK (type in ('incoming' , 'outgoing')), duration int)\"], \"oraclesql\": [\"Create table Contacts(id int, first_name varchar(20), last_name varchar(20))\", \"Create table Calls(contact_id int, type varchar(20) NOT NULL CHECK (type in ('incoming' , 'outgoing')), duration int)\"], \"database\": true, \"name\": \"find_longest_calls\", \"pythondata\": [\"Contacts = pd.DataFrame([], columns=['id', 'first_name', 'last_name']).astype({'id':'Int64', 'first_name':'object', 'last_name':'object'})\\n\", \"Calls = pd.DataFrame([], columns=['contact_id', 'type', 'duration']).astype({'contact_id': 'Int64', 'type': 'category', 'duration': 'Int64'})\\n\"], \"postgresql\": [\"CREATE TABLE Contacts (\\n id SERIAL PRIMARY KEY,\\n first_name VARCHAR(20),\\n last_name VARCHAR(20)\\n);\\n\", \"CREATE TABLE Calls (\\n contact_id INT,\\n type VARCHAR(20) NOT NULL CHECK (type IN ('incoming', 'outgoing')),\\n duration INT\\n);\\n\"], \"manual\": true, \"database_schema\": {\"Contacts\": {\"id\": \"INT\", \"first_name\": \"VARCHAR(20)\", \"last_name\": \"VARCHAR(20)\"}, \"Calls\": {\"contact_id\": \"INT\", \"type\": \"ENUM('incoming', 'outgoing')\", \"duration\": \"INT\"}}}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Create table if Not Exists Contacts(id int, first_name varchar(20), last_name varchar(20))",
|
||||
"Create table if Not Exists Calls(contact_id int, type ENUM('incoming', 'outgoing'), duration int)",
|
||||
"Truncate table Contacts",
|
||||
"insert into Contacts (id, first_name, last_name) values ('1', 'John', 'Doe')",
|
||||
"insert into Contacts (id, first_name, last_name) values ('2', 'Jane', 'Smith')",
|
||||
"insert into Contacts (id, first_name, last_name) values ('3', 'Alice', 'Johnson')",
|
||||
"insert into Contacts (id, first_name, last_name) values ('4', 'Michael', 'Brown')",
|
||||
"insert into Contacts (id, first_name, last_name) values ('5', 'Emily', 'Davis')",
|
||||
"Truncate table Calls",
|
||||
"insert into Calls (contact_id, type, duration) values ('1', 'incoming', '120')",
|
||||
"insert into Calls (contact_id, type, duration) values ('1', 'outgoing', '180')",
|
||||
"insert into Calls (contact_id, type, duration) values ('2', 'incoming', '300')",
|
||||
"insert into Calls (contact_id, type, duration) values ('2', 'outgoing', '240')",
|
||||
"insert into Calls (contact_id, type, duration) values ('3', 'incoming', '150')",
|
||||
"insert into Calls (contact_id, type, duration) values ('3', 'outgoing', '360')",
|
||||
"insert into Calls (contact_id, type, duration) values ('4', 'incoming', '420')",
|
||||
"insert into Calls (contact_id, type, duration) values ('4', 'outgoing', '200')",
|
||||
"insert into Calls (contact_id, type, duration) values ('5', 'incoming', '180')",
|
||||
"insert into Calls (contact_id, type, duration) values ('5', 'outgoing', '280')"
|
||||
],
|
||||
"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>\"], \"pythondata\": [\"Pandas\", \"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0</p>\"], \"postgresql\": [\"PostgreSQL\", \"<p>PostgreSQL 16</p>\"]}",
|
||||
"libraryUrl": null,
|
||||
"adminUrl": null,
|
||||
"challengeQuestion": null,
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
71
leetcode/originData/[no content]friday-purchase-iii.json
Normal file
71
leetcode/originData/[no content]friday-purchase-iii.json
Normal file
@ -0,0 +1,71 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "3424",
|
||||
"questionFrontendId": "3118",
|
||||
"boundTopicId": null,
|
||||
"title": "Friday Purchase III ",
|
||||
"titleSlug": "friday-purchase-iii",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Medium",
|
||||
"likes": 3,
|
||||
"dislikes": 2,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"exampleTestcases": "{\"headers\":{\"Purchases\":[\"user_id\",\"purchase_date\",\"amount_spend\"],\"Users\":[\"user_id\",\"membership\"]},\"rows\":{\"Purchases\":[[11,\"2023-11-03\",1126],[15,\"2023-11-10\",7473],[17,\"2023-11-17\",2414],[12,\"2023-11-24\",9692],[8,\"2023-11-24\",5117],[1,\"2023-11-24\",5241],[10,\"2023-11-22\",8266],[13,\"2023-11-21\",12000]],\"Users\":[[11,\"Premium\"],[15,\"VIP\"],[17,\"Standard\"],[12,\"VIP\"],[8,\"Premium\"],[1,\"VIP\"],[10,\"Standard\"],[13,\"Premium\"]]}}",
|
||||
"categoryTitle": "Database",
|
||||
"contributors": [],
|
||||
"topicTags": [
|
||||
{
|
||||
"name": "Database",
|
||||
"slug": "database",
|
||||
"translatedName": null,
|
||||
"__typename": "TopicTagNode"
|
||||
}
|
||||
],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"221\", \"totalSubmission\": \"341\", \"totalAcceptedRaw\": 221, \"totalSubmissionRaw\": 341, \"acRate\": \"64.8%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\":{\"Purchases\":[\"user_id\",\"purchase_date\",\"amount_spend\"],\"Users\":[\"user_id\",\"membership\"]},\"rows\":{\"Purchases\":[[11,\"2023-11-03\",1126],[15,\"2023-11-10\",7473],[17,\"2023-11-17\",2414],[12,\"2023-11-24\",9692],[8,\"2023-11-24\",5117],[1,\"2023-11-24\",5241],[10,\"2023-11-22\",8266],[13,\"2023-11-21\",12000]],\"Users\":[[11,\"Premium\"],[15,\"VIP\"],[17,\"Standard\"],[12,\"VIP\"],[8,\"Premium\"],[1,\"VIP\"],[10,\"Standard\"],[13,\"Premium\"]]}}",
|
||||
"metaData": "{\"mysql\": [\"Create Table if Not Exists Purchases( user_id int, purchase_date date, amount_spend int)\", \"Create Table if Not Exists Users (user_id int, membership enum('Standard', 'Premium', 'VIP'))\"], \"mssql\": [\"Create Table Purchases( user_id int, purchase_date date, amount_spend int)\", \"Create Table Users (user_id int, membership varchar(30) NOT NULL CHECK ( membership in ('Standard', 'Premium', 'VIP')))\"], \"oraclesql\": [\"Create Table Purchases( user_id int, purchase_date date, amount_spend int)\", \"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\", \"Create Table Users (user_id int, membership varchar(30) NOT NULL CHECK ( membership in ('Standard', 'Premium', 'VIP')))\"], \"database\": true, \"name\": \"friday_purchases\", \"postgresql\": [\"CREATE TABLE Purchases (\\n user_id int,\\n purchase_date date,\\n amount_spend int\\n);\", \"SET datestyle = 'ISO, MDY'; \\n\", \"CREATE TABLE Users (\\n user_id int,\\n membership varchar(30) NOT NULL CHECK (membership IN ('Standard', 'Premium', 'VIP'))\\n);\"], \"pythondata\": [\"Purchases = pd.DataFrame([], columns=['user_id', 'purchase_date', 'amount_spend']).astype({'user_id':'Int64', 'purchase_date':'datetime64[ns]', 'amount_spend':'Int64'})\\n\", \"Users = pd.DataFrame([], columns=['user_id', 'membership']).astype({\\n 'user_id': 'Int64',\\n 'membership': pd.CategoricalDtype(categories=['Standard', 'Premium', 'VIP'])\\n})\"], \"database_schema\": {\"Purchases\": {\"user_id\": \"INT\", \"purchase_date\": \"DATE\", \"amount_spend\": \"INT\"}, \"Users\": {\"user_id\": \"INT\", \"membership\": \"ENUM('Standard', 'Premium', 'VIP')\"}}}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Create Table if Not Exists Purchases( user_id int, purchase_date date, amount_spend int)",
|
||||
"Create Table if Not Exists Users (user_id int, membership enum('Standard', 'Premium', 'VIP'))",
|
||||
"Truncate table Purchases",
|
||||
"insert into Purchases (user_id, purchase_date, amount_spend) values ('11', '2023-11-03', '1126')",
|
||||
"insert into Purchases (user_id, purchase_date, amount_spend) values ('15', '2023-11-10', '7473')",
|
||||
"insert into Purchases (user_id, purchase_date, amount_spend) values ('17', '2023-11-17', '2414')",
|
||||
"insert into Purchases (user_id, purchase_date, amount_spend) values ('12', '2023-11-24', '9692')",
|
||||
"insert into Purchases (user_id, purchase_date, amount_spend) values ('8', '2023-11-24', '5117')",
|
||||
"insert into Purchases (user_id, purchase_date, amount_spend) values ('1', '2023-11-24', '5241')",
|
||||
"insert into Purchases (user_id, purchase_date, amount_spend) values ('10', '2023-11-22', '8266')",
|
||||
"insert into Purchases (user_id, purchase_date, amount_spend) values ('13', '2023-11-21', '12000')",
|
||||
"Truncate table Users",
|
||||
"insert into Users (user_id, membership) values ('11', 'Premium')",
|
||||
"insert into Users (user_id, membership) values ('15', 'VIP')",
|
||||
"insert into Users (user_id, membership) values ('17', 'Standard')",
|
||||
"insert into Users (user_id, membership) values ('12', 'VIP')",
|
||||
"insert into Users (user_id, membership) values ('8', 'Premium')",
|
||||
"insert into Users (user_id, membership) values ('1', 'VIP')",
|
||||
"insert into Users (user_id, membership) values ('10', 'Standard')",
|
||||
"insert into Users (user_id, membership) values ('13', 'Premium')"
|
||||
],
|
||||
"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>\"], \"pythondata\": [\"Pandas\", \"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0</p>\"], \"postgresql\": [\"PostgreSQL\", \"<p>PostgreSQL 16</p>\"]}",
|
||||
"libraryUrl": null,
|
||||
"adminUrl": null,
|
||||
"challengeQuestion": null,
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
47
leetcode/originData/[no content]maximum-number-that-makes-result-of-bitwise-and-zero.json
Normal file
47
leetcode/originData/[no content]maximum-number-that-makes-result-of-bitwise-and-zero.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
173
leetcode/originData/distribute-elements-into-two-arrays-i.json
Normal file
173
leetcode/originData/distribute-elements-into-two-arrays-i.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
192
leetcode/originData/find-edges-in-shortest-paths.json
Normal file
192
leetcode/originData/find-edges-in-shortest-paths.json
Normal file
File diff suppressed because one or more lines are too long
161
leetcode/originData/find-the-integer-added-to-array-i.json
Normal file
161
leetcode/originData/find-the-integer-added-to-array-i.json
Normal file
File diff suppressed because one or more lines are too long
161
leetcode/originData/find-the-integer-added-to-array-ii.json
Normal file
161
leetcode/originData/find-the-integer-added-to-array-ii.json
Normal file
File diff suppressed because one or more lines are too long
189
leetcode/originData/find-the-number-of-subarrays-where-boundary-elements-are-maximum.json
Normal file
189
leetcode/originData/find-the-number-of-subarrays-where-boundary-elements-are-maximum.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
160
leetcode/originData/make-a-square-with-the-same-color.json
Normal file
160
leetcode/originData/make-a-square-with-the-same-color.json
Normal file
File diff suppressed because one or more lines are too long
162
leetcode/originData/minimum-array-end.json
Normal file
162
leetcode/originData/minimum-array-end.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
181
leetcode/originData/minimum-rectangles-to-cover-points.json
Normal file
181
leetcode/originData/minimum-rectangles-to-cover-points.json
Normal file
File diff suppressed because one or more lines are too long
201
leetcode/originData/minimum-sum-of-values-by-dividing-array.json
Normal file
201
leetcode/originData/minimum-sum-of-values-by-dividing-array.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
162
leetcode/originData/right-triangles.json
Normal file
162
leetcode/originData/right-triangles.json
Normal file
File diff suppressed because one or more lines are too long
167
leetcode/originData/score-of-a-string.json
Normal file
167
leetcode/originData/score-of-a-string.json
Normal file
File diff suppressed because one or more lines are too long
@ -0,0 +1,48 @@
|
||||
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p>
|
||||
|
||||
<p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">word = "aaAbcBC"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">3</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The special characters in <code>word</code> are <code>'a'</code>, <code>'b'</code>, and <code>'c'</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">word = "abc"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">0</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>No character in <code>word</code> appears in uppercase.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">word = "abBCab"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> 1</p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The only special character in <code>word</code> is <code>'b'</code>.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= word.length <= 50</code></li>
|
||||
<li><code>word</code> consists of only lowercase and uppercase English letters.</li>
|
||||
</ul>
|
@ -0,0 +1,48 @@
|
||||
<p>You are given a string <code>word</code>. A letter <code>c</code> is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>, and <strong>every</strong> lowercase occurrence of <code>c</code> appears before the <strong>first</strong> uppercase occurrence of <code>c</code>.</p>
|
||||
|
||||
<p>Return the number of<em> </em><strong>special</strong> letters<em> </em>in<em> </em><code>word</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">word = "aaAbcBC"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">3</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The special characters are <code>'a'</code>, <code>'b'</code>, and <code>'c'</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">word = "abc"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">0</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>There are no special characters in <code>word</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">word = "AbBCab"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">0</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>There are no special characters in <code>word</code>.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= word.length <= 2 * 10<sup>5</sup></code></li>
|
||||
<li><code>word</code> consists of only lowercase and uppercase English letters.</li>
|
||||
</ul>
|
44
leetcode/problem/distribute-elements-into-two-arrays-i.html
Normal file
44
leetcode/problem/distribute-elements-into-two-arrays-i.html
Normal file
@ -0,0 +1,44 @@
|
||||
<p>You are given a <strong>1-indexed</strong> array of <strong>distinct</strong> integers <code>nums</code> of length <code>n</code>.</p>
|
||||
|
||||
<p>You need to distribute all the elements of <code>nums</code> between two arrays <code>arr1</code> and <code>arr2</code> using <code>n</code> operations. In the first operation, append <code>nums[1]</code> to <code>arr1</code>. In the second operation, append <code>nums[2]</code> to <code>arr2</code>. Afterwards, in the <code>i<sup>th</sup></code> operation:</p>
|
||||
|
||||
<ul>
|
||||
<li>If the last element of <code>arr1</code> is<strong> greater</strong> than the last element of <code>arr2</code>, append <code>nums[i]</code> to <code>arr1</code>. Otherwise, append <code>nums[i]</code> to <code>arr2</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>The array <code>result</code> is formed by concatenating the arrays <code>arr1</code> and <code>arr2</code>. For example, if <code>arr1 == [1,2,3]</code> and <code>arr2 == [4,5,6]</code>, then <code>result = [1,2,3,4,5,6]</code>.</p>
|
||||
|
||||
<p>Return <em>the array</em> <code>result</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [2,1,3]
|
||||
<strong>Output:</strong> [2,3,1]
|
||||
<strong>Explanation:</strong> After the first 2 operations, arr1 = [2] and arr2 = [1].
|
||||
In the 3<sup>rd</sup> operation, as the last element of arr1 is greater than the last element of arr2 (2 > 1), append nums[3] to arr1.
|
||||
After 3 operations, arr1 = [2,3] and arr2 = [1].
|
||||
Hence, the array result formed by concatenation is [2,3,1].
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [5,4,3,8]
|
||||
<strong>Output:</strong> [5,3,4,8]
|
||||
<strong>Explanation:</strong> After the first 2 operations, arr1 = [5] and arr2 = [4].
|
||||
In the 3<sup>rd</sup> operation, as the last element of arr1 is greater than the last element of arr2 (5 > 4), append nums[3] to arr1, hence arr1 becomes [5,3].
|
||||
In the 4<sup>th</sup> operation, as the last element of arr2 is greater than the last element of arr1 (4 > 3), append nums[4] to arr2, hence arr2 becomes [4,8].
|
||||
After 4 operations, arr1 = [5,3] and arr2 = [4,8].
|
||||
Hence, the array result formed by concatenation is [5,3,4,8].
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>3 <= n <= 50</code></li>
|
||||
<li><code>1 <= nums[i] <= 100</code></li>
|
||||
<li>All elements in <code>nums</code> are distinct.</li>
|
||||
</ul>
|
@ -0,0 +1,59 @@
|
||||
<p>You are given 3 positive integers <code>zero</code>, <code>one</code>, and <code>limit</code>.</p>
|
||||
|
||||
<p>A <span data-keyword="binary-array">binary array</span> <code>arr</code> is called <strong>stable</strong> if:</p>
|
||||
|
||||
<ul>
|
||||
<li>The number of occurrences of 0 in <code>arr</code> is <strong>exactly </strong><code>zero</code>.</li>
|
||||
<li>The number of occurrences of 1 in <code>arr</code> is <strong>exactly</strong> <code>one</code>.</li>
|
||||
<li>Each <span data-keyword="subarray-nonempty">subarray</span> of <code>arr</code> with a size greater than <code>limit</code> must contain <strong>both </strong>0 and 1.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return the <em>total</em> number of <strong>stable</strong> binary arrays.</p>
|
||||
|
||||
<p>Since the answer may be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">zero = 1, one = 1, limit = 2</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">2</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The two possible stable binary arrays are <code>[1,0]</code> and <code>[0,1]</code>, as both arrays have a single 0 and a single 1, and no subarray has a length greater than 2.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">zero = 1, one = 2, limit = 1</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">1</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The only possible stable binary array is <code>[1,0,1]</code>.</p>
|
||||
|
||||
<p>Note that the binary arrays <code>[1,1,0]</code> and <code>[0,1,1]</code> have subarrays of length 2 with identical elements, hence, they are not stable.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">zero = 3, one = 3, limit = 2</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">14</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>All the possible stable binary arrays are <code>[0,0,1,0,1,1]</code>, <code>[0,0,1,1,0,1]</code>, <code>[0,1,0,0,1,1]</code>, <code>[0,1,0,1,0,1]</code>, <code>[0,1,0,1,1,0]</code>, <code>[0,1,1,0,0,1]</code>, <code>[0,1,1,0,1,0]</code>, <code>[1,0,0,1,0,1]</code>, <code>[1,0,0,1,1,0]</code>, <code>[1,0,1,0,0,1]</code>, <code>[1,0,1,0,1,0]</code>, <code>[1,0,1,1,0,0]</code>, <code>[1,1,0,0,1,0]</code>, and <code>[1,1,0,1,0,0]</code>.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= zero, one, limit <= 200</code></li>
|
||||
</ul>
|
@ -0,0 +1,57 @@
|
||||
<p>You are given 3 positive integers <code>zero</code>, <code>one</code>, and <code>limit</code>.</p>
|
||||
|
||||
<p>A <span data-keyword="binary-array">binary array</span> <code>arr</code> is called <strong>stable</strong> if:</p>
|
||||
|
||||
<ul>
|
||||
<li>The number of occurrences of 0 in <code>arr</code> is <strong>exactly </strong><code>zero</code>.</li>
|
||||
<li>The number of occurrences of 1 in <code>arr</code> is <strong>exactly</strong> <code>one</code>.</li>
|
||||
<li>Each <span data-keyword="subarray-nonempty">subarray</span> of <code>arr</code> with a size greater than <code>limit</code> must contain <strong>both </strong>0 and 1.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return the <em>total</em> number of <strong>stable</strong> binary arrays.</p>
|
||||
|
||||
<p>Since the answer may be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">zero = 1, one = 1, limit = 2</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">2</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The two possible stable binary arrays are <code>[1,0]</code> and <code>[0,1]</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">zero = 1, one = 2, limit = 1</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">1</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The only possible stable binary array is <code>[1,0,1]</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">zero = 3, one = 3, limit = 2</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">14</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>All the possible stable binary arrays are <code>[0,0,1,0,1,1]</code>, <code>[0,0,1,1,0,1]</code>, <code>[0,1,0,0,1,1]</code>, <code>[0,1,0,1,0,1]</code>, <code>[0,1,0,1,1,0]</code>, <code>[0,1,1,0,0,1]</code>, <code>[0,1,1,0,1,0]</code>, <code>[1,0,0,1,0,1]</code>, <code>[1,0,0,1,1,0]</code>, <code>[1,0,1,0,0,1]</code>, <code>[1,0,1,0,1,0]</code>, <code>[1,0,1,1,0,0]</code>, <code>[1,1,0,0,1,0]</code>, and <code>[1,1,0,1,0,0]</code>.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= zero, one, limit <= 1000</code></li>
|
||||
</ul>
|
51
leetcode/problem/find-edges-in-shortest-paths.html
Normal file
51
leetcode/problem/find-edges-in-shortest-paths.html
Normal file
@ -0,0 +1,51 @@
|
||||
<p>You are given an undirected weighted graph of <code>n</code> nodes numbered from 0 to <code>n - 1</code>. The graph consists of <code>m</code> edges represented by a 2D array <code>edges</code>, where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge between nodes <code>a<sub>i</sub></code> and <code>b<sub>i</sub></code> with weight <code>w<sub>i</sub></code>.</p>
|
||||
|
||||
<p>Consider all the shortest paths from node 0 to node <code>n - 1</code> in the graph. You need to find a <strong>boolean</strong> array <code>answer</code> where <code>answer[i]</code> is <code>true</code> if the edge <code>edges[i]</code> is part of <strong>at least</strong> one shortest path. Otherwise, <code>answer[i]</code> is <code>false</code>.</p>
|
||||
|
||||
<p>Return the array <code>answer</code>.</p>
|
||||
|
||||
<p><strong>Note</strong> that the graph may not be connected.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2024/03/05/graph35drawio-1.png" style="height: 129px; width: 250px;" />
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">n = 6, edges = [[0,1,4],[0,2,1],[1,3,2],[1,4,3],[1,5,1],[2,3,1],[3,5,3],[4,5,2]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">[true,true,true,false,true,true,true,false]</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The following are <strong>all</strong> the shortest paths between nodes 0 and 5:</p>
|
||||
|
||||
<ul>
|
||||
<li>The path <code>0 -> 1 -> 5</code>: The sum of weights is <code>4 + 1 = 5</code>.</li>
|
||||
<li>The path <code>0 -> 2 -> 3 -> 5</code>: The sum of weights is <code>1 + 1 + 3 = 5</code>.</li>
|
||||
<li>The path <code>0 -> 2 -> 3 -> 1 -> 5</code>: The sum of weights is <code>1 + 1 + 2 + 1 = 5</code>.</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2024/03/05/graphhhh.png" style="width: 185px; height: 136px;" />
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">n = 4, edges = [[2,0,1],[0,1,1],[0,3,4],[3,2,2]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">[true,false,false,true]</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>There is one shortest path between nodes 0 and 3, which is the path <code>0 -> 2 -> 3</code> with the sum of weights <code>1 + 2 = 3</code>.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= n <= 5 * 10<sup>4</sup></code></li>
|
||||
<li><code>m == edges.length</code></li>
|
||||
<li><code>1 <= m <= min(5 * 10<sup>4</sup>, n * (n - 1) / 2)</code></li>
|
||||
<li><code>0 <= a<sub>i</sub>, b<sub>i</sub> < n</code></li>
|
||||
<li><code>a<sub>i</sub> != b<sub>i</sub></code></li>
|
||||
<li><code>1 <= w<sub>i</sub> <= 10<sup>5</sup></code></li>
|
||||
<li>There are no repeated edges.</li>
|
||||
</ul>
|
71
leetcode/problem/find-the-integer-added-to-array-i.html
Normal file
71
leetcode/problem/find-the-integer-added-to-array-i.html
Normal file
@ -0,0 +1,71 @@
|
||||
<p>You are given two arrays of equal length, <code>nums1</code> and <code>nums2</code>.</p>
|
||||
|
||||
<p>Each element in <code>nums1</code> has been increased (or decreased in the case of negative) by an integer, represented by the variable <code>x</code>.</p>
|
||||
|
||||
<p>As a result, <code>nums1</code> becomes <strong>equal</strong> to <code>nums2</code>. Two arrays are considered <strong>equal</strong> when they contain the same integers with the same frequencies.</p>
|
||||
|
||||
<p>Return the integer <code>x</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">nums1 = [2,6,4], nums2 = [9,7,5]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">3</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The integer added to each element of <code>nums1</code> is 3.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">nums1 = [10], nums2 = [5]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">-5</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The integer added to each element of <code>nums1</code> is -5.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">nums1 = [1,1,1,1], nums2 = [1,1,1,1]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">0</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The integer added to each element of <code>nums1</code> is 0.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums1.length == nums2.length <= 100</code></li>
|
||||
<li><code>0 <= nums1[i], nums2[i] <= 1000</code></li>
|
||||
<li>The test cases are generated in a way that there is an integer <code>x</code> such that <code>nums1</code> can become equal to <code>nums2</code> by adding <code>x</code> to each element of <code>nums1</code>.</li>
|
||||
</ul>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user