1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 10:38:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
zhangbk1 2024-08-06 08:46:50 +08:00
parent 43a450d3d7
commit 91ca37c7ef
114 changed files with 28799 additions and 15728 deletions

View File

@ -1,6 +1,6 @@
# 力扣题库(完整版)
> 最后更新日期: **2024.07.16**
> 最后更新日期: **2024.08.06**
>
> 使用脚本前请务必仔细完整阅读本 `README.md` 文件

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,64 @@
{
"data": {
"question": {
"questionId": "3549",
"questionFrontendId": "3236",
"categoryTitle": "Database",
"boundTopicId": 2861886,
"title": "CEO Subordinate Hierarchy",
"titleSlug": "ceo-subordinate-hierarchy",
"content": null,
"translatedTitle": "首席执行官下属层级",
"translatedContent": null,
"isPaidOnly": true,
"difficulty": "Hard",
"likes": 0,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
"contributors": [],
"langToValidPlayground": null,
"topicTags": [
{
"name": "Database",
"slug": "database",
"translatedName": "数据库",
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": null,
"stats": "{\"totalAccepted\": \"45\", \"totalSubmission\": \"57\", \"totalAcceptedRaw\": 45, \"totalSubmissionRaw\": 57, \"acRate\": \"78.9%\"}",
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "{\"headers\":{\"Employees\":[\"employee_id\",\"employee_name\",\"manager_id\",\"salary\"]},\"rows\":{\"Employees\":[[1,\"Alice\",null,150000],[2,\"Bob\",1,120000],[3,\"Charlie\",1,110000],[4,\"David\",2,105000],[5,\"Eve\",2,100000],[6,\"Frank\",3,95000],[7,\"Grace\",3,98000],[8,\"Helen\",5,90000]]}}",
"metaData": "{\"mysql\":[\"Create table if not exists employees(employee_id int, employee_name varchar(100), manager_id int, salary int)\"],\"mssql\":[\"Create table employees(employee_id int, employee_name varchar(100), manager_id int, salary int)\"],\"oraclesql\":[\"Create table employees(employee_id NUMBER, employee_name varchar2(100), manager_id NUMBER, salary NUMBER)\"],\"database\":true,\"name\":\"find_subordinates\",\"manual\":false,\"postgresql\":[\"CREATE TABLE IF NOT EXISTS employees (\\n employee_id INT,\\n employee_name VARCHAR(100),\\n manager_id INT,\\n salary INT\\n);\\n\"],\"pythondata\":[\"Employees = pd.DataFrame(columns=['employee_id', 'employee_name', 'manager_id', 'salary']).astype({\\n 'employee_id': pd.Int64Dtype(),\\n 'employee_name': 'str',\\n 'manager_id': pd.Int64Dtype(),\\n 'salary': pd.Int64Dtype()\\n})\"],\"database_schema\":{\"employees\":{\"employee_id\":\"INT\",\"employee_name\":\"VARCHAR(100)\",\"manager_id\":\"INT\",\"salary\":\"INT\"}}}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [
"Create table if not exists employees(employee_id int, employee_name varchar(100), manager_id int, salary int)",
"Truncate table Employees",
"insert into Employees (employee_id, employee_name, manager_id, salary) values ('1', 'Alice', 'None', '150000')",
"insert into Employees (employee_id, employee_name, manager_id, salary) values ('2', 'Bob', '1', '120000')",
"insert into Employees (employee_id, employee_name, manager_id, salary) values ('3', 'Charlie', '1', '110000')",
"insert into Employees (employee_id, employee_name, manager_id, salary) values ('4', 'David', '2', '105000')",
"insert into Employees (employee_id, employee_name, manager_id, salary) values ('5', 'Eve', '2', '100000')",
"insert into Employees (employee_id, employee_name, manager_id, salary) values ('6', 'Frank', '3', '95000')",
"insert into Employees (employee_id, employee_name, manager_id, salary) values ('7', 'Grace', '3', '98000')",
"insert into Employees (employee_id, employee_name, manager_id, salary) values ('8', 'Helen', '5', '90000')"
],
"enableRunCode": true,
"envInfo": "{\"mysql\":[\"MySQL\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>PostgreSQL 16<\\/p>\"]}",
"book": null,
"isSubscribed": false,
"isDailyQuestion": false,
"dailyRecordStatus": null,
"editorType": "CKEDITOR",
"ugcQuestionId": null,
"style": "LEETCODE",
"exampleTestcases": "{\"headers\":{\"Employees\":[\"employee_id\",\"employee_name\",\"manager_id\",\"salary\"]},\"rows\":{\"Employees\":[[1,\"Alice\",null,150000],[2,\"Bob\",1,120000],[3,\"Charlie\",1,110000],[4,\"David\",2,105000],[5,\"Eve\",2,100000],[6,\"Frank\",3,95000],[7,\"Grace\",3,98000],[8,\"Helen\",5,90000]]}}",
"__typename": "QuestionNode"
}
}
}

View File

@ -0,0 +1,66 @@
{
"data": {
"question": {
"questionId": "3539",
"questionFrontendId": "3230",
"categoryTitle": "Database",
"boundTopicId": 2852426,
"title": "Customer Purchasing Behavior Analysis",
"titleSlug": "customer-purchasing-behavior-analysis",
"content": null,
"translatedTitle": "客户购买行为分析",
"translatedContent": null,
"isPaidOnly": true,
"difficulty": "Medium",
"likes": 0,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
"contributors": [],
"langToValidPlayground": null,
"topicTags": [
{
"name": "Database",
"slug": "database",
"translatedName": "数据库",
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": null,
"stats": "{\"totalAccepted\": \"55\", \"totalSubmission\": \"162\", \"totalAcceptedRaw\": 55, \"totalSubmissionRaw\": 162, \"acRate\": \"34.0%\"}",
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "{\"headers\":{\"Transactions\":[\"transaction_id\",\"customer_id\",\"product_id\",\"transaction_date\",\"amount\"],\"Products\":[\"product_id\",\"category\",\"price\"]},\"rows\":{\"Transactions\":[[1,101,1,\"2023-01-01\",100.00],[2,101,2,\"2023-01-15\",150.00],[3,102,1,\"2023-01-01\",100.00],[4,102,3,\"2023-01-22\",200.00],[5,101,3,\"2023-02-10\",200.00]],\"Products\":[[1,\"A\",100.00],[2,\"B\",150.00],[3,\"C\",200.00]]}}",
"metaData": "{\"mysql\":[\"CREATE TABLE if not exists Transactions (\\n transaction_id INT,\\n customer_id INT,\\n product_id INT,\\n transaction_date DATE,\\n amount DECIMAL(10, 2)\\n)\",\"CREATE TABLE if not exists Products (\\n product_id INT ,\\n category VARCHAR(255),\\n price DECIMAL(10, 2)\\n)\\n\"],\"mssql\":[\"CREATE TABLE Transactions (\\n transaction_id INT ,\\n customer_id INT,\\n product_id INT,\\n transaction_date DATE,\\n amount DECIMAL(10, 2)\\n)\\n\",\"\\nCREATE TABLE Products (\\n product_id INT ,\\n category VARCHAR(255),\\n price DECIMAL(10, 2)\\n)\"],\"oraclesql\":[\"CREATE TABLE Transactions (\\n transaction_id NUMBER ,\\n customer_id NUMBER,\\n product_id NUMBER,\\n transaction_date DATE,\\n amount NUMBER(10, 2)\\n)\",\"CREATE TABLE Products (\\n product_id NUMBER ,\\n category VARCHAR2(255),\\n price NUMBER(10, 2)\\n)\",\"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"],\"database\":true,\"name\":\"analyze_customer_behavior\",\"postgresql\":[\"CREATE TABLE IF NOT EXISTS Transactions (\\n transaction_id INTEGER,\\n customer_id INTEGER,\\n product_id INTEGER,\\n transaction_date DATE,\\n amount NUMERIC(10, 2)\\n);\\n\",\"CREATE TABLE IF NOT EXISTS Products (\\n product_id INTEGER,\\n category VARCHAR(255),\\n price NUMERIC(10, 2)\\n);\\n\"],\"pythondata\":[\"Transactions = pd.DataFrame(columns=['transaction_id', 'customer_id', 'product_id', 'transaction_date', 'amount']).astype({'transaction_id': 'int', 'customer_id': 'int', 'product_id': 'int', 'transaction_date': 'datetime64[ns]', 'amount': 'float'})\",\"Products = pd.DataFrame(columns=['product_id', 'category', 'price']).astype({'product_id': 'int', 'category': 'str', 'price': 'float'})\"],\"database_schema\":{\"Transactions\":{\"transaction_id\":\"INT\",\"customer_id\":\"INT\",\"product_id\":\"INT\",\"transaction_date\":\"DATE\",\"amount\":\"DECIMAL(10, 2)\"},\"Products\":{\"product_id\":\"INT\",\"category\":\"VARCHAR(255)\",\"price\":\"DECIMAL(10, 2)\"}}}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [
"CREATE TABLE if not exists Transactions (\n transaction_id INT,\n customer_id INT,\n product_id INT,\n transaction_date DATE,\n amount DECIMAL(10, 2)\n)",
"CREATE TABLE if not exists Products (\n product_id INT ,\n category VARCHAR(255),\n price DECIMAL(10, 2)\n)\n",
"Truncate table Transactions",
"insert into Transactions (transaction_id, customer_id, product_id, transaction_date, amount) values ('1', '101', '1', '2023-01-01', '100.0')",
"insert into Transactions (transaction_id, customer_id, product_id, transaction_date, amount) values ('2', '101', '2', '2023-01-15', '150.0')",
"insert into Transactions (transaction_id, customer_id, product_id, transaction_date, amount) values ('3', '102', '1', '2023-01-01', '100.0')",
"insert into Transactions (transaction_id, customer_id, product_id, transaction_date, amount) values ('4', '102', '3', '2023-01-22', '200.0')",
"insert into Transactions (transaction_id, customer_id, product_id, transaction_date, amount) values ('5', '101', '3', '2023-02-10', '200.0')",
"Truncate table Products",
"insert into Products (product_id, category, price) values ('1', 'A', '100.0')",
"insert into Products (product_id, category, price) values ('2', 'B', '150.0')",
"insert into Products (product_id, category, price) values ('3', 'C', '200.0')"
],
"enableRunCode": true,
"envInfo": "{\"mysql\":[\"MySQL\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>PostgreSQL 16<\\/p>\"]}",
"book": null,
"isSubscribed": false,
"isDailyQuestion": false,
"dailyRecordStatus": null,
"editorType": "CKEDITOR",
"ugcQuestionId": null,
"style": "LEETCODE",
"exampleTestcases": "{\"headers\":{\"Transactions\":[\"transaction_id\",\"customer_id\",\"product_id\",\"transaction_date\",\"amount\"],\"Products\":[\"product_id\",\"category\",\"price\"]},\"rows\":{\"Transactions\":[[1,101,1,\"2023-01-01\",100.00],[2,101,2,\"2023-01-15\",150.00],[3,102,1,\"2023-01-01\",100.00],[4,102,3,\"2023-01-22\",200.00],[5,101,3,\"2023-02-10\",200.00]],\"Products\":[[1,\"A\",100.00],[2,\"B\",150.00],[3,\"C\",200.00]]}}",
"__typename": "QuestionNode"
}
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,61 @@
{
"data": {
"question": {
"questionId": "3554",
"questionFrontendId": "3246",
"categoryTitle": "Database",
"boundTopicId": 2869459,
"title": "Premier League Table Ranking",
"titleSlug": "premier-league-table-ranking",
"content": null,
"translatedTitle": "英超积分榜排名",
"translatedContent": null,
"isPaidOnly": true,
"difficulty": "Easy",
"likes": 0,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
"contributors": [],
"langToValidPlayground": null,
"topicTags": [
{
"name": "Database",
"slug": "database",
"translatedName": "数据库",
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": null,
"stats": "{\"totalAccepted\": \"32\", \"totalSubmission\": \"35\", \"totalAcceptedRaw\": 32, \"totalSubmissionRaw\": 35, \"acRate\": \"91.4%\"}",
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "{\"headers\":{\"TeamStats\":[\"team_id\",\"team_name\",\"matches_played\",\"wins\",\"draws\",\"losses\"]},\"rows\":{\"TeamStats\":[[1,\"Manchester City\",10,6,2,2],[2,\"Liverpool\",10,6,2,2],[3,\"Chelsea\",10,5,3,2],[4,\"Arsenal\",10,4,4,2],[5,\"Tottenham\",10,3,5,2]]}}",
"metaData": "{\"mysql\":[\"Create table if not exists TeamStats( team_id int, team_name varchar(100),matches_played int, wins int,draws int,losses int)\"],\"mssql\":[\"Create table TeamStats( team_id int, team_name varchar(100),matches_played int, wins int,draws int,losses int)\"],\"oraclesql\":[\"Create table TeamStats( team_id NUMBER, team_name varchar2(100),matches_played NUMBER, wins NUMBER,draws NUMBER,losses NUMBER)\"],\"database\":true,\"name\":\"calculate_team_standings\",\"postgresql\":[\"CREATE TABLE IF NOT EXISTS TeamStats (\\n team_id INT,\\n team_name VARCHAR(100),\\n matches_played INT,\\n wins INT,\\n draws INT,\\n losses INT\\n);\\n\"],\"pythondata\":[\"TeamStats = pd.DataFrame(data, columns=[\\\"team_id\\\", \\\"team_name\\\", \\\"matches_played\\\", \\\"wins\\\", \\\"draws\\\", \\\"losses\\\"]).astype({\\\"team_id\\\": \\\"int\\\", \\\"team_name\\\": \\\"string\\\", \\\"matches_played\\\": \\\"int\\\", \\\"wins\\\": \\\"int\\\", \\\"draws\\\": \\\"int\\\", \\\"losses\\\": \\\"int\\\"})\\n\"],\"database_schema\":{\"TeamStats\":{\"team_id\":\"INT\",\"team_name\":\"VARCHAR(100)\",\"matches_played\":\"INT\",\"wins\":\"INT\",\"draws\":\"INT\",\"losses\":\"INT\"}}}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [
"Create table if not exists TeamStats( team_id int, team_name varchar(100),matches_played int, wins int,draws int,losses int)",
"Truncate table TeamStats",
"insert into TeamStats (team_id, team_name, matches_played, wins, draws, losses) values ('1', 'Manchester City', '10', '6', '2', '2')",
"insert into TeamStats (team_id, team_name, matches_played, wins, draws, losses) values ('2', 'Liverpool', '10', '6', '2', '2')",
"insert into TeamStats (team_id, team_name, matches_played, wins, draws, losses) values ('3', 'Chelsea', '10', '5', '3', '2')",
"insert into TeamStats (team_id, team_name, matches_played, wins, draws, losses) values ('4', 'Arsenal', '10', '4', '4', '2')",
"insert into TeamStats (team_id, team_name, matches_played, wins, draws, losses) values ('5', 'Tottenham', '10', '3', '5', '2')"
],
"enableRunCode": true,
"envInfo": "{\"mysql\":[\"MySQL\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>PostgreSQL 16<\\/p>\"]}",
"book": null,
"isSubscribed": false,
"isDailyQuestion": false,
"dailyRecordStatus": null,
"editorType": "CKEDITOR",
"ugcQuestionId": null,
"style": "LEETCODE",
"exampleTestcases": "{\"headers\":{\"TeamStats\":[\"team_id\",\"team_name\",\"matches_played\",\"wins\",\"draws\",\"losses\"]},\"rows\":{\"TeamStats\":[[1,\"Manchester City\",10,6,2,2],[2,\"Liverpool\",10,6,2,2],[3,\"Chelsea\",10,5,3,2],[4,\"Arsenal\",10,4,4,2],[5,\"Tottenham\",10,3,5,2]]}}",
"__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

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,93 @@
{
"data": {
"question": {
"questionId": "3530",
"questionFrontendId": "3220",
"categoryTitle": "Database",
"boundTopicId": 2847569,
"title": "Odd and Even Transactions",
"titleSlug": "odd-and-even-transactions",
"content": "<p>Table: <code>transactions</code></p>\n\n<pre>\n+------------------+------+\n| Column Name | Type | \n+------------------+------+\n| transaction_id | int |\n| amount | int |\n| transaction_date | date |\n+------------------+------+\nThe transactions_id column uniquely identifies each row in this table.\nEach row of this table contains the transaction id, amount and transaction date.\n</pre>\n\n<p>Write a solution to find the <strong>sum of amounts</strong> for <strong>odd</strong> and <strong>even</strong> transactions for each day. If there are no odd or even transactions for a specific date, display as <code>0</code>.</p>\n\n<p>Return <em>the result table ordered by</em> <code>transaction_date</code> <em>in <strong>ascending</strong> order</em>.</p>\n\n<p>The result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example:</strong></p>\n\n<div class=\"example-block\">\n<p><strong>Input:</strong></p>\n\n<p><code>transactions</code> table:</p>\n\n<pre class=\"example-io\">\n+----------------+--------+------------------+\n| transaction_id | amount | transaction_date |\n+----------------+--------+------------------+\n| 1 | 150 | 2024-07-01 |\n| 2 | 200 | 2024-07-01 |\n| 3 | 75 | 2024-07-01 |\n| 4 | 300 | 2024-07-02 |\n| 5 | 50 | 2024-07-02 |\n| 6 | 120 | 2024-07-03 |\n+----------------+--------+------------------+\n </pre>\n\n<p><strong>Output:</strong></p>\n\n<pre class=\"example-io\">\n+------------------+---------+----------+\n| transaction_date | odd_sum | even_sum |\n+------------------+---------+----------+\n| 2024-07-01 | 75 | 350 |\n| 2024-07-02 | 0 | 350 |\n| 2024-07-03 | 0 | 120 |\n+------------------+---------+----------+\n </pre>\n\n<p><strong>Explanation:</strong></p>\n\n<ul>\n\t<li>For transaction dates:\n\t<ul>\n\t\t<li>2024-07-01:\n\t\t<ul>\n\t\t\t<li>Sum of amounts for odd transactions: 75</li>\n\t\t\t<li>Sum of amounts for even transactions: 150 + 200 = 350</li>\n\t\t</ul>\n\t\t</li>\n\t\t<li>2024-07-02:\n\t\t<ul>\n\t\t\t<li>Sum of amounts for odd transactions: 0</li>\n\t\t\t<li>Sum of amounts for even transactions: 300 + 50 = 350</li>\n\t\t</ul>\n\t\t</li>\n\t\t<li>2024-07-03:\n\t\t<ul>\n\t\t\t<li>Sum of amounts for odd transactions: 0</li>\n\t\t\t<li>Sum of amounts for even transactions: 120</li>\n\t\t</ul>\n\t\t</li>\n\t</ul>\n\t</li>\n</ul>\n\n<p><strong>Note:</strong> The output table is ordered by <code>transaction_date</code> in ascending order.</p>\n</div>\n",
"translatedTitle": "奇数和偶数交易",
"translatedContent": "<p>表:<code>transactions</code></p>\n\n<pre>\n+------------------+------+\n| Column Name | Type | \n+------------------+------+\n| transaction_id | int |\n| amount | int |\n| transaction_date | date |\n+------------------+------+\ntransactions_id 列唯一标识了表中的每一行。\n这张表的每一行包含交易 id金额总和和交易日期。\n</pre>\n\n<p>编写一个解决方案来查找每天 <strong>奇数</strong> 交易金额和 <strong>偶数</strong> 交易金额的 <strong>总和</strong>。如果某天没有奇数或偶数交易,显示为&nbsp;<code>0</code>。</p>\n\n<p>返回结果表以&nbsp;<code>transaction_date</code> <strong>升序</strong>&nbsp;排序。</p>\n\n<p>结果格式如下所示。</p>\n\n<p>&nbsp;</p>\n\n<p><strong class=\"example\">示例:</strong></p>\n\n<div class=\"example-block\">\n<p><b>输入:</b></p>\n\n<p><code>transactions</code> 表:</p>\n\n<pre class=\"example-io\">\n+----------------+--------+------------------+\n| transaction_id | amount | transaction_date |\n+----------------+--------+------------------+\n| 1 | 150 | 2024-07-01 |\n| 2 | 200 | 2024-07-01 |\n| 3 | 75 | 2024-07-01 |\n| 4 | 300 | 2024-07-02 |\n| 5 | 50 | 2024-07-02 |\n| 6 | 120 | 2024-07-03 |\n+----------------+--------+------------------+\n </pre>\n\n<p><strong>输出:</strong></p>\n\n<pre class=\"example-io\">\n+------------------+---------+----------+\n| transaction_date | odd_sum | even_sum |\n+------------------+---------+----------+\n| 2024-07-01 | 75 | 350 |\n| 2024-07-02 | 0 | 350 |\n| 2024-07-03 | 0 | 120 |\n+------------------+---------+----------+\n </pre>\n\n<p><strong>解释:</strong></p>\n\n<ul>\n\t<li>对于交易日期:\n\t<ul>\n\t\t<li>2024-07-01:\n\t\t<ul>\n\t\t\t<li>奇数交易金额总和75</li>\n\t\t\t<li>偶数交易金额总和150 + 200 = 350</li>\n\t\t</ul>\n\t\t</li>\n\t\t<li>2024-07-02:\n\t\t<ul>\n\t\t\t<li>奇数交易金额总和0</li>\n\t\t\t<li>偶数交易金额总和300 + 50 = 350</li>\n\t\t</ul>\n\t\t</li>\n\t\t<li>2024-07-03:\n\t\t<ul>\n\t\t\t<li>奇数交易金额总和0</li>\n\t\t\t<li>偶数交易金额总和120</li>\n\t\t</ul>\n\t\t</li>\n\t</ul>\n\t</li>\n</ul>\n\n<p><b>注意:</b>输出表以&nbsp;<code>transaction_date</code>&nbsp;升序排序。</p>\n</div>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 0,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
"contributors": [],
"langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false, \"cangjie\": false}",
"topicTags": [
{
"name": "Database",
"slug": "database",
"translatedName": "数据库",
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": [
{
"lang": "MySQL",
"langSlug": "mysql",
"code": "# Write your MySQL query statement below",
"__typename": "CodeSnippetNode"
},
{
"lang": "MS SQL Server",
"langSlug": "mssql",
"code": "/* Write your T-SQL query statement below */",
"__typename": "CodeSnippetNode"
},
{
"lang": "Oracle",
"langSlug": "oraclesql",
"code": "/* Write your PL/SQL query statement below */",
"__typename": "CodeSnippetNode"
},
{
"lang": "Pandas",
"langSlug": "pythondata",
"code": "import pandas as pd\n\ndef sum_daily_odd_even(transactions: pd.DataFrame) -> pd.DataFrame:\n ",
"__typename": "CodeSnippetNode"
},
{
"lang": "PostgreSQL",
"langSlug": "postgresql",
"code": "-- Write your PostgreSQL query statement below",
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"408\", \"totalSubmission\": \"548\", \"totalAcceptedRaw\": 408, \"totalSubmissionRaw\": 548, \"acRate\": \"74.5%\"}",
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "{\"headers\":{\"transactions\":[\"transaction_id\",\"amount\",\"transaction_date\"]},\"rows\":{\"transactions\":[[1,150,\"2024-07-01\"],[2,200,\"2024-07-01\"],[3,75,\"2024-07-01\"],[4,300,\"2024-07-02\"],[5,50,\"2024-07-02\"],[6,120,\"2024-07-03\"]]}}",
"metaData": "{\"mysql\":[\"Create table if not exists transactions ( transaction_id int, amount int, transaction_date date)\"],\"mssql\":[\"Create table transactions ( transaction_id int, amount int, transaction_date date)\"],\"oraclesql\":[\"Create table transactions ( transaction_id int, amount int, transaction_date date)\",\"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"],\"database\":true,\"name\":\"sum_daily_odd_even\",\"postgresql\":[\"CREATE TABLE IF NOT EXISTS transactions (\\n transaction_id int,\\n amount int,\\n transaction_date date\\n);\\n\"],\"pythondata\":[\"transactions = pd.DataFrame(\\n columns=[\\\"transaction_id\\\", \\\"amount\\\", \\\"transaction_date\\\"],\\n dtype={\\n \\\"transaction_id\\\": \\\"int\\\",\\n \\\"amount\\\": \\\"int\\\",\\n \\\"transaction_date\\\": \\\"datetime64[ns]\\\",\\n },\\n)\\n\"],\"database_schema\":{\"transactions\":{\"transaction_id\":\"INT\",\"amount\":\"INT\",\"transaction_date\":\"DATE\"}}}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [
"Create table if not exists transactions ( transaction_id int, amount int, transaction_date date)",
"Truncate table transactions",
"insert into transactions (transaction_id, amount, transaction_date) values ('1', '150', '2024-07-01')",
"insert into transactions (transaction_id, amount, transaction_date) values ('2', '200', '2024-07-01')",
"insert into transactions (transaction_id, amount, transaction_date) values ('3', '75', '2024-07-01')",
"insert into transactions (transaction_id, amount, transaction_date) values ('4', '300', '2024-07-02')",
"insert into transactions (transaction_id, amount, transaction_date) values ('5', '50', '2024-07-02')",
"insert into transactions (transaction_id, amount, transaction_date) values ('6', '120', '2024-07-03')"
],
"enableRunCode": true,
"envInfo": "{\"mysql\":[\"MySQL\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>PostgreSQL 16<\\/p>\"]}",
"book": null,
"isSubscribed": false,
"isDailyQuestion": false,
"dailyRecordStatus": null,
"editorType": "CKEDITOR",
"ugcQuestionId": null,
"style": "LEETCODE",
"exampleTestcases": "{\"headers\":{\"transactions\":[\"transaction_id\",\"amount\",\"transaction_date\"]},\"rows\":{\"transactions\":[[1,150,\"2024-07-01\"],[2,200,\"2024-07-01\"],[3,75,\"2024-07-01\"],[4,300,\"2024-07-02\"],[5,50,\"2024-07-02\"],[6,120,\"2024-07-03\"]]}}",
"__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

View File

@ -0,0 +1,82 @@
<p>给你一个整数数组 <code>colors</code> 和一个二维整数数组 <code>queries</code><code>colors</code>表示一个由红色和蓝色瓷砖组成的环,第 <code>i</code>&nbsp;块瓷砖的颜色为&nbsp;<code>colors[i]</code>&nbsp;</p>
<ul>
<li><code>colors[i] == 0</code>&nbsp;表示第&nbsp;<code>i</code>&nbsp;块瓷砖的颜色是 <strong>红色</strong>&nbsp;</li>
<li><code>colors[i] == 1</code>&nbsp;表示第 <code>i</code>&nbsp;块瓷砖的颜色是 <strong>蓝色</strong>&nbsp;</li>
</ul>
<p>环中连续若干块瓷砖的颜色如果是 <strong>交替</strong>&nbsp;颜色(也就是说这组瓷砖中除了第一块和最后一块瓷砖以外,中间瓷砖的颜色与它<strong>&nbsp;左边</strong>&nbsp;<strong>右边</strong>&nbsp;的颜色都不同),那么它被称为一个 <strong>交替组</strong></p>
<p>你需要处理两种类型的查询:</p>
<ul>
<li><code>queries[i] = [1, size<sub>i</sub>]</code>,确定大小为<code>size<sub>i</sub></code><strong> </strong><strong>交替组</strong> 的数量。</li>
<li><code>queries[i] = [2, index<sub>i</sub>, color<sub>i</sub>]</code>,将<code>colors[index<sub>i</sub>]</code>更改为<code>color<sub>i</sub></code></li>
</ul>
<p>返回数组 <code>answer</code>,数组中按顺序包含第一种类型查询的结果。</p>
<p><b>注意</b>&nbsp;,由于&nbsp;<code>colors</code>&nbsp;表示一个 <strong></strong>&nbsp;<strong>第一块</strong>&nbsp;瓷砖和 <strong>最后一块</strong>&nbsp;瓷砖是相邻的。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">colors = [0,1,1,0,1], queries = [[2,1,0],[1,4]]</span></p>
<p><strong>输出:</strong><span class="example-io">[2]</span></p>
<p><strong>解释:</strong></p>
<p>第一次查询:</p>
<p><code>colors[1]</code> 改为 0。</p>
<p><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/06/03/screenshot-from-2024-06-03-20-20-25.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /></p>
<p>第二次查询:</p>
<p>统计大小为 4 的交替组的数量:</p>
<p><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/06/03/screenshot-from-2024-06-03-20-25-02-2.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/06/03/screenshot-from-2024-06-03-20-24-12.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /></p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">colors = [0,0,1,0,1,1], queries = [[1,3],[2,3,0],[1,5]]</span></p>
<p><strong>输出:</strong><span class="example-io">[2,0]</span></p>
<p><strong>解释:</strong></p>
<p><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/06/03/screenshot-from-2024-06-03-20-35-50.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /></p>
<p>第一次查询:</p>
<p>统计大小为 3 的交替组的数量。</p>
<p><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/06/03/screenshot-from-2024-06-03-20-37-13.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/06/03/screenshot-from-2024-06-03-20-36-40.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /></p>
<p>第二次查询:<code>colors</code>不变。</p>
<p>第三次查询:不存在大小为 5 的交替组。</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>4 &lt;= colors.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>0 &lt;= colors[i] &lt;= 1</code></li>
<li><code>1 &lt;= queries.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>queries[i][0] == 1</code><code>queries[i][0] == 2</code></li>
<li>对于所有的<code>i</code>
<ul>
<li><code>queries[i][0] == 1</code> <code>queries[i].length == 2</code>, <code>3 &lt;= queries[i][1] &lt;= colors.length - 1</code></li>
<li><code>queries[i][0] == 2</code> <code>queries[i].length == 3</code>, <code>0 &lt;= queries[i][1] &lt;= colors.length - 1</code>, <code>0 &lt;= queries[i][2] &lt;= 1</code></li>
</ul>
</li>
</ul>

View File

@ -0,0 +1,50 @@
<p>给你两个正整数 <code>n</code><code>k</code></p>
<p>你可以选择 <code>n</code><strong>二进制表示</strong> 中任意一个值为 1 的位,并将其改为 0。</p>
<p>返回使得 <code>n</code> 等于 <code>k</code> 所需要的更改次数。如果无法实现,返回 -1。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">n = 13, k = 4</span></p>
<p><strong>输出:</strong> <span class="example-io">2</span></p>
<p><strong>解释:</strong><br />
最初,<code>n</code><code>k</code> 的二进制表示分别为 <code>n = (1101)<sub>2</sub></code><code>k = (0100)<sub>2</sub></code></p>
<p>我们可以改变 <code>n</code> 的第一位和第四位。结果整数为 <code>n = (<u><strong>0</strong></u>10<u><strong>0</strong></u>)<sub>2</sub> = k</code></p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">n = 21, k = 21</span></p>
<p><strong>输出:</strong> <span class="example-io">0</span></p>
<p><strong>解释:</strong><br />
<code>n</code><code>k</code> 已经相等,因此不需要更改。</p>
</div>
<p><strong class="example">示例 3</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">n = 14, k = 13</span></p>
<p><strong>输出:</strong> <span class="example-io">-1</span></p>
<p><strong>解释:</strong><br />
无法使 <code>n</code> 等于 <code>k</code></p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= n, k &lt;= 10<sup>6</sup></code></li>
</ul>

View File

@ -0,0 +1,59 @@
<p>给你一个长度为 <code>n</code>&nbsp;的整数数组&nbsp;<code>nums</code>&nbsp;<code>n</code>&nbsp;<strong>偶数</strong>&nbsp;,同时给你一个整数&nbsp;<code>k</code>&nbsp;</p>
<p>你可以对数组进行一些操作。每次操作中,你可以将数组中 <strong>任一</strong>&nbsp;元素替换为 <code>0</code>&nbsp;<code>k</code>&nbsp;之间的<strong>&nbsp;任一</strong>&nbsp;整数。</p>
<p>执行完所有操作以后,你需要确保最后得到的数组满足以下条件:</p>
<ul>
<li>存在一个整数 <code>X</code>&nbsp;,满足对于所有的&nbsp;<code>(0 &lt;= i &lt; n)</code>&nbsp;都有&nbsp;<code>abs(a[i] - a[n - i - 1]) = X</code>&nbsp;</li>
</ul>
<p>请你返回满足以上条件 <strong>最少</strong>&nbsp;修改次数。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>nums = [1,0,1,2,4,3], k = 4</span></p>
<p><span class="example-io"><b>输出:</b>2</span></p>
<p><strong>解释:</strong><br />
我们可以执行以下操作:</p>
<ul>
<li>&nbsp;<code>nums[1]</code>&nbsp;变为 2 ,结果数组为&nbsp;<code>nums = [1,<em><strong>2</strong></em>,1,2,4,3]</code>&nbsp;</li>
<li>&nbsp;<code>nums[3]</code>&nbsp;变为 3 ,结果数组为&nbsp;<code>nums = [1,2,1,<em><strong>3</strong></em>,4,3]</code>&nbsp;</li>
</ul>
<p>整数&nbsp;<code>X</code>&nbsp;为 2 。</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>nums = [0,1,2,3,3,6,5,4], k = 6</span></p>
<p><span class="example-io"><b>输出:</b>2</span></p>
<p><strong>解释:</strong><br />
我们可以执行以下操作:</p>
<ul>
<li>&nbsp;<code>nums[3]</code>&nbsp;变为 0 ,结果数组为&nbsp;<code>nums = [0,1,2,<em><strong>0</strong></em>,3,6,5,4]</code>&nbsp;</li>
<li>&nbsp;<code>nums[4]</code>&nbsp;变为 4 ,结果数组为&nbsp;<code>nums = [0,1,2,0,<em><strong>4</strong></em>,6,5,4]</code>&nbsp;</li>
</ul>
<p>整数 <code>X</code>&nbsp;为 4 。</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>2 &lt;= n == nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>n</code>&nbsp;是偶数。</li>
<li><code>0 &lt;= nums[i] &lt;= k &lt;= 10<sup>5</sup></code></li>
</ul>

View File

@ -0,0 +1,47 @@
<p>给你两个长度相同的正整数数组 <code>nums</code><code>target</code></p>
<p>在一次操作中,你可以选择 <code>nums</code> 的任何<span data-keyword="subarray">子数组</span>,并将该子数组内的每个元素的值增加或减少 1。</p>
<p>返回使 <code>nums</code> 数组变为 <code>target</code> 数组所需的 <strong>最少 </strong>操作次数。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">nums = [3,5,1,2], target = [4,6,2,4]</span></p>
<p><strong>输出:</strong> <span class="example-io">2</span></p>
<p><strong>解释:</strong></p>
<p>执行以下操作可以使 <code>nums</code> 等于 <code>target</code><br />
- <code>nums[0..3]</code> 增加 1<code>nums = [4,6,2,3]</code><br />
- <code>nums[3..3]</code> 增加 1<code>nums = [4,6,2,4]</code></p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">nums = [1,3,2], target = [2,1,4]</span></p>
<p><strong>输出:</strong> <span class="example-io">5</span></p>
<p><strong>解释:</strong></p>
<p>执行以下操作可以使 <code>nums</code> 等于 <code>target</code><br />
- <code>nums[0..0]</code> 增加 1<code>nums = [2,3,2]</code><br />
- <code>nums[1..1]</code> 减少 1<code>nums = [2,2,2]</code><br />
- <code>nums[1..1]</code> 减少 1<code>nums = [2,1,2]</code><br />
- <code>nums[2..2]</code> 增加 1<code>nums = [2,1,3]</code><br />
- <code>nums[2..2]</code> 增加 1<code>nums = [2,1,4]</code></p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length == target.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i], target[i] &lt;= 10<sup>8</sup></code></li>
</ul>

View File

@ -0,0 +1,52 @@
<p>给你一个 <strong>正整数 </strong>数组 <code>nums</code></p>
<p>Alice 和 Bob 正在玩游戏。在游戏中Alice 可以从 <code>nums</code> 中选择所有个位数 <strong></strong> 所有两位数,剩余的数字归 Bob 所有。如果 Alice 所选数字之和 <strong>严格大于 </strong>Bob 的数字之和,则 Alice 获胜。</p>
<p>如果 Alice 能赢得这场游戏,返回 <code>true</code>;否则,返回 <code>false</code></p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">nums = [1,2,3,4,10]</span></p>
<p><strong>输出:</strong><span class="example-io">false</span></p>
<p><strong>解释:</strong></p>
<p>Alice&nbsp;不管选个位数还是两位数都无法赢得比赛。</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">nums = [1,2,3,4,5,14]</span></p>
<p><strong>输出:</strong><span class="example-io">true</span></p>
<p><strong>解释:</strong></p>
<p>Alice&nbsp;选择个位数可以赢得比赛,所选数字之和为 15。</p>
</div>
<p><strong class="example">示例 3</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">nums = [5,5,5,25]</span></p>
<p><strong>输出:</strong><span class="example-io">true</span></p>
<p><strong>解释:</strong></p>
<p>Alice&nbsp;选择两位数可以赢得比赛,所选数字之和为 25。</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
<li><code>1 &lt;= nums[i] &lt;= 99</code></li>
</ul>

View File

@ -0,0 +1,72 @@
<p>给你两个正整数&nbsp;<code>X</code>&nbsp;<code>Y</code>&nbsp;和一个二维整数数组&nbsp;<code>circles</code>&nbsp;,其中&nbsp;<code>circles[i] = [x<sub>i</sub>, y<sub>i</sub>, r<sub>i</sub>]</code>&nbsp;表示一个圆心在&nbsp;<code>(x<sub>i</sub>, y<sub>i</sub>)</code>&nbsp;半径为&nbsp;<code>r<sub>i</sub></code>&nbsp;的圆。</p>
<p>坐标平面内有一个左下角在原点,右上角在&nbsp;<code>(X, Y)</code>&nbsp;的矩形。你需要判断是否存在一条从左下角到右上角的路径满足:路径&nbsp;<strong>完全</strong>&nbsp;在矩形内部,<strong>不会</strong>&nbsp;触碰或者经过 <strong>任何</strong>&nbsp;圆的内部和边界,同时&nbsp;<strong></strong> 在起点和终点接触到矩形。</p>
<p>如果存在这样的路径,请你返回&nbsp;<code>true</code>&nbsp;,否则返回&nbsp;<code>false</code>&nbsp;</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>X = 3, Y = 4, circles = [[2,1,1]]</span></p>
<p><span class="example-io"><b>输出:</b>true</span></p>
<p><strong>解释:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/05/18/example2circle1.png" style="width: 346px; height: 264px;" /></p>
<p>黑色曲线表示一条从&nbsp;<code>(0, 0)</code>&nbsp;&nbsp;<code>(3, 4)</code>&nbsp;的路径。</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>X = 3, Y = 3, circles = [[1,1,2]]</span></p>
<p><span class="example-io"><b>输出:</b>false</span></p>
<p><strong>解释:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/05/18/example1circle.png" style="width: 346px; height: 264px;" /></p>
<p>不存在从&nbsp;<code>(0, 0)</code>&nbsp;<code>(3, 3)</code>&nbsp;的路径。</p>
</div>
<p><strong class="example">示例 3</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>X = 3, Y = 3, circles = [[2,1,1],[1,2,1]]</span></p>
<p><span class="example-io"><b>输出:</b>false</span></p>
<p><b>解释:</b></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/05/18/example0circle.png" style="width: 346px; height: 264px;" /></p>
<p>不存在从&nbsp;<code>(0, 0)</code>&nbsp;&nbsp;<code>(3, 3)</code>&nbsp;的路径。</p>
</div>
<p><strong class="example">示例 4</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">X = 4, Y = 4, circles = [[5,5,1]]</span></p>
<p><span class="example-io"><b>输出:</b>true</span></p>
<p><strong>解释:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/08/04/rectangles.png" style="width: 346px; height: 264px;" /></p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>3 &lt;= X, Y &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= circles.length &lt;= 1000</code></li>
<li><code>circles[i].length == 3</code></li>
<li><code>1 &lt;= x<sub>i</sub>, y<sub>i</sub>, r<sub>i</sub> &lt;= 10<sup>9</sup></code></li>
</ul>

View File

@ -0,0 +1,83 @@
<p>表:<code>transactions</code></p>
<pre>
+------------------+------+
| Column Name | Type |
+------------------+------+
| transaction_id | int |
| amount | int |
| transaction_date | date |
+------------------+------+
transactions_id 列唯一标识了表中的每一行。
这张表的每一行包含交易 id金额总和和交易日期。
</pre>
<p>编写一个解决方案来查找每天 <strong>奇数</strong> 交易金额和 <strong>偶数</strong> 交易金额的 <strong>总和</strong>。如果某天没有奇数或偶数交易,显示为&nbsp;<code>0</code></p>
<p>返回结果表以&nbsp;<code>transaction_date</code> <strong>升序</strong>&nbsp;排序。</p>
<p>结果格式如下所示。</p>
<p>&nbsp;</p>
<p><strong class="example">示例:</strong></p>
<div class="example-block">
<p><b>输入:</b></p>
<p><code>transactions</code> 表:</p>
<pre class="example-io">
+----------------+--------+------------------+
| transaction_id | amount | transaction_date |
+----------------+--------+------------------+
| 1 | 150 | 2024-07-01 |
| 2 | 200 | 2024-07-01 |
| 3 | 75 | 2024-07-01 |
| 4 | 300 | 2024-07-02 |
| 5 | 50 | 2024-07-02 |
| 6 | 120 | 2024-07-03 |
+----------------+--------+------------------+
</pre>
<p><strong>输出:</strong></p>
<pre class="example-io">
+------------------+---------+----------+
| transaction_date | odd_sum | even_sum |
+------------------+---------+----------+
| 2024-07-01 | 75 | 350 |
| 2024-07-02 | 0 | 350 |
| 2024-07-03 | 0 | 120 |
+------------------+---------+----------+
</pre>
<p><strong>解释:</strong></p>
<ul>
<li>对于交易日期:
<ul>
<li>2024-07-01:
<ul>
<li>奇数交易金额总和75</li>
<li>偶数交易金额总和150 + 200 = 350</li>
</ul>
</li>
<li>2024-07-02:
<ul>
<li>奇数交易金额总和0</li>
<li>偶数交易金额总和300 + 50 = 350</li>
</ul>
</li>
<li>2024-07-03:
<ul>
<li>奇数交易金额总和0</li>
<li>偶数交易金额总和120</li>
</ul>
</li>
</ul>
</li>
</ul>
<p><b>注意:</b>输出表以&nbsp;<code>transaction_date</code>&nbsp;升序排序。</p>
</div>

View File

@ -0,0 +1,54 @@
<p>小红和小明在玩一个字符串元音游戏。</p>
<p>给你一个字符串 <code>s</code>,小红和小明将轮流参与游戏,小红<strong></strong>开始:</p>
<ul>
<li>在小红的回合,她必须移除 <code>s</code> 中包含 <strong>奇数 </strong>个元音的任意 <strong>非空</strong> <span data-keyword="substring">子字符串</span></li>
<li>在小明的回合,他必须移除 <code>s</code> 中包含 <strong>偶数 </strong>个元音的任意 <strong>非空</strong> <span data-keyword="substring">子字符串</span></li>
</ul>
<p>第一个无法在其回合内进行移除操作的玩家输掉游戏。假设小红和小明都采取 <strong>最优策略 </strong></p>
<p>如果小红赢得游戏,返回 <code>true</code>,否则返回 <code>false</code></p>
<p>英文元音字母包括:<code>a</code>, <code>e</code>, <code>i</code>, <code>o</code>, 和 <code>u</code></p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">s = "leetcoder"</span></p>
<p><strong>输出:</strong> <span class="example-io">true</span></p>
<p><strong>解释:</strong><br />
小红可以执行如下移除操作来赢得游戏:</p>
<ul>
<li>小红先手,她可以移除加下划线的子字符串 <code>s = "<u><strong>leetco</strong></u>der"</code>,其中包含 3 个元音。结果字符串为 <code>s = "der"</code></li>
<li>小明接着,他可以移除加下划线的子字符串 <code>s = "<u><strong>d</strong></u>er"</code>,其中包含 0 个元音。结果字符串为 <code>s = "er"</code></li>
<li>小红再次操作,她可以移除整个字符串 <code>s = "<strong><u>er</u></strong>"</code>,其中包含 1 个元音。</li>
<li>又轮到小明,由于字符串为空,无法执行移除操作,因此小红赢得游戏。</li>
</ul>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">s = "bbcd"</span></p>
<p><strong>输出:</strong> <span class="example-io">false</span></p>
<p><strong>解释:</strong><br />
小红在她的第一回合无法执行移除操作,因此小红输掉了游戏。</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
<li><code>s</code> 仅由小写英文字母组成。</li>
</ul>

View File

@ -0,0 +1,48 @@
<p>给你一个 <span data-keyword="binary-string">二进制字符串</span> <code>s</code></p>
<p>你可以对这个字符串执行 <strong>任意次</strong> 下述操作:</p>
<ul>
<li>选择字符串中的任一下标 <code>i</code> <code>i + 1 &lt; s.length</code> ),该下标满足 <code>s[i] == '1'</code><code>s[i + 1] == '0'</code></li>
<li>将字符 <code>s[i]</code><strong>右移 </strong>直到它到达字符串的末端或另一个 <code>'1'</code>。例如,对于 <code>s = "010010"</code>,如果我们选择 <code>i = 1</code>,结果字符串将会是 <code>s = "0<strong><u>001</u></strong>10"</code></li>
</ul>
<p>返回你能执行的<strong> 最大 </strong>操作次数。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">s = "1001101"</span></p>
<p><strong>输出:</strong> <span class="example-io">4</span></p>
<p><strong>解释:</strong></p>
<p>可以执行以下操作:</p>
<ul>
<li>选择下标 <code>i = 0</code>。结果字符串为 <code>s = "<u><strong>001</strong></u>1101"</code></li>
<li>选择下标 <code>i = 4</code>。结果字符串为 <code>s = "0011<u><strong>01</strong></u>1"</code></li>
<li>选择下标 <code>i = 3</code>。结果字符串为 <code>s = "001<strong><u>01</u></strong>11"</code></li>
<li>选择下标 <code>i = 2</code>。结果字符串为 <code>s = "00<strong><u>01</u></strong>111"</code></li>
</ul>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">s = "00111"</span></p>
<p><strong>输出:</strong> <span class="example-io">0</span></p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
<li><code>s[i]</code><code>'0'</code><code>'1'</code></li>
</ul>

View File

@ -0,0 +1,49 @@
<p>给你一个字符串&nbsp;<code>s</code>&nbsp;</p>
<p>你需要对 <code>s</code>&nbsp;执行以下操作 <strong>任意</strong>&nbsp;次:</p>
<ul>
<li>选择一个下标 <code>i</code>&nbsp;,满足 <code>s[i]</code>&nbsp;左边和右边都&nbsp;<strong>至少</strong>&nbsp;有一个字符与它相同。</li>
<li>删除 <code>s[i]</code>&nbsp;<strong>左边</strong>&nbsp;离它 <strong>最近</strong>&nbsp;且相同的字符。</li>
<li>删除 <code>s[i]</code>&nbsp;<strong>右边</strong>&nbsp;离它 <strong>最近</strong>&nbsp;且相同的字符。</li>
</ul>
<p>请你返回执行完所有操作后, <code>s</code>&nbsp;<strong>最短</strong>&nbsp;长度。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>s = "abaacbcbb"</span></p>
<p><span class="example-io"><b>输出:</b>5</span></p>
<p><strong>解释:</strong><br />
我们执行以下操作:</p>
<ul>
<li>选择下标 2 ,然后删除下标 0 和 3 处的字符,得到&nbsp;<code>s = "bacbcbb"</code>&nbsp;</li>
<li>选择下标 3 ,然后删除下标 0 和 5 处的字符,得到&nbsp;<code>s = "acbcb"</code>&nbsp;</li>
</ul>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>s = "aa"</span></p>
<p><span class="example-io"><b>输出:</b>2</span></p>
<p><strong>解释:</strong><br />
无法对字符串进行任何操作,所以返回初始字符串的长度。</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 2 * 10<sup>5</sup></code></li>
<li><code>s</code>&nbsp;只包含小写英文字母。</li>
</ul>

View File

@ -0,0 +1,62 @@
<p>给你一个整数 <code>n</code> 和一个二维整数数组 <code>queries</code></p>
<p><code>n</code> 个城市,编号从 <code>0</code><code>n - 1</code>。初始时,每个城市 <code>i</code> 都有一条<strong>单向</strong>道路通往城市 <code>i + 1</code> <code>0 &lt;= i &lt; n - 1</code>)。</p>
<p><code>queries[i] = [u<sub>i</sub>, v<sub>i</sub>]</code> 表示新建一条从城市 <code>u<sub>i</sub></code> 到城市 <code>v<sub>i</sub></code><strong>单向</strong>道路。每次查询后,你需要找到从城市 <code>0</code> 到城市 <code>n - 1</code><strong>最短路径</strong><strong>长度</strong></p>
<p>返回一个数组 <code>answer</code>,对于范围 <code>[0, queries.length - 1]</code> 中的每个 <code>i</code><code>answer[i]</code> 是处理完<strong></strong> <code>i + 1</code> 个查询后,从城市 <code>0</code> 到城市 <code>n - 1</code> 的最短路径的<em>长度</em></p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">n = 5, queries = [[2, 4], [0, 2], [0, 4]]</span></p>
<p><strong>输出:</strong> <span class="example-io">[3, 2, 1]</span></p>
<p><strong>解释:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/28/image8.jpg" style="width: 350px; height: 60px;" /></p>
<p>新增一条从 2 到 4 的道路后,从 0 到 4 的最短路径长度为 3。</p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/28/image9.jpg" style="width: 350px; height: 60px;" /></p>
<p>新增一条从 0 到 2 的道路后,从 0 到 4 的最短路径长度为 2。</p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/28/image10.jpg" style="width: 350px; height: 96px;" /></p>
<p>新增一条从 0 到 4 的道路后,从 0 到 4 的最短路径长度为 1。</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">n = 4, queries = [[0, 3], [0, 2]]</span></p>
<p><strong>输出:</strong> <span class="example-io">[1, 1]</span></p>
<p><strong>解释:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/28/image11.jpg" style="width: 300px; height: 70px;" /></p>
<p>新增一条从 0 到 3 的道路后,从 0 到 3 的最短路径长度为 1。</p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/28/image12.jpg" style="width: 300px; height: 70px;" /></p>
<p>新增一条从 0 到 2 的道路后,从 0 到 3 的最短路径长度仍为 1。</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>3 &lt;= n &lt;= 500</code></li>
<li><code>1 &lt;= queries.length &lt;= 500</code></li>
<li><code>queries[i].length == 2</code></li>
<li><code>0 &lt;= queries[i][0] &lt; queries[i][1] &lt; n</code></li>
<li><code>1 &lt; queries[i][1] - queries[i][0]</code></li>
<li>查询中没有重复的道路。</li>
</ul>

View File

@ -0,0 +1,65 @@
<p>给你一个整数 <code>n</code> 和一个二维整数数组 <code>queries</code></p>
<p><code>n</code> 个城市,编号从 <code>0</code><code>n - 1</code>。初始时,每个城市 <code>i</code> 都有一条<strong>单向</strong>道路通往城市 <code>i + 1</code> <code>0 &lt;= i &lt; n - 1</code>)。</p>
<p><code>queries[i] = [u<sub>i</sub>, v<sub>i</sub>]</code> 表示新建一条从城市 <code>u<sub>i</sub></code> 到城市 <code>v<sub>i</sub></code><strong>单向</strong>道路。每次查询后,你需要找到从城市 <code>0</code> 到城市 <code>n - 1</code><strong>最短路径</strong><strong>长度</strong></p>
<p>所有查询中不会存在两个查询都满足 <code>queries[i][0] &lt; queries[j][0] &lt; queries[i][1] &lt; queries[j][1]</code></p>
<p>返回一个数组 <code>answer</code>,对于范围 <code>[0, queries.length - 1]</code> 中的每个 <code>i</code><code>answer[i]</code> 是处理完<strong></strong> <code>i + 1</code> 个查询后,从城市 <code>0</code> 到城市 <code>n - 1</code> 的最短路径的<em>长度</em></p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">n = 5, queries = [[2, 4], [0, 2], [0, 4]]</span></p>
<p><strong>输出:</strong> <span class="example-io">[3, 2, 1]</span></p>
<p><strong>解释:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/28/image8.jpg" style="width: 350px; height: 60px;" /></p>
<p>新增一条从 2 到 4 的道路后,从 0 到 4 的最短路径长度为 3。</p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/28/image9.jpg" style="width: 350px; height: 60px;" /></p>
<p>新增一条从 0 到 2 的道路后,从 0 到 4 的最短路径长度为 2。</p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/28/image10.jpg" style="width: 350px; height: 96px;" /></p>
<p>新增一条从 0 到 4 的道路后,从 0 到 4 的最短路径长度为 1。</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">n = 4, queries = [[0, 3], [0, 2]]</span></p>
<p><strong>输出:</strong> <span class="example-io">[1, 1]</span></p>
<p><strong>解释:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/28/image11.jpg" style="width: 300px; height: 70px;" /></p>
<p>新增一条从 0 到 3 的道路后,从 0 到 3 的最短路径长度为 1。</p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/28/image12.jpg" style="width: 300px; height: 70px;" /></p>
<p>新增一条从 0 到 2 的道路后,从 0 到 3 的最短路径长度仍为 1。</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>3 &lt;= n &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= queries.length &lt;= 10<sup>5</sup></code></li>
<li><code>queries[i].length == 2</code></li>
<li><code>0 &lt;= queries[i][0] &lt; queries[i][1] &lt; n</code></li>
<li><code>1 &lt; queries[i][1] - queries[i][0]</code></li>
<li>查询中不存在重复的道路。</li>
<li>不存在两个查询都满足 <code>i != j</code><code>queries[i][0] &lt; queries[j][0] &lt; queries[i][1] &lt; queries[j][1]</code></li>
</ul>

View File

@ -0,0 +1,60 @@
<p>给你一个&nbsp;<code>m x n</code>&nbsp;的二进制矩阵&nbsp;<code>grid</code>&nbsp;</p>
<p>如果矩阵中一行或者一列从前往后与从后往前读是一样的,那么我们称这一行或者这一列是 <strong>回文</strong> 的。</p>
<p>你可以将 <code>grid</code>&nbsp;中任意格子的值 <strong>翻转</strong>&nbsp;,也就是将格子里的值从 <code>0</code>&nbsp;变成 <code>1</code>&nbsp;,或者从 <code>1</code>&nbsp;变成 <code>0</code>&nbsp;</p>
<p>请你返回 <strong>最少</strong>&nbsp;翻转次数,使得矩阵 <strong>要么</strong>&nbsp;所有行是 <strong>回文的</strong>&nbsp;,要么所有列是 <strong>回文的</strong>&nbsp;</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>grid = [[1,0,0],[0,0,0],[0,0,1]]</span></p>
<p><span class="example-io"><b>输出:</b>2</span></p>
<p><b>解释:</b></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/07/07/screenshot-from-2024-07-08-00-20-10.png" style="width: 420px; height: 108px;" /></p>
<p>将高亮的格子翻转,得到所有行都是回文的。</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>grid = </span>[[0,1],[0,1],[0,0]]</p>
<p><span class="example-io"><b>输出:</b>1</span></p>
<p><strong>解释:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/07/07/screenshot-from-2024-07-08-00-31-23.png" style="width: 300px; height: 100px;" /></p>
<p>将高亮的格子翻转,得到所有列都是回文的。</p>
</div>
<p><strong class="example">示例 3</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>grid = [[1],[0]]</span></p>
<p><span class="example-io"><b>输出:</b>0</span></p>
<p><strong>解释:</strong></p>
<p>所有行已经是回文的。</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>m == grid.length</code></li>
<li><code>n == grid[i].length</code></li>
<li><code>1 &lt;= m * n &lt;= 2 * 10<sup>5</sup></code></li>
<li><code>0 &lt;= grid[i][j] &lt;= 1</code></li>
</ul>

View File

@ -0,0 +1,56 @@
<p>给你一个&nbsp;<code>m x n</code>&nbsp;的二进制矩阵&nbsp;<code>grid</code>&nbsp;</p>
<p>如果矩阵中一行或者一列从前往后与从后往前读是一样的,那么我们称这一行或者这一列是 <strong>回文</strong>&nbsp;的。</p>
<p>你可以将 <code>grid</code>&nbsp;中任意格子的值 <strong>翻转</strong>&nbsp;,也就是将格子里的值从 <code>0</code>&nbsp;变成 <code>1</code>&nbsp;,或者从 <code>1</code>&nbsp;变成 <code>0</code>&nbsp;</p>
<p>请你返回 <strong>最少</strong>&nbsp;翻转次数,使得矩阵中 <strong>所有</strong>&nbsp;行和列都是 <strong>回文的</strong>&nbsp;,且矩阵中 <code>1</code>&nbsp;的数目可以被 <code>4</code>&nbsp;<strong>整除</strong>&nbsp;</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>grid = [[1,0,0],[0,1,0],[0,0,1]]</span></p>
<p><span class="example-io"><b>输出:</b>3</span></p>
<p><strong>解释:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2024/08/01/image.png" style="width: 400px; height: 105px;" /></p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>grid = [[0,1],[0,1],[0,0]]</span></p>
<p><span class="example-io"><b>输出:</b>2</span></p>
<p><strong>解释:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/07/08/screenshot-from-2024-07-09-01-37-48.png" style="width: 300px; height: 104px;" /></p>
</div>
<p><strong class="example">示例 3</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>grid = [[1],[1]]</span></p>
<p><span class="example-io"><b>输出:</b>2</span></p>
<p><strong>解释:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/08/01/screenshot-from-2024-08-01-23-05-26.png" style="width: 200px; height: 70px;" /></p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>m == grid.length</code></li>
<li><code>n == grid[i].length</code></li>
<li><code>1 &lt;= m * n &lt;= 2 * 10<sup>5</sup></code></li>
<li><code>0 &lt;= grid[i][j] &lt;= 1</code></li>
</ul>

View File

@ -0,0 +1,95 @@
<p>给你一棵 <strong>无向</strong>&nbsp;树,树中节点从 <code>0</code>&nbsp;<code>n - 1</code>&nbsp;编号。同时给你一个长度为 <code>n - 1</code>&nbsp;的二维整数数组&nbsp;<code>edges</code>&nbsp;,其中&nbsp;<code>edges[i] = [u<sub>i</sub>, v<sub>i</sub>]</code>&nbsp;表示节点&nbsp;<code>u<sub>i</sub></code>&nbsp;<code>v<sub>i</sub></code>&nbsp;在树中有一条边。</p>
<p>一开始,<strong>所有</strong>&nbsp;节点都 <strong>未标记</strong>&nbsp;。对于节点 <code>i</code>&nbsp;</p>
<ul>
<li>&nbsp;<code>i</code>&nbsp;是奇数时,如果时刻 <code>x - 1</code>&nbsp;该节点有 <strong>至少</strong>&nbsp;一个相邻节点已经被标记了,那么节点 <code>i</code>&nbsp;会在时刻 <code>x</code>&nbsp;被标记。</li>
<li>&nbsp;<code>i</code>&nbsp;是偶数时,如果时刻 <code>x - 2</code>&nbsp;该节点有 <strong>至少</strong>&nbsp;一个相邻节点已经被标记了,那么节点 <code>i</code>&nbsp;会在时刻 <code>x</code>&nbsp;被标记。</li>
</ul>
<p>请你返回一个数组&nbsp;<code>times</code>&nbsp;,表示如果你在时刻 <code>t = 0</code>&nbsp;标记节点 <code>i</code>&nbsp;,那么时刻 <code>times[i]</code>&nbsp;时,树中所有节点都会被标记。</p>
<p>请注意,每个 <code>times[i]</code> 的答案都是独立的,即当你标记节点 <code>i</code> 时,所有其他节点都未标记。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>edges = [[0,1],[0,2]]</span></p>
<p><b>输出:</b>[2,4,3]</p>
<p><strong>解释:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/01/screenshot-2024-06-02-122236.png" style="width: 500px; height: 241px;" /></p>
<ul>
<li>对于&nbsp;<code>i = 0</code>&nbsp;
<ul>
<li>节点 1 在时刻&nbsp;<code>t = 1</code>&nbsp;被标记,节点 2 在时刻&nbsp;<code>t = 2</code>&nbsp;被标记。</li>
</ul>
</li>
<li>对于&nbsp;<code>i = 1</code>&nbsp;
<ul>
<li>节点 0 在时刻&nbsp;<code>t = 2</code>&nbsp;被标记,节点 2 在时刻&nbsp;<code>t = 4</code>&nbsp;被标记。</li>
</ul>
</li>
<li>对于&nbsp;<code>i = 2</code>&nbsp;
<ul>
<li>节点 0 在时刻&nbsp;<code>t = 2</code>&nbsp;被标记,节点 1 在时刻&nbsp;<code>t = 3</code>&nbsp;被标记。</li>
</ul>
</li>
</ul>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>edges = [[0,1]]</span></p>
<p><b>输出:</b>[1,2]</p>
<p><strong>解释:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/01/screenshot-2024-06-02-122249.png" style="width: 500px; height: 257px;" /></p>
<ul>
<li>对于&nbsp;<code>i = 0</code>&nbsp;
<ul>
<li>节点 1 在时刻&nbsp;<code>t = 1</code>&nbsp;被标记。</li>
</ul>
</li>
<li>对于&nbsp;<code>i = 1</code>&nbsp;
<ul>
<li>节点 0 在时刻&nbsp;<code>t = 2</code>&nbsp;被标记。</li>
</ul>
</li>
</ul>
</div>
<p><strong class="example">示例 3</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>edges = </span>[[2,4],[0,1],[2,3],[0,2]]</p>
<p><b>输出:</b>[4,6,3,5,5]</p>
<p><b>解释:</b></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/03/screenshot-2024-06-03-210550.png" style="height: 266px; width: 500px;" /></p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>2 &lt;= n &lt;= 10<sup>5</sup></code></li>
<li><code>edges.length == n - 1</code></li>
<li><code>edges[i].length == 2</code></li>
<li><code>0 &lt;= edges[i][0], edges[i][1] &lt;= n - 1</code></li>
<li>输入保证&nbsp;<code>edges</code>&nbsp;表示一棵合法的树。</li>
</ul>

View File

@ -0,0 +1,48 @@
<p>给你两个 <strong></strong>&nbsp;整数&nbsp;<code>x</code>&nbsp;&nbsp;<code>y</code>&nbsp;,分别表示价值为 75 和 10 的硬币的数目。</p>
<p>Alice 和 Bob 正在玩一个游戏。每一轮中Alice&nbsp;先进行操作Bob 后操作。每次操作中,玩家需要拿出价值 <b>总和</b>&nbsp;为 115 的硬币。如果一名玩家无法执行此操作,那么这名玩家 <strong>输掉</strong>&nbsp;游戏。</p>
<p>两名玩家都采取 <strong>最优</strong>&nbsp;策略,请你返回游戏的赢家。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>x = 2, y = 7</span></p>
<p><span class="example-io"><b>输出:</b>"Alice"</span></p>
<p><strong>解释:</strong></p>
<p>游戏一次操作后结束:</p>
<ul>
<li>Alice 拿走 1 枚价值为 75 的硬币和 4 枚价值为 10 的硬币。</li>
</ul>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>x = 4, y = 11</span></p>
<p><span class="example-io"><b>输出:</b>"Bob"</span></p>
<p><strong>解释:</strong></p>
<p>游戏 2 次操作后结束:</p>
<ul>
<li>Alice 拿走&nbsp;1 枚价值为 75 的硬币和 4 枚价值为 10 的硬币。</li>
<li>Bob 拿走&nbsp;1 枚价值为 75 的硬币和 4 枚价值为 10 的硬币。</li>
</ul>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= x, y &lt;= 100</code></li>
</ul>

View File

@ -0,0 +1,64 @@
<p>给你一个整数&nbsp;<code>n</code>&nbsp;,表示在一个游戏中的玩家数目。同时给你一个二维整数数组&nbsp;<code>pick</code>&nbsp;,其中&nbsp;<code>pick[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>&nbsp;表示玩家&nbsp;<code>x<sub>i</sub></code>&nbsp;获得了一个颜色为&nbsp;<code>y<sub>i</sub></code>&nbsp;的球。</p>
<p>如果玩家 <code>i</code>&nbsp;获得的球中任何一种颜色球的数目 <strong>严格大于</strong>&nbsp;<code>i</code>&nbsp;个,那么我们说玩家 <code>i</code>&nbsp;是胜利玩家。换句话说:</p>
<ul>
<li>如果玩家 0 获得了任何的球,那么玩家 0 是胜利玩家。</li>
<li>如果玩家 1 获得了至少 2 个相同颜色的球,那么玩家 1 是胜利玩家。</li>
<li>...</li>
<li>如果玩家 <code>i</code>&nbsp;获得了至少&nbsp;<code>i + 1</code>&nbsp;个相同颜色的球,那么玩家 <code>i</code>&nbsp;是胜利玩家。</li>
</ul>
<p>请你返回游戏中 <strong>胜利玩家</strong>&nbsp;的数目。</p>
<p><strong>注意</strong>,可能有多个玩家是胜利玩家。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>n = 4, pick = [[0,0],[1,0],[1,0],[2,1],[2,1],[2,0]]</span></p>
<p><span class="example-io"><b>输出:</b>2</span></p>
<p><strong>解释:</strong></p>
<p>玩家 0 和玩家 1 是胜利玩家,玩家 2 和玩家 3 不是胜利玩家。</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>n = 5, pick = [[1,1],[1,2],[1,3],[1,4]]</span></p>
<p><span class="example-io"><b>输出:</b>0</span></p>
<p><strong>解释:</strong></p>
<p>没有胜利玩家。</p>
</div>
<p><strong class="example">示例 3</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>n = 5, pick = [[1,1],[2,4],[2,4],[2,4]]</span></p>
<p><span class="example-io"><b>输出:</b>1</span></p>
<p><b>解释:</b></p>
<p>玩家 2 是胜利玩家,因为玩家 2 获得了 3 个颜色为 4 的球。</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>2 &lt;= n &lt;= 10</code></li>
<li><code>1 &lt;= pick.length &lt;= 100</code></li>
<li><code>pick[i].length == 2</code></li>
<li><code>0 &lt;= x<sub>i</sub> &lt;= n - 1 </code></li>
<li><code>0 &lt;= y<sub>i</sub> &lt;= 10</code></li>
</ul>

View File

@ -0,0 +1,140 @@
<p>给你一个二进制字符串 <code>s</code></p>
<p>请你统计并返回其中 <strong>1 显著 </strong><span data-keyword="substring-nonempty">子字符串</span> 的数量。</p>
<p>如果字符串中 1 的数量 <strong>大于或等于</strong> 0 的数量的 <strong>平方</strong>,则认为该字符串是一个 <strong>1 显著</strong> 的字符串 。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">s = "00011"</span></p>
<p><strong>输出:</strong><span class="example-io">5</span></p>
<p><strong>解释:</strong></p>
<p>1 显著的子字符串如下表所示。</p>
</div>
<table>
<thead>
<tr>
<th>i</th>
<th>j</th>
<th>s[i..j]</th>
<th>0 的数量</th>
<th>1 的数量</th>
</tr>
</thead>
<tbody>
<tr>
<td>3</td>
<td>3</td>
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<td>4</td>
<td>4</td>
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
<td>3</td>
<td>01</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
<td>11</td>
<td>0</td>
<td>2</td>
</tr>
<tr>
<td>2</td>
<td>4</td>
<td>011</td>
<td>1</td>
<td>2</td>
</tr>
</tbody>
</table>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">s = "101101"</span></p>
<p><strong>输出:</strong><span class="example-io">16</span></p>
<p><strong>解释:</strong></p>
<p>1 不显著的子字符串如下表所示。</p>
<p>总共有 21 个子字符串,其中 5 个是 1 不显著字符串,因此有 16 个 1 显著子字符串。</p>
</div>
<table>
<thead>
<tr>
<th>i</th>
<th>j</th>
<th>s[i..j]</th>
<th>0 的数量</th>
<th>1 的数量</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<td>4</td>
<td>4</td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<td>1</td>
<td>4</td>
<td>0110</td>
<td>2</td>
<td>2</td>
</tr>
<tr>
<td>0</td>
<td>4</td>
<td>10110</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>1</td>
<td>5</td>
<td>01101</td>
<td>2</td>
<td>3</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 4 * 10<sup>4</sup></code></li>
<li><code>s</code> 仅包含字符 <code>'0'</code><code>'1'</code></li>
</ul>

View File

@ -0,0 +1,44 @@
<p>给你两个<strong> 正整数 </strong><code>l</code><code>r</code>。对于任何数字 <code>x</code><code>x</code> 的所有正因数(除了 <code>x</code> 本身)被称为 <code>x</code><strong>真因数</strong></p>
<p><span class="text-only" data-eleid="13" style="white-space: pre;">如果一个数字恰好仅有两个</span> <strong>真因数</strong>,则称该数字为 <strong>特殊数字</strong>。例如:</p>
<ul>
<li>数字 4 是<strong> 特殊数字</strong>,因为它的真因数为 1 和 2。</li>
<li>数字 6 不是 <strong>特殊数字</strong>,因为它的真因数为 1、2 和 3。</li>
</ul>
<p>返回区间 <code>[l, r]</code><strong> 不是 特殊数字 </strong>的数字数量。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">l = 5, r = 7</span></p>
<p><strong>输出:</strong> <span class="example-io">3</span></p>
<p><strong>解释:</strong></p>
<p>区间 <code>[5, 7]</code> 内不存在特殊数字。</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">l = 4, r = 16</span></p>
<p><strong>输出:</strong> <span class="reset-io">11</span></p>
<p><strong>解释:</strong></p>
<p>区间 <code>[4, 16]</code> 内的特殊数字为 4 和 9。</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= l &lt;= r &lt;= 10<sup>9</sup></code></li>
</ul>

View File

@ -0,0 +1,41 @@
<p>给你一个大小为 <code>n x n</code>&nbsp;的二维矩阵&nbsp;<code>grid</code>&nbsp;,一开始所有格子都是白色的。一次操作中,你可以选择任意下标为&nbsp;<code>(i, j)</code>&nbsp;的格子,并将第&nbsp;<code>j</code>&nbsp;列中从最上面到第&nbsp;<code>i</code>&nbsp;行所有格子改成黑色。</p>
<p>如果格子 <code>(i, j)</code>&nbsp;为白色,且左边或者右边的格子至少一个格子为黑色,那么我们将 <code>grid[i][j]</code>&nbsp;加到最后网格图的总分中去。</p>
<p>请你返回执行任意次操作以后,最终网格图的 <strong>最大</strong>&nbsp;总分数。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>grid = [[0,0,0,0,0],[0,0,3,0,0],[0,1,0,0,0],[5,0,0,3,0],[0,0,0,0,2]]</span></p>
<p><span class="example-io"><b>输出:</b>11</span></p>
<p><strong>解释:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2024/05/11/one.png" style="width: 300px; height: 200px;" />
<p>第一次操作中,我们将第 1 列中,最上面的格子到第 3 行的格子染成黑色。第二次操作中,我们将第 4 列中,最上面的格子到最后一行的格子染成黑色。最后网格图总分为&nbsp;<code>grid[3][0] + grid[1][2] + grid[3][3]</code>&nbsp;等于 11 。</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>grid = [[10,9,0,0,15],[7,1,0,8,0],[5,20,0,11,0],[0,0,0,1,2],[8,12,1,10,3]]</span></p>
<p><span class="example-io"><b>输出:</b>94</span></p>
<p><strong>解释:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2024/05/11/two-1.png" style="width: 300px; height: 200px;" />
<p>我们对第 1 2 3 列分别从上往下染黑色到第 1 4 0 行。最后网格图总分为&nbsp;<code>grid[0][0] + grid[1][0] + grid[2][1] + grid[4][1] + grid[1][3] + grid[2][3] + grid[3][3] + grid[4][3] + grid[0][4]</code>&nbsp;等于 94 。</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;=&nbsp;n == grid.length &lt;= 100</code></li>
<li><code>n == grid[i].length</code></li>
<li><code>0 &lt;= grid[i][j] &lt;= 10<sup>9</sup></code></li>
</ul>

View File

@ -0,0 +1,69 @@
<p>给你一个 <code>n x n</code> 的二维数组 <code>grid</code>,它包含范围 <code>[0, n<sup>2</sup> - 1]</code> 内的<strong>不重复</strong>元素。</p>
<p>实现 <code>neighborSum</code> 类:</p>
<ul>
<li><code>neighborSum(int [][]grid)</code> 初始化对象。</li>
<li><code>int adjacentSum(int value)</code> 返回在 <code>grid</code> 中与 <code>value</code> 相邻的元素之<strong></strong>,相邻指的是与 <code>value</code> 在上、左、右或下的元素。</li>
<li><code>int diagonalSum(int value)</code> 返回在 <code>grid</code> 中与 <code>value</code> 对角线相邻的元素之<strong></strong>,对角线相邻指的是与 <code>value</code> 在左上、右上、左下或右下的元素。</li>
</ul>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/24/design.png" style="width: 400px; height: 248px;" /></p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong></p>
<p>["neighborSum", "adjacentSum", "adjacentSum", "diagonalSum", "diagonalSum"]</p>
<p>[[[[0, 1, 2], [3, 4, 5], [6, 7, 8]]], [1], [4], [4], [8]]</p>
<p><strong>输出:</strong> [null, 6, 16, 16, 4]</p>
<p><strong>解释:</strong></p>
<p><strong class="example"><img alt="" src="https://assets.leetcode.com/uploads/2024/06/24/designexample0.png" style="width: 250px; height: 249px;" /></strong></p>
<ul>
<li>1 的相邻元素是 0、2 和 4。</li>
<li>4 的相邻元素是 1、3、5 和 7。</li>
<li>4 的对角线相邻元素是 0、2、6 和 8。</li>
<li>8 的对角线相邻元素是 4。</li>
</ul>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong></p>
<p>["neighborSum", "adjacentSum", "diagonalSum"]</p>
<p>[[[[1, 2, 0, 3], [4, 7, 15, 6], [8, 9, 10, 11], [12, 13, 14, 5]]], [15], [9]]</p>
<p><strong>输出:</strong> [null, 23, 45]</p>
<p><strong>解释:</strong></p>
<p><strong class="example"><img alt="" src="https://assets.leetcode.com/uploads/2024/06/24/designexample2.png" style="width: 300px; height: 300px;" /></strong></p>
<ul>
<li>15 的相邻元素是 0、10、7 和 6。</li>
<li>9 的对角线相邻元素是 4、12、14 和 15。</li>
</ul>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>3 &lt;= n == grid.length == grid[0].length &lt;= 10</code></li>
<li><code>0 &lt;= grid[i][j] &lt;= n<sup>2</sup> - 1</code></li>
<li>所有 <code>grid[i][j]</code> 值均不重复。</li>
<li><code>adjacentSum</code><code>diagonalSum</code> 中的 <code>value</code> 均在范围 <code>[0, n<sup>2</sup> - 1]</code> 内。</li>
<li>最多会调用 <code>adjacentSum</code><code>diagonalSum</code> 总共 <code>2 * n<sup>2</sup></code> 次。</li>
</ul>

View File

@ -0,0 +1,84 @@
<p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>colors[i] == 1</code> means that tile <code>i</code> is <strong>blue</strong>.</li>
</ul>
<p>An <strong>alternating</strong> group is a contiguous subset of tiles in the circle with <strong>alternating</strong> colors (each tile in the group except the first and last one has a different color from its <b>adjacent</b> tiles in the group).</p>
<p>You have to process queries of two types:</p>
<ul>
<li><code>queries[i] = [1, size<sub>i</sub>]</code>, determine the count of <strong>alternating</strong> groups with size <code>size<sub>i</sub></code>.</li>
<li><code>queries[i] = [2, index<sub>i</sub>, color<sub>i</sub>]</code>, change <code>colors[index<sub>i</sub>]</code> to <code>color<font face="monospace"><sub>i</sub></font></code>.</li>
</ul>
<p>Return an array <code>answer</code> containing the results of the queries of the first type <em>in order</em>.</p>
<p><strong>Note</strong> that since <code>colors</code> represents a <strong>circle</strong>, the <strong>first</strong> and the <strong>last</strong> tiles are considered to be next to each other.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">colors = [0,1,1,0,1], queries = [[2,1,0],[1,4]]</span></p>
<p><strong>Output:</strong> <span class="example-io">[2]</span></p>
<p><strong>Explanation:</strong></p>
<p><strong class="example"><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/06/03/screenshot-from-2024-06-03-20-14-44.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /></strong></p>
<p>First query:</p>
<p>Change <code>colors[1]</code> to 0.</p>
<p><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/06/03/screenshot-from-2024-06-03-20-20-25.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /></p>
<p>Second query:</p>
<p>Count of the alternating groups with size 4:</p>
<p><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/06/03/screenshot-from-2024-06-03-20-25-02-2.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/06/03/screenshot-from-2024-06-03-20-24-12.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /></p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">colors = [0,0,1,0,1,1], queries = [[1,3],[2,3,0],[1,5]]</span></p>
<p><strong>Output:</strong> <span class="example-io">[2,0]</span></p>
<p><strong>Explanation:</strong></p>
<p><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/06/03/screenshot-from-2024-06-03-20-35-50.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /></p>
<p>First query:</p>
<p>Count of the alternating groups with size 3:</p>
<p><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/06/03/screenshot-from-2024-06-03-20-37-13.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/06/03/screenshot-from-2024-06-03-20-36-40.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /></p>
<p>Second query: <code>colors</code> will not change.</p>
<p>Third query: There is no alternating group with size 5.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>4 &lt;= colors.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>0 &lt;= colors[i] &lt;= 1</code></li>
<li><code>1 &lt;= queries.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>queries[i][0] == 1</code> or <code>queries[i][0] == 2</code></li>
<li>For all <code>i</code> that:
<ul>
<li><code>queries[i][0] == 1</code>: <code>queries[i].length == 2</code>, <code>3 &lt;= queries[i][1] &lt;= colors.length - 1</code></li>
<li><code>queries[i][0] == 2</code>: <code>queries[i].length == 3</code>, <code>0 &lt;= queries[i][1] &lt;= colors.length - 1</code>, <code>0 &lt;= queries[i][2] &lt;= 1</code></li>
</ul>
</li>
</ul>

View File

@ -0,0 +1,47 @@
<p>You are given two positive integers <code>n</code> and <code>k</code>.</p>
<p>You can choose <strong>any</strong> bit in the <strong>binary representation</strong> of <code>n</code> that is equal to 1 and change it to 0.</p>
<p>Return the <em>number of changes</em> needed to make <code>n</code> equal to <code>k</code>. If it is impossible, return -1.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 13, k = 4</span></p>
<p><strong>Output:</strong> <span class="example-io">2</span></p>
<p><strong>Explanation:</strong><br />
Initially, the binary representations of <code>n</code> and <code>k</code> are <code>n = (1101)<sub>2</sub></code> and <code>k = (0100)<sub>2</sub></code>.<br />
We can change the first and fourth bits of <code>n</code>. The resulting integer is <code>n = (<u><strong>0</strong></u>10<u><strong>0</strong></u>)<sub>2</sub> = k</code>.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 21, k = 21</span></p>
<p><strong>Output:</strong> <span class="example-io">0</span></p>
<p><strong>Explanation:</strong><br />
<code>n</code> and <code>k</code> are already equal, so no changes are needed.</p>
</div>
<p><strong class="example">Example 3:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 14, k = 13</span></p>
<p><strong>Output:</strong> <span class="example-io">-1</span></p>
<p><strong>Explanation:</strong><br />
It is not possible to make <code>n</code> equal to <code>k</code>.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= n, k &lt;= 10<sup>6</sup></code></li>
</ul>

View File

@ -0,0 +1,57 @@
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p>
<p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in the range from <code>0</code> to <code>k</code>.</p>
<p>You need to perform some changes (possibly none) such that the final array satisfies the following condition:</p>
<ul>
<li>There exists an integer <code>X</code> such that <code>abs(a[i] - a[n - i - 1]) = X</code> for all <code>(0 &lt;= i &lt; n)</code>.</li>
</ul>
<p>Return the <strong>minimum</strong> number of changes required to satisfy the above condition.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [1,0,1,2,4,3], k = 4</span></p>
<p><strong>Output:</strong> <span class="example-io">2</span></p>
<p><strong>Explanation:</strong><br />
We can perform the following changes:</p>
<ul>
<li>Replace <code>nums[1]</code> by 2. The resulting array is <code>nums = [1,<u><strong>2</strong></u>,1,2,4,3]</code>.</li>
<li>Replace <code>nums[3]</code> by 3. The resulting array is <code>nums = [1,2,1,<u><strong>3</strong></u>,4,3]</code>.</li>
</ul>
<p>The integer <code>X</code> will be 2.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [0,1,2,3,3,6,5,4], k = 6</span></p>
<p><strong>Output:</strong> <span class="example-io">2</span></p>
<p><strong>Explanation:</strong><br />
We can perform the following operations:</p>
<ul>
<li>Replace <code>nums[3]</code> by 0. The resulting array is <code>nums = [0,1,2,<u><strong>0</strong></u>,3,6,5,4]</code>.</li>
<li>Replace <code>nums[4]</code> by 4. The resulting array is <code>nums = [0,1,2,0,<strong><u>4</u></strong>,6,5,4]</code>.</li>
</ul>
<p>The integer <code>X</code> will be 4.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>2 &lt;= n == nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>n</code> is even.</li>
<li><code>0 &lt;= nums[i] &lt;= k &lt;= 10<sup>5</sup></code></li>
</ul>

View File

@ -0,0 +1,45 @@
<p>You are given two positive integer arrays <code>nums</code> and <code>target</code>, of the same length.</p>
<p>In a single operation, you can select any <span data-keyword="subarray">subarray</span> of <code>nums</code> and increment or decrement each element within that subarray by 1.</p>
<p>Return the <strong>minimum</strong> number of operations required to make <code>nums</code> equal to the array <code>target</code>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [3,5,1,2], target = [4,6,2,4]</span></p>
<p><strong>Output:</strong> <span class="example-io">2</span></p>
<p><strong>Explanation:</strong></p>
<p>We will perform the following operations to make <code>nums</code> equal to <code>target</code>:<br />
- Increment&nbsp;<code>nums[0..3]</code> by 1, <code>nums = [4,6,2,3]</code>.<br />
- Increment&nbsp;<code>nums[3..3]</code> by 1, <code>nums = [4,6,2,4]</code>.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [1,3,2], target = [2,1,4]</span></p>
<p><strong>Output:</strong> <span class="example-io">5</span></p>
<p><strong>Explanation:</strong></p>
<p>We will perform the following operations to make <code>nums</code> equal to <code>target</code>:<br />
- Increment&nbsp;<code>nums[0..0]</code> by 1, <code>nums = [2,3,2]</code>.<br />
- Decrement&nbsp;<code>nums[1..1]</code> by 1, <code>nums = [2,2,2]</code>.<br />
- Decrement&nbsp;<code>nums[1..1]</code> by 1, <code>nums = [2,1,2]</code>.<br />
- Increment&nbsp;<code>nums[2..2]</code> by 1, <code>nums = [2,1,3]</code>.<br />
- Increment&nbsp;<code>nums[2..2]</code> by 1, <code>nums = [2,1,4]</code>.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= nums.length == target.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i], target[i] &lt;= 10<sup>8</sup></code></li>
</ul>

View File

@ -0,0 +1,50 @@
<p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Alice and Bob are playing a game. In the game, Alice can choose <strong>either</strong> all single-digit numbers or all double-digit numbers from <code>nums</code>, and the rest of the numbers are given to Bob. Alice wins if the sum of her numbers is <strong>strictly greater</strong> than the sum of Bob&#39;s numbers.</p>
<p>Return <code>true</code> if Alice can win this game, otherwise, return <code>false</code>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,3,4,10]</span></p>
<p><strong>Output:</strong> <span class="example-io">false</span></p>
<p><strong>Explanation:</strong></p>
<p>Alice cannot win by choosing either single-digit or double-digit numbers.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,3,4,5,14]</span></p>
<p><strong>Output:</strong> <span class="example-io">true</span></p>
<p><strong>Explanation:</strong></p>
<p>Alice can win by choosing single-digit numbers which have a sum equal to 15.</p>
</div>
<p><strong class="example">Example 3:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [5,5,5,25]</span></p>
<p><strong>Output:</strong> <span class="example-io">true</span></p>
<p><strong>Explanation:</strong></p>
<p>Alice can win by choosing double-digit numbers which have a sum equal to 25.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
<li><code>1 &lt;= nums[i] &lt;= 99</code></li>
</ul>

View File

@ -0,0 +1,70 @@
<p>You are given two positive integers <code>X</code> and <code>Y</code>, and a 2D array <code>circles</code>, where <code>circles[i] = [x<sub>i</sub>, y<sub>i</sub>, r<sub>i</sub>]</code> denotes a circle with center at <code>(x<sub>i</sub>, y<sub>i</sub>)</code> and radius <code>r<sub>i</sub></code>.</p>
<p>There is a rectangle in the coordinate plane with its bottom left corner at the origin and top right corner at the coordinate <code>(X, Y)</code>. You need to check whether there is a path from the bottom left corner to the top right corner such that the <strong>entire path</strong> lies inside the rectangle, <strong>does not</strong> touch or lie inside <strong>any</strong> circle, and touches the rectangle <strong>only</strong> at the two corners.</p>
<p>Return <code>true</code> if such a path exists, and <code>false</code> otherwise.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">X = 3, Y = 4, circles = [[2,1,1]]</span></p>
<p><strong>Output:</strong> <span class="example-io">true</span></p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/05/18/example2circle1.png" style="width: 346px; height: 264px;" /></p>
<p>The black curve shows a possible path between <code>(0, 0)</code> and <code>(3, 4)</code>.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">X = 3, Y = 3, circles = [[1,1,2]]</span></p>
<p><strong>Output:</strong> <span class="example-io">false</span></p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/05/18/example1circle.png" style="width: 346px; height: 264px;" /></p>
<p>No path exists from <code>(0, 0)</code> to <code>(3, 3)</code>.</p>
</div>
<p><strong class="example">Example 3:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">X = 3, Y = 3, circles = [[2,1,1],[1,2,1]]</span></p>
<p><strong>Output:</strong> <span class="example-io">false</span></p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/05/18/example0circle.png" style="width: 346px; height: 264px;" /></p>
<p>No path exists from <code>(0, 0)</code> to <code>(3, 3)</code>.</p>
</div>
<p><strong class="example">Example 4:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">X = 4, Y = 4, circles = [[5,5,1]]</span></p>
<p><strong>Output:</strong> <span class="example-io">true</span></p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/08/04/rectangles.png" style="width: 346px; height: 264px;" /></p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>3 &lt;= X, Y &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= circles.length &lt;= 1000</code></li>
<li><code>circles[i].length == 3</code></li>
<li><code>1 &lt;= x<sub>i</sub>, y<sub>i</sub>, r<sub>i</sub> &lt;= 10<sup>9</sup></code></li>
</ul>

View File

@ -0,0 +1,82 @@
<p>Table: <code>transactions</code></p>
<pre>
+------------------+------+
| Column Name | Type |
+------------------+------+
| transaction_id | int |
| amount | int |
| transaction_date | date |
+------------------+------+
The transactions_id column uniquely identifies each row in this table.
Each row of this table contains the transaction id, amount and transaction date.
</pre>
<p>Write a solution to find the <strong>sum of amounts</strong> for <strong>odd</strong> and <strong>even</strong> transactions for each day. If there are no odd or even transactions for a specific date, display as <code>0</code>.</p>
<p>Return <em>the result table ordered by</em> <code>transaction_date</code> <em>in <strong>ascending</strong> order</em>.</p>
<p>The result format is in the following example.</p>
<p>&nbsp;</p>
<p><strong class="example">Example:</strong></p>
<div class="example-block">
<p><strong>Input:</strong></p>
<p><code>transactions</code> table:</p>
<pre class="example-io">
+----------------+--------+------------------+
| transaction_id | amount | transaction_date |
+----------------+--------+------------------+
| 1 | 150 | 2024-07-01 |
| 2 | 200 | 2024-07-01 |
| 3 | 75 | 2024-07-01 |
| 4 | 300 | 2024-07-02 |
| 5 | 50 | 2024-07-02 |
| 6 | 120 | 2024-07-03 |
+----------------+--------+------------------+
</pre>
<p><strong>Output:</strong></p>
<pre class="example-io">
+------------------+---------+----------+
| transaction_date | odd_sum | even_sum |
+------------------+---------+----------+
| 2024-07-01 | 75 | 350 |
| 2024-07-02 | 0 | 350 |
| 2024-07-03 | 0 | 120 |
+------------------+---------+----------+
</pre>
<p><strong>Explanation:</strong></p>
<ul>
<li>For transaction dates:
<ul>
<li>2024-07-01:
<ul>
<li>Sum of amounts for odd transactions: 75</li>
<li>Sum of amounts for even transactions: 150 + 200 = 350</li>
</ul>
</li>
<li>2024-07-02:
<ul>
<li>Sum of amounts for odd transactions: 0</li>
<li>Sum of amounts for even transactions: 300 + 50 = 350</li>
</ul>
</li>
<li>2024-07-03:
<ul>
<li>Sum of amounts for odd transactions: 0</li>
<li>Sum of amounts for even transactions: 120</li>
</ul>
</li>
</ul>
</li>
</ul>
<p><strong>Note:</strong> The output table is ordered by <code>transaction_date</code> in ascending order.</p>
</div>

View File

@ -0,0 +1,52 @@
<p>Alice and Bob are playing a game on a string.</p>
<p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p>
<ul>
<li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substring</span> from <code>s</code> that contains an <strong>odd</strong> number of vowels.</li>
<li>On Bob&#39;s turn, he has to remove any <strong>non-empty</strong> <span data-keyword="substring">substring</span> from <code>s</code> that contains an <strong>even</strong> number of vowels.</li>
</ul>
<p>The first player who cannot make a move on their turn loses the game. We assume that both Alice and Bob play <strong>optimally</strong>.</p>
<p>Return <code>true</code> if Alice wins the game, and <code>false</code> otherwise.</p>
<p>The English vowels are: <code>a</code>, <code>e</code>, <code>i</code>, <code>o</code>, and <code>u</code>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;leetcoder&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">true</span></p>
<p><strong>Explanation:</strong><br />
Alice can win the game as follows:</p>
<ul>
<li>Alice plays first, she can delete the underlined substring in <code>s = &quot;<u><strong>leetco</strong></u>der&quot;</code> which contains 3 vowels. The resulting string is <code>s = &quot;der&quot;</code>.</li>
<li>Bob plays second, he can delete the underlined substring in <code>s = &quot;<u><strong>d</strong></u>er&quot;</code> which contains 0 vowels. The resulting string is <code>s = &quot;er&quot;</code>.</li>
<li>Alice plays third, she can delete the whole string <code>s = &quot;<strong><u>er</u></strong>&quot;</code> which contains 1 vowel.</li>
<li>Bob plays fourth, since the string is empty, there is no valid play for Bob. So Alice wins the game.</li>
</ul>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;bbcd&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">false</span></p>
<p><strong>Explanation:</strong><br />
There is no valid play for Alice in her first turn, so Alice loses the game.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
<li><code>s</code> consists only of lowercase English letters.</li>
</ul>

View File

@ -0,0 +1,46 @@
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p>
<p>You can perform the following operation on the string <strong>any</strong> number of times:</p>
<ul>
<li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that <code>s[i] == &#39;1&#39;</code> and <code>s[i + 1] == &#39;0&#39;</code>.</li>
<li>Move the character <code>s[i]</code> to the <strong>right</strong> until it reaches the end of the string or another <code>&#39;1&#39;</code>. For example, for <code>s = &quot;010010&quot;</code>, if we choose <code>i = 1</code>, the resulting string will be <code>s = &quot;0<strong><u>001</u></strong>10&quot;</code>.</li>
</ul>
<p>Return the <strong>maximum</strong> number of operations that you can perform.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;1001101&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">4</span></p>
<p><strong>Explanation:</strong></p>
<p>We can perform the following operations:</p>
<ul>
<li>Choose index <code>i = 0</code>. The resulting string is <code>s = &quot;<u><strong>001</strong></u>1101&quot;</code>.</li>
<li>Choose index <code>i = 4</code>. The resulting string is <code>s = &quot;0011<u><strong>01</strong></u>1&quot;</code>.</li>
<li>Choose index <code>i = 3</code>. The resulting string is <code>s = &quot;001<strong><u>01</u></strong>11&quot;</code>.</li>
<li>Choose index <code>i = 2</code>. The resulting string is <code>s = &quot;00<strong><u>01</u></strong>111&quot;</code>.</li>
</ul>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;00111&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">0</span></p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
<li><code>s[i]</code> is either <code>&#39;0&#39;</code> or <code>&#39;1&#39;</code>.</li>
</ul>

View File

@ -0,0 +1,47 @@
<p>You are given a string <code>s</code>.</p>
<p>You can perform the following process on <code>s</code> <strong>any</strong> number of times:</p>
<ul>
<li>Choose an index <code>i</code> in the string such that there is <strong>at least</strong> one character to the left of index <code>i</code> that is equal to <code>s[i]</code>, and <strong>at least</strong> one character to the right that is also equal to <code>s[i]</code>.</li>
<li>Delete the <strong>closest</strong> character to the <strong>left</strong> of index <code>i</code> that is equal to <code>s[i]</code>.</li>
<li>Delete the <strong>closest</strong> character to the <strong>right</strong> of index <code>i</code> that is equal to <code>s[i]</code>.</li>
</ul>
<p>Return the <strong>minimum</strong> length of the final string <code>s</code> that you can achieve.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;abaacbcbb&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">5</span></p>
<p><strong>Explanation:</strong><br />
We do the following operations:</p>
<ul>
<li>Choose index 2, then remove the characters at indices 0 and 3. The resulting string is <code>s = &quot;bacbcbb&quot;</code>.</li>
<li>Choose index 3, then remove the characters at indices 0 and 5. The resulting string is <code>s = &quot;acbcb&quot;</code>.</li>
</ul>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;aa&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">2</span></p>
<p><strong>Explanation:</strong><br />
We cannot perform any operations, so we return the length of the original string.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 2 * 10<sup>5</sup></code></li>
<li><code>s</code> consists only of lowercase English letters.</li>
</ul>

View File

@ -0,0 +1,60 @@
<p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 &lt;= i &lt; n - 1</code>.</p>
<p><code>queries[i] = [u<sub>i</sub>, v<sub>i</sub>]</code> represents the addition of a new <strong>unidirectional</strong> road from city <code>u<sub>i</sub></code> to city <code>v<sub>i</sub></code>. After each query, you need to find the <strong>length</strong> of the <strong>shortest path</strong> from city <code>0</code> to city <code>n - 1</code>.</p>
<p>Return an array <code>answer</code> where for each <code>i</code> in the range <code>[0, queries.length - 1]</code>, <code>answer[i]</code> is the <em>length of the shortest path</em> from city <code>0</code> to city <code>n - 1</code> after processing the <strong>first </strong><code>i + 1</code> queries.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 5, queries = [[2,4],[0,2],[0,4]]</span></p>
<p><strong>Output:</strong> <span class="example-io">[3,2,1]</span></p>
<p><strong>Explanation: </strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/28/image8.jpg" style="width: 350px; height: 60px;" /></p>
<p>After the addition of the road from 2 to 4, the length of the shortest path from 0 to 4 is 3.</p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/28/image9.jpg" style="width: 350px; height: 60px;" /></p>
<p>After the addition of the road from 0 to 2, the length of the shortest path from 0 to 4 is 2.</p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/28/image10.jpg" style="width: 350px; height: 96px;" /></p>
<p>After the addition of the road from 0 to 4, the length of the shortest path from 0 to 4 is 1.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 4, queries = [[0,3],[0,2]]</span></p>
<p><strong>Output:</strong> <span class="example-io">[1,1]</span></p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/28/image11.jpg" style="width: 300px; height: 70px;" /></p>
<p>After the addition of the road from 0 to 3, the length of the shortest path from 0 to 3 is 1.</p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/28/image12.jpg" style="width: 300px; height: 70px;" /></p>
<p>After the addition of the road from 0 to 2, the length of the shortest path remains 1.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>3 &lt;= n &lt;= 500</code></li>
<li><code>1 &lt;= queries.length &lt;= 500</code></li>
<li><code>queries[i].length == 2</code></li>
<li><code>0 &lt;= queries[i][0] &lt; queries[i][1] &lt; n</code></li>
<li><code>1 &lt; queries[i][1] - queries[i][0]</code></li>
<li>There are no repeated roads among the queries.</li>
</ul>

View File

@ -0,0 +1,63 @@
<p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 &lt;= i &lt; n - 1</code>.</p>
<p><code>queries[i] = [u<sub>i</sub>, v<sub>i</sub>]</code> represents the addition of a new <strong>unidirectional</strong> road from city <code>u<sub>i</sub></code> to city <code>v<sub>i</sub></code>. After each query, you need to find the <strong>length</strong> of the <strong>shortest path</strong> from city <code>0</code> to city <code>n - 1</code>.</p>
<p>There are no two queries such that <code>queries[i][0] &lt; queries[j][0] &lt; queries[i][1] &lt; queries[j][1]</code>.</p>
<p>Return an array <code>answer</code> where for each <code>i</code> in the range <code>[0, queries.length - 1]</code>, <code>answer[i]</code> is the <em>length of the shortest path</em> from city <code>0</code> to city <code>n - 1</code> after processing the <strong>first </strong><code>i + 1</code> queries.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 5, queries = [[2,4],[0,2],[0,4]]</span></p>
<p><strong>Output:</strong> <span class="example-io">[3,2,1]</span></p>
<p><strong>Explanation: </strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/28/image8.jpg" style="width: 350px; height: 60px;" /></p>
<p>After the addition of the road from 2 to 4, the length of the shortest path from 0 to 4 is 3.</p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/28/image9.jpg" style="width: 350px; height: 60px;" /></p>
<p>After the addition of the road from 0 to 2, the length of the shortest path from 0 to 4 is 2.</p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/28/image10.jpg" style="width: 350px; height: 96px;" /></p>
<p>After the addition of the road from 0 to 4, the length of the shortest path from 0 to 4 is 1.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 4, queries = [[0,3],[0,2]]</span></p>
<p><strong>Output:</strong> <span class="example-io">[1,1]</span></p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/28/image11.jpg" style="width: 300px; height: 70px;" /></p>
<p>After the addition of the road from 0 to 3, the length of the shortest path from 0 to 3 is 1.</p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/28/image12.jpg" style="width: 300px; height: 70px;" /></p>
<p>After the addition of the road from 0 to 2, the length of the shortest path remains 1.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>3 &lt;= n &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= queries.length &lt;= 10<sup>5</sup></code></li>
<li><code>queries[i].length == 2</code></li>
<li><code>0 &lt;= queries[i][0] &lt; queries[i][1] &lt; n</code></li>
<li><code>1 &lt; queries[i][1] - queries[i][0]</code></li>
<li>There are no repeated roads among the queries.</li>
<li>There are no two queries such that <code>i != j</code> and <code>queries[i][0] &lt; queries[j][0] &lt; queries[i][1] &lt; queries[j][1]</code>.</li>
</ul>

View File

@ -0,0 +1,58 @@
<p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code>1</code> to <code>0</code>.</p>
<p>Return the <strong>minimum</strong> number of cells that need to be flipped to make <strong>either</strong> all rows <strong>palindromic</strong> or all columns <strong>palindromic</strong>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">grid = [[1,0,0],[0,0,0],[0,0,1]]</span></p>
<p><strong>Output:</strong> <span class="example-io">2</span></p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/07/07/screenshot-from-2024-07-08-00-20-10.png" style="width: 420px; height: 108px;" /></p>
<p>Flipping the highlighted cells makes all the rows palindromic.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">grid = </span>[[0,1],[0,1],[0,0]]</p>
<p><strong>Output:</strong> <span class="example-io">1</span></p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/07/07/screenshot-from-2024-07-08-00-31-23.png" style="width: 300px; height: 100px;" /></p>
<p>Flipping the highlighted cell makes all the columns palindromic.</p>
</div>
<p><strong class="example">Example 3:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">grid = [[1],[0]]</span></p>
<p><strong>Output:</strong> <span class="example-io">0</span></p>
<p><strong>Explanation:</strong></p>
<p>All rows are already palindromic.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>m == grid.length</code></li>
<li><code>n == grid[i].length</code></li>
<li><code>1 &lt;= m * n &lt;= 2 * 10<sup>5</sup></code></li>
<li><code>0 &lt;= grid[i][j] &lt;= 1</code></li>
</ul>

View File

@ -0,0 +1,54 @@
<p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code>1</code> to <code>0</code>.</p>
<p>Return the <strong>minimum</strong> number of cells that need to be flipped to make <strong>all</strong> rows and columns <strong>palindromic</strong>, and the total number of <code>1</code>&#39;s in <code>grid</code> <strong>divisible</strong> by <code>4</code>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">grid = [[1,0,0],[0,1,0],[0,0,1]]</span></p>
<p><strong>Output:</strong> <span class="example-io">3</span></p>
<p><strong>Explanation:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2024/08/01/image.png" style="width: 400px; height: 105px;" /></p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">grid = [[0,1],[0,1],[0,0]]</span></p>
<p><strong>Output:</strong> <span class="example-io">2</span></p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/07/08/screenshot-from-2024-07-09-01-37-48.png" style="width: 300px; height: 104px;" /></p>
</div>
<p><strong class="example">Example 3:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">grid = [[1],[1]]</span></p>
<p><strong>Output:</strong> <span class="example-io">2</span></p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/08/01/screenshot-from-2024-08-01-23-05-26.png" style="width: 200px; height: 70px;" /></p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>m == grid.length</code></li>
<li><code>n == grid[i].length</code></li>
<li><code>1 &lt;= m * n &lt;= 2 * 10<sup>5</sup></code></li>
<li><code>0 &lt;= grid[i][j] &lt;= 1</code></li>
</ul>

View File

@ -0,0 +1,93 @@
<p>There exists an <strong>undirected</strong> tree with <code>n</code> nodes numbered <code>0</code> to <code>n - 1</code>. You are given a 2D integer array <code>edges</code> of length <code>n - 1</code>, where <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub>]</code> indicates that there is an edge between nodes <code>u<sub>i</sub></code> and <code>v<sub>i</sub></code> in the tree.</p>
<p>Initially, <strong>all</strong> nodes are <strong>unmarked</strong>. For each node <code>i</code>:</p>
<ul>
<li>If <code>i</code> is odd, the node will get marked at time <code>x</code> if there is <strong>at least</strong> one node <em>adjacent</em> to it which was marked at time <code>x - 1</code>.</li>
<li>If <code>i</code> is even, the node will get marked at time <code>x</code> if there is <strong>at least</strong> one node <em>adjacent</em> to it which was marked at time <code>x - 2</code>.</li>
</ul>
<p>Return an array <code>times</code> where <code>times[i]</code> is the time when all nodes get marked in the tree, if you mark node <code>i</code> at time <code>t = 0</code>.</p>
<p><strong>Note</strong> that the answer for each <code>times[i]</code> is <strong>independent</strong>, i.e. when you mark node <code>i</code> all other nodes are <em>unmarked</em>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">edges = [[0,1],[0,2]]</span></p>
<p><strong>Output:</strong> [2,4,3]</p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/01/screenshot-2024-06-02-122236.png" style="width: 500px; height: 241px;" /></p>
<ul>
<li>For <code>i = 0</code>:
<ul>
<li>Node 1 is marked at <code>t = 1</code>, and Node 2 at <code>t = 2</code>.</li>
</ul>
</li>
<li>For <code>i = 1</code>:
<ul>
<li>Node 0 is marked at <code>t = 2</code>, and Node 2 at <code>t = 4</code>.</li>
</ul>
</li>
<li>For <code>i = 2</code>:
<ul>
<li>Node 0 is marked at <code>t = 2</code>, and Node 1 at <code>t = 3</code>.</li>
</ul>
</li>
</ul>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">edges = [[0,1]]</span></p>
<p><strong>Output:</strong> [1,2]</p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/01/screenshot-2024-06-02-122249.png" style="width: 500px; height: 257px;" /></p>
<ul>
<li>For <code>i = 0</code>:
<ul>
<li>Node 1 is marked at <code>t = 1</code>.</li>
</ul>
</li>
<li>For <code>i = 1</code>:
<ul>
<li>Node 0 is marked at <code>t = 2</code>.</li>
</ul>
</li>
</ul>
</div>
<p><strong class="example">Example 3:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">edges = </span>[[2,4],[0,1],[2,3],[0,2]]</p>
<p><strong>Output:</strong> [4,6,3,5,5]</p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/03/screenshot-2024-06-03-210550.png" style="height: 266px; width: 500px;" /></p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>2 &lt;= n &lt;= 10<sup>5</sup></code></li>
<li><code>edges.length == n - 1</code></li>
<li><code>edges[i].length == 2</code></li>
<li><code>0 &lt;= edges[i][0], edges[i][1] &lt;= n - 1</code></li>
<li>The input is generated such that <code>edges</code> represents a valid tree.</li>
</ul>

View File

@ -0,0 +1,46 @@
<p>You are given two <strong>positive</strong> integers <code>x</code> and <code>y</code>, denoting the number of coins with values 75 and 10 <em>respectively</em>.</p>
<p>Alice and Bob are playing a game. Each turn, starting with <strong>Alice</strong>, the player must pick up coins with a <strong>total</strong> value 115. If the player is unable to do so, they <strong>lose</strong> the game.</p>
<p>Return the <em>name</em> of the player who wins the game if both players play <strong>optimally</strong>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">x = 2, y = 7</span></p>
<p><strong>Output:</strong> <span class="example-io">&quot;Alice&quot;</span></p>
<p><strong>Explanation:</strong></p>
<p>The game ends in a single turn:</p>
<ul>
<li>Alice picks 1 coin with a value of 75 and 4 coins with a value of 10.</li>
</ul>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">x = 4, y = 11</span></p>
<p><strong>Output:</strong> <span class="example-io">&quot;Bob&quot;</span></p>
<p><strong>Explanation:</strong></p>
<p>The game ends in 2 turns:</p>
<ul>
<li>Alice picks 1 coin with a value of 75 and 4 coins with a value of 10.</li>
<li>Bob picks 1 coin with a value of 75 and 4 coins with a value of 10.</li>
</ul>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= x, y &lt;= 100</code></li>
</ul>

View File

@ -0,0 +1,62 @@
<p>You are given an integer <code>n</code> representing the number of players in a game and a 2D array <code>pick</code> where <code>pick[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents that the player <code>x<sub>i</sub></code> picked a ball of color <code>y<sub>i</sub></code>.</p>
<p>Player <code>i</code> <strong>wins</strong> the game if they pick <strong>strictly more</strong> than <code>i</code> balls of the <strong>same</strong> color. In other words,</p>
<ul>
<li>Player 0 wins if they pick any ball.</li>
<li>Player 1 wins if they pick at least two balls of the <em>same</em> color.</li>
<li>...</li>
<li>Player <code>i</code> wins if they pick at least<code>i + 1</code> balls of the <em>same</em> color.</li>
</ul>
<p>Return the number of players who <strong>win</strong> the game.</p>
<p><strong>Note</strong> that <em>multiple</em> players can win the game.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 4, pick = [[0,0],[1,0],[1,0],[2,1],[2,1],[2,0]]</span></p>
<p><strong>Output:</strong> <span class="example-io">2</span></p>
<p><strong>Explanation:</strong></p>
<p>Player 0 and player 1 win the game, while players 2 and 3 do not win.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 5, pick = [[1,1],[1,2],[1,3],[1,4]]</span></p>
<p><strong>Output:</strong> <span class="example-io">0</span></p>
<p><strong>Explanation:</strong></p>
<p>No player wins the game.</p>
</div>
<p><strong class="example">Example 3:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 5, pick = [[1,1],[2,4],[2,4],[2,4]]</span></p>
<p><strong>Output:</strong> <span class="example-io">1</span></p>
<p><strong>Explanation:</strong></p>
<p>Player 2 wins the game by picking 3 balls with color 4.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>2 &lt;= n &lt;= 10</code></li>
<li><code>1 &lt;= pick.length &lt;= 100</code></li>
<li><code>pick[i].length == 2</code></li>
<li><code>0 &lt;= x<sub>i</sub> &lt;= n - 1 </code></li>
<li><code>0 &lt;= y<sub>i</sub> &lt;= 10</code></li>
</ul>

View File

@ -0,0 +1,138 @@
<p>You are given a binary string <code>s</code>.</p>
<p>Return the number of <span data-keyword="substring-nonempty">substrings</span> with <strong>dominant</strong> ones.</p>
<p>A string has <strong>dominant</strong> ones if the number of ones in the string is <strong>greater than or equal to</strong> the <strong>square</strong> of the number of zeros in the string.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;00011&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">5</span></p>
<p><strong>Explanation:</strong></p>
<p>The substrings with dominant ones are shown in the table below.</p>
</div>
<table>
<thead>
<tr>
<th>i</th>
<th>j</th>
<th>s[i..j]</th>
<th>Number of Zeros</th>
<th>Number of Ones</th>
</tr>
</thead>
<tbody>
<tr>
<td>3</td>
<td>3</td>
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<td>4</td>
<td>4</td>
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
<td>3</td>
<td>01</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
<td>11</td>
<td>0</td>
<td>2</td>
</tr>
<tr>
<td>2</td>
<td>4</td>
<td>011</td>
<td>1</td>
<td>2</td>
</tr>
</tbody>
</table>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;101101&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">16</span></p>
<p><strong>Explanation:</strong></p>
<p>The substrings with <strong>non-dominant</strong> ones are shown in the table below.</p>
<p>Since there are 21 substrings total and 5 of them have non-dominant ones, it follows that there are 16 substrings with dominant ones.</p>
</div>
<table>
<thead>
<tr>
<th>i</th>
<th>j</th>
<th>s[i..j]</th>
<th>Number of Zeros</th>
<th>Number of Ones</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<td>4</td>
<td>4</td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<td>1</td>
<td>4</td>
<td>0110</td>
<td>2</td>
<td>2</td>
</tr>
<tr>
<td>0</td>
<td>4</td>
<td>10110</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>1</td>
<td>5</td>
<td>01101</td>
<td>2</td>
<td>3</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 4 * 10<sup>4</sup></code></li>
<li><code>s</code> consists only of characters <code>&#39;0&#39;</code> and <code>&#39;1&#39;</code>.</li>
</ul>

View File

@ -0,0 +1,42 @@
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p>
<p>A number is called <strong>special</strong> if it has exactly 2 <strong>proper divisors</strong>. For example:</p>
<ul>
<li>The number 4 is <em>special</em> because it has proper divisors 1 and 2.</li>
<li>The number 6 is <em>not special</em> because it has proper divisors 1, 2, and 3.</li>
</ul>
<p>Return the count of numbers in the range <code>[l, r]</code> that are <strong>not</strong> <strong>special</strong>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">l = 5, r = 7</span></p>
<p><strong>Output:</strong> <span class="example-io">3</span></p>
<p><strong>Explanation:</strong></p>
<p>There are no special numbers in the range <code>[5, 7]</code>.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">l = 4, r = 16</span></p>
<p><strong>Output:</strong> <span class="example-io">11</span></p>
<p><strong>Explanation:</strong></p>
<p>The special numbers in the range <code>[4, 16]</code> are 4 and 9.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= l &lt;= r &lt;= 10<sup>9</sup></code></li>
</ul>

View File

@ -0,0 +1,39 @@
<p>You are given a 2D matrix <code>grid</code> of size <code>n x n</code>. Initially, all cells of the grid are colored white. In one operation, you can select any cell of indices <code>(i, j)</code>, and color black all the cells of the <code>j<sup>th</sup></code> column starting from the top row down to the <code>i<sup>th</sup></code> row.</p>
<p>The grid score is the sum of all <code>grid[i][j]</code> such that cell <code>(i, j)</code> is white and it has a horizontally adjacent black cell.</p>
<p>Return the <strong>maximum</strong> score that can be achieved after some number of operations.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">grid = [[0,0,0,0,0],[0,0,3,0,0],[0,1,0,0,0],[5,0,0,3,0],[0,0,0,0,2]]</span></p>
<p><strong>Output:</strong> <span class="example-io">11</span></p>
<p><strong>Explanation:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2024/05/11/one.png" style="width: 300px; height: 200px;" />
<p>In the first operation, we color all cells in column 1 down to row 3, and in the second operation, we color all cells in column 4 down to the last row. The score of the resulting grid is <code>grid[3][0] + grid[1][2] + grid[3][3]</code> which is equal to 11.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">grid = [[10,9,0,0,15],[7,1,0,8,0],[5,20,0,11,0],[0,0,0,1,2],[8,12,1,10,3]]</span></p>
<p><strong>Output:</strong> <span class="example-io">94</span></p>
<p><strong>Explanation:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2024/05/11/two-1.png" style="width: 300px; height: 200px;" />
<p>We perform operations on 1, 2, and 3 down to rows 1, 4, and 0, respectively. The score of the resulting grid is <code>grid[0][0] + grid[1][0] + grid[2][1] + grid[4][1] + grid[1][3] + grid[2][3] + grid[3][3] + grid[4][3] + grid[0][4]</code> which is equal to 94.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;=&nbsp;n == grid.length &lt;= 100</code></li>
<li><code>n == grid[i].length</code></li>
<li><code>0 &lt;= grid[i][j] &lt;= 10<sup>9</sup></code></li>
</ul>

View File

@ -0,0 +1,67 @@
<p>You are given a <code>n x n</code> 2D array <code>grid</code> containing <strong>distinct</strong> elements in the range <code>[0, n<sup>2</sup> - 1]</code>.</p>
<p>Implement the <code>neighborSum</code> class:</p>
<ul>
<li><code>neighborSum(int [][]grid)</code> initializes the object.</li>
<li><code>int adjacentSum(int value)</code> returns the <strong>sum</strong> of elements which are adjacent neighbors of <code>value</code>, that is either to the top, left, right, or bottom of <code>value</code> in <code>grid</code>.</li>
<li><code>int diagonalSum(int value)</code> returns the <strong>sum</strong> of elements which are diagonal neighbors of <code>value</code>, that is either to the top-left, top-right, bottom-left, or bottom-right of <code>value</code> in <code>grid</code>.</li>
</ul>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/24/design.png" style="width: 400px; height: 248px;" /></p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong></p>
<p>[&quot;neighborSum&quot;, &quot;adjacentSum&quot;, &quot;adjacentSum&quot;, &quot;diagonalSum&quot;, &quot;diagonalSum&quot;]</p>
<p>[[[[0, 1, 2], [3, 4, 5], [6, 7, 8]]], [1], [4], [4], [8]]</p>
<p><strong>Output:</strong> [null, 6, 16, 16, 4]</p>
<p><strong>Explanation:</strong></p>
<p><strong class="example"><img alt="" src="https://assets.leetcode.com/uploads/2024/06/24/designexample0.png" style="width: 250px; height: 249px;" /></strong></p>
<ul>
<li>The adjacent neighbors of 1 are 0, 2, and 4.</li>
<li>The adjacent neighbors of 4 are 1, 3, 5, and 7.</li>
<li>The diagonal neighbors of 4 are 0, 2, 6, and 8.</li>
<li>The diagonal neighbor of 8 is 4.</li>
</ul>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong></p>
<p>[&quot;neighborSum&quot;, &quot;adjacentSum&quot;, &quot;diagonalSum&quot;]</p>
<p>[[[[1, 2, 0, 3], [4, 7, 15, 6], [8, 9, 10, 11], [12, 13, 14, 5]]], [15], [9]]</p>
<p><strong>Output:</strong> [null, 23, 45]</p>
<p><strong>Explanation:</strong></p>
<p><strong class="example"><img alt="" src="https://assets.leetcode.com/uploads/2024/06/24/designexample2.png" style="width: 300px; height: 300px;" /></strong></p>
<ul>
<li>The adjacent neighbors of 15 are 0, 10, 7, and 6.</li>
<li>The diagonal neighbors of 9 are 4, 12, 14, and 15.</li>
</ul>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>3 &lt;= n == grid.length == grid[0].length &lt;= 10</code></li>
<li><code>0 &lt;= grid[i][j] &lt;= n<sup>2</sup> - 1</code></li>
<li>All <code>grid[i][j]</code> are distinct.</li>
<li><code>value</code> in <code>adjacentSum</code> and <code>diagonalSum</code> will be in the range <code>[0, n<sup>2</sup> - 1]</code>.</li>
<li>At most <code>2 * n<sup>2</sup></code> calls will be made to <code>adjacentSum</code> and <code>diagonalSum</code>.</li>
</ul>

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,90 @@
{
"data": {
"question": {
"questionId": "3530",
"questionFrontendId": "3220",
"boundTopicId": null,
"title": "Odd and Even Transactions",
"titleSlug": "odd-and-even-transactions",
"content": "<p>Table: <code>transactions</code></p>\n\n<pre>\n+------------------+------+\n| Column Name | Type | \n+------------------+------+\n| transaction_id | int |\n| amount | int |\n| transaction_date | date |\n+------------------+------+\nThe transactions_id column uniquely identifies each row in this table.\nEach row of this table contains the transaction id, amount and transaction date.\n</pre>\n\n<p>Write a solution to find the <strong>sum of amounts</strong> for <strong>odd</strong> and <strong>even</strong> transactions for each day. If there are no odd or even transactions for a specific date, display as <code>0</code>.</p>\n\n<p>Return <em>the result table ordered by</em> <code>transaction_date</code> <em>in <strong>ascending</strong> order</em>.</p>\n\n<p>The result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example:</strong></p>\n\n<div class=\"example-block\">\n<p><strong>Input:</strong></p>\n\n<p><code>transactions</code> table:</p>\n\n<pre class=\"example-io\">\n+----------------+--------+------------------+\n| transaction_id | amount | transaction_date |\n+----------------+--------+------------------+\n| 1 | 150 | 2024-07-01 |\n| 2 | 200 | 2024-07-01 |\n| 3 | 75 | 2024-07-01 |\n| 4 | 300 | 2024-07-02 |\n| 5 | 50 | 2024-07-02 |\n| 6 | 120 | 2024-07-03 |\n+----------------+--------+------------------+\n </pre>\n\n<p><strong>Output:</strong></p>\n\n<pre class=\"example-io\">\n+------------------+---------+----------+\n| transaction_date | odd_sum | even_sum |\n+------------------+---------+----------+\n| 2024-07-01 | 75 | 350 |\n| 2024-07-02 | 0 | 350 |\n| 2024-07-03 | 0 | 120 |\n+------------------+---------+----------+\n </pre>\n\n<p><strong>Explanation:</strong></p>\n\n<ul>\n\t<li>For transaction dates:\n\t<ul>\n\t\t<li>2024-07-01:\n\t\t<ul>\n\t\t\t<li>Sum of amounts for odd transactions: 75</li>\n\t\t\t<li>Sum of amounts for even transactions: 150 + 200 = 350</li>\n\t\t</ul>\n\t\t</li>\n\t\t<li>2024-07-02:\n\t\t<ul>\n\t\t\t<li>Sum of amounts for odd transactions: 0</li>\n\t\t\t<li>Sum of amounts for even transactions: 300 + 50 = 350</li>\n\t\t</ul>\n\t\t</li>\n\t\t<li>2024-07-03:\n\t\t<ul>\n\t\t\t<li>Sum of amounts for odd transactions: 0</li>\n\t\t\t<li>Sum of amounts for even transactions: 120</li>\n\t\t</ul>\n\t\t</li>\n\t</ul>\n\t</li>\n</ul>\n\n<p><strong>Note:</strong> The output table is ordered by <code>transaction_date</code> in ascending order.</p>\n</div>\n",
"translatedTitle": null,
"translatedContent": null,
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 16,
"dislikes": 1,
"isLiked": null,
"similarQuestions": "[]",
"exampleTestcases": "{\"headers\":{\"transactions\":[\"transaction_id\",\"amount\",\"transaction_date\"]},\"rows\":{\"transactions\":[[1,150,\"2024-07-01\"],[2,200,\"2024-07-01\"],[3,75,\"2024-07-01\"],[4,300,\"2024-07-02\"],[5,50,\"2024-07-02\"],[6,120,\"2024-07-03\"]]}}",
"categoryTitle": "Database",
"contributors": [],
"topicTags": [
{
"name": "Database",
"slug": "database",
"translatedName": null,
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": [
{
"lang": "MySQL",
"langSlug": "mysql",
"code": "# Write your MySQL query statement below\n",
"__typename": "CodeSnippetNode"
},
{
"lang": "MS SQL Server",
"langSlug": "mssql",
"code": "/* Write your T-SQL query statement below */\n",
"__typename": "CodeSnippetNode"
},
{
"lang": "Oracle",
"langSlug": "oraclesql",
"code": "/* Write your PL/SQL query statement below */\n",
"__typename": "CodeSnippetNode"
},
{
"lang": "Pandas",
"langSlug": "pythondata",
"code": "import pandas as pd\n\ndef sum_daily_odd_even(transactions: pd.DataFrame) -> pd.DataFrame:\n ",
"__typename": "CodeSnippetNode"
},
{
"lang": "PostgreSQL",
"langSlug": "postgresql",
"code": "-- Write your PostgreSQL query statement below\n",
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"2.3K\", \"totalSubmission\": \"3.3K\", \"totalAcceptedRaw\": 2337, \"totalSubmissionRaw\": 3253, \"acRate\": \"71.8%\"}",
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "{\"headers\":{\"transactions\":[\"transaction_id\",\"amount\",\"transaction_date\"]},\"rows\":{\"transactions\":[[1,150,\"2024-07-01\"],[2,200,\"2024-07-01\"],[3,75,\"2024-07-01\"],[4,300,\"2024-07-02\"],[5,50,\"2024-07-02\"],[6,120,\"2024-07-03\"]]}}",
"metaData": "{\"mysql\": [\"Create table if not exists transactions ( transaction_id int, amount int, transaction_date date)\"], \"mssql\": [\"Create table transactions ( transaction_id int, amount int, transaction_date date)\"], \"oraclesql\": [\"Create table transactions ( transaction_id int, amount int, transaction_date date)\", \"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"], \"database\": true, \"name\": \"sum_daily_odd_even\", \"postgresql\": [\"CREATE TABLE IF NOT EXISTS transactions (\\n transaction_id int,\\n amount int,\\n transaction_date date\\n);\\n\"], \"pythondata\": [\"transactions = pd.DataFrame(\\n columns=[\\\"transaction_id\\\", \\\"amount\\\", \\\"transaction_date\\\"],\\n dtype={\\n \\\"transaction_id\\\": \\\"int\\\",\\n \\\"amount\\\": \\\"int\\\",\\n \\\"transaction_date\\\": \\\"datetime64[ns]\\\",\\n },\\n)\\n\"], \"database_schema\": {\"transactions\": {\"transaction_id\": \"INT\", \"amount\": \"INT\", \"transaction_date\": \"DATE\"}}}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [
"Create table if not exists transactions ( transaction_id int, amount int, transaction_date date)",
"Truncate table transactions",
"insert into transactions (transaction_id, amount, transaction_date) values ('1', '150', '2024-07-01')",
"insert into transactions (transaction_id, amount, transaction_date) values ('2', '200', '2024-07-01')",
"insert into transactions (transaction_id, amount, transaction_date) values ('3', '75', '2024-07-01')",
"insert into transactions (transaction_id, amount, transaction_date) values ('4', '300', '2024-07-02')",
"insert into transactions (transaction_id, amount, transaction_date) values ('5', '50', '2024-07-02')",
"insert into transactions (transaction_id, amount, transaction_date) values ('6', '120', '2024-07-03')"
],
"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

View File

@ -0,0 +1,84 @@
<p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>colors[i] == 1</code> means that tile <code>i</code> is <strong>blue</strong>.</li>
</ul>
<p>An <strong>alternating</strong> group is a contiguous subset of tiles in the circle with <strong>alternating</strong> colors (each tile in the group except the first and last one has a different color from its <b>adjacent</b> tiles in the group).</p>
<p>You have to process queries of two types:</p>
<ul>
<li><code>queries[i] = [1, size<sub>i</sub>]</code>, determine the count of <strong>alternating</strong> groups with size <code>size<sub>i</sub></code>.</li>
<li><code>queries[i] = [2, index<sub>i</sub>, color<sub>i</sub>]</code>, change <code>colors[index<sub>i</sub>]</code> to <code>color<font face="monospace"><sub>i</sub></font></code>.</li>
</ul>
<p>Return an array <code>answer</code> containing the results of the queries of the first type <em>in order</em>.</p>
<p><strong>Note</strong> that since <code>colors</code> represents a <strong>circle</strong>, the <strong>first</strong> and the <strong>last</strong> tiles are considered to be next to each other.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">colors = [0,1,1,0,1], queries = [[2,1,0],[1,4]]</span></p>
<p><strong>Output:</strong> <span class="example-io">[2]</span></p>
<p><strong>Explanation:</strong></p>
<p><strong class="example"><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/06/03/screenshot-from-2024-06-03-20-14-44.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /></strong></p>
<p>First query:</p>
<p>Change <code>colors[1]</code> to 0.</p>
<p><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/06/03/screenshot-from-2024-06-03-20-20-25.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /></p>
<p>Second query:</p>
<p>Count of the alternating groups with size 4:</p>
<p><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/06/03/screenshot-from-2024-06-03-20-25-02-2.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/06/03/screenshot-from-2024-06-03-20-24-12.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /></p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">colors = [0,0,1,0,1,1], queries = [[1,3],[2,3,0],[1,5]]</span></p>
<p><strong>Output:</strong> <span class="example-io">[2,0]</span></p>
<p><strong>Explanation:</strong></p>
<p><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/06/03/screenshot-from-2024-06-03-20-35-50.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /></p>
<p>First query:</p>
<p>Count of the alternating groups with size 3:</p>
<p><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/06/03/screenshot-from-2024-06-03-20-37-13.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/06/03/screenshot-from-2024-06-03-20-36-40.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /></p>
<p>Second query: <code>colors</code> will not change.</p>
<p>Third query: There is no alternating group with size 5.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>4 &lt;= colors.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>0 &lt;= colors[i] &lt;= 1</code></li>
<li><code>1 &lt;= queries.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>queries[i][0] == 1</code> or <code>queries[i][0] == 2</code></li>
<li>For all <code>i</code> that:
<ul>
<li><code>queries[i][0] == 1</code>: <code>queries[i].length == 2</code>, <code>3 &lt;= queries[i][1] &lt;= colors.length - 1</code></li>
<li><code>queries[i][0] == 2</code>: <code>queries[i].length == 3</code>, <code>0 &lt;= queries[i][1] &lt;= colors.length - 1</code>, <code>0 &lt;= queries[i][2] &lt;= 1</code></li>
</ul>
</li>
</ul>

View File

@ -0,0 +1,70 @@
<p>You are given two positive integers <code>X</code> and <code>Y</code>, and a 2D array <code>circles</code>, where <code>circles[i] = [x<sub>i</sub>, y<sub>i</sub>, r<sub>i</sub>]</code> denotes a circle with center at <code>(x<sub>i</sub>, y<sub>i</sub>)</code> and radius <code>r<sub>i</sub></code>.</p>
<p>There is a rectangle in the coordinate plane with its bottom left corner at the origin and top right corner at the coordinate <code>(X, Y)</code>. You need to check whether there is a path from the bottom left corner to the top right corner such that the <strong>entire path</strong> lies inside the rectangle, <strong>does not</strong> touch or lie inside <strong>any</strong> circle, and touches the rectangle <strong>only</strong> at the two corners.</p>
<p>Return <code>true</code> if such a path exists, and <code>false</code> otherwise.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">X = 3, Y = 4, circles = [[2,1,1]]</span></p>
<p><strong>Output:</strong> <span class="example-io">true</span></p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/05/18/example2circle1.png" style="width: 346px; height: 264px;" /></p>
<p>The black curve shows a possible path between <code>(0, 0)</code> and <code>(3, 4)</code>.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">X = 3, Y = 3, circles = [[1,1,2]]</span></p>
<p><strong>Output:</strong> <span class="example-io">false</span></p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/05/18/example1circle.png" style="width: 346px; height: 264px;" /></p>
<p>No path exists from <code>(0, 0)</code> to <code>(3, 3)</code>.</p>
</div>
<p><strong class="example">Example 3:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">X = 3, Y = 3, circles = [[2,1,1],[1,2,1]]</span></p>
<p><strong>Output:</strong> <span class="example-io">false</span></p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/05/18/example0circle.png" style="width: 346px; height: 264px;" /></p>
<p>No path exists from <code>(0, 0)</code> to <code>(3, 3)</code>.</p>
</div>
<p><strong class="example">Example 4:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">X = 4, Y = 4, circles = [[5,5,1]]</span></p>
<p><strong>Output:</strong> <span class="example-io">true</span></p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/08/04/rectangles.png" style="width: 346px; height: 264px;" /></p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>3 &lt;= X, Y &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= circles.length &lt;= 1000</code></li>
<li><code>circles[i].length == 3</code></li>
<li><code>1 &lt;= x<sub>i</sub>, y<sub>i</sub>, r<sub>i</sub> &lt;= 10<sup>9</sup></code></li>
</ul>

View File

@ -0,0 +1,138 @@
<p>You are given a binary string <code>s</code>.</p>
<p>Return the number of <span data-keyword="substring-nonempty">substrings</span> with <strong>dominant</strong> ones.</p>
<p>A string has <strong>dominant</strong> ones if the number of ones in the string is <strong>greater than or equal to</strong> the <strong>square</strong> of the number of zeros in the string.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;00011&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">5</span></p>
<p><strong>Explanation:</strong></p>
<p>The substrings with dominant ones are shown in the table below.</p>
</div>
<table>
<thead>
<tr>
<th>i</th>
<th>j</th>
<th>s[i..j]</th>
<th>Number of Zeros</th>
<th>Number of Ones</th>
</tr>
</thead>
<tbody>
<tr>
<td>3</td>
<td>3</td>
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<td>4</td>
<td>4</td>
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
<td>3</td>
<td>01</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
<td>11</td>
<td>0</td>
<td>2</td>
</tr>
<tr>
<td>2</td>
<td>4</td>
<td>011</td>
<td>1</td>
<td>2</td>
</tr>
</tbody>
</table>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;101101&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">16</span></p>
<p><strong>Explanation:</strong></p>
<p>The substrings with <strong>non-dominant</strong> ones are shown in the table below.</p>
<p>Since there are 21 substrings total and 5 of them have non-dominant ones, it follows that there are 16 substrings with dominant ones.</p>
</div>
<table>
<thead>
<tr>
<th>i</th>
<th>j</th>
<th>s[i..j]</th>
<th>Number of Zeros</th>
<th>Number of Ones</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<td>4</td>
<td>4</td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<td>1</td>
<td>4</td>
<td>0110</td>
<td>2</td>
<td>2</td>
</tr>
<tr>
<td>0</td>
<td>4</td>
<td>10110</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>1</td>
<td>5</td>
<td>01101</td>
<td>2</td>
<td>3</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 4 * 10<sup>4</sup></code></li>
<li><code>s</code> consists only of characters <code>&#39;0&#39;</code> and <code>&#39;1&#39;</code>.</li>
</ul>

View File

@ -0,0 +1,67 @@
<p>You are given a <code>n x n</code> 2D array <code>grid</code> containing <strong>distinct</strong> elements in the range <code>[0, n<sup>2</sup> - 1]</code>.</p>
<p>Implement the <code>neighborSum</code> class:</p>
<ul>
<li><code>neighborSum(int [][]grid)</code> initializes the object.</li>
<li><code>int adjacentSum(int value)</code> returns the <strong>sum</strong> of elements which are adjacent neighbors of <code>value</code>, that is either to the top, left, right, or bottom of <code>value</code> in <code>grid</code>.</li>
<li><code>int diagonalSum(int value)</code> returns the <strong>sum</strong> of elements which are diagonal neighbors of <code>value</code>, that is either to the top-left, top-right, bottom-left, or bottom-right of <code>value</code> in <code>grid</code>.</li>
</ul>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/24/design.png" style="width: 400px; height: 248px;" /></p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong></p>
<p>[&quot;neighborSum&quot;, &quot;adjacentSum&quot;, &quot;adjacentSum&quot;, &quot;diagonalSum&quot;, &quot;diagonalSum&quot;]</p>
<p>[[[[0, 1, 2], [3, 4, 5], [6, 7, 8]]], [1], [4], [4], [8]]</p>
<p><strong>Output:</strong> [null, 6, 16, 16, 4]</p>
<p><strong>Explanation:</strong></p>
<p><strong class="example"><img alt="" src="https://assets.leetcode.com/uploads/2024/06/24/designexample0.png" style="width: 250px; height: 249px;" /></strong></p>
<ul>
<li>The adjacent neighbors of 1 are 0, 2, and 4.</li>
<li>The adjacent neighbors of 4 are 1, 3, 5, and 7.</li>
<li>The diagonal neighbors of 4 are 0, 2, 6, and 8.</li>
<li>The diagonal neighbor of 8 is 4.</li>
</ul>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong></p>
<p>[&quot;neighborSum&quot;, &quot;adjacentSum&quot;, &quot;diagonalSum&quot;]</p>
<p>[[[[1, 2, 0, 3], [4, 7, 15, 6], [8, 9, 10, 11], [12, 13, 14, 5]]], [15], [9]]</p>
<p><strong>Output:</strong> [null, 23, 45]</p>
<p><strong>Explanation:</strong></p>
<p><strong class="example"><img alt="" src="https://assets.leetcode.com/uploads/2024/06/24/designexample2.png" style="width: 300px; height: 300px;" /></strong></p>
<ul>
<li>The adjacent neighbors of 15 are 0, 10, 7, and 6.</li>
<li>The diagonal neighbors of 9 are 4, 12, 14, and 15.</li>
</ul>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>3 &lt;= n == grid.length == grid[0].length &lt;= 10</code></li>
<li><code>0 &lt;= grid[i][j] &lt;= n<sup>2</sup> - 1</code></li>
<li>All <code>grid[i][j]</code> are distinct.</li>
<li><code>value</code> in <code>adjacentSum</code> and <code>diagonalSum</code> will be in the range <code>[0, n<sup>2</sup> - 1]</code>.</li>
<li>At most <code>2 * n<sup>2</sup></code> calls will be made to <code>adjacentSum</code> and <code>diagonalSum</code>.</li>
</ul>

View File

@ -0,0 +1,50 @@
<p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Alice and Bob are playing a game. In the game, Alice can choose <strong>either</strong> all single-digit numbers or all double-digit numbers from <code>nums</code>, and the rest of the numbers are given to Bob. Alice wins if the sum of her numbers is <strong>strictly greater</strong> than the sum of Bob&#39;s numbers.</p>
<p>Return <code>true</code> if Alice can win this game, otherwise, return <code>false</code>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,3,4,10]</span></p>
<p><strong>Output:</strong> <span class="example-io">false</span></p>
<p><strong>Explanation:</strong></p>
<p>Alice cannot win by choosing either single-digit or double-digit numbers.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,3,4,5,14]</span></p>
<p><strong>Output:</strong> <span class="example-io">true</span></p>
<p><strong>Explanation:</strong></p>
<p>Alice can win by choosing single-digit numbers which have a sum equal to 15.</p>
</div>
<p><strong class="example">Example 3:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [5,5,5,25]</span></p>
<p><strong>Output:</strong> <span class="example-io">true</span></p>
<p><strong>Explanation:</strong></p>
<p>Alice can win by choosing double-digit numbers which have a sum equal to 25.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
<li><code>1 &lt;= nums[i] &lt;= 99</code></li>
</ul>

View File

@ -0,0 +1,42 @@
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p>
<p>A number is called <strong>special</strong> if it has exactly 2 <strong>proper divisors</strong>. For example:</p>
<ul>
<li>The number 4 is <em>special</em> because it has proper divisors 1 and 2.</li>
<li>The number 6 is <em>not special</em> because it has proper divisors 1, 2, and 3.</li>
</ul>
<p>Return the count of numbers in the range <code>[l, r]</code> that are <strong>not</strong> <strong>special</strong>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">l = 5, r = 7</span></p>
<p><strong>Output:</strong> <span class="example-io">3</span></p>
<p><strong>Explanation:</strong></p>
<p>There are no special numbers in the range <code>[5, 7]</code>.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">l = 4, r = 16</span></p>
<p><strong>Output:</strong> <span class="example-io">11</span></p>
<p><strong>Explanation:</strong></p>
<p>The special numbers in the range <code>[4, 16]</code> are 4 and 9.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= l &lt;= r &lt;= 10<sup>9</sup></code></li>
</ul>

View File

@ -0,0 +1,62 @@
<p>You are given an integer <code>n</code> representing the number of players in a game and a 2D array <code>pick</code> where <code>pick[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents that the player <code>x<sub>i</sub></code> picked a ball of color <code>y<sub>i</sub></code>.</p>
<p>Player <code>i</code> <strong>wins</strong> the game if they pick <strong>strictly more</strong> than <code>i</code> balls of the <strong>same</strong> color. In other words,</p>
<ul>
<li>Player 0 wins if they pick any ball.</li>
<li>Player 1 wins if they pick at least two balls of the <em>same</em> color.</li>
<li>...</li>
<li>Player <code>i</code> wins if they pick at least<code>i + 1</code> balls of the <em>same</em> color.</li>
</ul>
<p>Return the number of players who <strong>win</strong> the game.</p>
<p><strong>Note</strong> that <em>multiple</em> players can win the game.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 4, pick = [[0,0],[1,0],[1,0],[2,1],[2,1],[2,0]]</span></p>
<p><strong>Output:</strong> <span class="example-io">2</span></p>
<p><strong>Explanation:</strong></p>
<p>Player 0 and player 1 win the game, while players 2 and 3 do not win.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 5, pick = [[1,1],[1,2],[1,3],[1,4]]</span></p>
<p><strong>Output:</strong> <span class="example-io">0</span></p>
<p><strong>Explanation:</strong></p>
<p>No player wins the game.</p>
</div>
<p><strong class="example">Example 3:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 5, pick = [[1,1],[2,4],[2,4],[2,4]]</span></p>
<p><strong>Output:</strong> <span class="example-io">1</span></p>
<p><strong>Explanation:</strong></p>
<p>Player 2 wins the game by picking 3 balls with color 4.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>2 &lt;= n &lt;= 10</code></li>
<li><code>1 &lt;= pick.length &lt;= 100</code></li>
<li><code>pick[i].length == 2</code></li>
<li><code>0 &lt;= x<sub>i</sub> &lt;= n - 1 </code></li>
<li><code>0 &lt;= y<sub>i</sub> &lt;= 10</code></li>
</ul>

Some files were not shown because too many files have changed in this diff Show More