Skip to content

Commit 599d991

Browse files
author
Yi Gu
committed
[Array] update code style to Swift 3.0
1 parent af5470d commit 599d991

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

Array/SpiralMatrixII.swift

+6-10
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,17 @@
66
*/
77

88
class SpiralMatrixII {
9-
func generateMatrix(n: Int) -> [[Int]] {
9+
func generateMatrix(_ n: Int) -> [[Int]] {
1010
guard n > 0 else {
1111
return [[Int]]()
1212
}
1313

1414
var num = 1
15-
var res = Array(count: n, repeatedValue: Array(count: n, repeatedValue: 0))
16-
17-
var start = 0
18-
var end = 0
19-
var offset = 0
15+
var res = Array(repeating: Array(repeating: 0, count: n), count: n)
2016

2117
for layer in 0 ..< n / 2 {
22-
start = layer
23-
end = n - layer - 1
18+
let start = layer
19+
let end = n - layer - 1
2420

2521
// top
2622
for i in start ..< end {
@@ -35,13 +31,13 @@ class SpiralMatrixII {
3531
}
3632

3733
// bottom
38-
for i in end.stride(to: start, by: -1) {
34+
for i in stride(from: end, to: start, by: -1) {
3935
res[end][i] = num
4036
num += 1
4137
}
4238

4339
// left
44-
for i in end.stride(to: start, by: -1) {
40+
for i in stride(from: end, to: start, by: -1) {
4541
res[i][start] = num
4642
num += 1
4743
}

0 commit comments

Comments
 (0)