Skip to content

Commit ef4c3f0

Browse files
add yet prod variant for 1424
1 parent 6811ccd commit ef4c3f0

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

contest/src/main/java/com/github/contest/heap/HeapProdVariant.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,22 @@ fun findDiagonalOrderProdVariant(nums: List<List<Int>>): IntArray {
4141
}
4242

4343

44+
fun findDiagonalOrderProdVariantII(nums: List<List<Int>>): IntArray {
45+
PriorityQueue { a: Pair<Int, Pair<Int, Int>>, b: Pair<Int, Pair<Int, Int>> ->
46+
if (a.second.first != b.second.first) a.second.first - b.second.first
47+
else b.first - a.first
48+
}.apply {
49+
nums.forEachIndexed { row, _ ->
50+
nums[row].forEachIndexed { col, num ->
51+
offer(row to (row + col to num))
52+
}
53+
}
54+
}.apply {
55+
return mutableListOf<Int>().also {
56+
while (this.isNotEmpty()) it.add(this.poll().second.second)
57+
}.toIntArray()
58+
}
59+
}
60+
4461

4562

0 commit comments

Comments
 (0)