-
Notifications
You must be signed in to change notification settings - Fork 47
Time - Sharon Cheung #31
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?
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,3 +1,17 @@ | ||
| def intersection(list1, list2) | ||
| raise NotImplementedError, "Intersection not implemented" | ||
| count_hash = {} | ||
| result = [] | ||
|
|
||
| list1.each do |number| | ||
| count_hash[number] = true | ||
| end | ||
|
|
||
| list2.each do |number| | ||
| if count_hash[number] == true | ||
| result << number | ||
| end | ||
| end | ||
|
|
||
| return result | ||
|
|
||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,21 @@ | ||
|
|
||
| def palindrome_permutation?(string) | ||
| raise NotImplementedError, "palindrome_permutation? not implemented" | ||
| letter_hash = {} | ||
|
|
||
| string.split("").each do |letter| | ||
| if letter_hash[letter] == nil | ||
| letter_hash[letter] = 1 | ||
| else | ||
| letter_hash[letter] += 1 | ||
| end | ||
| end | ||
|
|
||
| midpoint = 0 | ||
| letter_hash.each_value do |times| | ||
| if times % 2 != 0 | ||
| midpoint += 0 | ||
| end | ||
| end | ||
|
Comment on lines
+14
to
+18
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. You would do better here to see how many letters appear an odd number of times.
Author
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. Sorry about that, Chris! I had a typo in my code. so it should be `def palindrome_permutation?(string) string.split("").each do |letter| midpoint = 0 |
||
|
|
||
| return midpoint <= 1 | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,28 @@ | ||
|
|
||
| def permutations?(string1, string2) | ||
|
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. 👍 |
||
| raise NotImplementedError, "permutations? not implemented" | ||
| word_hash = {} | ||
|
|
||
| string1.split("").each do |letter| | ||
| if word_hash[letter] == nil | ||
| word_hash[letter] = 1 | ||
| else | ||
| word_hash[letter] += 1 | ||
| end | ||
| end | ||
|
|
||
| string2.split("").each do |letter| | ||
| if word_hash[letter] == nil | ||
| return false | ||
| else | ||
| word_hash[letter] -= 1 | ||
| end | ||
| end | ||
|
|
||
| word_hash.each_value do |times| | ||
| if times != 0 | ||
| return false | ||
| end | ||
| end | ||
|
|
||
| return true | ||
| end | ||
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 doesn't seem to work.