Skip to content

Commit accb72e

Browse files
authored
feat: add solutions to lc problems: No.2273~2275 (doocs#3550)
1 parent aed6166 commit accb72e

File tree

32 files changed

+746
-238
lines changed

32 files changed

+746
-238
lines changed

solution/0600-0699/0658.Find K Closest Elements/README_EN.md

+15-6
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,21 @@ tags:
3232

3333
<p>&nbsp;</p>
3434
<p><strong class="example">Example 1:</strong></p>
35-
<pre><strong>Input:</strong> arr = [1,2,3,4,5], k = 4, x = 3
36-
<strong>Output:</strong> [1,2,3,4]
37-
</pre><p><strong class="example">Example 2:</strong></p>
38-
<pre><strong>Input:</strong> arr = [1,2,3,4,5], k = 4, x = -1
39-
<strong>Output:</strong> [1,2,3,4]
40-
</pre>
35+
36+
<div class="example-block">
37+
<p><strong>Input:</strong> <span class="example-io">arr = [1,2,3,4,5], k = 4, x = 3</span></p>
38+
39+
<p><strong>Output:</strong> <span class="example-io">[1,2,3,4]</span></p>
40+
</div>
41+
42+
<p><strong class="example">Example 2:</strong></p>
43+
44+
<div class="example-block">
45+
<p><strong>Input:</strong> <span class="example-io">arr = [1,1,2,3,4,5], k = 4, x = -1</span></p>
46+
47+
<p><strong>Output:</strong> <span class="example-io">[1,1,2,3]</span></p>
48+
</div>
49+
4150
<p>&nbsp;</p>
4251
<p><strong>Constraints:</strong></p>
4352

solution/0600-0699/0666.Path Sum IV/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ tags:
2020

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

23-
<p>对于一棵深度小于&nbsp;<code>5</code>&nbsp;的树,可以用一组三位十进制整数来表示。对于每个整数:</p>
23+
<p>对于一棵深度小于&nbsp;<code>5</code>&nbsp;的树,可以用一组三位十进制整数来表示。给定一个由三位数组成的&nbsp;<strong>递增</strong>&nbsp;的数组&nbsp;<code>nums</code>&nbsp;表示一棵深度小于&nbsp;<code>5</code>&nbsp;的二叉树,对于每个整数:</p>
2424

2525
<ul>
2626
<li>百位上的数字表示这个节点的深度 <code>d</code>,<code>1 &lt;= d&nbsp;&lt;= 4</code>。</li>
27-
<li>十位上的数字表示这个节点在当前层所在的位置 <code>P</code>, <code>1 &lt;= p&nbsp;&lt;= 8</code>。位置编号与一棵满二叉树的位置编号相同。</li>
27+
<li>十位上的数字表示这个节点在当前层所在的位置 <code>p</code>, <code>1 &lt;= p&nbsp;&lt;= 8</code>。位置编号与一棵 <strong>满二叉树</strong> 的位置编号相同。</li>
2828
<li>个位上的数字表示这个节点的权值 <code>v</code>,<code>0 &lt;= v&nbsp;&lt;= 9</code>。</li>
2929
</ul>
3030

31-
<p>给定一个包含三位整数的&nbsp;<strong>升序&nbsp;</strong>数组&nbsp;<code>nums</code>&nbsp;,表示一棵深度小于 <code>5</code> 的二叉树,请你返回 <em>从根到所有叶子结点的路径之和&nbsp;</em>。</p>
31+
<p>返回从&nbsp;<strong>&nbsp;</strong>到所有 <strong>叶子结点</strong> 的 <strong>路径</strong> 之 <strong>和</strong>。</p>
3232

3333
<p><strong>保证&nbsp;</strong>给定的数组表示一个有效的连接二叉树。</p>
3434

@@ -42,7 +42,7 @@ tags:
4242
<strong>输入:</strong> nums = [113, 215, 221]
4343
<strong>输出:</strong> 12
4444
<strong>解释:</strong> 列表所表示的树如上所示。
45-
路径和 = (3 + 5) + (3 + 1) = 12.
45+
路径和 = (3 + 5) + (3 + 1) = 12
4646
</pre>
4747

4848
<p><strong>示例 2:</strong></p>
@@ -53,7 +53,7 @@ tags:
5353
<strong>输入:</strong> nums = [113, 221]
5454
<strong>输出:</strong> 4
5555
<strong>解释:</strong> 列表所表示的树如上所示。
56-
路径和 = (3 + 1) = 4.
56+
路径和 = (3 + 1) = 4
5757
</pre>
5858

5959
<p>&nbsp;</p>

solution/0700-0799/0713.Subarray Product Less Than K/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ difficulty: 中等
44
edit_url: https://github.com/doocs/leetcode/edit/main/solution/0700-0799/0713.Subarray%20Product%20Less%20Than%20K/README.md
55
tags:
66
- 数组
7+
- 二分查找
8+
- 前缀和
79
- 滑动窗口
810
---
911

solution/0700-0799/0713.Subarray Product Less Than K/README_EN.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ difficulty: Medium
44
edit_url: https://github.com/doocs/leetcode/edit/main/solution/0700-0799/0713.Subarray%20Product%20Less%20Than%20K/README_EN.md
55
tags:
66
- Array
7+
- Binary Search
8+
- Prefix Sum
79
- Sliding Window
810
---
911

solution/0700-0799/0733.Flood Fill/README.md

+23-14
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,42 @@ tags:
1919

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

22-
<p>有一幅以&nbsp;<code>m x n</code>&nbsp;的二维整数数组表示的图画&nbsp;<code>image</code>&nbsp;,其中&nbsp;<code>image[i][j]</code>&nbsp;表示该图画的像素值大小。</p>
22+
<p>有一幅以&nbsp;<code>m x n</code>&nbsp;的二维整数数组表示的图画&nbsp;<code>image</code>&nbsp;,其中&nbsp;<code>image[i][j]</code>&nbsp;表示该图画的像素值大小。你也被给予三个整数 <code>sr</code> ,&nbsp; <code>sc</code> 和 <code>color</code> 。你应该从像素&nbsp;<code>image[sr][sc]</code>&nbsp;开始对图像进行上色&nbsp;<strong>填充</strong> 。</p>
2323

24-
<p>你也被给予三个整数 <code>sr</code> ,&nbsp; <code>sc</code> 和 <code>color</code> 。你应该从像素&nbsp;<code>image[sr][sc]</code>&nbsp;开始对图像进行 上色<strong>填充</strong></p>
24+
<p>为了完成 <strong>上色工作</strong></p>
2525

26-
<p>为了完成 <strong>上色工作</strong>,从初始像素开始,记录初始坐标的 <strong>上下左右四个方向上</strong> 相邻且同色的像素点,接着再记录与这些像素点相邻且同色的新像素点,……,重复该过程。将所有有记录的像素点的颜色值改为 <code>color</code>。</p>
26+
<ol>
27+
<li>从初始像素开始,将其颜色改为 <code>color</code>。</li>
28+
<li>对初始坐标的 <strong>上下左右四个方向上</strong> 相邻且与初始像素的原始颜色同色的像素点执行相同操作。</li>
29+
<li>通过检查与初始像素的原始颜色相同的相邻像素并修改其颜色来继续 <strong>重复</strong> 此过程。</li>
30+
<li>当 <strong>没有</strong> 其它原始颜色的相邻像素时 <strong>停止</strong> 操作。</li>
31+
</ol>
2732

28-
<p>最后返回 <em>经过上色渲染后的图像&nbsp;</em>。</p>
33+
<p>最后返回经过上色渲染&nbsp;<strong>修改</strong> 后的图像&nbsp;。</p>
2934

3035
<p>&nbsp;</p>
3136

3237
<p><strong>示例 1:</strong></p>
3338

3439
<p><img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0700-0799/0733.Flood%20Fill/images/flood1-grid.jpg" /></p>
3540

36-
<pre>
37-
<strong>输入:</strong> image = [[1,1,1],[1,1,0],[1,0,1]],sr = 1, sc = 1, color = 2
38-
<strong>输出:</strong> [[2,2,2],[2,2,0],[2,0,1]]
39-
<strong>解析:</strong> 在图像的正中间,(坐标(sr,sc)=(1,1)),在路径上所有符合条件的像素点的颜色都被更改成2。
40-
注意,右下角的像素没有更改为2,因为它不是在上下左右四个方向上与初始点相连的像素点。
41-
</pre>
41+
<div class="example-block"><strong>输入:</strong>image = [[1,1,1],[1,1,0],[1,0,1]],sr = 1, sc = 1, color = 2</div>
42+
43+
<div class="example-block"><strong>输出:</strong>[[2,2,2],[2,2,0],[2,0,1]]</div>
44+
45+
<div class="example-block"><b>解释:</b>在图像的正中间,坐标 <code>(sr,sc)=(1,1)</code>&nbsp;(即红色像素),在路径上所有符合条件的像素点的颜色都被更改成相同的新颜色(即蓝色像素)。</div>
46+
47+
<div class="example-block">注意,右下角的像素 <strong>没有</strong> 更改为2,因为它不是在上下左右四个方向上与初始点相连的像素点。</div>
48+
49+
<div class="example-block">&nbsp;</div>
4250

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

45-
<pre>
46-
<strong>输入:</strong> image = [[0,0,0],[0,0,0]], sr = 0, sc = 0, color = 0
47-
<strong>输出:</strong> [[0,0,0],[0,0,0]]
48-
</pre>
53+
<div class="example-block"><strong>输入:</strong>image = [[0,0,0],[0,0,0]], sr = 0, sc = 0, color = 0</div>
54+
55+
<div class="example-block"><strong>输出:</strong>[[0,0,0],[0,0,0]]</div>
56+
57+
<div class="example-block"><strong>解释:</strong>初始像素已经用 0 着色,这与目标颜色相同。因此,不会对图像进行任何更改。</div>
4958

5059
<p>&nbsp;</p>
5160

solution/1800-1899/1813.Sentence Similarity III/README.md

+31-23
Original file line numberDiff line numberDiff line change
@@ -20,49 +20,57 @@ tags:
2020

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

23-
<p>一个句子是由一些单词与它们之间的单个空格组成,且句子的开头和结尾没有多余空格。比方说,<code>"Hello World"</code> ,<code>"HELLO"</code> ,<code>"hello world hello world"</code> 都是句子。每个单词都 <strong></strong> 包含大写和小写英文字母。</p>
23+
<p>给定两个字符串&nbsp;<code>sentence1</code>&nbsp;&nbsp;<code>sentence2</code>,每个表示由一些单词组成的一个句子。句子是一系列由&nbsp;<strong>单个 </strong>空格分隔的&nbsp;<strong>单词</strong>,且开头和结尾没有多余空格。每个单词都只包含大写和小写英文字母。</p>
2424

25-
<p>如果两个句子 <code>sentence1</code> 和 <code>sentence2</code> ,可以通过往其中一个句子插入一个任意的句子(<strong>可以是空句子</strong>)而得到另一个句子,那么我们称这两个句子是 <strong>相似的</strong> 。比方说,<code>sentence1 = "Hello my name is Jane"</code> 且 <code>sentence2 = "Hello Jane"</code> ,我们可以往 <code>sentence2</code> 中 <code>"Hello"</code> 和 <code>"Jane"</code> 之间插入 <code>"my name is"</code> 得到 <code>sentence1</code> 。</p>
25+
<p>如果两个句子&nbsp;<code>s1</code>&nbsp;&nbsp;<code>s2</code>&nbsp;,可以通过往其中一个句子插入一个任意的句子(可以是空句子)而得到另一个句子,那么我们称这两个句子是 <strong>相似的</strong>&nbsp;。<strong>注意</strong>,插入的句子必须与现有单词用空白隔开。&nbsp;</p>
2626

27-
<p>给你两个句子 <code>sentence1</code> 和 <code>sentence2</code> ,如果<em> </em><code>sentence1</code> 和<em> </em><code>sentence2</code> 是相似的,请你返回 <code>true</code> ,否则返回 <code>false</code> 。</p>
27+
<p>比方说,</p>
2828

29-
<p> </p>
29+
<ul>
30+
<li><code>s1 = "Hello Jane"</code> 与&nbsp;<code>s2 = "Hello my name is Jane"</code>,我们可以往 <code>s1</code>&nbsp;中&nbsp;<code>"Hello"</code> 和&nbsp;<code>"Jane"</code>&nbsp;之间插入&nbsp;<code>"my name is"</code>&nbsp;得到 <code>s2</code>&nbsp;。</li>
31+
<li><code>s1 = "Frog cool"</code>&nbsp;与 <code>s2 = "Frogs are cool"</code>&nbsp;不是相似的,因为尽管往&nbsp;<code>s1</code>&nbsp;中插入&nbsp;<code>"s are"</code>,它没有与&nbsp;<code>"Frog"</code>&nbsp;用空格隔开。</li>
32+
</ul>
33+
34+
<p>给你两个句子&nbsp;<code>sentence1</code> 和&nbsp;<code>sentence2</code>&nbsp;,如果<em>&nbsp;</em><code>sentence1</code> 和<em>&nbsp;</em><code>sentence2</code> 是 <strong>相似</strong> 的,请你返回&nbsp;<code>true</code>&nbsp;,否则返回&nbsp;<code>false</code>&nbsp;。</p>
35+
36+
<p>&nbsp;</p>
3037

3138
<p><strong>示例 1:</strong></p>
3239

33-
<pre><b>输入:</b>sentence1 = "My name is Haley", sentence2 = "My Haley"
34-
<b>输出:</b>true
35-
<b>解释:</b>可以往 sentence2 中 "My" 和 "Haley" 之间插入 "name is" ,得到 sentence1 。
36-
</pre>
40+
<div class="example-block"><b>输入:</b>sentence1 = "My name is Haley", sentence2 = "My Haley"</div>
41+
42+
<div class="example-block"><b>输出:</b>true</div>
43+
44+
<div class="example-block"><b>解释:</b>可以往 <code>sentence2</code> 中 "My" 和 "Haley" 之间插入 "name is" ,得到 <code>sentence1</code> 。</div>
45+
46+
<div class="example-block">&nbsp;</div>
3747

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

40-
<pre><b>输入:</b>sentence1 = "of", sentence2 = "A lot of words"
41-
<b>输出:</b>false
42-
<strong>解释:</strong>没法往这两个句子中的一个句子只插入一个句子就得到另一个句子。
43-
</pre>
50+
<div class="example-block"><b>输入:</b>sentence1 = "of", sentence2 = "A lot of words"</div>
51+
52+
<div class="example-block"><b>输出:</b>false</div>
53+
54+
<div class="example-block"><strong>解释:</strong>没法往这两个句子中的一个句子只插入一个句子就得到另一个句子。</div>
55+
56+
<div class="example-block">&nbsp;</div>
4457

4558
<p><strong>示例 3:</strong></p>
4659

47-
<pre><b>输入:</b>sentence1 = "Eating right now", sentence2 = "Eating"
48-
<b>输出:</b>true
49-
<b>解释:</b>可以往 sentence2 的结尾插入 "right now" 得到 sentence1 。
50-
</pre>
60+
<div class="example-block"><b>输入:</b>sentence1 = "Eating right now", sentence2 = "Eating"</div>
5161

52-
<p><strong>示例 4:</strong></p>
62+
<div class="example-block"><b>输出:</b>true</div>
5363

54-
<pre><b>输入:</b>sentence1 = "Luky", sentence2 = "Lucccky"
55-
<b>输出:</b>false
56-
</pre>
64+
<div class="example-block"><b>解释:</b>可以往 <code>sentence2</code> 的结尾插入 "right now" 得到 <code>sentence1</code> 。</div>
5765

58-
<p> </p>
66+
<p>&nbsp;</p>
5967

6068
<p><strong>提示:</strong></p>
6169

6270
<ul>
6371
<li><code>1 &lt;= sentence1.length, sentence2.length &lt;= 100</code></li>
64-
<li><code>sentence1</code> 和 <code>sentence2</code> 都只包含大小写英文字母和空格。</li>
65-
<li><code>sentence1</code> 和 <code>sentence2</code> 中的单词都只由单个空格隔开。</li>
72+
<li><code>sentence1</code>&nbsp;和&nbsp;<code>sentence2</code>&nbsp;都只包含大小写英文字母和空格。</li>
73+
<li><code>sentence1</code>&nbsp;和&nbsp;<code>sentence2</code>&nbsp;中的单词都只由单个空格隔开。</li>
6674
</ul>
6775

6876
<!-- description:end -->

solution/1900-1999/1945.Sum of Digits of String After Convert/README.md

+48-20
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ tags:
1919

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

22-
<p>给你一个由小写字母组成的字符串 <code>s</code> ,以及一个整数 <code>k</code> 。</p>
22+
<p>给你一个由小写字母组成的字符串 <code>s</code> ,以及一个整数 <code>k</code> 。你的任务是通过一种特殊处理将字符串转为整数,然后通过重复对它的数位求和&nbsp;<code>k</code> 次来进行转换。更具体地说,执行以下步骤:</p>
2323

24-
<p>首先,用字母在字母表中的位置替换该字母,将 <code>s</code> <strong>转化</strong> 为一个整数(也就是,<code>'a'</code> 用 <code>1</code> 替换,<code>'b'</code> 用 <code>2</code> 替换,... <code>'z'</code> 用 <code>26</code> 替换)。接着,将整数 <strong>转换</strong> 为其 <strong>各位数字之和</strong> 。共重复 <strong>转换</strong> 操作 <strong><code>k</code> 次</strong> 。</p>
24+
<ol>
25+
<li>用字母在字母表中的位置&nbsp;<strong>替换&nbsp;</strong>该字母,将 <code>s</code> <strong>转化</strong> 为一个整数(也就是,<code>'a'</code> 用 <code>1</code> 替换,<code>'b'</code> 用 <code>2</code> 替换,... <code>'z'</code> 用 <code>26</code> 替换)。</li>
26+
<li>接着,将整数 <strong>转换</strong> 为其 <strong>各位数字之和</strong> 。</li>
27+
<li>共重复 <strong>转换</strong> 操作(第 2 步)&nbsp;<code>k</code><strong> 次</strong> 。</li>
28+
</ol>
2529

2630
<p>例如,如果 <code>s = "zbax"</code> 且 <code>k = 2</code> ,那么执行下述步骤后得到的结果是整数 <code>8</code> :</p>
2731

@@ -31,32 +35,56 @@ tags:
3135
<li><strong>转换 #2</strong>:<code>17 ➝ 1 + 7 ➝ 8</code></li>
3236
</ul>
3337

34-
<p>返回执行上述操作后得到的结果整数。</p>
38+
<p>返回执行上述 <strong>操作</strong> 后得到的 <strong>结果整数</strong>。</p>
3539

3640
<p>&nbsp;</p>
3741

3842
<p><strong>示例 1:</strong></p>
3943

40-
<pre>
41-
<strong>输入:</strong>s = "iiii", k = 1
42-
<strong>输出:</strong>36
43-
<strong>解释:</strong>操作如下:
44-
- 转化:"iiii" ➝ "(9)(9)(9)(9)" ➝ "9999" ➝ 9999
45-
- 转换 #1:9999 ➝ 9 + 9 + 9 + 9 ➝ 36
46-
因此,结果整数为 36 。
47-
</pre>
44+
<div class="example-block"><strong>输入:</strong>s = "iiii", k = 1</div>
45+
46+
<div class="example-block"><strong>输出:</strong>36</div>
47+
48+
<div class="example-block"><strong>解释:</strong></div>
49+
50+
<div class="example-block">操作如下:</div>
51+
52+
<ul>
53+
<li class="example-block">转化:"iiii" ➝ "(9)(9)(9)(9)" ➝ "9999" ➝ 9999</li>
54+
<li class="example-block">转换 #1:9999 ➝ 9 + 9 + 9 + 9 ➝ 36</li>
55+
</ul>
56+
57+
<div class="example-block">因此,结果整数为 36 。</div>
58+
59+
<div class="example-block">&nbsp;</div>
4860

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

51-
<pre>
52-
<strong>输入:</strong>s = "leetcode", k = 2
53-
<strong>输出:</strong>6
54-
<strong>解释:</strong>操作如下:
55-
- 转化:"leetcode" ➝ "(12)(5)(5)(20)(3)(15)(4)(5)" ➝ "12552031545" ➝ 12552031545
56-
- 转换 #1:12552031545 ➝ 1 + 2 + 5 + 5 + 2 + 0 + 3 + 1 + 5 + 4 + 5 ➝ 33
57-
- 转换 #2:33 ➝ 3 + 3 ➝ 6
58-
因此,结果整数为 6 。
59-
</pre>
63+
<div class="example-block"><strong>输入:</strong>s = "leetcode", k = 2</div>
64+
65+
<div class="example-block"><strong>输出:</strong>6</div>
66+
67+
<div class="example-block"><strong>解释:</strong></div>
68+
69+
<div class="example-block">操作如下:</div>
70+
71+
<ul>
72+
<li class="example-block">转化:"leetcode" ➝ "(12)(5)(5)(20)(3)(15)(4)(5)" ➝ "12552031545" ➝ 12552031545</li>
73+
<li class="example-block">转换 #1:12552031545 ➝ 1 + 2 + 5 + 5 + 2 + 0 + 3 + 1 + 5 + 4 + 5 ➝ 33</li>
74+
<li class="example-block">转换 #2:33 ➝ 3 + 3 ➝ 6</li>
75+
</ul>
76+
77+
<p class="example-block">因此,结果整数为 6 。</p>
78+
79+
<p class="example-block">&nbsp;</p>
80+
81+
<p><strong class="example">示例 3:</strong></p>
82+
83+
<div class="example-block">
84+
<p><strong>输入:</strong><span class="example-io">s = "zbax", k = 2</span></p>
85+
86+
<p><span class="example-io"><b>输出:</b>8</span></p>
87+
</div>
6088

6189
<p>&nbsp;</p>
6290

0 commit comments

Comments
 (0)