Kill Process



I also consider using sort to solve the problem, not by sorting the four points position but sorting the length of two points. Finally, [a, a, a, a, 2a, 2a] is the correct pattern.
public class Solution { public boolean validSquare(int[] p1, int[] p2, int[] p3, int[] p4) { int[] lens = new int[6]; lens[0] = (p1[0]p2[0])*(p1[0]p2[0])+(p1[1]p2[1])*(p1[1]p2[1]); lens[1] = (p1[0]p3[0])*(p1[0]p3[0])+(p1[1]p3[1])*(p1[1]p3[1]); lens[2] = (p1[0]p4[0])*(p1[0]p4[0])+(p1[1]p4[1])*(p1[1]p4[1]); lens[3] = (p2[0]p3[0])*(p2[0]p3[0])+(p2[1]p3[1])*(p2[1]p3[1]); lens[4] = (p2[0]p4[0])*(p2[0]p4[0])+(p2[1]p4[1])*(p2[1]p4[1]); lens[5] = (p3[0]p4[0])*(p3[0]p4[0])+(p3[1]p4[1])*(p3[1]p4[1]); Arrays.sort(lens); for(int i=0; i<3; i++) { if (lens[i]==lens[i+1]) continue; else return false; } if (lens[4]!=lens[5]) return false; if (lens[0]!=0) return true; else return false; } }

You don't consider the situation that a diamond but its angles are not 90degree. (For example,it angles are 60degree,120degree,60degree,120degree,like put two equilateral triangles together). I think your solution should add "the length of four sides != the length of diagonals" in order to avoid this case. And forgive my poor english...