https://leetcode.com/problems/two-sum Easy

Решение

class Solution {
    fun twoSum(nums: IntArray, target: Int): IntArray {
        val map = HashMap<Int, Int>(nums.size * 2)
        var i = 0
        val n = nums.size
        while (i < n) {
            val v = nums[i]
            val j = map[target - v]
            if (j != null) return intArrayOf(j, i)
            map[v] = i
            i++
        }
        return intArrayOf()
    }
}