Skip to content

Commit 25c1e2a

Browse files
add 35
1 parent 205972f commit 25c1e2a

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ LeetCode
2828
|0024|[Swap Nodes in Pairs](https://leetcode.com/problems/swap-nodes-in-pairs/) | c | [c++](./src/0445-Add-Two-Numbers-II/0024.cpp) |[python](./src/0445-Add-Two-Numbers-II/0024.py)|||Medium|
2929
|0026|[Remove Duplicates from Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array/) | c | [c++](./src/0026-Remove-Duplicates-from-Sorted-Array/0026.cpp) |[python](./src/0026-Remove-Duplicates-from-Sorted-Array/0026.py)|||Easy|
3030
|0027|[Remove Element](https://leetcode.com/problems/remove-element/) | c | [c++](./src/0027-Remove-Element/0027.cpp) |[python](./src/0027-Remove-Element/0027.py)|||Easy|
31+
|0035|[Search Insert Position](https://leetcode.com/problems/search-insert-position/) | c | [c++](./src/0035-Search-Insert-Position/0027.cpp) |[python](./src/0035-Search-Insert-Position/0027.py)|||Easy|
3132
|0039|[Combination Sum](https://leetcode.com/problems/combination-sum/) | c | [c++](./src/0039-Combination-Sum/0039.cpp) |[python](./src/0039-Combination-Sum/0039.py)|||Medium|
3233
|0040|[Combination Sum II](https://leetcode.com/problems/combination-sum-ii/) | c | [c++](./src/0040-Combination-Sum-II/0040.cpp) |[python](./src/0040-Combination-Sum-II/0040.py)|||Medium|
3334
|0046|[Permutations](https://leetcode.com/problems/permutations/) | c | [c++](./src/0046-Permutations/0046.cpp) |[python](./src/0046-Permutations/0046.py)|||Medium|
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <iostream>
2+
#include <vector>
3+
using namespace std;
4+
5+
static int x = [](){std::ios::sync_with_stdio(false);cin.tie(0);return 0;}();
6+
class Solution
7+
{
8+
public:
9+
int searchInsert(vector<int>& nums, int target)
10+
{
11+
int l = 0, r = nums.size();
12+
while (l < r)
13+
{
14+
int mid = (r - l)/2 + l;
15+
if (target > nums[mid]) l = mid + 1;
16+
else r = mid;
17+
}
18+
return l;
19+
}
20+
};
21+
int main()
22+
{
23+
vector<int> nums = {1, 3, 5, 6};
24+
int target = 0;
25+
cout << Solution().searchInsert(nums, target);
26+
return 0;
27+
}
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution:
2+
def searchInsert(self, nums, target):
3+
"""
4+
:type nums: List[int]
5+
:type target: int
6+
:rtype: int
7+
"""
8+
l, r = 0, len(nums)
9+
10+
while l < r:
11+
mid = (r + l)//2
12+
if target > nums[mid]:
13+
l = mid + 1
14+
else:
15+
r = mid
16+
17+
return l
18+
19+
if __name__ == "__main__":
20+
nums = [1, 3, 5, 6]
21+
target = 5
22+
print(Solution().searchInsert(nums, target))

0 commit comments

Comments
 (0)