Skip to content

Conversation

@gyjin
Copy link

@gyjin gyjin commented Sep 16, 2019

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.

Nice work, both your methods work well. Do take a look at my notes regarding the Big-O. Let me know if you have any questions.

counter = 0
list.length.times do |num|
if list[counter] == list[counter + 1]
list.delete_at(counter + 1)

Choose a reason for hiding this comment

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

Since delete_at shifts all subsequent element left one index, it has a runtime of O(n). Using in your loop here gives you a method time complexity of O(n2)


# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O(n) where n is the strings array

Choose a reason for hiding this comment

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

If the strings are small yes, otherwise you can say O(n * m) where m is the min length of the strings.

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