diff --git "a/lcof/\351\235\242\350\257\225\351\242\23052. \344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23052. \344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271/README.md" index dfe0bc42279fe..680239ae6247b 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23052. \344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23052. \344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271/README.md" @@ -253,6 +253,34 @@ public class Solution { } ``` +#### Swift + +```swift +/* 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 + } +} +``` + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23052. \344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271/Solution.swift" "b/lcof/\351\235\242\350\257\225\351\242\23052. \344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271/Solution.swift" new file mode 100644 index 0000000000000..5cdeea2fe35a6 --- /dev/null +++ "b/lcof/\351\235\242\350\257\225\351\242\23052. \344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271/Solution.swift" @@ -0,0 +1,23 @@ +/* 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