1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-07 00:11:41 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

存量题库数据更新

This commit is contained in:
2023-12-09 18:42:21 +08:00
parent a788808cd7
commit c198538f10
10843 changed files with 288489 additions and 248355 deletions

View File

@@ -7,17 +7,17 @@
"boundTopicId": 172858,
"title": "Capital Gain/Loss",
"titleSlug": "capital-gainloss",
"content": "<p>Table: <code>Stocks</code></p>\n\n<pre>\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| stock_name | varchar |\n| operation | enum |\n| operation_day | int |\n| price | int |\n+---------------+---------+\n(stock_name, operation_day) is the primary key for this table.\nThe operation column is an ENUM of type (&#39;Sell&#39;, &#39;Buy&#39;)\nEach row of this table indicates that the stock which has stock_name had an operation on the day operation_day with the price.\nIt is guaranteed that each &#39;Sell&#39; operation for a stock has a corresponding &#39;Buy&#39; operation in a previous day. It is also guaranteed that each &#39;Buy&#39; operation for a stock has a corresponding &#39;Sell&#39; operation in an upcoming day.\n</pre>\n\n<p>&nbsp;</p>\n\n<p>Write an SQL query to report the <strong>Capital gain/loss</strong> for each stock.</p>\n\n<p>The <strong>Capital gain/loss</strong> of a stock is the total gain or loss after buying and selling the stock one or many times.</p>\n\n<p>Return the result table in <strong>any order</strong>.</p>\n\n<p>The query result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong>Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \nStocks table:\n+---------------+-----------+---------------+--------+\n| stock_name | operation | operation_day | price |\n+---------------+-----------+---------------+--------+\n| Leetcode | Buy | 1 | 1000 |\n| Corona Masks | Buy | 2 | 10 |\n| Leetcode | Sell | 5 | 9000 |\n| Handbags | Buy | 17 | 30000 |\n| Corona Masks | Sell | 3 | 1010 |\n| Corona Masks | Buy | 4 | 1000 |\n| Corona Masks | Sell | 5 | 500 |\n| Corona Masks | Buy | 6 | 1000 |\n| Handbags | Sell | 29 | 7000 |\n| Corona Masks | Sell | 10 | 10000 |\n+---------------+-----------+---------------+--------+\n<strong>Output:</strong> \n+---------------+-------------------+\n| stock_name | capital_gain_loss |\n+---------------+-------------------+\n| Corona Masks | 9500 |\n| Leetcode | 8000 |\n| Handbags | -23000 |\n+---------------+-------------------+\n<strong>Explanation:</strong> \nLeetcode stock was bought at day 1 for 1000$ and was sold at day 5 for 9000$. Capital gain = 9000 - 1000 = 8000$.\nHandbags stock was bought at day 17 for 30000$ and was sold at day 29 for 7000$. Capital loss = 7000 - 30000 = -23000$.\nCorona Masks stock was bought at day 1 for 10$ and was sold at day 3 for 1010$. It was bought again at day 4 for 1000$ and was sold at day 5 for 500$. At last, it was bought at day 6 for 1000$ and was sold at day 10 for 10000$. Capital gain/loss is the sum of capital gains/losses for each (&#39;Buy&#39; --&gt; &#39;Sell&#39;) operation = (1010 - 10) + (500 - 1000) + (10000 - 1000) = 1000 - 500 + 9000 = 9500$.\n</pre>\n",
"content": "<p>Table: <code>Stocks</code></p>\n\n<pre>\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| stock_name | varchar |\n| operation | enum |\n| operation_day | int |\n| price | int |\n+---------------+---------+\n(stock_name, operation_day) is the primary key (combination of columns with unique values) for this table.\nThe operation column is an ENUM (category) of type (&#39;Sell&#39;, &#39;Buy&#39;)\nEach row of this table indicates that the stock which has stock_name had an operation on the day operation_day with the price.\nIt is guaranteed that each &#39;Sell&#39; operation for a stock has a corresponding &#39;Buy&#39; operation in a previous day. It is also guaranteed that each &#39;Buy&#39; operation for a stock has a corresponding &#39;Sell&#39; operation in an upcoming day.\n</pre>\n\n<p>&nbsp;</p>\n\n<p>Write a solution to report the <strong>Capital gain/loss</strong> for each stock.</p>\n\n<p>The <strong>Capital gain/loss</strong> of a stock is the total gain or loss after buying and selling the stock one or many times.</p>\n\n<p>Return the result table in <strong>any order</strong>.</p>\n\n<p>The&nbsp;result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \nStocks table:\n+---------------+-----------+---------------+--------+\n| stock_name | operation | operation_day | price |\n+---------------+-----------+---------------+--------+\n| Leetcode | Buy | 1 | 1000 |\n| Corona Masks | Buy | 2 | 10 |\n| Leetcode | Sell | 5 | 9000 |\n| Handbags | Buy | 17 | 30000 |\n| Corona Masks | Sell | 3 | 1010 |\n| Corona Masks | Buy | 4 | 1000 |\n| Corona Masks | Sell | 5 | 500 |\n| Corona Masks | Buy | 6 | 1000 |\n| Handbags | Sell | 29 | 7000 |\n| Corona Masks | Sell | 10 | 10000 |\n+---------------+-----------+---------------+--------+\n<strong>Output:</strong> \n+---------------+-------------------+\n| stock_name | capital_gain_loss |\n+---------------+-------------------+\n| Corona Masks | 9500 |\n| Leetcode | 8000 |\n| Handbags | -23000 |\n+---------------+-------------------+\n<strong>Explanation:</strong> \nLeetcode stock was bought at day 1 for 1000$ and was sold at day 5 for 9000$. Capital gain = 9000 - 1000 = 8000$.\nHandbags stock was bought at day 17 for 30000$ and was sold at day 29 for 7000$. Capital loss = 7000 - 30000 = -23000$.\nCorona Masks stock was bought at day 1 for 10$ and was sold at day 3 for 1010$. It was bought again at day 4 for 1000$ and was sold at day 5 for 500$. At last, it was bought at day 6 for 1000$ and was sold at day 10 for 10000$. Capital gain/loss is the sum of capital gains/losses for each (&#39;Buy&#39; --&gt; &#39;Sell&#39;) operation = (1010 - 10) + (500 - 1000) + (10000 - 1000) = 1000 - 500 + 9000 = 9500$.\n</pre>\n",
"translatedTitle": "股票的资本损益",
"translatedContent": "<p><code>Stocks</code>&nbsp;表:</p>\n\n<pre>+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| stock_name | varchar |\n| operation | enum |\n| operation_day | int |\n| price | int |\n+---------------+---------+\n(stock_name, day) 是这张表的主键\noperation 列使用的是一种枚举类型,包括:(&#39;Sell&#39;,&#39;Buy&#39;)\n此表的每一行代表了名为 stock_name 的某支股票在 operation_day 这一天的操作价格。\n保证股票的每次&#39;Sell&#39;操作前,都有相应的&#39;Buy&#39;操作。\n</pre>\n\n<p>&nbsp;</p>\n\n<p>编写一个SQL查询来报告每股票的资本损益。</p>\n\n<p>股票的资本损益是一次或多次买卖股票后的全部收益或损失。</p>\n\n<p>以任意顺序返回结果即可。</p>\n\n<p>SQL查询结果格式如下所示</p>\n\n<pre><code>Stocks</code> 表:\n+---------------+-----------+---------------+--------+\n| stock_name | operation | operation_day | price |\n+---------------+-----------+---------------+--------+\n| Leetcode | Buy | 1 | 1000 |\n| Corona Masks | Buy | 2 | 10 |\n| Leetcode | Sell | 5 | 9000 |\n| Handbags | Buy | 17 | 30000 |\n| Corona Masks | Sell | 3 | 1010 |\n| Corona Masks | Buy | 4 | 1000 |\n| Corona Masks | Sell | 5 | 500 |\n| Corona Masks | Buy | 6 | 1000 |\n| Handbags | Sell | 29 | 7000 |\n| Corona Masks | Sell | 10 | 10000 |\n+---------------+-----------+---------------+--------+\n\nResult 表:\n+---------------+-------------------+\n| stock_name | capital_gain_loss |\n+---------------+-------------------+\n| Corona Masks | 9500 |\n| Leetcode | 8000 |\n| Handbags | -23000 |\n+---------------+-------------------+\nLeetcode 股票在第一天以1000美元的价格买入在第五天以9000美元的价格卖出。资本收益=9000-1000=8000美元。\nHandbags 股票在第17天以30000美元的价格买入在第29天以7000美元的价格卖出。资本损失=7000-30000=-23000美元。\nCorona Masks 股票在第1天以10美元的价格买入在第3天以1010美元的价格卖出。在第4天以1000美元的价格再次购买在第5天以500美元的价格出售。最后它在第6天以1000美元的价格被买走在第10天以10000美元的价格被卖掉。资本损益是每次&rsquo;Buy&#39;-&gt;&#39;Sell&#39;)操作资本收益或损失的和=1010-10+500-1000+10000-1000=1000-500+9000=9500美元。\n</pre>\n",
"translatedContent": "<p><code>Stocks</code>&nbsp;表:</p>\n\n<pre>\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| stock_name | varchar |\n| operation | enum |\n| operation_day | int |\n| price | int |\n+---------------+---------+\n(stock_name, day) 是这张表的主键(具有唯一值的列的组合)\noperation 列使用的是一种枚举类型,包括:('Sell','Buy')\n此表的每一行代表了名为 stock_name 的某支股票在 operation_day 这一天的操作价格。\n此表可以保证股票的每个“卖出”操作在前一天都有相应的“买入”操作。并且,股票的每个“买入”操作在即将到来的一天都有相应的“卖出”操作。\n</pre>\n\n<p>&nbsp;</p>\n\n<p>编写解决方案报告每股票的 <strong>资本损益</strong>。</p>\n\n<p>股票的&nbsp;<strong>资本利得/损失&nbsp;</strong>是指一次或多次买卖股票后的收益或损失。</p>\n\n<p>以 <strong>任意顺序</strong> 返回结果。</p>\n\n<p>结果格式如下所示。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<code><strong>输入:</strong>\nStocks</code> 表:\n+---------------+-----------+---------------+--------+\n| stock_name | operation | operation_day | price |\n+---------------+-----------+---------------+--------+\n| Leetcode | Buy | 1 | 1000 |\n| Corona Masks | Buy | 2 | 10 |\n| Leetcode | Sell | 5 | 9000 |\n| Handbags | Buy | 17 | 30000 |\n| Corona Masks | Sell | 3 | 1010 |\n| Corona Masks | Buy | 4 | 1000 |\n| Corona Masks | Sell | 5 | 500 |\n| Corona Masks | Buy | 6 | 1000 |\n| Handbags | Sell | 29 | 7000 |\n| Corona Masks | Sell | 10 | 10000 |\n+---------------+-----------+---------------+--------+\n<strong>输出:</strong>\n+---------------+-------------------+\n| stock_name | capital_gain_loss |\n+---------------+-------------------+\n| Corona Masks | 9500 |\n| Leetcode | 8000 |\n| Handbags | -23000 |\n+---------------+-------------------+\n<strong>解释:</strong>\nLeetcode 股票在第一天以1000美元的价格买入在第五天以9000美元的价格卖出。资本收益=9000-1000=8000美元。\nHandbags 股票在第17天以30000美元的价格买入在第29天以7000美元的价格卖出。资本损失=7000-30000=-23000美元。\nCorona Masks 股票在第1天以10美元的价格买入在第3天以1010美元的价格卖出。在第4天以1000美元的价格再次购买在第5天以500美元的价格出售。最后它在第6天以1000美元的价格被买走在第10天以10000美元的价格被卖掉。资本损益是每次Buy'-&gt;'Sell')操作资本收益或损失的和=1010-10+500-1000+10000-1000=1000-500+9000=9500美元。\n</pre>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 21,
"likes": 79,
"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, \"ruby\": false, \"bash\": false, \"swift\": false, \"golang\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"kotlin\": false, \"rust\": false, \"php\": false, \"typescript\": false, \"racket\": false, \"erlang\": false, \"elixir\": false}",
"langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}",
"topicTags": [
{
"name": "Database",
@@ -45,14 +45,26 @@
"langSlug": "oraclesql",
"code": "/* Write your PL/SQL query statement below */",
"__typename": "CodeSnippetNode"
},
{
"lang": "Pandas",
"langSlug": "pythondata",
"code": "import pandas as pd\n\ndef capital_gainloss(stocks: pd.DataFrame) -> pd.DataFrame:\n ",
"__typename": "CodeSnippetNode"
},
{
"lang": "PostgreSQL",
"langSlug": "postgresql",
"code": "-- Write your PostgreSQL query statement below",
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"7.3K\", \"totalSubmission\": \"8.6K\", \"totalAcceptedRaw\": 7326, \"totalSubmissionRaw\": 8615, \"acRate\": \"85.0%\"}",
"stats": "{\"totalAccepted\": \"33.7K\", \"totalSubmission\": \"40.4K\", \"totalAcceptedRaw\": 33680, \"totalSubmissionRaw\": 40370, \"acRate\": \"83.4%\"}",
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "{\"headers\":{\"Stocks\":[\"stock_name\",\"operation\",\"operation_day\",\"price\"]},\"rows\":{\"Stocks\":[[\"Leetcode\",\"Buy\",1,1000],[\"Corona Masks\",\"Buy\",2,10],[\"Leetcode\",\"Sell\",5,9000],[\"Handbags\",\"Buy\",17,30000],[\"Corona Masks\",\"Sell\",3,1010],[\"Corona Masks\",\"Buy\",4,1000],[\"Corona Masks\",\"Sell\",5,500],[\"Corona Masks\",\"Buy\",6,1000],[\"Handbags\",\"Sell\",29,7000],[\"Corona Masks\",\"Sell\",10,10000]]}}",
"metaData": "{\n \"mysql\": [\n \"Create Table If Not Exists Stocks (stock_name varchar(15), operation ENUM('Sell', 'Buy'), operation_day int, price int)\"\n ],\n \"mssql\": [\n \"Create Table Stocks (stock_name varchar(15), operation VARCHAR(10) NOT NULL CHECK (operation IN ('Sell', 'Buy')), operation_day int, price int)\"\n ],\n \"oraclesql\": [\n \"Create Table Stocks (stock_name varchar(15), operation VARCHAR(10) NOT NULL CHECK (operation IN ('Sell', 'Buy')), operation_day int, price int)\"\n ],\n \"database\": true\n}",
"metaData": "{\"mysql\":[\"Create Table If Not Exists Stocks (stock_name varchar(15), operation ENUM('Sell', 'Buy'), operation_day int, price int)\"],\"mssql\":[\"Create Table Stocks (stock_name varchar(15), operation VARCHAR(10) NOT NULL CHECK (operation IN ('Sell', 'Buy')), operation_day int, price int)\"],\"oraclesql\":[\"Create Table Stocks (stock_name varchar(15), operation VARCHAR(10) NOT NULL CHECK (operation IN ('Sell', 'Buy')), operation_day int, price int)\"],\"database\":true,\"name\":\"capital_gainloss\",\"pythondata\":[\"Stocks = pd.DataFrame([], columns=['stock_name', 'operation', 'operation_day', 'price']).astype({'stock_name':'object', 'operation':'object', 'operation_day':'Int64', 'price':'Int64'})\"],\"postgresql\":[\"Create Table If Not Exists Stocks (stock_name varchar(15), operation VARCHAR(30) CHECK (operation IN ('Sell', 'Buy')), operation_day int, price int)\\n\"],\"database_schema\":{\"Stocks\":{\"stock_name\":\"VARCHAR(15)\",\"operation\":\"ENUM('Sell', 'Buy')\",\"operation_day\":\"INT\",\"price\":\"INT\"}}}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [
@@ -70,7 +82,7 @@
"insert into Stocks (stock_name, operation, operation_day, price) values ('Corona Masks', 'Sell', '10', '10000')"
],
"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>\"]}",
"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,