[Programmers] #120819 - 아이스 아메리카노 [Java][C++][Python]
가진 돈으로 살 수 있는 아메리카노 잔 수와 남는 돈을 구하는 워밍업 문제.
[Programmers] #120819 - 아이스 아메리카노 [Java][C++][Python]
1. 아이디어
아메리카노 한 잔 가격 5,500원으로 money를 나눈 몫이 살 수 있는 잔 수, 나머지가 남는 돈이다. 정수 나눗셈과 나머지 연산 한 번씩으로 바로 구할 수 있다.
2. 복잡도
| 접근 | 시간 | 공간 |
|---|---|---|
| 풀이 | $O(1)$ | $O(1)$ |
3. 코드
풀이 [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.