[Swift 알고리즘] 행렬의 덧셈

장주명·2021년 5월 14일

https://programmers.co.kr/learn/courses/30/lessons/12950

func solution(_ arr1:[[Int]], _ arr2:[[Int]]) -> [[Int]] {

    var answer = [[Int]]()

    for i in 0..<arr1.count {
        var temp = [Int]()
        for j in 0..<arr1[i].count {
            temp.append(arr1[i][j] + arr2[i][j])
        }
        answer.append(temp)
    }

    return answer
}

✏️인상적인 풀이

func solution(_ arr1:[[Int]], _ arr2:[[Int]]) -> [[Int]] {
    return zip(arr1, arr2).map{zip($0,$1).map{$0+$1}}
}
profile
flutter & ios 개발자

0개의 댓글