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 ef12666 commit 44bba29Copy full SHA for 44bba29
solution/035.Search Insert Position/README.md
@@ -38,6 +38,7 @@
38
39
除此之外还可用二分法做解。
40
41
+
42
```java
43
class Solution {
44
public int searchInsert(int[] nums, int target) {
@@ -93,6 +94,19 @@ class Solution {
93
94
95
#### CPP
96
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
110
```CPP
111
112
public:
0 commit comments