[JAVA 문제 풀이] 269. 콜라 문제

프로그래머스 (132267)
Stupefyee's avatar
May 21, 2025
[JAVA 문제 풀이] 269. 콜라 문제
notion image
notion image
 

내가 작성한 코드

class Solution { public int solution(int a, int b, int n) { int answer = 0; while (n >= a) { int temp = n / a; // 새로 받는 음료 개수 answer += temp * b; // 받은 음료 누적 n = n % a + temp * b; // 남은 음료 + 새로 받은 음료 } return answer; } }
 

다른 사람의 코드

class Solution { public int solution(int a, int b, int n) { return (n > b ? n - b : 0) / (a - b) * b; } }
Share article

stupefyee