-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
💬 문제
[코딩테스트 연습 - 로또의 최고 순위와 최저 순위](https://school.programmers.co.kr/learn/courses/30/lessons/77484?language=swift)
💬 Idea
- 최저점: 우승 넘버에서 lotto가 포함된 것을 filter로 거른 count
- 최고점: 우승 넘버에서 lotto가 포함된 것을 filter로 거른 count + 0으로 표기되어 알 수 없는 넘버들의 count
- 결과: 최저점과 최고점으로부터 등수를 뽑기 위해 7을 뺀 후 절댓값을 사용한다.
💬 풀이
func solution(_ lottos:[Int], _ win_nums:[Int]) -> [Int] {
let min = win_nums.filter({ lottos.contains($0 )}).count
let max = min + lottos.filter({ $0 == 0 }).count
return [max == 0 ? 6 : abs(max - 7), min == 0 ? 6 : abs(min - 7)]
}
소요시간
: 10분