Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d92687f

Browse filesBrowse files
authored
Create 7_reverse-integer.cpp
Solution to LeetCode problem no. 7 "Reverse Integer".
1 parent 50465aa commit d92687f
Copy full SHA for d92687f

File tree

Expand file treeCollapse file tree

1 file changed

+14
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+14
-0
lines changed

‎7_reverse-integer.cpp

Copy file name to clipboard
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public:
3+
int reverse(int x) {
4+
int ans = 0;
5+
for (; x != 0; x /= 10) {
6+
if ((ans > (INT_MAX / 10)) || (ans < INT_MIN / 10)) {
7+
return 0;
8+
} else {
9+
ans = (ans * 10) + (x % 10);
10+
}
11+
}
12+
return ans;
13+
}
14+
};

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.