Solution
int reverse(int x) { int reversed = 0; int max = INT_MAX/10; while (x != 0) { if (abs(reversed) > max) { return 0; } reversed *= 10; reversed += (x % 10); x /= 10; } return reversed; }
Complexity
Runtime: O(n)
Space: O(n)
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)