Loading…
Loading…
Checks each element in turn until the target is found or the array ends. Works on any array, sorted or not.
Scan left to right for 53.
Tip: click any bar to make it the target.
1int linearSearch(int[] arr, int target) {2 for (int i = 0; i < arr.length; i++) // Scan every element3 if (arr[i] == target) return i; // Match found4 return -1; // Not in array5}