Design a data structure that receives a stream of points on the
Implement the DetectSquares class:
DetectSquares() initializes the object with an empty set of points.
void add(int[] point) adds a new point point = [x, y] into the data structure. Duplicate points are permitted and are considered distinct instances.
int count(int[] point) returns the number of ways to choose point = [x, y], they form an axis-aligned square of positive area.
Note: An axis-aligned square has all
sides parallel or perpendicular to the coordinate axes.
Constraints:
point.length
At most add and count.
Design a data structure that receives a stream of points on the
Implement the DetectSquares class:
DetectSquares() initializes the object with an empty set of points.
void add(int[] point) adds a new point point = [x, y] into the data structure. Duplicate points are permitted and are considered distinct instances.
int count(int[] point) returns the number of ways to choose point = [x, y], they form an axis-aligned square of positive area.
Note: An axis-aligned square has all
sides parallel or perpendicular to the coordinate axes.
Constraints:
point.length
At most add and count.