-
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
Branches - Brianna K #29
base: master
Are you sure you want to change the base?
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,49 @@ | ||
|
||
# Time Complexity: ? | ||
# Space Complexity: ? | ||
# Time Complexity: O(m) | ||
# Space Complexity: O(1) | ||
def remove_duplicates(list) | ||
raise NotImplementedError, "Not implemented yet" | ||
(list.length - 1).times do |count| | ||
if list[count + 1] == list[count] | ||
list[count + 1] = nil | ||
end | ||
end | ||
|
||
(list.length - 1).times do |number| | ||
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. I like how this shifts I went ahead and added a test for C13 on this. |
||
if list[number] == nil | ||
list[number] = list[number + 1] | ||
list[number + 1] = nil | ||
if list[number - 1] == nil | ||
list[number - 1] = list[number] | ||
list[number] = nil | ||
end | ||
end | ||
end | ||
return list | ||
end | ||
|
||
# Time Complexity: ? | ||
# Space Complexity: ? | ||
# Time Complexity: O(n*m) | ||
# Space Complexity: O(1) | ||
def longest_prefix(strings) | ||
raise NotImplementedError, "Not implemented yet" | ||
initial_match = '' | ||
length = strings[0].length | ||
length.times do |letter| | ||
if strings[0][letter] == strings[1][letter] | ||
initial_match.concat(strings[0][letter]) | ||
end | ||
end | ||
|
||
strings.each do |word| | ||
match = '' | ||
initial_match.length.times do |letter| | ||
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. These two loops seem to do the roughly same thing. |
||
if initial_match[letter] == word[letter] | ||
match.concat(word[letter]) | ||
end | ||
end | ||
initial_match = match | ||
end | ||
|
||
return initial_match | ||
end | ||
|
||
# p remove_duplicates([1, 2, 2, 3, 3, 4]) | ||
p longest_prefix(["flower","flow","flight"]) |
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 will miss the times when the number appears 3 times in a row
For example:
[1, 2, 2, 3, 4]