func solution(_ arr1:[[Int]], _ arr2:[[Int]]) -> [[Int]] {
let n = arr1.count
let m = arr1[0].count
var result = [[Int]]()
for i in 0..<n {
result.append([])
for j in 0..<m {
result[i].append(arr1[i][j] + arr2[i][j])
}
}
return result
}
func solution(_ arr1:[[Int]], _ arr2:[[Int]]) -> [[Int]] {
var arr3:[[Int]] = Array(repeating:Array(repeating:0, count:arr1[0].count), count:arr1.count)
for i in 0..<arr1.count {
for j in 0..<arr1[i].count {
arr3[i][j] = arr1[i][j] + arr2[i][j]
}
}
return arr3
}
Array(repeating:, count:) 사용해서 전부 0인 배열 만들어준다.
import Foundation
func solution(_ arr1:[[Int]], _ arr2:[[Int]]) -> [[Int]] {
return zip(arr1, arr2).map{zip($0,$1).map{$0+$1}}
}