Skip to content

Commit 3281d77

Browse files
authored
feat: update lc problems (#3491)
1 parent 57f661e commit 3281d77

File tree

55 files changed

+936
-199
lines changed

Some content is hidden

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

55 files changed

+936
-199
lines changed

solution/0000-0099/0024.Swap Nodes in Pairs/README_EN.md

+28-13
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,40 @@ tags:
2121

2222
<p>&nbsp;</p>
2323
<p><strong class="example">Example 1:</strong></p>
24-
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0024.Swap%20Nodes%20in%20Pairs/images/swap_ex1.jpg" style="width: 422px; height: 222px;" />
25-
<pre>
26-
<strong>Input:</strong> head = [1,2,3,4]
27-
<strong>Output:</strong> [2,1,4,3]
28-
</pre>
24+
25+
<div class="example-block">
26+
<p><strong>Input:</strong> <span class="example-io">head = [1,2,3,4]</span></p>
27+
28+
<p><strong>Output:</strong> <span class="example-io">[2,1,4,3]</span></p>
29+
30+
<p><strong>Explanation:</strong></p>
31+
32+
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0024.Swap%20Nodes%20in%20Pairs/images/swap_ex1.jpg" style="width: 422px; height: 222px;" /></p>
33+
</div>
2934

3035
<p><strong class="example">Example 2:</strong></p>
3136

32-
<pre>
33-
<strong>Input:</strong> head = []
34-
<strong>Output:</strong> []
35-
</pre>
37+
<div class="example-block">
38+
<p><strong>Input:</strong> <span class="example-io">head = []</span></p>
39+
40+
<p><strong>Output:</strong> <span class="example-io">[]</span></p>
41+
</div>
3642

3743
<p><strong class="example">Example 3:</strong></p>
3844

39-
<pre>
40-
<strong>Input:</strong> head = [1]
41-
<strong>Output:</strong> [1]
42-
</pre>
45+
<div class="example-block">
46+
<p><strong>Input:</strong> <span class="example-io">head = [1]</span></p>
47+
48+
<p><strong>Output:</strong> <span class="example-io">[1]</span></p>
49+
</div>
50+
51+
<p><strong class="example">Example 4:</strong></p>
52+
53+
<div class="example-block">
54+
<p><strong>Input:</strong> <span class="example-io">head = [1,2,3]</span></p>
55+
56+
<p><strong>Output:</strong> <span class="example-io">[2,1,3]</span></p>
57+
</div>
4358

4459
<p>&nbsp;</p>
4560
<p><strong>Constraints:</strong></p>

solution/0000-0099/0049.Group Anagrams/README_EN.md

+32-12
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,41 @@ tags:
1919

2020
<!-- description:start -->
2121

22-
<p>Given an array of strings <code>strs</code>, group <strong>the anagrams</strong> together. You can return the answer in <strong>any order</strong>.</p>
23-
24-
<p>An <strong>Anagram</strong> is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.</p>
22+
<p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
2523

2624
<p>&nbsp;</p>
2725
<p><strong class="example">Example 1:</strong></p>
28-
<pre><strong>Input:</strong> strs = ["eat","tea","tan","ate","nat","bat"]
29-
<strong>Output:</strong> [["bat"],["nat","tan"],["ate","eat","tea"]]
30-
</pre><p><strong class="example">Example 2:</strong></p>
31-
<pre><strong>Input:</strong> strs = [""]
32-
<strong>Output:</strong> [[""]]
33-
</pre><p><strong class="example">Example 3:</strong></p>
34-
<pre><strong>Input:</strong> strs = ["a"]
35-
<strong>Output:</strong> [["a"]]
36-
</pre>
26+
27+
<div class="example-block">
28+
<p><strong>Input:</strong> <span class="example-io">strs = [&quot;eat&quot;,&quot;tea&quot;,&quot;tan&quot;,&quot;ate&quot;,&quot;nat&quot;,&quot;bat&quot;]</span></p>
29+
30+
<p><strong>Output:</strong> <span class="example-io">[[&quot;bat&quot;],[&quot;nat&quot;,&quot;tan&quot;],[&quot;ate&quot;,&quot;eat&quot;,&quot;tea&quot;]]</span></p>
31+
32+
<p><strong>Explanation:</strong></p>
33+
34+
<ul>
35+
<li>There is no string in strs that can be rearranged to form <code>&quot;bat&quot;</code>.</li>
36+
<li>The strings <code>&quot;nat&quot;</code> and <code>&quot;tan&quot;</code> are anagrams as they can be rearranged to form each other.</li>
37+
<li>The strings <code>&quot;ate&quot;</code>, <code>&quot;eat&quot;</code>, and <code>&quot;tea&quot;</code> are anagrams as they can be rearranged to form each other.</li>
38+
</ul>
39+
</div>
40+
41+
<p><strong class="example">Example 2:</strong></p>
42+
43+
<div class="example-block">
44+
<p><strong>Input:</strong> <span class="example-io">strs = [&quot;&quot;]</span></p>
45+
46+
<p><strong>Output:</strong> <span class="example-io">[[&quot;&quot;]]</span></p>
47+
</div>
48+
49+
<p><strong class="example">Example 3:</strong></p>
50+
51+
<div class="example-block">
52+
<p><strong>Input:</strong> <span class="example-io">strs = [&quot;a&quot;]</span></p>
53+
54+
<p><strong>Output:</strong> <span class="example-io">[[&quot;a&quot;]]</span></p>
55+
</div>
56+
3757
<p>&nbsp;</p>
3858
<p><strong>Constraints:</strong></p>
3959

solution/0000-0099/0071.Simplify Path/README.md

+23-16
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,18 @@ tags:
1717

1818
<!-- description:start -->
1919

20-
<p>给你一个字符串 <code>path</code> ,表示指向某一文件或目录的&nbsp;Unix 风格 <strong>绝对路径 </strong>(以 <code>'/'</code> 开头),请你将其转化为更加简洁的规范路径。</p>
20+
<p>给你一个字符串 <code>path</code> ,表示指向某一文件或目录的&nbsp;Unix 风格 <strong>绝对路径 </strong>(以 <code>'/'</code> 开头),请你将其转化为 <strong>更加简洁的规范路径</strong>。</p>
2121

22-
<p class="MachineTrans-lang-zh-CN">在 Unix 风格的文件系统中,一个点(<code>.</code>)表示当前目录本身;此外,两个点 (<code>..</code>)&nbsp;表示将目录切换到上一级(指向父目录);两者都可以是复杂相对路径的组成部分。任意多个连续的斜杠(即,<code>'//'</code>)都被视为单个斜杠 <code>'/'</code> 。 对于此问题,任何其他格式的点(例如,<code>'...'</code>)均被视为文件/目录名称。</p>
22+
<p class="MachineTrans-lang-zh-CN">在 Unix 风格的文件系统中规则如下:</p>
2323

24-
<p>请注意,返回的 <strong>规范路径</strong> 必须遵循下述格式:</p>
24+
<ul>
25+
<li class="MachineTrans-lang-zh-CN">一个点&nbsp;<code>'.'</code>&nbsp;表示当前目录本身。</li>
26+
<li class="MachineTrans-lang-zh-CN">此外,两个点 <code>'..'</code>&nbsp;表示将目录切换到上一级(指向父目录)。</li>
27+
<li class="MachineTrans-lang-zh-CN">任意多个连续的斜杠(即,<code>'//'</code>&nbsp;或 <code>'///'</code>)都被视为单个斜杠 <code>'/'</code>。</li>
28+
<li class="MachineTrans-lang-zh-CN">任何其他格式的点(例如,<code>'...'</code>&nbsp;或 <code>'....'</code>)均被视为有效的文件/目录名称。</li>
29+
</ul>
30+
31+
<p>返回的 <strong>简化路径</strong> 必须遵循下述格式:</p>
2532

2633
<ul>
2734
<li>始终以斜杠 <code>'/'</code> 开头。</li>
@@ -37,21 +44,21 @@ tags:
3744
<p><strong class="example">示例 1:</strong></p>
3845

3946
<div class="example-block">
40-
<p><span class="example-io"><b>输入:</b>path = "/home/"</span></p>
47+
<p><strong>输入:</strong><span class="example-io">path = "/home/"</span></p>
4148

4249
<p><span class="example-io"><b>输出:</b>"/home"</span></p>
4350

4451
<p><strong>解释:</strong></p>
4552

46-
<p>应删除尾部斜杠。</p>
53+
<p>应删除尾随斜杠。</p>
4754
</div>
4855

4956
<p><strong class="example">示例 2:</strong></p>
5057

5158
<div class="example-block">
52-
<p><span class="example-io"><b>输入:</b></span><span class="example-io">path = "/home//foo/"</span></p>
59+
<p><span class="example-io"><b>输入:</b>path = "/home//foo/"</span></p>
5360

54-
<p><span class="example-io"><b>输出:</b></span><span class="example-io">"/home/foo"</span></p>
61+
<p><span class="example-io"><b>输出:</b>"/home/foo"</span></p>
5562

5663
<p><strong>解释:</strong></p>
5764

@@ -61,37 +68,37 @@ tags:
6168
<p><strong class="example">示例 3:</strong></p>
6269

6370
<div class="example-block">
64-
<p><span class="example-io"><b>输入:</b></span><span class="example-io">path = "/home/user/Documents/../Pictures"</span></p>
71+
<p><strong>输入:</strong><span class="example-io">path = "/home/user/Documents/../Pictures"</span></p>
6572

66-
<p><span class="example-io"><b>输出:</b></span><span class="example-io">"/home/user/Pictures"</span></p>
73+
<p><span class="example-io"><b>输出:</b>"/home/user/Pictures"</span></p>
6774

6875
<p><strong>解释:</strong></p>
6976

70-
<p>两个点&nbsp;<code>".."</code>&nbsp;表示上一级目录。</p>
77+
<p>两个点&nbsp;<code>".."</code>&nbsp;表示上一级目录(父目录)。</p>
7178
</div>
7279

7380
<p><strong class="example">示例 4:</strong></p>
7481

7582
<div class="example-block">
76-
<p><span class="example-io"><b>输入:</b></span><span class="example-io">path = "/../"</span></p>
83+
<p><span class="example-io"><b>输入:</b>path = "/../"</span></p>
7784

78-
<p><span class="example-io"><b>输出:</b></span><span class="example-io">"/"</span></p>
85+
<p><span class="example-io"><b>输出:</b>"/"</span></p>
7986

8087
<p><strong>解释:</strong></p>
8188

82-
<p>不可能从根目录上升级一级。</p>
89+
<p>不可能从根目录上升一级目录。</p>
8390
</div>
8491

8592
<p><strong class="example">示例 5:</strong></p>
8693

8794
<div class="example-block">
88-
<p><span class="example-io"><b>输入:</b></span><span class="example-io">path = "/.../a/../b/c/../d/./"</span></p>
95+
<p><span class="example-io"><b>输入:</b>path = "/.../a/../b/c/../d/./"</span></p>
8996

90-
<p><span class="example-io"><b>输出:</b></span><span class="example-io">"/.../b/d"</span></p>
97+
<p><span class="example-io"><b>输出:</b>"/.../b/d"</span></p>
9198

9299
<p><strong>解释:</strong></p>
93100

94-
<p><code>"..."</code> 是此问题中目录的有效名称。</p>
101+
<p><code>"..."</code>&nbsp;在这个问题中是一个合法的目录名。</p>
95102
</div>
96103

97104
<p>&nbsp;</p>

solution/0000-0099/0071.Simplify Path/README_EN.md

+16-9
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,27 @@ tags:
1717

1818
<!-- description:start -->
1919

20-
<p>Given an absolute path for a Unix-style file system, which begins with a slash <code>&#39;/&#39;</code>, transform this path into its <strong>simplified canonical path</strong>.</p>
20+
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p>
2121

22-
<p>In Unix-style file system context, a single period <code>&#39;.&#39;</code> signifies the current directory, a double period <code>&quot;..&quot;</code> denotes moving up one directory level, and multiple slashes such as <code>&quot;//&quot;</code> are interpreted as a single slash. In this problem, treat sequences of periods not covered by the previous rules (like <code>&quot;...&quot;</code>) as valid names for files or directories.</p>
22+
<p>The <em>rules</em> of a Unix-style file system are as follows:</p>
2323

24-
<p>The simplified canonical path should adhere to the following rules:</p>
24+
<ul>
25+
<li>A single period <code>&#39;.&#39;</code> represents the current directory.</li>
26+
<li>A double period <code>&#39;..&#39;</code> represents the previous/parent directory.</li>
27+
<li>Multiple consecutive slashes such as <code>&#39;//&#39;</code> and <code>&#39;///&#39;</code> are treated as a single slash <code>&#39;/&#39;</code>.</li>
28+
<li>Any sequence of periods that does <strong>not match</strong> the rules above should be treated as a <strong>valid directory or</strong> <strong>file </strong><strong>name</strong>. For example, <code>&#39;...&#39; </code>and <code>&#39;....&#39;</code> are valid directory or file names.</li>
29+
</ul>
30+
31+
<p>The simplified canonical path should follow these <em>rules</em>:</p>
2532

2633
<ul>
27-
<li>It must start with a single slash <code>&#39;/&#39;</code>.</li>
28-
<li>Directories within the path should be separated by only one slash <code>&#39;/&#39;</code>.</li>
29-
<li>It should not end with a slash <code>&#39;/&#39;</code>, unless it&#39;s the root directory.</li>
30-
<li>It should exclude any single or double periods used to denote current or parent directories.</li>
34+
<li>The path must start with a single slash <code>&#39;/&#39;</code>.</li>
35+
<li>Directories within the path must be separated by exactly one slash <code>&#39;/&#39;</code>.</li>
36+
<li>The path must not end with a slash <code>&#39;/&#39;</code>, unless it is the root directory.</li>
37+
<li>The path must not have any single or double periods (<code>&#39;.&#39;</code> and <code>&#39;..&#39;</code>) used to denote current or parent directories.</li>
3138
</ul>
3239

33-
<p>Return the new path.</p>
40+
<p>Return the <strong>simplified canonical path</strong>.</p>
3441

3542
<p>&nbsp;</p>
3643
<p><strong class="example">Example 1:</strong></p>
@@ -66,7 +73,7 @@ tags:
6673

6774
<p><strong>Explanation:</strong></p>
6875

69-
<p>A double period <code>&quot;..&quot;</code> refers to the directory up a level.</p>
76+
<p>A double period <code>&quot;..&quot;</code> refers to the directory up a level (the parent directory).</p>
7077
</div>
7178

7279
<p><strong class="example">Example 4:</strong></p>

solution/0200-0299/0217.Contains Duplicate/README.md

+26-12
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,37 @@ tags:
2222

2323
<p>&nbsp;</p>
2424

25-
<p><strong>示例 1:</strong></p>
25+
<p><strong class="example">示例 1:</strong></p>
2626

27-
<pre>
28-
<strong>输入:</strong>nums = [1,2,3,1]
29-
<strong>输出:</strong>true</pre>
27+
<div class="example-block">
28+
<p><span class="example-io"><b>输入:</b>nums = [1,2,3,1]</span></p>
3029

31-
<p><strong>示例 2:</strong></p>
30+
<p><span class="example-io"><b>输出:</b>true</span></p>
3231

33-
<pre>
34-
<strong>输入:</strong>nums = [1,2,3,4]
35-
<strong>输出:</strong>false</pre>
32+
<p><strong>解释:</strong></p>
3633

37-
<p><strong>示例&nbsp;3:</strong></p>
34+
<p>元素 1 在下标 0 和 3 出现。</p>
35+
</div>
3836

39-
<pre>
40-
<strong>输入:</strong>nums = [1,1,1,3,3,4,3,2,4,2]
41-
<strong>输出:</strong>true</pre>
37+
<p><strong class="example">示例 2:</strong></p>
38+
39+
<div class="example-block">
40+
<p><span class="example-io"><b>输入:</b>nums = [1,2,3,4]</span></p>
41+
42+
<p><span class="example-io"><b>输出:</b>false</span></p>
43+
44+
<p><strong>解释:</strong></p>
45+
46+
<p>所有元素都不同。</p>
47+
</div>
48+
49+
<p><strong class="example">示例 3:</strong></p>
50+
51+
<div class="example-block">
52+
<p><span class="example-io"><b>输入:</b>nums = [1,1,1,3,3,4,3,2,4,2]</span></p>
53+
54+
<p><span class="example-io"><b>输出:</b>true</span></p>
55+
</div>
4256

4357
<p>&nbsp;</p>
4458

solution/0200-0299/0217.Contains Duplicate/README_EN.md

+31-9
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,37 @@ tags:
2222

2323
<p>&nbsp;</p>
2424
<p><strong class="example">Example 1:</strong></p>
25-
<pre><strong>Input:</strong> nums = [1,2,3,1]
26-
<strong>Output:</strong> true
27-
</pre><p><strong class="example">Example 2:</strong></p>
28-
<pre><strong>Input:</strong> nums = [1,2,3,4]
29-
<strong>Output:</strong> false
30-
</pre><p><strong class="example">Example 3:</strong></p>
31-
<pre><strong>Input:</strong> nums = [1,1,1,3,3,4,3,2,4,2]
32-
<strong>Output:</strong> true
33-
</pre>
25+
26+
<div class="example-block">
27+
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,3,1]</span></p>
28+
29+
<p><strong>Output:</strong> <span class="example-io">true</span></p>
30+
31+
<p><strong>Explanation:</strong></p>
32+
33+
<p>The element 1 occurs at the indices 0 and 3.</p>
34+
</div>
35+
36+
<p><strong class="example">Example 2:</strong></p>
37+
38+
<div class="example-block">
39+
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,3,4]</span></p>
40+
41+
<p><strong>Output:</strong> <span class="example-io">false</span></p>
42+
43+
<p><strong>Explanation:</strong></p>
44+
45+
<p>All elements are distinct.</p>
46+
</div>
47+
48+
<p><strong class="example">Example 3:</strong></p>
49+
50+
<div class="example-block">
51+
<p><strong>Input:</strong> <span class="example-io">nums = [1,1,1,3,3,4,3,2,4,2]</span></p>
52+
53+
<p><strong>Output:</strong> <span class="example-io">true</span></p>
54+
</div>
55+
3456
<p>&nbsp;</p>
3557
<p><strong>Constraints:</strong></p>
3658

solution/0200-0299/0242.Valid Anagram/README.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,21 @@ tags:
1818

1919
<!-- description:start -->
2020

21-
<p>给定两个字符串 <code><em>s</em></code> 和 <code><em>t</em></code> ,编写一个函数来判断 <code><em>t</em></code> 是否是 <code><em>s</em></code> 的字母异位词。</p>
22-
23-
<p><strong>字母异位词</strong> 是通过重新排列不同单词或短语的字母而形成的单词或短语,通常只使用所有原始字母一次。</p>
21+
<p>给定两个字符串 <code>s</code> 和 <code>t</code> ,编写一个函数来判断 <code>t</code> 是否是 <code>s</code> 的 <span data-keyword="anagram">字母异位词</span>。</p>
2422

2523
<p>&nbsp;</p>
2624

2725
<p><strong>示例&nbsp;1:</strong></p>
2826

2927
<pre>
30-
<strong>输入:</strong> <em>s</em> = "anagram", <em>t</em> = "nagaram"
28+
<strong>输入:</strong> s = "anagram", t = "nagaram"
3129
<strong>输出:</strong> true
3230
</pre>
3331

3432
<p><strong>示例 2:</strong></p>
3533

3634
<pre>
37-
<strong>输入:</strong> <em>s</em> = "rat", <em>t</em> = "car"
35+
<strong>输入:</strong> s = "rat", t = "car"
3836
<strong>输出: </strong>false</pre>
3937

4038
<p>&nbsp;</p>

0 commit comments

Comments
 (0)