Skip to content

Commit 44bba29

Browse files
committed
Add Solution 035[CPP]
1 parent ef12666 commit 44bba29

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

solution/035.Search Insert Position/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
除此之外还可用二分法做解。
4040

41+
4142
```java
4243
class Solution {
4344
public int searchInsert(int[] nums, int target) {
@@ -93,6 +94,19 @@ class Solution {
9394

9495
#### CPP
9596

97+
思路1:
98+
99+
1. 先调函数查找是否存在target元素
100+
2. 若存在,用二分法进行查找,或者顺序遍历
101+
3. 若不存在,则顺序遍历插入
102+
103+
时间复杂度O(log2(n))~O(n)
104+
105+
思路2:
106+
1. 直接顺序遍历---需要点取巧,下标比nums长度小,nums[p]元素要比targat小
107+
108+
时间复杂度O(n)
109+
96110
```CPP
97111
class Solution {
98112
public:

0 commit comments

Comments
 (0)