原创 All possible paths
public class AllPath { public static void main(String[] args) { int[][] matrix = new int[3][3]; /*int[][] matrix
原创 subArray Related
//Given an input sorted array find all subarrays with given sum K //time complexity: 0(n), this is for all subarrays
原创 isSubTree
public boolean isSubtree(TreeNode root1, TreeNode root2) { if(root1 == null) return true; else if(root2 == null
原创 Copy LinkedList With Arbitrary Node
To copy a linked list. Every node's next point to the next node, and anoth
原创 Serialize and deserialize a binary tree
//time: O(n), space: O(n). public ArrayList<String> serialize(Node root) { ArrayList<String> result = new ArrayList
原创 Subsets with repeated elements
Given a collection of integers that might contain duplicates, S, return all possible subsets. Note: Elements in a subse
原创 Container With Most Water
//time complexity: O(n). //the max area between twp lines should be decided by the min line public int maxA
原创 Spiral Matrix
public ArrayList<Integer> spiralOrder(int[][] matrix) { // Start typing your Java solution below //