From 215b4351ac9a0391ab7f2d06570be860cb178a91 Mon Sep 17 00:00:00 2001 From: Lanre Adedara Date: Mon, 3 Jun 2024 07:48:54 +0100 Subject: [PATCH] Swift implementation for LCOF2 023 --- .../Solution.swift" | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 "lcof2/\345\211\221\346\214\207 Offer II 023. \344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\351\207\215\345\220\210\350\212\202\347\202\271/Solution.swift" diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 023. \344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\351\207\215\345\220\210\350\212\202\347\202\271/Solution.swift" "b/lcof2/\345\211\221\346\214\207 Offer II 023. \344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\351\207\215\345\220\210\350\212\202\347\202\271/Solution.swift" new file mode 100644 index 0000000000000..6e15cff69fe12 --- /dev/null +++ "b/lcof2/\345\211\221\346\214\207 Offer II 023. \344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\351\207\215\345\220\210\350\212\202\347\202\271/Solution.swift" @@ -0,0 +1,23 @@ +/** + * Definition for singly-linked list. + * public class ListNode { + * public var val: Int + * public var next: ListNode? + * public init(_ val: Int) { + * self.val = val + * self.next = nil + * } + * } + */ + +class Solution { + func getIntersectionNode(_ headA: ListNode?, _ headB: ListNode?) -> ListNode? { + var a = headA + var b = headB + while a !== b { + a = a == nil ? headB : a?.next + b = b == nil ? headA : b?.next + } + return a + } +} \ No newline at end of file