티스토리 뷰
programmers.co.kr/learn/courses/30/lessons/64061
코딩테스트 연습 - 크레인 인형뽑기 게임
[[0,0,0,0,0],[0,0,1,0,3],[0,2,5,0,1],[4,2,4,4,2],[3,5,1,3,1]] [1,5,3,5,1,2,1,4] 4
programmers.co.kr
나의 풀이
import Foundation
func solution(_ board:[[Int]], _ moves:[Int]) -> Int {
var board = board
var arr: [Int] = []
var removeCount: Int = 0
for i in moves {
for j in 0..<board.count {
let target = board[j][i-1]
if target != 0 {
board[j][i-1] = 0
if arr.last == target {
arr.removeLast()
removeCount += 1
} else {
arr.append(target)
}
break
}
}
}
return removeCount * 2
}
'Algorithm' 카테고리의 다른 글
[Swift 알고리즘] 프로그래머스 Lv1 k번째수 (0) | 2021.04.27 |
---|---|
[Swift 알고리즘] 프로그래머스 Lv1 3진법 뒤집기 (0) | 2021.04.27 |
[Swift 알고리즘] 프로그래머스 Lv1 체육복 (0) | 2021.04.27 |
[Swift 알고리즘] 프로그래머스 Lv1 모의고사 (0) | 2021.04.27 |
[Swift 알고리즘] 프로그래머스 Lv1 신규 아이디 추천 (0) | 2021.04.27 |
댓글
공지사항