FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
leetcode/code/lc328.java at master · mJackie/leetcode · GitHub
mJackie
/
leetcode
Public
Notifications
You must be signed in to change notification settings
Fork
135
Star
405
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
leetcode
/
code
/
lc328.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
32 lines (32 loc) · 959 Bytes
Breadcrumbs
leetcode
/
code
/
lc328.java
Copy path
File metadata and controls
32 lines (32 loc) · 959 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package
code
;
/*
* 328. Odd Even Linked List
* 题意:奇数的node都在偶数node的后面,第一个节点index为0
* 难度:Medium
* 分类:Linked List
* 思路:while的条件很不好想,记住:这种跳两次的迭代,都判断后边那个节点的 next!=null 为终止条件
* Tips:lc318
*/
public
class
lc328
{
public
class
ListNode
{
int
val
;
ListNode
next
;
ListNode
(
int
x
) {
val
=
x
;
}
}
public
ListNode
oddEvenList
(
ListNode
head
) {
if
(
head
==
null
||
head
.
next
==
null
)
return
head
;
ListNode
even
=
head
;
ListNode
odd_head
=
head
.
next
;
ListNode
odd
=
head
.
next
;
while
(
odd
!=
null
&&
odd
.
next
!=
null
){
//这个条件很难想通
even
.
next
=
even
.
next
.
next
;
odd
.
next
=
odd
.
next
.
next
;
even
=
even
.
next
;
odd
=
odd
.
next
;
}
even
.
next
=
odd_head
;
return
head
;
}
}
Back
|
FazBrowse Home
|
New Git URL