코딩테스트/Leetcode

Leetcode - [Easy]7. Reverse Integer

aiemag 2021. 3. 4. 23:15
반응형

leetcode.com/problems/reverse-integer/

 

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

 

solution

1
2
3
4
5
6
7
8
9
10
11
12
int reverse(int x) {
    long long value = 0;
    long long tx = x;
 
    while (tx) {        
        value = value * 10 + tx % 10;        
        if (value < -2147483648 || value > 2147483647return 0;        
        tx /= 10;
    }
 
    return value;
}
cs

 

반응형