Skip to content
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

Sockets - Cyndi #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Sockets - Cyndi #6

wants to merge 2 commits into from

Conversation

cyndilopez
Copy link

No description provided.

Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This definitely works, but because you're using .includes your time complexity is actually O(n^3). Instead I suggest using 2 hashes so you can just look up and check to see if the index is in the hash with O(1).

There is also a counterintuitive way to solve the problem without the sets you used, instead using the 1st row and 1st column to store the row and columns to zero out. However this is a good solution. Nice work.

end
rows.times do |row|
columns.times do |col|
if pos.include? row

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest reducing the two if statements to: if pos.include? row || pos.values.include? col

However remember the .include? is a loop, so this is another nested loop.

rows.times do |row|
columns.times do |col|
if matrix[row][col] == 0
if pos.include? row

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure the point of this if statement.

I suggest instead of this if-else statement just having two hashes, one for the rows and the other for columns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants