Compare commits
No commits in common. "b415741eb0eb2aacacc2d3834ecb8583ea926daa" and "c664823f9c22d478a7fc2b9a0a43e3ecea9bb1ff" have entirely different histories.
b415741eb0
...
c664823f9c
|
|
@ -1,7 +1,6 @@
|
|||
<<<<<<< HEAD
|
||||
### IntelliJ IDEA ###
|
||||
out/
|
||||
/target/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
|
|
|
|||
15
pom.xml
15
pom.xml
|
|
@ -19,19 +19,4 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
</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>
|
||||
|
|
|
|||
|
|
@ -4,16 +4,17 @@ class BinarySearch {
|
|||
public static int binarySearchBasic(int[] nums, int target){
|
||||
int i = 0 ,j = nums.length - 1;//设置指针和初始值
|
||||
while (i <= j){
|
||||
int m = ((i + j) / 2);
|
||||
if (target < nums[m]){
|
||||
j = m - 1;
|
||||
int mid = ((i + j) / 2);
|
||||
if (target == nums[mid]){
|
||||
return mid;
|
||||
}
|
||||
else if (nums[m] < target){
|
||||
i = m + 1;
|
||||
else if (target < nums[mid]){
|
||||
j = mid - 1;
|
||||
}
|
||||
else {
|
||||
return m;
|
||||
j = mid + 1;
|
||||
}
|
||||
return mid;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue