Skip to content

Commit c533c20

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents adb8056 + 19f9daa commit c533c20

File tree

2,290 files changed

+230794
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,290 files changed

+230794
-0
lines changed

算法题/01-matrix.html

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<p>Given an <code>m x n</code> binary matrix <code>mat</code>, return <em>the distance of the nearest </em><code>0</code><em> for each cell</em>.</p>
2+
3+
<p>The distance between two adjacent cells is <code>1</code>.</p>
4+
5+
<p>&nbsp;</p>
6+
<p><strong>Example 1:</strong></p>
7+
<img alt="" src="https://assets.leetcode.com/uploads/2021/04/24/01-1-grid.jpg" style="width: 253px; height: 253px;" />
8+
<pre>
9+
<strong>Input:</strong> mat = [[0,0,0],[0,1,0],[0,0,0]]
10+
<strong>Output:</strong> [[0,0,0],[0,1,0],[0,0,0]]
11+
</pre>
12+
13+
<p><strong>Example 2:</strong></p>
14+
<img alt="" src="https://assets.leetcode.com/uploads/2021/04/24/01-2-grid.jpg" style="width: 253px; height: 253px;" />
15+
<pre>
16+
<strong>Input:</strong> mat = [[0,0,0],[0,1,0],[1,1,1]]
17+
<strong>Output:</strong> [[0,0,0],[0,1,0],[1,2,1]]
18+
</pre>
19+
20+
<p>&nbsp;</p>
21+
<p><strong>Constraints:</strong></p>
22+
23+
<ul>
24+
<li><code>m == mat.length</code></li>
25+
<li><code>n == mat[i].length</code></li>
26+
<li><code>1 &lt;= m, n &lt;= 10<sup>4</sup></code></li>
27+
<li><code>1 &lt;= m * n &lt;= 10<sup>4</sup></code></li>
28+
<li><code>mat[i][j]</code> is either <code>0</code> or <code>1</code>.</li>
29+
<li>There is at least one <code>0</code> in <code>mat</code>.</li>
30+
</ul>

算法题/01-matrix.json

+184
Large diffs are not rendered by default.
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<p>We have two special characters:</p>
2+
3+
<ul>
4+
<li>The first character can be represented by one bit <code>0</code>.</li>
5+
<li>The second character can be represented by two bits (<code>10</code> or <code>11</code>).</li>
6+
</ul>
7+
8+
<p>Given a binary array <code>bits</code> that ends with <code>0</code>, return <code>true</code> if the last character must be a one-bit character.</p>
9+
10+
<p>&nbsp;</p>
11+
<p><strong>Example 1:</strong></p>
12+
13+
<pre>
14+
<strong>Input:</strong> bits = [1,0,0]
15+
<strong>Output:</strong> true
16+
<strong>Explanation:</strong> The only way to decode it is two-bit character and one-bit character.
17+
So the last character is one-bit character.
18+
</pre>
19+
20+
<p><strong>Example 2:</strong></p>
21+
22+
<pre>
23+
<strong>Input:</strong> bits = [1,1,1,0]
24+
<strong>Output:</strong> false
25+
<strong>Explanation:</strong> The only way to decode it is two-bit character and two-bit character.
26+
So the last character is not one-bit character.
27+
</pre>
28+
29+
<p>&nbsp;</p>
30+
<p><strong>Constraints:</strong></p>
31+
32+
<ul>
33+
<li><code>1 &lt;= bits.length &lt;= 1000</code></li>
34+
<li><code>bits[i]</code> is either <code>0</code> or <code>1</code>.</li>
35+
</ul>
+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
{
2+
"data": {
3+
"question": {
4+
"questionId": "717",
5+
"questionFrontendId": "717",
6+
"boundTopicId": null,
7+
"title": "1-bit and 2-bit Characters",
8+
"titleSlug": "1-bit-and-2-bit-characters",
9+
"content": "<p>We have two special characters:</p>\n\n<ul>\n\t<li>The first character can be represented by one bit <code>0</code>.</li>\n\t<li>The second character can be represented by two bits (<code>10</code> or <code>11</code>).</li>\n</ul>\n\n<p>Given a binary array <code>bits</code> that ends with <code>0</code>, return <code>true</code> if the last character must be a one-bit character.</p>\n\n<p>&nbsp;</p>\n<p><strong>Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> bits = [1,0,0]\n<strong>Output:</strong> true\n<strong>Explanation:</strong> The only way to decode it is two-bit character and one-bit character.\nSo the last character is one-bit character.\n</pre>\n\n<p><strong>Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> bits = [1,1,1,0]\n<strong>Output:</strong> false\n<strong>Explanation:</strong> The only way to decode it is two-bit character and two-bit character.\nSo the last character is not one-bit character.\n</pre>\n\n<p>&nbsp;</p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= bits.length &lt;= 1000</code></li>\n\t<li><code>bits[i]</code> is either <code>0</code> or <code>1</code>.</li>\n</ul>\n",
10+
"translatedTitle": null,
11+
"translatedContent": null,
12+
"isPaidOnly": false,
13+
"difficulty": "Easy",
14+
"likes": 658,
15+
"dislikes": 1699,
16+
"isLiked": null,
17+
"similarQuestions": "[{\"title\": \"Gray Code\", \"titleSlug\": \"gray-code\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
18+
"exampleTestcases": "[1,0,0]\n[1,1,1,0]",
19+
"categoryTitle": "Algorithms",
20+
"contributors": [],
21+
"topicTags": [
22+
{
23+
"name": "Array",
24+
"slug": "array",
25+
"translatedName": null,
26+
"__typename": "TopicTagNode"
27+
}
28+
],
29+
"companyTagStats": null,
30+
"codeSnippets": [
31+
{
32+
"lang": "C++",
33+
"langSlug": "cpp",
34+
"code": "class Solution {\npublic:\n bool isOneBitCharacter(vector<int>& bits) {\n \n }\n};",
35+
"__typename": "CodeSnippetNode"
36+
},
37+
{
38+
"lang": "Java",
39+
"langSlug": "java",
40+
"code": "class Solution {\n public boolean isOneBitCharacter(int[] bits) {\n \n }\n}",
41+
"__typename": "CodeSnippetNode"
42+
},
43+
{
44+
"lang": "Python",
45+
"langSlug": "python",
46+
"code": "class Solution(object):\n def isOneBitCharacter(self, bits):\n \"\"\"\n :type bits: List[int]\n :rtype: bool\n \"\"\"\n ",
47+
"__typename": "CodeSnippetNode"
48+
},
49+
{
50+
"lang": "Python3",
51+
"langSlug": "python3",
52+
"code": "class Solution:\n def isOneBitCharacter(self, bits: List[int]) -> bool:\n ",
53+
"__typename": "CodeSnippetNode"
54+
},
55+
{
56+
"lang": "C",
57+
"langSlug": "c",
58+
"code": "\n\nbool isOneBitCharacter(int* bits, int bitsSize){\n\n}",
59+
"__typename": "CodeSnippetNode"
60+
},
61+
{
62+
"lang": "C#",
63+
"langSlug": "csharp",
64+
"code": "public class Solution {\n public bool IsOneBitCharacter(int[] bits) {\n \n }\n}",
65+
"__typename": "CodeSnippetNode"
66+
},
67+
{
68+
"lang": "JavaScript",
69+
"langSlug": "javascript",
70+
"code": "/**\n * @param {number[]} bits\n * @return {boolean}\n */\nvar isOneBitCharacter = function(bits) {\n \n};",
71+
"__typename": "CodeSnippetNode"
72+
},
73+
{
74+
"lang": "Ruby",
75+
"langSlug": "ruby",
76+
"code": "# @param {Integer[]} bits\n# @return {Boolean}\ndef is_one_bit_character(bits)\n \nend",
77+
"__typename": "CodeSnippetNode"
78+
},
79+
{
80+
"lang": "Swift",
81+
"langSlug": "swift",
82+
"code": "class Solution {\n func isOneBitCharacter(_ bits: [Int]) -> Bool {\n \n }\n}",
83+
"__typename": "CodeSnippetNode"
84+
},
85+
{
86+
"lang": "Go",
87+
"langSlug": "golang",
88+
"code": "func isOneBitCharacter(bits []int) bool {\n \n}",
89+
"__typename": "CodeSnippetNode"
90+
},
91+
{
92+
"lang": "Scala",
93+
"langSlug": "scala",
94+
"code": "object Solution {\n def isOneBitCharacter(bits: Array[Int]): Boolean = {\n \n }\n}",
95+
"__typename": "CodeSnippetNode"
96+
},
97+
{
98+
"lang": "Kotlin",
99+
"langSlug": "kotlin",
100+
"code": "class Solution {\n fun isOneBitCharacter(bits: IntArray): Boolean {\n \n }\n}",
101+
"__typename": "CodeSnippetNode"
102+
},
103+
{
104+
"lang": "Rust",
105+
"langSlug": "rust",
106+
"code": "impl Solution {\n pub fn is_one_bit_character(bits: Vec<i32>) -> bool {\n \n }\n}",
107+
"__typename": "CodeSnippetNode"
108+
},
109+
{
110+
"lang": "PHP",
111+
"langSlug": "php",
112+
"code": "class Solution {\n\n /**\n * @param Integer[] $bits\n * @return Boolean\n */\n function isOneBitCharacter($bits) {\n \n }\n}",
113+
"__typename": "CodeSnippetNode"
114+
},
115+
{
116+
"lang": "TypeScript",
117+
"langSlug": "typescript",
118+
"code": "function isOneBitCharacter(bits: number[]): boolean {\n\n};",
119+
"__typename": "CodeSnippetNode"
120+
},
121+
{
122+
"lang": "Racket",
123+
"langSlug": "racket",
124+
"code": "(define/contract (is-one-bit-character bits)\n (-> (listof exact-integer?) boolean?)\n\n )",
125+
"__typename": "CodeSnippetNode"
126+
},
127+
{
128+
"lang": "Erlang",
129+
"langSlug": "erlang",
130+
"code": "-spec is_one_bit_character(Bits :: [integer()]) -> boolean().\nis_one_bit_character(Bits) ->\n .",
131+
"__typename": "CodeSnippetNode"
132+
},
133+
{
134+
"lang": "Elixir",
135+
"langSlug": "elixir",
136+
"code": "defmodule Solution do\n @spec is_one_bit_character(bits :: [integer]) :: boolean\n def is_one_bit_character(bits) do\n\n end\nend",
137+
"__typename": "CodeSnippetNode"
138+
}
139+
],
140+
"stats": "{\"totalAccepted\": \"102.1K\", \"totalSubmission\": \"220.8K\", \"totalAcceptedRaw\": 102058, \"totalSubmissionRaw\": 220846, \"acRate\": \"46.2%\"}",
141+
"hints": [
142+
"Keep track of where the next character starts. At the end, you want to know if you started on the last bit."
143+
],
144+
"solution": null,
145+
"status": null,
146+
"sampleTestCase": "[1,0,0]",
147+
"metaData": "{\r\n \"name\": \"isOneBitCharacter\",\r\n \"params\": [\r\n {\r\n \"name\": \"bits\",\r\n \"type\": \"integer[]\"\r\n }\r\n ],\r\n \"return\": {\r\n \"type\": \"boolean\"\r\n }\r\n}\r\n",
148+
"judgerAvailable": true,
149+
"judgeType": "large",
150+
"mysqlSchemas": [],
151+
"enableRunCode": true,
152+
"enableTestMode": false,
153+
"enableDebugger": true,
154+
"envInfo": "{\"cpp\": [\"C++\", \"<p>Compiled with <code> clang 11 </code> using the latest C++ 17 standard.</p>\\r\\n\\r\\n<p>Your code is compiled with level two optimization (<code>-O2</code>). <a href=\\\"https://github.com/google/sanitizers/wiki/AddressSanitizer\\\" target=\\\"_blank\\\">AddressSanitizer</a> is also enabled to help detect out-of-bounds and use-after-free bugs.</p>\\r\\n\\r\\n<p>Most standard library headers are already included automatically for your convenience.</p>\"], \"java\": [\"Java\", \"<p><code> OpenJDK 17 </code>. Java 8 features such as lambda expressions and stream API can be used. </p>\\r\\n\\r\\n<p>Most standard library headers are already included automatically for your convenience.</p>\\r\\n<p>Includes <code>Pair</code> class from https://docs.oracle.com/javase/8/javafx/api/javafx/util/Pair.html.</p>\"], \"python\": [\"Python\", \"<p><code>Python 2.7.12</code>.</p>\\r\\n\\r\\n<p>Most libraries are already imported automatically for your convenience, such as <a href=\\\"https://docs.python.org/2/library/array.html\\\" target=\\\"_blank\\\">array</a>, <a href=\\\"https://docs.python.org/2/library/bisect.html\\\" target=\\\"_blank\\\">bisect</a>, <a href=\\\"https://docs.python.org/2/library/collections.html\\\" target=\\\"_blank\\\">collections</a>. If you need more libraries, you can import it yourself.</p>\\r\\n\\r\\n<p>For Map/TreeMap data structure, you may use <a href=\\\"http://www.grantjenks.com/docs/sortedcontainers/\\\" target=\\\"_blank\\\">sortedcontainers</a> library.</p>\\r\\n\\r\\n<p>Note that Python 2.7 <a href=\\\"https://www.python.org/dev/peps/pep-0373/\\\" target=\\\"_blank\\\">will not be maintained past 2020</a>. For the latest Python, please choose Python3 instead.</p>\"], \"c\": [\"C\", \"<p>Compiled with <code>gcc 8.2</code> using the gnu99 standard.</p>\\r\\n\\r\\n<p>Your code is compiled with level one optimization (<code>-O1</code>). <a href=\\\"https://github.com/google/sanitizers/wiki/AddressSanitizer\\\" target=\\\"_blank\\\">AddressSanitizer</a> is also enabled to help detect out-of-bounds and use-after-free bugs.</p>\\r\\n\\r\\n<p>Most standard library headers are already included automatically for your convenience.</p>\\r\\n\\r\\n<p>For hash table operations, you may use <a href=\\\"https://troydhanson.github.io/uthash/\\\" target=\\\"_blank\\\">uthash</a>. \\\"uthash.h\\\" is included by default. Below are some examples:</p>\\r\\n\\r\\n<p><b>1. Adding an item to a hash.</b>\\r\\n<pre>\\r\\nstruct hash_entry {\\r\\n int id; /* we'll use this field as the key */\\r\\n char name[10];\\r\\n UT_hash_handle hh; /* makes this structure hashable */\\r\\n};\\r\\n\\r\\nstruct hash_entry *users = NULL;\\r\\n\\r\\nvoid add_user(struct hash_entry *s) {\\r\\n HASH_ADD_INT(users, id, s);\\r\\n}\\r\\n</pre>\\r\\n</p>\\r\\n\\r\\n<p><b>2. Looking up an item in a hash:</b>\\r\\n<pre>\\r\\nstruct hash_entry *find_user(int user_id) {\\r\\n struct hash_entry *s;\\r\\n HASH_FIND_INT(users, &user_id, s);\\r\\n return s;\\r\\n}\\r\\n</pre>\\r\\n</p>\\r\\n\\r\\n<p><b>3. Deleting an item in a hash:</b>\\r\\n<pre>\\r\\nvoid delete_user(struct hash_entry *user) {\\r\\n HASH_DEL(users, user); \\r\\n}\\r\\n</pre>\\r\\n</p>\"], \"csharp\": [\"C#\", \"<p><a href=\\\"https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-9\\\" target=\\\"_blank\\\">C# 10 with .NET 6 runtime</a></p>\\r\\n\\r\\n<p>Your code is compiled with debug flag enabled (<code>/debug</code>).</p>\"], \"javascript\": [\"JavaScript\", \"<p><code>Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES6 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\\r\\n\\r\\n<p>For Priority Queue / Queue data structures, you may use <a href=\\\"https://github.com/datastructures-js/priority-queue\\\" target=\\\"_blank\\\">datastructures-js/priority-queue</a> and <a href=\\\"https://github.com/datastructures-js/queue\\\" target=\\\"_blank\\\">datastructures-js/queue</a>.</p>\"], \"ruby\": [\"Ruby\", \"<p><code>Ruby 3.1</code></p>\\r\\n\\r\\n<p>Some common data structure implementations are provided in the Algorithms module: https://www.rubydoc.info/github/kanwei/algorithms/Algorithms</p>\"], \"swift\": [\"Swift\", \"<p><code>Swift 5.5.2</code>.</p>\"], \"golang\": [\"Go\", \"<p><code>Go 1.17.6</code>.</p>\\r\\n\\r\\n<p>Support <a href=\\\"https://godoc.org/github.com/emirpasic/gods\\\" target=\\\"_blank\\\">https://godoc.org/github.com/emirpasic/gods</a> library.</p>\"], \"python3\": [\"Python3\", \"<p><code>Python 3.10</code>.</p>\\r\\n\\r\\n<p>Most libraries are already imported automatically for your convenience, such as <a href=\\\"https://docs.python.org/3/library/array.html\\\" target=\\\"_blank\\\">array</a>, <a href=\\\"https://docs.python.org/3/library/bisect.html\\\" target=\\\"_blank\\\">bisect</a>, <a href=\\\"https://docs.python.org/3/library/collections.html\\\" target=\\\"_blank\\\">collections</a>. If you need more libraries, you can import it yourself.</p>\\r\\n\\r\\n<p>For Map/TreeMap data structure, you may use <a href=\\\"http://www.grantjenks.com/docs/sortedcontainers/\\\" target=\\\"_blank\\\">sortedcontainers</a> library.</p>\"], \"scala\": [\"Scala\", \"<p><code>Scala 2.13.7</code>.</p>\"], \"kotlin\": [\"Kotlin\", \"<p><code>Kotlin 1.3.10</code>.</p>\"], \"rust\": [\"Rust\", \"<p><code>Rust 1.58.1</code></p>\\r\\n\\r\\n<p>Supports <a href=\\\"https://crates.io/crates/rand\\\" target=\\\"_blank\\\">rand </a> v0.6\\u00a0from crates.io</p>\"], \"php\": [\"PHP\", \"<p><code>PHP 8.1</code>.</p>\\r\\n<p>With bcmath module</p>\"], \"typescript\": [\"Typescript\", \"<p><code>TypeScript 4.5.4, Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES2020 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\"], \"racket\": [\"Racket\", \"<p>Run with <code>Racket 8.3</code>.</p>\"], \"erlang\": [\"Erlang\", \"Erlang/OTP 24.2\"], \"elixir\": [\"Elixir\", \"Elixir 1.13.0 with Erlang/OTP 24.2\"]}",
155+
"libraryUrl": null,
156+
"adminUrl": null,
157+
"challengeQuestion": null,
158+
"__typename": "QuestionNode"
159+
}
160+
}
161+
}

算法题/132-pattern.html

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<p>Given an array&nbsp;of <code>n</code> integers <code>nums</code>, a <strong>132 pattern</strong> is a subsequence of three integers <code>nums[i]</code>, <code>nums[j]</code> and <code>nums[k]</code> such that <code>i &lt; j &lt; k</code> and <code>nums[i] &lt; nums[k] &lt; nums[j]</code>.</p>
2+
3+
<p>Return <em><code>true</code> if there is a <strong>132 pattern</strong> in <code>nums</code>, otherwise, return <code>false</code>.</em></p>
4+
5+
<p>&nbsp;</p>
6+
<p><strong>Example 1:</strong></p>
7+
8+
<pre>
9+
<strong>Input:</strong> nums = [1,2,3,4]
10+
<strong>Output:</strong> false
11+
<strong>Explanation:</strong> There is no 132 pattern in the sequence.
12+
</pre>
13+
14+
<p><strong>Example 2:</strong></p>
15+
16+
<pre>
17+
<strong>Input:</strong> nums = [3,1,4,2]
18+
<strong>Output:</strong> true
19+
<strong>Explanation:</strong> There is a 132 pattern in the sequence: [1, 4, 2].
20+
</pre>
21+
22+
<p><strong>Example 3:</strong></p>
23+
24+
<pre>
25+
<strong>Input:</strong> nums = [-1,3,2,0]
26+
<strong>Output:</strong> true
27+
<strong>Explanation:</strong> There are three 132 patterns in the sequence: [-1, 3, 2], [-1, 3, 0] and [-1, 2, 0].
28+
</pre>
29+
30+
<p>&nbsp;</p>
31+
<p><strong>Constraints:</strong></p>
32+
33+
<ul>
34+
<li><code>n == nums.length</code></li>
35+
<li><code>1 &lt;= n &lt;= 2 * 10<sup>5</sup></code></li>
36+
<li><code>-10<sup>9</sup> &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
37+
</ul>

0 commit comments

Comments
 (0)