Playground/자바문제집

[프로그래머스] 부족한 금액 계산하기

미숫가루설탕많이 2023. 2. 9. 16:49
class Solution {
    public long solution(int price, int money, int count) {
        long sum = 0;
        
        for (int i = 1; i <= count; i++) {
            sum += price * i;
        }
        return money - sum > 0 ? 0 : Math.abs(money - sum);
    }
}

 

처음에 돈이 부족하지 않은 경우를 고려하지 않아서 테스트 케이스 4번을 통과하지 못했던 것 같다.