Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 deletions solution/0000-0099/0001.Two Sum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,25 @@ def two_sum(nums, target)
end
```

#### Kotlin

```kotlin
class Solution {
fun twoSum(nums: IntArray, target: Int): IntArray {
val m = mutableMapOf<Int, Int>()
nums.forEachIndexed { i, x ->
val y = target - x
val j = m.get(y)
if (j != null) {
return intArrayOf(j, i)
}
m[x] = i
}
return intArrayOf()
}
}
```

#### Nim

```nim
Expand All @@ -318,21 +337,19 @@ proc twoSum(nums: seq[int], target: int): seq[int] =
return @[]
```

#### Kotlin
#### Cangjie

```kotlin
```cj
class Solution {
fun twoSum(nums: IntArray, target: Int): IntArray {
val m = mutableMapOf<Int, Int>()
nums.forEachIndexed { i, x ->
val y = target - x
val j = m.get(y)
if (j != null) {
return intArrayOf(j, i)
func twoSum(nums: Array<Int64>, target: Int64): Array<Int64> {
let d = HashMap<Int64, Int64>()
for (i in 0..nums.size) {
if (d.contains(target - nums[i])) {
return [d[target - nums[i]], i]
}
m[x] = i
d[nums[i]] = i
}
return intArrayOf()
[]
}
}
```
Expand Down
39 changes: 28 additions & 11 deletions solution/0000-0099/0001.Two Sum/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,25 @@ def two_sum(nums, target)
end
```

#### Kotlin

```kotlin
class Solution {
fun twoSum(nums: IntArray, target: Int): IntArray {
val m = mutableMapOf<Int, Int>()
nums.forEachIndexed { i, x ->
val y = target - x
val j = m.get(y)
if (j != null) {
return intArrayOf(j, i)
}
m[x] = i
}
return intArrayOf()
}
}
```

#### Nim

```nim
Expand All @@ -315,21 +334,19 @@ proc twoSum(nums: seq[int], target: int): seq[int] =
return @[]
```

#### Kotlin
#### Cangjie

```kotlin
```cj
class Solution {
fun twoSum(nums: IntArray, target: Int): IntArray {
val m = mutableMapOf<Int, Int>()
nums.forEachIndexed { i, x ->
val y = target - x
val j = m.get(y)
if (j != null) {
return intArrayOf(j, i)
func twoSum(nums: Array<Int64>, target: Int64): Array<Int64> {
let d = HashMap<Int64, Int64>()
for (i in 0..nums.size) {
if (d.contains(target - nums[i])) {
return [d[target - nums[i]], i]
}
m[x] = i
d[nums[i]] = i
}
return intArrayOf()
[]
}
}
```
Expand Down
12 changes: 12 additions & 0 deletions solution/0000-0099/0001.Two Sum/Solution.cj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution {
func twoSum(nums: Array<Int64>, target: Int64): Array<Int64> {
let d = HashMap<Int64, Int64>()
for (i in 0..nums.size) {
if (d.contains(target - nums[i])) {
return [d[target - nums[i]], i]
}
d[nums[i]] = i
}
[]
}
}