Skip to content

Commit b7bb7b0

Browse files
authored
Update binary-search.md
寻找最右插入位置-Code by Java
1 parent 1344863 commit b7bb7b0

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

91/binary-search.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,23 @@ def bisect_right(A, x):
606606
else: r = mid - 1
607607
return l # 或者返回 r + 1
608608
```
609+
##### Java
610+
611+
```java
612+
import java.util.*;
613+
public class BinarySearch {
614+
public int getPos(int[] A, int val) {
615+
int low=0,high=A.lenght-1;
616+
while (low <= high){
617+
int mid = (low + high)/2;
618+
if (A[mid] <= val){
619+
low = mid + 1;
620+
}else high = mid - 1;
621+
}
622+
return low;
623+
}
624+
}
625+
```
609626

610627
其他语言暂时空缺,欢迎
611628
[PR](https://github.com/azl397985856/leetcode-cheat/issues/4)

0 commit comments

Comments
 (0)