Skip to content

Commit ab59941

Browse files
authored
Merge branch 'doocs:main' into main
2 parents 9d7b867 + add0319 commit ab59941

File tree

125 files changed

+5203
-423
lines changed

Some content is hidden

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

125 files changed

+5203
-423
lines changed

solution/0100-0199/0195.Tenth Line/README_EN.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,41 @@ tags:
2323
<p>Assume that <code>file.txt</code> has the following content:</p>
2424

2525
<pre>
26+
2627
Line 1
28+
2729
Line 2
30+
2831
Line 3
32+
2933
Line 4
34+
3035
Line 5
36+
3137
Line 6
38+
3239
Line 7
40+
3341
Line 8
42+
3443
Line 9
44+
3545
Line 10
46+
3647
</pre>
3748

3849
<p>Your script should output the tenth line, which is:</p>
3950

4051
<pre>
52+
4153
Line 10
54+
4255
</pre>
4356

4457
<div class="spoilers"><b>Note:</b><br />
58+
4559
1. If the file contains less than 10 lines, what should you output?<br />
60+
4661
2. There&#39;s at least three different solutions. Try to explore all possibilities.</div>
4762

4863
<!-- description:end -->

solution/0200-0299/0281.Zigzag Iterator/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,54 @@ public class ZigzagIterator {
149149
*/
150150
```
151151

152+
#### Go
153+
154+
```go
155+
type ZigzagIterator struct {
156+
cur int
157+
size int
158+
indexes []int
159+
vectors [][]int
160+
}
161+
162+
func Constructor(v1, v2 []int) *ZigzagIterator {
163+
return &ZigzagIterator{
164+
cur: 0,
165+
size: 2,
166+
indexes: []int{0, 0},
167+
vectors: [][]int{v1, v2},
168+
}
169+
}
170+
171+
func (this *ZigzagIterator) next() int {
172+
vector := this.vectors[this.cur]
173+
index := this.indexes[this.cur]
174+
res := vector[index]
175+
this.indexes[this.cur]++
176+
this.cur = (this.cur + 1) % this.size
177+
return res
178+
}
179+
180+
func (this *ZigzagIterator) hasNext() bool {
181+
start := this.cur
182+
for this.indexes[this.cur] == len(this.vectors[this.cur]) {
183+
this.cur = (this.cur + 1) % this.size
184+
if start == this.cur {
185+
return false
186+
}
187+
}
188+
return true
189+
}
190+
191+
/**
192+
* Your ZigzagIterator object will be instantiated and called as such:
193+
* obj := Constructor(param_1, param_2);
194+
* for obj.hasNext() {
195+
* ans = append(ans, obj.next())
196+
* }
197+
*/
198+
```
199+
152200
#### Rust
153201

154202
```rust

solution/0200-0299/0281.Zigzag Iterator/README_EN.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,54 @@ public class ZigzagIterator {
163163
*/
164164
```
165165

166+
#### Go
167+
168+
```go
169+
type ZigzagIterator struct {
170+
cur int
171+
size int
172+
indexes []int
173+
vectors [][]int
174+
}
175+
176+
func Constructor(v1, v2 []int) *ZigzagIterator {
177+
return &ZigzagIterator{
178+
cur: 0,
179+
size: 2,
180+
indexes: []int{0, 0},
181+
vectors: [][]int{v1, v2},
182+
}
183+
}
184+
185+
func (this *ZigzagIterator) next() int {
186+
vector := this.vectors[this.cur]
187+
index := this.indexes[this.cur]
188+
res := vector[index]
189+
this.indexes[this.cur]++
190+
this.cur = (this.cur + 1) % this.size
191+
return res
192+
}
193+
194+
func (this *ZigzagIterator) hasNext() bool {
195+
start := this.cur
196+
for this.indexes[this.cur] == len(this.vectors[this.cur]) {
197+
this.cur = (this.cur + 1) % this.size
198+
if start == this.cur {
199+
return false
200+
}
201+
}
202+
return true
203+
}
204+
205+
/**
206+
* Your ZigzagIterator object will be instantiated and called as such:
207+
* obj := Constructor(param_1, param_2);
208+
* for obj.hasNext() {
209+
* ans = append(ans, obj.next())
210+
* }
211+
*/
212+
```
213+
166214
#### Rust
167215

168216
```rust
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
type ZigzagIterator struct {
2+
cur int
3+
size int
4+
indexes []int
5+
vectors [][]int
6+
}
7+
8+
func Constructor(v1, v2 []int) *ZigzagIterator {
9+
return &ZigzagIterator{
10+
cur: 0,
11+
size: 2,
12+
indexes: []int{0, 0},
13+
vectors: [][]int{v1, v2},
14+
}
15+
}
16+
17+
func (this *ZigzagIterator) next() int {
18+
vector := this.vectors[this.cur]
19+
index := this.indexes[this.cur]
20+
res := vector[index]
21+
this.indexes[this.cur]++
22+
this.cur = (this.cur + 1) % this.size
23+
return res
24+
}
25+
26+
func (this *ZigzagIterator) hasNext() bool {
27+
start := this.cur
28+
for this.indexes[this.cur] == len(this.vectors[this.cur]) {
29+
this.cur = (this.cur + 1) % this.size
30+
if start == this.cur {
31+
return false
32+
}
33+
}
34+
return true
35+
}
36+
37+
/**
38+
* Your ZigzagIterator object will be instantiated and called as such:
39+
* obj := Constructor(param_1, param_2);
40+
* for obj.hasNext() {
41+
* ans = append(ans, obj.next())
42+
* }
43+
*/

solution/0700-0799/0799.Champagne Tower/README_EN.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,51 @@ tags:
2727
<p>Now after pouring some non-negative integer cups of champagne, return how full the <code>j<sup>th</sup></code> glass in the <code>i<sup>th</sup></code> row is (both <code>i</code> and <code>j</code> are 0-indexed.)</p>
2828

2929
<p>&nbsp;</p>
30+
3031
<p><strong class="example">Example 1:</strong></p>
3132

3233
<pre>
34+
3335
<strong>Input:</strong> poured = 1, query_row = 1, query_glass = 1
36+
3437
<strong>Output:</strong> 0.00000
38+
3539
<strong>Explanation:</strong> We poured 1 cup of champange to the top glass of the tower (which is indexed as (0, 0)). There will be no excess liquid so all the glasses under the top glass will remain empty.
40+
3641
</pre>
3742

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

4045
<pre>
46+
4147
<strong>Input:</strong> poured = 2, query_row = 1, query_glass = 1
48+
4249
<strong>Output:</strong> 0.50000
50+
4351
<strong>Explanation:</strong> We poured 2 cups of champange to the top glass of the tower (which is indexed as (0, 0)). There is one cup of excess liquid. The glass indexed as (1, 0) and the glass indexed as (1, 1) will share the excess liquid equally, and each will get half cup of champange.
52+
4453
</pre>
4554

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

4857
<pre>
58+
4959
<strong>Input:</strong> poured = 100000009, query_row = 33, query_glass = 17
60+
5061
<strong>Output:</strong> 1.00000
62+
5163
</pre>
5264

5365
<p>&nbsp;</p>
66+
5467
<p><strong>Constraints:</strong></p>
5568

5669
<ul>
57-
<li><code>0 &lt;=&nbsp;poured &lt;= 10<sup>9</sup></code></li>
58-
<li><code>0 &lt;= query_glass &lt;= query_row&nbsp;&lt; 100</code></li>
70+
71+
<li><code>0 &lt;=&nbsp;poured &lt;= 10<sup>9</sup></code></li>
72+
73+
<li><code>0 &lt;= query_glass &lt;= query_row&nbsp;&lt; 100</code></li>
74+
5975
</ul>
6076

6177
<!-- description:end -->

solution/1100-1199/1108.Defanging an IP Address/README_EN.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,29 @@ tags:
2323
<p>A <em>defanged&nbsp;IP address</em>&nbsp;replaces every period <code>&quot;.&quot;</code> with <code>&quot;[.]&quot;</code>.</p>
2424

2525
<p>&nbsp;</p>
26+
2627
<p><strong class="example">Example 1:</strong></p>
28+
2729
<pre><strong>Input:</strong> address = "1.1.1.1"
30+
2831
<strong>Output:</strong> "1[.]1[.]1[.]1"
32+
2933
</pre><p><strong class="example">Example 2:</strong></p>
34+
3035
<pre><strong>Input:</strong> address = "255.100.50.0"
36+
3137
<strong>Output:</strong> "255[.]100[.]50[.]0"
38+
3239
</pre>
40+
3341
<p>&nbsp;</p>
42+
3443
<p><strong>Constraints:</strong></p>
3544

3645
<ul>
37-
<li>The given <code>address</code> is a valid IPv4 address.</li>
46+
47+
<li>The given <code>address</code> is a valid IPv4 address.</li>
48+
3849
</ul>
3950

4051
<!-- description:end -->

solution/1100-1199/1111.Maximum Nesting Depth of Two Valid Parentheses Strings/README_EN.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,25 @@ tags:
2222
<p>A string is a <em>valid parentheses string</em>&nbsp;(denoted VPS) if and only if it consists of <code>&quot;(&quot;</code> and <code>&quot;)&quot;</code> characters only, and:</p>
2323

2424
<ul>
25-
<li>It is the empty string, or</li>
26-
<li>It can be written as&nbsp;<code>AB</code>&nbsp;(<code>A</code>&nbsp;concatenated with&nbsp;<code>B</code>), where&nbsp;<code>A</code>&nbsp;and&nbsp;<code>B</code>&nbsp;are VPS&#39;s, or</li>
27-
<li>It can be written as&nbsp;<code>(A)</code>, where&nbsp;<code>A</code>&nbsp;is a VPS.</li>
25+
26+
<li>It is the empty string, or</li>
27+
28+
<li>It can be written as&nbsp;<code>AB</code>&nbsp;(<code>A</code>&nbsp;concatenated with&nbsp;<code>B</code>), where&nbsp;<code>A</code>&nbsp;and&nbsp;<code>B</code>&nbsp;are VPS&#39;s, or</li>
29+
30+
<li>It can be written as&nbsp;<code>(A)</code>, where&nbsp;<code>A</code>&nbsp;is a VPS.</li>
31+
2832
</ul>
2933

3034
<p>We can&nbsp;similarly define the <em>nesting depth</em> <code>depth(S)</code> of any VPS <code>S</code> as follows:</p>
3135

3236
<ul>
33-
<li><code>depth(&quot;&quot;) = 0</code></li>
34-
<li><code>depth(A + B) = max(depth(A), depth(B))</code>, where <code>A</code> and <code>B</code> are VPS&#39;s</li>
35-
<li><code>depth(&quot;(&quot; + A + &quot;)&quot;) = 1 + depth(A)</code>, where <code>A</code> is a VPS.</li>
37+
38+
<li><code>depth(&quot;&quot;) = 0</code></li>
39+
40+
<li><code>depth(A + B) = max(depth(A), depth(B))</code>, where <code>A</code> and <code>B</code> are VPS&#39;s</li>
41+
42+
<li><code>depth(&quot;(&quot; + A + &quot;)&quot;) = 1 + depth(A)</code>, where <code>A</code> is a VPS.</li>
43+
3644
</ul>
3745

3846
<p>For example,&nbsp; <code>&quot;&quot;</code>,&nbsp;<code>&quot;()()&quot;</code>, and&nbsp;<code>&quot;()(()())&quot;</code>&nbsp;are VPS&#39;s (with nesting depths 0, 1, and 2), and <code>&quot;)(&quot;</code> and <code>&quot;(()&quot;</code> are not VPS&#39;s.</p>

solution/1100-1199/1138.Alphabet Board Path/README_EN.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,49 @@ tags:
2828
<p>We may make the following moves:</p>
2929

3030
<ul>
31-
<li><code>&#39;U&#39;</code> moves our position up one row, if the position exists on the board;</li>
32-
<li><code>&#39;D&#39;</code> moves our position down one row, if the position exists on the board;</li>
33-
<li><code>&#39;L&#39;</code> moves our position left one column, if the position exists on the board;</li>
34-
<li><code>&#39;R&#39;</code> moves our position right one column, if the position exists on the board;</li>
35-
<li><code>&#39;!&#39;</code>&nbsp;adds the character <code>board[r][c]</code> at our current position <code>(r, c)</code>&nbsp;to the&nbsp;answer.</li>
31+
32+
<li><code>&#39;U&#39;</code> moves our position up one row, if the position exists on the board;</li>
33+
34+
<li><code>&#39;D&#39;</code> moves our position down one row, if the position exists on the board;</li>
35+
36+
<li><code>&#39;L&#39;</code> moves our position left one column, if the position exists on the board;</li>
37+
38+
<li><code>&#39;R&#39;</code> moves our position right one column, if the position exists on the board;</li>
39+
40+
<li><code>&#39;!&#39;</code>&nbsp;adds the character <code>board[r][c]</code> at our current position <code>(r, c)</code>&nbsp;to the&nbsp;answer.</li>
41+
3642
</ul>
3743

3844
<p>(Here, the only positions that exist on the board are positions with letters on them.)</p>
3945

4046
<p>Return a sequence of moves that makes our answer equal to <code>target</code>&nbsp;in the minimum number of moves.&nbsp; You may return any path that does so.</p>
4147

4248
<p>&nbsp;</p>
49+
4350
<p><strong class="example">Example 1:</strong></p>
51+
4452
<pre><strong>Input:</strong> target = "leet"
53+
4554
<strong>Output:</strong> "DDR!UURRR!!DDD!"
55+
4656
</pre><p><strong class="example">Example 2:</strong></p>
57+
4758
<pre><strong>Input:</strong> target = "code"
59+
4860
<strong>Output:</strong> "RR!DDRR!UUL!R!"
61+
4962
</pre>
63+
5064
<p>&nbsp;</p>
65+
5166
<p><strong>Constraints:</strong></p>
5267

5368
<ul>
54-
<li><code>1 &lt;= target.length &lt;= 100</code></li>
55-
<li><code>target</code> consists only of English lowercase letters.</li>
69+
70+
<li><code>1 &lt;= target.length &lt;= 100</code></li>
71+
72+
<li><code>target</code> consists only of English lowercase letters.</li>
73+
5674
</ul>
5775

5876
<!-- description:end -->

0 commit comments

Comments
 (0)