Find first occurrence
Java
Easy
4 views
Problem Description
Task: return first index of target in array, else -1.
Output Format
Return value
Official Solution
static int indexOf(int[] a,int target){for(int i=0;i<a.length;i++) if(a[i]==target) return i;return -1;}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!