Skip to content

Commit a0fd1b5

Browse files
authored
Update syntax for Swift 4
1 parent c3799cf commit a0fd1b5

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Array/ProductExceptSelf.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
class ProductExceptSelf {
9-
func productExceptSelf(nums: [Int]) -> [Int] {
9+
func productExceptSelf(_ nums: [Int]) -> [Int] {
1010
var res = [Int]()
1111

1212
guard nums.count > 0 else {
@@ -23,7 +23,7 @@ class ProductExceptSelf {
2323
return res
2424
}
2525

26-
private func _initLeft(nums: [Int]) -> [Int] {
26+
private func _initLeft(_ nums: [Int]) -> [Int] {
2727
var left = [Int]()
2828
left.append(1)
2929

@@ -34,13 +34,13 @@ class ProductExceptSelf {
3434
return left
3535
}
3636

37-
private func _initRight(nums: [Int]) -> [Int] {
38-
var right = Array(count: nums.count, repeatedValue: 1)
37+
private func _initRight(_ nums: [Int]) -> [Int] {
38+
var right = Array(repeating: 1, count: nums.count)
3939

40-
for i in (nums.count - 2).stride(through: 0, by: -1) {
40+
for i in stride(from: nums.count - 2, through: 0, by: -1) {
4141
right[i] = right[i + 1] * nums[i + 1]
4242
}
4343

4444
return right
4545
}
46-
}
46+
}

0 commit comments

Comments
 (0)