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
34 changes: 34 additions & 0 deletions design-hashmap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Time Complexity :O(1)
// Space Complexity :O(n)
// Did this code successfully run on Leetcode :Yes
// Any problem you faced while coding this :No

import java.util.Arrays;
class MyHashMap {

int[] hashstorage = new int[1000001];

public MyHashMap() {
Arrays.fill(hashstorage, -1);
}

public void put(int key, int value) {
hashstorage[key] = value;
}

public int get(int key) {
return hashstorage[key];
}

public void remove(int key) {
hashstorage[key]=-1;
}
}

/**
* Your MyHashMap object will be instantiated and called as such:
* MyHashMap obj = new MyHashMap();
* obj.put(key,value);
* int param_2 = obj.get(key);
* obj.remove(key);
*/
45 changes: 45 additions & 0 deletions implement-queue-using-stacks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Time Complexity : O(1)
// Space Complexity : O(n)
// Did this code successfully run on Leetcode : Yes
// Any problem you faced while coding this :No

import java.util.Stack;

class MyQueue {
Stack<Integer> in = new Stack<>();
Stack<Integer> out = new Stack<>();
public MyQueue() {

}

public void push(int x) {
in.push(x);
}

public int pop() {
peek();
return out.pop();
}

public int peek() {
if(out.isEmpty()){
while(!in.isEmpty()){
out.push(in.pop());
}
}
return out.peek();
}

public boolean empty() {
return out.isEmpty() && in.isEmpty();
}
}

/**
* Your MyQueue object will be instantiated and called as such:
* MyQueue obj = new MyQueue();
* obj.push(x);
* int param_2 = obj.pop();
* int param_3 = obj.peek();
* boolean param_4 = obj.empty();
*/