The title

Given an integer array nums and an integer target value target, find the two integers in the array and the target values and return their array subscripts.

You can assume that there is only one answer for each type of input. However, the same element in an array cannot be used twice.

You can return the answers in any order.

Example 1: input: nums = [2,7,11,15], target = 9 output: [0,1] description: because nums[0] + nums[1] == 9, return [0,1]. Example 2: input: nums = [3,2,4], target = 6 output: [1,2] example 3: input: nums = [3,3], target = 6 output: [0,1]Copy the code

Their thinking

class Solution { func twoSum(_ nums: [Int], _ target: Int) -> [Int] { var dic: [Int: Int] = [:] for (index, value) in nums.enumerated() { let reminder: Int = target - value print(reminder) print(dic) if dic.keys.contains(reminder) { if let reminderIndex = dic[reminder],reminderIndex ! = index { return [reminderIndex, index] } } dic[value] = index } return [] } }Copy the code