Compare commits

..

No commits in common. "b415741eb0eb2aacacc2d3834ecb8583ea926daa" and "c664823f9c22d478a7fc2b9a0a43e3ecea9bb1ff" have entirely different histories.

3 changed files with 7 additions and 22 deletions

1
.gitignore vendored
View File

@ -1,7 +1,6 @@
<<<<<<< HEAD <<<<<<< HEAD
### IntelliJ IDEA ### ### IntelliJ IDEA ###
out/ out/
/target/
!**/src/main/**/out/ !**/src/main/**/out/
!**/src/test/**/out/ !**/src/test/**/out/

15
pom.xml
View File

@ -19,19 +19,4 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project> </project>

View File

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