diff --git a/jung0115/README.md b/jung0115/README.md index b58f2f3..6c71072 100644 --- a/jung0115/README.md +++ b/jung0115/README.md @@ -26,4 +26,5 @@ | 22차시 | 2024.10.30.수 | 브루트포스 | [점 찍기(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/140107) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/182 | | 23차시 | 2024.11.02.토 | 그리디 알고리즘 | [구명보트(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/42885) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/184 | | 24차시 | 2024.11.09.토 | 그리디 알고리즘 | [섬 연결하기(Lv.3)](https://school.programmers.co.kr/learn/courses/30/lessons/42861) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/187 | -| 25차시 | 2024.11.27.수 | 그리디 알고리즘 | [호텔 대실(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/155651) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/189 | \ No newline at end of file +| 25차시 | 2024.11.27.수 | 그리디 알고리즘 | [호텔 대실(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/155651) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/189 | +| 26차시 | 2024.12.02.월 | 수학 | [시소 짝꿍(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/152996) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/190 | \ No newline at end of file diff --git "a/jung0115/\354\210\230\355\225\231/Programmers_152996.kt" "b/jung0115/\354\210\230\355\225\231/Programmers_152996.kt" new file mode 100644 index 0000000..84566db --- /dev/null +++ "b/jung0115/\354\210\230\355\225\231/Programmers_152996.kt" @@ -0,0 +1,35 @@ +// 26차시 2024.12.02.월 : 프로그래머스 - 시소 짝꿍(Lv.2) +class Solution { + fun solution(weights: IntArray): Long { + var answer: Long = 0 + val weightCount = mutableMapOf() + + for(weight in weights) { + weightCount[weight] = weightCount.getOrDefault(weight, 0L) + 1 + } + + for((weight, count) in weightCount) { + // 같은 무게인 사람이 2명 이상 -> 1:1로 앉을 수 있음 + if(count > 1) { + answer += count * (count - 1) / 2 + } + + // 2:3 비율 + if (weight * 3 % 2 == 0 && weightCount.containsKey(weight * 3 / 2)) { + answer += count * weightCount[weight * 3 / 2]!! + } + + // 2:4 = 1:2 비율 + if (weight * 2 % 1 == 0 && weightCount.containsKey(weight * 2)) { + answer += count * weightCount[weight * 2]!! + } + + // 3:4 비율 + if (weight * 4 % 3 == 0 && weightCount.containsKey(weight * 4 / 3)) { + answer += count * weightCount[weight * 4 / 3]!! + } + } + + return answer + } +} \ No newline at end of file