1. fun twoSum(nums: IntArray, target: Int): IntArray {
    2. // key为target-数组的值,value为数组的索引
    3. val resultMap = mutableMapOf<Int, Int>()
    4. nums.forEachIndexed { index, value ->
    5. // 若存在,直接返回
    6. if (resultMap.containsKey(value)) {
    7. val anotherIndex: Int = resultMap[value]!!
    8. return intArrayOf(anotherIndex, index)
    9. }else{
    10. // 存入map
    11. resultMap[target-value] = index
    12. }
    13. }
    14. // 没有,返回空数组
    15. return IntArray(2)
    16. }