Swap two elements
Java
Easy
4 views
Problem Description
Task: swap a[i] and a[j] in an int array.
Output Format
In-place update
Constraints
Check bounds.
Official Solution
static void swap(int[] a,int i,int j){int t=a[i];a[i]=a[j];a[j]=t;}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!