FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaArithmetic/src/LeetCode/LeetCode24.java at master · feinibuai/JavaArithmetic · GitHub
feinibuai
JavaArithmetic
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaArithmetic
/
src
/
LeetCode
/
LeetCode24.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
28 lines (22 loc) · 701 Bytes
Breadcrumbs
JavaArithmetic
/
src
/
LeetCode
/
LeetCode24.java
Copy path
File metadata and controls
28 lines (22 loc) · 701 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
package
LeetCode
;
public
class
LeetCode24
{
// 24. Swap Nodes in Pairs
// https://leetcode.com/problems/swap-nodes-in-pairs/description/
// 时间复杂度: O(n)
// 空间复杂度: O(1)
public
ListNode
swapPairs
(
ListNode
head
) {
ListNode
dummyHead
=
new
ListNode
(
0
);
dummyHead
.
next
=
head
;
ListNode
p
=
dummyHead
;
while
(
p
.
next
!=
null
&&
p
.
next
.
next
!=
null
){
ListNode
node1
=
p
.
next
;
ListNode
node2
=
node1
.
next
;
ListNode
next
=
node2
.
next
;
node2
.
next
=
node1
;
node1
.
next
=
next
;
p
.
next
=
node2
;
p
=
node1
;
}
return
dummyHead
.
next
;
}
}
Back
|
FazBrowse Home
|
New Git URL