공부/알고리즘
부족한 금액 계산하기
shining park
2025. 1. 4. 18:00
https://school.programmers.co.kr/learn/courses/30/lessons/82612
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
- 나의 코드
class Solution {
public long solution(int price, int money, int count) {
long answer = -1;
long total = 0;
for(int i=1; i<count+1; i++) {
total = total + (price*i);
}
if(money > total) {
answer = 0;
} else {
answer = total - money;
}
return answer;
}
}