Skip to content

Commit 3480784

Browse files
authored
Merge branch 'doocs:main' into main
2 parents 3921949 + c9842c3 commit 3480784

File tree

252 files changed

+37726
-30432
lines changed

Some content is hidden

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

252 files changed

+37726
-30432
lines changed

images/starcharts.svg

Lines changed: 27068 additions & 26964 deletions
Loading

lcp/LCP 33. 蓄水/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@ class Solution {
177177
if maxVat == 0 {
178178
return 0
179179
}
180-
180+
181181
let n = vat.count
182182
var ans = Int.max
183-
183+
184184
for x in 1...maxVat {
185185
var y = 0
186186
for i in 0..<n {
@@ -190,7 +190,7 @@ class Solution {
190190
}
191191
ans = min(ans, x + y)
192192
}
193-
193+
194194
return ans
195195
}
196196
}

lcp/LCP 34. 二叉树染色/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,22 +242,22 @@ var maxValue = function (root, k) {
242242

243243
class Solution {
244244
private var k: Int = 0
245-
245+
246246
func maxValue(_ root: TreeNode?, _ k: Int) -> Int {
247247
self.k = k
248248
return dfs(root).max() ?? 0
249249
}
250-
250+
251251
private func dfs(_ root: TreeNode?) -> [Int] {
252252
var ans = [Int](repeating: 0, count: k + 1)
253253
guard let root = root else {
254254
return ans
255255
}
256256
let l = dfs(root.left)
257257
let r = dfs(root.right)
258-
258+
259259
ans[0] = (l.max() ?? 0) + (r.max() ?? 0)
260-
260+
261261
for i in 0..<k {
262262
for j in 0..<k - i {
263263
ans[i + j + 1] = max(ans[i + j + 1], root.val + l[i] + r[j])

lcp/LCP 41. 黑白翻转棋/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,13 @@ class Solution {
299299
private var m = 0
300300
private var n = 0
301301
private var chessboard: [String] = []
302-
302+
303303
func flipChess(_ chessboard: [String]) -> Int {
304304
self.m = chessboard.count
305305
self.n = chessboard[0].count
306306
self.chessboard = chessboard
307307
var ans = 0
308-
308+
309309
for i in 0..<m {
310310
for j in 0..<n {
311311
if Array(chessboard[i])[j] == "." {
@@ -315,32 +315,32 @@ class Solution {
315315
}
316316
return ans
317317
}
318-
318+
319319
private func bfs(_ i: Int, _ j: Int) -> Int {
320320
var queue: [[Int]] = [[i, j]]
321321
var g = chessboard.map { Array($0) }
322322
g[i][j] = "X"
323323
var count = 0
324-
324+
325325
while !queue.isEmpty {
326326
let p = queue.removeFirst()
327327
let i = p[0], j = p[1]
328-
328+
329329
for a in -1...1 {
330330
for b in -1...1 {
331331
if a == 0 && b == 0 { continue }
332-
332+
333333
var x = i + a, y = j + b
334334
while x >= 0 && x < m && y >= 0 && y < n && g[x][y] == "O" {
335335
x += a
336336
y += b
337337
}
338-
338+
339339
if x >= 0 && x < m && y >= 0 && y < n && g[x][y] == "X" {
340340
x -= a
341341
y -= b
342342
count += max(abs(x - i), abs(y - j))
343-
343+
344344
while x != i || y != j {
345345
g[x][y] = "X"
346346
queue.append([x, y])

lcp/LCP 44. 开幕式焰火/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,12 @@ func dfs(root *TreeNode) {
176176

177177
class Solution {
178178
private var uniqueColors: Set<Int> = []
179-
179+
180180
func numColor(_ root: TreeNode?) -> Int {
181181
dfs(root)
182182
return uniqueColors.count
183183
}
184-
184+
185185
private func dfs(_ node: TreeNode?) {
186186
guard let node = node else { return }
187187
uniqueColors.insert(node.val)

lcp/LCP 50. 宝石补给/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,14 @@ function giveGem(gem: number[], operations: number[][]): number {
160160
class Solution {
161161
func giveGem(_ gem: [Int], _ operations: [[Int]]) -> Int {
162162
var gem = gem
163-
163+
164164
for op in operations {
165165
let x = op[0], y = op[1]
166166
let v = gem[x] / 2
167167
gem[y] += v
168168
gem[x] -= v
169169
}
170-
170+
171171
let maxGem = gem.max() ?? 0
172172
let minGem = gem.min() ?? 0
173173
return maxGem - minGem

solution/0000-0099/0001.Two Sum/README.md

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,25 @@ def two_sum(nums, target)
302302
end
303303
```
304304

305+
#### Kotlin
306+
307+
```kotlin
308+
class Solution {
309+
fun twoSum(nums: IntArray, target: Int): IntArray {
310+
val m = mutableMapOf<Int, Int>()
311+
nums.forEachIndexed { i, x ->
312+
val y = target - x
313+
val j = m.get(y)
314+
if (j != null) {
315+
return intArrayOf(j, i)
316+
}
317+
m[x] = i
318+
}
319+
return intArrayOf()
320+
}
321+
}
322+
```
323+
305324
#### Nim
306325

307326
```nim
@@ -318,21 +337,19 @@ proc twoSum(nums: seq[int], target: int): seq[int] =
318337
return @[]
319338
```
320339

321-
#### Kotlin
340+
#### Cangjie
322341

323-
```kotlin
342+
```cj
324343
class Solution {
325-
fun twoSum(nums: IntArray, target: Int): IntArray {
326-
val m = mutableMapOf<Int, Int>()
327-
nums.forEachIndexed { i, x ->
328-
val y = target - x
329-
val j = m.get(y)
330-
if (j != null) {
331-
return intArrayOf(j, i)
344+
func twoSum(nums: Array<Int64>, target: Int64): Array<Int64> {
345+
let d = HashMap<Int64, Int64>()
346+
for (i in 0..nums.size) {
347+
if (d.contains(target - nums[i])) {
348+
return [d[target - nums[i]], i]
332349
}
333-
m[x] = i
350+
d[nums[i]] = i
334351
}
335-
return intArrayOf()
352+
[]
336353
}
337354
}
338355
```

solution/0000-0099/0001.Two Sum/README_EN.md

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,25 @@ def two_sum(nums, target)
299299
end
300300
```
301301

302+
#### Kotlin
303+
304+
```kotlin
305+
class Solution {
306+
fun twoSum(nums: IntArray, target: Int): IntArray {
307+
val m = mutableMapOf<Int, Int>()
308+
nums.forEachIndexed { i, x ->
309+
val y = target - x
310+
val j = m.get(y)
311+
if (j != null) {
312+
return intArrayOf(j, i)
313+
}
314+
m[x] = i
315+
}
316+
return intArrayOf()
317+
}
318+
}
319+
```
320+
302321
#### Nim
303322

304323
```nim
@@ -315,21 +334,19 @@ proc twoSum(nums: seq[int], target: int): seq[int] =
315334
return @[]
316335
```
317336

318-
#### Kotlin
337+
#### Cangjie
319338

320-
```kotlin
339+
```cj
321340
class Solution {
322-
fun twoSum(nums: IntArray, target: Int): IntArray {
323-
val m = mutableMapOf<Int, Int>()
324-
nums.forEachIndexed { i, x ->
325-
val y = target - x
326-
val j = m.get(y)
327-
if (j != null) {
328-
return intArrayOf(j, i)
341+
func twoSum(nums: Array<Int64>, target: Int64): Array<Int64> {
342+
let d = HashMap<Int64, Int64>()
343+
for (i in 0..nums.size) {
344+
if (d.contains(target - nums[i])) {
345+
return [d[target - nums[i]], i]
329346
}
330-
m[x] = i
347+
d[nums[i]] = i
331348
}
332-
return intArrayOf()
349+
[]
333350
}
334351
}
335352
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
func twoSum(nums: Array<Int64>, target: Int64): Array<Int64> {
3+
let d = HashMap<Int64, Int64>()
4+
for (i in 0..nums.size) {
5+
if (d.contains(target - nums[i])) {
6+
return [d[target - nums[i]], i]
7+
}
8+
d[nums[i]] = i
9+
}
10+
[]
11+
}
12+
}

solution/0100-0199/0199.Binary Tree Right Side View/README.md

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,55 @@ tags:
2121

2222
<p>给定一个二叉树的 <strong>根节点</strong> <code>root</code>,想象自己站在它的右侧,按照从顶部到底部的顺序,返回从右侧所能看到的节点值。</p>
2323

24-
<p> </p>
24+
<p>&nbsp;</p>
2525

26-
<p><strong>示例 1:</strong></p>
26+
<p><strong class="example">示例 1</strong></p>
2727

28-
<p><img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0199.Binary%20Tree%20Right%20Side%20View/images/tree.jpg" style="width: 270px; " /></p>
28+
<div class="example-block">
29+
<p><span class="example-io"><b>输入:</b>root = [1,2,3,null,5,null,4]</span></p>
2930

30-
<pre>
31-
<strong>输入:</strong> [1,2,3,null,5,null,4]
32-
<strong>输出:</strong> [1,3,4]
33-
</pre>
31+
<p><strong>输出:</strong><span class="example-io">[1,3,4]</span></p>
3432

35-
<p><strong>示例 2:</strong></p>
33+
<p><strong>解释:</strong></p>
3634

37-
<pre>
38-
<strong>输入:</strong> [1,null,3]
39-
<strong>输出:</strong> [1,3]
40-
</pre>
35+
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0199.Binary%20Tree%20Right%20Side%20View/images/tmpd5jn43fs-1.png" style="width: 400px; height: 207px;" /></p>
36+
</div>
4137

42-
<p><strong>示例 3:</strong></p>
38+
<p><strong class="example">示例 2:</strong></p>
4339

44-
<pre>
45-
<strong>输入:</strong> []
46-
<strong>输出:</strong> []
47-
</pre>
40+
<div class="example-block">
41+
<p><span class="example-io"><b>输入:</b>root = [1,2,3,4,null,null,null,5]</span></p>
4842

49-
<p> </p>
43+
<p><span class="example-io"><b>输出:</b>[1,3,4,5]</span></p>
44+
45+
<p><strong>解释:</strong></p>
46+
47+
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0199.Binary%20Tree%20Right%20Side%20View/images/tmpkpe40xeh-1.png" style="width: 400px; height: 214px;" /></p>
48+
</div>
49+
50+
<p><strong class="example">示例 3:</strong></p>
51+
52+
<div class="example-block">
53+
<p><strong>输入:</strong><span class="example-io">root = [1,null,3]</span></p>
54+
55+
<p><strong>输出:</strong><span class="example-io">[1,3]</span></p>
56+
</div>
57+
58+
<p><strong class="example">示例 4:</strong></p>
59+
60+
<div class="example-block">
61+
<p><span class="example-io"><b>输入:</b>root = []</span></p>
62+
63+
<p><strong>输出:</strong><span class="example-io">[]</span></p>
64+
65+
<p>&nbsp;</p>
66+
</div>
5067

5168
<p><strong>提示:</strong></p>
5269

5370
<ul>
5471
<li>二叉树的节点个数的范围是 <code>[0,100]</code></li>
55-
<li><meta charset="UTF-8" /><code>-100 <= Node.val <= 100</code> </li>
72+
<li><meta charset="UTF-8" /><code>-100&nbsp;&lt;= Node.val &lt;= 100</code>&nbsp;</li>
5673
</ul>
5774

5875
<!-- description:end -->

0 commit comments

Comments
 (0)