LeetCode 1. Two Sum - Swift Solution
Problem https://leetcode.com/problems/two-sum/ Problem Summary Given an array of integers and a target, find the indices of two numbers that add up to the target. Return the indices in any order. Solution class Solution { func twoSum ( _ nums : [ Int ], _ target : Int ) -> [ Int ] { var answer : [ Int ] = [] var dictionary : [ Int : Int ] = [ : ] for index in 0 .. < nums . count { let diff = target - nums [ index ] if let storedIndex = dictionary [ diff ] { answer = [ storedIndex , index ] break } else { dictionary [ nums [ index ]] = index } } return answer } } This code implements the solution to the "two sum" problem. The function takes an array of integers and a target integer as inputs and returns the indices of two numbers in the array that add up to the target....