Skip to content

Commit 894e1ae

Browse files
committed
update
1 parent 07b8303 commit 894e1ae

File tree

1 file changed

+48
-7
lines changed

1 file changed

+48
-7
lines changed

leetcode_java/src/main/java/dev/workspace5.java

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2094,18 +2094,32 @@ public int[] beautifulArray(int n) {
20942094
*
20952095
*
20962096
*/
2097+
/**
2098+
* if no one in room -> seat at idx 0
2099+
* if someone in the room -> seat max distance from it
2100+
*
2101+
* a heap to track "all distance", so can pop max val from heap
2102+
*
2103+
*
2104+
*
2105+
*
2106+
*/
20972107
class ExamRoom {
2108+
// attr
2109+
int[] seats;
2110+
PriorityQueue<Integer> pq;
20982111

20992112
public ExamRoom(int n) {
2100-
2113+
this.seats = new int[n];
2114+
this.pq = new PriorityQueue();
21012115
}
21022116

21032117
public int seat() {
21042118
return 0;
21052119
}
21062120

21072121
public void leave(int p) {
2108-
2122+
this.seats[p] = 0;
21092123
}
21102124

21112125
}
@@ -2339,22 +2353,34 @@ public int minKnightMoves(int x, int y) {
23392353
* s s f
23402354
*
23412355
*/
2342-
// 2 pointers
23432356
public int removeDuplicates(int[] nums) {
2344-
//
23452357
int s = 0;
23462358
for (int f = 1; f < nums.length; f++){
2347-
if (nums[f] != nums[s]){
2348-
//
2359+
if (nums[s] != nums[f]){
23492360
s += 1;
23502361
int tmp = nums[f];
23512362
nums[f] = nums[s];
23522363
nums[s] = tmp;
23532364
}
23542365
}
2355-
//
23562366
return s+1;
23572367
}
2368+
// 2 pointers
2369+
// public int removeDuplicates(int[] nums) {
2370+
// //
2371+
// int s = 0;
2372+
// for (int f = 1; f < nums.length; f++){
2373+
// if (nums[f] != nums[s]){
2374+
// //
2375+
// s += 1;
2376+
// int tmp = nums[f];
2377+
// nums[f] = nums[s];
2378+
// nums[s] = tmp;
2379+
// }
2380+
// }
2381+
// //
2382+
// return s+1;
2383+
// }
23582384
/**
23592385
* - exp 1
23602386
*
@@ -2531,13 +2557,28 @@ public int removeElement(int[] nums, int val) {
25312557
int s = 0;
25322558
for (int f = 0; f < nums.length; f++){
25332559
if (nums[f] != val){
2560+
//int tmp = nums[f];
25342561
nums[s] = nums[f];
25352562
s += 1;
25362563
}
25372564
}
25382565
return s;
25392566
}
25402567

2568+
2569+
2570+
2571+
// public int removeElement(int[] nums, int val) {
2572+
// int s = 0;
2573+
// for (int f = 0; f < nums.length; f++){
2574+
// if (nums[f] != val){
2575+
// nums[s] = nums[f];
2576+
// s += 1;
2577+
// }
2578+
// }
2579+
// return s;
2580+
// }
2581+
25412582
// public int removeElement(int[] nums, int val) {
25422583
//
25432584
// int s = 0;

0 commit comments

Comments
 (0)