We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c31a82f commit 42cf39cCopy full SHA for 42cf39c
two-sum/jdalma.kt
@@ -19,7 +19,9 @@ class `two-sum` {
19
nums.forEachIndexed { i, e ->
20
val diff: Int = target - e
21
if (map.containsKey(diff) && map[diff] != i) {
22
- return intArrayOf(i , map[diff]!!)
+ return map[diff]?.let {
23
+ intArrayOf(it, i)
24
+ } ?: intArrayOf()
25
}
26
27
return intArrayOf()
@@ -35,7 +37,9 @@ class `two-sum` {
35
37
for (index in nums.indices) {
36
38
val diff = target - nums[index]
39
if (map.containsKey(diff)) {
- return intArrayOf(map[diff]!!, index)
40
41
+ intArrayOf(it, index)
42
43
44
map[nums[index]] = index
45
0 commit comments