Skip to content

Commit 79387a5

Browse files
realDuYuanChaogithub-actions
andauthored
binary-search (examplehub#86)
* binary-search * Formatted with Google Java Formatter Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
1 parent ee6cb00 commit 79387a5

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.examplehub.leetcode.easy;
2+
3+
import com.examplehub.searches.BinarySearchRecursion;
4+
5+
/** https://leetcode.com/problems/binary-search/ */
6+
public class BinarySearch {
7+
public static int solution1(int[] nums, int target) {
8+
com.examplehub.searches.BinarySearch binarySearch = new com.examplehub.searches.BinarySearch();
9+
return binarySearch.search(nums, target);
10+
}
11+
12+
public static int solution2(int nums[], int target) {
13+
BinarySearchRecursion binarySearchRecursion = new BinarySearchRecursion();
14+
return binarySearchRecursion.search(nums, target);
15+
}
16+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.examplehub.leetcode.easy;
2+
3+
import static org.junit.jupiter.api.Assertions.*;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
class BinarySearchTest {
8+
@Test
9+
void testSolution1() {
10+
assertEquals(4, BinarySearch.solution1(new int[] {-1, 0, 3, 5, 9, 12}, 9));
11+
assertEquals(-1, BinarySearch.solution1(new int[] {-1, 0, 3, 5, 9, 12}, 2));
12+
}
13+
14+
@Test
15+
void testSolution2() {
16+
assertEquals(4, BinarySearch.solution2(new int[] {-1, 0, 3, 5, 9, 12}, 9));
17+
assertEquals(-1, BinarySearch.solution2(new int[] {-1, 0, 3, 5, 9, 12}, 2));
18+
}
19+
}

0 commit comments

Comments
 (0)