forked from neetcode-gh/leetcode
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2013-Detect-Squares.cs
35 lines (28 loc) · 989 Bytes
/
2013-Detect-Squares.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
publicclassDetectSquares{
privateDictionary<(intx,inty),int>_pointsCounter=new();
privateList<(intx,inty)>_points=new();
publicDetectSquares(){}
publicvoidAdd(int[]point){
varp=(point[0],point[1]);
_points.Add(p);
_pointsCounter[p]=1+_pointsCounter.GetValueOrDefault(p,0);
}
publicintCount(int[]point){
intpx=point[0],py=point[1];
intresult=0;
foreach(var(x,y)in_points){
if(Math.Abs(px-x)!=Math.Abs(py-y)
||x==px||y==py){
continue;
}
result+=_pointsCounter.GetValueOrDefault((px,y),0)*_pointsCounter.GetValueOrDefault((x,py),0);
}
returnresult;
}
}
/**
* Your DetectSquares object will be instantiated and called as such:
* DetectSquares obj = new DetectSquares();
* obj.Add(point);
* int param_2 = obj.Count(point);
*/