https://programmers.co.kr/learn/courses/30/lessons/82612
코딩테스트 연습 - 부족한 금액 계산하기
새로 생긴 놀이기구는 인기가 매우 많아 줄이 끊이질 않습니다. 이 놀이기구의 원래 이용료는 price원 인데, 놀이기구를 N 번 째 이용한다면 원래 이용료의 N배를 받기로 하였습니다. 즉, 처음 이
programmers.co.kr
기본틀
class Solution {
public long solution(int price, int money, int count) {
long answer = -1;
return answer;
}
}
첫번째 시도
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(total <= money){
answer = 0;
}else{
answer = total - money;
}
return answer;
}
}
성공! 쏘 이지~!
'프로그래머스 > Lv.1' 카테고리의 다른 글
Lv.1 최소직사각형 (0) | 2022.06.19 |
---|---|
Lv.1 나머지가 1이 되는 수 찾기 (0) | 2022.06.19 |
Lv.1 2016년 (0) | 2022.06.17 |
Lv.1 가운데 글자 가져오기 (0) | 2022.06.10 |
Lv.1 [1차] 다트 게임 (0) | 2022.06.09 |