[Programmers] #181850 - 정수 부분 [Java][C++][Python]
[Programmers] #181850 - 정수 부분 [Java][C++][Python]
1. 아이디어
실수 flo의 정수 부분을 반환하는 문제로 정수로 바로 변환하면 소수점 아래가 절삭되는 것을 활용했다.
2. 복잡도
| 접근 | 시간 | 공간 |
|---|---|---|
| 풀이 | $O(1)$ | $O(1)$ |
3. 코드
풀이 [Java][C++][Python]
1
2
3
4
5
class Solution {
public int solution(double flo) {
return (int) flo;
}
}
1
2
3
4
5
6
#include <bits/stdc++.h>
using namespace std;
int solution(double flo) {
return (int)flo;
}
1
2
def solution(flo):
return int(flo)
This post is licensed under CC BY 4.0 by the author.