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

Commitb016aeb

Browse files
committed
Revert changes for already submitted solutions
1 parentf4aeeb2 commitb016aeb

File tree

3 files changed

+43
-31
lines changed

3 files changed

+43
-31
lines changed
Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
classKthLargest(privatevalk:Int,nums:IntArray) {
2-
privateval minHeap=PriorityQueue<Int>()
3-
1+
classKthLargest(k:Int,nums:IntArray) {
2+
val minHeap=PriorityQueue<Int>{ a:Int, b:Int->
3+
a- b
4+
}
5+
var k=Integer.MIN_VALUE
46
init{
5-
with (minHeap) {
6-
for (numin nums) add(num)
7-
while (size> k) poll()
8-
}
7+
this.k= k
8+
for(numin nums)
9+
minHeap.add(num)
10+
while(minHeap.size> k)
11+
minHeap.poll()
912
}
10-
1113
funadd(`val`:Int):Int {
12-
with (minHeap) {
13-
add(`val`)
14-
if(size> k) poll()
15-
return peek()
16-
}
14+
minHeap.add(`val`)
15+
if(minHeap.size> k)
16+
minHeap.poll()
17+
return minHeap.peek()
1718
}
19+
1820
}

‎kotlin/1046-Last-Stone-Weight.kt

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
classSolution {
22
funlastStoneWeight(stones:IntArray):Int {
3-
valmaxHeap=PriorityQueue<Int>{ x, y->y- x}
3+
valheap=PriorityQueue<Int>{a, b->b-a}
44

5-
return maxHeap.run {
6-
for (stonein stones) add(stone)
5+
stones.forEach{ stone->
6+
heap.add(stone)
7+
}
78

8-
while (size>1) {
9-
val y= poll()
10-
val x=poll()
9+
while (!heap.isEmpty()) {
10+
if (heap.size==1)
11+
return heap.poll()
1112

12-
if (y!= x) add(y- x)
13-
}
13+
val first= heap.poll()
14+
val sec= heap.poll()
1415

15-
if (size==1) peek()else0
16+
if (first!= sec) {
17+
heap.add(first- sec)
18+
}
1619
}
20+
21+
return0
1722
}
1823
}

‎kotlin/1046-last-stone-weight.kt

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
classSolution {
22
funlastStoneWeight(stones:IntArray):Int {
3-
valmaxHeap=PriorityQueue<Int>{ x, y->y- x}
3+
valheap=PriorityQueue<Int>{a, b->b-a}
44

5-
return maxHeap.run {
6-
for (stonein stones) add(stone)
5+
stones.forEach{ stone->
6+
heap.add(stone)
7+
}
78

8-
while (size>1) {
9-
val y= poll()
10-
val x=poll()
9+
while (!heap.isEmpty()) {
10+
if (heap.size==1)
11+
return heap.poll()
1112

12-
if (y!= x) add(y- x)
13-
}
13+
val first= heap.poll()
14+
val sec= heap.poll()
1415

15-
if (size==1) peek()else0
16+
if (first!= sec) {
17+
heap.add(first- sec)
18+
}
1619
}
20+
21+
return0
1722
}
1823
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp