We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f0f3765 commit 283beb7Copy full SHA for 283beb7
Searching/search_insert_position.cpp
@@ -0,0 +1,35 @@
1
+#include <bits/stdc++.h>
2
+using namespace std;
3
+
4
+int searchInsert(vector<int> nums, int target)
5
+{
6
+ int low = 0, high = nums.size() - 1;
7
8
+ while (low <= high)
9
+ {
10
+ int mid = low + (high - low) / 2;
11
12
+ if (nums[mid] < target)
13
+ low = mid + 1;
14
+ else
15
+ high = mid - 1;
16
+ }
17
18
+ return high + 1;
19
+}
20
21
+int main()
22
23
+ int n;
24
+ cin >> n;
25
+ vector<int> v;
26
+ for (int i = 0; i < n; i++)
27
28
+ int temp;
29
+ cin >> temp;
30
+ v.push_back(temp);
31
32
+ int target;
33
+ cin>>target;
34
+ cout<<searchInsert(v, target);
35
0 commit comments