Skip to content

Instantly share code, notes, and snippets.

@codeperfectplus
Created September 8, 2023 14:30
Show Gist options
  • Select an option

  • Save codeperfectplus/f9b93b29c4f32a748d1533af8266c911 to your computer and use it in GitHub Desktop.

Select an option

Save codeperfectplus/f9b93b29c4f32a748d1533af8266c911 to your computer and use it in GitHub Desktop.
class Solution {
public:
int reverse(int x) {
int rev = 0;
while (x != 0) {
int pop = x % 10;
x /= 10;
if (rev > INT_MAX / 10 || rev < INT_MIN / 10) return 0;
rev = rev * 10 + pop;
}
return rev;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment