Skip to content

Commit 0ece569

Browse files
committed
Adjust SecondLargestElement solution, add test case
1 parent 14e7bbe commit 0ece569

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/main/java/by/andd3dfx/numeric/SecondLargestElement.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ public static int find_N(int[] array) {
2727
int max_2 = Math.min(array[0], array[1]);
2828

2929
for (int i = 2; i < array.length; i++) {
30-
if (array[i] >= max_1) {
30+
if (array[i] > max_1) {
3131
max_2 = max_1;
3232
max_1 = array[i];
3333
continue;
3434
}
35-
if (array[i] >= max_2) {
35+
if (array[i] > max_2) {
3636
max_2 = array[i];
3737
}
3838
}

src/test/java/by/andd3dfx/numeric/SecondLargestElementTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ public void find_NlogN() {
1313

1414
int[] array2 = {3, 1, 2, 5, 8, 3, 7};
1515
assertThat(SecondLargestElement.find_NlogN(array2)).isEqualTo(7);
16+
17+
int[] array3 = {3, 1, 2, 5, 8, 3, 7, 8};
18+
assertThat(SecondLargestElement.find_N(array3)).isEqualTo(8);
1619
}
1720

1821
@Test
@@ -22,5 +25,8 @@ public void find_N() {
2225

2326
int[] array2 = {3, 1, 2, 5, 8, 3, 7};
2427
assertThat(SecondLargestElement.find_N(array2)).isEqualTo(7);
28+
29+
int[] array3 = {3, 1, 2, 5, 8, 3, 7, 8};
30+
assertThat(SecondLargestElement.find_N(array3)).isEqualTo(8);
2531
}
2632
}

0 commit comments

Comments
 (0)