Reverse digits
Java
Easy
6 views
Problem Description
Task: reverse digits of a number and return result (ignore overflow for now).
Output Format
Return value
Constraints
Handle negative input.
Official Solution
static int reverseDigits(int x){int sign=x<0?-1:1;int n=x*sign;int r=0;while(n>0){r=r*10+(n%10);n/=10;}return r*sign;}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!