problems(swift): add “867. Transpose Matrix”
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
75305c4b8d
commit
c1f7120274
1 changed files with 16 additions and 0 deletions
16
problems/swift/transpose-matrix.swift
Normal file
16
problems/swift/transpose-matrix.swift
Normal file
|
@ -0,0 +1,16 @@
|
|||
class Solution {
|
||||
func transpose(_ matrix: [[Int]]) -> [[Int]] {
|
||||
var m = Array(
|
||||
repeating: Array(repeating: 0, count: matrix.count),
|
||||
count: matrix[0].count
|
||||
)
|
||||
|
||||
for y in 0..<matrix.count {
|
||||
for x in 0..<matrix[y].count {
|
||||
m[x][y] = matrix[y][x]
|
||||
}
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue