Skip to content

Commit 7d86132

Browse files
committed
Updated find second largest
1 parent 2f03934 commit 7d86132

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Other/FindSecondLargest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public int secondLargest(int[] array) {
2727
sec = max;
2828
max = array[i];
2929
}
30-
else if (array[i] > sec) sec = array[i]; // smaller than max
30+
else if (array[i] > sec && array[i] != max) sec = array[i]; // smaller than max
3131
}
3232
return sec;
3333
}

0 commit comments

Comments
 (0)