Swap without temp using arithmetic
Java
Medium
4 views
Problem Description
Task: swap two ints without temp using + and - and return [b,a].
Output Format
Return value
Constraints
Assume no overflow.
Official Solution
static int[] swapNoTemp(int a,int b){a=a+b;b=a-b;a=a-b;return new int[]{a,b};}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!