Skip to content

Commit

Permalink
Merge pull request neetcode-gh#2005 from saip7795/sp/detect-squares
Browse files Browse the repository at this point in the history
Create : 2013-Detect-Squares.rb
  • Loading branch information
saip7795 authored Jan 17, 2023
2 parents b797d10 + 62b2b72 commit 3c6fac4
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions ruby/2013-detect-squares.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class DetectSquares
def initialize()
@points_count = Hash.new(0)
@points = []
end


def add(point)
@points_count[point] +=1
@points.append(point)
end

def count(point)
result = 0
px = point[0]
py = point[1]

@points.each do |p|
next if (((py-p[1]).abs != (px-p[0]).abs) || (p[0]==px) ||(p[1]==py))
result += @points_count[[p[0],py]] * @points_count[[px,p[1]]]
end

return result

end


end

0 comments on commit 3c6fac4

Please sign in to comment.