Absolute difference as long
Java
Easy
4 views
Problem Description
Task: return absolute difference between two ints as a long (avoid overflow).
Output Format
Return value
Constraints
Cast to long first.
Official Solution
static long absDiff(int a,int b){long x=a;long y=b;long d=x-y;return d<0?-d:d;}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!