mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-10-21 21:16:45 +08:00
update
This commit is contained in:
@@ -12,12 +12,12 @@
|
||||
"translatedContent": "<p>表:<code>ProductPurchases</code></p>\n\n<pre>\n+-------------+------+\n| Column Name | Type | \n+-------------+------+\n| user_id | int |\n| product_id | int |\n| quantity | int |\n+-------------+------+\n(user_id, product_id) 是这张表的唯一主键。\n每一行代表用户以特定数量购买的产品。\n</pre>\n\n<p>表:<code>ProductInfo</code></p>\n\n<pre>\n+-------------+---------+\n| Column Name | Type | \n+-------------+---------+\n| product_id | int |\n| category | varchar |\n| price | decimal |\n+-------------+---------+\nproduct_id 是这张表的唯一主键。\n每一行表示一个产品的类别和价格。\n</pre>\n\n<p>亚马逊希望根据 <strong>共同购买模式</strong> 实现 “<strong>购买此商品的用户还购买了...</strong>” 功能。编写一个解决方案以实现:</p>\n\n<ol>\n\t<li>识别 <strong>被同一客户一起频繁购买的</strong> <strong>不同</strong> 产品对(其中 <code>product1_id</code> < <code>product2_id</code>)</li>\n\t<li>对于 <strong>每个产品对</strong>,确定有多少客户购买了这两种产品</li>\n</ol>\n\n<p>如果 <strong>至少有</strong> <code>3</code> <strong>位不同的</strong> 客户同时购买了这两种产品,则认为该 <strong>产品对 </strong>适合推荐。</p>\n\n<p>返回结果表以<em> </em><strong>customer_count</strong> <strong>降序 </strong>排序,并且为了避免排序持平,以 <code>product1_id</code><em> </em><strong>升序 </strong>排序,并以<em> </em><code>product2_id</code><em> </em><strong>升序 </strong>排序。</p>\n\n<p>结果格式如下所示。</p>\n\n<p> </p>\n\n<p><strong class=\"example\">示例:</strong></p>\n\n<div class=\"example-block\">\n<p><strong>输入:</strong></p>\n\n<p>ProductPurchases 表:</p>\n\n<pre class=\"example-io\">\n+---------+------------+----------+\n| user_id | product_id | quantity |\n+---------+------------+----------+\n| 1 | 101 | 2 |\n| 1 | 102 | 1 |\n| 1 | 103 | 3 |\n| 2 | 101 | 1 |\n| 2 | 102 | 5 |\n| 2 | 104 | 1 |\n| 3 | 101 | 2 |\n| 3 | 103 | 1 |\n| 3 | 105 | 4 |\n| 4 | 101 | 1 |\n| 4 | 102 | 1 |\n| 4 | 103 | 2 |\n| 4 | 104 | 3 |\n| 5 | 102 | 2 |\n| 5 | 104 | 1 |\n+---------+------------+----------+\n</pre>\n\n<p>ProductInfo 表:</p>\n\n<pre class=\"example-io\">\n+------------+-------------+-------+\n| product_id | category | price |\n+------------+-------------+-------+\n| 101 | Electronics | 100 |\n| 102 | Books | 20 |\n| 103 | Clothing | 35 |\n| 104 | Kitchen | 50 |\n| 105 | Sports | 75 |\n+------------+-------------+-------+\n</pre>\n\n<p><strong>输出:</strong></p>\n\n<pre class=\"example-io\">\n+-------------+-------------+-------------------+-------------------+----------------+\n| product1_id | product2_id | product1_category | product2_category | customer_count |\n+-------------+-------------+-------------------+-------------------+----------------+\n| 101 | 102 | Electronics | Books | 3 |\n| 101 | 103 | Electronics | Clothing | 3 |\n| 102 | 104 | Books | Kitchen | 3 |\n+-------------+-------------+-------------------+-------------------+----------------+\n</pre>\n\n<p><strong>解释:</strong></p>\n\n<ul>\n\t<li><strong>产品对 (101, 102):</strong>\n\n\t<ul>\n\t\t<li>被用户 1,2 和 4 购买(3 个消费者)</li>\n\t\t<li>产品 101 属于电子商品类别</li>\n\t\t<li>产品 102 属于图书类别</li>\n\t</ul>\n\t</li>\n\t<li><strong>产品对 (101, 103):</strong>\n\t<ul>\n\t\t<li>被用户 1,3 和 4 购买(3 个消费者)</li>\n\t\t<li>产品 101 属于电子商品类别</li>\n\t\t<li>产品 103 属于服装类别</li>\n\t</ul>\n\t</li>\n\t<li><strong>产品对 (102, 104):</strong>\n\t<ul>\n\t\t<li>被用户 2,4 和 5 购买(3 个消费者)</li>\n\t\t<li>产品 102 属于图书类别</li>\n\t\t<li>产品 104 属于厨房用品类别</li>\n\t</ul>\n\t</li>\n</ul>\n\n<p>结果以 customer_count 降序排序。对于有相同 customer_count 的产品对,将它们以 product1_id 升序排序,然后以 product2_id 升序排序。</p>\n</div>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Medium",
|
||||
"likes": 1,
|
||||
"likes": 3,
|
||||
"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}",
|
||||
"langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python3\": false, \"python\": false, \"javascript\": false, \"typescript\": false, \"csharp\": false, \"c\": false, \"golang\": false, \"kotlin\": false, \"swift\": false, \"rust\": false, \"ruby\": false, \"php\": false, \"dart\": false, \"scala\": false, \"elixir\": false, \"erlang\": false, \"racket\": false, \"cangjie\": false, \"bash\": false, \"html\": false, \"pythonml\": false, \"react\": false, \"vanillajs\": false, \"mysql\": false, \"mssql\": false, \"postgresql\": false, \"oraclesql\": false, \"pythondata\": false}",
|
||||
"topicTags": [
|
||||
{
|
||||
"name": "Database",
|
||||
@@ -40,6 +40,12 @@
|
||||
"code": "/* Write your T-SQL query statement below */",
|
||||
"__typename": "CodeSnippetNode"
|
||||
},
|
||||
{
|
||||
"lang": "PostgreSQL",
|
||||
"langSlug": "postgresql",
|
||||
"code": "-- Write your PostgreSQL query statement below",
|
||||
"__typename": "CodeSnippetNode"
|
||||
},
|
||||
{
|
||||
"lang": "Oracle",
|
||||
"langSlug": "oraclesql",
|
||||
@@ -51,15 +57,9 @@
|
||||
"langSlug": "pythondata",
|
||||
"code": "import pandas as pd\n\ndef find_product_recommendation_pairs(product_purchases: pd.DataFrame, product_info: pd.DataFrame) -> pd.DataFrame:\n ",
|
||||
"__typename": "CodeSnippetNode"
|
||||
},
|
||||
{
|
||||
"lang": "PostgreSQL",
|
||||
"langSlug": "postgresql",
|
||||
"code": "-- Write your PostgreSQL query statement below",
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"172\", \"totalSubmission\": \"231\", \"totalAcceptedRaw\": 172, \"totalSubmissionRaw\": 231, \"acRate\": \"74.5%\"}",
|
||||
"stats": "{\"totalAccepted\": \"1.4K\", \"totalSubmission\": \"2.4K\", \"totalAcceptedRaw\": 1444, \"totalSubmissionRaw\": 2410, \"acRate\": \"59.9%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
|
Reference in New Issue
Block a user