summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-07-15 17:01:16 +0800
committercrupest <crupest@outlook.com>2020-07-15 17:01:16 +0800
commit43e2906b771b63202d2a153c3b1a510921260296 (patch)
tree9a0394370af8fb8a510bbc49e4cd251c6989d842
parentb9d7b176c19f6ff7dcaab497be3d4c8c5de506b2 (diff)
downloadsolutions-43e2906b771b63202d2a153c3b1a510921260296.tar.gz
solutions-43e2906b771b63202d2a153c3b1a510921260296.tar.bz2
solutions-43e2906b771b63202d2a153c3b1a510921260296.zip
Add problem 7 .
-rw-r--r--cpp/7.cpp18
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;
+ }
+};