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

Sarah #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Sarah #10

wants to merge 1 commit into from

Conversation

sjscotton
Copy link

No description provided.

Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice work. You hit all the learning goals here.

# Time Complexity: O(n) where n is the length of the list. We will ahve to visit each node exactly once
# Space Complexity: O(1) We only use constant size variables
def find_max
max = nil

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just assign max to the 1st element's data?

slow = @head
i = 0
until fast.nil?
slow = slow.next if i % 2 == 1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also do

slow = slow.next
fast = fast.next.next

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

Successfully merging this pull request may close these issues.

2 participants