Skip to content

Commit 151de7b

Browse files
committed
Create: 0704-Binary-Search.dart
1 parent ff32745 commit 151de7b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

dart/0704-binary-search.dart

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
int search(List<int> nums, int target) {
3+
int l = 0, r = nums.length - 1;
4+
while (l <= r) {
5+
int m = (l + r) ~/ 2;
6+
if (nums[m] == target) {
7+
return m;
8+
} else {
9+
if (nums[m] > target) {
10+
r = m - 1;
11+
} else {
12+
l = m + 1;
13+
}
14+
}
15+
}
16+
return -1;
17+
}
18+
}

0 commit comments

Comments
 (0)