We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent cc75b5e commit 92d4702Copy full SHA for 92d4702
src/main/java/com/thealgorithms/searches/LinearSearch.java
@@ -41,10 +41,13 @@ public class LinearSearch implements SearchAlgorithm {
41
*
42
* @param array List to be searched
43
* @param value Key being searched for
44
- * @return Location of the key
+ * @return Location of the key, -1 if array is null or empty, or key not found
45
*/
46
@Override
47
public <T extends Comparable<T>> int find(T[] array, T value) {
48
+ if (array == null || array.length == 0) {
49
+ return -1;
50
+ }
51
for (int i = 0; i < array.length; i++) {
52
if (array[i].compareTo(value) == 0) {
53
return i;
0 commit comments