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

Commit2c27ff3

Browse files
authored
Create 0149-max-points-on-a-line.kt
1 parent93b3b24 commit2c27ff3

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

‎kotlin/0149-max-points-on-a-line.kt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
classSolution {
2+
funmaxPoints(points:Array<IntArray>):Int {
3+
val n= points.size
4+
5+
var res=1
6+
for (iin0 until n) {
7+
val p1= points[i]
8+
val count=HashMap<Double,Int>()
9+
10+
for (jin i+1 until n) {
11+
val p2= points[j]
12+
13+
val slope=when {
14+
p1[1]== p2[1]->0.0
15+
p1[0]!= p2[0]-> (p1[1]- p2[1])*1.0/ (p1[0]- p2[0])
16+
else->Double.MAX_VALUE
17+
}
18+
19+
count[slope]= count.getOrDefault(slope,0)+1
20+
res= maxOf(res, (count[slope]?:0)+1)
21+
}
22+
}
23+
24+
return res
25+
}
26+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp