-
Notifications
You must be signed in to change notification settings - Fork 49
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 - Cloudy #50
base: master
Are you sure you want to change the base?
Leaves - Cloudy #50
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,43 @@ | ||
|
||
# Time Complexity: ? | ||
# Space Complexity: ? | ||
# Time Complexity: OofNsquared bc delete_at takes up ALOT of space (so says my tutor) | ||
# Space Complexity: Oof1 constant bc were not adding to it, we're subtracting | ||
def remove_duplicates(list) | ||
raise NotImplementedError, "Not implemented yet" | ||
i = 0 | ||
list.length.times do |num| | ||
if list[i] == list [i + 1] #if this matches its neighbor... | ||
list.delete_at(i +1) #...delete it! | ||
else | ||
i += 1 #move on | ||
end | ||
end | ||
return list | ||
end | ||
|
||
# Time Complexity: ? | ||
# Space Complexity: ? | ||
#hi chris, this one boggled my mind, dont mind my notes. | ||
# Time Complexity: OofNsquared *maybe? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good idea, it's O(n * m) where n is the number of strings and m is the length of the strings. |
||
# Space Complexity: OofN | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's probably simpler just to put You're right where n is the number of letters in a string. |
||
def longest_prefix(strings) | ||
raise NotImplementedError, "Not implemented yet" | ||
end | ||
prefix = "" #where the prefix is gonna end up | ||
i = 0 #always start here :] | ||
|
||
while i < strings[0].length #from array - starting at the beginning of the word | ||
j = strings[0][i] #get index of word @ letter | ||
k = 0 #counter For same letters #lets see how far we get | ||
|
||
strings.each do |string| #lets look and see whats up | ||
if j == string[i] #does j[letter] match index of letter of comparable string? | ||
k += 1 # If it does, it increments here! | ||
end | ||
end | ||
|
||
if k == strings.length #comparing matches against length | ||
prefix += j #adds letter if it finds a match | ||
else | ||
break #gotta exit loop | ||
end | ||
i += 1 #index moves on | ||
end | ||
return prefix #boom boom | ||
|
||
end #end of method | ||
|
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.
Not space, but time, I understand what you're getting at.