Skip to content

Commit 0227ee1

Browse files
committed
update readme
1 parent 56a5fa6 commit 0227ee1

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Two-Sum Problem/README.markdown

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ There are a variety of solutions to this problem (some better than others). The
88

99
This solution uses a dictionary to store differences between each element in the array and the sum `k` that we're looking for. The dictionary also stores the indices of each element.
1010

11-
With this approach, each key in the dictionary corresponds to a new target value. If one of the successive numbers from the array is equal to one of the dictionary's keys, then we know there exist two numbers that sum to `k`.
11+
With this approach, each key in the dictionary corresponds to a new target value. If one of the successive numbers from the array is equal to one of the dictionary's keys, then we know there exist two numbers that sum to `k`.
1212

1313
```swift
14-
func twoSumProblem(a: [Int], k: Int) -> ((Int, Int))? {
14+
func twoSumProblem(_ a: [Int], k: Int) -> ((Int, Int))? {
1515
var dict = [Int: Int]()
1616

1717
for i in 0 ..< a.count {
@@ -69,7 +69,7 @@ The running time of this algorithm is **O(n)** because it potentially may need t
6969
Here is the code in Swift:
7070

7171
```swift
72-
func twoSumProblem(a: [Int], k: Int) -> ((Int, Int))? {
72+
func twoSumProblem(_ a: [Int], k: Int) -> ((Int, Int))? {
7373
var i = 0
7474
var j = a.count - 1
7575

@@ -78,9 +78,9 @@ func twoSumProblem(a: [Int], k: Int) -> ((Int, Int))? {
7878
if sum == k {
7979
return (i, j)
8080
} else if sum < k {
81-
++i
81+
i += 1
8282
} else {
83-
--j
83+
j -= 1
8484
}
8585
}
8686
return nil

0 commit comments

Comments
 (0)