일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 2022
- 하늘과 바람과 별과 詩
- K8S
- MySQL
- hackerrank
- C++
- 정보과학과
- 하늘과 바람과 별과 시
- secondlowestgrade
- swift
- 코딩테스트
- LEVEL 2
- 방통대 대학원 정보과학과
- 해커랭크
- ingress-nginx
- Code Jam 2022
- Kubernetes
- openebs
- GitLab
- 방송통신대학교 대학원 정보과학과
- nestedlists
- Code Jam
- ESXi 업데이트
- 3D PRINTING
- Python
- on-prem
- Qualification Round
- 프로그래머스
- 파이썬
Archives
- Today
- Total
공대생의 비망록
[프로그래머스][Lv. 1] 체육복 Swift 풀이 본문
https://programmers.co.kr/learn/courses/30/lessons/42862
풀이는 추후에 차차 올리도록 하겠습니다...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
import Foundation
func solution(_ n:Int, _ lost:[Int], _ reserve:[Int]) -> Int {
var _lost: [Int] = lost.filter{!reserve.contains($0)}.sorted()
var _reserve: [Int] = reserve.filter{!lost.contains($0)}.sorted()
for savior in _reserve {
if let index = _lost.index(of: savior - 1) {
_lost.remove(at: index)
continue
}
if let index = _lost.index(of: savior + 1) {
_lost.remove(at: index)
}
}
return n - _lost.count
}
|
cs |
'Programming Language > Swift' 카테고리의 다른 글
[프로그래머스][Lv. 1] 3진법 뒤집기 Swift 풀이 (0) | 2022.03.14 |
---|---|
[프로그래머스][Lv. 1] 약수의 개수와 덧셈 Swift 풀이 (0) | 2022.03.14 |
[프로그래머스][Lv. 1] 모의고사 Swift 풀이 (0) | 2022.03.14 |
[프로그래머스][Lv. 1] K번째 수 Swift 풀이 (0) | 2022.03.14 |
[프로그래머스][Lv. 1] 소수 만들기 Swift 풀이 (0) | 2022.03.14 |
Comments