2119. A Number After a Double Reversal

problem

solution

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Solution {
public:
int reverse(int num){
int ret = 0;
while(num){
ret*=10;
ret+=(num%10);
num/=10;
}
cout<<ret<<endl;
return ret;
}
bool isSameAfterReversals(int num) {
return reverse(reverse(num)) == num;

}
};

analyze

  • time complexity O(1)
  • space complexity O(1)