Skip to content

Instantly share code, notes, and snippets.

@LeoPFreitas
Last active August 6, 2020 16:08
Show Gist options
  • Save LeoPFreitas/2c57f351c229e6e8ebda4a1460ff3583 to your computer and use it in GitHub Desktop.
Save LeoPFreitas/2c57f351c229e6e8ebda4a1460ff3583 to your computer and use it in GitHub Desktop.
Linear search in array of integers.
public static int linearSearchArray(int[] array, int value) {
int index = -1;
for (int i = 0; i < array.length; i++) {
if (array[i] == value) {
index = i;
break;
}
}
return index;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment