Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5640128

Browse files
committed
Create 2013-detect-squares.swift
1 parent7a6051c commit5640128

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

‎swift/2013-detect-squares.swift‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
classDetectSquares{
3+
4+
varpts=[[Int]]()
5+
varptsCount=[[Int]: Int]()
6+
7+
init(){
8+
9+
}
10+
11+
func add(_ point:[Int]){
12+
ptsCount[point, default:0]+=1
13+
pts.append(point)
14+
}
15+
16+
func count(_ point:[Int])->Int{
17+
varres=0
18+
varx=point[0],y=point[1]
19+
forvalin pts{
20+
letpx=val[0],py=val[1]
21+
ifabs(py- y)!=abs(px- x) || x== px || y== py{
22+
continue
23+
}
24+
res+=ptsCount[[x, py], default:0]* ptsCount[[px, y], default:0]
25+
}
26+
return res
27+
}
28+
}
29+
30+
/**
31+
* Your DetectSquares object will be instantiated and called as such:
32+
* let obj = DetectSquares()
33+
* obj.add(point)
34+
* let ret_2: Int = obj.count(point)
35+
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp