← 返回 bytedance 的题目列表Check for Valid Square Formation
类型:online_judge
Given an array of N coordinate points, determine if there exist four points that can form a square. Assume the square's edges are parallel to the x and y axes. Return a boolean value true or false. Input should be a list of coordinate points, and produce standard output.
Requirements
Determine if four points can form a square.
Calculate the distances between every two points and check for four equal edges and longer diagonals.
Number of coordinates varies from 4 to 10^5.
Time complexity should achieve O(N^2).
Input Example
[(0,0), (0,1), (1,0), (1,1)]
Output Example
true
Example
Input
[(0,0), (0,1), (1,0), (1,1)]