Compare commits

..

No commits in common. "45b40688c79178f74098a273ad80968a15eaf8a1" and "5d29f810a2c10c1b15a0a1c8bc900ff8e9c01fe3" have entirely different histories.

7 changed files with 7 additions and 110 deletions

View File

@ -1,2 +1,2 @@
# main.practice.Solution
# solution.Solution

22
pom.xml
View File

@ -1,22 +0,0 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.nbee</groupId>
<artifactId>solution</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,21 +0,0 @@
package com.nbee.solution.practice;
class BinarySearch {
public static int binarySearchBasic(int[] nums, int target){
int i = 0 ,j = nums.length - 1;//设置指针和初始值
while (i <= j){
int mid = ((i + j) / 2);
if (target == nums[mid]){
return mid;
}
else if (target < nums[mid]){
j = mid - 1;
}
else {
j = mid + 1;
}
return mid;
}
return -1;
}
}

View File

@ -1,4 +1,4 @@
package com.nbee.solution.solution;
package solution;
public class ListNode {
int val;

View File

@ -1,4 +1,4 @@
package com.nbee.solution.solution;
package solution;
import java.util.*;
import java.util.stream.Collectors;

View File

@ -1,6 +1,9 @@
package com.nbee.solution.solution;
package solution;
import java.util.*;
import java.util.stream.Collectors;
public class test {
public static void main(String[] args) {
ListNode head = new ListNode(1);

View File

@ -1,63 +0,0 @@
package com.nbee.solution.practice;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class BinarySearchTest {
@Test
public void testBinarySearchBasic_Found() {
int[] nums = {1, 3, 5, 7, 9};
int target = 5;
int expected = 2;
int result = BinarySearch.binarySearchBasic(nums, target);
assertEquals(expected, result);
}
@Test
public void testBinarySearchBasic_NotFound() {
int[] nums = {1, 3, 5, 7, 9};
int target = 4;
int expected = -1;
int result = BinarySearch.binarySearchBasic(nums, target);
assertEquals(expected, result);
}
@Test
public void testBinarySearchBasic_EmptyArray() {
int[] nums = {};
int target = 0;
int expected = -1;
int result = BinarySearch.binarySearchBasic(nums, target);
assertEquals(expected, result);
}
@Test
public void testBinarySearchBasic_SingleElementFound() {
int[] nums = {2};
int target = 2;
int expected = 0;
int result = BinarySearch.binarySearchBasic(nums, target);
assertEquals(expected, result);
}
@Test
public void testBinarySearchBasic_SingleElementNotFound() {
int[] nums = {2};
int target = 3;
int expected = -1;
int result = BinarySearch.binarySearchBasic(nums, target);
assertEquals(expected, result);
}
@Test
public void testBinarySearchBasic_DecreasingArray() {
int[] nums = {9, 7, 5, 3, 1};
int target = 3;
int expected = 2;
int result = BinarySearch.binarySearchBasic(nums, target);
assertEquals(expected, result);
}
}