forked from AdaGold/Hashmap
-
Notifications
You must be signed in to change notification settings - Fork 47
Space - Jessica #25
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
Open
seaweeddol
wants to merge
5
commits into
Ada-C13:master
Choose a base branch
from
seaweeddol:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Space - Jessica #25
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b28b01d
pass tests with array
seaweeddol d876075
pass tests with hash map
seaweeddol 1a02ee3
pass all tests for permutations
seaweeddol 79a4e40
pass all tests for palindrome_permutation
seaweeddol bcdab63
add time and space complexity
seaweeddol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,27 @@ | ||
| # Time complexity: O(n^2) | ||
| # Space complexity: O(n) | ||
|
|
||
| def intersection(list1, list2) | ||
| raise NotImplementedError, "Intersection not implemented" | ||
| hash = {} | ||
| list1.each do |i| | ||
| if hash[i/10] | ||
| hash[i/10] << i | ||
| else | ||
| hash[i/10] = [i] | ||
| end | ||
| end | ||
|
|
||
| array = [] | ||
| list2.each do |i| | ||
| if hash[i/10] | ||
| hash[i/10].each do |x| | ||
| if i == x | ||
| array << i | ||
| break | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| return array | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,26 @@ | ||
| # Time complexity: O(n) | ||
| # Space complexity: O(n) | ||
|
|
||
| def palindrome_permutation?(string) | ||
|
Comment on lines
+1
to
4
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. 👍 Well done. |
||
| raise NotImplementedError, "palindrome_permutation? not implemented" | ||
| hash = {} | ||
|
|
||
| string.length.times do |i| | ||
| if hash[string[i]] | ||
| hash[string[i]] += 1 | ||
| else | ||
| hash[string[i]] = 1 | ||
| end | ||
| end | ||
|
|
||
|
|
||
| odd = 0 | ||
| hash.each do |k, v| | ||
| if v % 2 != 0 | ||
| if v == 1 | ||
| return false if (odd += 1) > 1 | ||
| end | ||
| end | ||
| end | ||
|
|
||
| return true | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,24 @@ | ||
|
|
||
| # Time complexity: O(n) | ||
| # Space complexity: O(n) | ||
| def permutations?(string1, string2) | ||
|
Comment on lines
+1
to
3
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. 👍 Well done |
||
| raise NotImplementedError, "permutations? not implemented" | ||
| return false if string1.length != string2.length | ||
|
|
||
| hash = {} | ||
| string1.length.times do |i| | ||
| if hash[string1[i]] | ||
| hash[string1[i]] += 1 | ||
| else | ||
| hash[string1[i]] = 1 | ||
| end | ||
| end | ||
|
|
||
| string2.length.times do |i| | ||
| if hash[string2[i]] && hash[string2[i]] > 0 | ||
| hash[string2[i]] -= 1 | ||
| else | ||
| return false | ||
| end | ||
| end | ||
|
|
||
| return true | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Your time complexity is O(n + m) where n and m are the lengths of the two arrays. Otherwise well done.