Compare commits
No commits in common. "b415741eb0eb2aacacc2d3834ecb8583ea926daa" and "c664823f9c22d478a7fc2b9a0a43e3ecea9bb1ff" have entirely different histories.
b415741eb0
...
c664823f9c
|
|
@ -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
15
pom.xml
|
|
@ -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>
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue