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
4907f055
Commit
4907f055
authored
Dec 01, 2021
by
anqiwa
😲
Browse files
added linkedlist section
parent
5535d5ad
Changes
2
Hide whitespace changes
Inline
Side-by-side
Linked List/328 odd even Linked List/328.odd-even-linked-list.cpp
0 → 100644
View file @
4907f055
/*
* @lc app=leetcode id=328 lang=cpp
*
* [328] Odd Even Linked List
*/
// @lc code=start
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode() : val(0), next(nullptr) {}
* ListNode(int x) : val(x), next(nullptr) {}
* ListNode(int x, ListNode *next) : val(x), next(next) {}
* };
*/
class
Solution
{
public:
ListNode
*
oddEvenList
(
ListNode
*
head
)
{
if
(
!
head
||
!
head
->
next
)
{
return
head
;
}
ListNode
dummy
;
ListNode
*
dummyPtr
=
&
dummy
;
ListNode
*
curr
=
head
->
next
;
ListNode
*
prev
=
head
;
int
cnt
=
0
;
while
(
curr
)
{
if
(
cnt
%
2
==
0
)
{
prev
->
next
=
curr
->
next
;
dummyPtr
->
next
=
curr
;
curr
=
curr
->
next
;
dummyPtr
=
dummyPtr
->
next
;
dummyPtr
->
next
=
nullptr
;
}
else
{
prev
=
prev
->
next
;
curr
=
curr
->
next
;
}
cnt
++
;
}
prev
->
next
=
dummy
.
next
;
return
head
;
}
};
// @lc code=end
Linked List/328 odd even Linked List/Readme.md
0 → 100644
View file @
4907f055
# 328 Odd Even Linked List
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