mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-03 14:32:54 +08:00
update
This commit is contained in:
File diff suppressed because it is too large
Load Diff
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
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
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>
|
54
leetcode/problem/find-the-integer-added-to-array-ii.html
Normal file
54
leetcode/problem/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>
|
@@ -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>
|
@@ -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,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>
|
129
leetcode/problem/make-a-square-with-the-same-color.html
Normal file
129
leetcode/problem/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>
|
35
leetcode/problem/minimum-array-end.html
Normal file
35
leetcode/problem/minimum-array-end.html
Normal file
@@ -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>
|
@@ -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>
|
125
leetcode/problem/minimum-rectangles-to-cover-points.html
Normal file
125
leetcode/problem/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>
|
@@ -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>
|
@@ -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>
|
164
leetcode/problem/right-triangles.html
Normal file
164
leetcode/problem/right-triangles.html
Normal file
@@ -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>
|
36
leetcode/problem/score-of-a-string.html
Normal file
36
leetcode/problem/score-of-a-string.html
Normal file
@@ -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>
|
Reference in New Issue
Block a user