Skip to content

Commit 2f77c80

Browse files
add test for 378
1 parent f9feb70 commit 2f77c80

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/main/java/com/fishercoder/solutions/_378.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static class Solution2 {
2828
* end of row util we find the element is less than the mid, the left side element is all less than mid; keep tracking elements
2929
* that less than mid and compare with k, then update the k.
3030
*/
31-
public int kthSmallestBS(int[][] matrix, int k) {
31+
public int kthSmallest(int[][] matrix, int k) {
3232
int row = matrix.length - 1;
3333
int col = matrix[0].length - 1;
3434
int lo = matrix[0][0];
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.common.utils.CommonUtils;
4+
import com.fishercoder.solutions._378;
5+
import org.junit.BeforeClass;
6+
import org.junit.Test;
7+
8+
import static org.junit.Assert.assertEquals;
9+
10+
public class _378Test {
11+
private static _378.Solution1 solution1;
12+
private static _378.Solution2 solution2;
13+
private static int[][] matrix;
14+
15+
@BeforeClass
16+
public static void setup() {
17+
solution1 = new _378.Solution1();
18+
solution2 = new _378.Solution2();
19+
}
20+
21+
@Test
22+
public void test1() {
23+
matrix = new int[][]{
24+
new int[]{-5}
25+
};
26+
assertEquals(-5, solution1.kthSmallest(matrix, 1));
27+
assertEquals(-5, solution2.kthSmallest(matrix, 1));
28+
}
29+
30+
@Test
31+
public void test2() {
32+
matrix = CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray("[1,2],[1,3]");
33+
assertEquals(1, solution1.kthSmallest(matrix, 2));
34+
assertEquals(1, solution2.kthSmallest(matrix, 2));
35+
}
36+
37+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy