Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5eb8c94

Browse files
feat: add swift implementation to lcof2 problem: No.023 (#3011)
1 parent 67829fa commit 5eb8c94

File tree

1 file changed

+23
-0
lines changed
  • lcof2/剑指 Offer II 023. 两个链表的第一个重合节点

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* public class ListNode {
4+
* public var val: Int
5+
* public var next: ListNode?
6+
* public init(_ val: Int) {
7+
* self.val = val
8+
* self.next = nil
9+
* }
10+
* }
11+
*/
12+
13+
class Solution {
14+
func getIntersectionNode(_ headA: ListNode?, _ headB: ListNode?) -> ListNode? {
15+
var a = headA
16+
var b = headB
17+
while a !== b {
18+
a = a == nil ? headB : a?.next
19+
b = b == nil ? headA : b?.next
20+
}
21+
return a
22+
}
23+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /