일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 프로그래머스
- 방송통신대학교 대학원 정보과학과
- nestedlists
- swift
- GitLab
- 해커랭크
- ESXi 업데이트
- Qualification Round
- K8S
- Code Jam 2022
- ingress-nginx
- C++
- on-prem
- LEVEL 2
- 3D PRINTING
- 2022
- 파이썬
- 코딩테스트
- 하늘과 바람과 별과 시
- Code Jam
- openebs
- Python
- 방통대 대학원 정보과학과
- Kubernetes
- MySQL
- 하늘과 바람과 별과 詩
- hackerrank
- 정보과학과
- secondlowestgrade
Archives
- Today
- Total
공대생의 비망록
[프로그래머스][Lv. 1] 크레인 인형뽑기 게임 Swift 풀이 본문
https://programmers.co.kr/learn/courses/30/lessons/64061
풀이는 추후에 차차 올리도록 하겠습니다...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
import Foundation
func solution(\_ board:\[\[Int\]\], \_ moves:\[Int\]) -> Int {
var popped: Int = 0
var grapped: \[Int\] = \[Int\]()
var colBoard: \[\[Int\]\] = Array(repeating: \[\], count: board.count)
for i in 0..<board.count {
for j in 0..<board\[i\].count {
colBoard\[j\]\[i\] = board\[i\]\[j\]
}
}
for move in moves {
for i in 0..<colBoard\[move - 1\].count {
if colBoard\[move - 1\]\[i\] != 0 {
if !grapped.isEmpty && grapped.last! == colBoard\[move - 1\]\[i\] {
grapped.popLast()
popped += 2
} else {
grapped.append(colBoard\[move - 1\]\[i\])
}
colBoard\[move - 1\]\[i\] = 0
break
}
}
}
return popped
}
|
cs |
'Programming Language > Swift' 카테고리의 다른 글
[프로그래머스][Lv. 1] 음양 더하기 Swift 풀이 (0) | 2022.03.14 |
---|---|
[프로그래머스][Lv. 1] 없는 숫자 더하기 Swift 풀이 (0) | 2022.03.14 |
[프로그래머스][Lv. 1] 키패드 누르기 Swift 풀이 (0) | 2022.03.14 |
[프로그래머스][Lv. 1] 숫자 문자열과 영단어 Swift 풀이 (0) | 2022.03.14 |
[프로그래머스][Lv. 1] 신규 아이디 추천 Swift 풀이 (0) | 2022.03.14 |
Comments