Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- class Solution {
- public:
- int reverse(int x) {
- string s = to_string (x);
- if ( s[0] =='-') s.erase(s.begin());
- std::reverse(s.begin(),s.end());
- for (int i=0;i<s.size();i++){
- if ( s[i]!='0'){
- s=s.substr(i);
- break;
- }
- }
- long long real = stoll ( s);
- if ( real > 2147483648 ) return 0; // 2^31-1 = 2147483648
- return x>0? stoi(s) : -stoi(s);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment