This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // N time and O(1)O(1) space | |
| import java.util.Map; | |
| import java.util.HashMap; | |
| class Fibber { | |
| Map<Integer, Integer> memo = new HashMap<Integer, Integer>(); | |
| public int fib(int n) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.HashMap; | |
| import java.util.Map; | |
| import java.util.Set; | |
| import java.util.ArrayList; | |
| import java.util.Iterator; | |
| class Trie { | |
| private class TrieNode { | |
| Map<Character, TrieNode> children; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // http://www.geeksforgeeks.org/longest-prefix-matching-a-trie-based-solution-in-java/ | |
| import java.util.HashMap; | |
| import java.util.Map; | |
| import java.util.Set; | |
| import java.util.ArrayList; | |
| import java.util.Iterator; | |
| class Trie { | |
| private class TrieNode { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.HashMap; | |
| import java.util.Map; | |
| import java.util.Set; | |
| import java.util.ArrayList; | |
| import java.util.Iterator; | |
| class Trie { | |
| private class TrieNode { | |
| Map<Character, TrieNode> children; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Java Program to Implement a Phone | |
| // Directory Using Trie Data Structure | |
| import java.util.*; | |
| class TrieNode | |
| { | |
| // Each Trie Node contains a Map 'child' | |
| // where each alphabet points to a Trie | |
| // Node. | |
| HashMap<Character,TrieNode> child; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MyStackImpl { | |
| private int stackSize; | |
| private int[] stackArr; | |
| private int top; | |
| /** | |
| * constructor to create stack with size | |
| * @param size | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.*; | |
| class sort{ | |
| public static void main(String args[]) { | |
| Stack<Integer> s = new Stack<Integer>(); | |
| s.push(10); | |
| s.push(8); | |
| s.push(11); | |
| s.push(1); | |
| s.push(3); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Stack; | |
| class Main { | |
| public static void main(String[] args) { | |
| Stack<Integer> stack = new Stack<Integer>(); | |
| stack.push(30); | |
| stack.push(-5); | |
| stack.push(18); | |
| stack.push(14); | |
| stack.push(-3); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // A class to represent a queue | |
| class Queue | |
| { | |
| int front, rear, size; | |
| int capacity; | |
| int array[]; | |
| public Queue(int n) { | |
| capacity = n; | |
| front = size = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // A linked list (LL) node to store a queue entry | |
| class QNode | |
| { | |
| public int key; | |
| public QNode next; | |
| // constructor to create a new linked list node | |
| public QNode(int key) { | |
| this.key = key; | |
| this.next = null; |