mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-05 23:41:41 +08:00
92 lines
13 KiB
JSON
92 lines
13 KiB
JSON
{
|
||
"data": {
|
||
"question": {
|
||
"questionId": "3803",
|
||
"questionFrontendId": "3465",
|
||
"categoryTitle": "Database",
|
||
"boundTopicId": 3087164,
|
||
"title": "Find Products with Valid Serial Numbers",
|
||
"titleSlug": "find-products-with-valid-serial-numbers",
|
||
"content": "<p>Table: <code>products</code></p>\n\n<pre>\n+--------------+------------+\n| Column Name | Type |\n+--------------+------------+\n| product_id | int |\n| product_name | varchar |\n| description | varchar |\n+--------------+------------+\n(product_id) is the unique key for this table.\nEach row in the table represents a product with its unique ID, name, and description.\n</pre>\n\n<p>Write a solution to find all products whose description <strong>contains a valid serial number</strong> pattern. A valid serial number follows these rules:</p>\n\n<ul>\n\t<li>It starts with the letters <strong>SN</strong> (case-sensitive).</li>\n\t<li>Followed by exactly <code>4</code> digits.</li>\n\t<li>It must have a hyphen (-) <strong>followed by exactly</strong> <code>4</code> digits.</li>\n\t<li>The serial number must be within the description (it may not necessarily start at the beginning).</li>\n</ul>\n\n<p>Return <em>the result table ordered by</em> <code>product_id</code> <em>in <strong>ascending</strong> order</em>.</p>\n\n<p>The result format is in the following example.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example:</strong></p>\n\n<div class=\"example-block\">\n<p><strong>Input:</strong></p>\n\n<p>products table:</p>\n\n<pre class=\"example-io\">\n+------------+--------------+------------------------------------------------------+\n| product_id | product_name | description |\n+------------+--------------+------------------------------------------------------+\n| 1 | Widget A | This is a sample product with SN1234-5678 |\n| 2 | Widget B | A product with serial SN9876-1234 in the description |\n| 3 | Widget C | Product SN1234-56789 is available now |\n| 4 | Widget D | No serial number here |\n| 5 | Widget E | Check out SN4321-8765 in this description |\n+------------+--------------+------------------------------------------------------+\n </pre>\n\n<p><strong>Output:</strong></p>\n\n<pre class=\"example-io\">\n+------------+--------------+------------------------------------------------------+\n| product_id | product_name | description |\n+------------+--------------+------------------------------------------------------+\n| 1 | Widget A | This is a sample product with SN1234-5678 |\n| 2 | Widget B | A product with serial SN9876-1234 in the description |\n| 5 | Widget E | Check out SN4321-8765 in this description |\n+------------+--------------+------------------------------------------------------+\n </pre>\n\n<p><strong>Explanation:</strong></p>\n\n<ul>\n\t<li><strong>Product 1:</strong> Valid serial number SN1234-5678</li>\n\t<li><strong>Product 2:</strong> Valid serial number SN9876-1234</li>\n\t<li><strong>Product 3:</strong> Invalid serial number SN1234-56789 (contains 5 digits after the hyphen)</li>\n\t<li><strong>Product 4:</strong> No serial number in the description</li>\n\t<li><strong>Product 5:</strong> Valid serial number SN4321-8765</li>\n</ul>\n\n<p>The result table is ordered by product_id in ascending order.</p>\n</div>\n",
|
||
"translatedTitle": "查找具有有效序列号的产品",
|
||
"translatedContent": "<p>表:<code>products</code></p>\n\n<pre>\n+--------------+------------+\n| Column Name | Type |\n+--------------+------------+\n| product_id | int |\n| product_name | varchar |\n| description | varchar |\n+--------------+------------+\n(product_id) 是这张表的唯一主键。\n这张表的每一行表示一个产品的唯一 ID,名字和描述。\n</pre>\n\n<p>编写一个解决方案来找到所有描述中 <strong>包含一个有效序列号</strong> 模式的产品。一个有效序列号符合下述规则:</p>\n\n<ul>\n\t<li>以 <strong>SN </strong>字母开头(区分大小写)。</li>\n\t<li>后面有恰好 <code>4</code> 位数字。</li>\n\t<li>接着是一个短横(-), 短横后面还有另一组 <code>4</code> <strong>位数字</strong></li>\n\t<li>序列号必须在描述内(可能不在描述的开头)</li>\n</ul>\n\n<p>返回结果表以 <code>product_id</code> <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>products 表:</p>\n\n<pre class=\"example-io\">\n+------------+--------------+------------------------------------------------------+\n| product_id | product_name | description |\n+------------+--------------+------------------------------------------------------+\n| 1 | Widget A | This is a sample product with SN1234-5678 |\n| 2 | Widget B | A product with serial SN9876-1234 in the description |\n| 3 | Widget C | Product SN1234-56789 is available now |\n| 4 | Widget D | No serial number here |\n| 5 | Widget E | Check out SN4321-8765 in this description |\n+------------+--------------+------------------------------------------------------+\n </pre>\n\n<p><strong>输出:</strong></p>\n\n<pre class=\"example-io\">\n+------------+--------------+------------------------------------------------------+\n| product_id | product_name | description |\n+------------+--------------+------------------------------------------------------+\n| 1 | Widget A | This is a sample product with SN1234-5678 |\n| 2 | Widget B | A product with serial SN9876-1234 in the description |\n| 5 | Widget E | Check out SN4321-8765 in this description |\n+------------+--------------+------------------------------------------------------+\n </pre>\n\n<p><strong>解释:</strong></p>\n\n<ul>\n\t<li><strong>产品 1:</strong>有效的序列号 SN1234-5678</li>\n\t<li><strong>产品 2:</strong>有效的序列号 SN9876-1234</li>\n\t<li><strong>产品 3:</strong>无效的序列号 SN1234-56789(短横后包含 5 位数字)</li>\n\t<li><strong>产品 4:</strong>描述中没有序列号</li>\n\t<li><strong>产品 5:</strong>有效的序列号 SN4321-8765</li>\n</ul>\n\n<p>结果表以 product_id 升序排序。</p>\n</div>\n",
|
||
"isPaidOnly": false,
|
||
"difficulty": "Easy",
|
||
"likes": 1,
|
||
"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 find_valid_serial_products(products: pd.DataFrame) -> pd.DataFrame:\n ",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "PostgreSQL",
|
||
"langSlug": "postgresql",
|
||
"code": "-- Write your PostgreSQL query statement below",
|
||
"__typename": "CodeSnippetNode"
|
||
}
|
||
],
|
||
"stats": "{\"totalAccepted\": \"442\", \"totalSubmission\": \"542\", \"totalAcceptedRaw\": 442, \"totalSubmissionRaw\": 542, \"acRate\": \"81.5%\"}",
|
||
"hints": [],
|
||
"solution": null,
|
||
"status": null,
|
||
"sampleTestCase": "{\"headers\":{\"products\":[\"product_id\",\"product_name\",\"description\"]},\"rows\":{\"products\":[[1,\"Widget A\",\"This is a sample product with SN1234-5678\"],[2,\"Widget B\",\"A product with serial SN9876-1234 in the description\"],[3,\"Widget C\",\"Product SN1234-56789 is available now\"],[4,\"Widget D\",\"No serial number here\"],[5,\"Widget E\",\"Check out SN4321-8765 in this description\"]]}}",
|
||
"metaData": "{\"mysql\":[\"CREATE TABLE If not exists products (\\n product_id INT,\\n product_name VARCHAR(255),\\n description VARCHAR(255)\\n)\\n\"],\"mssql\":[\"CREATE TABLE products (\\n product_id INT,\\n product_name VARCHAR(255),\\n description VARCHAR(255)\\n)\"],\"oraclesql\":[\"CREATE TABLE products (\\n product_id NUMBER,\\n product_name VARCHAR2(255),\\n description VARCHAR2(255)\\n)\\n\"],\"database\":true,\"name\":\"find_valid_serial_products\",\"postgresql\":[\"CREATE TABLE IF NOT EXISTS products (\\n product_id SERIAL PRIMARY KEY,\\n product_name VARCHAR(255) NOT NULL,\\n description TEXT\\n);\\n\"],\"pythondata\":[\"products = pd.DataFrame(columns=['product_id', 'product_name', 'description']).astype({'product_id': 'int32', 'product_name': 'string', 'description': 'string'})\\n\"],\"database_schema\":{\"products\":{\"product_id\":\"INT\",\"product_name\":\"VARCHAR(255)\",\"description\":\"VARCHAR(255)\"}}}",
|
||
"judgerAvailable": true,
|
||
"judgeType": "large",
|
||
"mysqlSchemas": [
|
||
"CREATE TABLE If not exists products (\n product_id INT,\n product_name VARCHAR(255),\n description VARCHAR(255)\n)\n",
|
||
"Truncate table products",
|
||
"insert into products (product_id, product_name, description) values ('1', 'Widget A', 'This is a sample product with SN1234-5678')",
|
||
"insert into products (product_id, product_name, description) values ('2', 'Widget B', 'A product with serial SN9876-1234 in the description')",
|
||
"insert into products (product_id, product_name, description) values ('3', 'Widget C', 'Product SN1234-56789 is available now')",
|
||
"insert into products (product_id, product_name, description) values ('4', 'Widget D', 'No serial number here')",
|
||
"insert into products (product_id, product_name, description) values ('5', 'Widget E', 'Check out SN4321-8765 in this description')"
|
||
],
|
||
"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.2.2 and NumPy 1.26.4<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>PostgreSQL 16<\\/p>\"]}",
|
||
"book": null,
|
||
"isSubscribed": false,
|
||
"isDailyQuestion": false,
|
||
"dailyRecordStatus": null,
|
||
"editorType": "CKEDITOR",
|
||
"ugcQuestionId": null,
|
||
"style": "LEETCODE",
|
||
"exampleTestcases": "{\"headers\":{\"products\":[\"product_id\",\"product_name\",\"description\"]},\"rows\":{\"products\":[[1,\"Widget A\",\"This is a sample product with SN1234-5678\"],[2,\"Widget B\",\"A product with serial SN9876-1234 in the description\"],[3,\"Widget C\",\"Product SN1234-56789 is available now\"],[4,\"Widget D\",\"No serial number here\"],[5,\"Widget E\",\"Check out SN4321-8765 in this description\"]]}}",
|
||
"__typename": "QuestionNode"
|
||
}
|
||
}
|
||
} |