Recursive solution in swift and my illustration

  • 0

    Here is my swift code and my illustration for someone who can hardly understand recursive as me ... :)

    func deleteDuplicates(_ head: ListNode?) -> ListNode? {
        if head == nil || head?.next == nil { return head }
        head!.next = deleteDuplicates(head!.next)
        return head!.val == head!.next?.val ? head!.next : head

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.