Skip to content

Commit

Permalink
2024-12-02
Browse files Browse the repository at this point in the history
  • Loading branch information
jung0115 committed Dec 2, 2024
1 parent 883e84f commit c236844
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion jung0115/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
| 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 |
35 changes: 35 additions & 0 deletions jung0115/수학/Programmers_152996.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 26차시 2024.12.02.월 : 프로그래머스 - 시소 짝꿍(Lv.2)
class Solution {
fun solution(weights: IntArray): Long {
var answer: Long = 0
val weightCount = mutableMapOf<Int, Long>()

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
}
}

0 comments on commit c236844

Please sign in to comment.