Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LinkedList Get Last Node Cost NOT O(1) Time. #980

Open
beta-yu opened this issue Jul 12, 2021 · 1 comment
Open

LinkedList Get Last Node Cost NOT O(1) Time. #980

beta-yu opened this issue Jul 12, 2021 · 1 comment

Comments

@beta-yu
Copy link

beta-yu commented Jul 12, 2021

@beta-yu beta-yu changed the title LinkedList Get Last Node Cost Time NOT O(1) Time. LinkedList Get Last Node Cost NOT O(1) Time. Jul 12, 2021
@beta-yu
Copy link
Author

beta-yu commented Jul 12, 2021

    /// Computed property to iterate through the linked list and return the last node in the list (if any)
    public var last: Node? {
        guard var node = head else {
            return nil
        }
        
        while let next = node.next {
            node = next
        }
        return node
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant