class Solution {
fun twoSum(nums: IntArray, target: Int): IntArray {
val map = mutableMapOf<Int, Int>()
for ((i, v) in nums.withIndex()) {
if (map.containsKey(target - v)) {
return intArrayOf(map[target - v]!!, i)
}
map[v] = i
}
return intArrayOf()
}
}
'Algorithm > LeetCode' 카테고리의 다른 글
[LeetCode] Majority Element - (Kotlin) (0) | 2023.01.20 |
---|---|
[LeetCode] Valid Palindrome - (Kotlin) (0) | 2023.01.16 |
[LeetCode] Convert Sorted Array to Binary Search Tree (Kotlin) (0) | 2023.01.15 |
[LeetCode] Symmetric Tree (Kotlin) (0) | 2023.01.14 |
[LeetCode] Merge Sorted Array (Kotlin) (0) | 2023.01.14 |
댓글