Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Week 01/id_436/Leetcode_26_436.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

/**
* 在这里给出对类 Leetcode_26_436 的描述。
*
* @作者(你的名字)
* @版本(一个版本号或者一个日期)
*/
public class Leetcode_26_436
{
public int removeDuplicates(int[] nums) {
if(nums.length == 0)
return 0;
int result = 1;
int j = 0;// previous pointer;
for(int i = 0; i < nums.length; i++){
if(nums[j] != nums[i]){
result++;
j++;
nums[j] = nums[i];
}
}
return result;
}
}
28 changes: 28 additions & 0 deletions Week 01/id_436/Leetcode_42_436.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* 在这里给出对类 Leetcode_42_436 的描述。
*
* @作者(你的名字)
* @版本(一个版本号或者一个日期)
*/
import java.util.*;
public class Leetcode_42_436
{
public int trap(int[] height){
int n = height.length;
Deque<Integer> stack = new ArrayDeque<>();
int result = 0;
int index = 0;
while(index < n){
while(!stack.isEmpty() && height[index] > height[stack.peek()]){
int top = stack.pop();
if(stack.isEmpty()) break;
int h = Math.min(height[stack.peek()], height[index]) - height[top];
int dist = index - stack.peek() - 1;
result += dist * h;
}
stack.push(index);
index++;
}
return result;
}
}