class Solution {
    fun twoSum(nums: List<Int>, target: Int): List<Int> {
        val prevMap = hashMapOf<Int, Int>()
        
        for ((i, num) in nums.withIndex()) {
            val diff = target - num
            if (prevMap.containsKey(diff)) {
                return listOf(prevMap[diff]!!, i)
            }
            prevMap[num] = i
        }
        
        return listOf()
    }
}

fun main() {
    val nums = listOf(1, 2, 3, 4, 5)
    
    for (i in 1..11) {
        var result = Solution().twoSum(nums, i)
        println(result)
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: