Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 83ea32e

Browse files
authoredSep 7, 2024
feat: add kotlin solutions to lc problems (doocs#3492)
1 parent 1680a82 commit 83ea32e

File tree

49 files changed

+1841
-8
lines changed

Some content is hidden

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

49 files changed

+1841
-8
lines changed
 

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,25 @@ proc twoSum(nums: seq[int], target: int): seq[int] =
318318
return @[]
319319
```
320320

321+
#### Kotlin
322+
323+
```kotlin
324+
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)
332+
}
333+
m[x] = i
334+
}
335+
return intArrayOf()
336+
}
337+
}
338+
```
339+
321340
<!-- tabs:end -->
322341

323342
<!-- solution:end -->

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,25 @@ proc twoSum(nums: seq[int], target: int): seq[int] =
315315
return @[]
316316
```
317317

318+
#### Kotlin
319+
320+
```kotlin
321+
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)
329+
}
330+
m[x] = i
331+
}
332+
return intArrayOf()
333+
}
334+
}
335+
```
336+
318337
<!-- tabs:end -->
319338

320339
<!-- solution:end -->

0 commit comments

Comments
 (0)
Please sign in to comment.