Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
anqiwa
myLeetcodeSolu
Commits
44fe2a21
Commit
44fe2a21
authored
Dec 01, 2021
by
anqiwa
😲
Browse files
started binary search
parent
5c7a8da6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Binary Search/35. Search Insert Position/35.Search insert position.cpp
0 → 100644
View file @
44fe2a21
class
Solution
{
public:
int
searchInsert
(
vector
<
int
>
&
nums
,
int
target
)
{
int
l
=
0
;
int
r
=
nums
.
size
();
while
(
l
<
r
)
{
int
mid
=
l
+
(
r
-
l
)
/
2
;
// [0,1] -> 0
if
(
nums
[
mid
]
<
target
)
{
l
=
mid
+
1
;
}
else
if
(
nums
[
mid
]
>
target
)
{
r
=
mid
;
}
else
{
return
mid
;
}
}
return
r
;
}
};
\ No newline at end of file
Binary Search/35. Search Insert Position/Readme.md
0 → 100644
View file @
44fe2a21
# 35. Search Insert Position
此题是binary search的模板题,很基础,初学者一定要牢记于心,闭着眼睛也要能默写出来
```
cpp
int
l
=
0
,
r
=
nums
.
size
();
while
(
l
<
r
)
{
int
mid
=
l
+
(
r
-
l
)
/
2
;
// [0,1] -> 0
if
(
nums
[
mid
]
<
target
)
{
l
=
mid
+
1
;
}
else
if
(
nums
[
mid
]
>
target
)
{
r
=
mid
;
}
else
{
return
mid
;
}
}
```
\ No newline at end of file
Readme.md
View file @
44fe2a21
...
...
@@ -6,6 +6,14 @@
<br/><br/>
### <b/>分类目录</b>
[
Binary Search
](
)
[
35. Search Insert Position
](
)
[
34. Find First and Last Position of Element in Sorted Array
](
)
[
1060. Missing Element in Sorted Array
](
)
[
Linked List
](
https://gitlab.eecs.umich.edu/anqiwa/myleetcodesolu/-/tree/master/Linked%20List
)
[
328.odd even linked list
](
https://gitlab.eecs.umich.edu/anqiwa/myleetcodesolu/-/tree/master/Linked%20List/328%20odd%20even%20Linked%20List
)
(
M-
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment