안녕하십니까. Eun🦆입니다.

풀이법 입니다.
Reverse Integer - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
class Solution {
public:
int reverse(int x) {
// MAX, MIN
if(x>2147483647 || x<-2147483647)
return 0;
int sign;
long answer = 0;
if(x>0)
sign = 1;
else
{
sign = -1;
x = x*sign;
}
while(1)
{
if(x>0)
{
if(x%10>0)
answer += x%10;
if(answer>0 & x/10>0)
{
if(answer>2147483648/10)
{
answer = 0;
break;
}
answer = answer*10;
}
x=x/10;
}
else
break;
}
answer = answer*sign;
return answer;
}
};
'개발 > Coding Test' 카테고리의 다른 글
[SW Expert Academy D1] 홀수만 더하기 (0) | 2022.06.09 |
---|---|
[SW Expert Academy D1] 중간값 찾기 (0) | 2022.06.09 |
[LeetCode 1] Two Sum (0) | 2022.06.07 |
[프로그래머스 Lv3 C++] 야근 지수 (0) | 2022.06.07 |
[프로그래머스 Lv3 C++] 멀리 뛰기 (0) | 2022.06.07 |
댓글