FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
leetcode-javascript/intersection-of-two-linked-lists.js at master · didi0613/leetcode-javascript · GitHub
didi0613
/
leetcode-javascript
Public
Notifications
You must be signed in to change notification settings
Fork
4
Star
8
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-javascript
/
intersection-of-two-linked-lists.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
54 lines (48 loc) · 925 Bytes
Breadcrumbs
leetcode-javascript
/
intersection-of-two-linked-lists.js
Copy path
File metadata and controls
54 lines (48 loc) · 925 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* Definition for singly-linked list.
* function ListNode(val) {
* this.val = val;
* this.next = null;
* }
*/
/**
*
@param
{
ListNode
} headA
*
@param
{
ListNode
} headB
*
@return
{
ListNode
}
*/
var
getIntersectionNode
=
function
(
headA
,
headB
)
{
var
lenA
=
0
,
lenB
=
0
;
var
pa
=
headA
;
var
pb
=
headB
;
while
(
pa
)
{
lenA
++
;
pa
=
pa
.
next
;
}
while
(
pb
)
{
lenB
++
;
pb
=
pb
.
next
;
}
if
(
lenA
>=
lenB
)
{
var
diff
=
lenA
-
lenB
;
pa
=
headA
;
pb
=
headB
;
while
(
diff
)
{
pa
=
pa
.
next
;
diff
--
;
}
}
else
{
var
diff2
=
lenB
-
lenA
;
pa
=
headA
;
pb
=
headB
;
while
(
diff2
)
{
pb
=
pb
.
next
;
diff2
--
;
}
}
while
(
pa
!==
pb
)
{
pa
=
pa
.
next
;
pb
=
pb
.
next
;
}
return
pa
;
}
;
// 时间 O(N) 空间 O(1)
Back
|
FazBrowse Home
|
New Git URL