Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Algorithm] 로또의 최고 순위와 최저 순위 #55

Closed
hwangJi-dev opened this issue Jan 4, 2023 · 0 comments
Closed

[Algorithm] 로또의 최고 순위와 최저 순위 #55

hwangJi-dev opened this issue Jan 4, 2023 · 0 comments

Comments

@hwangJi-dev
Copy link
Owner

💬 문제

[코딩테스트 연습 - 로또의 최고 순위와 최저 순위](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분

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant