Safe average without overflow
Java
Medium
5 views
Problem Description
Task: return average of two ints without overflow.
Output Format
Return value
Constraints
Use long or bit trick.
Official Solution
static int safeAvg(int a,int b){return (int)(((long)a+(long)b)/2); }
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!