inblog logo
|
stupefyee
    알고리즘문제풀기

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

    프로그래머스 (132267)
    Stupefyee's avatar
    Stupefyee
    May 21, 2025
    [JAVA 문제 풀이] 269. 콜라 문제
    Contents
    내가 작성한 코드다른 사람의 코드
    school.programmers.co.kr
    https://school.programmers.co.kr/learn/courses/30/lessons/132267
    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
    Contents
    내가 작성한 코드다른 사람의 코드

    stupefyee

    RSS·Powered by Inblog