Open
Conversation
CheezItMan
reviewed
Oct 1, 2019
CheezItMan
left a comment
There was a problem hiding this comment.
Overall nice work, some small bits could use some work. Take a look at my comments and let me know if you have questions.
Comment on lines
+4
to
+28
| string_stack = Stack.new() | ||
| length = 0 | ||
|
|
||
| string.each_char do |char| | ||
| string_stack.push(Node.new(char)) | ||
| length += 1 | ||
| end | ||
|
|
||
| return false if length % 2 != 0 | ||
|
|
||
| length /= 2 | ||
| comparison_string_stack = Stack.new() | ||
|
|
||
| length.times do | ||
| comparison_string_stack.push(string_stack.pop) | ||
| end | ||
|
|
||
| key = {"[" => "]", "]" => "[", "{" => "}", "}" => "{", "(" => ")", ")" => "("} | ||
|
|
||
| until string_stack.empty? | ||
| letter1 = string_stack.pop | ||
| letter2 = comparison_string_stack.pop | ||
| return false if letter1.data != key[letter2.data] | ||
| end | ||
| return true |
There was a problem hiding this comment.
This method wouldn't work for this balanced string
"{()}[()]"
Consider just using one stack, and traverse the string. When you see a start brace of some sort, you push it on the stack, when you see a close brace you pop and see if they match.
By the end the stack should be empty.
| dequeued = @store[@front] | ||
| @store[@front] = nil | ||
|
|
||
| self.size == 0 ? @front = @rear = -1 : @front = (@front + 1) % QUEUE_SIZE |
There was a problem hiding this comment.
I would say if self.size == 1 (because you'd have 1 element).
|
|
||
| def size | ||
| raise NotImplementedError, "Not yet implemented" | ||
| store = @store.select { |item| item != nil } |
There was a problem hiding this comment.
You could also do this in O(1) with some math.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Stacks and Queues
Thanks for doing some brain yoga. You are now submitting this assignment!
Comprehension Questions
OPTIONAL JobSimulation