Skip to content
Open
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
36 changes: 36 additions & 0 deletions MinStack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import java.util.Stack;

class MinStack {

int min;
Stack<Integer> st;
public MinStack() {
st = new Stack<>();
min = Integer.MAX_VALUE;
st.push(min);
}

public void push(int val) {
if(val <= min){
st.push(min);
min = val;
}
st.push(val);
}

public void pop() {
int valPopped = st.pop();
if(valPopped == min){
min = st.pop();
}
}

public int top() {

return st.peek();
}

public int getMin() {
return min;
}
}
68 changes: 68 additions & 0 deletions MyHashSet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Time Complexity :
// Space Complexity :
// Did this code successfully run on Leetcode :
// Any problem you faced while coding this :


// Your code here along with comments explaining your approach
class MyHashSet {

private boolean storage[][];
private int arraySize1;
private int arraySize2;


public MyHashSet() {

this.arraySize1 = 1000;
this.arraySize2 = 1000;
this.storage = new boolean[arraySize1][];

}

private int hash1(int key){

return key%arraySize1;

}

private int hash2(int key){
return key/arraySize2;
}

public void add(int key) {

int arrayIndex1 = hash1(key);
int arrayIndex2 = hash2(key);

if(storage[arrayIndex1] == null){
if(arrayIndex1 == 0){
storage[arrayIndex1]= new boolean[arraySize2+1];
}else{
storage[arrayIndex1]= new boolean[arraySize2];
}
}

storage[arrayIndex1][arrayIndex2] = true;
}

public void remove(int key) {

int arrayIndex1 = hash1(key);
int arrayIndex2 = hash2(key);

if( storage[arrayIndex1] == null) return;
storage[arrayIndex1][arrayIndex2] = false;
}

public boolean contains(int key) {

int arrayIndex1 = hash1(key);
int arrayIndex2 = hash2(key);

if(storage[arrayIndex1] == null) return false;

return storage[arrayIndex1][arrayIndex2];

}
}
7 changes: 0 additions & 7 deletions Sample.java

This file was deleted.