-
Notifications
You must be signed in to change notification settings - Fork 46
Branches, C. Gutierrez #21
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work! You hit all the learning goals here. Well done!
# Space complexity - ? | ||
|
||
# Time complexity - O(1) | ||
# Space complexity - O(1) | ||
def add_first(data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Could also be done as:
head = Node.new(data, head)
# Space complexity - ? | ||
|
||
# Time complexity - O(1) | ||
# Space complexity - O(1) | ||
def get_first |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
# Space complexity - ? | ||
|
||
# Time complexity - O(n) | ||
# Space complexity - O(1) | ||
def length |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
elsif current.next == nil | ||
current.next = temp | ||
return | ||
else | ||
current = self.last_node | ||
current.next = temp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a little overly complicated. Can you think of a way to simplify this a bit?
|
||
current = @head | ||
|
||
if @head == nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥇
|
||
current = @head | ||
|
||
if index >= self.length |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
Linked List Comprehension Questions