Skip to content

Commit 9286d6a

Browse files
committed
Fixed sonar
1 parent 6f51211 commit 9286d6a

File tree

1 file changed

+3
-8
lines changed
  • src/main/kotlin/g3301_3400/s3382_maximum_area_rectangle_with_point_constraints_ii

1 file changed

+3
-8
lines changed

src/main/kotlin/g3301_3400/s3382_maximum_area_rectangle_with_point_constraints_ii/Solution.kt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,23 @@ class Solution {
1212
return -1
1313
}
1414
val pair = xCoord.zip(yCoord) { x, y -> Pair(x, y) }.toTypedArray()
15-
for (i in xCoord.indices) {
16-
val x0 = xCoord[i]
17-
val y0 = yCoord[i]
18-
pair[i] = Pair(x0, y0)
19-
}
2015
pair.sort()
2116
val map = HashMap<Int?, Pair>()
2217
val yVals = TreeSet<Int?>()
2318
var best: Long = -1
2419
for (i in 0..<pair.size - 1) {
25-
if (!yVals.isEmpty()) {
20+
if (yVals.isNotEmpty()) {
2621
val y0 = pair[i].y
2722
var y1 = yVals.floor(y0)
2823
while (y1 != null) {
29-
val p1: Pair = map.get(y1)!!
24+
val p1: Pair = map[y1]!!
3025
if (p1.y < y0) {
3126
break
3227
}
3328
if (y1 == y0 && pair[i + 1].x == pair[i].x && pair[i + 1].y == p1.y) {
3429
val dY = p1.y - y0.toLong()
3530
val dX = pair[i].x - p1.x.toLong()
36-
best = max((dY * dX).toDouble(), best.toDouble()).toLong()
31+
best = max(dY * dX, best)
3732
}
3833
if (p1.x != pair[i].x) {
3934
yVals.remove(y1)

0 commit comments

Comments
 (0)