-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
15.1 Reverse Integer(cpp): have not check integer overflow.... #45
Comments
Thanks for pointing this out, I'll check it later. |
|
@billlipeng #include <math>
class Solution {
public:
int reverse(int x) {
signed long long int result = 0;
for (; x; x/=10)
{
result = result * 10 + x % 10;
}
if (abs(result) > (pow(2, 31)-1)) {
return 0;
} else {
return result;
}
}
}; |
+1. The solution is wrong. |
谢谢,我周末抽时间检查一下 |
This issue was solved. Plz check my comment on Feb 26, update the code and close it. Thanks a lot! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Did you notice that the reversed integer might overflow? Assume the input is a 32-bit integer, then the reverse of 1000000003 overflows. How should you handle such cases?
yeah?
The text was updated successfully, but these errors were encountered: