-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinarySearch.cpp
More file actions
48 lines (43 loc) · 956 Bytes
/
binarySearch.cpp
File metadata and controls
48 lines (43 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <stack>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <sstream>
#include <iomanip>
using namespace std;
bool solve(int start, int end, vector<int> arr, int target){
if(start > end)
return false;
int mid = (start+end)/2;
if(arr[mid] == target)
return true;
else if(arr[mid] < target)
return solve(mid+1, end, arr, target);
else
return solve(start, mid-1, arr, target);
}
int32_t main()
{
vector<int> arr = {1, 2, 3, 5, 6, 8, 12, 24, 46, 89};
int start = 0;
int end = arr.size()-1;
int target = 1;
cout<<solve(start, end, arr, target);
}