[Programmers] #120819 - 아이스 아메리카노 [Java][C++][Python]
[Programmers] #120819 - 아이스 아메리카노 [Java][C++][Python]
1. 아이디어
더 살 수 없을 때까지, 즉 남는 돈이 5,500원 미만이 될 때까지 사는 것이 최대이므로, 잔 수는 돈을 5,500으로 나눈 몫이고 남는 돈은 나머지이다. 한 번의 나눗셈으로 둘 다 구해진다.
2. 코드
풀이 [Java][C++][Python]
1
2
3
4
5
class Solution {
public int[] solution(int money) {
return new int[]{money / 5500, money % 5500};
}
}
1
2
3
4
5
6
#include <bits/stdc++.h>
using namespace std;
vector<int> solution(int money) {
return {money / 5500, money % 5500};
}
1
2
def solution(money):
return [money // 5500, money % 5500]
This post is licensed under CC BY 4.0 by the author.