diff options
author | crupest <crupest@outlook.com> | 2020-07-15 17:01:16 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-07-15 17:01:16 +0800 |
commit | 43e2906b771b63202d2a153c3b1a510921260296 (patch) | |
tree | 9a0394370af8fb8a510bbc49e4cd251c6989d842 /cpp | |
parent | b9d7b176c19f6ff7dcaab497be3d4c8c5de506b2 (diff) | |
download | solutions-43e2906b771b63202d2a153c3b1a510921260296.tar.gz solutions-43e2906b771b63202d2a153c3b1a510921260296.tar.bz2 solutions-43e2906b771b63202d2a153c3b1a510921260296.zip |
Add problem 7 .
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/7.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/cpp/7.cpp b/cpp/7.cpp new file mode 100644 index 0000000..a1a05c1 --- /dev/null +++ b/cpp/7.cpp @@ -0,0 +1,18 @@ +class Solution
+{
+public:
+ int reverse(int x)
+ {
+ int result = 0;
+ while (x != 0)
+ {
+ int digit = x % 10;
+ x /= 10;
+ if (__builtin_smul_overflow(result, 10, &result))
+ return 0;
+ if (__builtin_sadd_overflow(result, digit, &result))
+ return 0;
+ }
+ return result;
+ }
+};
|