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