[프로그래머스] 콜라 문제

·2022년 12월 20일
0

코테문제풀기

목록 보기
56/57
//처음에 b를 고려하지 않음
function solution(a, b, n) {
  var answer = 0;
  let cola = n;
  let rest = 0;

  while (true) {
    if (cola < a && rest === 0) return answer;

    rest += cola % a;
    cola = Math.floor(cola / a) * b;
    answer += cola;

    cola += rest;
    rest = 0;
  }
}

0개의 댓글