부족한 금액 계산하기(java)
문제설명
생각하기
- 반복문을 돌며 price를 n배 해준다.
- 조건문으로 내가 가진 돈보다 비용이 더 드는지 확인
내 풀이
class Solution {
public long solution(int price, int money, int count) {
long ans =0;
for(int i=1; i <= count; i++){
ans += price*i;
}
if(money - ans >= 0){
ans =0;
}else ans -= money;
return ans;
}
}
기본적인 연산 문제이기에 설명은 생략.
Author And Source
이 문제에 관하여(부족한 금액 계산하기(java)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@juntree/부족한-금액-계산하기java저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)