Remove element (new length)
Java
Medium
4 views
Problem Description
Task: remove all occurrences of val in-place and return new length (order can change).
Output Format
Return value
Official Solution
static int removeValue(int[] a,int val){int n=a.length;int i=0;while(i<n){if(a[i]==val){a[i]=a[n-1];n--;}else i++;}return n;}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!