Skip to content

feat: update lc problems #3491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 28 additions & 13 deletions solution/0000-0099/0024.Swap Nodes in Pairs/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,40 @@ tags:

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></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;" />
<pre>
<strong>Input:</strong> head = [1,2,3,4]
<strong>Output:</strong> [2,1,4,3]
</pre>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">head = [1,2,3,4]</span></p>

<p><strong>Output:</strong> <span class="example-io">[2,1,4,3]</span></p>

<p><strong>Explanation:</strong></p>

<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>
</div>

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

<pre>
<strong>Input:</strong> head = []
<strong>Output:</strong> []
</pre>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">head = []</span></p>

<p><strong>Output:</strong> <span class="example-io">[]</span></p>
</div>

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

<pre>
<strong>Input:</strong> head = [1]
<strong>Output:</strong> [1]
</pre>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">head = [1]</span></p>

<p><strong>Output:</strong> <span class="example-io">[1]</span></p>
</div>

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

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">head = [1,2,3]</span></p>

<p><strong>Output:</strong> <span class="example-io">[2,1,3]</span></p>
</div>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
Expand Down
44 changes: 32 additions & 12 deletions solution/0000-0099/0049.Group Anagrams/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,41 @@ tags:

<!-- description:start -->

<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>

<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>
<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>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> strs = ["eat","tea","tan","ate","nat","bat"]
<strong>Output:</strong> [["bat"],["nat","tan"],["ate","eat","tea"]]
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> strs = [""]
<strong>Output:</strong> [[""]]
</pre><p><strong class="example">Example 3:</strong></p>
<pre><strong>Input:</strong> strs = ["a"]
<strong>Output:</strong> [["a"]]
</pre>

<div class="example-block">
<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>

<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>

<p><strong>Explanation:</strong></p>

<ul>
<li>There is no string in strs that can be rearranged to form <code>&quot;bat&quot;</code>.</li>
<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>
<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>
</ul>
</div>

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

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">strs = [&quot;&quot;]</span></p>

<p><strong>Output:</strong> <span class="example-io">[[&quot;&quot;]]</span></p>
</div>

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

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">strs = [&quot;a&quot;]</span></p>

<p><strong>Output:</strong> <span class="example-io">[[&quot;a&quot;]]</span></p>
</div>

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

Expand Down
39 changes: 23 additions & 16 deletions solution/0000-0099/0071.Simplify Path/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@ tags:

<!-- description:start -->

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

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

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

<p>返回的 <strong>简化路径</strong> 必须遵循下述格式:</p>

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

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

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

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

<p>应删除尾部斜杠。</p>
<p>应删除尾随斜杠。</p>
</div>

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

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

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

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

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

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

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

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

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

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

<div class="example-block">
<p><span class="example-io"><b>输入:</b></span><span class="example-io">path = "/../"</span></p>
<p><span class="example-io"><b>输入:</b>path = "/../"</span></p>

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

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

<p>不可能从根目录上升级一级。</p>
<p>不可能从根目录上升一级目录。</p>
</div>

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

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

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

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

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

<p>&nbsp;</p>
Expand Down
25 changes: 16 additions & 9 deletions solution/0000-0099/0071.Simplify Path/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,27 @@ tags:

<!-- description:start -->

<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>
<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>

<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>
<p>The <em>rules</em> of a Unix-style file system are as follows:</p>

<p>The simplified canonical path should adhere to the following rules:</p>
<ul>
<li>A single period <code>&#39;.&#39;</code> represents the current directory.</li>
<li>A double period <code>&#39;..&#39;</code> represents the previous/parent directory.</li>
<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>
<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>
</ul>

<p>The simplified canonical path should follow these <em>rules</em>:</p>

<ul>
<li>It must start with a single slash <code>&#39;/&#39;</code>.</li>
<li>Directories within the path should be separated by only one slash <code>&#39;/&#39;</code>.</li>
<li>It should not end with a slash <code>&#39;/&#39;</code>, unless it&#39;s the root directory.</li>
<li>It should exclude any single or double periods used to denote current or parent directories.</li>
<li>The path must start with a single slash <code>&#39;/&#39;</code>.</li>
<li>Directories within the path must be separated by exactly one slash <code>&#39;/&#39;</code>.</li>
<li>The path must not end with a slash <code>&#39;/&#39;</code>, unless it is the root directory.</li>
<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>
</ul>

<p>Return the new path.</p>
<p>Return the <strong>simplified canonical path</strong>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
Expand Down Expand Up @@ -66,7 +73,7 @@ tags:

<p><strong>Explanation:</strong></p>

<p>A double period <code>&quot;..&quot;</code> refers to the directory up a level.</p>
<p>A double period <code>&quot;..&quot;</code> refers to the directory up a level (the parent directory).</p>
</div>

<p><strong class="example">Example 4:</strong></p>
Expand Down
38 changes: 26 additions & 12 deletions solution/0200-0299/0217.Contains Duplicate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,37 @@ tags:

<p>&nbsp;</p>

<p><strong>示例 1:</strong></p>
<p><strong class="example">示例 1:</strong></p>

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

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

<pre>
<strong>输入:</strong>nums = [1,2,3,4]
<strong>输出:</strong>false</pre>
<p><strong>解释:</strong></p>

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

<pre>
<strong>输入:</strong>nums = [1,1,1,3,3,4,3,2,4,2]
<strong>输出:</strong>true</pre>
<p><strong class="example">示例 2:</strong></p>

<div class="example-block">
<p><span class="example-io"><b>输入:</b>nums = [1,2,3,4]</span></p>

<p><span class="example-io"><b>输出:</b>false</span></p>

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

<p>所有元素都不同。</p>
</div>

<p><strong class="example">示例 3:</strong></p>

<div class="example-block">
<p><span class="example-io"><b>输入:</b>nums = [1,1,1,3,3,4,3,2,4,2]</span></p>

<p><span class="example-io"><b>输出:</b>true</span></p>
</div>

<p>&nbsp;</p>

Expand Down
40 changes: 31 additions & 9 deletions solution/0200-0299/0217.Contains Duplicate/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,37 @@ tags:

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> nums = [1,2,3,1]
<strong>Output:</strong> true
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> nums = [1,2,3,4]
<strong>Output:</strong> false
</pre><p><strong class="example">Example 3:</strong></p>
<pre><strong>Input:</strong> nums = [1,1,1,3,3,4,3,2,4,2]
<strong>Output:</strong> true
</pre>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,3,1]</span></p>

<p><strong>Output:</strong> <span class="example-io">true</span></p>

<p><strong>Explanation:</strong></p>

<p>The element 1 occurs at the indices 0 and 3.</p>
</div>

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

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,3,4]</span></p>

<p><strong>Output:</strong> <span class="example-io">false</span></p>

<p><strong>Explanation:</strong></p>

<p>All elements are distinct.</p>
</div>

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

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [1,1,1,3,3,4,3,2,4,2]</span></p>

<p><strong>Output:</strong> <span class="example-io">true</span></p>
</div>

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

Expand Down
8 changes: 3 additions & 5 deletions solution/0200-0299/0242.Valid Anagram/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,21 @@ tags:

<!-- description:start -->

<p>给定两个字符串 <code><em>s</em></code> 和 <code><em>t</em></code> ,编写一个函数来判断 <code><em>t</em></code> 是否是 <code><em>s</em></code> 的字母异位词。</p>

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

<p>&nbsp;</p>

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

<pre>
<strong>输入:</strong> <em>s</em> = "anagram", <em>t</em> = "nagaram"
<strong>输入:</strong> s = "anagram", t = "nagaram"
<strong>输出:</strong> true
</pre>

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

<pre>
<strong>输入:</strong> <em>s</em> = "rat", <em>t</em> = "car"
<strong>输入:</strong> s = "rat", t = "car"
<strong>输出: </strong>false</pre>

<p>&nbsp;</p>
Expand Down
Loading
Loading