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.*; | |
| public class Solution { | |
| public static void main(String[] args) { | |
| /* some tree nodes */ | |
| checkBST(n, Integer.min_value, Integer.max_value); | |
| } | |
| public static boolean checkBST(TreeNode n, int min, int max) { |
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 TreeNode{ | |
| public int value; | |
| public TreeNode left; | |
| public TreeNode right; | |
| public TreeNode(int v) { | |
| value = v; | |
| left = null; |
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.*; | |
| public class Solution { | |
| public static void main(String[] args) { | |
| TreeNode a = new TreeNode(1); | |
| a.left = new TreeNode(2); | |
| a.right = new TreeNode(3); | |
| a.left.left = new TreeNode(4); | |
| a.left.right = new TreeNode(5); |
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.*; | |
| public class Solution { | |
| public static void main(String[] args) { | |
| LinkedList<Integer> s = new LinkedList<Integer>(); | |
| s.push(4); | |
| s.push(8); | |
| s.push(3); | |
| s.push(5); |
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
| class Tower { | |
| private LinkedList<Integer> plates; | |
| public Tower() { | |
| plates = new LinkedList<Integer>(); | |
| } | |
| /* add plates */ | |
| public void add(int i) { | |
| if(!disks.isEmpty() && disks.peek() <= d) { |
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.*; | |
| public class Solution { | |
| public static void main(String[] args) { | |
| TripleStack ts = new TripleStack(3); | |
| print(ts.pop(0)); | |
| print(ts.pop(1)); | |
| print(ts.pop(2)); | |
| ts.push(0, 1); |
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.*; | |
| public class Solution { | |
| public static void main(String[] args) { | |
| Shelter s = new Shelter(); | |
| s.enqueue("dog1"); | |
| s.enqueue("dog2"); | |
| s.enqueue("cat1"); | |
| s.enqueue("dog3"); | |
| s.enqueue("cat2"); |
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.*; | |
| public class Solution { | |
| public static void main(String[] args) { | |
| MyQueue q = new MyQueue(); | |
| print(q.isEmpty()); | |
| print(q.size()); | |
| q.offer(1); | |
| q.offer(2); | |
| print(q.isEmpty()); |
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
| class SetOfStacks { | |
| private static int threshold = 3; | |
| private LinkedList<LinkedList<Integer>> data; | |
| public SetOfStacks() { | |
| data = new LinkedList<LinkedList<Integer>> (); | |
| LinkedList<Integer> stack1 = new LinkedList<Integer>(); | |
| data.push(stack1); | |
| } |
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
| class Stack { | |
| private LinkedList<Integer> data; | |
| private LinkedList<Integer> min; | |
| public Integer peek() { | |
| /* return the top */ | |
| } | |
| public Integer pop() { | |
| /* pop the top value */ |