1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-05 23:41:41 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
Files
leetcode-problemset/leetcode-cn/originData/find-invalid-ip-addresses.json
2025-02-22 16:46:22 +08:00

94 lines
10 KiB
JSON
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
"data": {
"question": {
"questionId": "3792",
"questionFrontendId": "3451",
"categoryTitle": "Database",
"boundTopicId": 3073058,
"title": "Find Invalid IP Addresses",
"titleSlug": "find-invalid-ip-addresses",
"content": "<p>Table: <code> logs</code></p>\n\n<pre>\n+-------------+---------+\n| Column Name | Type |\n+-------------+---------+\n| log_id | int |\n| ip | varchar |\n| status_code | int |\n+-------------+---------+\nlog_id is the unique key for this table.\nEach row contains server access log information including IP address and HTTP status code.\n</pre>\n\n<p>Write a solution to find <strong>invalid IP addresses</strong>. An IPv4 address is invalid if it meets any of these conditions:</p>\n\n<ul>\n\t<li>Contains numbers <strong>greater than</strong> <code>255</code> in any octet</li>\n\t<li>Has <strong>leading zeros</strong> in any octet (like <code>01.02.03.04</code>)</li>\n\t<li>Has <strong>less or more</strong> than <code>4</code> octets</li>\n</ul>\n\n<p>Return <em>the result table </em><em>ordered by</em> <code>invalid_count</code>,&nbsp;<code>ip</code>&nbsp;<em>in <strong>descending</strong> order respectively</em>.&nbsp;</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>logs table:</p>\n\n<pre class=\"example-io\">\n+--------+---------------+-------------+\n| log_id | ip | status_code | \n+--------+---------------+-------------+\n| 1 | 192.168.1.1 | 200 | \n| 2 | 256.1.2.3 | 404 | \n| 3 | 192.168.001.1 | 200 | \n| 4 | 192.168.1.1 | 200 | \n| 5 | 192.168.1 | 500 | \n| 6 | 256.1.2.3 | 404 | \n| 7 | 192.168.001.1 | 200 | \n+--------+---------------+-------------+\n</pre>\n\n<p><strong>Output:</strong></p>\n\n<pre class=\"example-io\">\n+---------------+--------------+\n| ip | invalid_count|\n+---------------+--------------+\n| 256.1.2.3 | 2 |\n| 192.168.001.1 | 2 |\n| 192.168.1 | 1 |\n+---------------+--------------+\n</pre>\n\n<p><strong>Explanation:</strong></p>\n\n<ul>\n\t<li>256.1.2.3&nbsp;is invalid because 256 &gt; 255</li>\n\t<li>192.168.001.1&nbsp;is invalid because of leading zeros</li>\n\t<li>192.168.1&nbsp;is invalid because it has only 3 octets</li>\n</ul>\n\n<p>The output table is ordered by invalid_count, ip in descending order respectively.</p>\n</div>\n",
"translatedTitle": "查找无效的 IP 地址",
"translatedContent": "<p>表:<code>logs</code></p>\n\n<pre>\n+-------------+---------+\n| Column Name | Type |\n+-------------+---------+\n| log_id | int |\n| ip | varchar |\n| status_code | int |\n+-------------+---------+\nlog_id 是这张表的唯一主键。\n每一行包含服务器访问日志信息包括 IP 地址和 HTTP 状态码。\n</pre>\n\n<p>编写一个解决方案来查找 <strong>无效的 IP 地址</strong>。一个 IPv4 地址如果满足以下任何条件之一,则无效:</p>\n\n<ul>\n\t<li>任何 8 位字节中包含大于 255 的数字</li>\n\t<li>任何 8 位字节中含有 <strong>前导零</strong>(如&nbsp;<code>01.02.03.04</code></li>\n\t<li><strong>少于或多于</strong>&nbsp;<code>4</code>&nbsp;个 8 位字节</li>\n</ul>\n\n<p>返回结果表分别以&nbsp;<code>invalid_count</code><code>ip</code>&nbsp;<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><strong>输入:</strong></p>\n\n<p>logs 表:</p>\n\n<pre class=\"example-io\">\n+--------+---------------+-------------+\n| log_id | ip | status_code | \n+--------+---------------+-------------+\n| 1 | 192.168.1.1 | 200 | \n| 2 | 256.1.2.3 | 404 | \n| 3 | 192.168.001.1 | 200 | \n| 4 | 192.168.1.1 | 200 | \n| 5 | 192.168.1 | 500 | \n| 6 | 256.1.2.3 | 404 | \n| 7 | 192.168.001.1 | 200 | \n+--------+---------------+-------------+\n</pre>\n\n<p><strong>输出:</strong></p>\n\n<pre class=\"example-io\">\n+---------------+--------------+\n| ip | invalid_count|\n+---------------+--------------+\n| 256.1.2.3 | 2 |\n| 192.168.001.1 | 2 |\n| 192.168.1 | 1 |\n+---------------+--------------+\n</pre>\n\n<p><strong>解释:</strong></p>\n\n<ul>\n\t<li>256.1.2.3 是无效的,因为&nbsp;256 &gt; 255</li>\n\t<li>192.168.001.1 是无效的,因为有前导零</li>\n\t<li>192.168.1 是非法的,因为只有 3 个 8 位字节</li>\n</ul>\n\n<p>输出表分别以&nbsp;<code>invalid_count</code><code>ip</code>&nbsp;降序排序。</p>\n</div>\n",
"isPaidOnly": false,
"difficulty": "Hard",
"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 find_invalid_ips(logs: pd.DataFrame) -> pd.DataFrame:\n ",
"__typename": "CodeSnippetNode"
},
{
"lang": "PostgreSQL",
"langSlug": "postgresql",
"code": "-- Write your PostgreSQL query statement below",
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"114\", \"totalSubmission\": \"181\", \"totalAcceptedRaw\": 114, \"totalSubmissionRaw\": 181, \"acRate\": \"63.0%\"}",
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "{\"headers\":{\"logs\":[\"log_id\",\"ip\",\"status_code\"]},\"rows\":{\"logs\":[[1,\"192.168.1.1\",200],[2,\"256.1.2.3\",404],[3,\"192.168.001.1\",200],[4,\"192.168.1.1\",200],[5,\"192.168.1\",500],[6,\"256.1.2.3\",404],[7,\"192.168.001.1\",200]]}}",
"metaData": "{\"mysql\":[\"CREATE TABLE logs (\\n log_id INT,\\n ip VARCHAR(255),\\n status_code INT\\n)\\n\"],\"mssql\":[\"CREATE TABLE logs (\\n log_id INT,\\n ip VARCHAR(255),\\n status_code INT\\n)\\n\"],\"oraclesql\":[\"CREATE TABLE logs (\\n log_id NUMBER,\\n ip VARCHAR2(255),\\n status_code NUMBER\\n)\\n\"],\"database\":true,\"name\":\"find_invalid_ips\",\"postgresql\":[\"CREATE TABLE logs (\\n log_id INTEGER,\\n ip VARCHAR(255), \\n status_code INTEGER \\n);\"],\"pythondata\":[\"logs = pd.DataFrame(columns=[\\\"log_id\\\", \\\"ip\\\", \\\"status_code\\\"]).astype({\\\"log_id\\\": \\\"Int64\\\", \\\"ip\\\": \\\"string\\\", \\\"status_code\\\": \\\"Int64\\\"})\\n\"],\"database_schema\":{\"logs\":{\"log_id\":\"INT\",\"ip\":\"VARCHAR(255)\",\"status_code\":\"INT\"}}}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [
"CREATE TABLE logs (\n log_id INT,\n ip VARCHAR(255),\n status_code INT\n)\n",
"Truncate table logs",
"insert into logs (log_id, ip, status_code) values ('1', '192.168.1.1', '200')",
"insert into logs (log_id, ip, status_code) values ('2', '256.1.2.3', '404')",
"insert into logs (log_id, ip, status_code) values ('3', '192.168.001.1', '200')",
"insert into logs (log_id, ip, status_code) values ('4', '192.168.1.1', '200')",
"insert into logs (log_id, ip, status_code) values ('5', '192.168.1', '500')",
"insert into logs (log_id, ip, status_code) values ('6', '256.1.2.3', '404')",
"insert into logs (log_id, ip, status_code) values ('7', '192.168.001.1', '200')"
],
"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\":{\"logs\":[\"log_id\",\"ip\",\"status_code\"]},\"rows\":{\"logs\":[[1,\"192.168.1.1\",200],[2,\"256.1.2.3\",404],[3,\"192.168.001.1\",200],[4,\"192.168.1.1\",200],[5,\"192.168.1\",500],[6,\"256.1.2.3\",404],[7,\"192.168.001.1\",200]]}}",
"__typename": "QuestionNode"
}
}
}