Skip to content
Open

done #2432

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
20 changes: 20 additions & 0 deletions MyHashMap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class MyHashMap {
Map <Integer,Integer> m;

public MyHashMap() {
m=new HashMap<>();
}

public void put(int key, int value) {
m.put(key, value);
}

public int get(int key) {
return (m.containsKey(key)) ? m.get(key) : -1;
}

public void remove(int key) {
m.remove(key);
}
}

43 changes: 43 additions & 0 deletions MyQueue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class MyQueue {
Stack <Integer> in;
Stack <Integer> t;

public MyQueue() {
in=new Stack<>();
t= new Stack<>();
}

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

public int pop() {
if(t.isEmpty())
{
while(!in.isEmpty())
{t.push(in.pop());}
}

return t.pop();
}

public int peek() {
if(t.isEmpty())
{
while(!in.isEmpty())

{
t.push(in.pop());
}


}
return t.peek();

}

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