https://programmers.co.kr/learn/courses/30/lessons/77484?language=go
코딩테스트 연습 - 로또의 최고 순위와 최저 순위
로또 6/45(이하 '로또'로 표기)는 1부터 45까지의 숫자 중 6개를 찍어서 맞히는 대표적인 복권입니다. 아래는 로또의 순위를 정하는 방식입니다. 1 순위 당첨 내용 1 6개 번호가 모두 일치 2 5개 번호
programmers.co.kr
func solution(lottos []int, win_nums []int) []int {
lucky := []int{}
result := []int{}
count := 0
max := 0
min := 0
for _, v := range lottos {
if v == 0 {
count++
continue
}
if contains(win_nums, v) {
lucky = append(lucky, v)
}
}
if len(lucky) <= 1 {
min = 6
} else if len(lucky) == 2 {
min = 5
} else if len(lucky) == 3 {
min = 4
} else if len(lucky) == 4 {
min = 3
} else if len(lucky) == 5 {
min = 2
} else {
min = 1
}
if len(lucky)+count == 6 {
max = 1
} else if len(lucky)+count == 5 {
max = 2
} else if len(lucky)+count == 4 {
max = 3
} else if len(lucky)+count == 3 {
max = 4
} else if len(lucky)+count == 2 {
max = 5
} else {
max = 6
}
result = []int{max, min}
return result
}
func contains(list []int, i int) bool {
for _, value := range list {
if value == i {
return true
}
}
return false
}
'Algorithm > Go' 카테고리의 다른 글
[LeetCode] Consecutive Characters (Go) (0) | 2021.12.06 |
---|---|
[Leetcode] Two Sum (Go) (0) | 2021.12.06 |
[프로그래머스] 음양 더하기 (Go) (0) | 2021.11.22 |
[LeetCode] PlusOne (Go) (0) | 2021.11.14 |
[프로그래머스] 핸드폰 번호 가리기 (Go) (0) | 2021.11.08 |