Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8a4905e

Browse files
authored
feat: update lc problems (doocs#4097)
1 parent c73dfce commit 8a4905e

File tree

50 files changed

+478
-126
lines changed

Some content is hidden

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

50 files changed

+478
-126
lines changed

solution/0200-0299/0254.Factor Combinations/README.md

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ tags:
2020

2121
<p>例如:</p>
2222

23-
<pre>8 = 2 x 2 x 2;
23+
<pre>
24+
8 = 2 x 2 x 2;
2425
= 2 x 4.</pre>
2526

2627
<p>请实现一个函数,该函数接收一个整数 <em>n</em>&nbsp;并返回该整数所有的因子组合。</p>
@@ -34,18 +35,21 @@ tags:
3435

3536
<p><strong>示例 1:</strong></p>
3637

37-
<pre><strong>输入: </strong><code>1</code>
38+
<pre>
39+
<strong>输入: </strong><code>1</code>
3840
<strong>输出: </strong>[]
3941
</pre>
4042

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

43-
<pre><strong>输入: </strong><code>37</code>
45+
<pre>
46+
<strong>输入: </strong><code>37</code>
4447
<strong>输出: </strong>[]</pre>
4548

4649
<p><strong>示例 3:</strong></p>
4750

48-
<pre><strong>输入: </strong><code>12</code>
51+
<pre>
52+
<strong>输入: </strong><code>12</code>
4953
<strong>输出:</strong>
5054
[
5155
[2, 6],
@@ -55,7 +59,8 @@ tags:
5559

5660
<p><strong>示例 4: </strong></p>
5761

58-
<pre><strong>输入: </strong><code>32</code>
62+
<pre>
63+
<strong>输入: </strong><code>32</code>
5964
<strong>输出:</strong>
6065
[
6166
[2, 16],
@@ -67,6 +72,14 @@ tags:
6772
]
6873
</pre>
6974

75+
<p>&nbsp;</p>
76+
77+
<p><b>提示:</b></p>
78+
79+
<ul>
80+
<li><code>1 &lt;= n &lt;= 10<sup>7</sup></code></li>
81+
</ul>
82+
7083
<!-- description:end -->
7184

7285
## 解法

solution/0200-0299/0262.Trips and Users/README_EN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ banned is an ENUM (category) type of (&#39;Yes&#39;, &#39;No&#39;).
5555

5656
<p>The <strong>cancellation rate</strong> is computed by dividing the number of canceled (by client or driver) requests with unbanned users by the total number of requests with unbanned users on that day.</p>
5757

58-
<p>Write a solution to find the <strong>cancellation rate</strong> of requests with unbanned users (<strong>both client and driver must not be banned</strong>) each day between <code>&quot;2013-10-01&quot;</code> and <code>&quot;2013-10-03&quot;</code>. Round <code>Cancellation Rate</code> to <strong>two decimal</strong> points.</p>
58+
<p>Write a solution to find the <strong>cancellation rate</strong> of requests with unbanned users (<strong>both client and driver must not be banned</strong>) each day between <code>&quot;2013-10-01&quot;</code> and <code>&quot;2013-10-03&quot;</code> with <strong>at least</strong> one trip. Round <code>Cancellation Rate</code> to <strong>two decimal</strong> points.</p>
5959

6060
<p>Return the result table in <strong>any order</strong>.</p>
6161

solution/0700-0799/0720.Longest Word in Dictionary/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ tags:
4141
<pre>
4242
<strong>输入:</strong>words = ["a", "banana", "app", "appl", "ap", "apply", "apple"]
4343
<strong>输出:</strong>"apple"
44-
<strong>解释:</strong>"apply" 和 "apple" 都能由词典中的单词组成。但是 "apple" 的字典序小于 "apply"
44+
<strong>解释:</strong>"apply" 和 "apple" 都能由词典中的单词组成。但是 "apple" 的字典序小于 "apply"
4545
</pre>
4646

4747
<p>&nbsp;</p>

solution/0700-0799/0722.Remove Comments/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,20 @@ tags:
5959
<strong>解释:</strong> 示例代码可以编排成这样:
6060
/*Test program */
6161
int main()
62-
{
63-
// variable declaration
62+
{
63+
// variable declaration
6464
int a, b, c;
6565
/* This is a test
66-
multiline
67-
comment for
66+
multiline
67+
comment for
6868
testing */
6969
a = b + c;
7070
}
7171
第 1 行和第 6-9 行的字符串 /* 表示块注释。第 4 行的字符串 // 表示行注释。
72-
编排后:
72+
编排后:
7373
int main()
74-
{
75-
74+
{
75+
7676
int a, b, c;
7777
a = b + c;
7878
}</pre>

solution/0700-0799/0722.Remove Comments/README_EN.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,20 @@ tags:
5858
<strong>Explanation:</strong> The line by line code is visualized as below:
5959
/*Test program */
6060
int main()
61-
{
62-
// variable declaration
61+
{
62+
// variable declaration
6363
int a, b, c;
6464
/* This is a test
65-
multiline
66-
comment for
65+
multiline
66+
comment for
6767
testing */
6868
a = b + c;
6969
}
7070
The string /* denotes a block comment, including line 1 and lines 6-9. The string // denotes line 4 as comments.
7171
The line by line output code is visualized as below:
7272
int main()
73-
{
74-
73+
{
74+
7575
int a, b, c;
7676
a = b + c;
7777
}

solution/0700-0799/0727.Minimum Window Subsequence/README_EN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ tags:
2828
<pre>
2929
<strong>Input:</strong> s1 = &quot;abcdebdde&quot;, s2 = &quot;bde&quot;
3030
<strong>Output:</strong> &quot;bcde&quot;
31-
<strong>Explanation:</strong>
31+
<strong>Explanation:</strong>
3232
&quot;bcde&quot; is the answer because it occurs before &quot;bdde&quot; which has the same length.
3333
&quot;deb&quot; is not a smaller window because the elements of s2 in the window must occur in order.
3434
</pre>

solution/0700-0799/0763.Partition Labels/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ tags:
1919

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

22-
<p>给你一个字符串 <code>s</code> 。我们要把这个字符串划分为尽可能多的片段,同一字母最多出现在一个片段中。</p>
22+
<p>给你一个字符串 <code>s</code> 。我们要把这个字符串划分为尽可能多的片段,同一字母最多出现在一个片段中。例如,字符串&nbsp;<code>"ababcc"</code> 能够被分为 <code>["abab", "cc"]</code>,但类似&nbsp;<code>["aba", "bcc"]</code> 或&nbsp;<code>["ab", "ab", "cc"]</code> 的划分是非法的。</p>
2323

2424
<p>注意,划分结果需要满足:将所有划分结果按顺序连接,得到的字符串仍然是 <code>s</code> 。</p>
2525

solution/0800-0899/0801.Minimum Swaps To Make Sequences Increasing/README_EN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ tags:
3333
<pre>
3434
<strong>Input:</strong> nums1 = [1,3,5,4], nums2 = [1,2,3,7]
3535
<strong>Output:</strong> 1
36-
<strong>Explanation:</strong>
36+
<strong>Explanation:</strong>
3737
Swap nums1[3] and nums2[3]. Then the sequences are:
3838
nums1 = [1, 3, 5, 7] and nums2 = [1, 2, 3, 4]
3939
which are both strictly increasing.

solution/0800-0899/0850.Rectangle Area II/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ tags:
1919

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

22-
<p>给你一个轴对齐的二维数组&nbsp;<code>rectangles</code>&nbsp;。 对于&nbsp;<code>rectangle[i] = [x1, y1, x2, y2]</code>,其中(x1,y1)是矩形&nbsp;<code>i</code>&nbsp;左下角的坐标,<meta charset="UTF-8" />&nbsp;<code>(x<sub>i1</sub>, y<sub>i1</sub>)</code>&nbsp;是该矩形 <strong>左下角</strong> 的坐标,<meta charset="UTF-8" />&nbsp;<code>(x<sub>i2</sub>, y<sub>i2</sub>)</code>&nbsp;是该矩形&nbsp;<strong>右上角</strong> 的坐标。</p>
22+
<p>给你一个轴对齐的二维数组&nbsp;<code>rectangles</code>&nbsp;。 对于&nbsp;<code>rectangle[i] = [x1, y1, x2, y2]</code>,其中&nbsp;<code>(x<sub>i1</sub>, y<sub>i1</sub>)</code>&nbsp;是该矩形 <strong>左下角</strong> 的坐标,<meta charset="UTF-8" />&nbsp;<code>(x<sub>i2</sub>, y<sub>i2</sub>)</code>&nbsp;是该矩形&nbsp;<strong>右上角</strong> 的坐标。</p>
2323

2424
<p>计算平面中所有&nbsp;<code>rectangles</code>&nbsp;所覆盖的 <strong>总面积 </strong>。任何被两个或多个矩形覆盖的区域应只计算 <strong>一次</strong> 。</p>
2525

solution/1400-1499/1408.String Matching in an Array/README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@ tags:
2020

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

23-
<p>给你一个字符串数组 <code>words</code> ,数组中的每个字符串都可以看作是一个单词。请你按 <strong>任意</strong> 顺序返回 <code>words</code> 中是其他单词的子字符串的所有单词。</p>
24-
25-
<p>如果你可以删除 <code>words[j]</code>&nbsp;最左侧和/或最右侧的若干字符得到 <code>words[i]</code> ,那么字符串 <code>words[i]</code> 就是 <code>words[j]</code> 的一个子字符串。</p>
23+
<p>给你一个字符串数组 <code>words</code> ,数组中的每个字符串都可以看作是一个单词。请你按 <strong>任意</strong> 顺序返回 <code>words</code> 中是其他单词的 <span data-keyword="substring-nonempty">子字符串</span> 的所有单词。</p>
2624

2725
<p>&nbsp;</p>
2826

29-
<p><strong>示例 1:</strong></p>
27+
<p><strong class="example">示例 1:</strong></p>
3028

3129
<pre>
3230
<strong>输入:</strong>words = ["mass","as","hero","superhero"]
@@ -35,15 +33,15 @@ tags:
3533
["hero","as"] 也是有效的答案。
3634
</pre>
3735

38-
<p><strong>示例 2:</strong></p>
36+
<p><strong class="example">示例 2:</strong></p>
3937

4038
<pre>
4139
<strong>输入:</strong>words = ["leetcode","et","code"]
4240
<strong>输出:</strong>["et","code"]
4341
<strong>解释:</strong>"et" 和 "code" 都是 "leetcode" 的子字符串。
4442
</pre>
4543

46-
<p><strong>示例 3:</strong></p>
44+
<p><strong class="example">示例 3:</strong></p>
4745

4846
<pre>
4947
<strong>输入:</strong>words = ["blue","green","bu"]
@@ -58,7 +56,7 @@ tags:
5856
<li><code>1 &lt;= words.length &lt;= 100</code></li>
5957
<li><code>1 &lt;= words[i].length &lt;= 30</code></li>
6058
<li><code>words[i]</code> 仅包含小写英文字母。</li>
61-
<li>题目数据 <strong>保证</strong> 每个 <code>words[i]</code> 都是独一无二的。</li>
59+
<li>题目数据 <strong>保证</strong> <code>words</code>&nbsp;的每个字符串都是独一无二的。</li>
6260
</ul>
6361

6462
<!-- description:end -->

solution/1700-1799/1718.Construct the Lexicographically Largest Valid Sequence/README_EN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ tags:
1919

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

22-
<p>Given an integer <code>n</code>, find a sequence that satisfies all of the following:</p>
22+
<p>Given an integer <code>n</code>, find a sequence with elements in the range <code>[1, n]</code> that satisfies all of the following:</p>
2323

2424
<ul>
2525
<li>The integer <code>1</code> occurs once in the sequence.</li>

solution/1700-1799/1730.Shortest Path to Get Food/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ tags:
5555
<strong>输出:</strong> 6
5656
<strong>解释:</strong> 这里有多个食物。拿到下边的食物仅需走 6 步。</pre>
5757

58+
<p><strong class="example">示例 4:</strong></p>
59+
60+
<pre>
61+
<b>输入:</b>grid = [["X","X","X","X","X","X","X","X"],["X","*","O","X","O","#","O","X"],["X","O","O","X","O","O","X","X"],["X","O","O","O","O","#","O","X"],["O","O","O","O","O","O","O","O"]]
62+
<b>输出:</b>5</pre>
63+
5864
<p>&nbsp;</p>
5965

6066
<p><b>提示:</b></p>

solution/1700-1799/1752.Check if Array Is Sorted and Rotated/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ tags:
2424

2525
<p>源数组中可能存在 <strong>重复项</strong> 。</p>
2626

27-
<p><strong>注意:</strong>我们称数组 <code>A</code> 在轮转 <code>x</code> 个位置后得到长度相同的数组 <code>B</code> ,当它们满足 <code>A[i] == B[(i+x) % A.length]</code> ,其中 <code>%</code> 为取余运算。</p>
27+
<p><strong>注意:</strong>数组 <code>A</code> 在轮转 <code>x</code> 个位置后得到长度相同的数组 <code>B</code> ,使得对于每一个有效的下标&nbsp;<code>i</code>,满足&nbsp;<code>B[i] == A[(i+x) % A.length]</code>。</p>
2828

2929
<p>&nbsp;</p>
3030

solution/1800-1899/1800.Maximum Ascending Subarray Sum/README.md

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ tags:
1818

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

21-
<p>给你一个正整数组成的数组 <code>nums</code> ,返回 <code>nums</code> 中一个 <strong>升序 </strong>子数组的最大可能元素和。</p>
21+
<p>给你一个正整数组成的数组 <code>nums</code> ,返回 <code>nums</code> 中一个 <span data-keyword="strictly-increasing-array">严格递增子数组</span> 的最大可能元素和。</p>
2222

2323
<p>子数组是数组中的一个连续数字序列。</p>
2424

25-
<p>已知子数组 <code>[nums<sub>l</sub>, nums<sub>l+1</sub>, ..., nums<sub>r-1</sub>, nums<sub>r</sub>]</code> ,若对所有 <code>i</code>(<code>l <= i < r</code>),<code>nums<sub>i </sub> < nums<sub>i+1</sub></code> 都成立,则称这一子数组为 <strong>升序</strong> 子数组。注意,大小为 <code>1</code> 的子数组也视作 <strong>升序</strong> 子数组。</p>
26-
27-
<p> </p>
25+
<p>&nbsp;</p>
2826

2927
<p><strong>示例 1:</strong></p>
3028

@@ -50,20 +48,13 @@ tags:
5048
<strong>解释:</strong>[10,11,12] 是元素和最大的升序子数组,最大元素和为 33 。
5149
</pre>
5250

53-
<p><strong>示例 4:</strong></p>
54-
55-
<pre>
56-
<strong>输入:</strong>nums = [100,10,1]
57-
<strong>输出:</strong>100
58-
</pre>
59-
60-
<p> </p>
51+
<p>&nbsp;</p>
6152

6253
<p><strong>提示:</strong></p>
6354

6455
<ul>
65-
<li><code>1 <= nums.length <= 100</code></li>
66-
<li><code>1 <= nums[i] <= 100</code></li>
56+
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
57+
<li><code>1 &lt;= nums[i] &lt;= 100</code></li>
6758
</ul>
6859

6960
<!-- description:end -->

solution/1800-1899/1852.Distinct Numbers in Each Subarray/README.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ tags:
1818

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

21-
<p>给你一个整数数组&nbsp;<code>nums</code>与一个整数 <code>k</code>,请你构造一个长度 <code>n-k+1</code> 的数组 <code>ans</code>,这个数组第<code>i</code>个元素 <code>ans[i]</code> 是每个长度为k的子数组 <code>nums[i:i+k-1] = [nums[i], nums[i+1], ..., nums[i+k-1]]</code>中数字的种类数。</p>
21+
<p>给你一个长度为&nbsp;<code>n</code>&nbsp;的整数数组&nbsp;<code>nums</code>&nbsp;与一个整数 <code>k</code>。你的任务是找到&nbsp;<code>nums</code>&nbsp;<strong>所有</strong>&nbsp;长度为&nbsp;<code>k</code>&nbsp;的子数组中&nbsp;<strong>不同</strong>&nbsp;元素的数量。</p>
2222

23-
<p>返回这个数组 <code>ans</code>。</p>
23+
<p>返回一个数组 <code>ans</code>,其中&nbsp;<code>ans[i]</code>&nbsp;是对于每个索引&nbsp;<code>0 &lt;= i &lt; n - k</code>,<code>nums[i..(i + k - 1)]</code>&nbsp;中不同元素的数量。</p>
24+
25+
<p>&nbsp;</p>
2426

2527
<p>&nbsp;</p>
2628

@@ -30,11 +32,11 @@ tags:
3032
<strong>输入:</strong> nums = [1,2,3,2,2,1,3], k = 3
3133
<strong>输出:</strong> [3,2,2,2,3]
3234
<b>解释</b>:每个子数组的数字种类计算方法如下:
33-
- nums[0:2] = [1,2,3] 所以 ans[0] = 3
34-
- nums[1:3] = [2,3,2] 所以 ans[1] = 2
35-
- nums[2:4] = [3,2,2] 所以 ans[2] = 2
36-
- nums[3:5] = [2,2,1] 所以 ans[3] = 2
37-
- nums[4:6] = [2,1,3] 所以 ans[4] = 3
35+
- nums[0..2] = [1,2,3] 所以 ans[0] = 3
36+
- nums[1..3] = [2,3,2] 所以 ans[1] = 2
37+
- nums[2..4] = [3,2,2] 所以 ans[2] = 2
38+
- nums[3..5] = [2,2,1] 所以 ans[3] = 2
39+
- nums[4..6] = [2,1,3] 所以 ans[4] = 3
3840
</pre>
3941

4042
<p><strong>示例&nbsp;2:</strong></p>
@@ -43,10 +45,10 @@ tags:
4345
<strong>输入:</strong> nums = [1,1,1,1,2,3,4], k = 4
4446
<strong>输出:</strong> [1,2,3,4]
4547
<strong>解释: </strong>每个子数组的数字种类计算方法如下:
46-
- nums[0:3] = [1,1,1,1] 所以 ans[0] = 1
47-
- nums[1:4] = [1,1,1,2] 所以 ans[1] = 2
48-
- nums[2:5] = [1,1,2,3] 所以 ans[2] = 3
49-
- nums[3:6] = [1,2,3,4] 所以 ans[3] = 4
48+
- nums[0..3] = [1,1,1,1] 所以 ans[0] = 1
49+
- nums[1..4] = [1,1,1,2] 所以 ans[1] = 2
50+
- nums[2..5] = [1,1,2,3] 所以 ans[2] = 3
51+
- nums[3..6] = [1,2,3,4] 所以 ans[3] = 4
5052
</pre>
5153

5254
<p>&nbsp;</p>

solution/1900-1999/1944.Number of Visible People in a Queue/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ tags:
7272

7373
我们观察发现,对于第 $i$ 个人来说,他能看到的人一定是按从左到右高度严格单调递增的。
7474

75-
因此,我们可以倒序遍历数组 $heights$,用一个从栈顶到栈底单调递增的栈 $stk$ 记录已经遍历过的人的高度。
75+
因此,我们可以倒序遍历数组 $\textit{heights}$,用一个从栈顶到栈底单调递增的栈 $\textit{stk}$ 记录已经遍历过的人的高度。
7676

77-
对于第 $i$ 个人,如果栈不为空并且栈顶元素小于 $heights[i]$,累加当前第 $i$ 个人能看到的人数,然后将栈顶元素出栈,直到栈为空或者栈顶元素大于等于 $heights[i]$。如果此时栈不为空,说明栈顶元素大于等于 $heights[i]$,那么第 $i$ 个人能看到的人数还要再加 $1$。
77+
对于第 $i$ 个人,如果栈不为空并且栈顶元素小于 $\textit{heights}[i]$,累加当前第 $i$ 个人能看到的人数,然后将栈顶元素出栈,直到栈为空或者栈顶元素大于等于 $\textit{heights}[i]$。如果此时栈不为空,说明栈顶元素大于等于 $\textit{heights}[i]$,那么第 $i$ 个人能看到的人数还要再加 $1$。
7878

79-
接下来,我们将 $heights[i]$ 入栈,继续遍历下一个人。
79+
接下来,我们将 $\textit{heights}[i]$ 入栈,继续遍历下一个人。
8080

81-
遍历结束后,返回答案数组 $ans$。
81+
遍历结束后,返回答案数组 $\textit{ans}$。
8282

83-
时间复杂度 $O(n)$,空间复杂度 $O(n)$。其中 $n$ 是数组 $heights$ 的长度。
83+
时间复杂度 $O(n)$,空间复杂度 $O(n)$。其中 $n$ 是数组 $\textit{heights}$ 的长度。
8484

8585
相似题目:
8686

solution/1900-1999/1944.Number of Visible People in a Queue/README_EN.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,19 @@ Person 5 can see no one since nobody is to the right of them.
6666

6767
<!-- solution:start -->
6868

69-
### Solution 1
69+
### Solution 1: Monotonic Stack
70+
71+
We observe that for the $i$-th person, the people he can see must be strictly increasing in height from left to right.
72+
73+
Therefore, we can traverse the array $\textit{heights}$ in reverse order, using a stack $\textit{stk}$ that is monotonically increasing from top to bottom to record the heights of the people we have traversed.
74+
75+
For the $i$-th person, if the stack is not empty and the top element of the stack is less than $\textit{heights}[i]$, we increment the count of people the $i$-th person can see, then pop the top element of the stack, until the stack is empty or the top element of the stack is greater than or equal to $\textit{heights}[i]$. If the stack is not empty at this point, it means the top element of the stack is greater than or equal to $\textit{heights}[i]$, so we increment the count of people the $i$-th person can see by 1.
76+
77+
Next, we push $\textit{heights}[i]$ onto the stack and continue to the next person.
78+
79+
After traversing, we return the answer array $\textit{ans}$.
80+
81+
The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is the length of the array $\textit{heights}$.
7082

7183
<!-- tabs:start -->
7284

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,15 @@ class Solution {
151151
public:
152152
int getLucky(string s, int k) {
153153
string t;
154-
for (char c : s) t += to_string(c - 'a' + 1);
154+
for (char c : s) {
155+
t += to_string(c - 'a' + 1);
156+
}
155157
s = t;
156158
while (k--) {
157159
int t = 0;
158-
for (char c : s) t += c - '0';
160+
for (char c : s) {
161+
t += c - '0';
162+
}
159163
s = to_string(t);
160164
}
161165
return stoi(s);

0 commit comments

Comments
 (0)