We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b1f422e commit b270797Copy full SHA for b270797
README.md
@@ -90,6 +90,7 @@ Leetcode刷题记录
90
91
## 二分
92
93
++ No.32 [cpp](cpp/35.cpp)
94
+ No.50 快速幂 [cpp](cpp/50.cpp) [python](python/50.py)
95
+ No.128 [cpp](cpp/128.cpp) [python](python/128.py)
96
+ No.1300 [cpp](cpp/1300.cpp) [python](python/1300.py)
cpp/35.cpp
@@ -0,0 +1,19 @@
1
+class Solution {
2
+public:
3
+ int searchInsert(vector<int>& nums, int target) {
4
+ int n = nums.size();
5
+ int i = 0, j = n-1, mid;
6
+ while(i < j) {
7
+ mid = (j - i) / 2 + i;
8
+ if (nums[mid] < target) {
9
+ i = mid + 1;
10
+ } else if (nums [mid] > target) {
11
+ j = mid;
12
+ } else {
13
+ return mid;
14
+ }
15
16
+ if (nums[i] < target) i++;
17
+ return i;
18
19
+};
0 commit comments