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
yaozc
ProjectLeet
Commits
d819cdd6
Commit
d819cdd6
authored
Jan 25, 2019
by
yaozc
Browse files
26 solved
parent
778ccbab
Changes
1
Hide whitespace changes
Inline
Side-by-side
code.cpp
View file @
d819cdd6
...
...
@@ -28,3 +28,19 @@ ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {
return
l2
;
}
}
//26 Remove Duplicates from Sorted Array
//solution1: use vector earse function
//solution2 (following one): left and right pointer, once nums[left] is less than nums[right] swap them so nums[left] is the largest distinct element so far. Hard to think but elegent
int
removeDuplicates
(
vector
<
int
>&
nums
)
{
if
(
nums
.
size
()
<
2
){
return
nums
.
size
();
}
int
left
=
0
;
for
(
int
right
=
1
;
right
<
nums
.
size
();
right
++
){
if
(
nums
[
left
]
<
nums
[
right
]){
swap
(
nums
[
++
left
],
nums
[
right
]);
}
}
return
++
left
;
}
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