Compare commits
3 Commits
c664823f9c
...
b415741eb0
| Author | SHA1 | Date |
|---|---|---|
|
|
b415741eb0 | |
|
|
67d4fa3983 | |
|
|
abd073c2b5 |
|
|
@ -1,6 +1,7 @@
|
||||||
<<<<<<< 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,4 +19,19 @@
|
||||||
<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,17 +4,16 @@ 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 mid = ((i + j) / 2);
|
int m = ((i + j) / 2);
|
||||||
if (target == nums[mid]){
|
if (target < nums[m]){
|
||||||
return mid;
|
j = m - 1;
|
||||||
}
|
}
|
||||||
else if (target < nums[mid]){
|
else if (nums[m] < target){
|
||||||
j = mid - 1;
|
i = m + 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
j = mid + 1;
|
return m;
|
||||||
}
|
}
|
||||||
return mid;
|
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue