https://leetcode.com/problems/reverse-integer/submissions/
class Solution {
public int reverse(int x) {
boolean minus = false;
long ans=0;
if(x<0){minus=true; x=Math.abs(x);}
while(x>0){
int temp=x%10;
x/=10;
ans=ans*10+temp;
}
if (ans<Integer.MIN_VALUE || ans > Integer.MAX_VALUE) return 0;
return (minus)? (int)-ans: (int)ans;
}
}
'Algorithm > Java' 카테고리의 다른 글
프로그래머스 - 숫자의 표현 (0) | 2022.09.22 |
---|---|
leetcode - 11. Container With Most Water (0) | 2022.09.22 |
leetcode - Zigzag Conversion (1) | 2022.09.21 |
leetcode - add two numbers (0) | 2022.09.21 |
프로그래머스 - n^2 배열 자르기 (0) | 2022.09.18 |