Skip to content

Commit 966bb31

Browse files
authored
feat: binary search cpp code
2 parents 1344863 + 731dda9 commit 966bb31

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

91/binary-search.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,25 @@ public class BinarySearch {
562562
}
563563
```
564564

565+
##### C++
566+
567+
```cpp
568+
public:
569+
int binarySearch(int* arr, int arrLen,int a) {
570+
int left = 0;
571+
int right = arrLen - 1;
572+
while(left<=right)
573+
{
574+
int mid = (left+right)/2;
575+
if(arr[mid]>=a)
576+
right = mid - 1;
577+
else
578+
left = mid + 1;
579+
}
580+
return left;
581+
}
582+
```
583+
565584
其他语言暂时空缺,欢迎
566585
[PR](https://github.com/azl397985856/leetcode-cheat/issues/4)
567586

0 commit comments

Comments
 (0)