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

Leaves_Ga-Young #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Leaves_Ga-Young #27

wants to merge 2 commits into from

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)

end

# 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