# Share my very easy understood Java solution using HashSet

• ``````public class Solution {
public boolean validSquare(int[] p1, int[] p2, int[] p3, int[] p4) {
double a1 = Math.sqrt( (p1[0]-p2[0])*(p1[0]-p2[0]) + (p1[1]-p2[1])*(p1[1]-p2[1]));
double a2 = Math.sqrt( (p1[0]-p3[0])*(p1[0]-p3[0]) + (p1[1]-p3[1])*(p1[1]-p3[1]));
double a3 = Math.sqrt( (p1[0]-p4[0])*(p1[0]-p4[0]) + (p1[1]-p4[1])*(p1[1]-p4[1]));
double a4 = Math.sqrt( (p3[0]-p2[0])*(p3[0]-p2[0]) + (p3[1]-p2[1])*(p3[1]-p2[1]));
double a5 = Math.sqrt( (p4[0]-p2[0])*(p4[0]-p2[0]) + (p4[1]-p2[1])*(p4[1]-p2[1]));
double a6 = Math.sqrt( (p3[0]-p4[0])*(p3[0]-p4[0]) + (p3[1]-p4[1])*(p3[1]-p4[1]));
HashSet <Double> set = new HashSet<>();
if (set.size() == 2){
for (double i:set){
if (i<1)return false;
}
return true;
}
return false;
}
}
``````

• if (i<1)return false;

In my approach, I am comparing the length of the sides vs the length of diagonal. Can you please explain what you are doing here?

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.