새소식

인기 검색어

프로그래머스/Lv.0

[Swift] 2차원으로 만들기

  • -
import Foundation

func solution(_ num_list:[Int], _ n:Int) -> [[Int]] {
    
    var tmp = [Int]()
    var result = [[Int]]()
    var num_list = num_list

    var i = 0
    
    for num in num_list {
        if i == n {
            i = 0
            result.append(tmp)
            tmp.removeAll()
        }
        tmp.append(num)
        i += 1
    }
    
    result.append(tmp)
    return result
}

'프로그래머스 > Lv.0' 카테고리의 다른 글

[Swift] 가위 바위 보  (0) 2022.12.13
[Swift] 가까운 수  (0) 2022.12.13
[Swift] 369게임  (0) 2022.12.13
[Swift] 7의 개수  (0) 2022.12.13
[Swift] 평행  (0) 2022.12.13
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.