160. 相交链表

题目链接:https://leetcode-cn.com/problems/intersection-of-two-linked-lists/

执行用时:156 ms, 在所有 Kotlin 提交中击败了64.44% 的用户
内存消耗:37.7 MB, 在所有 Kotlin 提交中击败了34.45% 的用户

1
2
3
4
5
6
7
8
9
10
11
class Solution {
fun getIntersectionNode(headA:ListNode?, headB:ListNode?):ListNode? {
var p1 = headA
var p2 = headB
while (p1 != p2) {
p1 = if (p1 != null) p1.next else headB
p2 = if (p2 != null) p2.next else headA
}
return p1;
}
}

160. 相交链表
https://pisces34.github.io/2022/04/19/leetcode/160/
发布于
2022年4月19日
许可协议