Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed Nov 7, 2024
1 parent 07b8303 commit 894e1ae
Showing 1 changed file with 48 additions and 7 deletions.
55 changes: 48 additions & 7 deletions leetcode_java/src/main/java/dev/workspace5.java
Original file line number Diff line number Diff line change
Expand Up @@ -2094,18 +2094,32 @@ public int[] beautifulArray(int n) {
*
*
*/
/**
* if no one in room -> seat at idx 0
* if someone in the room -> seat max distance from it
*
* a heap to track "all distance", so can pop max val from heap
*
*
*
*
*/
class ExamRoom {
// attr
int[] seats;
PriorityQueue<Integer> pq;

public ExamRoom(int n) {

this.seats = new int[n];
this.pq = new PriorityQueue();
}

public int seat() {
return 0;
}

public void leave(int p) {

this.seats[p] = 0;
}

}
Expand Down Expand Up @@ -2339,22 +2353,34 @@ public int minKnightMoves(int x, int y) {
* s s f
*
*/
// 2 pointers
public int removeDuplicates(int[] nums) {
//
int s = 0;
for (int f = 1; f < nums.length; f++){
if (nums[f] != nums[s]){
//
if (nums[s] != nums[f]){
s += 1;
int tmp = nums[f];
nums[f] = nums[s];
nums[s] = tmp;
}
}
//
return s+1;
}
// 2 pointers
// public int removeDuplicates(int[] nums) {
// //
// int s = 0;
// for (int f = 1; f < nums.length; f++){
// if (nums[f] != nums[s]){
// //
// s += 1;
// int tmp = nums[f];
// nums[f] = nums[s];
// nums[s] = tmp;
// }
// }
// //
// return s+1;
// }
/**
* - exp 1
*
Expand Down Expand Up @@ -2531,13 +2557,28 @@ public int removeElement(int[] nums, int val) {
int s = 0;
for (int f = 0; f < nums.length; f++){
if (nums[f] != val){
//int tmp = nums[f];
nums[s] = nums[f];
s += 1;
}
}
return s;
}




// public int removeElement(int[] nums, int val) {
// int s = 0;
// for (int f = 0; f < nums.length; f++){
// if (nums[f] != val){
// nums[s] = nums[f];
// s += 1;
// }
// }
// return s;
// }

// public int removeElement(int[] nums, int val) {
//
// int s = 0;
Expand Down

0 comments on commit 894e1ae

Please sign in to comment.