Skip to content

Commit de776ba

Browse files
authored
fix: update solutions to lc problems: No.1046,1354 (#4575)
* No.1046.Last Stone Weight * No.1354.Construct Target Array With Multiple Sums
1 parent 5a94bc4 commit de776ba

File tree

7 files changed

+30
-30
lines changed

7 files changed

+30
-30
lines changed

solution/1000-1099/1046.Last Stone Weight/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,18 +163,18 @@ func (h *hp) pop() int { return heap.Pop(h).(int) }
163163

164164
```ts
165165
function lastStoneWeight(stones: number[]): number {
166-
const pq = new MaxPriorityQueue();
166+
const pq = new MaxPriorityQueue<number>();
167167
for (const x of stones) {
168168
pq.enqueue(x);
169169
}
170170
while (pq.size() > 1) {
171-
const y = pq.dequeue().element;
172-
const x = pq.dequeue().element;
171+
const y = pq.dequeue();
172+
const x = pq.dequeue();
173173
if (x !== y) {
174174
pq.enqueue(y - x);
175175
}
176176
}
177-
return pq.isEmpty() ? 0 : pq.dequeue().element;
177+
return pq.isEmpty() ? 0 : pq.dequeue();
178178
}
179179
```
180180

@@ -191,13 +191,13 @@ var lastStoneWeight = function (stones) {
191191
pq.enqueue(x);
192192
}
193193
while (pq.size() > 1) {
194-
const y = pq.dequeue()['priority'];
195-
const x = pq.dequeue()['priority'];
194+
const y = pq.dequeue();
195+
const x = pq.dequeue();
196196
if (x != y) {
197197
pq.enqueue(y - x);
198198
}
199199
}
200-
return pq.isEmpty() ? 0 : pq.dequeue()['priority'];
200+
return pq.isEmpty() ? 0 : pq.dequeue();
201201
};
202202
```
203203

solution/1000-1099/1046.Last Stone Weight/README_EN.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,18 +165,18 @@ func (h *hp) pop() int { return heap.Pop(h).(int) }
165165

166166
```ts
167167
function lastStoneWeight(stones: number[]): number {
168-
const pq = new MaxPriorityQueue();
168+
const pq = new MaxPriorityQueue<number>();
169169
for (const x of stones) {
170170
pq.enqueue(x);
171171
}
172172
while (pq.size() > 1) {
173-
const y = pq.dequeue().element;
174-
const x = pq.dequeue().element;
173+
const y = pq.dequeue();
174+
const x = pq.dequeue();
175175
if (x !== y) {
176176
pq.enqueue(y - x);
177177
}
178178
}
179-
return pq.isEmpty() ? 0 : pq.dequeue().element;
179+
return pq.isEmpty() ? 0 : pq.dequeue();
180180
}
181181
```
182182

@@ -193,13 +193,13 @@ var lastStoneWeight = function (stones) {
193193
pq.enqueue(x);
194194
}
195195
while (pq.size() > 1) {
196-
const y = pq.dequeue()['priority'];
197-
const x = pq.dequeue()['priority'];
196+
const y = pq.dequeue();
197+
const x = pq.dequeue();
198198
if (x != y) {
199199
pq.enqueue(y - x);
200200
}
201201
}
202-
return pq.isEmpty() ? 0 : pq.dequeue()['priority'];
202+
return pq.isEmpty() ? 0 : pq.dequeue();
203203
};
204204
```
205205

solution/1000-1099/1046.Last Stone Weight/Solution.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ var lastStoneWeight = function (stones) {
88
pq.enqueue(x);
99
}
1010
while (pq.size() > 1) {
11-
const y = pq.dequeue()['priority'];
12-
const x = pq.dequeue()['priority'];
11+
const y = pq.dequeue();
12+
const x = pq.dequeue();
1313
if (x != y) {
1414
pq.enqueue(y - x);
1515
}
1616
}
17-
return pq.isEmpty() ? 0 : pq.dequeue()['priority'];
17+
return pq.isEmpty() ? 0 : pq.dequeue();
1818
};
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
function lastStoneWeight(stones: number[]): number {
2-
const pq = new MaxPriorityQueue();
2+
const pq = new MaxPriorityQueue<number>();
33
for (const x of stones) {
44
pq.enqueue(x);
55
}
66
while (pq.size() > 1) {
7-
const y = pq.dequeue().element;
8-
const x = pq.dequeue().element;
7+
const y = pq.dequeue();
8+
const x = pq.dequeue();
99
if (x !== y) {
1010
pq.enqueue(y - x);
1111
}
1212
}
13-
return pq.isEmpty() ? 0 : pq.dequeue().element;
13+
return pq.isEmpty() ? 0 : pq.dequeue();
1414
}

solution/1300-1399/1354.Construct Target Array With Multiple Sums/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,14 @@ func (hp) Push(any) {}
198198

199199
```ts
200200
function isPossible(target: number[]): boolean {
201-
const pq = new MaxPriorityQueue();
201+
const pq = new MaxPriorityQueue<number>();
202202
let s = 0;
203203
for (const x of target) {
204204
s += x;
205205
pq.enqueue(x);
206206
}
207-
while (pq.front().element > 1) {
208-
const mx = pq.dequeue().element;
207+
while (pq.front() > 1) {
208+
const mx = pq.dequeue();
209209
const t = s - mx;
210210
if (t < 1 || mx - t < 1) {
211211
return false;

solution/1300-1399/1354.Construct Target Array With Multiple Sums/README_EN.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,14 @@ func (hp) Push(any) {}
199199

200200
```ts
201201
function isPossible(target: number[]): boolean {
202-
const pq = new MaxPriorityQueue();
202+
const pq = new MaxPriorityQueue<number>();
203203
let s = 0;
204204
for (const x of target) {
205205
s += x;
206206
pq.enqueue(x);
207207
}
208-
while (pq.front().element > 1) {
209-
const mx = pq.dequeue().element;
208+
while (pq.front() > 1) {
209+
const mx = pq.dequeue();
210210
const t = s - mx;
211211
if (t < 1 || mx - t < 1) {
212212
return false;

solution/1300-1399/1354.Construct Target Array With Multiple Sums/Solution.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
function isPossible(target: number[]): boolean {
2-
const pq = new MaxPriorityQueue();
2+
const pq = new MaxPriorityQueue<number>();
33
let s = 0;
44
for (const x of target) {
55
s += x;
66
pq.enqueue(x);
77
}
8-
while (pq.front().element > 1) {
9-
const mx = pq.dequeue().element;
8+
while (pq.front() > 1) {
9+
const mx = pq.dequeue();
1010
const t = s - mx;
1111
if (t < 1 || mx - t < 1) {
1212
return false;

0 commit comments

Comments
 (0)