Skip to content

Commit 8cb4917

Browse files
committed
migrate two sum problem to swift 3
1 parent 3960cf5 commit 8cb4917

File tree

3 files changed

+4
-10
lines changed

3 files changed

+4
-10
lines changed

Two-Sum Problem/Solution 1/2Sum.playground/Contents.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//: Playground - noun: a place where people can play
22

3-
func twoSumProblem(a: [Int], k: Int) -> ((Int, Int))? {
3+
func twoSumProblem(_ a: [Int], k: Int) -> ((Int, Int))? {
44
var map = [Int: Int]()
55

66
for i in 0 ..< a.count {

Two-Sum Problem/Solution 1/2Sum.playground/timeline.xctimeline

Lines changed: 0 additions & 6 deletions
This file was deleted.

Two-Sum Problem/Solution 2/2Sum.playground/Contents.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//: Playground - noun: a place where people can play
22

3-
func twoSumProblem(a: [Int], k: Int) -> ((Int, Int))? {
3+
func twoSumProblem(_ a: [Int], k: Int) -> ((Int, Int))? {
44
var i = 0
55
var j = a.count - 1
66

@@ -9,9 +9,9 @@ func twoSumProblem(a: [Int], k: Int) -> ((Int, Int))? {
99
if sum == k {
1010
return (i, j)
1111
} else if sum < k {
12-
++i
12+
i += 1
1313
} else {
14-
--j
14+
j -= 1
1515
}
1616
}
1717
return nil

0 commit comments

Comments
 (0)