diff --git a/.classpath b/.classpath
deleted file mode 100644
index 33bc9a4..0000000
--- a/.classpath
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
-	<classpathentry kind="src" path="."/>
-	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
-	<classpathentry kind="output" path="bin"/>
-</classpath>
diff --git a/.gitignore b/.gitignore
index 5e56e04..45884c4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
-/bin
+/.idea
+*.iml
diff --git a/.project b/.project
deleted file mode 100644
index 1436b0b..0000000
--- a/.project
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
-	<name>Leetcode</name>
-	<comment></comment>
-	<projects>
-	</projects>
-	<buildSpec>
-		<buildCommand>
-			<name>org.eclipse.jdt.core.javabuilder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-	</buildSpec>
-	<natures>
-		<nature>org.eclipse.jdt.core.javanature</nature>
-	</natures>
-</projectDescription>
diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs
deleted file mode 100644
index 99f26c0..0000000
--- a/.settings/org.eclipse.core.resources.prefs
+++ /dev/null
@@ -1,2 +0,0 @@
-eclipse.preferences.version=1
-encoding/<project>=UTF-8
diff --git a/.settings/org.eclipse.ltk.core.refactoring.prefs b/.settings/org.eclipse.ltk.core.refactoring.prefs
deleted file mode 100644
index b196c64..0000000
--- a/.settings/org.eclipse.ltk.core.refactoring.prefs
+++ /dev/null
@@ -1,2 +0,0 @@
-eclipse.preferences.version=1
-org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false
diff --git a/3SumWithMultiplicity.java b/3SumWithMultiplicity.java
new file mode 100644
index 0000000..a87024f
--- /dev/null
+++ b/3SumWithMultiplicity.java
@@ -0,0 +1,47 @@
+/**
+ * Given an integer array A, and an integer target, return the number of tuples i, j, k  such that i < j < k and A[i] + A[j] + A[k] == target.
+ *
+ * As the answer can be very large, return it modulo 10^9 + 7.
+ */
+class Solution {
+  public int threeSumMulti(int[] A, int target) {
+    Map<Integer, Integer> count = new HashMap<>();
+    for (int a : A) {
+      if (count.containsKey(a)) {
+        count.put(a, count.get(a) + 1);
+      } else {
+        count.put(a, 1);
+      }
+    }
+    Object[] elements = count.keySet().toArray();
+    Integer[] integers = Arrays.copyOf(elements, elements.length, Integer[].class);
+    long ret = 0;
+    Arrays.sort(integers);
+    for (int i = 0; i < integers.length; i++) {
+      for (int j = i; j < integers.length; j++) {
+        int rest = target - integers[i] - integers[j];
+        if (count.containsKey(rest) && rest >= integers[j]) {
+          if (integers[i] == integers[j] && integers[j] == rest) {
+            ret += calculate(count.get(rest), 3);
+          } else if (integers[i] == rest && integers[i] != integers[j]) {
+            ret += (calculate(count.get(integers[i]), 2) * count.get(integers[j]));
+          } else if (integers[j] == rest && integers[i] != integers[j]) {
+            ret += (calculate(count.get(integers[j]), 2) * count.get(integers[i]));
+          } else if (integers[i] == integers[j] && integers[i] != rest) {
+            ret += (calculate(count.get(integers[j]), 2) * count.get(rest));
+          } else {
+            ret += (count.get(integers[i]) * count.get(integers[j]) * count.get(rest));
+          }
+        }
+      }
+    }
+    return (int) (ret % (1e9 + 7));
+  }
+
+  private long calculate(long x, long n) {
+    if (n == 2) {
+      return x * (x - 1) / 2;
+    }
+    return x * (x - 1) * (x - 2) / 6;
+  }
+}
diff --git a/AddBinary.java b/AddBinary.java
index 9eec9dc..81b1eab 100644
--- a/AddBinary.java
+++ b/AddBinary.java
@@ -1,44 +1,41 @@
-
-
 /**
  * Given two binary strings, return their sum (also a binary string).
- * 
- * For example, a = "11" b = "1" Return "100".
+ *
+ * <p>For example, a = "11" b = "1" Return "100".
  */
-
 public class AddBinary {
-	public String addBinary(String a, String b) {
-		int i = a.length() - 1;
-		int j = b.length() - 1;
-		int da = 0;
-		int db = 0;
-		int adv = 0;
-		StringBuffer result = new StringBuffer();
-		while (i >= 0 && j >= 0) {
-			da = a.charAt(i--) == '0' ? 0 : 1;
-			db = b.charAt(j--) == '0' ? 0 : 1;
-			int d = da + db + adv;
-			result.append(d % 2 == 0 ? '0' : '1');
-			adv = d >> 1;
-		}
-		if (i >= 0) {
-			while (i >= 0) {
-				da = a.charAt(i--) == '0' ? 0 : 1;
-				int d = da + adv;
-				result.append(d % 2 == 0 ? '0' : '1');
-				adv = d >> 1;
-			}
-		} else if (j >= 0) {
-			while (j >= 0) {
-				db = b.charAt(j--) == '0' ? 0 : 1;
-				int d = db + adv;
-				result.append(d % 2 == 0 ? '0' : '1');
-				adv = d >> 1;
-			}
-		}
-		if (adv == 1) {
-			result.append('1');
-		}
-		return result.reverse().toString();
-	}
-}
\ No newline at end of file
+  public String addBinary(String a, String b) {
+    int i = a.length() - 1;
+    int j = b.length() - 1;
+    int da = 0;
+    int db = 0;
+    int adv = 0;
+    StringBuffer result = new StringBuffer();
+    while (i >= 0 && j >= 0) {
+      da = a.charAt(i--) == '0' ? 0 : 1;
+      db = b.charAt(j--) == '0' ? 0 : 1;
+      int d = da + db + adv;
+      result.append(d % 2 == 0 ? '0' : '1');
+      adv = d >> 1;
+    }
+    if (i >= 0) {
+      while (i >= 0) {
+        da = a.charAt(i--) == '0' ? 0 : 1;
+        int d = da + adv;
+        result.append(d % 2 == 0 ? '0' : '1');
+        adv = d >> 1;
+      }
+    } else if (j >= 0) {
+      while (j >= 0) {
+        db = b.charAt(j--) == '0' ? 0 : 1;
+        int d = db + adv;
+        result.append(d % 2 == 0 ? '0' : '1');
+        adv = d >> 1;
+      }
+    }
+    if (adv == 1) {
+      result.append('1');
+    }
+    return result.reverse().toString();
+  }
+}
diff --git a/AddTwoNumbers.java b/AddTwoNumbers.java
index 41c64e4..3509a8b 100644
--- a/AddTwoNumbers.java
+++ b/AddTwoNumbers.java
@@ -1,49 +1,44 @@
-
-
 /**
- * You are given two linked lists representing two non-negative numbers. 
- * 
- * The digits are stored in reverse order and each of their nodes contain a single digit.
- * 
- * Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
- * 
- * Output: 7 -> 0 -> 8
+ * You are given two linked lists representing two non-negative numbers.
+ *
+ * <p>The digits are stored in reverse order and each of their nodes contain a single digit.
+ *
+ * <p>Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
+ *
+ * <p>Output: 7 -> 0 -> 8
  */
-
 public class AddTwoNumbers {
-	public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
-		if (l1 == null)
-			return l2;
-		if (l2 == null)
-			return l1;
-		ListNode head = new ListNode(0);
-		ListNode cur = head;
-		int plus = 0;
-		while (l1 != null && l2 != null) {
-			int sum = l1.val + l2.val + plus;
-			plus = sum / 10;
-			sum = sum % 10;
-			cur.next = new ListNode(sum);
-			cur = cur.next;
-			l1 = l1.next;
-			l2 = l2.next;
-		}
-		if (l1 != null) {
-			if (plus != 0) {
-				cur.next = addTwoNumbers(l1, new ListNode(plus));
-			} else {
-				cur.next = l1;
-			}
-		} else if (l2 != null) {
-			if (plus != 0) {
-				cur.next = addTwoNumbers(l2, new ListNode(plus));
-			} else {
-				cur.next = l2;
-			}
-		} else if (plus != 0) {
-			cur.next = new ListNode(plus);
-		}
+  public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
+    if (l1 == null) return l2;
+    if (l2 == null) return l1;
+    ListNode head = new ListNode(0);
+    ListNode cur = head;
+    int plus = 0;
+    while (l1 != null && l2 != null) {
+      int sum = l1.val + l2.val + plus;
+      plus = sum / 10;
+      sum = sum % 10;
+      cur.next = new ListNode(sum);
+      cur = cur.next;
+      l1 = l1.next;
+      l2 = l2.next;
+    }
+    if (l1 != null) {
+      if (plus != 0) {
+        cur.next = addTwoNumbers(l1, new ListNode(plus));
+      } else {
+        cur.next = l1;
+      }
+    } else if (l2 != null) {
+      if (plus != 0) {
+        cur.next = addTwoNumbers(l2, new ListNode(plus));
+      } else {
+        cur.next = l2;
+      }
+    } else if (plus != 0) {
+      cur.next = new ListNode(plus);
+    }
 
-		return head.next;
-	}
-}
\ No newline at end of file
+    return head.next;
+  }
+}
diff --git a/Anagrams.java b/Anagrams.java
index c19b827..924d078 100644
--- a/Anagrams.java
+++ b/Anagrams.java
@@ -1,44 +1,40 @@
-
-
 import java.util.ArrayList;
 import java.util.Arrays;
 
 /**
  * Given an array of strings, return all groups of strings that are anagrams.
- * 
- * Note: All inputs will be in lower-case.
+ *
+ * <p>Note: All inputs will be in lower-case.
  */
-
 public class Anagrams {
-	public ArrayList<String> anagrams(String[] strs) {
-		ArrayList<String> ret = new ArrayList<String>();
-		ArrayList<String> ar = new ArrayList<String>();
-		for (String s : strs) {
-			char[] c = s.toCharArray();
-			Arrays.sort(c);
-			ar.add(new String(c));
-		}
-		int[] list = new int[strs.length];
-		int tmp = 0;
-		for (int i = 0; i < ar.size(); i++) {
-			if (list[i] == 0) {
-				list[i] = 1;
-				tmp = 1;
-				for (int j = i + 1; j < ar.size(); j++) {
-					if (list[j] == 0 && ar.get(i).equals(ar.get(j))) {
-						list[j] = 1;
-						tmp++;
-					}
-				}
-				if (tmp == 1) {
-					list[i] = 0;
-				}
-			}
-		}
-		for (int i = 0; i < list.length; i++) {
-			if (list[i] == 1)
-				ret.add(strs[i]);
-		}
-		return ret;
-	}
-}
\ No newline at end of file
+  public ArrayList<String> anagrams(String[] strs) {
+    ArrayList<String> ret = new ArrayList<String>();
+    ArrayList<String> ar = new ArrayList<String>();
+    for (String s : strs) {
+      char[] c = s.toCharArray();
+      Arrays.sort(c);
+      ar.add(new String(c));
+    }
+    int[] list = new int[strs.length];
+    int tmp = 0;
+    for (int i = 0; i < ar.size(); i++) {
+      if (list[i] == 0) {
+        list[i] = 1;
+        tmp = 1;
+        for (int j = i + 1; j < ar.size(); j++) {
+          if (list[j] == 0 && ar.get(i).equals(ar.get(j))) {
+            list[j] = 1;
+            tmp++;
+          }
+        }
+        if (tmp == 1) {
+          list[i] = 0;
+        }
+      }
+    }
+    for (int i = 0; i < list.length; i++) {
+      if (list[i] == 1) ret.add(strs[i]);
+    }
+    return ret;
+  }
+}
diff --git a/BalancedBinaryTree.java b/BalancedBinaryTree.java
index a8b5a74..ff6d65f 100644
--- a/BalancedBinaryTree.java
+++ b/BalancedBinaryTree.java
@@ -1,28 +1,22 @@
-
 /**
  * Given a binary tree, determine if it is height-balanced.
- * 
- * For this problem, a height-balanced binary tree is defined as a binary tree
- * in which the depth of the two subtrees of every node never differ by more
- * than 1.
- * 
+ *
+ * <p>For this problem, a height-balanced binary tree is defined as a binary tree in which the depth
+ * of the two subtrees of every node never differ by more than 1.
  */
-
 public class BalancedBinaryTree {
-	public boolean isBalanced(TreeNode root) {
-		return determine(root) >= 0 ? true : false;
-	}
+  public boolean isBalanced(TreeNode root) {
+    return determine(root) >= 0 ? true : false;
+  }
 
-	private int determine(TreeNode root) {
-		if (root == null) {
-			return 0;
-		} else {
-			int leftDepth = determine(root.left);
-			int rightDepth = determine(root.right);
-			if (leftDepth < 0 || rightDepth < 0
-					|| Math.abs(leftDepth - rightDepth) > 1)
-				return -1;
-			return Math.max(leftDepth, rightDepth) + 1;
-		}
-	}
-}
\ No newline at end of file
+  private int determine(TreeNode root) {
+    if (root == null) {
+      return 0;
+    } else {
+      int leftDepth = determine(root.left);
+      int rightDepth = determine(root.right);
+      if (leftDepth < 0 || rightDepth < 0 || Math.abs(leftDepth - rightDepth) > 1) return -1;
+      return Math.max(leftDepth, rightDepth) + 1;
+    }
+  }
+}
diff --git a/BestTimetoBuyandSellStock.java b/BestTimetoBuyandSellStock.java
index 346d02c..96fc935 100644
--- a/BestTimetoBuyandSellStock.java
+++ b/BestTimetoBuyandSellStock.java
@@ -1,26 +1,22 @@
-
-
 /**
- * Say you have an array for which the ith element is the price of a given stock
- * on day i.
- * 
- * If you were only permitted to complete at most one transaction (ie, buy one
- * and sell one share of the stock), design an algorithm to find the maximum
- * profit.
+ * Say you have an array for which the ith element is the price of a given stock on day i.
+ *
+ * <p>If you were only permitted to complete at most one transaction (ie, buy one and sell one share
+ * of the stock), design an algorithm to find the maximum profit.
  */
 public class BestTimetoBuyandSellStock {
-	public int maxProfit(int[] prices) {
-		int lowest = 0;
-		int maxProfit = 0;
-		if (prices.length > 0) {
-			lowest = prices[0];
-			for (int i = 0; i < prices.length; i++) {
-				if (lowest > prices[i]) {
-					lowest = prices[i];
-				}
-				maxProfit = Math.max(maxProfit, prices[i] - lowest);
-			}
-		}
-		return maxProfit;
-	}
-}
\ No newline at end of file
+  public int maxProfit(int[] prices) {
+    int lowest = 0;
+    int maxProfit = 0;
+    if (prices.length > 0) {
+      lowest = prices[0];
+      for (int i = 0; i < prices.length; i++) {
+        if (lowest > prices[i]) {
+          lowest = prices[i];
+        }
+        maxProfit = Math.max(maxProfit, prices[i] - lowest);
+      }
+    }
+    return maxProfit;
+  }
+}
diff --git a/BestTimetoBuyandSellStockII.java b/BestTimetoBuyandSellStockII.java
index b5a831d..3426531 100644
--- a/BestTimetoBuyandSellStockII.java
+++ b/BestTimetoBuyandSellStockII.java
@@ -1,24 +1,19 @@
-
-
 /**
- * Say you have an array for which the ith element is the price of a given stock
- * on day i.
- * 
- * Design an algorithm to find the maximum profit. You may complete as many
- * transactions as you like (ie, buy one and sell one share of the stock
- * multiple times). However, you may not engage in multiple transactions at the
- * same time (ie, you must sell the stock before you buy again).
+ * Say you have an array for which the ith element is the price of a given stock on day i.
+ *
+ * <p>Design an algorithm to find the maximum profit. You may complete as many transactions as you
+ * like (ie, buy one and sell one share of the stock multiple times). However, you may not engage in
+ * multiple transactions at the same time (ie, you must sell the stock before you buy again).
  */
-
 public class BestTimetoBuyandSellStockII {
-	public int maxProfit(int[] prices) {
-		int profit = 0;
-		for (int i = 1; i < prices.length; i++) {
-			int d = prices[i] - prices[i - 1];
-			if (d > 0) {
-				profit += d;
-			}
-		}
-		return profit;
-	}
-}
\ No newline at end of file
+  public int maxProfit(int[] prices) {
+    int profit = 0;
+    for (int i = 1; i < prices.length; i++) {
+      int d = prices[i] - prices[i - 1];
+      if (d > 0) {
+        profit += d;
+      }
+    }
+    return profit;
+  }
+}
diff --git a/BestTimetoBuyandSellStockIII.java b/BestTimetoBuyandSellStockIII.java
index 209dcb9..bf9b5b7 100644
--- a/BestTimetoBuyandSellStockIII.java
+++ b/BestTimetoBuyandSellStockIII.java
@@ -1,49 +1,44 @@
-
-
 /**
- * Say you have an array for which the ith element is the price of a given stock
- * on day i.
- * 
- * Design an algorithm to find the maximum profit. You may complete at most two
- * transactions.
- * 
- * Note: You may not engage in multiple transactions at the same time (ie, you
- * must sell the stock before you buy again).
+ * Say you have an array for which the ith element is the price of a given stock on day i.
+ *
+ * <p>Design an algorithm to find the maximum profit. You may complete at most two transactions.
+ *
+ * <p>Note: You may not engage in multiple transactions at the same time (ie, you must sell the
+ * stock before you buy again).
  */
-
 public class BestTimetoBuyandSellStockIII {
-	public int maxProfit(int[] prices) {
-		int length = prices.length;
-		if (length == 0) return 0;
-		int profit = 0;
-		int lowest = prices[0];
-		int[] left = new int[length];
-		int[] right = new int[length];
-		for (int i = 1; i < length; i++) {
-			if (prices[i] < lowest) {
-				lowest = prices[i];
-			} else if (prices[i] - lowest > profit) {
-				profit = prices[i] - lowest;
-			}
-			left[i] = profit;
-		}
-		profit = 0;
-		int topest = prices[length - 1];
-		for (int j = length - 2; j >= 0; j--) {
-			if (prices[j] > topest) {
-				topest = prices[j];
-			} else if (topest - prices[j] > profit) {
-				profit = topest - prices[j];
-			}
-			right[length - 1 - j] = profit;
-		}
-		profit = 0;
-		for (int k = 0; k < length; k++) {
-			int p = left[k] + right[length - 1 - k];
-			if (p > profit) {
-				profit = p;
-			}
-		}
-		return profit;
-	}
-}
\ No newline at end of file
+  public int maxProfit(int[] prices) {
+    int length = prices.length;
+    if (length == 0) return 0;
+    int profit = 0;
+    int lowest = prices[0];
+    int[] left = new int[length];
+    int[] right = new int[length];
+    for (int i = 1; i < length; i++) {
+      if (prices[i] < lowest) {
+        lowest = prices[i];
+      } else if (prices[i] - lowest > profit) {
+        profit = prices[i] - lowest;
+      }
+      left[i] = profit;
+    }
+    profit = 0;
+    int topest = prices[length - 1];
+    for (int j = length - 2; j >= 0; j--) {
+      if (prices[j] > topest) {
+        topest = prices[j];
+      } else if (topest - prices[j] > profit) {
+        profit = topest - prices[j];
+      }
+      right[length - 1 - j] = profit;
+    }
+    profit = 0;
+    for (int k = 0; k < length; k++) {
+      int p = left[k] + right[length - 1 - k];
+      if (p > profit) {
+        profit = p;
+      }
+    }
+    return profit;
+  }
+}
diff --git a/BinaryTreeInorderTraversal.java b/BinaryTreeInorderTraversal.java
index ac53803..e62920f 100644
--- a/BinaryTreeInorderTraversal.java
+++ b/BinaryTreeInorderTraversal.java
@@ -1,41 +1,31 @@
-
-
 import java.util.ArrayList;
 import java.util.Stack;
 
 /**
- * For example: Given binary tree {1,#,2,3},
- * 1
- *  \
- *   2
- *  /
- * 3
- * return [1,3,2].
+ * For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [1,3,2].
  *
- * Note: Recursive solution is trivial, could you do it iteratively?
+ * <p>Note: Recursive solution is trivial, could you do it iteratively?
  */
-
 public class BinaryTreeInorderTraversal {
-	public ArrayList<Integer> inorderTraversal(TreeNode root) {
-		ArrayList<Integer> inOrder = new ArrayList<Integer>();
-		if (root == null)
-			return inOrder;
-		Stack<TreeNode> s = new Stack<TreeNode>();
-		s.add(root);
-		TreeNode p = root.left;
-		while (!s.empty()) {
-			while (p != null) {
-				s.add(p);
-				p = p.left;
-			}
-			TreeNode n = s.pop();
-			inOrder.add(n.val);
-			p = n.right;
-			if (p != null) {
-				s.add(p);
-				p = p.left;
-			}
-		}
-		return inOrder;
-	}
-}
\ No newline at end of file
+  public ArrayList<Integer> inorderTraversal(TreeNode root) {
+    ArrayList<Integer> inOrder = new ArrayList<Integer>();
+    if (root == null) return inOrder;
+    Stack<TreeNode> s = new Stack<TreeNode>();
+    s.add(root);
+    TreeNode p = root.left;
+    while (!s.empty()) {
+      while (p != null) {
+        s.add(p);
+        p = p.left;
+      }
+      TreeNode n = s.pop();
+      inOrder.add(n.val);
+      p = n.right;
+      if (p != null) {
+        s.add(p);
+        p = p.left;
+      }
+    }
+    return inOrder;
+  }
+}
diff --git a/BinaryTreeLevelOrderTraversalII.java b/BinaryTreeLevelOrderTraversalII.java
index 44a656c..f30d3c4 100644
--- a/BinaryTreeLevelOrderTraversalII.java
+++ b/BinaryTreeLevelOrderTraversalII.java
@@ -1,66 +1,51 @@
-
-
 import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.Queue;
 
-/** 
- * Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).
+/**
+ * Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from
+ * left to right, level by level from leaf to root).
  *
- * For example:
- * Given binary tree {3,9,20,#,#,15,7},
- *    3
- *   / \
- *  9  20
- *  /   \
- * 15    7
- * return its bottom-up level order traversal as:
- * [
- *  [15,7]
- *  [9,20],
- *  [3],
- * ]
- * confused what "{1,#,2,3}" means? > read more on how binary tree is serialized on OJ.
- * 
+ * <p>For example: Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7 return its bottom-up
+ * level order traversal as: [ [15,7] [9,20], [3], ] confused what "{1,#,2,3}" means? > read more on
+ * how binary tree is serialized on OJ.
  */
-
 public class BinaryTreeLevelOrderTraversalII {
-	public ArrayList<ArrayList<Integer>> levelOrderBottom(TreeNode root) {
-		ArrayList<ArrayList<Integer>> ret = new ArrayList<ArrayList<Integer>>();
-		if (root == null)
-			return ret;
-		ArrayList<Integer> level = new ArrayList<Integer>();
-		Queue<TreeNode> queue = new LinkedList<TreeNode>();
-		queue.add(root);
-		int currentLevel = 1;
-		int nextLevel = 0;
-		while (!queue.isEmpty()) {
-			TreeNode node = queue.remove();
-			level.add(node.val);
-			currentLevel--;
-			if (node.left != null) {
-				queue.add(node.left);
-				nextLevel++;
-			}
-			if (node.right != null) {
-				queue.add(node.right);
-				nextLevel++;
-			}
-			if (currentLevel == 0) {
-				ret.add(level);
-				level = new ArrayList<Integer>();
-				currentLevel = nextLevel;
-				nextLevel = 0;
-			}
-		}
-		int i = 0, j = ret.size() - 1;
-		while (i < j) {
-			ArrayList<Integer> tmp = ret.get(i);
-			ret.set(i, ret.get(j));
-			ret.set(j, tmp);
-			i++;
-			j--;
-		}
-		return ret;
-	}
-}
\ No newline at end of file
+  public ArrayList<ArrayList<Integer>> levelOrderBottom(TreeNode root) {
+    ArrayList<ArrayList<Integer>> ret = new ArrayList<ArrayList<Integer>>();
+    if (root == null) return ret;
+    ArrayList<Integer> level = new ArrayList<Integer>();
+    Queue<TreeNode> queue = new LinkedList<TreeNode>();
+    queue.add(root);
+    int currentLevel = 1;
+    int nextLevel = 0;
+    while (!queue.isEmpty()) {
+      TreeNode node = queue.remove();
+      level.add(node.val);
+      currentLevel--;
+      if (node.left != null) {
+        queue.add(node.left);
+        nextLevel++;
+      }
+      if (node.right != null) {
+        queue.add(node.right);
+        nextLevel++;
+      }
+      if (currentLevel == 0) {
+        ret.add(level);
+        level = new ArrayList<Integer>();
+        currentLevel = nextLevel;
+        nextLevel = 0;
+      }
+    }
+    int i = 0, j = ret.size() - 1;
+    while (i < j) {
+      ArrayList<Integer> tmp = ret.get(i);
+      ret.set(i, ret.get(j));
+      ret.set(j, tmp);
+      i++;
+      j--;
+    }
+    return ret;
+  }
+}
diff --git a/BinaryTreeMaximumPathSum.java b/BinaryTreeMaximumPathSum.java
index ac0a217..e2f7137 100644
--- a/BinaryTreeMaximumPathSum.java
+++ b/BinaryTreeMaximumPathSum.java
@@ -1,50 +1,43 @@
 /**
  * Given a binary tree, find the maximum path sum.
- * 
- * The path may start and end at any node in the tree.
- * 
- * For example: Given the below binary tree,
- * 
- *   1 
- *  / \ 
- * 2   3
- * 
- * Return 6.
- * 
+ *
+ * <p>The path may start and end at any node in the tree.
+ *
+ * <p>For example: Given the below binary tree,
+ *
+ * <p>1 / \ 2 3
+ *
+ * <p>Return 6.
  */
-
 public class BinaryTreeMaximumPathSum {
-	public int maxPathSum(TreeNode root) {
-		if (root == null)
-			return 0;
-		int[] max = new int[1];
-		max[0] = Integer.MIN_VALUE;
-		maxPathSum(root, max);
-		return max[0];
-	}
+  public int maxPathSum(TreeNode root) {
+    if (root == null) return 0;
+    int[] max = new int[1];
+    max[0] = Integer.MIN_VALUE;
+    maxPathSum(root, max);
+    return max[0];
+  }
 
-	private int maxPathSum(TreeNode root, int[] max) {
-		if (root.left == null && root.right == null) {
-			max[0] = root.val > max[0] ? root.val : max[0];
-			return root.val;
-		} else if (root.left != null && root.right == null) {
-			int left = maxPathSum(root.left, max);
-			max[0] = left > 0 ? Math.max(left + root.val, max[0]) : Math.max(
-					root.val, max[0]);
-			return left > 0 ? left + root.val : root.val;
-		} else if (root.left == null && root.right != null) {
-			int right = maxPathSum(root.right, max);
-			max[0] = right > 0 ? Math.max(right + root.val, max[0]) : Math.max(
-					root.val, max[0]);
-			return right > 0 ? right + root.val : root.val;
-		} else {
-			int left = maxPathSum(root.left, max);
-			int right = maxPathSum(root.right, max);
-			int tmp = root.val;
-			tmp += left > 0 ? left : 0;
-			tmp += right > 0 ? right : 0;
-			max[0] = tmp > max[0] ? tmp : max[0];
-			return Math.max(Math.max(left, right), 0) + root.val;
-		}
-	}
-}
\ No newline at end of file
+  private int maxPathSum(TreeNode root, int[] max) {
+    if (root.left == null && root.right == null) {
+      max[0] = root.val > max[0] ? root.val : max[0];
+      return root.val;
+    } else if (root.left != null && root.right == null) {
+      int left = maxPathSum(root.left, max);
+      max[0] = left > 0 ? Math.max(left + root.val, max[0]) : Math.max(root.val, max[0]);
+      return left > 0 ? left + root.val : root.val;
+    } else if (root.left == null && root.right != null) {
+      int right = maxPathSum(root.right, max);
+      max[0] = right > 0 ? Math.max(right + root.val, max[0]) : Math.max(root.val, max[0]);
+      return right > 0 ? right + root.val : root.val;
+    } else {
+      int left = maxPathSum(root.left, max);
+      int right = maxPathSum(root.right, max);
+      int tmp = root.val;
+      tmp += left > 0 ? left : 0;
+      tmp += right > 0 ? right : 0;
+      max[0] = tmp > max[0] ? tmp : max[0];
+      return Math.max(Math.max(left, right), 0) + root.val;
+    }
+  }
+}
diff --git a/BinaryTreePostorderTraversal.java b/BinaryTreePostorderTraversal.java
index ee9713d..c03c69e 100644
--- a/BinaryTreePostorderTraversal.java
+++ b/BinaryTreePostorderTraversal.java
@@ -1,62 +1,48 @@
-
-
 import java.util.ArrayList;
 import java.util.Stack;
 
 /**
  * Given a binary tree, return the postorder traversal of its nodes' values.
  *
- * For example:
- * Given binary tree {1,#,2,3},
- *   1
- *    \
- *     2
- *    /
- *   3
- * return [3,2,1].
+ * <p>For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [3,2,1].
+ *
+ * <p>Note: Recursive solution is trivial, could you do it iteratively?
  *
- * Note: Recursive solution is trivial, could you do it iteratively?
- * 
- * Solution:
- * 
- * 1. Root - Right - Left
- * 2. Then reverse the sequence
- * 3. Left - Right - Root
+ * <p>Solution:
  *
+ * <p>1. Root - Right - Left 2. Then reverse the sequence 3. Left - Right - Root
  */
-
 public class BinaryTreePostorderTraversal {
-    public ArrayList<Integer> postorderTraversal(TreeNode root) {
-    	ArrayList<Integer> ret = new ArrayList<Integer>();
-		if (root == null)
-			return ret;
-		Stack<TreeNode> st = new Stack<TreeNode>();
-		TreeNode p = root.right;
-		ret.add(root.val);
-		st.add(root);
-		while (!st.isEmpty()) {
-			while (p != null) {
-				ret.add(p.val);
-				st.add(p);
-				p = p.right;
-			}
-			TreeNode node = st.pop();
-			p = node.left;
-			if (p != null) {
-				ret.add(p.val);
-				st.add(p);
-				p = p.right;
-			}
-		}
-		int i = 0;
-		int j = ret.size() - 1;
-		while(i < j) {
-			int tmp = ret.get(i);
-			ret.set(i, ret.get(j));
-			ret.set(j, tmp);
-			i++;
-			j--;
-		}
-		return ret;
+  public ArrayList<Integer> postorderTraversal(TreeNode root) {
+    ArrayList<Integer> ret = new ArrayList<Integer>();
+    if (root == null) return ret;
+    Stack<TreeNode> st = new Stack<TreeNode>();
+    TreeNode p = root.right;
+    ret.add(root.val);
+    st.add(root);
+    while (!st.isEmpty()) {
+      while (p != null) {
+        ret.add(p.val);
+        st.add(p);
+        p = p.right;
+      }
+      TreeNode node = st.pop();
+      p = node.left;
+      if (p != null) {
+        ret.add(p.val);
+        st.add(p);
+        p = p.right;
+      }
+    }
+    int i = 0;
+    int j = ret.size() - 1;
+    while (i < j) {
+      int tmp = ret.get(i);
+      ret.set(i, ret.get(j));
+      ret.set(j, tmp);
+      i++;
+      j--;
     }
+    return ret;
+  }
 }
diff --git a/BinaryTreePreorderTraversal.java b/BinaryTreePreorderTraversal.java
index 1c9f5f3..381e113 100644
--- a/BinaryTreePreorderTraversal.java
+++ b/BinaryTreePreorderTraversal.java
@@ -1,47 +1,35 @@
-
-
 import java.util.ArrayList;
 import java.util.Stack;
 
 /**
  * Given a binary tree, return the preorder traversal of its nodes' values.
  *
- * For example:
- * Given binary tree {1,#,2,3},
- *  1
- *   \
- *    2
- *   /
- *  3
- * return [1,2,3].
+ * <p>For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [1,2,3].
  *
- * Note: Recursive solution is trivial, could you do it iteratively?
- * 
+ * <p>Note: Recursive solution is trivial, could you do it iteratively?
  */
-
 public class BinaryTreePreorderTraversal {
-	public ArrayList<Integer> preorderTraversal(TreeNode root) {
-		ArrayList<Integer> ret = new ArrayList<Integer>();
-		if (root == null)
-			return ret;
-		Stack<TreeNode> st = new Stack<TreeNode>();
-		TreeNode p = root.left;
-		ret.add(root.val);
-		st.add(root);
-		while (!st.isEmpty()) {
-			while (p != null) {
-				ret.add(p.val);
-				st.add(p);
-				p = p.left;
-			}
-			TreeNode node = st.pop();
-			p = node.right;
-			if (p != null) {
-				ret.add(p.val);
-				st.add(p);
-				p = p.left;
-			}
-		}
-		return ret;
-	}
+  public ArrayList<Integer> preorderTraversal(TreeNode root) {
+    ArrayList<Integer> ret = new ArrayList<Integer>();
+    if (root == null) return ret;
+    Stack<TreeNode> st = new Stack<TreeNode>();
+    TreeNode p = root.left;
+    ret.add(root.val);
+    st.add(root);
+    while (!st.isEmpty()) {
+      while (p != null) {
+        ret.add(p.val);
+        st.add(p);
+        p = p.left;
+      }
+      TreeNode node = st.pop();
+      p = node.right;
+      if (p != null) {
+        ret.add(p.val);
+        st.add(p);
+        p = p.left;
+      }
+    }
+    return ret;
+  }
 }
diff --git a/Candy.java b/Candy.java
index 0ec71c8..71118d0 100644
--- a/Candy.java
+++ b/Candy.java
@@ -1,28 +1,27 @@
-
 /**
- * There are N children standing in a line. Each child is assigned a rating
- * value. You are giving candies to these children subjected to the following
- * requirements:
- * 
- * Each child must have at least one candy. Children with a higher rating get
- * more candies than their neighbors.
- * 
- * What is the minimum candies you must give?
- * 
+ * There are N children standing in a line. Each child is assigned a rating value. You are giving
+ * candies to these children subjected to the following requirements:
+ *
+ * <p>Each child must have at least one candy. Children with a higher rating get more candies than
+ * their neighbors.
+ *
+ * <p>What is the minimum candies you must give?
  */
-
 public class Candy {
-	public int candy(int[] ratings) {
-		int[] candy = new int[ratings.length];
-		candy[0] = 1;
-		for (int i = 1; i < ratings.length; i++) {
-			candy[i] = ratings[i] > ratings[i - 1] ? candy[i - 1] + 1 : 1;
-		}
-		int totalCandy = candy[ratings.length - 1];
-		for (int i = ratings.length - 2; i >= 0; i--) {
-			candy[i] = (ratings[i] > ratings[i + 1] && candy[i + 1] + 1 > candy[i]) ? candy[i + 1] + 1 : candy[i];
-			totalCandy += candy[i];
-		}
-		return totalCandy;
-	}
-}
\ No newline at end of file
+  public int candy(int[] ratings) {
+    int[] candy = new int[ratings.length];
+    candy[0] = 1;
+    for (int i = 1; i < ratings.length; i++) {
+      candy[i] = ratings[i] > ratings[i - 1] ? candy[i - 1] + 1 : 1;
+    }
+    int totalCandy = candy[ratings.length - 1];
+    for (int i = ratings.length - 2; i >= 0; i--) {
+      candy[i] =
+          (ratings[i] > ratings[i + 1] && candy[i + 1] + 1 > candy[i])
+              ? candy[i + 1] + 1
+              : candy[i];
+      totalCandy += candy[i];
+    }
+    return totalCandy;
+  }
+}
diff --git a/ClimbingStairs.java b/ClimbingStairs.java
index ac9d9d7..cdb140c 100644
--- a/ClimbingStairs.java
+++ b/ClimbingStairs.java
@@ -1,20 +1,17 @@
-
-
 /**
  * You are climbing a stair case. It takes n steps to reach to the top.
- * 
- * Each time you can either climb 1 or 2 steps. In how many distinct ways can
- * you climb to the top?
+ *
+ * <p>Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the
+ * top?
  */
-
 public class ClimbingStairs {
-	public int climbStairs(int n) {
-		int[] arr = new int[n + 1];
-		arr[0] = 1;
-		arr[1] = 1;
-		for (int i = 2; i <= n; i++) {
-			arr[i] = arr[i - 1] + arr[i - 2];
-		}
-		return arr[n];
-	}
-}
\ No newline at end of file
+  public int climbStairs(int n) {
+    int[] arr = new int[n + 1];
+    arr[0] = 1;
+    arr[1] = 1;
+    for (int i = 2; i <= n; i++) {
+      arr[i] = arr[i - 1] + arr[i - 2];
+    }
+    return arr[n];
+  }
+}
diff --git a/CloneGraph.java b/CloneGraph.java
index d1c8f80..0e15da0 100644
--- a/CloneGraph.java
+++ b/CloneGraph.java
@@ -1,25 +1,18 @@
 /**
  * Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.
- * 
- * OJ's undirected graph serialization:
- * Nodes are labeled uniquely.
- * 
- * We use # as a separator for each node, and , as a separator for node label and each neighbor of the node.
- * As an example, consider the serialized graph {0,1,2#1,2#2,2}.
- * 
- * The graph has a total of three nodes, and therefore contains three parts as separated by #.
- * 
- * First node is labeled as 0. Connect node 0 to both nodes 1 and 2.
- * Second node is labeled as 1. Connect node 1 to node 2.
- * Third node is labeled as 2. Connect node 2 to node 2 (itself), thus forming a self-cycle.
- * Visually, the graph looks like the following:
  *
- *      1
- *     / \
- *    /   \
- *   0 --- 2
- *        / \
- *        \_/
+ * <p>OJ's undirected graph serialization: Nodes are labeled uniquely.
+ *
+ * <p>We use # as a separator for each node, and , as a separator for node label and each neighbor
+ * of the node. As an example, consider the serialized graph {0,1,2#1,2#2,2}.
+ *
+ * <p>The graph has a total of three nodes, and therefore contains three parts as separated by #.
+ *
+ * <p>First node is labeled as 0. Connect node 0 to both nodes 1 and 2. Second node is labeled as 1.
+ * Connect node 1 to node 2. Third node is labeled as 2. Connect node 2 to node 2 (itself), thus
+ * forming a self-cycle. Visually, the graph looks like the following:
+ *
+ * <p>1 / \ / \ 0 --- 2 / \ \_/
  */
 
 import java.util.HashMap;
@@ -30,37 +23,36 @@
 import java.util.Set;
 
 public class CloneGraph {
-	public UndirectedGraphNode cloneGraph(UndirectedGraphNode node) {
-		if (node == null)
-			return node;
-		Queue<UndirectedGraphNode> queue = new LinkedList<UndirectedGraphNode>();
-		queue.add(node);
-		Set<UndirectedGraphNode> visited = new HashSet<UndirectedGraphNode>();
-		Map<UndirectedGraphNode, UndirectedGraphNode> map = new HashMap<UndirectedGraphNode, UndirectedGraphNode>();
-		while (!queue.isEmpty()) {
-			UndirectedGraphNode n = queue.remove();
-			if (visited.contains(n))
-				continue;
-			visited.add(n);
-			UndirectedGraphNode clone;
-			if (!map.containsKey(n)) {
-				clone = new UndirectedGraphNode(n.label);
-				map.put(n, clone);
-			} else {
-				clone = map.get(n);
-			}
-			for (UndirectedGraphNode child : n.neighbors) {
-				queue.add(child);
-				UndirectedGraphNode cloneChild;
-				if (!map.containsKey(child)) {
-					cloneChild = new UndirectedGraphNode(child.label);
-					map.put(child, cloneChild);
-				} else {
-					cloneChild = map.get(child);
-				}
-				clone.neighbors.add(cloneChild);
-			}
-		}
-		return map.get(node);
-	}
+  public UndirectedGraphNode cloneGraph(UndirectedGraphNode node) {
+    if (node == null) return node;
+    Queue<UndirectedGraphNode> queue = new LinkedList<UndirectedGraphNode>();
+    queue.add(node);
+    Set<UndirectedGraphNode> visited = new HashSet<UndirectedGraphNode>();
+    Map<UndirectedGraphNode, UndirectedGraphNode> map =
+        new HashMap<UndirectedGraphNode, UndirectedGraphNode>();
+    while (!queue.isEmpty()) {
+      UndirectedGraphNode n = queue.remove();
+      if (visited.contains(n)) continue;
+      visited.add(n);
+      UndirectedGraphNode clone;
+      if (!map.containsKey(n)) {
+        clone = new UndirectedGraphNode(n.label);
+        map.put(n, clone);
+      } else {
+        clone = map.get(n);
+      }
+      for (UndirectedGraphNode child : n.neighbors) {
+        queue.add(child);
+        UndirectedGraphNode cloneChild;
+        if (!map.containsKey(child)) {
+          cloneChild = new UndirectedGraphNode(child.label);
+          map.put(child, cloneChild);
+        } else {
+          cloneChild = map.get(child);
+        }
+        clone.neighbors.add(cloneChild);
+      }
+    }
+    return map.get(node);
+  }
 }
diff --git a/CombinationSum.java b/CombinationSum.java
index fb1b4ec..619c0a7 100644
--- a/CombinationSum.java
+++ b/CombinationSum.java
@@ -1,47 +1,47 @@
-
 import java.util.ArrayList;
 import java.util.Arrays;
 
 /**
- * Given a set of candidate numbers (C) and a target number (T), find all unique
- * combinations in C where the candidate numbers sums to T.
- * 
- * The same repeated number may be chosen from C unlimited number of times.
- * 
- * Note:
- * 
- * All numbers (including target) will be positive integers.
- * 
- * Elements in a combination (a1, a2, ... , ak) must be in non-descending order.
- * (ie, a1 <= a2 <= ... <= ak).
- * 
- * The solution set must not contain duplicate combinations. For example, given
- * candidate set 2,3,6,7 and target 7, A solution set is: [7] [2, 2, 3]
+ * Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C
+ * where the candidate numbers sums to T.
+ *
+ * <p>The same repeated number may be chosen from C unlimited number of times.
+ *
+ * <p>Note:
+ *
+ * <p>All numbers (including target) will be positive integers.
+ *
+ * <p>Elements in a combination (a1, a2, ... , ak) must be in non-descending order. (ie, a1 <= a2 <=
+ * ... <= ak).
+ *
+ * <p>The solution set must not contain duplicate combinations. For example, given candidate set
+ * 2,3,6,7 and target 7, A solution set is: [7] [2, 2, 3]
  */
-
 public class CombinationSum {
-	public ArrayList<ArrayList<Integer>> combinationSum(int[] candidates,
-			int target) {
-		ArrayList<ArrayList<Integer>> ret = new ArrayList<ArrayList<Integer>>();
-		ArrayList<Integer> solution = new ArrayList<Integer>();
-		Arrays.sort(candidates);
-		combinationSum(candidates, 0, 0, target, ret, solution);
-		return ret;
-	}
+  public ArrayList<ArrayList<Integer>> combinationSum(int[] candidates, int target) {
+    ArrayList<ArrayList<Integer>> ret = new ArrayList<ArrayList<Integer>>();
+    ArrayList<Integer> solution = new ArrayList<Integer>();
+    Arrays.sort(candidates);
+    combinationSum(candidates, 0, 0, target, ret, solution);
+    return ret;
+  }
 
-	private void combinationSum(int[] candidates, int start, int sum,
-			int target, ArrayList<ArrayList<Integer>> ret,
-			ArrayList<Integer> solution) {
-		if (sum == target) {
-			ret.add(new ArrayList<Integer>(solution));
-			return;
-		}
-		if (sum > target)
-			return;
-		for (int i = start; i < candidates.length; i++) {
-			solution.add(candidates[i]);
-			combinationSum(candidates, start, sum + candidates[i], target, ret, solution);
-			solution.remove(solution.size() - 1);
-		}
-	}
-}
\ No newline at end of file
+  private void combinationSum(
+      int[] candidates,
+      int start,
+      int sum,
+      int target,
+      ArrayList<ArrayList<Integer>> ret,
+      ArrayList<Integer> solution) {
+    if (sum == target) {
+      ret.add(new ArrayList<Integer>(solution));
+      return;
+    }
+    if (sum > target) return;
+    for (int i = start; i < candidates.length; i++) {
+      solution.add(candidates[i]);
+      combinationSum(candidates, start, sum + candidates[i], target, ret, solution);
+      solution.remove(solution.size() - 1);
+    }
+  }
+}
diff --git a/CombinationSumII.java b/CombinationSumII.java
index 408a1f2..9737e1b 100644
--- a/CombinationSumII.java
+++ b/CombinationSumII.java
@@ -1,50 +1,48 @@
 /**
- * Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.
- * 
- * Each number in C may only be used once in the combination.
- * 
- * Note:
- * 
- * All numbers (including target) will be positive integers.
- * 
- * Elements in a combination (a1, a2, … , ak) must be in non-descending order. (ie, a1 ≤ a2 ≤ … ≤ ak).
- * The solution set must not contain duplicate combinations.
- * For example, given candidate set 10,1,2,7,6,1,5 and target 8, A solution set is: 
- * [1, 7] 
- * [1, 2, 5] 
- * [2, 6] 
- * [1, 1, 6] 
+ * Given a collection of candidate numbers (C) and a target number (T), find all unique combinations
+ * in C where the candidate numbers sums to T.
+ *
+ * <p>Each number in C may only be used once in the combination.
+ *
+ * <p>Note:
+ *
+ * <p>All numbers (including target) will be positive integers.
+ *
+ * <p>Elements in a combination (a1, a2, … , ak) must be in non-descending order. (ie, a1 ≤ a2 ≤ … ≤
+ * ak). The solution set must not contain duplicate combinations. For example, given candidate set
+ * 10,1,2,7,6,1,5 and target 8, A solution set is: [1, 7] [1, 2, 5] [2, 6] [1, 1, 6]
  */
 
 import java.util.ArrayList;
 import java.util.Arrays;
 
 public class CombinationSumII {
-	public ArrayList<ArrayList<Integer>> combinationSum2(int[] candidates,
-			int target) {
-		ArrayList<ArrayList<Integer>> res = new ArrayList<ArrayList<Integer>>();
-		ArrayList<Integer> list = new ArrayList<Integer>();
-		Arrays.sort(candidates);
-		dfs(res, 0, candidates, list, target);
-		return res;
-	}
+  public ArrayList<ArrayList<Integer>> combinationSum2(int[] candidates, int target) {
+    ArrayList<ArrayList<Integer>> res = new ArrayList<ArrayList<Integer>>();
+    ArrayList<Integer> list = new ArrayList<Integer>();
+    Arrays.sort(candidates);
+    dfs(res, 0, candidates, list, target);
+    return res;
+  }
 
-	private void dfs(ArrayList<ArrayList<Integer>> res, int start,
-			int[] candidates, ArrayList<Integer> list, int target) {
-		if (target == 0) {
-			res.add(new ArrayList<Integer>(list));
-			return;
-		}
-		int pre = -1;
-		for (int i = start; i < candidates.length; i++) {
-			if (pre == candidates[i])
-				continue;
-			if (candidates[i] > target)
-				return;
-			pre = candidates[i];
-			list.add(candidates[i]);
-			dfs(res, i + 1, candidates, list, target - candidates[i]);
-			list.remove(list.size() - 1);
-		}
-	}
+  private void dfs(
+      ArrayList<ArrayList<Integer>> res,
+      int start,
+      int[] candidates,
+      ArrayList<Integer> list,
+      int target) {
+    if (target == 0) {
+      res.add(new ArrayList<Integer>(list));
+      return;
+    }
+    int pre = -1;
+    for (int i = start; i < candidates.length; i++) {
+      if (pre == candidates[i]) continue;
+      if (candidates[i] > target) return;
+      pre = candidates[i];
+      list.add(candidates[i]);
+      dfs(res, i + 1, candidates, list, target - candidates[i]);
+      list.remove(list.size() - 1);
+    }
+  }
 }
diff --git a/Combinations.java b/Combinations.java
index 3abe1e5..7e8228b 100644
--- a/Combinations.java
+++ b/Combinations.java
@@ -1,38 +1,39 @@
-
-
 import java.util.ArrayList;
 
 /**
- * Given two integers n and k, return all possible combinations of k numbers out
- * of 1 ... n. For example, If n = 4 and k = 2, a solution is:
- * 
- * [ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4], ]
- * 
+ * Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For
+ * example, If n = 4 and k = 2, a solution is:
+ *
+ * <p>[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4], ]
  */
-
 public class Combinations {
-	public ArrayList<ArrayList<Integer>> combine(int n, int k) {
-		ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>();
-		ArrayList<Integer> subset = new ArrayList<Integer>();
-		int[] num = new int[n];
-		for (int j = 0; j < n; j++) {
-			num[j] = j + 1;
-		}
-		subsets(n, k, num, 0, subset, result);
-		return result;
-	}
+  public ArrayList<ArrayList<Integer>> combine(int n, int k) {
+    ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>();
+    ArrayList<Integer> subset = new ArrayList<Integer>();
+    int[] num = new int[n];
+    for (int j = 0; j < n; j++) {
+      num[j] = j + 1;
+    }
+    subsets(n, k, num, 0, subset, result);
+    return result;
+  }
 
-	private void subsets(int n, int k, int[] num, int begin,
-			ArrayList<Integer> subset, ArrayList<ArrayList<Integer>> result) {
-		if (subset.size() >= k) {
-			ArrayList<Integer> c = new ArrayList<Integer>(subset);
-			result.add(c);
-		} else {
-			for (int i = begin; i < num.length; i++) {
-				subset.add(num[i]);
-				subsets(n, k, num, i + 1, subset, result);
-				subset.remove(subset.size() - 1);
-			}
-		}
-	}
-}
\ No newline at end of file
+  private void subsets(
+      int n,
+      int k,
+      int[] num,
+      int begin,
+      ArrayList<Integer> subset,
+      ArrayList<ArrayList<Integer>> result) {
+    if (subset.size() >= k) {
+      ArrayList<Integer> c = new ArrayList<Integer>(subset);
+      result.add(c);
+    } else {
+      for (int i = begin; i < num.length; i++) {
+        subset.add(num[i]);
+        subsets(n, k, num, i + 1, subset, result);
+        subset.remove(subset.size() - 1);
+      }
+    }
+  }
+}
diff --git a/ConstructBinaryTreefromInorderandPostorderTraversal.java b/ConstructBinaryTreefromInorderandPostorderTraversal.java
index 3a6fbf8..2c3e686 100644
--- a/ConstructBinaryTreefromInorderandPostorderTraversal.java
+++ b/ConstructBinaryTreefromInorderandPostorderTraversal.java
@@ -1,36 +1,27 @@
-
-
 /**
  * Given inorder and postorder traversal of a tree, construct the binary tree.
  *
- * Note:
- * 
- * You may assume that duplicates do not exist in the tree.
- * 
+ * <p>Note:
+ *
+ * <p>You may assume that duplicates do not exist in the tree.
  */
-
 public class ConstructBinaryTreefromInorderandPostorderTraversal {
-	public TreeNode buildTree(int[] inorder, int[] postorder) {
-		return buildTree(inorder, 0, inorder.length - 1, postorder, 0,
-				postorder.length - 1);
-	}
+  public TreeNode buildTree(int[] inorder, int[] postorder) {
+    return buildTree(inorder, 0, inorder.length - 1, postorder, 0, postorder.length - 1);
+  }
 
-	public TreeNode buildTree(int[] inorder, int is, int ie, int[] postorder,
-			int ps, int pe) {
-		if (is > ie || ps > pe)
-			return null;
-		int rootVal = postorder[pe];
-		TreeNode root = new TreeNode(rootVal);
-		for (int i = is; i <= ie; i++) {
-			if (inorder[i] == rootVal) {
-				TreeNode left = buildTree(inorder, is, i - 1, postorder, ps, ps
-						+ i - is - 1);
-				TreeNode right = buildTree(inorder, i + 1, ie, postorder, pe
-						- ie + i, pe - 1);
-				root.left = left;
-				root.right = right;
-			}
-		}
-		return root;
-	}
-}
\ No newline at end of file
+  public TreeNode buildTree(int[] inorder, int is, int ie, int[] postorder, int ps, int pe) {
+    if (is > ie || ps > pe) return null;
+    int rootVal = postorder[pe];
+    TreeNode root = new TreeNode(rootVal);
+    for (int i = is; i <= ie; i++) {
+      if (inorder[i] == rootVal) {
+        TreeNode left = buildTree(inorder, is, i - 1, postorder, ps, ps + i - is - 1);
+        TreeNode right = buildTree(inorder, i + 1, ie, postorder, pe - ie + i, pe - 1);
+        root.left = left;
+        root.right = right;
+      }
+    }
+    return root;
+  }
+}
diff --git a/ConstructBinaryTreefromPreorderAndInorderTraversal.java b/ConstructBinaryTreefromPreorderAndInorderTraversal.java
index 68fb3c5..6e4d871 100644
--- a/ConstructBinaryTreefromPreorderAndInorderTraversal.java
+++ b/ConstructBinaryTreefromPreorderAndInorderTraversal.java
@@ -1,40 +1,36 @@
 /**
  * Given preorder and inorder traversal of a tree, construct the binary tree.
- * 
- * Note:
- * 
- * You may assume that duplicates do not exist in the tree.
+ *
+ * <p>Note:
+ *
+ * <p>You may assume that duplicates do not exist in the tree.
  */
-
 public class ConstructBinaryTreefromPreorderAndInorderTraversal {
-	public TreeNode buildTree(int[] preorder, int[] inorder) {
-		int length1 = preorder.length;
-		int length2 = inorder.length;
-		return buildTree(preorder, 0, length1, inorder, 0, length2);
-	}
+  public TreeNode buildTree(int[] preorder, int[] inorder) {
+    int length1 = preorder.length;
+    int length2 = inorder.length;
+    return buildTree(preorder, 0, length1, inorder, 0, length2);
+  }
 
-	private TreeNode buildTree(int[] preorder, int s1, int e1, int[] inorder,
-			int s2, int e2) {
-		if (s1 >= e1 || s2 >= e2) {
-			return null;
-		}
-		if (s1 + 1 == e1) {
-			return new TreeNode(preorder[s1]);
-		}
-		int mid = preorder[s1];
-		int i = s2;
-		for (; i < e2; i++) {
-			if (inorder[i] == mid) {
-				break;
-			}
-		}
-		TreeNode left = buildTree(preorder, s1 + 1, s1 + 1 + i - s2, inorder,
-				s2, i);
-		TreeNode right = buildTree(preorder, s1 + 1 + i - s2, e1, inorder,
-				i + 1, e2);
-		TreeNode root = new TreeNode(preorder[s1]);
-		root.left = left;
-		root.right = right;
-		return root;
-	}
+  private TreeNode buildTree(int[] preorder, int s1, int e1, int[] inorder, int s2, int e2) {
+    if (s1 >= e1 || s2 >= e2) {
+      return null;
+    }
+    if (s1 + 1 == e1) {
+      return new TreeNode(preorder[s1]);
+    }
+    int mid = preorder[s1];
+    int i = s2;
+    for (; i < e2; i++) {
+      if (inorder[i] == mid) {
+        break;
+      }
+    }
+    TreeNode left = buildTree(preorder, s1 + 1, s1 + 1 + i - s2, inorder, s2, i);
+    TreeNode right = buildTree(preorder, s1 + 1 + i - s2, e1, inorder, i + 1, e2);
+    TreeNode root = new TreeNode(preorder[s1]);
+    root.left = left;
+    root.right = right;
+    return root;
+  }
 }
diff --git a/ContainerWithMostWater.java b/ContainerWithMostWater.java
index ad8f4fa..fe39aa4 100644
--- a/ContainerWithMostWater.java
+++ b/ContainerWithMostWater.java
@@ -1,27 +1,23 @@
-
-
 /**
- * Given n non-negative integers a1, a2, ..., an, where each represents a point
- * at coordinate (i, ai). n vertical lines are drawn such that the two endpoints
- * of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis
- * forms a container, such that the container contains the most water.
- * 
- * Note: You may not slant the container.
+ * Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i,
+ * ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0).
+ * Find two lines, which together with x-axis forms a container, such that the container contains
+ * the most water.
+ *
+ * <p>Note: You may not slant the container.
  */
-
 public class ContainerWithMostWater {
-	public int maxArea(int[] height) {
-		int len = height.length, low = 0, high = len - 1;
-		int maxArea = 0;
-		while (low < high) {
-			maxArea = Math.max(maxArea,
-					(high - low) * Math.min(height[low], height[high]));
-			if (height[low] < height[high]) {
-				low++;
-			} else {
-				high--;
-			}
-		}
-		return maxArea;
-	}
-}
\ No newline at end of file
+  public int maxArea(int[] height) {
+    int len = height.length, low = 0, high = len - 1;
+    int maxArea = 0;
+    while (low < high) {
+      maxArea = Math.max(maxArea, (high - low) * Math.min(height[low], height[high]));
+      if (height[low] < height[high]) {
+        low++;
+      } else {
+        high--;
+      }
+    }
+    return maxArea;
+  }
+}
diff --git a/ConvertSortedArraytoBinarySearchTree.java b/ConvertSortedArraytoBinarySearchTree.java
index ae78786..0382f5d 100644
--- a/ConvertSortedArraytoBinarySearchTree.java
+++ b/ConvertSortedArraytoBinarySearchTree.java
@@ -1,24 +1,21 @@
-
-
 /**
  * Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
  */
-
 public class ConvertSortedArraytoBinarySearchTree {
-	public TreeNode sortedArrayToBST(int[] num) {
-		return sortedArrayToBST(num, 0, num.length - 1);
-	}
+  public TreeNode sortedArrayToBST(int[] num) {
+    return sortedArrayToBST(num, 0, num.length - 1);
+  }
 
-	public TreeNode sortedArrayToBST(int[] num, int start, int end) {
-		if (start <= end) {
-			int mid = (start + end) / 2;
-			TreeNode left = sortedArrayToBST(num, start, mid - 1);
-			TreeNode right = sortedArrayToBST(num, mid + 1, end);
-			TreeNode node = new TreeNode(num[mid]);
-			node.left = left;
-			node.right = right;
-			return node;
-		}
-		return null;
-	}
-}
\ No newline at end of file
+  public TreeNode sortedArrayToBST(int[] num, int start, int end) {
+    if (start <= end) {
+      int mid = (start + end) / 2;
+      TreeNode left = sortedArrayToBST(num, start, mid - 1);
+      TreeNode right = sortedArrayToBST(num, mid + 1, end);
+      TreeNode node = new TreeNode(num[mid]);
+      node.left = left;
+      node.right = right;
+      return node;
+    }
+    return null;
+  }
+}
diff --git a/ConvertSortedListtoBinarySearchTree.java b/ConvertSortedListtoBinarySearchTree.java
index 039f203..0099e1b 100644
--- a/ConvertSortedListtoBinarySearchTree.java
+++ b/ConvertSortedListtoBinarySearchTree.java
@@ -1,30 +1,29 @@
 /**
- * Given a singly linked list where elements are sorted in ascending order,
- * convert it to a height balanced BST.
+ * Given a singly linked list where elements are sorted in ascending order, convert it to a height
+ * balanced BST.
  */
-
 public class ConvertSortedListtoBinarySearchTree {
-	public TreeNode sortedListToBST(ListNode head) {
-		return sortedListToBST(head, null);
-	}
+  public TreeNode sortedListToBST(ListNode head) {
+    return sortedListToBST(head, null);
+  }
 
-	private TreeNode sortedListToBST(ListNode start, ListNode end) {
-		if (start == end) {
-			return null;
-		} else if (start.next == end) {
-			return new TreeNode(start.val);
-		} else {
-			ListNode fast = start, slow = start;
-			while (fast.next != end && fast.next.next != end) {
-				fast = fast.next.next;
-				slow = slow.next;
-			}
-			TreeNode left = sortedListToBST(start, slow);
-			TreeNode right = sortedListToBST(slow.next, end);
-			TreeNode root = new TreeNode(slow.val);
-			root.left = left;
-			root.right = right;
-			return root;
-		}
-	}
-}
\ No newline at end of file
+  private TreeNode sortedListToBST(ListNode start, ListNode end) {
+    if (start == end) {
+      return null;
+    } else if (start.next == end) {
+      return new TreeNode(start.val);
+    } else {
+      ListNode fast = start, slow = start;
+      while (fast.next != end && fast.next.next != end) {
+        fast = fast.next.next;
+        slow = slow.next;
+      }
+      TreeNode left = sortedListToBST(start, slow);
+      TreeNode right = sortedListToBST(slow.next, end);
+      TreeNode root = new TreeNode(slow.val);
+      root.left = left;
+      root.right = right;
+      return root;
+    }
+  }
+}
diff --git a/CopyListwithRandomPointer.java b/CopyListwithRandomPointer.java
index 7701f06..afe400b 100644
--- a/CopyListwithRandomPointer.java
+++ b/CopyListwithRandomPointer.java
@@ -1,39 +1,35 @@
-
-
 /**
- * A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.
- * Return a deep copy of the list.
+ * A linked list is given such that each node contains an additional random pointer which could
+ * point to any node in the list or null. Return a deep copy of the list.
  */
-
 public class CopyListwithRandomPointer {
-	public RandomListNode copyRandomList(RandomListNode head) {
-		if (head == null)
-			return head;
-		RandomListNode cur = head;
-		while (cur != null) {
-			RandomListNode newNode = new RandomListNode(cur.label);
-			newNode.next = cur.next;
-			cur.next = newNode;
-			cur = newNode.next;
-		}
-		cur = head;
-		while (cur != null) {
-			if (cur.random != null) {
-				cur.next.random = cur.random.next;
-			}
-			cur = cur.next.next;
-		}
-		cur = head.next;
-		RandomListNode newHead = cur;
-		RandomListNode old = head;
-		while (old != null) {
-			old.next = old.next.next;
-			if (old.next != null) {
-				cur.next = old.next.next;
-			}
-			cur = cur.next;
-			old = old.next;
-		}
-		return newHead;
-	}
-}
\ No newline at end of file
+  public RandomListNode copyRandomList(RandomListNode head) {
+    if (head == null) return head;
+    RandomListNode cur = head;
+    while (cur != null) {
+      RandomListNode newNode = new RandomListNode(cur.label);
+      newNode.next = cur.next;
+      cur.next = newNode;
+      cur = newNode.next;
+    }
+    cur = head;
+    while (cur != null) {
+      if (cur.random != null) {
+        cur.next.random = cur.random.next;
+      }
+      cur = cur.next.next;
+    }
+    cur = head.next;
+    RandomListNode newHead = cur;
+    RandomListNode old = head;
+    while (old != null) {
+      old.next = old.next.next;
+      if (old.next != null) {
+        cur.next = old.next.next;
+      }
+      cur = cur.next;
+      old = old.next;
+    }
+    return newHead;
+  }
+}
diff --git a/CountandSay.java b/CountandSay.java
index 779ec77..068cb7e 100644
--- a/CountandSay.java
+++ b/CountandSay.java
@@ -1,41 +1,38 @@
-
-
 /**
- * The count-and-say sequence is the sequence of integers beginning as follows:
- * 1, 11, 21, 1211, 111221, ...
- * 
- * 1 is read off as "one 1" or 11. 11 is read off as "two 1s" or 21. 21 is read
- * off as "one 2, then one 1" or 1211.
- * 
- * Given an integer n, generate the nth sequence.
- * 
- * Note: The sequence of integers will be represented as a string.
+ * The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211,
+ * 111221, ...
+ *
+ * <p>1 is read off as "one 1" or 11. 11 is read off as "two 1s" or 21. 21 is read off as "one 2,
+ * then one 1" or 1211.
+ *
+ * <p>Given an integer n, generate the nth sequence.
+ *
+ * <p>Note: The sequence of integers will be represented as a string.
  */
-
 public class CountandSay {
-	public String countAndSay(int n) {
-		StringBuilder s1 = new StringBuilder("1");
-		StringBuilder s2 = new StringBuilder();
-		for (int i = 1; i < n; i++) {
-			int j = 0;
-			int len = s1.length();
-			while (j < len) {
-				int count = 1;
-				char c = s1.charAt(j);
-				while (j < len - 1 && s1.charAt(j + 1) == s1.charAt(j)) {
-					count++;
-					j++;
-				}
-				s2.append(count + "");
-				s2.append(c);
-				if (j == len - 1) {
-					break;
-				}
-				j++;
-			}
-			s1 = s2;
-			s2 = new StringBuilder();
-		}
-		return s1.toString();
-	}
-}
\ No newline at end of file
+  public String countAndSay(int n) {
+    StringBuilder s1 = new StringBuilder("1");
+    StringBuilder s2 = new StringBuilder();
+    for (int i = 1; i < n; i++) {
+      int j = 0;
+      int len = s1.length();
+      while (j < len) {
+        int count = 1;
+        char c = s1.charAt(j);
+        while (j < len - 1 && s1.charAt(j + 1) == s1.charAt(j)) {
+          count++;
+          j++;
+        }
+        s2.append(count + "");
+        s2.append(c);
+        if (j == len - 1) {
+          break;
+        }
+        j++;
+      }
+      s1 = s2;
+      s2 = new StringBuilder();
+    }
+    return s1.toString();
+  }
+}
diff --git a/DecodeWays.java b/DecodeWays.java
index b58a7a8..5c5e350 100644
--- a/DecodeWays.java
+++ b/DecodeWays.java
@@ -1,39 +1,30 @@
-
-
 /**
- * A message containing letters from A-Z is being encoded to numbers using the
- * following mapping:
- * 
- * 'A' -> 1 'B' -> 2 ... 'Z' -> 26 Given an encoded message containing digits,
- * determine the total number of ways to decode it.
- * 
- * For example, Given encoded message "12", it could be decoded as "AB" (1 2) or
- * "L" (12).
- * 
- * The number of ways decoding "12" is 2.
+ * A message containing letters from A-Z is being encoded to numbers using the following mapping:
+ *
+ * <p>'A' -> 1 'B' -> 2 ... 'Z' -> 26 Given an encoded message containing digits, determine the
+ * total number of ways to decode it.
+ *
+ * <p>For example, Given encoded message "12", it could be decoded as "AB" (1 2) or "L" (12).
+ *
+ * <p>The number of ways decoding "12" is 2.
  */
-
 public class DecodeWays {
-	public int numDecodings(String s) {
-		if (s.length() == 0)
-			return 0;
-		int[] c = new int[s.length() + 1];
-		c[0] = 1;
-		if (s.charAt(0) != '0')
-			c[1] = c[0];
-		else
-			c[1] = 0;
-		for (int i = 2; i <= s.length(); i++) {
-			if (s.charAt(i - 1) == '0') {
-				c[i] = 0;
-			} else {
-				c[i] = c[i - 1];
-			}
-			if (s.charAt(i - 2) == '1'
-					|| (s.charAt(i - 2) == '2' && s.charAt(i - 1) <= '6')) {
-				c[i] += c[i - 2];
-			}
-		}
-		return c[s.length()];
-	}
-}
\ No newline at end of file
+  public int numDecodings(String s) {
+    if (s.length() == 0) return 0;
+    int[] c = new int[s.length() + 1];
+    c[0] = 1;
+    if (s.charAt(0) != '0') c[1] = c[0];
+    else c[1] = 0;
+    for (int i = 2; i <= s.length(); i++) {
+      if (s.charAt(i - 1) == '0') {
+        c[i] = 0;
+      } else {
+        c[i] = c[i - 1];
+      }
+      if (s.charAt(i - 2) == '1' || (s.charAt(i - 2) == '2' && s.charAt(i - 1) <= '6')) {
+        c[i] += c[i - 2];
+      }
+    }
+    return c[s.length()];
+  }
+}
diff --git a/DistinctSubsequences.java b/DistinctSubsequences.java
index f5139a5..5df2a3f 100644
--- a/DistinctSubsequences.java
+++ b/DistinctSubsequences.java
@@ -1,36 +1,31 @@
-
-
 /**
- * Distinct SubsequencesOct 19 '12 Given a string S and a string T, count the
- * number of distinct subsequences of T in S.
- * 
- * A subsequence of a string is a new string which is formed from the original
- * string by deleting some (can be none) of the characters without disturbing
- * the relative positions of the remaining characters. (ie, "ACE" is a
- * subsequence of "ABCDE" while "AEC" is not).
- * 
- * Here is an example: S = "rabbbit", T = "rabbit"
- * 
- * Return 3.
- * 
- * f(i, j) = f(i - 1, j) + S[i] == T[j]? f(i - 1, j - 1) : 0 Where f(i, j) is
- * the number of distinct sub-sequence for T[0:j] in S[0:i].
+ * Distinct SubsequencesOct 19 '12 Given a string S and a string T, count the number of distinct
+ * subsequences of T in S.
+ *
+ * <p>A subsequence of a string is a new string which is formed from the original string by deleting
+ * some (can be none) of the characters without disturbing the relative positions of the remaining
+ * characters. (ie, "ACE" is a subsequence of "ABCDE" while "AEC" is not).
+ *
+ * <p>Here is an example: S = "rabbbit", T = "rabbit"
+ *
+ * <p>Return 3.
+ *
+ * <p>f(i, j) = f(i - 1, j) + S[i] == T[j]? f(i - 1, j - 1) : 0 Where f(i, j) is the number of
+ * distinct sub-sequence for T[0:j] in S[0:i].
  */
-
 public class DistinctSubsequences {
-	public int numDistinct(String S, String T) {
-		int[][] f = new int[S.length() + 1][T.length() + 1];
-		for (int k = 0; k < S.length(); k++)
-			f[k][0] = 1;
-		for (int i = 1; i <= S.length(); i++) {
-			for (int j = 1; j <= T.length(); j++) {
-				if (S.charAt(i - 1) == T.charAt(j - 1)) {
-					f[i][j] += f[i - 1][j] + f[i - 1][j - 1];
-				} else {
-					f[i][j] += f[i - 1][j];
-				}
-			}
-		}
-		return f[S.length()][T.length()];
-	}
-}
\ No newline at end of file
+  public int numDistinct(String S, String T) {
+    int[][] f = new int[S.length() + 1][T.length() + 1];
+    for (int k = 0; k < S.length(); k++) f[k][0] = 1;
+    for (int i = 1; i <= S.length(); i++) {
+      for (int j = 1; j <= T.length(); j++) {
+        if (S.charAt(i - 1) == T.charAt(j - 1)) {
+          f[i][j] += f[i - 1][j] + f[i - 1][j - 1];
+        } else {
+          f[i][j] += f[i - 1][j];
+        }
+      }
+    }
+    return f[S.length()][T.length()];
+  }
+}
diff --git a/DivideTwoIntegers.java b/DivideTwoIntegers.java
index 0471da2..c996661 100644
--- a/DivideTwoIntegers.java
+++ b/DivideTwoIntegers.java
@@ -1,46 +1,39 @@
-
-
 import java.math.BigDecimal;
 import java.util.ArrayList;
 
-/**
- * Divide two integers without using multiplication, division and mod operator.
- */
-
+/** Divide two integers without using multiplication, division and mod operator. */
 public class DivideTwoIntegers {
-	public int divide(int dividend, int divisor) {
-		if (dividend == 0)
-			return 0;
-		ArrayList<Integer> list = new ArrayList<Integer>();
-		BigDecimal d0 = new BigDecimal(dividend);
-		d0 = d0.abs();
-		BigDecimal d1;
-		BigDecimal d3 = new BigDecimal(divisor);
-		d3 = d3.abs();
-		int count = 0;
-		boolean start = true;
-		while (d0.compareTo(d3) == 1 || d0.compareTo(d3) == 0) {
-			d1 = new BigDecimal(divisor);
-			d1 = d1.abs();
-			start = true;
-			while (d0.compareTo(d1) == 1 || d0.compareTo(d1) == 0) {
-				if (start) {
-					list.add(1);
-					start = false;
-				} else {
-					int last = list.get(list.size() - 1);
-					list.add(last + last);
-				}
-				d0 = d0.subtract(d1);
-				d1 = d1.add(d1);
-			}
-		}
+  public int divide(int dividend, int divisor) {
+    if (dividend == 0) return 0;
+    ArrayList<Integer> list = new ArrayList<Integer>();
+    BigDecimal d0 = new BigDecimal(dividend);
+    d0 = d0.abs();
+    BigDecimal d1;
+    BigDecimal d3 = new BigDecimal(divisor);
+    d3 = d3.abs();
+    int count = 0;
+    boolean start = true;
+    while (d0.compareTo(d3) == 1 || d0.compareTo(d3) == 0) {
+      d1 = new BigDecimal(divisor);
+      d1 = d1.abs();
+      start = true;
+      while (d0.compareTo(d1) == 1 || d0.compareTo(d1) == 0) {
+        if (start) {
+          list.add(1);
+          start = false;
+        } else {
+          int last = list.get(list.size() - 1);
+          list.add(last + last);
+        }
+        d0 = d0.subtract(d1);
+        d1 = d1.add(d1);
+      }
+    }
 
-		for (int e : list) {
-			count += e;
-		}
+    for (int e : list) {
+      count += e;
+    }
 
-		return (dividend < 0 && divisor < 0) || (dividend > 0 && divisor > 0) ? count
-				: -count;
-	}
-}
\ No newline at end of file
+    return (dividend < 0 && divisor < 0) || (dividend > 0 && divisor > 0) ? count : -count;
+  }
+}
diff --git a/EditDistance.java b/EditDistance.java
index 8ce0788..c8f8c58 100644
--- a/EditDistance.java
+++ b/EditDistance.java
@@ -1,39 +1,36 @@
 /**
- * Given two words word1 and word2, find the minimum number of steps required to
- * convert word1 to word2. (each operation is counted as 1 step.)
- * 
- * You have the following 3 operations permitted on a word:
- * 
- * a) Insert a character 
- * b) Delete a character 
- * c) Replace a character
+ * Given two words word1 and word2, find the minimum number of steps required to convert word1 to
+ * word2. (each operation is counted as 1 step.)
+ *
+ * <p>You have the following 3 operations permitted on a word:
+ *
+ * <p>a) Insert a character b) Delete a character c) Replace a character
  */
-
 public class EditDistance {
-	public int minDistance(String word1, String word2) {
-		if (word1.length() == 0 || word2.length() == 0)
-			return word1.length() == 0 ? word2.length() : word1.length();
-		int[][] arr = new int[word2.length() + 1][word1.length() + 1];
-		for (int i = 0; i <= word1.length(); i++) {
-			arr[0][i] = i;
-		}
-		for (int j = 0; j <= word2.length(); j++) {
-			arr[j][0] = j;
-		}
-		for (int i = 0; i < word1.length(); i++) {
-			for (int j = 0; j < word2.length(); j++) {
-				if (word1.charAt(i) == word2.charAt(j)) {
-					arr[j + 1][i + 1] = arr[j][i];
-				} else {
-					int dis = Math.min(arr[j][i + 1], arr[j + 1][i]);
-					arr[j + 1][i + 1] = Math.min(arr[j][i], dis) + 1;
-				}
-			}
-		}
-		return arr[word2.length()][word1.length()];
-	}
-	
-	public static void main (String[] args) {
-		System.out.println(new EditDistance().minDistance("ab", "bc"));
-	}
-}
\ No newline at end of file
+  public int minDistance(String word1, String word2) {
+    if (word1.length() == 0 || word2.length() == 0)
+      return word1.length() == 0 ? word2.length() : word1.length();
+    int[][] arr = new int[word2.length() + 1][word1.length() + 1];
+    for (int i = 0; i <= word1.length(); i++) {
+      arr[0][i] = i;
+    }
+    for (int j = 0; j <= word2.length(); j++) {
+      arr[j][0] = j;
+    }
+    for (int i = 0; i < word1.length(); i++) {
+      for (int j = 0; j < word2.length(); j++) {
+        if (word1.charAt(i) == word2.charAt(j)) {
+          arr[j + 1][i + 1] = arr[j][i];
+        } else {
+          int dis = Math.min(arr[j][i + 1], arr[j + 1][i]);
+          arr[j + 1][i + 1] = Math.min(arr[j][i], dis) + 1;
+        }
+      }
+    }
+    return arr[word2.length()][word1.length()];
+  }
+
+  public static void main(String[] args) {
+    System.out.println(new EditDistance().minDistance("ab", "bc"));
+  }
+}
diff --git a/EvaluateReversePolishNotation.java b/EvaluateReversePolishNotation.java
index 4925cec..cd543a0 100644
--- a/EvaluateReversePolishNotation.java
+++ b/EvaluateReversePolishNotation.java
@@ -1,52 +1,49 @@
-
-
 /**
  * Evaluate the value of an arithmetic expression in Reverse Polish Notation.
- * 
- * Valid operators are +, -, *, /. Each operand may be an integer or another expression.
- * 
- * Some examples:
- * ["2", "1", "+", "3", "*"] -> ((2 + 1) * 3) -> 9
- * ["4", "13", "5", "/", "+"] -> (4 + (13 / 5)) -> 6
+ *
+ * <p>Valid operators are +, -, *, /. Each operand may be an integer or another expression.
+ *
+ * <p>Some examples: ["2", "1", "+", "3", "*"] -> ((2 + 1) * 3) -> 9 ["4", "13", "5", "/", "+"] ->
+ * (4 + (13 / 5)) -> 6
  */
 
 import java.util.Stack;
 
 public class EvaluateReversePolishNotation {
-	public int evalRPN(String[] tokens) {
-		Stack<Integer> st = new Stack<Integer>();
-		int size = tokens.length;
-		for (int i = 0; i < size; i++) {
-			if (isDigital(tokens[i])) {
-				st.push(Integer.parseInt(tokens[i]));
-			} else {
-				st.push(calc(st.pop(), st.pop(), tokens[i]));
-			}
-		}
-		return st.pop();
-	}
+  public int evalRPN(String[] tokens) {
+    Stack<Integer> st = new Stack<Integer>();
+    int size = tokens.length;
+    for (int i = 0; i < size; i++) {
+      if (isDigital(tokens[i])) {
+        st.push(Integer.parseInt(tokens[i]));
+      } else {
+        st.push(calc(st.pop(), st.pop(), tokens[i]));
+      }
+    }
+    return st.pop();
+  }
 
-	private Integer calc(Integer num2, Integer num1, String op) {
-		switch (op.charAt(0)) {
-		case '+':
-			return num1 + num2;
-		case '-':
-			return num1 - num2;
-		case '*':
-			return num1 * num2;
-		case '/':
-			return num1 / num2;
-		default:
-			return 0;
-		}
-	}
+  private Integer calc(Integer num2, Integer num1, String op) {
+    switch (op.charAt(0)) {
+      case '+':
+        return num1 + num2;
+      case '-':
+        return num1 - num2;
+      case '*':
+        return num1 * num2;
+      case '/':
+        return num1 / num2;
+      default:
+        return 0;
+    }
+  }
 
-	private boolean isDigital(String s) {
-		try {
-			Integer.parseInt(s);
-		} catch (NumberFormatException e) {
-			return false;
-		}
-		return true;
-	}
+  private boolean isDigital(String s) {
+    try {
+      Integer.parseInt(s);
+    } catch (NumberFormatException e) {
+      return false;
+    }
+    return true;
+  }
 }
diff --git a/ExpressionAddOperators.java b/ExpressionAddOperators.java
new file mode 100644
index 0000000..83d5de9
--- /dev/null
+++ b/ExpressionAddOperators.java
@@ -0,0 +1,55 @@
+/**
+* Given a string that contains only digits 0-9 and a target value,
+* return all possibilities to add binary operators (not unary) +, -, or * between the digits so they evaluate to the target value.
+*
+* Example 1:
+*
+* Input: num = "123", target = 6
+* Output: ["1+2+3", "1*2*3"] 
+* Example 2:
+*
+* Input: num = "232", target = 8
+* Output: ["2*3+2", "2+3*2"]
+* Example 3:
+*
+* Input: num = "105", target = 5
+* Output: ["1*0+5","10-5"]
+* Example 4:
+*
+* Input: num = "00", target = 0
+* Output: ["0+0", "0-0", "0*0"]
+* Example 5:
+*
+* Input: num = "3456237490", target = 9191
+* Output: []
+*/
+
+class Solution {
+  public List<String> addOperators(String num, int target) {
+    List<String> rst = new ArrayList<>();
+    if (num == null || num.length() == 0) return rst;
+    helper(rst, "", num, target, 0, 0, 0);
+    return rst;
+  }
+
+  public void helper(List<String> rst, String path, String num, int target, int pos, long eval, long multed) {
+    if (pos == num.length()) {
+      if (target == eval)
+        rst.add(path);
+      return;
+    }
+    for (int i = pos; i < num.length(); i++) {
+      if (i != pos && num.charAt(pos) == '0') break;
+      long cur = Long.parseLong(num.substring(pos, i + 1));
+      if (pos == 0) {
+        helper(rst, path + cur, num, target, i + 1, cur, cur);
+      } else {
+        helper(rst, path + "+" + cur, num, target, i + 1, eval + cur, cur);
+
+        helper(rst, path + "-" + cur, num, target, i + 1, eval - cur, -cur);
+
+        helper(rst, path + "*" + cur, num, target, i + 1, eval - multed + multed * cur, multed * cur);
+      }
+    }
+  }
+}
diff --git a/FindMedianFromDataStream.java b/FindMedianFromDataStream.java
new file mode 100644
index 0000000..153c163
--- /dev/null
+++ b/FindMedianFromDataStream.java
@@ -0,0 +1,60 @@
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Median is the middle value in an ordered integer list. If the size of the list is even,
+ * there is no middle value. So the median is the mean of the two middle value.
+ * <p>
+ * For example,
+ * [2,3,4], the median is 3
+ * <p>
+ * [2,3], the median is (2 + 3) / 2 = 2.5
+ * <p>
+ * Design a data structure that supports the following two operations:
+ * <p>
+ * void addNum(int num) - Add a integer number from the data stream to the data structure.
+ * double findMedian() - Return the median of all elements so far.
+ */
+
+class MedianFinder {
+
+  private final List<Integer> elements = new ArrayList<>();
+
+  /**
+   * initialize your data structure here.
+   */
+  public MedianFinder() {
+  }
+
+  public void addNum(int num) {
+    qinsert(0, elements.size() - 1, num);
+  }
+
+  public double findMedian() {
+    if (elements.size() % 2 == 0) {
+      int q = elements.size() / 2;
+      int p = q > 0 ? q - 1 : q;
+      return (elements.get(p) + elements.get(q)) / 2.f;
+    } else {
+      return elements.get((elements.size() - 1) / 2);
+    }
+  }
+
+  private void qinsert(int start, int end, int num) {
+    if (start > end) {
+      elements.add(start, num);
+      return;
+    }
+    int index = (start + end) / 2;
+    int mid = elements.get(index);
+    if (mid == num) {
+      elements.add(index, num);
+      return;
+    }
+    if (mid < num) {
+      qinsert(index + 1, end, num);
+    } else {
+      qinsert(start, index - 1, num);
+    }
+  }
+}
\ No newline at end of file
diff --git a/FindMinimumInRotatedSortedArray.java b/FindMinimumInRotatedSortedArray.java
new file mode 100644
index 0000000..52f411f
--- /dev/null
+++ b/FindMinimumInRotatedSortedArray.java
@@ -0,0 +1,29 @@
+/**
+ * Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.
+ *
+ * (i.e.,  [0,1,2,4,5,6,7] might become  [4,5,6,7,0,1,2]).
+ *
+ * Find the minimum element.
+ *
+ * You may assume no duplicate exists in the array.
+ *
+ * Example 1:
+ *
+ * Input: [3,4,5,1,2] 
+ * Output: 1
+ */
+class Solution {
+    public int findMin(int[] nums) {
+        return find(nums, 0, nums.length - 1);
+    }
+
+    private int find(int[] nums, int left, int right) {
+        if (nums[right] >= nums[left]) return nums[left];
+        int mid = (left + right) / 2;
+        if (nums[mid] >= nums[left]) {
+            return find(nums, mid + 1, right);
+        } else {
+            return find(nums, left, mid);
+        }
+    }
+}
\ No newline at end of file
diff --git a/FindPeakElement.java b/FindPeakElement.java
new file mode 100644
index 0000000..f11403b
--- /dev/null
+++ b/FindPeakElement.java
@@ -0,0 +1,38 @@
+/**
+ * A peak element is an element that is greater than its neighbors.
+ *
+ * Given an input array nums, where nums[i] ≠ nums[i+1], find a peak element and return its index.
+ *
+ * The array may contain multiple peaks, in that case return the index to any one of the peaks is fine.
+ *
+ * You may imagine that nums[-1] = nums[n] = -∞.
+ *
+ * Example 1:
+ *
+ * Input: nums = [1,2,3,1]
+ * Output: 2
+ */
+class Solution {
+    public int findPeakElement(int[] nums) {
+        if (nums.length == 1) return 0;
+        return find(nums, 0, nums.length - 1);
+    }
+    
+    private int find(int[] nums, int left, int right) {
+        int mid = (left + right) / 2;
+        if ((mid == 0 && nums[mid + 1] < nums[mid])
+            || (mid == nums.length - 1 && nums[mid - 1] < nums[mid])
+            || (mid > 0 && mid < nums.length - 1 && nums[mid - 1] < nums[mid] && nums[mid + 1] < nums[mid])) {
+            return mid;
+        } else {
+            int ret = -1;
+            if (mid > left && nums[mid] < nums[mid - 1]) {
+                ret = find(nums, left, mid - 1);
+            }
+            if (ret < 0 && mid < right && nums[mid] < nums[mid + 1]) {
+                ret = find(nums, mid + 1, right);
+            }
+            return ret;
+        }
+    }
+}
\ No newline at end of file
diff --git a/FindTheDuplicateNumber.java b/FindTheDuplicateNumber.java
new file mode 100644
index 0000000..f551a5d
--- /dev/null
+++ b/FindTheDuplicateNumber.java
@@ -0,0 +1,42 @@
+/**
+ * Given an unsorted integer array, find the smallest missing positive integer.
+ *
+ * Example 1:
+ *
+ * Input: [1,2,0]
+ * Output: 3
+ * Example 2:
+ *
+ * Input: [3,4,-1,1]
+ * Output: 2
+ * Example 3:
+ *
+ * Input: [7,8,9,11,12]
+ * Output: 1
+ * Note:
+ *
+ * Your algorithm should run in O(n) time and uses constant extra space.
+ */
+class Solution {
+    public int firstMissingPositive(int[] a) {
+        int i = 0;
+        while (i < a.length) {
+            if (a[i] > 0 && a[i] <= a.length && a[i] != a[a[i] - 1]) {
+                swap(a, i, a[i] - 1);
+            } else {
+                i++;
+            }
+        }
+        i = 0;
+        while (i < a.length && a[i] == i + 1) {
+            i++;
+        }
+        return i + 1;
+    }
+        
+    private void swap(int[] a, int i, int j) {
+        int b = a[i];
+        a[i] = a[j];
+        a[j] = b;
+    }
+}
\ No newline at end of file
diff --git a/FirstMissingPositive.java b/FirstMissingPositive.java
index 43c7687..339a83e 100644
--- a/FirstMissingPositive.java
+++ b/FirstMissingPositive.java
@@ -1,32 +1,30 @@
-
-
 /**
  * Given an unsorted integer array, find the first missing positive integer.
- * 
- * For example, Given [1,2,0] return 3, and [3,4,-1,1] return 2.
- * 
- * Your algorithm should run in O(n) time and uses constant space.
+ *
+ * <p>For example, Given [1,2,0] return 3, and [3,4,-1,1] return 2.
+ *
+ * <p>Your algorithm should run in O(n) time and uses constant space.
  */
-
-public class FirstMissingPositive {
-	public int firstMissingPositive(int[] A) {
-		if (A.length == 0)
-			return 1;
-		for (int i = 0; i < A.length; i++) {
-			if (A[i] > 0 && A[i] - 1 < A.length && A[i] - 1 != i
-					&& A[i] != A[A[i] - 1]) {
-				int t = A[A[i] - 1];
-				A[A[i] - 1] = A[i];
-				A[i] = t;
-				i--;
-			}
-		}
-
-		for (int j = 0; j < A.length; j++) {
-			if (A[j] - 1 != j) {
-				return j + 1;
-			}
-		}
-		return A.length + 1;
-	}
-}
\ No newline at end of file
+class Solution {
+    public int firstMissingPositive(int[] a) {
+        int i = 0;
+        while (i < a.length) {
+            if (a[i] > 0 && a[i] <= a.length && a[i] != a[a[i] - 1]) {
+                swap(a, i, a[i] - 1);
+            } else {
+                i++;
+            }
+        }
+        i = 0;
+        while (i < a.length && a[i] == i + 1) {
+            i++;
+        }
+        return i + 1;
+    }
+        
+    private void swap(int[] a, int i, int j) {
+        int b = a[i];
+        a[i] = a[j];
+        a[j] = b;
+    }
+}
diff --git a/FlattenBinaryTreetoLinkedList.java b/FlattenBinaryTreetoLinkedList.java
index 5eb4ecf..3601423 100644
--- a/FlattenBinaryTreetoLinkedList.java
+++ b/FlattenBinaryTreetoLinkedList.java
@@ -1,45 +1,25 @@
-
-
 /**
  * Given a binary tree, flatten it to a linked list in-place.
- * 
- * For example,
- * Given
  *
- *        1
- *       / \
- *      2   5
- *     / \   \
- *    3   4   6
- * The flattened tree should look like:
- *  1
- *   \
- *    2
- *     \
- *      3
- *       \
- *        4
- *         \
- *          5
- *           \
- *            6
+ * <p>For example, Given
+ *
+ * <p>1 / \ 2 5 / \ \ 3 4 6 The flattened tree should look like: 1 \ 2 \ 3 \ 4 \ 5 \ 6
  */
-
 public class FlattenBinaryTreetoLinkedList {
-	public void flatten(TreeNode root) {
-        if (root == null) return;
-        if (root.left != null) {
-            TreeNode rightMost = findRightMost(root.left);
-            TreeNode rightChild = root.right;
-            root.right = root.left;
-            root.left = null;
-            rightMost.right = rightChild;
-        }
-        flatten(root.right);
-    }
-    
-    private TreeNode findRightMost(TreeNode root) {
-        if (root == null || root.right == null) return root;
-        return findRightMost(root.right);
+  public void flatten(TreeNode root) {
+    if (root == null) return;
+    if (root.left != null) {
+      TreeNode rightMost = findRightMost(root.left);
+      TreeNode rightChild = root.right;
+      root.right = root.left;
+      root.left = null;
+      rightMost.right = rightChild;
     }
-}
\ No newline at end of file
+    flatten(root.right);
+  }
+
+  private TreeNode findRightMost(TreeNode root) {
+    if (root == null || root.right == null) return root;
+    return findRightMost(root.right);
+  }
+}
diff --git a/FourSum.java b/FourSum.java
index 53f33d6..b4d598b 100644
--- a/FourSum.java
+++ b/FourSum.java
@@ -1,63 +1,59 @@
-
-
 import java.util.ArrayList;
 import java.util.Arrays;
 
 /**
- * Given an array S of n integers, are there elements a, b, c, and d in S such
- * that a + b + c + d = target? 
- * 
- * Find all unique quadruplets in the array which gives the sum of target.
- * 
- * Note:
- * 
- * Elements in a quadruplet (a,b,c,d) must be in non-descending order. (ie, a <= b <= c <= d) The solution set must not contain duplicate quadruplets.
- * 
- * For example, given array S = {1 0 -1 0 -2 2}, and target = 0.
- * 
- * A solution set is: (-1, 0, 0, 1) (-2, -1, 1, 2) (-2, 0, 0, 2)
+ * Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d =
+ * target?
+ *
+ * <p>Find all unique quadruplets in the array which gives the sum of target.
+ *
+ * <p>Note:
+ *
+ * <p>Elements in a quadruplet (a,b,c,d) must be in non-descending order. (ie, a <= b <= c <= d) The
+ * solution set must not contain duplicate quadruplets.
+ *
+ * <p>For example, given array S = {1 0 -1 0 -2 2}, and target = 0.
+ *
+ * <p>A solution set is: (-1, 0, 0, 1) (-2, -1, 1, 2) (-2, 0, 0, 2)
  */
-
 public class FourSum {
-	public ArrayList<ArrayList<Integer>> fourSum(int[] num, int target) {
-		ArrayList<ArrayList<Integer>> ret = new ArrayList<ArrayList<Integer>>();
-		Arrays.sort(num);
-		int length = num.length;
-		for (int i = 0; i < length - 3; i++) {
-			if (i > 0 && num[i] == num[i - 1])
-				continue;
-			for (int j = i + 1; j < length - 2; j++) {
-				if (j > i + 1 && num[j] == num[j - 1])
-					continue;
-				int l = j + 1;
-				int r = length - 1;
-				while (l < r) {
-					int delta = num[i] + num[j] + num[l] + num[r] - target;
-					if (delta == 0) {
-						if (l > j + 1 && num[l] == num[l - 1]) {
-							l++;
-							continue;
-						}
-						if (r < length - 1 && num[r] == num[r + 1]) {
-							r--;
-							continue;
-						}
-						ArrayList<Integer> item = new ArrayList<Integer>();
-						item.add(num[i]);
-						item.add(num[j]);
-						item.add(num[l]);
-						item.add(num[r]);
-						ret.add(item);
-						l++;
-						r--;
-					} else if (delta < 0) {
-						l++;
-					} else {
-						r--;
-					}
-				}
-			}
-		}
-		return ret;
-	}
-}
\ No newline at end of file
+  public ArrayList<ArrayList<Integer>> fourSum(int[] num, int target) {
+    ArrayList<ArrayList<Integer>> ret = new ArrayList<ArrayList<Integer>>();
+    Arrays.sort(num);
+    int length = num.length;
+    for (int i = 0; i < length - 3; i++) {
+      if (i > 0 && num[i] == num[i - 1]) continue;
+      for (int j = i + 1; j < length - 2; j++) {
+        if (j > i + 1 && num[j] == num[j - 1]) continue;
+        int l = j + 1;
+        int r = length - 1;
+        while (l < r) {
+          int delta = num[i] + num[j] + num[l] + num[r] - target;
+          if (delta == 0) {
+            if (l > j + 1 && num[l] == num[l - 1]) {
+              l++;
+              continue;
+            }
+            if (r < length - 1 && num[r] == num[r + 1]) {
+              r--;
+              continue;
+            }
+            ArrayList<Integer> item = new ArrayList<Integer>();
+            item.add(num[i]);
+            item.add(num[j]);
+            item.add(num[l]);
+            item.add(num[r]);
+            ret.add(item);
+            l++;
+            r--;
+          } else if (delta < 0) {
+            l++;
+          } else {
+            r--;
+          }
+        }
+      }
+    }
+    return ret;
+  }
+}
diff --git a/GasStation.java b/GasStation.java
index d861d2c..13d0f14 100644
--- a/GasStation.java
+++ b/GasStation.java
@@ -1,28 +1,27 @@
-
 /**
  * There are N gas stations along a circular route, where the amount of gas at station i is gas[i].
- * 
- * You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its next station (i+1). You begin the journey with an empty tank at one of the gas stations.
- * 
- * Return the starting gas station's index if you can travel around the circuit once, otherwise return -1.
- * 
- * Note:
- * 
- * The solution is guaranteed to be unique.
  *
+ * <p>You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i
+ * to its next station (i+1). You begin the journey with an empty tank at one of the gas stations.
+ *
+ * <p>Return the starting gas station's index if you can travel around the circuit once, otherwise
+ * return -1.
+ *
+ * <p>Note:
+ *
+ * <p>The solution is guaranteed to be unique.
  */
-
 public class GasStation {
-	public int canCompleteCircuit(int[] gas, int[] cost) {
-		int sum = 0, total = 0, len = gas.length, index = -1;
-		for (int i = 0; i < len; i++) {
-			sum += gas[i] - cost[i];
-			total += gas[i] - cost[i];
-			if (sum < 0) {
-				index = i;
-				sum = 0;
-			}
-		}
-		return total >= 0 ? index + 1 : -1;
-	}
-}
\ No newline at end of file
+  public int canCompleteCircuit(int[] gas, int[] cost) {
+    int sum = 0, total = 0, len = gas.length, index = -1;
+    for (int i = 0; i < len; i++) {
+      sum += gas[i] - cost[i];
+      total += gas[i] - cost[i];
+      if (sum < 0) {
+        index = i;
+        sum = 0;
+      }
+    }
+    return total >= 0 ? index + 1 : -1;
+  }
+}
diff --git a/GenerateParentheses.java b/GenerateParentheses.java
index 7cc0c7f..297d1a9 100644
--- a/GenerateParentheses.java
+++ b/GenerateParentheses.java
@@ -1,39 +1,36 @@
-
-
 import java.util.ArrayList;
 
 /**
- * Given n pairs of parentheses, write a function to generate all combinations
- * of well-formed parentheses.
- * 
- * For example, given n = 3, a solution set is:
- * 
- * "((()))", "(()())", "(())()", "()(())", "()()()"
+ * Given n pairs of parentheses, write a function to generate all combinations of well-formed
+ * parentheses.
+ *
+ * <p>For example, given n = 3, a solution set is:
+ *
+ * <p>"((()))", "(()())", "(())()", "()(())", "()()()"
  */
-
 public class GenerateParentheses {
-	public ArrayList<String> generateParenthesis(int n) {
-		ArrayList<String> ret = new ArrayList<String>();
-		StringBuilder sb = new StringBuilder();
-		generateParenthesis(n, 0, 0, 0, sb, ret);
-		return ret;
-	}
+  public ArrayList<String> generateParenthesis(int n) {
+    ArrayList<String> ret = new ArrayList<String>();
+    StringBuilder sb = new StringBuilder();
+    generateParenthesis(n, 0, 0, 0, sb, ret);
+    return ret;
+  }
 
-	public void generateParenthesis(int n, int s, int e, int l,
-			StringBuilder sb, ArrayList<String> ret) {
-		if (s == n && e == n) {
-			ret.add(sb.toString());
-		} else {
-			if (l > 0 && e < n) {
-				sb.append(')');
-				generateParenthesis(n, s, e + 1, l - 1, sb, ret);
-				sb.deleteCharAt(sb.length() - 1);
-			}
-			if (s < n) {
-				sb.append('(');
-				generateParenthesis(n, s + 1, e, l + 1, sb, ret);
-				sb.deleteCharAt(sb.length() - 1);
-			}
-		}
-	}
-}
\ No newline at end of file
+  public void generateParenthesis(
+      int n, int s, int e, int l, StringBuilder sb, ArrayList<String> ret) {
+    if (s == n && e == n) {
+      ret.add(sb.toString());
+    } else {
+      if (l > 0 && e < n) {
+        sb.append(')');
+        generateParenthesis(n, s, e + 1, l - 1, sb, ret);
+        sb.deleteCharAt(sb.length() - 1);
+      }
+      if (s < n) {
+        sb.append('(');
+        generateParenthesis(n, s + 1, e, l + 1, sb, ret);
+        sb.deleteCharAt(sb.length() - 1);
+      }
+    }
+  }
+}
diff --git a/GrayCode.java b/GrayCode.java
index 0763b68..b4a5f6e 100644
--- a/GrayCode.java
+++ b/GrayCode.java
@@ -1,48 +1,42 @@
-
-
 import java.util.ArrayList;
 
 /**
- * The gray code is a binary numeral system where two successive values differ
- * in only one bit.
- * 
- * Given a non-negative integer n representing the total number of bits in the
- * code, print the sequence of gray code. A gray code sequence must begin with 0.
- * 
- * For example, given n = 2, return [0,1,3,2]. Its gray code sequence is:
- * 
- * 00 - 0
- * 01 - 1
- * 11 - 3
- * 10 - 2
- * 
- * Note:
- * 
- * For a given n, a gray code sequence is not uniquely defined.
- * 
- * For example, [0,2,3,1] is also a valid gray code sequence according to the above definition.
- * 
- * For now, the judge is able to judge based on one instance of gray code sequence. Sorry about that.
+ * The gray code is a binary numeral system where two successive values differ in only one bit.
+ *
+ * <p>Given a non-negative integer n representing the total number of bits in the code, print the
+ * sequence of gray code. A gray code sequence must begin with 0.
+ *
+ * <p>For example, given n = 2, return [0,1,3,2]. Its gray code sequence is:
+ *
+ * <p>00 - 0 01 - 1 11 - 3 10 - 2
+ *
+ * <p>Note:
+ *
+ * <p>For a given n, a gray code sequence is not uniquely defined.
+ *
+ * <p>For example, [0,2,3,1] is also a valid gray code sequence according to the above definition.
+ *
+ * <p>For now, the judge is able to judge based on one instance of gray code sequence. Sorry about
+ * that.
  */
-
 public class GrayCode {
-	public ArrayList<Integer> grayCode(int n) {
-		ArrayList<Integer> result = new ArrayList<Integer>();
-		if (n == 0) {
-			result.add(0);
-			return result;
-		}
-		;
-		result.add(0);
-		result.add(1);
-		for (int i = 1; i < n; i++) {
-			ArrayList<Integer> tmp = new ArrayList<Integer>(result);
-			Integer a = 1 << i;
-			for (int k = result.size() - 1; k >= 0; k--) {
-				tmp.add(result.get(k) + a);
-			}
-			result = tmp;
-		}
-		return result;
-	}
-}
\ No newline at end of file
+  public ArrayList<Integer> grayCode(int n) {
+    ArrayList<Integer> result = new ArrayList<Integer>();
+    if (n == 0) {
+      result.add(0);
+      return result;
+    }
+    ;
+    result.add(0);
+    result.add(1);
+    for (int i = 1; i < n; i++) {
+      ArrayList<Integer> tmp = new ArrayList<Integer>(result);
+      Integer a = 1 << i;
+      for (int k = result.size() - 1; k >= 0; k--) {
+        tmp.add(result.get(k) + a);
+      }
+      result = tmp;
+    }
+    return result;
+  }
+}
diff --git a/ImplementStrStr.java b/ImplementStrStr.java
index a428871..495812c 100644
--- a/ImplementStrStr.java
+++ b/ImplementStrStr.java
@@ -1,35 +1,30 @@
-
-
 /**
  * Implement strStr().
- * 
- * Returns a pointer to the first occurrence of needle in haystack, or null if
- * needle is not part of haystack.
+ *
+ * <p>Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part
+ * of haystack.
  */
-
 public class ImplementStrStr {
-	public String strStr(String haystack, String needle) {
-		int i = 0;
-		int len1 = haystack.length();
-		int len2 = needle.length();
-		if (len1 == 0 && len2 == 0)
-			return "";
-		for (; i < len1; i++) {
-			int a = i;
-			int b = 0;
-			boolean match = true;
-			while (b < len2) {
-				if (a >= len1 || haystack.charAt(a) != needle.charAt(b)) {
-					match = false;
-					break;
-				} else {
-					a++;
-					b++;
-				}
-			}
-			if (match)
-				return haystack.substring(i);
-		}
-		return null;
-	}
-}
\ No newline at end of file
+  public String strStr(String haystack, String needle) {
+    int i = 0;
+    int len1 = haystack.length();
+    int len2 = needle.length();
+    if (len1 == 0 && len2 == 0) return "";
+    for (; i < len1; i++) {
+      int a = i;
+      int b = 0;
+      boolean match = true;
+      while (b < len2) {
+        if (a >= len1 || haystack.charAt(a) != needle.charAt(b)) {
+          match = false;
+          break;
+        } else {
+          a++;
+          b++;
+        }
+      }
+      if (match) return haystack.substring(i);
+    }
+    return null;
+  }
+}
diff --git a/InsertInterval.java b/InsertInterval.java
index 51aac21..487cf64 100644
--- a/InsertInterval.java
+++ b/InsertInterval.java
@@ -1,15 +1,15 @@
 /**
- * Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).
- * 
- * You may assume that the intervals were initially sorted according to their start times.
+ * Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if
+ * necessary).
  *
- * Example 1:
- * Given intervals [1,3],[6,9], insert and merge [2,5] in as [1,5],[6,9].
+ * <p>You may assume that the intervals were initially sorted according to their start times.
  *
- * Example 2:
- * Given [1,2],[3,5],[6,7],[8,10],[12,16], insert and merge [4,9] in as [1,2],[3,10],[12,16].
+ * <p>Example 1: Given intervals [1,3],[6,9], insert and merge [2,5] in as [1,5],[6,9].
  *
- * This is because the new interval [4,9] overlaps with [3,5],[6,7],[8,10].
+ * <p>Example 2: Given [1,2],[3,5],[6,7],[8,10],[12,16], insert and merge [4,9] in as
+ * [1,2],[3,10],[12,16].
+ *
+ * <p>This is because the new interval [4,9] overlaps with [3,5],[6,7],[8,10].
  */
 
 import java.util.ArrayList;
@@ -17,40 +17,38 @@
 import java.util.Comparator;
 
 public class InsertInterval {
-	public class IntervalCmp implements Comparator<Interval> {
-
-		@Override
-		public int compare(Interval i1, Interval i2) {
-			if (i1.start < i2.start) {
-				return -1;
-			}
-			if (i1.start == i2.start && i1.end <= i2.end) {
-				return -1;
-			}
-			return 1;
-		}
+  public class IntervalCmp implements Comparator<Interval> {
 
-	}
+    @Override
+    public int compare(Interval i1, Interval i2) {
+      if (i1.start < i2.start) {
+        return -1;
+      }
+      if (i1.start == i2.start && i1.end <= i2.end) {
+        return -1;
+      }
+      return 1;
+    }
+  }
 
-	public ArrayList<Interval> insert(ArrayList<Interval> intervals,
-			Interval newInterval) {
-		intervals.add(newInterval);
-		Interval[] arr = new Interval[intervals.size()];
-		intervals.toArray(arr);
-		Arrays.sort(arr, new IntervalCmp());
-		intervals.clear();
-		int start = arr[0].start;
-		int end = arr[0].end;
-		for (int i = 1; i < arr.length; i++) {
-			if (arr[i].start <= end) {
-				end = Math.max(end, arr[i].end);
-			} else {
-				intervals.add(new Interval(start, end));
-				start = arr[i].start;
-				end = arr[i].end;
-			}
-		}
-		intervals.add(new Interval(start, end));
-		return intervals;
-	}
+  public ArrayList<Interval> insert(ArrayList<Interval> intervals, Interval newInterval) {
+    intervals.add(newInterval);
+    Interval[] arr = new Interval[intervals.size()];
+    intervals.toArray(arr);
+    Arrays.sort(arr, new IntervalCmp());
+    intervals.clear();
+    int start = arr[0].start;
+    int end = arr[0].end;
+    for (int i = 1; i < arr.length; i++) {
+      if (arr[i].start <= end) {
+        end = Math.max(end, arr[i].end);
+      } else {
+        intervals.add(new Interval(start, end));
+        start = arr[i].start;
+        end = arr[i].end;
+      }
+    }
+    intervals.add(new Interval(start, end));
+    return intervals;
+  }
 }
diff --git a/InsertionSortList.java b/InsertionSortList.java
index 8a0e103..00c6ad2 100644
--- a/InsertionSortList.java
+++ b/InsertionSortList.java
@@ -1,32 +1,26 @@
-
-
-/**
- * Sort a linked list using insertion sort.
- * 
- */
-
+/** Sort a linked list using insertion sort. */
 public class InsertionSortList {
-	public ListNode insertionSortList(ListNode head) {
-		ListNode ret = new ListNode(Integer.MIN_VALUE);
-		ListNode result = ret;
-		ListNode cur = new ListNode(0);
-		cur.next = head;
-		while (cur.next != null) {
-			while (result.next != null && cur.next.val > result.next.val) {
-				result = result.next;
-			}
-			ListNode tmp = cur.next;
-			cur.next = cur.next.next;
-			if (result.next == null) {
-				result.next = tmp;
-				tmp.next = null;
-			} else {
-				ListNode tmp2 = result.next;
-				result.next = tmp;
-				tmp.next = tmp2;
-			}
-			result = ret;
-		}
-		return result.next;
-	}
+  public ListNode insertionSortList(ListNode head) {
+    ListNode ret = new ListNode(Integer.MIN_VALUE);
+    ListNode result = ret;
+    ListNode cur = new ListNode(0);
+    cur.next = head;
+    while (cur.next != null) {
+      while (result.next != null && cur.next.val > result.next.val) {
+        result = result.next;
+      }
+      ListNode tmp = cur.next;
+      cur.next = cur.next.next;
+      if (result.next == null) {
+        result.next = tmp;
+        tmp.next = null;
+      } else {
+        ListNode tmp2 = result.next;
+        result.next = tmp;
+        tmp.next = tmp2;
+      }
+      result = ret;
+    }
+    return result.next;
+  }
 }
diff --git a/IntegertoRoman.java b/IntegertoRoman.java
index 5bfdb0b..e3d22d2 100644
--- a/IntegertoRoman.java
+++ b/IntegertoRoman.java
@@ -1,28 +1,26 @@
-
-
 /**
  * Given an integer, convert it to a roman numeral.
- * 
- * Input is guaranteed to be within the range from 1 to 3999.
+ *
+ * <p>Input is guaranteed to be within the range from 1 to 3999.
  */
-
 public class IntegertoRoman {
-	public String intToRoman(int num) {
-		String a[][] = {
-				{ "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX" },
-				{ "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC" },
-				{ "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM" },
-				{ "M", "MM", "MMM", "", "", "", "", "", "" } };
-		String result = "";
-		int key = 0;
-		while (num != 0) {
-			int d = num - num / 10 * 10;
-			if (d != 0) {
-				result = a[key][d - 1] + result;
-			}
-			num /= 10;
-			key++;
-		}
-		return result;
-	}
-}
\ No newline at end of file
+  public String intToRoman(int num) {
+    String a[][] = {
+      {"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"},
+      {"X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"},
+      {"C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"},
+      {"M", "MM", "MMM", "", "", "", "", "", ""}
+    };
+    String result = "";
+    int key = 0;
+    while (num != 0) {
+      int d = num - num / 10 * 10;
+      if (d != 0) {
+        result = a[key][d - 1] + result;
+      }
+      num /= 10;
+      key++;
+    }
+    return result;
+  }
+}
diff --git a/InterleavingString.java b/InterleavingString.java
index 3c8fe3c..43fbf08 100644
--- a/InterleavingString.java
+++ b/InterleavingString.java
@@ -1,29 +1,24 @@
-
-
 /**
  * Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.
- * 
- * For example, Given: s1 = "aabcc", s2 = "dbbca",
- * 
- * When s3 = "aadbbcbcac", return true. When s3 = "aadbbbaccc", return false.
+ *
+ * <p>For example, Given: s1 = "aabcc", s2 = "dbbca",
+ *
+ * <p>When s3 = "aadbbcbcac", return true. When s3 = "aadbbbaccc", return false.
  */
-
 public class InterleavingString {
-	public boolean isInterleave(String s1, String s2, String s3) {
-		if (s1.length() + s2.length() != s3.length())
-			return false;
-		boolean[][] mat = new boolean[s1.length() + 1][s2.length() + 1];
-		mat[0][0] = true;
-		for (int i = 1; i <= s1.length(); ++i)
-			mat[i][0] = mat[i - 1][0] && (s3.charAt(i - 1) == s1.charAt(i - 1));
-		for (int i = 1; i <= s2.length(); ++i)
-			mat[0][i] = mat[0][i - 1] && (s3.charAt(i - 1) == s2.charAt(i - 1));
-		for (int i = 1; i <= s1.length(); ++i)
-			for (int j = 1; j <= s2.length(); ++j)
-				mat[i][j] = (mat[i][j - 1] && s2.charAt(j - 1) == s3.charAt(i
-						+ j - 1))
-						|| (mat[i - 1][j] && s1.charAt(i - 1) == s3.charAt(i
-								+ j - 1));
-		return mat[s1.length()][s2.length()];
-	}
-}
\ No newline at end of file
+  public boolean isInterleave(String s1, String s2, String s3) {
+    if (s1.length() + s2.length() != s3.length()) return false;
+    boolean[][] mat = new boolean[s1.length() + 1][s2.length() + 1];
+    mat[0][0] = true;
+    for (int i = 1; i <= s1.length(); ++i)
+      mat[i][0] = mat[i - 1][0] && (s3.charAt(i - 1) == s1.charAt(i - 1));
+    for (int i = 1; i <= s2.length(); ++i)
+      mat[0][i] = mat[0][i - 1] && (s3.charAt(i - 1) == s2.charAt(i - 1));
+    for (int i = 1; i <= s1.length(); ++i)
+      for (int j = 1; j <= s2.length(); ++j)
+        mat[i][j] =
+            (mat[i][j - 1] && s2.charAt(j - 1) == s3.charAt(i + j - 1))
+                || (mat[i - 1][j] && s1.charAt(i - 1) == s3.charAt(i + j - 1));
+    return mat[s1.length()][s2.length()];
+  }
+}
diff --git a/Interval.java b/Interval.java
index 456a1e1..39b481d 100644
--- a/Interval.java
+++ b/Interval.java
@@ -1,19 +1,19 @@
 public class Interval {
-	int start;
-	int end;
+  int start;
+  int end;
 
-	public Interval() {
-		start = 0;
-		end = 0;
-	}
+  public Interval() {
+    start = 0;
+    end = 0;
+  }
 
-	public Interval(int s, int e) {
-		start = s;
-		end = e;
-	}
-	
-	@Override
-	public String toString() {
-		return "[" + start + ", " + end + "]";
-	}
-}
\ No newline at end of file
+  public Interval(int s, int e) {
+    start = s;
+    end = e;
+  }
+
+  @Override
+  public String toString() {
+    return "[" + start + ", " + end + "]";
+  }
+}
diff --git a/JumpGame.java b/JumpGame.java
index 827f09c..5ca6273 100644
--- a/JumpGame.java
+++ b/JumpGame.java
@@ -1,35 +1,28 @@
-
-
 /**
- * Given an array of non-negative integers, you are initially positioned at the
- * first index of the array.
- * 
- * Each element in the array represents your maximum jump length at that
- * position.
- * 
- * Determine if you are able to reach the last index.
- * 
- * For example: A = [2,3,1,1,4], return true.
- * 
- * A = [3,2,1,0,4], return false.
+ * Given an array of non-negative integers, you are initially positioned at the first index of the
+ * array.
+ *
+ * <p>Each element in the array represents your maximum jump length at that position.
+ *
+ * <p>Determine if you are able to reach the last index.
+ *
+ * <p>For example: A = [2,3,1,1,4], return true.
+ *
+ * <p>A = [3,2,1,0,4], return false.
  */
-
 public class JumpGame {
-	public boolean canJump(int[] A) {
-		if (A.length <= 1)
-			return true;
-		int curMax = 0;
-		int max = 0;
-		for (int i = 0; i < A.length - 1; i++) {
-			if (i > max)
-				break;
-			curMax = A[i] + i;
-			if (curMax > max) {
-				max = curMax;
-			}
-			if (max >= A.length - 1)
-				return true;
-		}
-		return false;
-	}
-}
\ No newline at end of file
+  public boolean canJump(int[] A) {
+    if (A.length <= 1) return true;
+    int curMax = 0;
+    int max = 0;
+    for (int i = 0; i < A.length - 1; i++) {
+      if (i > max) break;
+      curMax = A[i] + i;
+      if (curMax > max) {
+        max = curMax;
+      }
+      if (max >= A.length - 1) return true;
+    }
+    return false;
+  }
+}
diff --git a/JumpGameII.java b/JumpGameII.java
index f644599..b50d383 100644
--- a/JumpGameII.java
+++ b/JumpGameII.java
@@ -1,30 +1,30 @@
 /**
- * 
- * Given an array of non-negative integers, you are initially positioned at the first index of the array.
- * 
- * Each element in the array represents your maximum jump length at that position.
- * 
- * Your goal is to reach the last index in the minimum number of jumps.
- * 
- * For example:
- * 
- * Given array A = [2,3,1,1,4]
- * 
- * The minimum number of jumps to reach the last index is 2. (Jump 1 step from index 0 to 1, then 3 steps to the last index.)
+ * Given an array of non-negative integers, you are initially positioned at the first index of the
+ * array.
+ *
+ * <p>Each element in the array represents your maximum jump length at that position.
+ *
+ * <p>Your goal is to reach the last index in the minimum number of jumps.
+ *
+ * <p>For example:
+ *
+ * <p>Given array A = [2,3,1,1,4]
+ *
+ * <p>The minimum number of jumps to reach the last index is 2. (Jump 1 step from index 0 to 1, then
+ * 3 steps to the last index.)
  */
-
 public class JumpGameII {
-	public int jump(int[] A) {
-		int ret = 0;
-		int last = 0;
-		int curr = 0;
-		for (int i = 0; i < A.length; ++i) {
-			if (i > last) {
-				last = curr;
-				++ret;
-			}
-			curr = Math.max(curr, i + A[i]);
-		}
-		return ret;
-	}
+  public int jump(int[] A) {
+    int ret = 0;
+    int last = 0;
+    int curr = 0;
+    for (int i = 0; i < A.length; ++i) {
+      if (i > last) {
+        last = curr;
+        ++ret;
+      }
+      curr = Math.max(curr, i + A[i]);
+    }
+    return ret;
+  }
 }
diff --git a/KthLargestElement.java b/KthLargestElement.java
new file mode 100644
index 0000000..2c9f01c
--- /dev/null
+++ b/KthLargestElement.java
@@ -0,0 +1,39 @@
+/**
+ * Find the kth largest element in an unsorted array. Note that it is the kth largest element in the
+ * sorted order, not the kth distinct element.
+ *
+ * <p>For example, Given [3,2,1,5,6,4] and k = 2, return 5.
+ *
+ * <p>Note: You may assume k is always valid, 1 ≤ k ≤ array's length.
+ */
+public class KthLargestElement {
+  public int findKthLargest(int[] nums, int k) {
+    return findKthLargest(nums, k, 0, nums.length);
+  }
+
+  private int findKthLargest(int[] nums, int k, int start, int end) {
+    if (end - start < 2) return nums[start];
+    int mid = nums[end - 1];
+    int index = start - 1;
+    for (int i = start; i < end - 1; i++) {
+      if (nums[i] >= mid) {
+        exchange(nums, i, index + 1);
+        index++;
+      }
+    }
+    exchange(nums, index + 1, end - 1);
+    if (index + 1 == k - 1) {
+      return mid;
+    } else if (index + 1 < k - 1) {
+      return findKthLargest(nums, k, index + 2, end);
+    } else {
+      return findKthLargest(nums, k, start, index + 1);
+    }
+  }
+
+  private void exchange(int[] nums, int i, int j) {
+    int temp = nums[i];
+    nums[i] = nums[j];
+    nums[j] = temp;
+  }
+}
diff --git a/LRUCache.java b/LRUCache.java
index 337d5c3..5f59249 100644
--- a/LRUCache.java
+++ b/LRUCache.java
@@ -1,152 +1,143 @@
-
-
 import java.util.HashMap;
 import java.util.Map;
 
 /**
- * Design and implement a data structure for Least Recently Used (LRU) cache. It
- * should support the following operations: get and set.
- * 
- * get(key) - Get the value (will always be positive) of the key if the key
- * exists in the cache, otherwise return -1. set(key, value) - Set or insert the
- * value if the key is not already present. When the cache reached its capacity,
- * it should invalidate the least recently used item before inserting a new
- * item.
- * 
+ * Design and implement a data structure for Least Recently Used (LRU) cache. It should support the
+ * following operations: get and set.
+ *
+ * <p>get(key) - Get the value (will always be positive) of the key if the key exists in the cache,
+ * otherwise return -1. set(key, value) - Set or insert the value if the key is not already present.
+ * When the cache reached its capacity, it should invalidate the least recently used item before
+ * inserting a new item.
  */
-
 public class LRUCache {
 
-	public class CacheItem<K, V> {
-
-		private K key;
-		private V value;
-		private CacheItem<K, V> prev;
-		private CacheItem<K, V> next;
-
-		public CacheItem<K, V> getPrev() {
-			return prev;
-		}
-
-		public void setPrev(CacheItem<K, V> prev) {
-			this.prev = prev;
-		}
-
-		public CacheItem<K, V> getNext() {
-			return next;
-		}
-
-		public void setNext(CacheItem<K, V> next) {
-			this.next = next;
-		}
-
-		public CacheItem(K key, V value) {
-			this.key = key;
-			this.value = value;
-		}
-	}
-
-	public class BidirectionalList<K, V> {
-		private CacheItem<K, V> head = new CacheItem<K, V>(null, null);
-		private CacheItem<K, V> tail = head;
-
-		public void insertTail(CacheItem<K, V> node) {
-			tail.next = node;
-			node.prev = tail;
-			node.next = null;
-			tail = node;
-		}
-
-		public void delete(CacheItem<K, V> node) {
-			if (head.next == null)
-				return;
-			if (node == head.next) {
-				deleteHead();
-			} else if (node == tail) {
-				deleteTail();
-			} else {
-				node.prev.next = node.next;
-				node.next.prev = node.prev;
-				node.next = null;
-				node.prev = null;
-			}
-		}
-
-		public CacheItem<K, V> deleteTail() {
-			if (head.next == null)
-				return null;
-			CacheItem<K, V> ret = tail;
-			tail = tail.prev;
-			tail.next = null;
-			ret.prev = null;
-			ret.next = null;
-			return ret;
-		}
-
-		public CacheItem<K, V> deleteHead() {
-			if (head.next == null)
-				return null;
-			if (head.next == tail) {
-				tail = tail.prev;
-			}
-			CacheItem<K, V> ret = head.next;
-			head.next = ret.next;
-			if (ret.next != null) {
-				ret.next.prev = head;
-			}
-			ret.next = null;
-			ret.prev = null;
-			return ret;
-		}
-	}
-
-	private Map<Integer, CacheItem<Integer, Integer>> cacheMap = new HashMap<Integer, CacheItem<Integer, Integer>>();
-	private BidirectionalList<Integer, Integer> cacheList = new BidirectionalList<Integer, Integer>();
-	private int cacheSize = 0;
-	private int capacity;
-
-	public LRUCache(int capacity) {
-		this.capacity = capacity;
-	}
-
-	public int get(int key) {
-		CacheItem<Integer, Integer> itm = cacheMap.get(key);
-		if (itm == null)
-			return -1;
-		cacheList.delete(itm);
-		cacheList.insertTail(itm);
-		return itm.value.intValue();
-	}
-
-	public void set(int key, int value) {
-		if (cacheMap.containsKey(key)) {
-			updateItem(key, value);
-		} else if (cacheSize == capacity && removeLeastUsed()) {
-			cacheSize--;
-			addItem(key, value);
-		} else {
-			addItem(key, value);
-		}
-	}
-
-	private void addItem(int key, int value) {
-		CacheItem<Integer, Integer> newCacheItem = new CacheItem<Integer, Integer>(
-				key, value);
-		cacheList.insertTail(newCacheItem);
-		cacheMap.put(key, newCacheItem);
-		cacheSize++;
-	}
-
-	private void updateItem(int key, int value) {
-		CacheItem<Integer, Integer> exitedKey = cacheMap.get(key);
-		exitedKey.value = value;
-		cacheList.delete(exitedKey);
-		cacheList.insertTail(exitedKey);
-	}
-
-	private boolean removeLeastUsed() {
-		CacheItem<Integer, Integer> removedKey = cacheList.deleteHead();
-		cacheMap.remove(removedKey.key);
-		return removedKey == null ? false : true;
-	}
+  public class CacheItem<K, V> {
+
+    private K key;
+    private V value;
+    private CacheItem<K, V> prev;
+    private CacheItem<K, V> next;
+
+    public CacheItem<K, V> getPrev() {
+      return prev;
+    }
+
+    public void setPrev(CacheItem<K, V> prev) {
+      this.prev = prev;
+    }
+
+    public CacheItem<K, V> getNext() {
+      return next;
+    }
+
+    public void setNext(CacheItem<K, V> next) {
+      this.next = next;
+    }
+
+    public CacheItem(K key, V value) {
+      this.key = key;
+      this.value = value;
+    }
+  }
+
+  public class BidirectionalList<K, V> {
+    private CacheItem<K, V> head = new CacheItem<K, V>(null, null);
+    private CacheItem<K, V> tail = head;
+
+    public void insertTail(CacheItem<K, V> node) {
+      tail.next = node;
+      node.prev = tail;
+      node.next = null;
+      tail = node;
+    }
+
+    public void delete(CacheItem<K, V> node) {
+      if (head.next == null) return;
+      if (node == head.next) {
+        deleteHead();
+      } else if (node == tail) {
+        deleteTail();
+      } else {
+        node.prev.next = node.next;
+        node.next.prev = node.prev;
+        node.next = null;
+        node.prev = null;
+      }
+    }
+
+    public CacheItem<K, V> deleteTail() {
+      if (head.next == null) return null;
+      CacheItem<K, V> ret = tail;
+      tail = tail.prev;
+      tail.next = null;
+      ret.prev = null;
+      ret.next = null;
+      return ret;
+    }
+
+    public CacheItem<K, V> deleteHead() {
+      if (head.next == null) return null;
+      if (head.next == tail) {
+        tail = tail.prev;
+      }
+      CacheItem<K, V> ret = head.next;
+      head.next = ret.next;
+      if (ret.next != null) {
+        ret.next.prev = head;
+      }
+      ret.next = null;
+      ret.prev = null;
+      return ret;
+    }
+  }
+
+  private Map<Integer, CacheItem<Integer, Integer>> cacheMap =
+      new HashMap<Integer, CacheItem<Integer, Integer>>();
+  private BidirectionalList<Integer, Integer> cacheList = new BidirectionalList<Integer, Integer>();
+  private int cacheSize = 0;
+  private int capacity;
+
+  public LRUCache(int capacity) {
+    this.capacity = capacity;
+  }
+
+  public int get(int key) {
+    CacheItem<Integer, Integer> itm = cacheMap.get(key);
+    if (itm == null) return -1;
+    cacheList.delete(itm);
+    cacheList.insertTail(itm);
+    return itm.value.intValue();
+  }
+
+  public void set(int key, int value) {
+    if (cacheMap.containsKey(key)) {
+      updateItem(key, value);
+    } else if (cacheSize == capacity && removeLeastUsed()) {
+      cacheSize--;
+      addItem(key, value);
+    } else {
+      addItem(key, value);
+    }
+  }
+
+  private void addItem(int key, int value) {
+    CacheItem<Integer, Integer> newCacheItem = new CacheItem<Integer, Integer>(key, value);
+    cacheList.insertTail(newCacheItem);
+    cacheMap.put(key, newCacheItem);
+    cacheSize++;
+  }
+
+  private void updateItem(int key, int value) {
+    CacheItem<Integer, Integer> exitedKey = cacheMap.get(key);
+    exitedKey.value = value;
+    cacheList.delete(exitedKey);
+    cacheList.insertTail(exitedKey);
+  }
+
+  private boolean removeLeastUsed() {
+    CacheItem<Integer, Integer> removedKey = cacheList.deleteHead();
+    cacheMap.remove(removedKey.key);
+    return removedKey == null ? false : true;
+  }
 }
diff --git a/LargestRectangleinHistogram.java b/LargestRectangleinHistogram.java
index 2f0e3f0..829d298 100644
--- a/LargestRectangleinHistogram.java
+++ b/LargestRectangleinHistogram.java
@@ -2,33 +2,30 @@
 import java.util.Stack;
 
 /**
- * Given n non-negative integers representing the histogram's bar height where
- * the width of each bar is 1, find the area of largest rectangle in the
- * histogram.
- * 
- * Above is a histogram where width of each bar is 1, given height =
- * [2,1,5,6,2,3].
- * 
- * The largest rectangle is shown in the shaded area, which has area = 10 unit.
- * 
- * For example, Given height = [2,1,5,6,2,3], return 10.
+ * Given n non-negative integers representing the histogram's bar height where the width of each bar
+ * is 1, find the area of largest rectangle in the histogram.
+ *
+ * <p>Above is a histogram where width of each bar is 1, given height = [2,1,5,6,2,3].
+ *
+ * <p>The largest rectangle is shown in the shaded area, which has area = 10 unit.
+ *
+ * <p>For example, Given height = [2,1,5,6,2,3], return 10.
  */
-
 public class LargestRectangleinHistogram {
-	public int largestRectangleArea(int[] height) {
-		Stack<Integer> stack = new Stack<Integer>();
-		int i = 0;
-		int maxArea = 0;
-		int[] h = new int[height.length + 1];
-		h = Arrays.copyOf(height, height.length + 1);
-		while (i < h.length) {
-			if (stack.isEmpty() || h[stack.peek()] <= h[i]) {
-				stack.push(i++);
-			} else {
-				int t = stack.pop();
-				maxArea = Math.max(maxArea, h[t] * (stack.isEmpty() ? i : i - stack.peek() - 1));
-			}
-		}
-		return maxArea;
-	}
-}
\ No newline at end of file
+  public int largestRectangleArea(int[] height) {
+    Stack<Integer> stack = new Stack<Integer>();
+    int i = 0;
+    int maxArea = 0;
+    int[] h = new int[height.length + 1];
+    h = Arrays.copyOf(height, height.length + 1);
+    while (i < h.length) {
+      if (stack.isEmpty() || h[stack.peek()] <= h[i]) {
+        stack.push(i++);
+      } else {
+        int t = stack.pop();
+        maxArea = Math.max(maxArea, h[t] * (stack.isEmpty() ? i : i - stack.peek() - 1));
+      }
+    }
+    return maxArea;
+  }
+}
diff --git a/LengthofLastWord.java b/LengthofLastWord.java
index 976998f..a566eb8 100644
--- a/LengthofLastWord.java
+++ b/LengthofLastWord.java
@@ -1,29 +1,24 @@
-
-
 /**
- * Given a string s consists of upper/lower-case alphabets and empty space
- * characters ' ', return the length of last word in the string.
- * 
- * If the last word does not exist, return 0.
- * 
- * Note: A word is defined as a character sequence consists of non-space
- * characters only.
- * 
- * For example, Given s = "Hello World", return 5.
+ * Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return
+ * the length of last word in the string.
+ *
+ * <p>If the last word does not exist, return 0.
+ *
+ * <p>Note: A word is defined as a character sequence consists of non-space characters only.
+ *
+ * <p>For example, Given s = "Hello World", return 5.
  */
-
 public class LengthofLastWord {
-	public int lengthOfLastWord(String s) {
-		int i = s.length() - 1;
-		while (i >= 0 && s.charAt(i) == ' ') {
-			i--;
-		}
-		if (i < 0)
-			return 0;
-		int j = i;
-		while (j - 1 >= 0 && s.charAt(j - 1) != ' ') {
-			j--;
-		}
-		return i - j + 1;
-	}
-}
\ No newline at end of file
+  public int lengthOfLastWord(String s) {
+    int i = s.length() - 1;
+    while (i >= 0 && s.charAt(i) == ' ') {
+      i--;
+    }
+    if (i < 0) return 0;
+    int j = i;
+    while (j - 1 >= 0 && s.charAt(j - 1) != ' ') {
+      j--;
+    }
+    return i - j + 1;
+  }
+}
diff --git a/LetterCombinationsofaPhoneNumber.java b/LetterCombinationsofaPhoneNumber.java
index ecea2db..d3f4e80 100644
--- a/LetterCombinationsofaPhoneNumber.java
+++ b/LetterCombinationsofaPhoneNumber.java
@@ -1,41 +1,43 @@
-
-
 import java.util.ArrayList;
 
 /**
- * Given a digit string, return all possible letter combinations that the number
- * could represent.
- * 
- * A mapping of digit to letters (just like on the telephone buttons) is given below.
- * 
- * Input:Digit string "23"
- * Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].
+ * Given a digit string, return all possible letter combinations that the number could represent.
+ *
+ * <p>A mapping of digit to letters (just like on the telephone buttons) is given below.
+ *
+ * <p>Input:Digit string "23" Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].
  */
-
 public class LetterCombinationsofaPhoneNumber {
-	private char[][] map = new char[][] { { 'a', 'b', 'c' }, { 'd', 'e', 'f' },
-			{ 'g', 'h', 'i' }, { 'j', 'k', 'l' }, { 'm', 'n', 'o' },
-			{ 'p', 'q', 'r', 's' }, { 't', 'u', 'v' }, { 'w', 'x', 'y', 'z' } };
+  private char[][] map =
+      new char[][] {
+        {'a', 'b', 'c'},
+        {'d', 'e', 'f'},
+        {'g', 'h', 'i'},
+        {'j', 'k', 'l'},
+        {'m', 'n', 'o'},
+        {'p', 'q', 'r', 's'},
+        {'t', 'u', 'v'},
+        {'w', 'x', 'y', 'z'}
+      };
 
-	public ArrayList<String> letterCombinations(String digits) {
-		ArrayList<String> ret = new ArrayList<String>();
-		StringBuilder sb = new StringBuilder();
-		letterCombinations(digits, 0, sb, ret);
-		return ret;
-	}
+  public ArrayList<String> letterCombinations(String digits) {
+    ArrayList<String> ret = new ArrayList<String>();
+    StringBuilder sb = new StringBuilder();
+    letterCombinations(digits, 0, sb, ret);
+    return ret;
+  }
 
-	private void letterCombinations(String digits, int i, StringBuilder sb,
-			ArrayList<String> ret) {
-		if (i >= digits.length()) {
-			ret.add(sb.toString());
-		} else {
-			int index = digits.charAt(i) - '1' - 1;
-			int size = map[index].length;
-			for (int j = 0; j < size; j++) {
-				sb.append(map[index][j]);
-				letterCombinations(digits, i + 1, sb, ret);
-				sb.deleteCharAt(sb.length() - 1);
-			}
-		}
-	}
-}
\ No newline at end of file
+  private void letterCombinations(String digits, int i, StringBuilder sb, ArrayList<String> ret) {
+    if (i >= digits.length()) {
+      ret.add(sb.toString());
+    } else {
+      int index = digits.charAt(i) - '1' - 1;
+      int size = map[index].length;
+      for (int j = 0; j < size; j++) {
+        sb.append(map[index][j]);
+        letterCombinations(digits, i + 1, sb, ret);
+        sb.deleteCharAt(sb.length() - 1);
+      }
+    }
+  }
+}
diff --git a/LinkedListCycle.java b/LinkedListCycle.java
index 24eb4e9..ed243d9 100644
--- a/LinkedListCycle.java
+++ b/LinkedListCycle.java
@@ -1,29 +1,25 @@
-
-
 /**
  * Given a linked list, determine if it has a cycle in it.
- * 
- * Follow up:
- * Can you solve it without using extra space?
+ *
+ * <p>Follow up: Can you solve it without using extra space?
  */
-
 public class LinkedListCycle {
-	public boolean hasCycle(ListNode head) {
-		if (head == null) return false;
-		ListNode fast = head;
-		ListNode late = head;
-		do {
-			fast = fast.next;
-			late = late.next;
-			if (late == null) {
-				return false;
-			} else {
-				late = late.next;
-				if (fast == late) {
-					return true;
-				}
-			}
-		} while(fast != null && late != null);
-		return false;
-	}
+  public boolean hasCycle(ListNode head) {
+    if (head == null) return false;
+    ListNode fast = head;
+    ListNode late = head;
+    do {
+      fast = fast.next;
+      late = late.next;
+      if (late == null) {
+        return false;
+      } else {
+        late = late.next;
+        if (fast == late) {
+          return true;
+        }
+      }
+    } while (fast != null && late != null);
+    return false;
+  }
 }
diff --git a/LinkedListCycleII.java b/LinkedListCycleII.java
index 4495176..85c13b7 100644
--- a/LinkedListCycleII.java
+++ b/LinkedListCycleII.java
@@ -1,28 +1,25 @@
 /**
- * Given a linked list, return the node where the cycle begins. If there is no
- * cycle, return null.
- * 
- * Follow up: Can you solve it without using extra space?
- * 
+ * Given a linked list, return the node where the cycle begins. If there is no cycle, return null.
+ *
+ * <p>Follow up: Can you solve it without using extra space?
  */
 public class LinkedListCycleII {
-	public ListNode detectCycle(ListNode head) {
-		if (head == null)
-			return head;
-		ListNode fast = head, slow = head;
-		do {
-			if (fast.next != null && fast.next.next != null) {
-				fast = fast.next.next;
-				slow = slow.next;
-			} else {
-				return null;
-			}
-		} while (fast != slow);
-		slow = head;
-		while (fast != slow) {
-			fast = fast.next;
-			slow = slow.next;
-		}
-		return fast;
-	}
+  public ListNode detectCycle(ListNode head) {
+    if (head == null) return head;
+    ListNode fast = head, slow = head;
+    do {
+      if (fast.next != null && fast.next.next != null) {
+        fast = fast.next.next;
+        slow = slow.next;
+      } else {
+        return null;
+      }
+    } while (fast != slow);
+    slow = head;
+    while (fast != slow) {
+      fast = fast.next;
+      slow = slow.next;
+    }
+    return fast;
+  }
 }
diff --git a/ListNode.java b/ListNode.java
index 4783752..6e09d58 100644
--- a/ListNode.java
+++ b/ListNode.java
@@ -1,11 +1,9 @@
-
-
 class ListNode {
-	int val;
-	ListNode next;
+  int val;
+  ListNode next;
 
-	ListNode(int x) {
-		val = x;
-		next = null;
-	}
-}
\ No newline at end of file
+  ListNode(int x) {
+    val = x;
+    next = null;
+  }
+}
diff --git a/LongPressedName.java b/LongPressedName.java
new file mode 100644
index 0000000..1df9b9c
--- /dev/null
+++ b/LongPressedName.java
@@ -0,0 +1,35 @@
+/**
+ * Your friend is typing his name into a keyboard.  Sometimes, when typing a character c, the key might get long pressed, and the character will be typed 1 or more times.
+ *
+ * You examine the typed characters of the keyboard.  Return True if it is possible that it was your friends name, with some characters (possibly none) being long pressed.
+ *
+ * Example 1:
+ *
+ * Input: name = "alex", typed = "aaleex"
+ * Output: true
+ * Explanation: 'a' and 'e' in 'alex' were long pressed.
+ */
+class Solution {
+  public boolean isLongPressedName(String name, String typed) {
+    int i = 0;
+    int j = 0;
+    int m = name.length();
+    int n = typed.length();
+    if (m > n) return false;
+    while(i < m) {
+      while (i < m && j < n && name.charAt(i) == typed.charAt(j)) {
+        i++;
+        j++;
+      }
+      while(j > 0 && j < n && typed.charAt(j - 1) == typed.charAt(j)) {
+        j++;
+      }
+      if (i == m) {
+        return j == n;
+      } else if (j == n || name.charAt(i) != typed.charAt(j)) {
+        return false;
+      }
+    }
+    return j == n;
+  }
+}
\ No newline at end of file
diff --git a/LongestCommonPrefix.java b/LongestCommonPrefix.java
index ed17c6a..3ae0c84 100644
--- a/LongestCommonPrefix.java
+++ b/LongestCommonPrefix.java
@@ -1,24 +1,17 @@
-
-
-/**
- * Write a function to find the longest common prefix string amongst an array of
- * strings.
- */
-
+/** Write a function to find the longest common prefix string amongst an array of strings. */
 public class LongestCommonPrefix {
-	public String longestCommonPrefix(String[] strs) {
-		if (strs.length == 0)
-			return "";
-		int index = 0;
-		while (index < strs[0].length()) {
-			char c = strs[0].charAt(index);
-			for (int i = 1; i < strs.length; ++i) {
-				if (index >= strs[i].length() || strs[i].charAt(index) != c) {
-					return strs[0].substring(0, index);
-				}
-			}
-			index++;
-		}
-		return strs[0];
-	}
-}
\ No newline at end of file
+  public String longestCommonPrefix(String[] strs) {
+    if (strs.length == 0) return "";
+    int index = 0;
+    while (index < strs[0].length()) {
+      char c = strs[0].charAt(index);
+      for (int i = 1; i < strs.length; ++i) {
+        if (index >= strs[i].length() || strs[i].charAt(index) != c) {
+          return strs[0].substring(0, index);
+        }
+      }
+      index++;
+    }
+    return strs[0];
+  }
+}
diff --git a/LongestConsecutiveSequence.java b/LongestConsecutiveSequence.java
index 3a073bf..a4b968c 100644
--- a/LongestConsecutiveSequence.java
+++ b/LongestConsecutiveSequence.java
@@ -1,41 +1,46 @@
-
-
 import java.util.HashSet;
 
 /**
- * Given an unsorted array of integers, find the length of the longest
- * consecutive elements sequence.
- * 
- * For example, Given [100, 4, 200, 1, 3, 2], The longest consecutive elements
- * sequence is [1, 2, 3, 4]. Return its length: 4.
- * 
- * Your algorithm should run in O(n) complexity.
+ * Given an unsorted array of integers, find the length of the longest consecutive elements
+ * sequence.
+ *
+ * <p>For example, Given [100, 4, 200, 1, 3, 2], The longest consecutive elements sequence is [1, 2,
+ * 3, 4]. Return its length: 4.
+ *
+ * <p>Your algorithm should run in O(n) complexity.
  */
+class Solution {
+  public int longestConsecutive(int[] nums) {
+    if (nums.length == 0) {
+      return 0;
+    }
+
+    Set<Integer> set = new HashSet<Integer>();
+    int max = 1;
+
+    for (int e : nums)
+      set.add(e);
+
+    for (int e : nums) {
+      int left = e - 1;
+      int right = e + 1;
+      int count = 1;
+
+      while (set.contains(left)) {
+        count++;
+        set.remove(left);
+        left--;
+      }
+
+      while (set.contains(right)) {
+        count++;
+        set.remove(right);
+        right++;
+      }
+
+      max = Math.max(count, max);
+    }
 
-public class LongestConsecutiveSequence {
-	public int longestConsecutive(int[] num) {
-		int max = 0;
-		HashSet<Integer> h = new HashSet<Integer>();
-		for (int n : num) {
-			h.add(n);
-		}
-		for (int n : num) {
-			max = Math.max(max, getCount(h, n, false)
-					+ getCount(h, n + 1, true));
-		}
-		return max;
-	}
-
-	public int getCount(HashSet<Integer> h, int value, boolean asc) {
-		int count = 0;
-		while (h.contains(value)) {
-			count++;
-			h.remove(value);
-			if (asc)
-				value++;
-			else
-				value--;
-		}
-		return count;
-	}
-}
\ No newline at end of file
+    return max;
+  }
+}
diff --git a/LongestPalindromicSubstring.java b/LongestPalindromicSubstring.java
index eca13c2..9acac41 100644
--- a/LongestPalindromicSubstring.java
+++ b/LongestPalindromicSubstring.java
@@ -1,33 +1,29 @@
-
-
 /**
- * Given a string S, find the longest palindromic substring in S. You may assume
- * that the maximum length of S is 1000, and there exists one unique longest
- * palindromic substring.
+ * Given a string S, find the longest palindromic substring in S. You may assume that the maximum
+ * length of S is 1000, and there exists one unique longest palindromic substring.
  */
-
 public class LongestPalindromicSubstring {
-	public String longestPalindrome(String s) {
-		int length = s.length();
-		String result = "";
-		for (int i = 0; i < length; i++) {
-			String ps = getPalindrome(s, i, i);
-			if (ps.length() > result.length()) {
-				result = ps;
-			}
-			ps = getPalindrome(s, i, i + 1);
-			if (ps.length() > result.length()) {
-				result = ps;
-			}
-		}
-		return result;
-	}
+  public String longestPalindrome(String s) {
+    int length = s.length();
+    String result = "";
+    for (int i = 0; i < length; i++) {
+      String ps = getPalindrome(s, i, i);
+      if (ps.length() > result.length()) {
+        result = ps;
+      }
+      ps = getPalindrome(s, i, i + 1);
+      if (ps.length() > result.length()) {
+        result = ps;
+      }
+    }
+    return result;
+  }
 
-	private String getPalindrome(String s, int l, int r) {
-		while (l >= 0 && r < s.length() && s.charAt(l) == s.charAt(r)) {
-			l--;
-			r++;
-		}
-		return s.substring(l + 1, r);
-	}
-}
\ No newline at end of file
+  private String getPalindrome(String s, int l, int r) {
+    while (l >= 0 && r < s.length() && s.charAt(l) == s.charAt(r)) {
+      l--;
+      r++;
+    }
+    return s.substring(l + 1, r);
+  }
+}
diff --git a/LongestSubstringWithoutRepeatingCharacters.java b/LongestSubstringWithoutRepeatingCharacters.java
index 1baf4f0..bca3001 100644
--- a/LongestSubstringWithoutRepeatingCharacters.java
+++ b/LongestSubstringWithoutRepeatingCharacters.java
@@ -1,40 +1,33 @@
-
-
 import java.util.HashMap;
 
 /**
- * Given a string, find the length of the longest substring without repeating
- * characters. For example, the longest substring without repeating letters for
- * "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring
- * is "b", with the length of 1.
+ * Given a string, find the length of the longest substring without repeating characters. For
+ * example, the longest substring without repeating letters for "abcabcbb" is "abc", which the
+ * length is 3. For "bbbbb" the longest substring is "b", with the length of 1.
  */
-
 public class LongestSubstringWithoutRepeatingCharacters {
-	public int lengthOfLongestSubstring(String s) {
-		if (s.length() == 0)
-			return 0;
-		int i = 0, j = 0;
-		int result = 0;
-		HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
-		while (j < s.length()) {
-			Integer c = new Integer(s.charAt(j));
-			if (!map.containsKey(c)) {
-				map.put(c, j);
-			} else {
-				int length = j - i;
-				if (result < length) {
-					result = length;
-				}
-				Integer index = map.get(c);
-				i = Math.max(i, index + 1);
-				map.put(c, j);
-			}
-			j++;
-		}
+  public int lengthOfLongestSubstring(String s) {
+    if (s.length() == 0) return 0;
+    int i = 0, j = 0;
+    int result = 0;
+    HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
+    while (j < s.length()) {
+      Integer c = new Integer(s.charAt(j));
+      if (!map.containsKey(c)) {
+        map.put(c, j);
+      } else {
+        int length = j - i;
+        if (result < length) {
+          result = length;
+        }
+        Integer index = map.get(c);
+        i = Math.max(i, index + 1);
+        map.put(c, j);
+      }
+      j++;
+    }
 
-		if (result < j - i)
-			return j - i;
-		else
-			return result;
-	}
-}
\ No newline at end of file
+    if (result < j - i) return j - i;
+    else return result;
+  }
+}
diff --git a/LongestValidParentheses.java b/LongestValidParentheses.java
index 3883a84..ff2fa40 100644
--- a/LongestValidParentheses.java
+++ b/LongestValidParentheses.java
@@ -1,43 +1,42 @@
 import java.util.Stack;
 
 /**
- * Given a string containing just the characters '(' and ')', find the length of
- * the longest valid (well-formed) parentheses substring.
- * 
- * For "(()", the longest valid parentheses substring is "()", which has length = 2.
- * 
- * Another example is ")()())", where the longest valid parentheses substring is "()()", which has length = 4.
+ * Given a string containing just the characters '(' and ')', find the length of the longest valid
+ * (well-formed) parentheses substring.
+ *
+ * <p>For "(()", the longest valid parentheses substring is "()", which has length = 2.
+ *
+ * <p>Another example is ")()())", where the longest valid parentheses substring is "()()", which
+ * has length = 4.
  */
-
 public class LongestValidParentheses {
-	public int longestValidParentheses(String s) {
-		int length = s.length();
-		if (length == 0)
-			return 0;
-		int left = 0;
-		Stack<Integer> indexs = new Stack<Integer>();
-		boolean[] record = new boolean[length];
-		for (int i = 0; i < length; i++) {
-			if (s.charAt(i) == '(') {
-				left++;
-				indexs.push(i);
-			} else if (left > 0) {
-				int idx = indexs.pop();
-				record[idx] = true;
-				record[i] = true;
-				left--;
-			}
-		}
-		int ret = 0;
-		int current = 0;
-		for (int k = 0; k < length; k++) {
-			if (record[k]) {
-				current++;
-			} else {
-				ret = current > ret ? current : ret;
-				current = 0;
-			}
-		}
-		return ret > current ? ret : current;
-	}
-}
\ No newline at end of file
+  public int longestValidParentheses(String s) {
+    int length = s.length();
+    if (length == 0) return 0;
+    int left = 0;
+    Stack<Integer> indexs = new Stack<Integer>();
+    boolean[] record = new boolean[length];
+    for (int i = 0; i < length; i++) {
+      if (s.charAt(i) == '(') {
+        left++;
+        indexs.push(i);
+      } else if (left > 0) {
+        int idx = indexs.pop();
+        record[idx] = true;
+        record[i] = true;
+        left--;
+      }
+    }
+    int ret = 0;
+    int current = 0;
+    for (int k = 0; k < length; k++) {
+      if (record[k]) {
+        current++;
+      } else {
+        ret = current > ret ? current : ret;
+        current = 0;
+      }
+    }
+    return ret > current ? ret : current;
+  }
+}
diff --git a/LowestCommonAncestorOfBinaryTree.java b/LowestCommonAncestorOfBinaryTree.java
index aeb124d..7f1d1fe 100644
--- a/LowestCommonAncestorOfBinaryTree.java
+++ b/LowestCommonAncestorOfBinaryTree.java
@@ -1,31 +1,20 @@
 /**
  * Given a binary tree, find the lowest common ancestor of two given nodes in the tree.
  *
+ * <p>_______3______ / \ ___5__ ___1__ / \ / \ 6 _2 0 8 / \ 7 4 If you are not so sure about the
+ * definition of lowest common ancestor (LCA), please refer to my previous post: Lowest Common
+ * Ancestor of a Binary Search Tree (BST) or the definition of LCA here. Using the tree above as an
+ * example, the LCA of nodes 5 and 1 is 3. Please note that LCA for nodes 5 and 4 is 5.
  *
- *       _______3______
- *      /              \
- *   ___5__          ___1__
- *  /      \        /      \
- *  6      _2       0       8
- *        /  \
- *        7   4
- * If you are not so sure about the definition of lowest common ancestor (LCA), please refer to my previous 
- * post: Lowest Common Ancestor of a Binary Search Tree (BST) or the definition of LCA here. Using the tree 
- * above as an example, the LCA of nodes 5 and 1 is 3. Please note that LCA for nodes 5 and 4 is 5.
- *
- * Hint:
- * Top-down or bottom-up? Consider both approaches and see which one is more efficient.
+ * <p>Hint: Top-down or bottom-up? Consider both approaches and see which one is more efficient.
  */
 public class LowestCommonAncestorOfBinaryTree {
-	public TreeNode LCA(TreeNode root, TreeNode p, TreeNode q) {
-		if (root == null)
-			return null;
-		if (root == p || root == q)
-			return root;
-		TreeNode left = LCA(root.left, p, q);
-		TreeNode right = LCA(root.right, p, q);
-		if (left != null && right != null)
-			return root;
-		return left != null ? left : right;
-	}
+  public TreeNode LCA(TreeNode root, TreeNode p, TreeNode q) {
+    if (root == null) return null;
+    if (root == p || root == q) return root;
+    TreeNode left = LCA(root.left, p, q);
+    TreeNode right = LCA(root.right, p, q);
+    if (left != null && right != null) return root;
+    return left != null ? left : right;
+  }
 }
diff --git a/LowestCommonAncestorOfaBinarySearchTree.java b/LowestCommonAncestorOfaBinarySearchTree.java
index 1b44e06..cd0243b 100644
--- a/LowestCommonAncestorOfaBinarySearchTree.java
+++ b/LowestCommonAncestorOfaBinarySearchTree.java
@@ -1,35 +1,25 @@
 /**
  * Lowest Common Ancestor of a Binary Search Tree (BST)
  *
- * Given a binary search tree (BST), find the lowest common ancestor of two given nodes in the BST.
+ * <p>Given a binary search tree (BST), find the lowest common ancestor of two given nodes in the
+ * BST.
  *
+ * <p>_______6______ / \ ___2__ ___8__ / \ / \ 0 _4 7 9 / \ 3 5 Using the above tree as an example,
+ * the lowest common ancestor (LCA) of nodes 2 and 8 is 6. But how about LCA of nodes 2 and 4?
+ * Should it be 6 or 2?
  *
- *       _______6______
- *      /              \
- *   ___2__          ___8__
- *  /      \        /      \
- *  0      _4       7       9
- *        /  \
- *        3   5
- * Using the above tree as an example, the lowest common ancestor (LCA) of nodes 2 and 8 is 6. 
- * But how about LCA of nodes 2 and 4? Should it be 6 or 2?
+ * <p>According to the definition of LCA on Wikipedia: ��The lowest common ancestor is defined
+ * between two nodes v and w as the lowest node in T that has both v and w as descendants (where we
+ * allow a node to be a descendant of itself).�� Since a node can be a descendant of itself, the LCA
+ * of 2 and 4 should be 2, according to this definition.
  *
- * According to the definition of LCA on Wikipedia: ��The lowest common ancestor is defined between 
- * two nodes v and w as the lowest node in T that has both v and w as descendants (where we allow a 
- * node to be a descendant of itself).�� Since a node can be a descendant of itself, the LCA of 2 and 
- * 4 should be 2, according to this definition.
- *
- * Hint:
- * A top-down walk from the root of the tree is enough.
+ * <p>Hint: A top-down walk from the root of the tree is enough.
  */
 public class LowestCommonAncestorOfaBinarySearchTree {
-	public TreeNode LCA(TreeNode root, TreeNode p, TreeNode q) {
-		if (root == null || p == null || q == null)
-			return null;
-		if (Math.max(p.val, q.val) < root.val)
-			return LCA(root.left, p, q);
-		if (Math.min(p.val, q.val) > root.val)
-			return LCA(root.right, p, q);
-		return root;
-	}
+  public TreeNode LCA(TreeNode root, TreeNode p, TreeNode q) {
+    if (root == null || p == null || q == null) return null;
+    if (Math.max(p.val, q.val) < root.val) return LCA(root.left, p, q);
+    if (Math.min(p.val, q.val) > root.val) return LCA(root.right, p, q);
+    return root;
+  }
 }
diff --git a/MaxPointsOnALine.java b/MaxPointsOnALine.java
index 3f1c434..c761691 100644
--- a/MaxPointsOnALine.java
+++ b/MaxPointsOnALine.java
@@ -1,47 +1,87 @@
-
-
 /**
- * Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.
+ * Given n points on a 2D plane, find the maximum number of points that lie on the same straight
+ * line.
  */
 
 import java.util.HashMap;
 import java.util.Map;
 
+/**
+ * Definition for a point. class Point { int x; int y; Point() { x = 0; y = 0; } Point(int a, int b)
+ * { x = a; y = b; } }
+ */
 public class MaxPointsOnALine {
-	public int maxPoints(Point[] points) {
-		Map<Double, Integer> map = new HashMap<Double, Integer>();
-		int ret = 0;
-		int size = points.length;
-		for (int i = 0; i < size; i++) {
-			int invalidK = 0;
-			int add = 1;
-			for (int j = i + 1; j < size; j++) {
-				if (points[j].x == points[i].x) {
-					if (points[j].y == points[i].y) {
-						add++;
-					} else {
-						invalidK++;
-					}
-					continue;
-				}
-				double k = points[j].y == points[i].y ? 0.0
-						: (1.0 * (points[j].y - points[i].y))
-								/ (points[j].x - points[i].x);
-				if (map.containsKey(k)) {
-					int count = map.get(k);
-					map.put(k, count + 1);
-				} else {
-					map.put(k, 1);
-				}
-			}
-			for (Integer it : map.values()) {
-				if (it + add > ret) {
-					ret = it.intValue() + add;
-				}
-			}
-			ret = Math.max(invalidK + add, ret);
-			map.clear();
-		}
-		return ret;
-	}
+
+  private class Line {
+    private final double mSlope;
+    private final double mIntercept;
+
+    public Line(double slope, double intercept) {
+      mSlope = slope;
+      mIntercept = intercept;
+    }
+
+    @Override
+    public boolean equals(Object object) {
+      if (this == object) {
+        return true;
+      } else if (object == null) {
+        return false;
+      } else if (object instanceof Line) {
+        Line line = (Line) object;
+        if (Math.abs(mSlope - line.mSlope) < 0.0001
+            && Math.abs(mIntercept - line.mIntercept) < 0.0001) {
+          return true;
+        }
+      }
+      return false;
+    }
+
+    @Override
+    public int hashCode() {
+      final int prime = 31;
+      return prime * Double.toString(mSlope).hashCode() + Double.toString(mIntercept).hashCode();
+    }
+  }
+
+  public int maxPoints(Point[] points) {
+    Map<Line, Integer> map = new HashMap<Line, Integer>();
+    int ret = 0;
+    int size = points.length;
+    for (int i = 0; i < size; i++) {
+      int dup = 0;
+      for (int j = i + 1; j < size; j++) {
+        Line line = null;
+        if (points[j].x == points[i].x) {
+          if (points[j].y == points[i].y) {
+            // Record how many times the same "start" point occurs.
+            dup++;
+            continue;
+          }
+          line = new Line(Double.MAX_VALUE, Double.MAX_VALUE);
+        } else {
+          double slope =
+              points[j].y == points[i].y
+                  ? 0.0
+                  : (1.0 * (points[j].y - points[i].y)) / (points[j].x - points[i].x);
+          double intercept = points[i].y - slope * points[i].x;
+          line = new Line(slope, intercept);
+        }
+        if (map.containsKey(line)) {
+          map.put(line, map.get(line) + 1);
+        } else {
+          map.put(line, 2);
+        }
+      }
+      // Now check all lines which contains the current "start" point (point[i]).
+      for (Integer count : map.values()) {
+        ret = Math.max(ret, count.intValue() + dup);
+      }
+      map.clear();
+    }
+    // If we got ret as 0, all points in input array should be exactly the
+    // same point so that we cannot construct a line. So just need to return
+    // the length of the input array since all these points are in the same line.
+    return ret > 0 ? ret : points.length;
+  }
 }
diff --git a/MaximalRectangle.java b/MaximalRectangle.java
index 9f20ffe..acef393 100644
--- a/MaximalRectangle.java
+++ b/MaximalRectangle.java
@@ -1,42 +1,39 @@
 /**
- * Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle
- * containing all ones and return its area.
+ * Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones
+ * and return its area.
  */
-
 public class MaximalRectangle {
-	public int maximalRectangle(char[][] matrix) {
-		int rows = matrix.length;
-		if (rows == 0)
-			return 0;
-		int maxArea = 0;
-		int cols = matrix[0].length;
-		int[][] map = new int[rows][cols];
-		for (int j = 0; j < cols; j++) {
-			map[0][j] = matrix[0][j] == '0' ? 0 : 1;
-		}
-		for (int i = 1; i < rows; i++) {
-			for (int j = 0; j < cols; j++) {
-				map[i][j] = matrix[i][j] == '0' ? map[i - 1][j]
-						: map[i - 1][j] + 1;
-			}
-		}
-		int[] row = new int[cols];
-		for (int i = 0; i < rows; i++) {
-			for (int j = i; j < rows; j++) {
-				for (int k = 0; k < cols; k++) {
-					row[k] = map[j][k] - (i == 0 ? 0 : map[i - 1][k]);
-				}
-				int count = 0;
-				for (int k = 0; k < cols; k++) {
-					if (row[k] == j - i + 1) {
-						maxArea = Math.max(maxArea, ++count * (j - i + 1));
-					} else {
-						maxArea = Math.max(maxArea, count * (j - i + 1));
-						count = 0;
-					}
-				}
-			}
-		}
-		return maxArea;
-	}
-}
\ No newline at end of file
+  public int maximalRectangle(char[][] matrix) {
+    int rows = matrix.length;
+    if (rows == 0) return 0;
+    int maxArea = 0;
+    int cols = matrix[0].length;
+    int[][] map = new int[rows][cols];
+    for (int j = 0; j < cols; j++) {
+      map[0][j] = matrix[0][j] == '0' ? 0 : 1;
+    }
+    for (int i = 1; i < rows; i++) {
+      for (int j = 0; j < cols; j++) {
+        map[i][j] = matrix[i][j] == '0' ? map[i - 1][j] : map[i - 1][j] + 1;
+      }
+    }
+    int[] row = new int[cols];
+    for (int i = 0; i < rows; i++) {
+      for (int j = i; j < rows; j++) {
+        for (int k = 0; k < cols; k++) {
+          row[k] = map[j][k] - (i == 0 ? 0 : map[i - 1][k]);
+        }
+        int count = 0;
+        for (int k = 0; k < cols; k++) {
+          if (row[k] == j - i + 1) {
+            maxArea = Math.max(maxArea, ++count * (j - i + 1));
+          } else {
+            maxArea = Math.max(maxArea, count * (j - i + 1));
+            count = 0;
+          }
+        }
+      }
+    }
+    return maxArea;
+  }
+}
diff --git a/MaximumDepthOfBinaryTree.java b/MaximumDepthOfBinaryTree.java
index 1ff13d0..b140294 100644
--- a/MaximumDepthOfBinaryTree.java
+++ b/MaximumDepthOfBinaryTree.java
@@ -1,40 +1,40 @@
 /**
  * Given a binary tree, find its maximum depth.
- * 
- * The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
+ *
+ * <p>The maximum depth is the number of nodes along the longest path from the root node down to the
+ * farthest leaf node.
  */
 
 import java.util.LinkedList;
 import java.util.Queue;
 
-
 public class MaximumDepthOfBinaryTree {
-    public int maxDepth(TreeNode root) {
-        if (root == null) return 0;
-    	int ret = 1;
-    	int currentLevel = 1;
-    	int nextLevel = 0;
-    	Queue<TreeNode> queue = new LinkedList<TreeNode>();
-    	queue.add(root);
-    	while (!queue.isEmpty()) {
-    		TreeNode node = queue.remove();
-    		currentLevel--;
-    		if (node.left != null) {
-    			queue.add(root.left);
-    			nextLevel++;
-    		}
-    		if (node.right != null) {
-    			queue.add(root.right);
-    			nextLevel++;
-    		}
-    		if (currentLevel == 0) {
-    			if (nextLevel != 0) {
-    				ret++;
-    			}
-    			currentLevel = nextLevel;
-    			nextLevel = 0;
-    		}
-    	}
-    	return ret;
+  public int maxDepth(TreeNode root) {
+    if (root == null) return 0;
+    int ret = 1;
+    int currentLevel = 1;
+    int nextLevel = 0;
+    Queue<TreeNode> queue = new LinkedList<TreeNode>();
+    queue.add(root);
+    while (!queue.isEmpty()) {
+      TreeNode node = queue.remove();
+      currentLevel--;
+      if (node.left != null) {
+        queue.add(root.left);
+        nextLevel++;
+      }
+      if (node.right != null) {
+        queue.add(root.right);
+        nextLevel++;
+      }
+      if (currentLevel == 0) {
+        if (nextLevel != 0) {
+          ret++;
+        }
+        currentLevel = nextLevel;
+        nextLevel = 0;
+      }
     }
+    return ret;
+  }
 }
diff --git a/MaximumSubarray.java b/MaximumSubarray.java
index 1abcc4c..ef999c8 100644
--- a/MaximumSubarray.java
+++ b/MaximumSubarray.java
@@ -1,29 +1,28 @@
 /**
- * Find the contiguous subarray within an array (containing at least one number)
- * which has the largest sum.
- * 
- * For example, given the array [−2,1,−3,4,−1,2,1,−5,4], the contiguous subarray
- * [4,−1,2,1] has the largest sum = 6.
- * 
- * click to show more practice.
- * 
- * More practice: If you have figured out the O(n) solution, try coding another
- * solution using the divide and conquer approach, which is more subtle.
+ * Find the contiguous subarray within an array (containing at least one number) which has the
+ * largest sum.
+ *
+ * <p>For example, given the array [−2,1,−3,4,−1,2,1,−5,4], the contiguous subarray [4,−1,2,1] has
+ * the largest sum = 6.
+ *
+ * <p>click to show more practice.
+ *
+ * <p>More practice: If you have figured out the O(n) solution, try coding another solution using
+ * the divide and conquer approach, which is more subtle.
  */
-
 public class MaximumSubarray {
-	public int maxSubArray(int[] A) {
-		int max = Integer.MIN_VALUE;
-		int sum = 0;
-		for (int i = 0; i < A.length; i++) {
-			sum += A[i];
-			if (sum > max) {
-				max = sum;
-			}
-			if (sum < 0) {
-				sum = 0;
-			}
-		}
-		return max;
-	}
+  public int maxSubArray(int[] A) {
+    int max = Integer.MIN_VALUE;
+    int sum = 0;
+    for (int i = 0; i < A.length; i++) {
+      sum += A[i];
+      if (sum > max) {
+        max = sum;
+      }
+      if (sum < 0) {
+        sum = 0;
+      }
+    }
+    return max;
+  }
 }
diff --git a/MedianOfTwoSortedArrays.java b/MedianOfTwoSortedArrays.java
index f8bac38..8d35f4f 100644
--- a/MedianOfTwoSortedArrays.java
+++ b/MedianOfTwoSortedArrays.java
@@ -1,41 +1,37 @@
-
-
 /**
- * There are two sorted arrays A and B of size m and n respectively. Find the
- * median of the two sorted arrays. The overall run time complexity should be
- * O(log (m+n)).
+ * There are two sorted arrays A and B of size m and n respectively. Find the median of the two
+ * sorted arrays. The overall run time complexity should be O(log (m+n)).
  */
-
 public class MedianOfTwoSortedArrays {
-	public double findMedianSortedArrays(int A[], int B[]) {
-		int m = A.length;
-		int n = B.length;
-		int k = m + n;
-		if (k % 2 != 0) {
-			return findKth(A, 0, B, 0, k / 2 + 1);
-		} else {
-			return (findKth(A, 0, B, 0, k / 2) + findKth(A, 0, B, 0, k / 2 + 1)) / 2.0;
-		}
-	}
+  public double findMedianSortedArrays(int A[], int B[]) {
+    int m = A.length;
+    int n = B.length;
+    int k = m + n;
+    if (k % 2 != 0) {
+      return findKth(A, 0, B, 0, k / 2 + 1);
+    } else {
+      return (findKth(A, 0, B, 0, k / 2) + findKth(A, 0, B, 0, k / 2 + 1)) / 2.0;
+    }
+  }
 
-	private double findKth(int A[], int a, int B[], int b, int k) {
-		if (A.length - a > B.length - b) {
-			return findKth(B, b, A, a, k);
-		}
-		if (a >= A.length) {
-			return B[b + k - 1];
-		}
-		if (k == 1) {
-			return Math.min(A[a], B[b]);
-		}
-		int midA = Math.min(k / 2, A.length - a);
-		int midB = k - midA;
-		if (A[a + midA - 1] < B[b + midB - 1]) {
-			return findKth(A, a + midA, B, b, k - midA);
-		} else if (A[a + midA - 1] > B[b + midB - 1]) {
-			return findKth(A, a, B, b + midB, k - midB);
-		} else {
-			return A[a + midA - 1];
-		}
-	}
+  private double findKth(int A[], int a, int B[], int b, int k) {
+    if (A.length - a > B.length - b) {
+      return findKth(B, b, A, a, k);
+    }
+    if (a >= A.length) {
+      return B[b + k - 1];
+    }
+    if (k == 1) {
+      return Math.min(A[a], B[b]);
+    }
+    int midA = Math.min(k / 2, A.length - a);
+    int midB = k - midA;
+    if (A[a + midA - 1] < B[b + midB - 1]) {
+      return findKth(A, a + midA, B, b, k - midA);
+    } else if (A[a + midA - 1] > B[b + midB - 1]) {
+      return findKth(A, a, B, b + midB, k - midB);
+    } else {
+      return A[a + midA - 1];
+    }
+  }
 }
diff --git a/MergeIntervals.java b/MergeIntervals.java
index cb102dd..071b8c0 100644
--- a/MergeIntervals.java
+++ b/MergeIntervals.java
@@ -2,42 +2,39 @@
 import java.util.Arrays;
 import java.util.Comparator;
 
-/** 
+/**
  * Given a collection of intervals, merge all overlapping intervals.
- * 
- * For example,
- * Given [1,3],[2,6],[8,10],[15,18],
- * return [1,6],[8,10],[15,18].
+ *
+ * <p>For example, Given [1,3],[2,6],[8,10],[15,18], return [1,6],[8,10],[15,18].
  */
-
 public class MergeIntervals {
-	public class IntervalCmp implements Comparator<Interval> {
-		@Override
-		public int compare(Interval i1, Interval i2) {
-			if (i1.start < i2.start) return -1;
-			if (i1.start == i2.start && i1.end <= i2.end) return -1;
-			return 1;
-		}
-	}
-	
-	public ArrayList<Interval> merge(ArrayList<Interval> intervals) {
-		ArrayList<Interval> ret = new ArrayList<Interval>();
-		if (intervals.size() == 0) return ret;
-		Interval[] arr = new Interval[intervals.size()];
-		intervals.toArray(arr);
-		Arrays.sort(arr, new IntervalCmp());
-		int start = arr[0].start;
-		int end = arr[0].end;
-		for (int i = 0; i < arr.length; i++) {
-			if (arr[i].start <= end) {
-				end = Math.max(end, arr[i].end);
-			} else {
-				ret.add(new Interval(start, end));
-				start = arr[i].start;
-				end = arr[i].end;
-			}
-		}
-		ret.add(new Interval(start, end));
-		return ret;
-	}
-}
\ No newline at end of file
+  public class IntervalCmp implements Comparator<Interval> {
+    @Override
+    public int compare(Interval i1, Interval i2) {
+      if (i1.start < i2.start) return -1;
+      if (i1.start == i2.start && i1.end <= i2.end) return -1;
+      return 1;
+    }
+  }
+
+  public ArrayList<Interval> merge(ArrayList<Interval> intervals) {
+    ArrayList<Interval> ret = new ArrayList<Interval>();
+    if (intervals.size() == 0) return ret;
+    Interval[] arr = new Interval[intervals.size()];
+    intervals.toArray(arr);
+    Arrays.sort(arr, new IntervalCmp());
+    int start = arr[0].start;
+    int end = arr[0].end;
+    for (int i = 0; i < arr.length; i++) {
+      if (arr[i].start <= end) {
+        end = Math.max(end, arr[i].end);
+      } else {
+        ret.add(new Interval(start, end));
+        start = arr[i].start;
+        end = arr[i].end;
+      }
+    }
+    ret.add(new Interval(start, end));
+    return ret;
+  }
+}
diff --git a/MergeSortedArray.java b/MergeSortedArray.java
index 6eee23d..e9f22b3 100644
--- a/MergeSortedArray.java
+++ b/MergeSortedArray.java
@@ -1,21 +1,20 @@
 /**
  * Given two sorted integer arrays A and B, merge B into A as one sorted array.
- * 
- * Note: 
- * 
- * You may assume that A has enough space to hold additional elements from B. 
- * The number of elements initialized in A and B are m and n respectively.
+ *
+ * <p>Note:
+ *
+ * <p>You may assume that A has enough space to hold additional elements from B. The number of
+ * elements initialized in A and B are m and n respectively.
  */
-
 public class MergeSortedArray {
-	public void merge(int A[], int m, int B[], int n) {
-		int i = m - 1, j = n - 1;
-		int k = m + n - 1;
-		while (i >= 0 && j >= 0) {
-			A[k--] = A[i] >= B[j] ? A[i--] : B[j--];
-		}
-		while (j >= 0) {
-			A[k--] = B[j--];
-		}
-	}
-}
\ No newline at end of file
+  public void merge(int A[], int m, int B[], int n) {
+    int i = m - 1, j = n - 1;
+    int k = m + n - 1;
+    while (i >= 0 && j >= 0) {
+      A[k--] = A[i] >= B[j] ? A[i--] : B[j--];
+    }
+    while (j >= 0) {
+      A[k--] = B[j--];
+    }
+  }
+}
diff --git a/MergeTwoSortedLists.java b/MergeTwoSortedLists.java
index 8104ba3..06b5a85 100644
--- a/MergeTwoSortedLists.java
+++ b/MergeTwoSortedLists.java
@@ -1,29 +1,26 @@
-
-
-/** 
- * Merge two sorted linked lists and return it as a new list. 
- * The new list should be made by splicing together the nodes of the first two lists. 
+/**
+ * Merge two sorted linked lists and return it as a new list. The new list should be made by
+ * splicing together the nodes of the first two lists.
  */
-
 public class MergeTwoSortedLists {
-	public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
-		ListNode head = new ListNode(0);
-		ListNode cur = head;
-		while (l1 != null && l2 != null) {
-			if (l1.val <= l2.val) {
-				cur.next = l1;
-				l1 = l1.next;
-			} else {
-				cur.next = l2;
-				l2 = l2.next;
-			}
-			cur = cur.next;
-		}
-		if (l1 != null) {
-			cur.next = l1;
-		} else {
-			cur.next = l2;
-		}
-		return head.next;
-	}
-}
\ No newline at end of file
+  public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
+    ListNode head = new ListNode(0);
+    ListNode cur = head;
+    while (l1 != null && l2 != null) {
+      if (l1.val <= l2.val) {
+        cur.next = l1;
+        l1 = l1.next;
+      } else {
+        cur.next = l2;
+        l2 = l2.next;
+      }
+      cur = cur.next;
+    }
+    if (l1 != null) {
+      cur.next = l1;
+    } else {
+      cur.next = l2;
+    }
+    return head.next;
+  }
+}
diff --git a/MergekSortedLists.java b/MergekSortedLists.java
index 81c3575..a8a4390 100644
--- a/MergekSortedLists.java
+++ b/MergekSortedLists.java
@@ -1,46 +1,38 @@
-
-
 import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.PriorityQueue;
 
-/** 
- * Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 
- *
+/**
+ * Merge k sorted linked lists and return it as one sorted list. Analyze and describe its
+ * complexity.
  */
-
 public class MergekSortedLists {
-	public ListNode mergeKLists(ArrayList<ListNode> lists) {
-		if (lists == null || lists.isEmpty())
-			return null;
+  public ListNode mergeKLists(ArrayList<ListNode> lists) {
+    if (lists == null || lists.isEmpty()) return null;
 
-		Comparator<ListNode> comp = new Comparator<ListNode>() {
-			public int compare(ListNode o1, ListNode o2) {
-				if (o1.val < o2.val)
-					return -1;
-				if (o1.val > o2.val)
-					return 1;
-				return 0;
-			}
-		};
-		PriorityQueue<ListNode> heap = new PriorityQueue<ListNode>(
-				lists.size(), comp);
-		for (ListNode node : lists) {
-			if (node != null)
-				heap.add(node);
-		}
-		ListNode head = null, cur = null;
-		while (!heap.isEmpty()) {
-			if (head == null) {
-				head = heap.poll();
-				cur = head;
-			} else {
-				cur.next = heap.poll();
-				cur = cur.next;
-			}
-			if (cur.next != null)
-				heap.add(cur.next);
-		}
-		return head;
-	}
-}
\ No newline at end of file
+    Comparator<ListNode> comp =
+        new Comparator<ListNode>() {
+          public int compare(ListNode o1, ListNode o2) {
+            if (o1.val < o2.val) return -1;
+            if (o1.val > o2.val) return 1;
+            return 0;
+          }
+        };
+    PriorityQueue<ListNode> heap = new PriorityQueue<ListNode>(lists.size(), comp);
+    for (ListNode node : lists) {
+      if (node != null) heap.add(node);
+    }
+    ListNode head = null, cur = null;
+    while (!heap.isEmpty()) {
+      if (head == null) {
+        head = heap.poll();
+        cur = head;
+      } else {
+        cur.next = heap.poll();
+        cur = cur.next;
+      }
+      if (cur.next != null) heap.add(cur.next);
+    }
+    return head;
+  }
+}
diff --git a/MinimumAddToMakeParenthesesValid.java b/MinimumAddToMakeParenthesesValid.java
new file mode 100644
index 0000000..ff9b985
--- /dev/null
+++ b/MinimumAddToMakeParenthesesValid.java
@@ -0,0 +1,49 @@
+/**
+ * Given a string S of '(' and ')' parentheses, we add the minimum number of parentheses ( '(' or ')',
+ * and in any positions ) so that the resulting parentheses string is valid.
+ *
+ * Formally, a parentheses string is valid if and only if:
+ *
+ * It is the empty string, or
+ * It can be written as AB (A concatenated with B), where A and B are valid strings, or
+ * It can be written as (A), where A is a valid string.
+ * Given a parentheses string, return the minimum number of parentheses we must add to make the resulting string valid.
+ *
+ * Example 1:
+ *
+ * Input: "())"
+ * Output: 1
+ * Example 2:
+ *
+ * Input: "((("
+ * Output: 3
+ * Example 3:
+ *
+ * Input: "()"
+ * Output: 0
+ * Example 4:
+ *
+ * Input: "()))(("
+ * Output: 4
+ */
+
+class Solution {
+  public int minAddToMakeValid(String S) {
+    int left = 0;
+    int change = 0;
+    int index = 0;
+    while(index < S.length()) {
+      if (S.charAt(index) == '(') {
+        left++;
+      } else if (S.charAt(index) == ')') {
+        if (left > 0) {
+          left--;
+        } else if (left == 0) {
+          change++;
+        }
+      }
+      index++;
+    }
+    return change + left;
+  }
+}
diff --git a/MinimumDepthofBinaryTree.java b/MinimumDepthofBinaryTree.java
index 396f52a..d8f5da2 100644
--- a/MinimumDepthofBinaryTree.java
+++ b/MinimumDepthofBinaryTree.java
@@ -1,23 +1,17 @@
-
-
-/** 
+/**
  * Given a binary tree, find its minimum depth.
  *
- * The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. 
+ * <p>The minimum depth is the number of nodes along the shortest path from the root node down to
+ * the nearest leaf node.
  */
-
 public class MinimumDepthofBinaryTree {
-	public int minDepth(TreeNode root) {
-		if (root == null)
-			return 0;
-		if (root.left == null && root.right == null)
-			return 1;
-		else {
-			int leftDepth = root.left != null ? minDepth(root.left)
-					: Integer.MAX_VALUE;
-			int rightDepth = root.right != null ? minDepth(root.right)
-					: Integer.MAX_VALUE;
-			return Math.min(leftDepth, rightDepth) + 1;
-		}
-	}
-}
\ No newline at end of file
+  public int minDepth(TreeNode root) {
+    if (root == null) return 0;
+    if (root.left == null && root.right == null) return 1;
+    else {
+      int leftDepth = root.left != null ? minDepth(root.left) : Integer.MAX_VALUE;
+      int rightDepth = root.right != null ? minDepth(root.right) : Integer.MAX_VALUE;
+      return Math.min(leftDepth, rightDepth) + 1;
+    }
+  }
+}
diff --git a/MinimumPathSum.java b/MinimumPathSum.java
index e36da7b..4e1422a 100644
--- a/MinimumPathSum.java
+++ b/MinimumPathSum.java
@@ -1,27 +1,23 @@
-
-
 /**
- * Given a m x n grid filled with non-negative numbers, find a path from top
- * left to bottom right which minimizes the sum of all numbers along its path.
- * 
- * Note: You can only move either down or right at any point in time.
+ * Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right
+ * which minimizes the sum of all numbers along its path.
+ *
+ * <p>Note: You can only move either down or right at any point in time.
  */
-
 public class MinimumPathSum {
-	public int minPathSum(int[][] grid) {
-		int[][] path = new int[grid.length][grid[0].length];
-		path[0][0] = grid[0][0];
-		for (int i = 1; i < grid.length; i++) {
-			path[i][0] = path[i - 1][0] + grid[i][0];
-		}
-		for (int j = 1; j < grid[0].length; j++) {
-			path[0][j] = path[0][j - 1] + grid[0][j];
-		}
-		for (int i = 1; i < grid.length; i++)
-			for (int j = 1; j < grid[0].length; j++) {
-				path[i][j] = Math.min(path[i - 1][j], path[i][j - 1])
-						+ grid[i][j];
-			}
-		return path[grid.length - 1][grid[0].length - 1];
-	}
-}
\ No newline at end of file
+  public int minPathSum(int[][] grid) {
+    int[][] path = new int[grid.length][grid[0].length];
+    path[0][0] = grid[0][0];
+    for (int i = 1; i < grid.length; i++) {
+      path[i][0] = path[i - 1][0] + grid[i][0];
+    }
+    for (int j = 1; j < grid[0].length; j++) {
+      path[0][j] = path[0][j - 1] + grid[0][j];
+    }
+    for (int i = 1; i < grid.length; i++)
+      for (int j = 1; j < grid[0].length; j++) {
+        path[i][j] = Math.min(path[i - 1][j], path[i][j - 1]) + grid[i][j];
+      }
+    return path[grid.length - 1][grid[0].length - 1];
+  }
+}
diff --git a/MinimumWindowSubstring.java b/MinimumWindowSubstring.java
index 573723d..8a07c09 100644
--- a/MinimumWindowSubstring.java
+++ b/MinimumWindowSubstring.java
@@ -1,53 +1,50 @@
-
-
 /**
- * Given a string S and a string T, find the minimum window in S which will
- * contain all the characters in T in complexity O(n).
- * 
- * For example, S = "ADOBECODEBANC" T = "ABC" Minimum window is "BANC".
- * 
- * Note: 
- * 
- * If there is no such window in S that covers all characters in T, return the emtpy string "".
- * 
- * If there are multiple such windows, you are guaranteed that there will always be only one unique minimum window in S.
+ * Given a string S and a string T, find the minimum window in S which will contain all the
+ * characters in T in complexity O(n).
+ *
+ * <p>For example, S = "ADOBECODEBANC" T = "ABC" Minimum window is "BANC".
+ *
+ * <p>Note:
+ *
+ * <p>If there is no such window in S that covers all characters in T, return the emtpy string "".
+ *
+ * <p>If there are multiple such windows, you are guaranteed that there will always be only one
+ * unique minimum window in S.
  */
-
 public class MinimumWindowSubstring {
-	public String minWindow(String S, String T) {
-		int[] hasFound = new int[256];
-		int[] needFound = new int[256];
-		int diffCount = T.length();
-		int length = S.length();
-		String window = "";
-		int size = Integer.MAX_VALUE;
-		if (length == 0 || diffCount == 0)
-			return window;
-		for (int l = 0; l < diffCount; l++) {
-			needFound[T.charAt(l)]++;
-		}
-		int i = 0, j = 0;
-		while (j < length) {
-			char c = S.charAt(j);
-			if (needFound[c] > 0 && ++hasFound[c] <= needFound[c]) {
-				diffCount--;
-			}
-			if (diffCount == 0) {
-				while (i <= j) {
-					char h = S.charAt(i);
-					i++;
-					if (needFound[h] > 0 && --hasFound[h] < needFound[h]) {
-						if (j - i + 1 < size) {
-							size = j - i + 1;
-							window = S.substring(i - 1, j + 1);
-						}
-						diffCount++;
-						break;
-					}
-				}
-			}
-			j++;
-		}
-		return window;
-	}
-}
\ No newline at end of file
+  public String minWindow(String S, String T) {
+    int[] hasFound = new int[256];
+    int[] needFound = new int[256];
+    int diffCount = T.length();
+    int length = S.length();
+    String window = "";
+    int size = Integer.MAX_VALUE;
+    if (length == 0 || diffCount == 0) return window;
+    for (int l = 0; l < diffCount; l++) {
+      needFound[T.charAt(l)]++;
+    }
+    int i = 0, j = 0;
+    while (j < length) {
+      char c = S.charAt(j);
+      if (needFound[c] > 0 && ++hasFound[c] <= needFound[c]) {
+        diffCount--;
+      }
+      if (diffCount == 0) {
+        while (i <= j) {
+          char h = S.charAt(i);
+          i++;
+          if (needFound[h] > 0 && --hasFound[h] < needFound[h]) {
+            if (j - i + 1 < size) {
+              size = j - i + 1;
+              window = S.substring(i - 1, j + 1);
+            }
+            diffCount++;
+            break;
+          }
+        }
+      }
+      j++;
+    }
+    return window;
+  }
+}
diff --git a/Movezeros.java b/Movezeros.java
new file mode 100644
index 0000000..e01f35a
--- /dev/null
+++ b/Movezeros.java
@@ -0,0 +1,30 @@
+/**
+ * Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.
+ *
+ * Example:
+ *
+ * Input: [0,1,0,3,12]
+ * Output: [1,3,12,0,0]
+ * Note:
+ *
+ * You must do this in-place without making a copy of the array.
+ * Minimize the total number of operations.
+ */
+class Solution {
+    public void moveZeroes(int[] nums) {
+        int i = 0;
+        int j = 0;
+        while(j < nums.length) {
+            if (nums[j] != 0) {
+                change(nums, i++, j);
+            }
+            j++;
+        }
+    }
+    
+    private void change(int[] nums, int i, int j) {
+        int tmp = nums[i];
+        nums[i] = nums[j];
+        nums[j] = tmp;
+    }
+}
diff --git a/MultiplyStrings.java b/MultiplyStrings.java
index a14ece0..1992fc8 100644
--- a/MultiplyStrings.java
+++ b/MultiplyStrings.java
@@ -1,29 +1,28 @@
 public class MultiplyStrings {
-	public String multiply(String num1, String num2) {
-		int length1 = num1.length();
-		int length2 = num2.length();
-		int[] m = new int[length1 + length2];
-		for (int k = length2 - 1, offset2 = 0; k >= 0; k--, offset2++) {
-			for (int i = length1 - 1, offset1 = 0; i >= 0; i--, offset1++) {
-				m[length1 + length2 - 1 - offset1 - offset2] += (num1.charAt(i) - '0')
-						* (num2.charAt(k) - '0');
-			}
-		}
-		int add = 0;
-		for (int t = length1 + length2 - 1; t >= 0; t--) {
-			int value = m[t] + add;
-			add = value / 10;
-			m[t] = value % 10;
-		}
-		StringBuffer sb = new StringBuffer();
-		int w = 0;
-		for (; w < length1 + length2; w++) {
-			if (m[w] != 0)
-				break;
-		}
-		for (int e = w; e < length1 + length2; e++) {
-			sb.append(m[e]);
-		}
-		return sb.length() == 0 ? "0" : sb.toString();
-	}
+  public String multiply(String num1, String num2) {
+    int length1 = num1.length();
+    int length2 = num2.length();
+    int[] m = new int[length1 + length2];
+    for (int k = length2 - 1, offset2 = 0; k >= 0; k--, offset2++) {
+      for (int i = length1 - 1, offset1 = 0; i >= 0; i--, offset1++) {
+        m[length1 + length2 - 1 - offset1 - offset2] +=
+            (num1.charAt(i) - '0') * (num2.charAt(k) - '0');
+      }
+    }
+    int add = 0;
+    for (int t = length1 + length2 - 1; t >= 0; t--) {
+      int value = m[t] + add;
+      add = value / 10;
+      m[t] = value % 10;
+    }
+    StringBuffer sb = new StringBuffer();
+    int w = 0;
+    for (; w < length1 + length2; w++) {
+      if (m[w] != 0) break;
+    }
+    for (int e = w; e < length1 + length2; e++) {
+      sb.append(m[e]);
+    }
+    return sb.length() == 0 ? "0" : sb.toString();
+  }
 }
diff --git a/NQueens.java b/NQueens.java
index 0e81de6..78c780e 100644
--- a/NQueens.java
+++ b/NQueens.java
@@ -1,77 +1,69 @@
 /**
- * The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.
- * 
- * Given an integer n, return all distinct solutions to the n-queens puzzle.
- * 
- * Each solution contains a distinct board configuration of the n-queens' placement, where 'Q' and '.' both indicate a queen and an empty space respectively.
- * 
- * For example,
- * 
- * There exist two distinct solutions to the 4-queens puzzle:
- * 
- * [
- *  [".Q..",  // Solution 1
- *   "...Q",
- *   "Q...",
- *   "..Q."],
+ * The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two
+ * queens attack each other.
  *
- *  ["..Q.",  // Solution 2
- *   "Q...",
- *   "...Q",
- *   ".Q.."]
- *  ]
+ * <p>Given an integer n, return all distinct solutions to the n-queens puzzle.
+ *
+ * <p>Each solution contains a distinct board configuration of the n-queens' placement, where 'Q'
+ * and '.' both indicate a queen and an empty space respectively.
+ *
+ * <p>For example,
+ *
+ * <p>There exist two distinct solutions to the 4-queens puzzle:
+ *
+ * <p>[ [".Q..", // Solution 1 "...Q", "Q...", "..Q."],
+ *
+ * <p>["..Q.", // Solution 2 "Q...", "...Q", ".Q.."] ]
  */
 
 import java.util.ArrayList;
 
 public class NQueens {
-	public ArrayList<String[]> solveNQueens(int n) {
-		ArrayList<String[]> ret = new ArrayList<String[]>();
-		if (n == 0)
-			return ret;
-		StringBuffer line = new StringBuffer();
-		for (int i = 0; i < n; i++) {
-			line.append('.');
-		}
-		StringBuffer[] sol = new StringBuffer[n];
-		for (int i = 0; i < n; i++) {
-			sol[i] = new StringBuffer(line.toString());
-		}
-		boolean[] cols = new boolean[n];
-		int[] row = new int[n];
-		findSolutions(n, 0, ret, sol, row, cols);
-		return ret;
-	}
+  public ArrayList<String[]> solveNQueens(int n) {
+    ArrayList<String[]> ret = new ArrayList<String[]>();
+    if (n == 0) return ret;
+    StringBuffer line = new StringBuffer();
+    for (int i = 0; i < n; i++) {
+      line.append('.');
+    }
+    StringBuffer[] sol = new StringBuffer[n];
+    for (int i = 0; i < n; i++) {
+      sol[i] = new StringBuffer(line.toString());
+    }
+    boolean[] cols = new boolean[n];
+    int[] row = new int[n];
+    findSolutions(n, 0, ret, sol, row, cols);
+    return ret;
+  }
 
-	private void findSolutions(int n, int start, ArrayList<String[]> ret,
-			StringBuffer[] sol, int[] row, boolean[] cols) {
-		if (start == n) {
-			String[] newSol = new String[n];
-			for (int i = 0; i < n; i++) {
-				newSol[i] = sol[i].toString();
-			}
-			ret.add(newSol);
-		} else {
-			for (int i = 0; i < n; i++) {
-				if (cols[i])
-					continue;
-				boolean ok = true;
-				for (int j = 0; j < start; j++) {
-					if (Math.abs(start - j) == Math.abs(i - row[j])) {
-						ok = false;
-						break;
-					}
-				}
-				if (ok) {
-					cols[i] = true;
-					sol[start].setCharAt(i, 'Q');
-					row[start] = i;
-					findSolutions(n, start + 1, ret, sol, row, cols);
-					row[start] = 0;
-					sol[start].setCharAt(i, '.');
-					cols[i] = false;
-				}
-			}
-		}
-	}
+  private void findSolutions(
+      int n, int start, ArrayList<String[]> ret, StringBuffer[] sol, int[] row, boolean[] cols) {
+    if (start == n) {
+      String[] newSol = new String[n];
+      for (int i = 0; i < n; i++) {
+        newSol[i] = sol[i].toString();
+      }
+      ret.add(newSol);
+    } else {
+      for (int i = 0; i < n; i++) {
+        if (cols[i]) continue;
+        boolean ok = true;
+        for (int j = 0; j < start; j++) {
+          if (Math.abs(start - j) == Math.abs(i - row[j])) {
+            ok = false;
+            break;
+          }
+        }
+        if (ok) {
+          cols[i] = true;
+          sol[start].setCharAt(i, 'Q');
+          row[start] = i;
+          findSolutions(n, start + 1, ret, sol, row, cols);
+          row[start] = 0;
+          sol[start].setCharAt(i, '.');
+          cols[i] = false;
+        }
+      }
+    }
+  }
 }
diff --git a/NQueensII.java b/NQueensII.java
index a22ca61..dec57cd 100644
--- a/NQueensII.java
+++ b/NQueensII.java
@@ -1,54 +1,50 @@
 /**
  * Follow up for N-Queens problem.
- * 
- * Now, instead outputting board configurations, return the total number of distinct solutions.
  *
+ * <p>Now, instead outputting board configurations, return the total number of distinct solutions.
  */
-
 public class NQueensII {
-	public int solveNQueens(int n) {
-		if (n == 0)
-			return 0;
-		StringBuffer line = new StringBuffer();
-		for (int i = 0; i < n; i++) {
-			line.append('.');
-		}
-		StringBuffer[] sol = new StringBuffer[n];
-		for (int i = 0; i < n; i++) {
-			sol[i] = new StringBuffer(line.toString());
-		}
-		boolean[] cols = new boolean[n];
-		int[] row = new int[n];
-		int[] count = new int[1];
-		findSolutions(n, 0, sol, row, cols, count);
-		return count[0];
-	}
+  public int solveNQueens(int n) {
+    if (n == 0) return 0;
+    StringBuffer line = new StringBuffer();
+    for (int i = 0; i < n; i++) {
+      line.append('.');
+    }
+    StringBuffer[] sol = new StringBuffer[n];
+    for (int i = 0; i < n; i++) {
+      sol[i] = new StringBuffer(line.toString());
+    }
+    boolean[] cols = new boolean[n];
+    int[] row = new int[n];
+    int[] count = new int[1];
+    findSolutions(n, 0, sol, row, cols, count);
+    return count[0];
+  }
 
-	private void findSolutions(int n, int start, StringBuffer[] sol, int[] row,
-			boolean[] cols, int[] count) {
-		if (start == n) {
-			count[0]++;
-		} else {
-			for (int i = 0; i < n; i++) {
-				if (cols[i])
-					continue;
-				boolean ok = true;
-				for (int j = 0; j < start; j++) {
-					if (Math.abs(start - j) == Math.abs(i - row[j])) {
-						ok = false;
-						break;
-					}
-				}
-				if (ok) {
-					cols[i] = true;
-					sol[start].setCharAt(i, 'Q');
-					row[start] = i;
-					findSolutions(n, start + 1, sol, row, cols, count);
-					row[start] = 0;
-					sol[start].setCharAt(i, '.');
-					cols[i] = false;
-				}
-			}
-		}
-	}
+  private void findSolutions(
+      int n, int start, StringBuffer[] sol, int[] row, boolean[] cols, int[] count) {
+    if (start == n) {
+      count[0]++;
+    } else {
+      for (int i = 0; i < n; i++) {
+        if (cols[i]) continue;
+        boolean ok = true;
+        for (int j = 0; j < start; j++) {
+          if (Math.abs(start - j) == Math.abs(i - row[j])) {
+            ok = false;
+            break;
+          }
+        }
+        if (ok) {
+          cols[i] = true;
+          sol[start].setCharAt(i, 'Q');
+          row[start] = i;
+          findSolutions(n, start + 1, sol, row, cols, count);
+          row[start] = 0;
+          sol[start].setCharAt(i, '.');
+          cols[i] = false;
+        }
+      }
+    }
+  }
 }
diff --git a/NextPermutation.java b/NextPermutation.java
index e7ac414..9c78a3d 100644
--- a/NextPermutation.java
+++ b/NextPermutation.java
@@ -1,47 +1,42 @@
-
-
 import java.util.Arrays;
 
 /**
- * Implement next permutation, which rearranges numbers into the
- * lexicographically next greater permutation of numbers.
- * 
- * If such arrangement is not possible, it must rearrange it as the lowest
- * possible order (ie, sorted in ascending order).
- * 
- * The replacement must be in-place, do not allocate extra memory.
- * 
- * Here are some examples. 
- * 
- * Inputs are in the left-hand column and its corresponding outputs are in the right-hand column.
- * 1,2,3 -> 1,3,2
- * 3,2,1 -> 1,2,3
- * 1,1,5 -> 1,5,1
+ * Implement next permutation, which rearranges numbers into the lexicographically next greater
+ * permutation of numbers.
+ *
+ * <p>If such arrangement is not possible, it must rearrange it as the lowest possible order (ie,
+ * sorted in ascending order).
+ *
+ * <p>The replacement must be in-place, do not allocate extra memory.
+ *
+ * <p>Here are some examples.
+ *
+ * <p>Inputs are in the left-hand column and its corresponding outputs are in the right-hand column.
+ * 1,2,3 -> 1,3,2 3,2,1 -> 1,2,3 1,1,5 -> 1,5,1
  */
-
 public class NextPermutation {
-	public void nextPermutation(int[] num) {
-		int i1 = 0;
-		int i2 = 0;
-		int i = num.length - 1;
-		int j = 0;
-		while (i > 0 && num[i - 1] >= num[i]) {
-			i--;
-		}
-		if (i == 0) {
-			Arrays.sort(num);
-			return;
-		} else {
-			i1 = i - 1;
-		}
-		j = i1 + 1;
-		while (j < num.length && num[i1] < num[j]) {
-			j++;
-		}
-		i2 = j - 1;
-		int temp = num[i1];
-		num[i1] = num[i2];
-		num[i2] = temp;
-		Arrays.sort(num, i1 + 1, num.length);
-	}
-}
\ No newline at end of file
+  public void nextPermutation(int[] num) {
+    int i1 = 0;
+    int i2 = 0;
+    int i = num.length - 1;
+    int j = 0;
+    while (i > 0 && num[i - 1] >= num[i]) {
+      i--;
+    }
+    if (i == 0) {
+      Arrays.sort(num);
+      return;
+    } else {
+      i1 = i - 1;
+    }
+    j = i1 + 1;
+    while (j < num.length && num[i1] < num[j]) {
+      j++;
+    }
+    i2 = j - 1;
+    int temp = num[i1];
+    num[i1] = num[i2];
+    num[i2] = temp;
+    Arrays.sort(num, i1 + 1, num.length);
+  }
+}
diff --git a/PalindromeNumber.java b/PalindromeNumber.java
index 389ed5f..ad9debf 100644
--- a/PalindromeNumber.java
+++ b/PalindromeNumber.java
@@ -1,36 +1,30 @@
-
-
 /**
  * Determine whether an integer is a palindrome. Do this without extra space.
- * 
- * Some hints: Could negative integers be palindromes? (ie, -1)
- * 
- * If you are thinking of converting the integer to string, note the restriction
- * of using extra space.
- * 
- * You could also try reversing an integer. However, if you have solved the
- * problem "Reverse Integer", you know that the reversed integer might overflow.
- * How would you handle such case?
- * 
- * There is a more generic way of solving this problem.
+ *
+ * <p>Some hints: Could negative integers be palindromes? (ie, -1)
+ *
+ * <p>If you are thinking of converting the integer to string, note the restriction of using extra
+ * space.
+ *
+ * <p>You could also try reversing an integer. However, if you have solved the problem "Reverse
+ * Integer", you know that the reversed integer might overflow. How would you handle such case?
+ *
+ * <p>There is a more generic way of solving this problem.
  */
-
 public class PalindromeNumber {
-	public boolean isPalindrome(int x) {
-		if (x < 0)
-			return false;
-		int k = 1;
-		while (x / k >= 10) {
-			k *= 10;
-		}
-		while (x >= 10) {
-			int left = x / k;
-			int right = x - x / 10 * 10;
-			if (left != right)
-				return false;
-			x = (x - x / k * k) / 10;
-			k /= 100;
-		}
-		return true;
-	}
-}
\ No newline at end of file
+  public boolean isPalindrome(int x) {
+    if (x < 0) return false;
+    int k = 1;
+    while (x / k >= 10) {
+      k *= 10;
+    }
+    while (x >= 10) {
+      int left = x / k;
+      int right = x - x / 10 * 10;
+      if (left != right) return false;
+      x = (x - x / k * k) / 10;
+      k /= 100;
+    }
+    return true;
+  }
+}
diff --git a/PalindromePartitioning.java b/PalindromePartitioning.java
index 59652a9..c5ae630 100644
--- a/PalindromePartitioning.java
+++ b/PalindromePartitioning.java
@@ -1,45 +1,41 @@
-
-
 import java.util.ArrayList;
 
 /**
  * Given a string s, partition s such that every substring of the partition is a palindrome.
- * 
- * Return all possible palindrome partitioning of s.
- * 
- * For example, given s = "aab", Return
- * 
- * [ ["aa","b"], ["a","a","b"] ]
+ *
+ * <p>Return all possible palindrome partitioning of s.
+ *
+ * <p>For example, given s = "aab", Return
+ *
+ * <p>[ ["aa","b"], ["a","a","b"] ]
  */
-
 public class PalindromePartitioning {
-	public ArrayList<ArrayList<String>> partition(String s) {
-		ArrayList<ArrayList<String>> ret = new ArrayList<ArrayList<String>>();
-		ArrayList<String> r = new ArrayList<String>();
-		int length = s.length();
-		boolean[][] map = new boolean[length][length];
-		findPartition(s, 0, ret, r, map);
-		return ret;
-	}
+  public ArrayList<ArrayList<String>> partition(String s) {
+    ArrayList<ArrayList<String>> ret = new ArrayList<ArrayList<String>>();
+    ArrayList<String> r = new ArrayList<String>();
+    int length = s.length();
+    boolean[][] map = new boolean[length][length];
+    findPartition(s, 0, ret, r, map);
+    return ret;
+  }
 
-	private void findPartition(String s, int start,
-			ArrayList<ArrayList<String>> ret, ArrayList<String> r,
-			boolean[][] map) {
-		int length = s.length();
-		if (start == length && r.size() != 0) {
-			ArrayList<String> clone = new ArrayList<String>(r);
-			ret.add(clone);
-		} else {
-			for (int j = start; j < length; j++) {
-				if (start == j
-						|| (j - start > 1 && s.charAt(start) == s.charAt(j) && map[start + 1][j - 1])
-						|| (j - start == 1 && s.charAt(start) == s.charAt(j))) {
-					map[start][j] = true;
-					r.add(s.substring(start, j + 1));
-					findPartition(s, j + 1, ret, r, map);
-					r.remove(r.size() - 1);
-				}
-			}
-		}
-	}
-}
\ No newline at end of file
+  private void findPartition(
+      String s, int start, ArrayList<ArrayList<String>> ret, ArrayList<String> r, boolean[][] map) {
+    int length = s.length();
+    if (start == length && r.size() != 0) {
+      ArrayList<String> clone = new ArrayList<String>(r);
+      ret.add(clone);
+    } else {
+      for (int j = start; j < length; j++) {
+        if (start == j
+            || (j - start > 1 && s.charAt(start) == s.charAt(j) && map[start + 1][j - 1])
+            || (j - start == 1 && s.charAt(start) == s.charAt(j))) {
+          map[start][j] = true;
+          r.add(s.substring(start, j + 1));
+          findPartition(s, j + 1, ret, r, map);
+          r.remove(r.size() - 1);
+        }
+      }
+    }
+  }
+}
diff --git a/PalindromePartitioningII.java b/PalindromePartitioningII.java
index a4df41f..a04fc6f 100644
--- a/PalindromePartitioningII.java
+++ b/PalindromePartitioningII.java
@@ -1,34 +1,31 @@
-
-
 /**
- * Given a string s, partition s such that every substring of the partition is a palindrome. 
- * Return the minimum cuts needed for a palindrome partitioning of s. 
- * 
- * For example, given s = "aab", Return 1 since the palindrome partitioning ["aa","b"] could be produced using 1 cut.
- * 
- * D[i] = min(1 + D[j + 1], D[i]) i<=j<n s[i, j] is palindrome
+ * Given a string s, partition s such that every substring of the partition is a palindrome. Return
+ * the minimum cuts needed for a palindrome partitioning of s.
+ *
+ * <p>For example, given s = "aab", Return 1 since the palindrome partitioning ["aa","b"] could be
+ * produced using 1 cut.
+ *
+ * <p>D[i] = min(1 + D[j + 1], D[i]) i<=j<n s[i, j] is palindrome
  */
-
 public class PalindromePartitioningII {
-	public int minCut(String s) {
-		int length = s.length();
-		int[] dp = new int[length + 1];
-		boolean[][] parlin = new boolean[length][length];
+  public int minCut(String s) {
+    int length = s.length();
+    int[] dp = new int[length + 1];
+    boolean[][] parlin = new boolean[length][length];
 
-		for (int i = length; i >= 0; i--) {
-			dp[i] = length - i;
-		}
+    for (int i = length; i >= 0; i--) {
+      dp[i] = length - i;
+    }
 
-		for (int i = length - 1; i >= 0; i--) {
-			for (int j = i; j < length; j++) {
-				if (s.charAt(i) == s.charAt(j)
-						&& (j - i < 2 || parlin[i + 1][j - 1])) {
-					parlin[i][j] = true;
-					dp[i] = Math.min(dp[i], dp[j + 1] + 1);
-				}
-			}
-		}
+    for (int i = length - 1; i >= 0; i--) {
+      for (int j = i; j < length; j++) {
+        if (s.charAt(i) == s.charAt(j) && (j - i < 2 || parlin[i + 1][j - 1])) {
+          parlin[i][j] = true;
+          dp[i] = Math.min(dp[i], dp[j + 1] + 1);
+        }
+      }
+    }
 
-		return dp[0] - 1;
-	}
-}
\ No newline at end of file
+    return dp[0] - 1;
+  }
+}
diff --git a/PartitionArrayIntoDisjointIntervals.java b/PartitionArrayIntoDisjointIntervals.java
new file mode 100644
index 0000000..e91cffd
--- /dev/null
+++ b/PartitionArrayIntoDisjointIntervals.java
@@ -0,0 +1,43 @@
+/**
+ * Given an array A, partition it into two (contiguous) subarrays left and right so that:
+ *
+ * Every element in left is less than or equal to every element in right.
+ * left and right are non-empty.
+ * left has the smallest possible size.
+ * Return the length of left after such a partitioning.
+ * It is guaranteed that such a partitioning exists.
+ *
+ *
+ * Example 1:
+ *
+ * Input: [5,0,3,8,6]
+ * Output: 3
+ * Explanation: left = [5,0,3], right = [8,6]
+ * 
+ * Example 2:
+ *
+ * Input: [1,1,1,0,6,12]
+ * Output: 4
+ * Explanation: left = [1,1,1,0], right = [6,12]
+ */
+class Solution {
+    public int partitionDisjoint(int[] A) {
+        if (A.length == 0) return 0;
+        int[] left = new int[A.length];
+        int[] right = new int[A.length];
+        left[0] = A[0];
+        right[A.length - 1] = A[A.length - 1];
+        for (int i = 1; i < A.length; i++) {
+            left[i] = Math.max(left[i - 1], A[i]);
+        }
+        for (int j = A.length - 2; j >= 0; j--) {
+            right[j] = Math.min(right[j + 1], A[j]);
+        }
+        int k = 0;
+        while(k < A.length - 1) {
+            if (right[k + 1] >= left[k]) return k + 1;
+            k++;
+        }
+        return 0;
+    }
+}
\ No newline at end of file
diff --git a/PartitionList.java b/PartitionList.java
index 50910ab..8f6c4ac 100644
--- a/PartitionList.java
+++ b/PartitionList.java
@@ -1,37 +1,35 @@
-/** 
- * Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.
+/**
+ * Given a linked list and a value x, partition it such that all nodes less than x come before nodes
+ * greater than or equal to x.
  *
- * You should preserve the original relative order of the nodes in each of the two partitions.
+ * <p>You should preserve the original relative order of the nodes in each of the two partitions.
  *
- * For example,
- * Given 1->4->3->2->5->2 and x = 3,
- * return 1->2->2->4->3->5.
+ * <p>For example, Given 1->4->3->2->5->2 and x = 3, return 1->2->2->4->3->5.
  */
-
 public class PartitionList {
-	public ListNode partition(ListNode head, int x) {
-        ListNode start = new ListNode(0);
-        start.next = head;
-        ListNode slow = start;
-        while (slow.next != null) {
-            if (slow.next.val < x) {
-                slow = slow.next;
-            } else {
-                break;
-            }
-        }
-        ListNode fast = slow;
-        while (fast.next != null) {
-            if (fast.next.val >= x) {
-                fast = fast.next;
-            } else {
-                ListNode target = fast.next;
-                fast.next = target.next;
-                target.next = slow.next;
-                slow.next = target;
-                slow = slow.next;
-            }
-        }
-        return start.next;
+  public ListNode partition(ListNode head, int x) {
+    ListNode start = new ListNode(0);
+    start.next = head;
+    ListNode slow = start;
+    while (slow.next != null) {
+      if (slow.next.val < x) {
+        slow = slow.next;
+      } else {
+        break;
+      }
     }
-}
\ No newline at end of file
+    ListNode fast = slow;
+    while (fast.next != null) {
+      if (fast.next.val >= x) {
+        fast = fast.next;
+      } else {
+        ListNode target = fast.next;
+        fast.next = target.next;
+        target.next = slow.next;
+        slow.next = target;
+        slow = slow.next;
+      }
+    }
+    return start.next;
+  }
+}
diff --git a/PascalTriangle.java b/PascalTriangle.java
index dee7ace..b0b15a3 100644
--- a/PascalTriangle.java
+++ b/PascalTriangle.java
@@ -1,40 +1,31 @@
-
-
 import java.util.ArrayList;
 
 /**
  * Given numRows, generate the first numRows of Pascal's triangle.
- * 
- * For example, given numRows = 5, Return
- * 
- * [      
- *        [1], 
- *       [1,1], 
- *      [1,2,1], 
- *     [1,3,3,1], 
- *    [1,4,6,4,1] 
- * ]
+ *
+ * <p>For example, given numRows = 5, Return
+ *
+ * <p>[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ]
  */
-
 public class PascalTriangle {
-	public ArrayList<ArrayList<Integer>> pascalTriangle(int numRows) {
-		ArrayList<ArrayList<Integer>> pt = new ArrayList<ArrayList<Integer>>();
-		int k = 1;
-		for (int i = 0; i < numRows; i++) {
-			ArrayList<Integer> r = new ArrayList<Integer>();
-			for (int j = 0; j < k; j++) {
-				r.add(1);
-			}
-			k++;
-			pt.add(r);
-		}
-		for (int f = 2; f < pt.size(); f++) {
-			ArrayList<Integer> prev = pt.get(f - 1);
-			ArrayList<Integer> current = pt.get(f);
-			for (int g = 1; g < current.size() - 1; g++) {
-				current.set(g, prev.get(g - 1) + prev.get(g));
-			}
-		}
-		return pt;
-	}
-}
\ No newline at end of file
+  public ArrayList<ArrayList<Integer>> pascalTriangle(int numRows) {
+    ArrayList<ArrayList<Integer>> pt = new ArrayList<ArrayList<Integer>>();
+    int k = 1;
+    for (int i = 0; i < numRows; i++) {
+      ArrayList<Integer> r = new ArrayList<Integer>();
+      for (int j = 0; j < k; j++) {
+        r.add(1);
+      }
+      k++;
+      pt.add(r);
+    }
+    for (int f = 2; f < pt.size(); f++) {
+      ArrayList<Integer> prev = pt.get(f - 1);
+      ArrayList<Integer> current = pt.get(f);
+      for (int g = 1; g < current.size() - 1; g++) {
+        current.set(g, prev.get(g - 1) + prev.get(g));
+      }
+    }
+    return pt;
+  }
+}
diff --git a/PascalsTriangleII.java b/PascalsTriangleII.java
index 67ed99a..3e162e7 100644
--- a/PascalsTriangleII.java
+++ b/PascalsTriangleII.java
@@ -1,35 +1,35 @@
 /**
  * Given an index k, return the kth row of the Pascal's triangle.
- * 
- * For example, given k = 3, Return [1,3,3,1].
- * 
- * Note:
- * 
- * Could you optimize your algorithm to use only O(k) extra space?
+ *
+ * <p>For example, given k = 3, Return [1,3,3,1].
+ *
+ * <p>Note:
+ *
+ * <p>Could you optimize your algorithm to use only O(k) extra space?
  */
 
 import java.util.ArrayList;
 
 public class PascalsTriangleII {
-	public ArrayList<Integer> getRow(int rowIndex) {
-		ArrayList<Integer> ret = new ArrayList<Integer>();
-		int[] tmp = new int[rowIndex + 1];
-		for (int i = 0; i <= rowIndex; i++) {
-			ret.add(1);
-			tmp[i] = 1;
-		}
-		for (int k = 2; k <= rowIndex; k++) {
-			int mid = k / 2;
-			for (int i = 1; i <= mid; i++) {
-				ret.set(i, tmp[i - 1] + tmp[i]);
-			}
-			for (int m = k; m > mid; m--) {
-				ret.set(m, ret.get(k - m));
-			}
-			for (int n = 0; n <= k; n++) {
-				tmp[n] = ret.get(n);
-			}
-		}
-		return ret;
-	}
+  public ArrayList<Integer> getRow(int rowIndex) {
+    ArrayList<Integer> ret = new ArrayList<Integer>();
+    int[] tmp = new int[rowIndex + 1];
+    for (int i = 0; i <= rowIndex; i++) {
+      ret.add(1);
+      tmp[i] = 1;
+    }
+    for (int k = 2; k <= rowIndex; k++) {
+      int mid = k / 2;
+      for (int i = 1; i <= mid; i++) {
+        ret.set(i, tmp[i - 1] + tmp[i]);
+      }
+      for (int m = k; m > mid; m--) {
+        ret.set(m, ret.get(k - m));
+      }
+      for (int n = 0; n <= k; n++) {
+        tmp[n] = ret.get(n);
+      }
+    }
+    return ret;
+  }
 }
diff --git a/PathSum.java b/PathSum.java
index c282c9b..cb5f921 100644
--- a/PathSum.java
+++ b/PathSum.java
@@ -1,30 +1,16 @@
-
-
-/** 
- * Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.
- * 
- * For example:
- * Given the below binary tree and sum = 22,
- *             5
- *            / \
- *           4   8
- *          /   / \
- *         11  13  4
- *        /  \      \
- *       7    2      1
+/**
+ * Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up
+ * all the values along the path equals the given sum.
+ *
+ * <p>For example: Given the below binary tree and sum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ \ 7 2 1
  * return true, as there exist a root-to-leaf path 5->4->11->2 which sum is 22.
  */
-
 public class PathSum {
-	public boolean hasPathSum(TreeNode root, int sum) {
-		if (root == null)
-			return false;
-		if (root.left == null && root.right == null && root.val == sum)
-			return true;
-		boolean l = root.left != null ? hasPathSum(root.left, sum - root.val)
-				: false;
-		boolean r = root.right != null ? hasPathSum(root.right, sum - root.val)
-				: false;
-		return l || r;
-	}
-}
\ No newline at end of file
+  public boolean hasPathSum(TreeNode root, int sum) {
+    if (root == null) return false;
+    if (root.left == null && root.right == null && root.val == sum) return true;
+    boolean l = root.left != null ? hasPathSum(root.left, sum - root.val) : false;
+    boolean r = root.right != null ? hasPathSum(root.right, sum - root.val) : false;
+    return l || r;
+  }
+}
diff --git a/PathSumII.java b/PathSumII.java
index 1325b54..0270c4e 100644
--- a/PathSumII.java
+++ b/PathSumII.java
@@ -1,53 +1,38 @@
-
-
 import java.util.ArrayList;
 
-/** 
- * Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.
+/**
+ * Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given
+ * sum.
  *
- * For example:
- * Given the below binary tree and sum = 22,
- *             5
- *            / \
- *           4   8
- *          /   / \
- *         11  13  4
- *        /  \    / \
- *       7    2  5   1
- * return
- * [
- *  [5,4,11,2],
- *  [5,8,4,5]
- * ]
+ * <p>For example: Given the below binary tree and sum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ / \ 7 2 5 1
+ * return [ [5,4,11,2], [5,8,4,5] ]
  */
-
 public class PathSumII {
-	public ArrayList<ArrayList<Integer>> pathSum(TreeNode root, int sum) {
-		ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>();
-		if (root != null) {
-			ArrayList<Integer> path = new ArrayList<Integer>();
-			findPathSum(root, sum, result, path);
-		}
-		return result;
-	}
+  public ArrayList<ArrayList<Integer>> pathSum(TreeNode root, int sum) {
+    ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>();
+    if (root != null) {
+      ArrayList<Integer> path = new ArrayList<Integer>();
+      findPathSum(root, sum, result, path);
+    }
+    return result;
+  }
 
-	public void findPathSum(TreeNode root, int sum,
-			ArrayList<ArrayList<Integer>> result, ArrayList<Integer> path) {
-		if (root == null)
-			return;
-		if (root.left == null && root.right == null && root.val == sum) {
-			ArrayList<Integer> clone = new ArrayList<Integer>(path);
-			clone.add(root.val);
-			result.add(clone);
-		} else {
-			path.add(root.val);
-			if (root.left != null) {
-				findPathSum(root.left, sum - root.val, result, path);
-			}
-			if (root.right != null) {
-				findPathSum(root.right, sum - root.val, result, path);
-			}
-			path.remove(path.size() - 1);
-		}
-	}
-}
\ No newline at end of file
+  public void findPathSum(
+      TreeNode root, int sum, ArrayList<ArrayList<Integer>> result, ArrayList<Integer> path) {
+    if (root == null) return;
+    if (root.left == null && root.right == null && root.val == sum) {
+      ArrayList<Integer> clone = new ArrayList<Integer>(path);
+      clone.add(root.val);
+      result.add(clone);
+    } else {
+      path.add(root.val);
+      if (root.left != null) {
+        findPathSum(root.left, sum - root.val, result, path);
+      }
+      if (root.right != null) {
+        findPathSum(root.right, sum - root.val, result, path);
+      }
+      path.remove(path.size() - 1);
+    }
+  }
+}
diff --git a/PermutationSequence.java b/PermutationSequence.java
index 9bc64d2..731e48c 100644
--- a/PermutationSequence.java
+++ b/PermutationSequence.java
@@ -1,37 +1,34 @@
 /**
- * The set [1,2,3,��,n] contains a total of n! unique permutations.
- * 
- * By listing and labeling all of the permutations in order, We get the
- * following sequence (ie, for n = 3):
- * 
- * "123" "132" "213" "231" "312" "321" Given n and k, return the kth permutation
- * sequence.
- * 
- * Note: Given n will be between 1 and 9 inclusive.
- * 
+ * The set [1,2,3,��,n] contains a total of n! unique permutations.
+ *
+ * <p>By listing and labeling all of the permutations in order, We get the following sequence (ie,
+ * for n = 3):
+ *
+ * <p>"123" "132" "213" "231" "312" "321" Given n and k, return the kth permutation sequence.
+ *
+ * <p>Note: Given n will be between 1 and 9 inclusive.
  */
-
 public class PermutationSequence {
-	public String getPermutation(int n, int k) {
-		char[] arr = new char[n];
-		int pro = 1;
-		for (int i = 0; i < n; ++i) {
-			arr[i] = (char) ('1' + i);
-			pro *= (i + 1);
-		}
-		k = k - 1;
-		k %= pro;
-		pro /= n;
-		for (int i = 0; i < n - 1; ++i) {
-			int selectI = k / pro;
-			k = k % pro;
-			pro /= (n - i - 1);
-			int temp = arr[selectI + i];
-			for (int j = selectI; j > 0; --j) {
-				arr[i + j] = arr[i + j - 1];
-			}
-			arr[i] = (char) temp;
-		}
-		return String.valueOf(arr);
-	}
+  public String getPermutation(int n, int k) {
+    char[] arr = new char[n];
+    int pro = 1;
+    for (int i = 0; i < n; ++i) {
+      arr[i] = (char) ('1' + i);
+      pro *= (i + 1);
+    }
+    k = k - 1;
+    k %= pro;
+    pro /= n;
+    for (int i = 0; i < n - 1; ++i) {
+      int selectI = k / pro;
+      k = k % pro;
+      pro /= (n - i - 1);
+      int temp = arr[selectI + i];
+      for (int j = selectI; j > 0; --j) {
+        arr[i + j] = arr[i + j - 1];
+      }
+      arr[i] = (char) temp;
+    }
+    return String.valueOf(arr);
+  }
 }
diff --git a/PermutationsII.java b/PermutationsII.java
index 84b2173..d02f9e4 100644
--- a/PermutationsII.java
+++ b/PermutationsII.java
@@ -1,52 +1,47 @@
-
-
 import java.util.ArrayList;
 
 /**
- * Given a collection of numbers that might contain duplicates, return all
- * possible unique permutations.
- * 
- * For example, [1,1,2] have the following unique permutations: 
- * [1,1,2], [1,2,1], and [2,1,1].
+ * Given a collection of numbers that might contain duplicates, return all possible unique
+ * permutations.
+ *
+ * <p>For example, [1,1,2] have the following unique permutations: [1,1,2], [1,2,1], and [2,1,1].
  */
-
 public class PermutationsII {
-	public ArrayList<ArrayList<Integer>> permuteUnique(int[] num) {
-		ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>();
-		permuteUnique(num, 0, result);
-		return result;
-	}
+  public ArrayList<ArrayList<Integer>> permuteUnique(int[] num) {
+    ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>();
+    permuteUnique(num, 0, result);
+    return result;
+  }
+
+  void permuteUnique(int[] num, int begin, ArrayList<ArrayList<Integer>> result) {
+    if (begin > num.length - 1) {
+      ArrayList<Integer> item = new ArrayList<Integer>();
+      for (int h = 0; h < num.length; h++) {
+        item.add(num[h]);
+      }
+      result.add(item);
+    }
+    for (int end = begin; end < num.length; end++) {
+      if (isSwap(num, begin, end)) {
+        swap(num, begin, end);
+        permuteUnique(num, begin + 1, result);
+        swap(num, begin, end);
+      }
+    }
+  }
 
-	void permuteUnique(int[] num, int begin,
-			ArrayList<ArrayList<Integer>> result) {
-		if (begin > num.length - 1) {
-			ArrayList<Integer> item = new ArrayList<Integer>();
-			for (int h = 0; h < num.length; h++) {
-				item.add(num[h]);
-			}
-			result.add(item);
-		}
-		for (int end = begin; end < num.length; end++) {
-			if (isSwap(num, begin, end)) {
-				swap(num, begin, end);
-				permuteUnique(num, begin + 1, result);
-				swap(num, begin, end);
-			}
-		}
-	}
+  boolean isSwap(int[] arr, int i, int j) {
+    for (int k = i; k < j; k++) {
+      if (arr[k] == arr[j]) {
+        return false;
+      }
+    }
+    return true;
+  }
 
-	boolean isSwap(int[] arr, int i, int j) {
-		for (int k = i; k < j; k++) {
-			if (arr[k] == arr[j]) {
-				return false;
-			}
-		}
-		return true;
-	}
-	
-	private void swap(int[] a, int i, int j) {
-		int tmp = a[i];
-		a[i] = a[j];
-		a[j] = tmp;
-	}
-}
\ No newline at end of file
+  private void swap(int[] a, int i, int j) {
+    int tmp = a[i];
+    a[i] = a[j];
+    a[j] = tmp;
+  }
+}
diff --git a/PlusOne.java b/PlusOne.java
index f5a649c..494b9f7 100644
--- a/PlusOne.java
+++ b/PlusOne.java
@@ -1,23 +1,19 @@
-/** 
- * Given a number represented as an array of digits, plus one to the number. 
- */
-
+/** Given a number represented as an array of digits, plus one to the number. */
 public class PlusOne {
-	public int[] plusOne(int[] digits) {
-		int length = digits.length;
-		int add = 1;
-		for (int i = length - 1; i >= 0; i--) {
-			int sum = digits[i] + add;
-			digits[i] = sum % 10;
-			add = sum / 10;
-			if (add == 0)
-				return digits;
-		}
-		int[] ret = new int[length + 1];
-		ret[0] = add;
-		for (int i = 0; i < length; i++) {
-			ret[i + 1] = digits[i];
-		}
-		return ret;
-	}
-}
\ No newline at end of file
+  public int[] plusOne(int[] digits) {
+    int length = digits.length;
+    int add = 1;
+    for (int i = length - 1; i >= 0; i--) {
+      int sum = digits[i] + add;
+      digits[i] = sum % 10;
+      add = sum / 10;
+      if (add == 0) return digits;
+    }
+    int[] ret = new int[length + 1];
+    ret[0] = add;
+    for (int i = 0; i < length; i++) {
+      ret[i + 1] = digits[i];
+    }
+    return ret;
+  }
+}
diff --git a/Point.java b/Point.java
index 591cd36..e413945 100644
--- a/Point.java
+++ b/Point.java
@@ -1,11 +1,9 @@
-
-
 public class Point {
-	public int x;
-	public int y;
+  public int x;
+  public int y;
 
-	public Point(int x, int y) {
-		this.x = x;
-		this.y = y;
-	}
-}
\ No newline at end of file
+  public Point(int x, int y) {
+    this.x = x;
+    this.y = y;
+  }
+}
diff --git a/PopulatingNextRightPointersinEachNode.java b/PopulatingNextRightPointersinEachNode.java
index 694c1ae..a839f6c 100644
--- a/PopulatingNextRightPointersinEachNode.java
+++ b/PopulatingNextRightPointersinEachNode.java
@@ -1,60 +1,42 @@
-
-
-/** 
+/**
  * Given a binary tree
  *
- *   struct TreeLinkNode {
- *     TreeLinkNode *left;
- *     TreeLinkNode *right;
- *     TreeLinkNode *next;
- *   }
- * Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL.
+ * <p>struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; } Populate
+ * each next pointer to point to its next right node. If there is no next right node, the next
+ * pointer should be set to NULL.
  *
- * Initially, all next pointers are set to NULL.
+ * <p>Initially, all next pointers are set to NULL.
  *
- * Note:
+ * <p>Note:
  *
- * You may only use constant extra space.
- * You may assume that it is a perfect binary tree (ie, all leaves are at the same level, and every parent has two children).
- * 
- * For example,
- * Given the following perfect binary tree,
- *        1
- *       /  \
- *      2    3
- *     / \  / \
- *    4  5  6  7
- * After calling your function, the tree should look like:
- *        1 -> NULL
- *       /  \
- *      2 -> 3 -> NULL
- *     / \  / \
- *    4->5->6->7 -> NULL
+ * <p>You may only use constant extra space. You may assume that it is a perfect binary tree (ie,
+ * all leaves are at the same level, and every parent has two children).
+ *
+ * <p>For example, Given the following perfect binary tree, 1 / \ 2 3 / \ / \ 4 5 6 7 After calling
+ * your function, the tree should look like: 1 -> NULL / \ 2 -> 3 -> NULL / \ / \ 4->5->6->7 -> NULL
  */
-
 public class PopulatingNextRightPointersinEachNode {
-	public void connect(TreeLinkNode root) {
-		if (root == null)
-			return;
-		TreeLinkNode curLevel = root;
-		TreeLinkNode cur = root;
-		curLevel.next = null;
-		while (true) {
-			while (cur != null) {
-				if (cur.left != null) {
-					cur.left.next = cur.right;
-					if (cur.next != null) {
-						cur.right.next = cur.next.left;
-					}
-				}
-				cur = cur.next;
-			}
-			if (curLevel.left != null) {
-				curLevel = curLevel.left;
-				cur = curLevel;
-			} else {
-				break;
-			}
-		}
-	}
-}
\ No newline at end of file
+  public void connect(TreeLinkNode root) {
+    if (root == null) return;
+    TreeLinkNode curLevel = root;
+    TreeLinkNode cur = root;
+    curLevel.next = null;
+    while (true) {
+      while (cur != null) {
+        if (cur.left != null) {
+          cur.left.next = cur.right;
+          if (cur.next != null) {
+            cur.right.next = cur.next.left;
+          }
+        }
+        cur = cur.next;
+      }
+      if (curLevel.left != null) {
+        curLevel = curLevel.left;
+        cur = curLevel;
+      } else {
+        break;
+      }
+    }
+  }
+}
diff --git a/PopulatingNextRightPointersinEachNodeII.java b/PopulatingNextRightPointersinEachNodeII.java
index c7e2dcb..d3c4073 100644
--- a/PopulatingNextRightPointersinEachNodeII.java
+++ b/PopulatingNextRightPointersinEachNodeII.java
@@ -1,59 +1,44 @@
 import java.util.ArrayList;
 import java.util.List;
 
-
-
-/** 
- * Populating Next Right Pointers in Each Node IIOct 28 '12
- * Follow up for problem "Populating Next Right Pointers in Each Node".
+/**
+ * Populating Next Right Pointers in Each Node IIOct 28 '12 Follow up for problem "Populating Next
+ * Right Pointers in Each Node".
  *
- * What if the given tree could be any binary tree? Would your previous solution still work?
+ * <p>What if the given tree could be any binary tree? Would your previous solution still work?
  *
- * Note:
+ * <p>Note:
  *
- * You may only use constant extra space.
- * For example,
- * Given the following binary tree,
- *        1
- *       /  \
- *      2    3
- *     / \    \
- *    4   5    7
- * After calling your function, the tree should look like:
- *        1 -> NULL
- *       /  \
- *      2 -> 3 -> NULL
- *     / \    \
- *    4-> 5 -> 7 -> NULL
+ * <p>You may only use constant extra space. For example, Given the following binary tree, 1 / \ 2 3
+ * / \ \ 4 5 7 After calling your function, the tree should look like: 1 -> NULL / \ 2 -> 3 -> NULL
+ * / \ \ 4-> 5 -> 7 -> NULL
  */
-	
 public class PopulatingNextRightPointersinEachNodeII {
-	public void connect(TreeLinkNode root) {
-		if (root == null)
-			return;
-		TreeLinkNode curLevel = root, cur = root;
-		curLevel.next = null;
-		List<TreeLinkNode> nextLevelNodes = new ArrayList<TreeLinkNode>();
-		while (true) {
-			while (cur != null) {
-				if (cur.left != null) {
-					nextLevelNodes.add(cur.left);
-				}
-				if (cur.right != null) {
-					nextLevelNodes.add(cur.right);
-				}
-				cur = cur.next;
-			}
-			for (int i = 0; i < nextLevelNodes.size() - 1; i++) {
-				nextLevelNodes.get(i).next = nextLevelNodes.get(i + 1);
-			}
-			if (nextLevelNodes.size() > 0) {
-				curLevel = nextLevelNodes.get(0);
-				cur = curLevel;
-				nextLevelNodes.clear();
-			} else {
-				break;
-			}
-		}
-	}
-}
\ No newline at end of file
+  public void connect(TreeLinkNode root) {
+    if (root == null) return;
+    TreeLinkNode curLevel = root, cur = root;
+    curLevel.next = null;
+    List<TreeLinkNode> nextLevelNodes = new ArrayList<TreeLinkNode>();
+    while (true) {
+      while (cur != null) {
+        if (cur.left != null) {
+          nextLevelNodes.add(cur.left);
+        }
+        if (cur.right != null) {
+          nextLevelNodes.add(cur.right);
+        }
+        cur = cur.next;
+      }
+      for (int i = 0; i < nextLevelNodes.size() - 1; i++) {
+        nextLevelNodes.get(i).next = nextLevelNodes.get(i + 1);
+      }
+      if (nextLevelNodes.size() > 0) {
+        curLevel = nextLevelNodes.get(0);
+        cur = curLevel;
+        nextLevelNodes.clear();
+      } else {
+        break;
+      }
+    }
+  }
+}
diff --git a/PowXN.java b/PowXN.java
index 025f76c..586235c 100644
--- a/PowXN.java
+++ b/PowXN.java
@@ -1,22 +1,16 @@
-
-
-/** 
- * Implement pow(x, n) 
- */
-
+/** Implement pow(x, n) */
 public class PowXN {
-	public double pow(double x, int n) {
-		if (n == 0)
-			return 1;
-		else if (n % 2 == 0) {
-			double d = pow(x, n / 2);
-			return d * d;
-		} else if (n > 0) {
-			double d = pow(x, (n - 1) / 2);
-			return d * d * x;
-		} else {
-			double d = pow(x, (n + 1) / 2);
-			return d * d / x;
-		}
-	}
-}
\ No newline at end of file
+  public double pow(double x, int n) {
+    if (n == 0) return 1;
+    else if (n % 2 == 0) {
+      double d = pow(x, n / 2);
+      return d * d;
+    } else if (n > 0) {
+      double d = pow(x, (n - 1) / 2);
+      return d * d * x;
+    } else {
+      double d = pow(x, (n + 1) / 2);
+      return d * d / x;
+    }
+  }
+}
diff --git a/RandomListNode.java b/RandomListNode.java
index 8b225f5..8936c94 100644
--- a/RandomListNode.java
+++ b/RandomListNode.java
@@ -1,10 +1,8 @@
-
-
 class RandomListNode {
-	int label;
-	RandomListNode next, random;
+  int label;
+  RandomListNode next, random;
 
-	RandomListNode(int x) {
-		this.label = x;
-	}
-}
\ No newline at end of file
+  RandomListNode(int x) {
+    this.label = x;
+  }
+}
diff --git a/ReconstructItinerary.java b/ReconstructItinerary.java
new file mode 100644
index 0000000..788d3b3
--- /dev/null
+++ b/ReconstructItinerary.java
@@ -0,0 +1,62 @@
+Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], reconstruct the itinerary in order. All of the tickets belong to a man who departs from JFK. Thus, the itinerary must begin with JFK.
+
+Note:
+
+If there are multiple valid itineraries, you should return the itinerary that has the smallest lexical order when read as a single string. For example, the itinerary ["JFK", "LGA"] has a smaller lexical order than ["JFK", "LGB"].
+All airports are represented by three capital letters (IATA code).
+You may assume all tickets form at least one valid itinerary.
+Example 1:
+
+Input: [["MUC", "LHR"], ["JFK", "MUC"], ["SFO", "SJC"], ["LHR", "SFO"]]
+Output: ["JFK", "MUC", "LHR", "SFO", "SJC"]
+Example 2:
+
+Input: [["JFK","SFO"],["JFK","ATL"],["SFO","ATL"],["ATL","JFK"],["ATL","SFO"]]
+Output: ["JFK","ATL","JFK","SFO","ATL","SFO"]
+Explanation: Another possible reconstruction is ["JFK","SFO","ATL","JFK","ATL","SFO"].
+             But it is larger in lexical order.
+
+class Solution {
+    
+    public List<String> findItinerary(String[][] tickets) {
+        Set<String> set = new HashSet<>();
+        int col = tickets.length;
+        for (int i = 0; i < col; i++) {
+            set.add(tickets[i][0]);
+            set.add(tickets[i][1]);
+        }
+        String[] airports = set.toArray(new String[0]);
+        Arrays.sort(airports);
+        Map<String, Integer> indexs = new HashMap<>();
+        for (int i = 0; i < airports.length; i++) {
+            indexs.put(airports[i], i);
+        }
+        int[][] m = new int[set.size()][set.size()];
+        for (int i = 0; i < col; i++) {
+            m[indexs.get(tickets[i][0])][indexs.get(tickets[i][1])] += 1;
+        }
+        List<String> sol = new ArrayList<>();
+        sol.add("JFK");
+        find(m, "JFK", sol, indexs, airports, tickets.length);
+        return sol;
+    }
+
+    private boolean find(
+        int[][] m, String airport, List<String> sol, Map<String, Integer> indexs, String[] airports, int count) {
+        if (count == 0) return true;
+        int row = indexs.get(airport);
+        for (int i = 0; i < m.length; i++) {
+            if (m[row][i] > 0) {
+                m[row][i] -= 1;
+                sol.add(airports[i]);
+                boolean ret = find(m, airports[i], sol, indexs, airports, count - 1);
+                if (ret) {
+                    return true;
+                }
+                sol.remove(sol.size() - 1);
+                m[row][i] += 1;
+            }
+        }
+        return false;
+    }
+}
\ No newline at end of file
diff --git a/RecoverBinarySearchTree.java b/RecoverBinarySearchTree.java
index 38bb16a..a3ae4ca 100644
--- a/RecoverBinarySearchTree.java
+++ b/RecoverBinarySearchTree.java
@@ -1,50 +1,45 @@
-
-
 import java.util.ArrayList;
 
 /**
  * Two elements of a binary search tree (BST) are swapped by mistake.
  *
- * Recover the tree without changing its structure.
+ * <p>Recover the tree without changing its structure.
  *
- * Note:
- * 
- * A solution using O(n) space is pretty straight forward. Could you devise a constant space solution?
+ * <p>Note:
+ *
+ * <p>A solution using O(n) space is pretty straight forward. Could you devise a constant space
+ * solution?
  */
-
 public class RecoverBinarySearchTree {
-	public void recoverTree(TreeNode root) {
-		if (root == null)
-			return;
-		ArrayList<TreeNode> nodes = new ArrayList<TreeNode>();
-		findWrongNode(root, nodes);
-		TreeNode a = null, b = null;
-		int i = 0;
-		for (i = 0; i < nodes.size() - 1; i++) {
-			if (nodes.get(i).val > nodes.get(i + 1).val) {
-				a = nodes.get(i);
-				break;
-			}
-		}
-		for (int j = i + 1; j < nodes.size() - 1; j++) {
-			if (nodes.get(j).val > nodes.get(j + 1).val) {
-				b = nodes.get(j + 1);
-				break;
-			}
-		}
-		if (b == null)
-			b = nodes.get(i + 1);
+  public void recoverTree(TreeNode root) {
+    if (root == null) return;
+    ArrayList<TreeNode> nodes = new ArrayList<TreeNode>();
+    findWrongNode(root, nodes);
+    TreeNode a = null, b = null;
+    int i = 0;
+    for (i = 0; i < nodes.size() - 1; i++) {
+      if (nodes.get(i).val > nodes.get(i + 1).val) {
+        a = nodes.get(i);
+        break;
+      }
+    }
+    for (int j = i + 1; j < nodes.size() - 1; j++) {
+      if (nodes.get(j).val > nodes.get(j + 1).val) {
+        b = nodes.get(j + 1);
+        break;
+      }
+    }
+    if (b == null) b = nodes.get(i + 1);
 
-		int t = a.val;
-		a.val = b.val;
-		b.val = t;
-	}
+    int t = a.val;
+    a.val = b.val;
+    b.val = t;
+  }
 
-	private void findWrongNode(TreeNode root, ArrayList<TreeNode> nodes) {
-		if (root == null)
-			return;
-		findWrongNode(root.left, nodes);
-		nodes.add(root);
-		findWrongNode(root.right, nodes);
-	}
-}
\ No newline at end of file
+  private void findWrongNode(TreeNode root, ArrayList<TreeNode> nodes) {
+    if (root == null) return;
+    findWrongNode(root.left, nodes);
+    nodes.add(root);
+    findWrongNode(root.right, nodes);
+  }
+}
diff --git a/RegularExpressionMatching.java b/RegularExpressionMatching.java
index d29f7c3..2e5595c 100644
--- a/RegularExpressionMatching.java
+++ b/RegularExpressionMatching.java
@@ -1,43 +1,35 @@
 /**
  * Implement regular expression matching with support for '.' and '*'.
- * 
- * '.' Matches any single character.
- * '*' Matches zero or more of the preceding element.
- * 
- * The matching should cover the entire input string (not partial).
- * 
- * The function prototype should be:
- * bool isMatch(const char *s, const char *p)
- * 
- * Some examples:
- * isMatch("aa","a") -> false
- * isMatch("aa","aa") -> true
- * isMatch("aaa","aa") -> false
- * isMatch("aa", "a*") -> true
- * isMatch("aa", ".*") -> true
- * isMatch("ab", ".*") -> true
- * isMatch("aab", "c*a*b") -> true
  *
+ * <p>'.' Matches any single character. '*' Matches zero or more of the preceding element.
+ *
+ * <p>The matching should cover the entire input string (not partial).
+ *
+ * <p>The function prototype should be: bool isMatch(const char *s, const char *p)
+ *
+ * <p>Some examples: isMatch("aa","a") -> false isMatch("aa","aa") -> true isMatch("aaa","aa") ->
+ * false isMatch("aa", "a*") -> true isMatch("aa", ".*") -> true isMatch("ab", ".*") -> true
+ * isMatch("aab", "c*a*b") -> true
  */
 public class RegularExpressionMatching {
-	public boolean isMatch(String s, String p) {
-		return isMatch(s, 0, p, 0);
-	}
+  public boolean isMatch(String s, String p) {
+    return isMatch(s, 0, p, 0);
+  }
 
-	private boolean isMatch(String s, int i, String p, int j) {
-		int ls = s.length();
-		int lp = p.length();
-		if (j == lp) {
-			return i == ls;
-		}
-		if ((j < lp - 1 && p.charAt(j + 1) != '*') || j == lp - 1) {
-			return (i < ls && s.charAt(i) == p.charAt(j) || p.charAt(j) == '.') && isMatch(s, i + 1, p, j + 1);
-		}
-		while ((i < ls && s.charAt(i) == p.charAt(j)) || (p.charAt(j) == '.' && i < ls)) {
-			if (isMatch(s, i, p, j + 2))
-				return true;
-			i++;
-		}
-		return isMatch(s, i, p, j + 2);
-	}
+  private boolean isMatch(String s, int i, String p, int j) {
+    int ls = s.length();
+    int lp = p.length();
+    if (j == lp) {
+      return i == ls;
+    }
+    if ((j < lp - 1 && p.charAt(j + 1) != '*') || j == lp - 1) {
+      return (i < ls && s.charAt(i) == p.charAt(j) || p.charAt(j) == '.')
+          && isMatch(s, i + 1, p, j + 1);
+    }
+    while ((i < ls && s.charAt(i) == p.charAt(j)) || (p.charAt(j) == '.' && i < ls)) {
+      if (isMatch(s, i, p, j + 2)) return true;
+      i++;
+    }
+    return isMatch(s, i, p, j + 2);
+  }
 }
diff --git a/RemoveDuplicatesFromSortedArrayII.java b/RemoveDuplicatesFromSortedArrayII.java
index bb9f49b..a82b0ca 100644
--- a/RemoveDuplicatesFromSortedArrayII.java
+++ b/RemoveDuplicatesFromSortedArrayII.java
@@ -1,37 +1,35 @@
 /**
  * Follow up for "Remove Duplicates": What if duplicates are allowed at most twice?
- * 
- * For example,
- * 
- * Given sorted array A = [1,1,1,2,2,3],
- * 
- * Your function should return length = 5, and A is now [1,1,2,2,3].
  *
+ * <p>For example,
+ *
+ * <p>Given sorted array A = [1,1,1,2,2,3],
+ *
+ * <p>Your function should return length = 5, and A is now [1,1,2,2,3].
  */
 public class RemoveDuplicatesFromSortedArrayII {
-	public int removeDuplicates(int[] A) {
-		int length = A.length;
-		if (length < 3)
-			return length;
-		int slow = 0, fast = 1, idx = 0;
-		while (fast < length) {
-			while (fast < length && A[fast] == A[slow]) {
-				fast++;
-			}
-			if (fast - slow <= 2) {
-				while (slow < fast) {
-					A[idx++] = A[slow++];
-				}
-			} else {
-				A[idx++] = A[slow++];
-				A[idx++] = A[slow++];
-				slow = fast;
-			}
-			fast++;
-		}
-		while (slow < length) {
-			A[idx++] = A[slow++];
-		}
-		return idx;
-	}
-}
\ No newline at end of file
+  public int removeDuplicates(int[] A) {
+    int length = A.length;
+    if (length < 3) return length;
+    int slow = 0, fast = 1, idx = 0;
+    while (fast < length) {
+      while (fast < length && A[fast] == A[slow]) {
+        fast++;
+      }
+      if (fast - slow <= 2) {
+        while (slow < fast) {
+          A[idx++] = A[slow++];
+        }
+      } else {
+        A[idx++] = A[slow++];
+        A[idx++] = A[slow++];
+        slow = fast;
+      }
+      fast++;
+    }
+    while (slow < length) {
+      A[idx++] = A[slow++];
+    }
+    return idx;
+  }
+}
diff --git a/RemoveDuplicatesfromSortedArray.java b/RemoveDuplicatesfromSortedArray.java
index adbab54..20b0c89 100644
--- a/RemoveDuplicatesfromSortedArray.java
+++ b/RemoveDuplicatesfromSortedArray.java
@@ -1,33 +1,27 @@
-
-
 /**
- * Given a sorted array, remove the duplicates in place such that each element
- * appear only once and return the new length.
- * 
- * Do not allocate extra space for another array, you must do this in place with
- * constant memory.
- * 
- * For example, Given input array A = [1,1,2],
- * 
- * Your function should return length = 2, and A is now [1,2].
+ * Given a sorted array, remove the duplicates in place such that each element appear only once and
+ * return the new length.
+ *
+ * <p>Do not allocate extra space for another array, you must do this in place with constant memory.
+ *
+ * <p>For example, Given input array A = [1,1,2],
+ *
+ * <p>Your function should return length = 2, and A is now [1,2].
  */
-
 public class RemoveDuplicatesfromSortedArray {
-	public int removeDuplicates(int[] A) {
-		if (A.length == 0)
-			return 0;
-		else if (A.length == 1)
-			return 1;
-		else {
-			int ret = 1;
-			int p = 0;
-			for (int p1 = 1; p1 < A.length; p1++) {
-				if (A[p1 - 1] != A[p1]) {
-					ret++;
-					A[++p] = A[p1];
-				}
-			}
-			return ret;
-		}
-	}
-}
\ No newline at end of file
+  public int removeDuplicates(int[] A) {
+    if (A.length == 0) return 0;
+    else if (A.length == 1) return 1;
+    else {
+      int ret = 1;
+      int p = 0;
+      for (int p1 = 1; p1 < A.length; p1++) {
+        if (A[p1 - 1] != A[p1]) {
+          ret++;
+          A[++p] = A[p1];
+        }
+      }
+      return ret;
+    }
+  }
+}
diff --git a/RemoveDuplicatesfromSortedList.java b/RemoveDuplicatesfromSortedList.java
index 70bca58..38dc38d 100644
--- a/RemoveDuplicatesfromSortedList.java
+++ b/RemoveDuplicatesfromSortedList.java
@@ -1,30 +1,24 @@
-
-
-/** 
+/**
  * Given a sorted linked list, delete all duplicates such that each element appear only once.
  *
- * For example,
- * Given 1->1->2, return 1->2.
- * Given 1->1->2->3->3, return 1->2->3.
+ * <p>For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2->3.
  */
-
 public class RemoveDuplicatesfromSortedList {
-	public ListNode deleteDuplicates(ListNode head) {
-		if (head == null)
-			return head;
-		int cur = head.val;
-		ListNode p = head.next;
-		ListNode prev = head;
-		while (p != null) {
-			if (p.val == cur) {
-				prev.next = p.next;
-				p = prev.next;
-			} else {
-				cur = p.val;
-				prev = prev.next;
-				p = p.next;
-			}
-		}
-		return head;
-	}
-}
\ No newline at end of file
+  public ListNode deleteDuplicates(ListNode head) {
+    if (head == null) return head;
+    int cur = head.val;
+    ListNode p = head.next;
+    ListNode prev = head;
+    while (p != null) {
+      if (p.val == cur) {
+        prev.next = p.next;
+        p = prev.next;
+      } else {
+        cur = p.val;
+        prev = prev.next;
+        p = p.next;
+      }
+    }
+    return head;
+  }
+}
diff --git a/RemoveDuplicatesfromSortedListII.java b/RemoveDuplicatesfromSortedListII.java
index 67253fd..27c9d40 100644
--- a/RemoveDuplicatesfromSortedListII.java
+++ b/RemoveDuplicatesfromSortedListII.java
@@ -1,32 +1,29 @@
 /**
- * Given a sorted linked list, delete all nodes that have duplicate numbers,
- * leaving only distinct numbers from the original list.
- * 
- * For example, Given 1->2->3->3->4->4->5, return 1->2->5. Given 1->1->1->2->3,
- * return 2->3.
+ * Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct
+ * numbers from the original list.
+ *
+ * <p>For example, Given 1->2->3->3->4->4->5, return 1->2->5. Given 1->1->1->2->3, return 2->3.
  */
-
 public class RemoveDuplicatesfromSortedListII {
-	public ListNode deleteDuplicates(ListNode head) {
-		if (head == null)
-			return head;
-		ListNode start = new ListNode(0);
-		start.next = head;
-		ListNode slow = start;
-		ListNode fast = head;
-		while (fast.next != null) {
-			if (slow.next.val != fast.next.val) {
-				if (slow.next.next == fast.next) {
-					slow = slow.next;
-				} else {
-					slow.next = fast.next;
-				}
-			}
-			fast = fast.next;
-		}
-		if (slow.next.next != fast.next) {
-			slow.next = fast.next;
-		}
-		return start.next;
-	}
-}
\ No newline at end of file
+  public ListNode deleteDuplicates(ListNode head) {
+    if (head == null) return head;
+    ListNode start = new ListNode(0);
+    start.next = head;
+    ListNode slow = start;
+    ListNode fast = head;
+    while (fast.next != null) {
+      if (slow.next.val != fast.next.val) {
+        if (slow.next.next == fast.next) {
+          slow = slow.next;
+        } else {
+          slow.next = fast.next;
+        }
+      }
+      fast = fast.next;
+    }
+    if (slow.next.next != fast.next) {
+      slow.next = fast.next;
+    }
+    return start.next;
+  }
+}
diff --git a/RemoveElement.java b/RemoveElement.java
index 1131f2d..d865f90 100644
--- a/RemoveElement.java
+++ b/RemoveElement.java
@@ -1,25 +1,20 @@
-
-
 /**
- * Given an array and a value, remove all instances of that value in place and
- * return the new length.
- * 
- * The order of elements can be changed. It doesn't matter what you leave beyond
- * the new length.
+ * Given an array and a value, remove all instances of that value in place and return the new
+ * length.
+ *
+ * <p>The order of elements can be changed. It doesn't matter what you leave beyond the new length.
  */
-
 public class RemoveElement {
-	public int removeElement(int[] A, int elem) {
-		if (A.length == 0)
-			return 0;
-		else {
-			int p = 0;
-			for (int i = 0; i < A.length; i++) {
-				if (A[i] != elem) {
-					A[p++] = A[i];
-				}
-			}
-			return p;
-		}
-	}
-}
\ No newline at end of file
+  public int removeElement(int[] A, int elem) {
+    if (A.length == 0) return 0;
+    else {
+      int p = 0;
+      for (int i = 0; i < A.length; i++) {
+        if (A[i] != elem) {
+          A[p++] = A[i];
+        }
+      }
+      return p;
+    }
+  }
+}
diff --git a/RemoveNthNodeFromEndofList.java b/RemoveNthNodeFromEndofList.java
index 8ae7612..7685a15 100644
--- a/RemoveNthNodeFromEndofList.java
+++ b/RemoveNthNodeFromEndofList.java
@@ -1,33 +1,28 @@
-
-
-/** 
+/**
  * Given a linked list, remove the nth node from the end of list and return its head.
  *
- * For example,
+ * <p>For example,
  *
- * Given linked list: 1->2->3->4->5, and n = 2.
+ * <p>Given linked list: 1->2->3->4->5, and n = 2.
  *
- * After removing the second node from the end, the linked list becomes 1->2->3->5.
- * 
- * Note:
- * Given n will always be valid.
- * Try to do this in one pass.
+ * <p>After removing the second node from the end, the linked list becomes 1->2->3->5.
+ *
+ * <p>Note: Given n will always be valid. Try to do this in one pass.
  */
-
 public class RemoveNthNodeFromEndofList {
-	public ListNode removeNthFromEnd(ListNode head, int n) {
-        ListNode root = new ListNode(0);
-        ListNode fast = root;
-        ListNode slow = root;
-        root.next = head;
-        for (int i = 0; i < n; i++) {
-            fast = fast.next;
-        }
-        while (fast.next != null) {
-            fast = fast.next;
-            slow = slow.next;
-        }
-        slow.next = slow.next.next;
-        return root.next;
+  public ListNode removeNthFromEnd(ListNode head, int n) {
+    ListNode root = new ListNode(0);
+    ListNode fast = root;
+    ListNode slow = root;
+    root.next = head;
+    for (int i = 0; i < n; i++) {
+      fast = fast.next;
+    }
+    while (fast.next != null) {
+      fast = fast.next;
+      slow = slow.next;
     }
-}
\ No newline at end of file
+    slow.next = slow.next.next;
+    return root.next;
+  }
+}
diff --git a/RemoveSuperInterval.java b/RemoveSuperInterval.java
index e88b1ca..d8a51ce 100644
--- a/RemoveSuperInterval.java
+++ b/RemoveSuperInterval.java
@@ -3,31 +3,31 @@
 import java.util.Comparator;
 
 public class RemoveSuperInterval {
-	public class IntervalCmp implements Comparator<Interval> {
-		@Override
-		public int compare(Interval i1, Interval i2) {
-			if (i1.start < i2.start) return -1;
-			if (i1.start == i2.start && i1.end >= i2.end) return -1;
-			return 1;
-		}
-	}
-	
-	public ArrayList<Interval> merge(ArrayList<Interval> intervals) {
-		ArrayList<Interval> ret = new ArrayList<Interval>();
-		if (intervals.size() == 0) return ret;
-		Interval[] arr = new Interval[intervals.size()];
-		intervals.toArray(arr);
-		Arrays.sort(arr, new IntervalCmp());
-		int start = arr[arr.length - 1].start;
-		int end = arr[arr.length - 1].end;
-		for (int i = arr.length - 2; i >= 0; i--) {
-			if (arr[i].end < end) {
-				ret.add(new Interval(start, end));
-				start = arr[i].start;
-				end = arr[i].end;
-			}
-		}
-		ret.add(new Interval(start, end));
-		return ret;
-	}
-}
\ No newline at end of file
+  public class IntervalCmp implements Comparator<Interval> {
+    @Override
+    public int compare(Interval i1, Interval i2) {
+      if (i1.start < i2.start) return -1;
+      if (i1.start == i2.start && i1.end >= i2.end) return -1;
+      return 1;
+    }
+  }
+
+  public ArrayList<Interval> merge(ArrayList<Interval> intervals) {
+    ArrayList<Interval> ret = new ArrayList<Interval>();
+    if (intervals.size() == 0) return ret;
+    Interval[] arr = new Interval[intervals.size()];
+    intervals.toArray(arr);
+    Arrays.sort(arr, new IntervalCmp());
+    int start = arr[arr.length - 1].start;
+    int end = arr[arr.length - 1].end;
+    for (int i = arr.length - 2; i >= 0; i--) {
+      if (arr[i].end < end) {
+        ret.add(new Interval(start, end));
+        start = arr[i].start;
+        end = arr[i].end;
+      }
+    }
+    ret.add(new Interval(start, end));
+    return ret;
+  }
+}
diff --git a/ReorderList.java b/ReorderList.java
index 332e337..36c68fc 100644
--- a/ReorderList.java
+++ b/ReorderList.java
@@ -1,67 +1,62 @@
-
-
 /**
- * Given a singly linked list L: L0->L1->...->Ln-1->Ln,
- * reorder it to: L0->Ln->L1->Ln-1->L2->Ln-2->...
- * 
- * You must do this in-place without altering the nodes' values.
- * 
- * For example, Given {1,2,3,4}, reorder it to {1,4,2,3}.
- * 
+ * Given a singly linked list L: L0->L1->...->Ln-1->Ln, reorder it to:
+ * L0->Ln->L1->Ln-1->L2->Ln-2->...
+ *
+ * <p>You must do this in-place without altering the nodes' values.
+ *
+ * <p>For example, Given {1,2,3,4}, reorder it to {1,4,2,3}.
  */
-
 public class ReorderList {
-	public void reorderList(ListNode head) {
-		if (head == null || head.next == null)
-			return;
-		ListNode fast = head;
-		ListNode late = head;
-		while (fast.next != null && fast.next.next != null) {
-			fast = fast.next.next;
-			late = late.next;
-		}
-		ListNode ret = new ListNode(0);
-		ListNode cur = ret;
-		ListNode leftHalf = head;
-		ListNode rightHalf;
-		if (fast.next != null) {
-			rightHalf = reverseList(late.next);
-			late.next = null;
-		} else {
-			rightHalf = reverseList(late);
-			ListNode tmp = head;
-			while (tmp.next != late) {
-				tmp = tmp.next;
-			}
-			tmp.next = null;
-		}
-		leftHalf = head;
-		while (leftHalf != null && rightHalf != null) {
-			cur.next = leftHalf;
-			leftHalf = leftHalf.next;
-			cur = cur.next;
-			cur.next = rightHalf;
-			rightHalf = rightHalf.next;
-			cur = cur.next;
-		}
-		if (leftHalf != null) {
-			cur.next = leftHalf;
-		} else if (rightHalf != null) {
-			cur.next = rightHalf;
-		}
-		head = ret.next;
-	}
+  public void reorderList(ListNode head) {
+    if (head == null || head.next == null) return;
+    ListNode fast = head;
+    ListNode late = head;
+    while (fast.next != null && fast.next.next != null) {
+      fast = fast.next.next;
+      late = late.next;
+    }
+    ListNode ret = new ListNode(0);
+    ListNode cur = ret;
+    ListNode leftHalf = head;
+    ListNode rightHalf;
+    if (fast.next != null) {
+      rightHalf = reverseList(late.next);
+      late.next = null;
+    } else {
+      rightHalf = reverseList(late);
+      ListNode tmp = head;
+      while (tmp.next != late) {
+        tmp = tmp.next;
+      }
+      tmp.next = null;
+    }
+    leftHalf = head;
+    while (leftHalf != null && rightHalf != null) {
+      cur.next = leftHalf;
+      leftHalf = leftHalf.next;
+      cur = cur.next;
+      cur.next = rightHalf;
+      rightHalf = rightHalf.next;
+      cur = cur.next;
+    }
+    if (leftHalf != null) {
+      cur.next = leftHalf;
+    } else if (rightHalf != null) {
+      cur.next = rightHalf;
+    }
+    head = ret.next;
+  }
 
-	private ListNode reverseList(ListNode head) {
-		ListNode cur = head;
-		ListNode prev = null;
-		ListNode next = null;
-		while (cur != null) {
-			next = cur.next;
-			cur.next = prev;
-			prev = cur;
-			cur = next;
-		}
-		return prev;
-	}
-}
\ No newline at end of file
+  private ListNode reverseList(ListNode head) {
+    ListNode cur = head;
+    ListNode prev = null;
+    ListNode next = null;
+    while (cur != null) {
+      next = cur.next;
+      cur.next = prev;
+      prev = cur;
+      cur = next;
+    }
+    return prev;
+  }
+}
diff --git a/RestoreIPAddresses.java b/RestoreIPAddresses.java
index a014975..a1e5bf8 100644
--- a/RestoreIPAddresses.java
+++ b/RestoreIPAddresses.java
@@ -1,54 +1,49 @@
-
-
 import java.util.ArrayList;
 
 /**
- * Given a string containing only digits, restore it by returning all possible
- * valid IP address combinations.
- * 
- * For example: Given "25525511135",
- * 
- * return ["255.255.11.135", "255.255.111.35"]. (Order does not matter)
+ * Given a string containing only digits, restore it by returning all possible valid IP address
+ * combinations.
+ *
+ * <p>For example: Given "25525511135",
+ *
+ * <p>return ["255.255.11.135", "255.255.111.35"]. (Order does not matter)
  */
-
 public class RestoreIPAddresses {
-	public ArrayList<String> restoreIpAddresses(String s) {
-		ArrayList<String> ips = new ArrayList<String>();
-		StringBuffer sb = new StringBuffer();
-		restoreIpAddresses(s, 0, ips, sb, 0);
-		return ips;
-	}
+  public ArrayList<String> restoreIpAddresses(String s) {
+    ArrayList<String> ips = new ArrayList<String>();
+    StringBuffer sb = new StringBuffer();
+    restoreIpAddresses(s, 0, ips, sb, 0);
+    return ips;
+  }
 
-	private void restoreIpAddresses(String s, int i, ArrayList<String> ips,
-			StringBuffer ip, int step) {
-		if ((step >= 4 && i < s.length()) || (step < 4 && i >= s.length()))
-			return;
-		if (step >= 4 && i >= s.length()) {
-			ips.add(ip.substring(0, ip.length() - 1));
-		} else {
-			if (s.charAt(i) == '0') {
-				ip.append('0');
-				ip.append('.');
-				restoreIpAddresses(s, i + 1, ips, ip, step + 1);
-				ip.deleteCharAt(ip.length() - 1);
-				ip.deleteCharAt(ip.length() - 1);
-			} else {
-				for (int j = 1; j <= 3 && i + j <= s.length(); j++) {
-					StringBuffer nextSeg = new StringBuffer();
-					nextSeg.append(s.substring(i, i + j));
-					int n = Integer.parseInt(nextSeg.toString());
-					if (n > 0 && n <= 255) {
-						ip.append(nextSeg.toString());
-						ip.append('.');
-						restoreIpAddresses(s, i + j, ips, ip, step + 1);
-						ip.deleteCharAt(ip.length() - 1);
-						for (int k = 0; k < nextSeg.length(); k++)
-							ip.deleteCharAt(ip.length() - 1);
-					} else {
-						break;
-					}
-				}
-			}
-		}
-	}
-}
\ No newline at end of file
+  private void restoreIpAddresses(
+      String s, int i, ArrayList<String> ips, StringBuffer ip, int step) {
+    if ((step >= 4 && i < s.length()) || (step < 4 && i >= s.length())) return;
+    if (step >= 4 && i >= s.length()) {
+      ips.add(ip.substring(0, ip.length() - 1));
+    } else {
+      if (s.charAt(i) == '0') {
+        ip.append('0');
+        ip.append('.');
+        restoreIpAddresses(s, i + 1, ips, ip, step + 1);
+        ip.deleteCharAt(ip.length() - 1);
+        ip.deleteCharAt(ip.length() - 1);
+      } else {
+        for (int j = 1; j <= 3 && i + j <= s.length(); j++) {
+          StringBuffer nextSeg = new StringBuffer();
+          nextSeg.append(s.substring(i, i + j));
+          int n = Integer.parseInt(nextSeg.toString());
+          if (n > 0 && n <= 255) {
+            ip.append(nextSeg.toString());
+            ip.append('.');
+            restoreIpAddresses(s, i + j, ips, ip, step + 1);
+            ip.deleteCharAt(ip.length() - 1);
+            for (int k = 0; k < nextSeg.length(); k++) ip.deleteCharAt(ip.length() - 1);
+          } else {
+            break;
+          }
+        }
+      }
+    }
+  }
+}
diff --git a/ReverseInteger.java b/ReverseInteger.java
index f6c4c01..ad74c38 100644
--- a/ReverseInteger.java
+++ b/ReverseInteger.java
@@ -1,36 +1,30 @@
-
-
 /**
  * Reverse digits of an integer.
- * 
- * Example1: x = 123, return 321 Example2: x = -123, return -321
- * 
- * Have you thought about this? Here are some good questions to ask before
- * coding. Bonus points for you if you have already thought through this!
- * 
- * If the integer's last digit is 0, what should the output be? ie, cases such
- * as 10, 100.
- * 
- * Did you notice that the reversed integer might overflow? Assume the input is
- * a 32-bit integer, then the reverse of 1000000003 overflows. How should you
- * handle such cases?
- * 
- * Throw an exception? Good, but what if throwing an exception is not an option?
- * You would then have to re-design the function (ie, add an extra parameter).
+ *
+ * <p>Example1: x = 123, return 321 Example2: x = -123, return -321
+ *
+ * <p>Have you thought about this? Here are some good questions to ask before coding. Bonus points
+ * for you if you have already thought through this!
+ *
+ * <p>If the integer's last digit is 0, what should the output be? ie, cases such as 10, 100.
+ *
+ * <p>Did you notice that the reversed integer might overflow? Assume the input is a 32-bit integer,
+ * then the reverse of 1000000003 overflows. How should you handle such cases?
+ *
+ * <p>Throw an exception? Good, but what if throwing an exception is not an option? You would then
+ * have to re-design the function (ie, add an extra parameter).
  */
-
 public class ReverseInteger {
-	public int reverse(int x) {
-		int num = Math.abs(x);
-		int ret = 0;
-		while (num != 0) {
-			int d = num - num / 10 * 10;
-			ret = ret * 10 + d;
-			num /= 10;
-		}
-		if (x < 0)
-			return -ret;
-		else
-			return ret;
-	}
-}
\ No newline at end of file
+  public int reverse(int x) {
+    long l = x;
+    long num = Math.abs(l);
+    long ret = 0;
+    while (num != 0) {
+      long d = num - num / 10 * 10;
+      ret = ret * 10 + d;
+      num /= 10;
+    }
+    if (x < 0) return (int) (-ret < -2147483648 ? 0 : -ret);
+    else return (int) (ret > 2147483647 ? 0 : ret);
+  }
+}
diff --git a/ReverseLinkedListII.java b/ReverseLinkedListII.java
index 25864d1..f2c6d36 100644
--- a/ReverseLinkedListII.java
+++ b/ReverseLinkedListII.java
@@ -1,49 +1,48 @@
-/** 
+/**
  * Reverse a linked list from position m to n. Do it in-place and in one-pass.
- * 
- * For example:
- * 
- * Given 1->2->3->4->5->NULL, m = 2 and n = 4,
  *
- * return 1->4->3->2->5->NULL. 
+ * <p>For example:
+ *
+ * <p>Given 1->2->3->4->5->NULL, m = 2 and n = 4,
+ *
+ * <p>return 1->4->3->2->5->NULL.
  */
-
 public class ReverseLinkedListII {
-	public ListNode reverseBetween(ListNode head, int m, int n) {
-		ListNode start = new ListNode(0);
-		start.next = head;
-		ListNode low = start;
-		ListNode high = start;
-		ListNode p1 = null;
-		ListNode p2 = null;
-		for (int i = 0; i < m - 1; i++) {
-			low = low.next;
-		}
-		p1 = low;
-		low = low.next;
-		for (int i = 0; i < n; i++) {
-			high = high.next;
-		}
-		p2 = high.next;
-		high.next = null;
-		p1.next = reverseList(low);
-		while (p1.next != null) {
-			p1 = p1.next;
-		}
-		p1.next = p2;
-		return start.next;
-	}
+  public ListNode reverseBetween(ListNode head, int m, int n) {
+    ListNode start = new ListNode(0);
+    start.next = head;
+    ListNode low = start;
+    ListNode high = start;
+    ListNode p1 = null;
+    ListNode p2 = null;
+    for (int i = 0; i < m - 1; i++) {
+      low = low.next;
+    }
+    p1 = low;
+    low = low.next;
+    for (int i = 0; i < n; i++) {
+      high = high.next;
+    }
+    p2 = high.next;
+    high.next = null;
+    p1.next = reverseList(low);
+    while (p1.next != null) {
+      p1 = p1.next;
+    }
+    p1.next = p2;
+    return start.next;
+  }
 
-	private ListNode reverseList(ListNode low) {
-		ListNode cur = low;
-		ListNode prev = null;
-		ListNode next = null;
-		while (cur != null) {
-			next = cur.next;
-			cur.next = prev;
-			prev = cur;
-			cur = next;
-		}
-		return prev;
-	}
-}
\ No newline at end of file
+  private ListNode reverseList(ListNode low) {
+    ListNode cur = low;
+    ListNode prev = null;
+    ListNode next = null;
+    while (cur != null) {
+      next = cur.next;
+      cur.next = prev;
+      prev = cur;
+      cur = next;
+    }
+    return prev;
+  }
+}
diff --git a/ReverseNodesinkGroup.java b/ReverseNodesinkGroup.java
index 2018ad5..dea32bf 100644
--- a/ReverseNodesinkGroup.java
+++ b/ReverseNodesinkGroup.java
@@ -1,53 +1,54 @@
-
-
-/** 
+/**
  * Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.
  *
- * If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is.
+ * <p>If the number of nodes is not a multiple of k then left-out nodes in the end should remain as
+ * it is.
  *
- * You may not alter the values in the nodes, only nodes itself may be changed.
+ * <p>You may not alter the values in the nodes, only nodes itself may be changed.
  *
- * Only constant memory is allowed.
+ * <p>Only constant memory is allowed.
  *
- * For example,
- * 
- * Given this linked list: 1->2->3->4->5
+ * <p>For example,
  *
- * For k = 2, you should return: 2->1->4->3->5
+ * <p>Given this linked list: 1->2->3->4->5
  *
- * For k = 3, you should return: 3->2->1->4->5
+ * <p>For k = 2, you should return: 2->1->4->3->5
+ *
+ * <p>For k = 3, you should return: 3->2->1->4->5
  */
-
 public class ReverseNodesinkGroup {
-	public ListNode reverseKGroup(ListNode head, int k) {
-		if (head == null)
-			return null;
-		int t = 0;
-		ListNode nextHead = head;
-		while (nextHead != null && t < k - 1) {
-			nextHead = nextHead.next;
-			t++;
-		}
-		if (nextHead == null || t < k - 1) {
-			return head;
-		} else {
-			ListNode nextPart = reverseKGroup(nextHead.next, k);
-			return reverseList(head, k, nextPart);
-		}
-	}
+  public ListNode reverseKGroup(ListNode head, int k) {
+    if (head == null || k < 2) {
+      return head;
+    }
+    int count = 0;
+    ListNode root = new ListNode(0);
+    root.next = head;
+    ListNode start = head;
+    ListNode end = start;
+    while (count < k - 1 && end != null && end.next != null) {
+      count++;
+      end = end.next;
+    }
+    if (count == k - 1) {
+      ListNode nextStart = end.next;
+      end.next = null;
+      reverseList(start);
+      root.next = end;
+      start.next = reverseKGroup(nextStart, k);
+    }
+    return root.next;
+  }
 
-	private ListNode reverseList(ListNode head, int k, ListNode nextPart) {
-		ListNode cur = head, prev = null, next = null;
-		for (int i = 0; i < k; i++) {
-			next = cur.next;
-			if (i != 0) {
-				cur.next = prev;
-			} else {
-				cur.next = nextPart;
-			}
-			prev = cur;
-			cur = next;
-		}
-		return prev;
-	}
-}
\ No newline at end of file
+  private void reverseList(ListNode start) {
+    ListNode next;
+    ListNode cur = start;
+    ListNode prev = null;
+    while (cur != null) {
+      next = cur.next;
+      cur.next = prev;
+      prev = cur;
+      cur = next;
+    }
+  }
+}
diff --git a/RomantoInteger.java b/RomantoInteger.java
index a8217ad..e293b5c 100644
--- a/RomantoInteger.java
+++ b/RomantoInteger.java
@@ -1,48 +1,45 @@
-
-
 /**
  * Given a roman numeral, convert it to an integer.
- * 
- * Input is guaranteed to be within the range from 1 to 3999.
+ *
+ * <p>Input is guaranteed to be within the range from 1 to 3999.
  */
-
 public class RomantoInteger {
-	public int romanToInt(String s) {
-		int result = 0;
-		if (s.length() != 0) {
-			int prev = getDigit(s.charAt(s.length() - 1));
-			result += prev;
-			for (int i = s.length() - 2; i >= 0; i--) {
-				int d = getDigit(s.charAt(i));
-				if (d < prev) {
-					result -= d;
-				} else if (d >= prev) {
-					result += d;
-				}
-				prev = d;
-			}
-		}
-		return result;
-	}
+  public int romanToInt(String s) {
+    int result = 0;
+    if (s.length() != 0) {
+      int prev = getDigit(s.charAt(s.length() - 1));
+      result += prev;
+      for (int i = s.length() - 2; i >= 0; i--) {
+        int d = getDigit(s.charAt(i));
+        if (d < prev) {
+          result -= d;
+        } else if (d >= prev) {
+          result += d;
+        }
+        prev = d;
+      }
+    }
+    return result;
+  }
 
-	private int getDigit(char c) {
-		switch (c) {
-		case 'I':
-			return 1;
-		case 'V':
-			return 5;
-		case 'X':
-			return 10;
-		case 'L':
-			return 50;
-		case 'C':
-			return 100;
-		case 'D':
-			return 500;
-		case 'M':
-			return 1000;
-		default:
-			return 0;
-		}
-	}
-}
\ No newline at end of file
+  private int getDigit(char c) {
+    switch (c) {
+      case 'I':
+        return 1;
+      case 'V':
+        return 5;
+      case 'X':
+        return 10;
+      case 'L':
+        return 50;
+      case 'C':
+        return 100;
+      case 'D':
+        return 500;
+      case 'M':
+        return 1000;
+      default:
+        return 0;
+    }
+  }
+}
diff --git a/RotateImage.java b/RotateImage.java
index 00b3fc6..43e523a 100644
--- a/RotateImage.java
+++ b/RotateImage.java
@@ -1,31 +1,27 @@
-
-
 /**
  * You are given an n x n 2D matrix representing an image.
- * 
- * Rotate the image by 90 degrees (clockwise).
- * 
- * Follow up: Could you do this in-place?
+ *
+ * <p>Rotate the image by 90 degrees (clockwise).
+ *
+ * <p>Follow up: Could you do this in-place?
  */
-
 public class RotateImage {
-	public void rotate(int[][] matrix) {
-		int n = matrix.length;
-		if (n == 0)
-			return;
-		for (int i = 0; i < n; i++) {
-			for (int j = i; j < n; j++) {
-				int t = matrix[i][j];
-				matrix[i][j] = matrix[j][i];
-				matrix[j][i] = t;
-			}
-		}
-		for (int i = 0; i < n; i++) {
-			for (int j = 0; j < n / 2; j++) {
-				int t = matrix[i][j];
-				matrix[i][j] = matrix[i][n - j - 1];
-				matrix[i][n - j - 1] = t;
-			}
-		}
-	}
-}
\ No newline at end of file
+  public void rotate(int[][] matrix) {
+    int n = matrix.length;
+    if (n == 0) return;
+    for (int i = 0; i < n; i++) {
+      for (int j = i; j < n; j++) {
+        int t = matrix[i][j];
+        matrix[i][j] = matrix[j][i];
+        matrix[j][i] = t;
+      }
+    }
+    for (int i = 0; i < n; i++) {
+      for (int j = 0; j < n / 2; j++) {
+        int t = matrix[i][j];
+        matrix[i][j] = matrix[i][n - j - 1];
+        matrix[i][n - j - 1] = t;
+      }
+    }
+  }
+}
diff --git a/RotateList.java b/RotateList.java
index f1bbf8e..81e182e 100644
--- a/RotateList.java
+++ b/RotateList.java
@@ -1,36 +1,31 @@
 /**
- * Given a list, rotate the list to the right by k places, where k is
- * non-negative.
- * 
- * For example:
- * 
- * Given 1->2->3->4->5->NULL and k = 2, return 4->5->1->2->3->NULL.
- * 
+ * Given a list, rotate the list to the right by k places, where k is non-negative.
+ *
+ * <p>For example:
+ *
+ * <p>Given 1->2->3->4->5->NULL and k = 2, return 4->5->1->2->3->NULL.
  */
-
 public class RotateList {
-	public ListNode rotateRight(ListNode head, int n) {
-		if (head == null)
-			return head;
-		int length = 1;
-		ListNode last = head;
-		while (last.next != null) {
-			last = last.next;
-			length++;
-		}
-		n = n % length;
-		if (n == 0)
-			return head;
-		int steps = length - n;
-		ListNode start = new ListNode(0);
-		start.next = head;
-		while (steps > 0) {
-			start = start.next;
-			steps--;
-		}
-		ListNode ret = start.next;
-		start.next = null;
-		last.next = head;
-		return ret;
-	}
+  public ListNode rotateRight(ListNode head, int n) {
+    if (head == null) return head;
+    int length = 1;
+    ListNode last = head;
+    while (last.next != null) {
+      last = last.next;
+      length++;
+    }
+    n = n % length;
+    if (n == 0) return head;
+    int steps = length - n;
+    ListNode start = new ListNode(0);
+    start.next = head;
+    while (steps > 0) {
+      start = start.next;
+      steps--;
+    }
+    ListNode ret = start.next;
+    start.next = null;
+    last.next = head;
+    return ret;
+  }
 }
diff --git a/SameTree.java b/SameTree.java
index 5e3c115..eb5a5cd 100644
--- a/SameTree.java
+++ b/SameTree.java
@@ -1,20 +1,16 @@
-
-
 /**
  * Given two binary trees, write a function to check if they are equal or not.
  *
- * Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
+ * <p>Two binary trees are considered equal if they are structurally identical and the nodes have
+ * the same value.
  */
 public class SameTree {
-	public boolean isSameTree(TreeNode p, TreeNode q) {
-		if (p == null && q == null)
-			return true;
-		if ((p == null && q != null) || (p != null && q == null))
-			return false;
-		if (p.val != q.val)
-			return false;
-		else {
-			return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
-		}
-	}
-}
\ No newline at end of file
+  public boolean isSameTree(TreeNode p, TreeNode q) {
+    if (p == null && q == null) return true;
+    if ((p == null && q != null) || (p != null && q == null)) return false;
+    if (p.val != q.val) return false;
+    else {
+      return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
+    }
+  }
+}
diff --git a/ScrambleString.java b/ScrambleString.java
index 5ee01e3..b4b5e66 100644
--- a/ScrambleString.java
+++ b/ScrambleString.java
@@ -1,73 +1,54 @@
-/** 
- * Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.
+/**
+ * Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty
+ * substrings recursively.
  *
- * Below is one possible representation of s1 = "great":
+ * <p>Below is one possible representation of s1 = "great":
  *
- *      great
- *     /    \
- *    gr    eat
- *   / \    /  \
- *  g   r  e   at
- *            / \
- *           a   t
- * To scramble the string, we may choose any non-leaf node and swap its two children.
+ * <p>great / \ gr eat / \ / \ g r e at / \ a t To scramble the string, we may choose any non-leaf
+ * node and swap its two children.
  *
- * For example, if we choose the node "gr" and swap its two children, it produces a scrambled string "rgeat".
+ * <p>For example, if we choose the node "gr" and swap its two children, it produces a scrambled
+ * string "rgeat".
  *
- *       rgeat
- *      /    \
- *     rg    eat
- *    / \    /  \
- *   r   g  e   at
- *             / \
- *            a   t
- * We say that "rgeat" is a scrambled string of "great".
+ * <p>rgeat / \ rg eat / \ / \ r g e at / \ a t We say that "rgeat" is a scrambled string of
+ * "great".
  *
- * Similarly, if we continue to swap the children of nodes "eat" and "at", it produces a scrambled string "rgtae".
+ * <p>Similarly, if we continue to swap the children of nodes "eat" and "at", it produces a
+ * scrambled string "rgtae".
  *
- *       rgtae
- *      /    \
- *     rg    tae
- *    / \    /  \
- *   r   g  ta  e
- *         / \
- *        t   a
- * We say that "rgtae" is a scrambled string of "great".
+ * <p>rgtae / \ rg tae / \ / \ r g ta e / \ t a We say that "rgtae" is a scrambled string of
+ * "great".
  *
- * Given two strings s1 and s2 of the same length, determine if s2 is a scrambled string of s1.
+ * <p>Given two strings s1 and s2 of the same length, determine if s2 is a scrambled string of s1.
  */
-
 public class ScrambleString {
-	public boolean isScramble(String s1, String s2) {
-		if (s1.length() != s2.length())
-			return false;
-		if (s1.equals(s2))
-			return true;
+  public boolean isScramble(String s1, String s2) {
+    if (s1.length() != s2.length()) return false;
+    if (s1.equals(s2)) return true;
 
-		int[] A = new int[26];
-		for (int i = 0; i < s1.length(); i++) {
-			++A[s1.charAt(i) - 'a'];
-		}
+    int[] A = new int[26];
+    for (int i = 0; i < s1.length(); i++) {
+      ++A[s1.charAt(i) - 'a'];
+    }
 
-		for (int j = 0; j < s2.length(); j++) {
-			--A[s2.charAt(j) - 'a'];
-		}
+    for (int j = 0; j < s2.length(); j++) {
+      --A[s2.charAt(j) - 'a'];
+    }
 
-		for (int k = 0; k < 26; k++) {
-			if (A[k] != 0)
-				return false;
-		}
+    for (int k = 0; k < 26; k++) {
+      if (A[k] != 0) return false;
+    }
 
-		for (int i = 1; i < s1.length(); i++) {
-			boolean result = isScramble(s1.substring(0, i), s2.substring(0, i))
-					&& isScramble(s1.substring(i), s2.substring(i));
-			result = result
-					|| (isScramble(s1.substring(0, i),
-							s2.substring(s2.length() - i, s2.length())) && isScramble(
-							s1.substring(i), s2.substring(0, s2.length() - i)));
-			if (result)
-				return true;
-		}
-		return false;
-	}
-}
\ No newline at end of file
+    for (int i = 1; i < s1.length(); i++) {
+      boolean result =
+          isScramble(s1.substring(0, i), s2.substring(0, i))
+              && isScramble(s1.substring(i), s2.substring(i));
+      result =
+          result
+              || (isScramble(s1.substring(0, i), s2.substring(s2.length() - i, s2.length()))
+                  && isScramble(s1.substring(i), s2.substring(0, s2.length() - i)));
+      if (result) return true;
+    }
+    return false;
+  }
+}
diff --git a/SearchInsertPosition.java b/SearchInsertPosition.java
index 30d3b04..4834126 100644
--- a/SearchInsertPosition.java
+++ b/SearchInsertPosition.java
@@ -1,35 +1,25 @@
-
-
 /**
- * Given a sorted array and a target value, return the index if the target is
- * found. If not, return the index where it would be if it were inserted in
- * order.
- * 
- * You may assume no duplicates in the array.
- * 
- * Here are few examples. 
- * [1,3,5,6], 5 -> 2
- * [1,3,5,6], 2 -> 1
- * [1,3,5,6], 7 -> 4
- * [1,3,5,6], 0 -> 0
+ * Given a sorted array and a target value, return the index if the target is found. If not, return
+ * the index where it would be if it were inserted in order.
+ *
+ * <p>You may assume no duplicates in the array.
+ *
+ * <p>Here are few examples. [1,3,5,6], 5 -> 2 [1,3,5,6], 2 -> 1 [1,3,5,6], 7 -> 4 [1,3,5,6], 0 -> 0
  */
-
 public class SearchInsertPosition {
-	public int searchInsert(int[] A, int target) {
-		int length = A.length;
-		if (A.length == 0)
-			return 0;
-		int i = 0, j = length - 1;
-		while (i < j) {
-			int mid = (i + j) / 2;
-			if (A[mid] == target)
-				return mid;
-			if (A[mid] < target) {
-				i = mid + 1;
-			} else {
-				j = mid - 1;
-			}
-		}
-		return A[i] < target ? i + 1 : i;
-	}
-}
\ No newline at end of file
+  public int searchInsert(int[] A, int target) {
+    int length = A.length;
+    if (A.length == 0) return 0;
+    int i = 0, j = length - 1;
+    while (i < j) {
+      int mid = (i + j) / 2;
+      if (A[mid] == target) return mid;
+      if (A[mid] < target) {
+        i = mid + 1;
+      } else {
+        j = mid - 1;
+      }
+    }
+    return A[i] < target ? i + 1 : i;
+  }
+}
diff --git a/Searcha2DMatrix.java b/Searcha2DMatrix.java
index c9f91da..0784cf5 100644
--- a/Searcha2DMatrix.java
+++ b/Searcha2DMatrix.java
@@ -1,42 +1,32 @@
-
-
-/** 
- * Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:
+/**
+ * Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the
+ * following properties:
  *
- * Integers in each row are sorted from left to right.
- * The first integer of each row is greater than the last integer of the previous row.
- * For example,
+ * <p>Integers in each row are sorted from left to right. The first integer of each row is greater
+ * than the last integer of the previous row. For example,
  *
- * Consider the following matrix:
+ * <p>Consider the following matrix:
  *
- * [
- *   [1,   3,  5,  7],
- *   [10, 11, 16, 20],
- *   [23, 30, 34, 50]
- * ]
- * Given target = 3, return true.
+ * <p>[ [1, 3, 5, 7], [10, 11, 16, 20], [23, 30, 34, 50] ] Given target = 3, return true.
  */
-
 public class Searcha2DMatrix {
-	public boolean searchMatrix(int[][] matrix, int target) {
-		int length = matrix.length;
-		if (length == 0)
-			return false;
-		int width = matrix[0].length;
-		int low = 0;
-		int high = width * length - 1;
-		while (low <= high) {
-			int mid = (low + high) / 2;
-			int x = mid / width;
-			int y = mid % width;
-			if (matrix[x][y] == target)
-				return true;
-			else if (matrix[x][y] > target) {
-				high = mid - 1;
-			} else {
-				low = mid + 1;
-			}
-		}
-		return false;
-	}
-}
\ No newline at end of file
+  public boolean searchMatrix(int[][] matrix, int target) {
+    int length = matrix.length;
+    if (length == 0) return false;
+    int width = matrix[0].length;
+    int low = 0;
+    int high = width * length - 1;
+    while (low <= high) {
+      int mid = (low + high) / 2;
+      int x = mid / width;
+      int y = mid % width;
+      if (matrix[x][y] == target) return true;
+      else if (matrix[x][y] > target) {
+        high = mid - 1;
+      } else {
+        low = mid + 1;
+      }
+    }
+    return false;
+  }
+}
diff --git a/SearchforaRange.java b/SearchforaRange.java
index e06cf03..783b4fb 100644
--- a/SearchforaRange.java
+++ b/SearchforaRange.java
@@ -1,66 +1,61 @@
-
-
 /**
- * Given a sorted array of integers, find the starting and ending position of a
- * given target value.
- * 
- * Your algorithm's runtime complexity must be in the order of O(log n).
- * 
- * If the target is not found in the array, return [-1, -1].
- * 
- * For example, Given [5, 7, 7, 8, 8, 10] and target value 8, return [3, 4].
+ * Given a sorted array of integers, find the starting and ending position of a given target value.
+ *
+ * <p>Your algorithm's runtime complexity must be in the order of O(log n).
+ *
+ * <p>If the target is not found in the array, return [-1, -1].
+ *
+ * <p>For example, Given [5, 7, 7, 8, 8, 10] and target value 8, return [3, 4].
  */
-
 public class SearchforaRange {
-	public int[] searchRange(int[] A, int target) {
-		int low = findLow(A, target, 0, A.length - 1);
-		int high = findHigh(A, target, 0, A.length - 1);
-		int[] ret = new int[2];
-		ret[0] = low;
-		ret[1] = high;
-		return ret;
-	}
-
-	private int findLow(int[] A, int target, int l, int r) {
-		int mid = 0;
-		int ret = -1;
-		while (l <= r) {
-			mid = (l + r) / 2;
-			if (A[mid] == target) {
-				ret = mid;
-				int next = findLow(A, target, l, mid - 1);
-				if (next != -1) {
-					ret = next;
-				}
-				break;
-			} else if (A[mid] < target) {
-				l = mid + 1;
-			} else {
-				r = mid - 1;
-			}
+  public int[] searchRange(int[] A, int target) {
+    int low = findLow(A, target, 0, A.length - 1);
+    int high = findHigh(A, target, 0, A.length - 1);
+    int[] ret = new int[2];
+    ret[0] = low;
+    ret[1] = high;
+    return ret;
+  }
 
-		}
-		return ret;
-	}
+  private int findLow(int[] A, int target, int l, int r) {
+    int mid = 0;
+    int ret = -1;
+    while (l <= r) {
+      mid = (l + r) / 2;
+      if (A[mid] == target) {
+        ret = mid;
+        int next = findLow(A, target, l, mid - 1);
+        if (next != -1) {
+          ret = next;
+        }
+        break;
+      } else if (A[mid] < target) {
+        l = mid + 1;
+      } else {
+        r = mid - 1;
+      }
+    }
+    return ret;
+  }
 
-	private int findHigh(int[] A, int target, int l, int r) {
-		int mid = 0;
-		int ret = -1;
-		while (l <= r) {
-			mid = (l + r) / 2;
-			if (A[mid] == target) {
-				ret = mid;
-				int next = findHigh(A, target, mid + 1, r);
-				if (next != -1) {
-					ret = next;
-				}
-				break;
-			} else if (A[mid] < target) {
-				l = mid + 1;
-			} else {
-				r = mid - 1;
-			}
-		}
-		return ret;
-	}
-}
\ No newline at end of file
+  private int findHigh(int[] A, int target, int l, int r) {
+    int mid = 0;
+    int ret = -1;
+    while (l <= r) {
+      mid = (l + r) / 2;
+      if (A[mid] == target) {
+        ret = mid;
+        int next = findHigh(A, target, mid + 1, r);
+        if (next != -1) {
+          ret = next;
+        }
+        break;
+      } else if (A[mid] < target) {
+        l = mid + 1;
+      } else {
+        r = mid - 1;
+      }
+    }
+    return ret;
+  }
+}
diff --git a/SearchinRotatedSortedArray.java b/SearchinRotatedSortedArray.java
index 03385f5..a414157 100644
--- a/SearchinRotatedSortedArray.java
+++ b/SearchinRotatedSortedArray.java
@@ -1,41 +1,37 @@
-
-
 /**
  * Suppose a sorted array is rotated at some pivot unknown to you beforehand.
- * 
- * (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).
- * 
- * You are given a target value to search. If found in the array return its
- * index, otherwise return -1.
- * 
- * You may assume no duplicate exists in the array.
+ *
+ * <p>(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).
+ *
+ * <p>You are given a target value to search. If found in the array return its index, otherwise
+ * return -1.
+ *
+ * <p>You may assume no duplicate exists in the array.
  */
-
 public class SearchinRotatedSortedArray {
-	public int search(int[] A, int target) {
-		int low = 0;
-		int high = A.length - 1;
-		int mid = 0;
-		while (low <= high) {
-			mid = (low + high) / 2;
-			if (A[mid] == target)
-				return mid;
-			else {
-				if (A[low] <= A[mid]) {
-					if (target >= A[low] && target < A[mid]) {
-						high = mid - 1;
-					} else {
-						low = mid + 1;
-					}
-				} else {
-					if (target <= A[high] && target > A[mid]) {
-						low = mid + 1;
-					} else {
-						high = mid - 1;
-					}
-				}
-			}
-		}
-		return -1;
-	}
-}
\ No newline at end of file
+  public int search(int[] A, int target) {
+    int low = 0;
+    int high = A.length - 1;
+    int mid = 0;
+    while (low <= high) {
+      mid = (low + high) / 2;
+      if (A[mid] == target) return mid;
+      else {
+        if (A[low] <= A[mid]) {
+          if (target >= A[low] && target < A[mid]) {
+            high = mid - 1;
+          } else {
+            low = mid + 1;
+          }
+        } else {
+          if (target <= A[high] && target > A[mid]) {
+            low = mid + 1;
+          } else {
+            high = mid - 1;
+          }
+        }
+      }
+    }
+    return -1;
+  }
+}
diff --git a/SearchinRotatedSortedArrayII.java b/SearchinRotatedSortedArrayII.java
index bba0c8f..6e438aa 100644
--- a/SearchinRotatedSortedArrayII.java
+++ b/SearchinRotatedSortedArrayII.java
@@ -1,45 +1,39 @@
-
-
 /**
- * Follow up for "Search in Rotated Sorted Array": What if duplicates are
- * allowed?
- * 
- * Would this affect the run-time complexity? How and why?
- * 
- * Write a function to determine if a given target is in the array.
+ * Follow up for "Search in Rotated Sorted Array": What if duplicates are allowed?
+ *
+ * <p>Would this affect the run-time complexity? How and why?
+ *
+ * <p>Write a function to determine if a given target is in the array.
  */
-
 public class SearchinRotatedSortedArrayII {
-	public boolean search(int[] A, int target) {
-		int low = 0;
-		int high = A.length - 1;
-		int mid = 0;
-		while (low <= high) {
-			mid = (low + high) / 2;
-			if (A[mid] == target)
-				return true;
-			else if (A[low] != A[high]) {
-				if (A[low] <= A[mid]) {
-					if (target >= A[low] && target < A[mid]) {
-						high = mid - 1;
-					} else {
-						low = mid + 1;
-					}
-				} else {
-					if (target <= A[high] && target > A[mid]) {
-						low = mid + 1;
-					} else {
-						high = mid - 1;
-					}
-				}
-			} else {
-				for (int k = low; k < high; k++) {
-					if (A[k] == target)
-						return true;
-				}
-				return false;
-			}
-		}
-		return true;
-	}
-}
\ No newline at end of file
+  public boolean search(int[] A, int target) {
+    int low = 0;
+    int high = A.length - 1;
+    int mid = 0;
+    while (low <= high) {
+      mid = (low + high) / 2;
+      if (A[mid] == target) return true;
+      else if (A[low] != A[high]) {
+        if (A[low] <= A[mid]) {
+          if (target >= A[low] && target < A[mid]) {
+            high = mid - 1;
+          } else {
+            low = mid + 1;
+          }
+        } else {
+          if (target <= A[high] && target > A[mid]) {
+            low = mid + 1;
+          } else {
+            high = mid - 1;
+          }
+        }
+      } else {
+        for (int k = low; k < high; k++) {
+          if (A[k] == target) return true;
+        }
+        return false;
+      }
+    }
+    return true;
+  }
+}
diff --git a/SerializeAndDeserializeBinaryTree.java b/SerializeAndDeserializeBinaryTree.java
new file mode 100644
index 0000000..2a18ecc
--- /dev/null
+++ b/SerializeAndDeserializeBinaryTree.java
@@ -0,0 +1,16 @@
+/**
+ * Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment.
+ *
+ * Design an algorithm to serialize and deserialize a binary tree. There is no restriction on how your serialization/deserialization algorithm should work. You just need to ensure that a binary tree can be serialized to a string and this string can be deserialized to the original tree structure.
+ *
+ * Example: 
+ *
+ * You may serialize the following tree:
+ *
+ *   1
+ *  / \
+ * 2   3
+ *    / \
+ *   4   5
+ *
+ * as "[1,2,3,null,null,4,5]"
\ No newline at end of file
diff --git a/SetMatrixZeroes.java b/SetMatrixZeroes.java
index b920f8e..92a2595 100644
--- a/SetMatrixZeroes.java
+++ b/SetMatrixZeroes.java
@@ -1,42 +1,33 @@
-
-
 /**
- * Given a m x n matrix, if an element is 0, set its entire row and column to 0.
- * Do it in place.
- * 
- * Follow up: 
- * Did you use extra space? 
- * A straight forward solution using O(mn) space is probably a bad idea. 
- * A simple improvement uses O(m + n) space, but still not the best solution. 
- * Could you devise a constant space solution?
+ * Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.
+ *
+ * <p>Follow up: Did you use extra space? A straight forward solution using O(mn) space is probably
+ * a bad idea. A simple improvement uses O(m + n) space, but still not the best solution. Could you
+ * devise a constant space solution?
  */
-
 public class SetMatrixZeroes {
-	public void setZeroes(int[][] matrix) {
-		int row = matrix.length;
-		if (row == 0)
-			return;
-		int col = matrix[0].length;
-		for (int i = 0; i < row; i++) {
-			for (int j = 0; j < col; j++) {
-				if (matrix[i][j] == 0) {
-					for (int k = 0; k < col; k++) {
-						if (matrix[i][k] != 0)
-							matrix[i][k] = -1;
-					}
-					for (int f = 0; f < row; f++) {
-						if (matrix[f][j] != 0)
-							matrix[f][j] = -1;
-					}
-				}
-			}
-		}
-		for (int i = 0; i < row; i++) {
-			for (int j = 0; j < col; j++) {
-				if (matrix[i][j] == -1) {
-					matrix[i][j] = 0;
-				}
-			}
-		}
-	}
-}
\ No newline at end of file
+  public void setZeroes(int[][] matrix) {
+    int row = matrix.length;
+    if (row == 0) return;
+    int col = matrix[0].length;
+    for (int i = 0; i < row; i++) {
+      for (int j = 0; j < col; j++) {
+        if (matrix[i][j] == 0) {
+          for (int k = 0; k < col; k++) {
+            if (matrix[i][k] != 0) matrix[i][k] = -1;
+          }
+          for (int f = 0; f < row; f++) {
+            if (matrix[f][j] != 0) matrix[f][j] = -1;
+          }
+        }
+      }
+    }
+    for (int i = 0; i < row; i++) {
+      for (int j = 0; j < col; j++) {
+        if (matrix[i][j] == -1) {
+          matrix[i][j] = 0;
+        }
+      }
+    }
+  }
+}
diff --git a/SimplifyPath.java b/SimplifyPath.java
index 9dc6c57..acc967e 100644
--- a/SimplifyPath.java
+++ b/SimplifyPath.java
@@ -3,55 +3,48 @@
 
 /**
  * Given an absolute path for a file (Unix-style), simplify it.
- * 
- * For example,
- * 
- * path = "/home/", => "/home"
- * path = "/a/./b/../../c/", => "/c"
- * 
- * click to show corner cases.
- * 
- * Corner Cases:
- * Did you consider the case where path = "/../"?
- * In this case, you should return "/".
- * Another corner case is the path might contain multiple slashes '/' together, such as "/home//foo/".
- * In this case, you should ignore redundant slashes and return "/home/foo".
  *
+ * <p>For example,
+ *
+ * <p>path = "/home/", => "/home" path = "/a/./b/../../c/", => "/c"
+ *
+ * <p>click to show corner cases.
+ *
+ * <p>Corner Cases: Did you consider the case where path = "/../"? In this case, you should return
+ * "/". Another corner case is the path might contain multiple slashes '/' together, such as
+ * "/home//foo/". In this case, you should ignore redundant slashes and return "/home/foo".
  */
-
 public class SimplifyPath {
-	public String simplifyPath(String path) {
-		int length = path.length();
-		if (length == 0)
-			return path;
-		List<String> dicts = new LinkedList<String>();
-		int slow = 0;
-		int fast = 0;
-		while (true) {
-			while (slow < length && path.charAt(slow) == '/') {
-				slow++;
-			}
-			if (slow >= length)
-				break;
-			fast = slow;
-			while (fast < length && path.charAt(fast) != '/') {
-				fast++;
-			}
-			String s = path.substring(slow, fast);
-			if (s.equals("..")) {
-				if (!dicts.isEmpty()) {
-					dicts.remove(dicts.size() - 1);
-				}
-			} else if (!s.equals(".")) {
-				dicts.add(s);
-			}
-			slow = fast;
-		}
-		StringBuffer ret = new StringBuffer();
-		for (String s : dicts) {
-			ret.append('/');
-			ret.append(s);
-		}
-		return ret.length() == 0 ? "/" : ret.toString();
-	}
+  public String simplifyPath(String path) {
+    int length = path.length();
+    if (length == 0) return path;
+    List<String> dicts = new LinkedList<String>();
+    int slow = 0;
+    int fast = 0;
+    while (true) {
+      while (slow < length && path.charAt(slow) == '/') {
+        slow++;
+      }
+      if (slow >= length) break;
+      fast = slow;
+      while (fast < length && path.charAt(fast) != '/') {
+        fast++;
+      }
+      String s = path.substring(slow, fast);
+      if (s.equals("..")) {
+        if (!dicts.isEmpty()) {
+          dicts.remove(dicts.size() - 1);
+        }
+      } else if (!s.equals(".")) {
+        dicts.add(s);
+      }
+      slow = fast;
+    }
+    StringBuffer ret = new StringBuffer();
+    for (String s : dicts) {
+      ret.append('/');
+      ret.append(s);
+    }
+    return ret.length() == 0 ? "/" : ret.toString();
+  }
 }
diff --git a/SingleNumber.java b/SingleNumber.java
index 24b9896..14a7e1e 100644
--- a/SingleNumber.java
+++ b/SingleNumber.java
@@ -1,19 +1,15 @@
-
-
 /**
- * Given an array of integers, every element appears twice except for one. Find
- * that single one.
- * 
- * Note: Your algorithm should have a linear runtime complexity. Could you
- * implement it without using extra memory?
+ * Given an array of integers, every element appears twice except for one. Find that single one.
+ *
+ * <p>Note: Your algorithm should have a linear runtime complexity. Could you implement it without
+ * using extra memory?
  */
-
 public class SingleNumber {
-	public int singleNumber(int[] A) {
-		int ret = A[0];
-		for (int i = 1; i < A.length; i++) {
-			ret ^= A[i];
-		}
-		return ret;
-	}
-}
\ No newline at end of file
+  public int singleNumber(int[] A) {
+    int ret = A[0];
+    for (int i = 1; i < A.length; i++) {
+      ret ^= A[i];
+    }
+    return ret;
+  }
+}
diff --git a/SingleNumberII.java b/SingleNumberII.java
index 1929cff..b4de7aa 100644
--- a/SingleNumberII.java
+++ b/SingleNumberII.java
@@ -1,23 +1,22 @@
 /**
- * Given an array of integers, every element appears three times except for one.
- * Find that single one.
- * 
- * Note:
- * 
- * Your algorithm should have a linear runtime complexity. Could you implement
- * it without using extra memory?
- * 
+ * Given an array of integers, every element appears three times except for one. Find that single
+ * one.
+ *
+ * <p>Note:
+ *
+ * <p>Your algorithm should have a linear runtime complexity. Could you implement it without using
+ * extra memory?
  */
 public class SingleNumberII {
-	public int singleNumber(int[] A) {
-		int ones = 0, twos = 0, xthrees = 0;
-		for (int i = 0; i < A.length; ++i) {
-			twos |= (ones & A[i]);
-			ones ^= A[i];
-			xthrees = ~(ones & twos);
-			ones &= xthrees;
-			twos &= xthrees;
-		}
-		return ones;
-	}
+  public int singleNumber(int[] A) {
+    int ones = 0, twos = 0, xthrees = 0;
+    for (int i = 0; i < A.length; ++i) {
+      twos |= (ones & A[i]);
+      ones ^= A[i];
+      xthrees = ~(ones & twos);
+      ones &= xthrees;
+      twos &= xthrees;
+    }
+    return ones;
+  }
 }
diff --git a/SortArrayByParity.java b/SortArrayByParity.java
new file mode 100644
index 0000000..3e792c0
--- /dev/null
+++ b/SortArrayByParity.java
@@ -0,0 +1,29 @@
+/**
+ * Given an array A of non-negative integers, return an array consisting of all the even elements of A, followed by all the odd elements of A.
+ *
+ * You may return any answer array that satisfies this condition.
+ *
+ * Example 1:
+ *
+ * Input: [3,1,2,4]
+ * Output: [2,4,3,1]
+ * The outputs [4,2,3,1], [2,4,1,3], and [4,2,1,3] would also be accepted.
+ */
+class Solution {
+    public int[] sortArrayByParity(int[] A) {
+        int i = 0;
+        int j = A.length - 1;
+        while(i < A.length && j >= 0 && i < j) {
+            while (i < A.length && A[i] % 2 == 0) i++;
+            while (j >= 0 && A[j] % 2 != 0) j--;
+            if (i < A.length && j >= 0 && i < j) {
+                int tmp = A[i];
+                A[i] = A[j];
+                A[j] = tmp;
+                i++;
+                j--;
+            }
+        }
+        return A;
+    }
+}
\ No newline at end of file
diff --git a/SortArrayByParityII.java b/SortArrayByParityII.java
new file mode 100644
index 0000000..2ac0de6
--- /dev/null
+++ b/SortArrayByParityII.java
@@ -0,0 +1,31 @@
+/**
+ * Given an array A of non-negative integers, half of the integers in A are odd, and half of the integers are even.
+ * Sort the array so that whenever A[i] is odd, i is odd; and whenever A[i] is even, i is even.
+ * You may return any answer array that satisfies this condition.
+ *
+ * Input: [4,2,5,7]
+ * Output: [4,5,2,7]
+ * Explanation: [4,7,2,5], [2,5,4,7], [2,7,4,5] would also have been accepted.
+ */
+class Solution {
+  public int[] sortArrayByParityII(int[] A) {
+    int odd = 1;
+    int even = 0;
+    while(odd < A.length && even < A.length) {
+      while(odd < A.length && A[odd] % 2 != 0) {
+        odd += 2;
+      }
+      while(even < A.length && A[even] % 2 == 0) {
+        even += 2;
+      }
+      if (odd < A.length && even < A.length) {
+        int tmp = A[odd];
+        A[odd] = A[even];
+        A[even] = tmp;
+        odd += 2;
+        even += 2;
+      }
+    }
+    return A;
+  }
+}
diff --git a/SortColors.java b/SortColors.java
index 913cd88..fc81f1f 100644
--- a/SortColors.java
+++ b/SortColors.java
@@ -1,46 +1,41 @@
-
-
 /**
- * Given an array with n objects colored red, white or blue, sort them so that
- * objects of the same color are adjacent, with the colors in the order red,
- * white and blue.
- * 
- * Here, we will use the integers 0, 1, and 2 to represent the color red, white,
- * and blue respectively.
- * 
- * Note: 
- * 
- * You are not suppose to use the library's sort function for this problem.
- * 
- * Follow up: 
- * A rather straight forward solution is a two-pass algorithm using counting sort. 
- * 
- * First, iterate the array counting number of 0's, 1's, and 2's,
- * then overwrite array with total number of 0's, then 1's and followed by 2's.
- * 
- * Could you come up with an one-pass algorithm using only constant space?
+ * Given an array with n objects colored red, white or blue, sort them so that objects of the same
+ * color are adjacent, with the colors in the order red, white and blue.
+ *
+ * <p>Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue
+ * respectively.
+ *
+ * <p>Note:
+ *
+ * <p>You are not suppose to use the library's sort function for this problem.
+ *
+ * <p>Follow up: A rather straight forward solution is a two-pass algorithm using counting sort.
+ *
+ * <p>First, iterate the array counting number of 0's, 1's, and 2's, then overwrite array with total
+ * number of 0's, then 1's and followed by 2's.
+ *
+ * <p>Could you come up with an one-pass algorithm using only constant space?
  */
-
 public class SortColors {
-	public void sortColors(int[] A) {
-		int length = A.length;
-		int left = -1;
-		int right = length;
-		int i = 0;
-		while (i < right) {
-			if (A[i] == 0) {
-				swap(A, ++left, i++);
-			} else if (A[i] == 2) {
-				swap(A, i, --right);
-			} else {
-				i++;
-			}
-		}
-	}
+  public void sortColors(int[] A) {
+    int length = A.length;
+    int left = -1;
+    int right = length;
+    int i = 0;
+    while (i < right) {
+      if (A[i] == 0) {
+        swap(A, ++left, i++);
+      } else if (A[i] == 2) {
+        swap(A, i, --right);
+      } else {
+        i++;
+      }
+    }
+  }
 
-	private void swap(int[] a, int i, int j) {
-		int tmp = a[i];
-		a[i] = a[j];
-		a[j] = tmp;
-	}
-}
\ No newline at end of file
+  private void swap(int[] a, int i, int j) {
+    int tmp = a[i];
+    a[i] = a[j];
+    a[j] = tmp;
+  }
+}
diff --git a/SortList.java b/SortList.java
index ff310bb..92093a8 100644
--- a/SortList.java
+++ b/SortList.java
@@ -1,45 +1,38 @@
-
-
-/**
- * Sort a linked list in O(n log n) time using constant space complexity.
- * 
- */
-
+/** Sort a linked list in O(n log n) time using constant space complexity. */
 public class SortList {
-	public ListNode sortList(ListNode head) {
-		if (head == null || head.next == null)
-			return head;
-		ListNode fast = head;
-		ListNode slow = head;
-		while (fast.next != null && fast.next.next != null) {
-			fast = fast.next.next;
-			slow = slow.next;
-		}
-		fast = slow.next;
-		slow.next = null;
-		slow = sortList(head);
-		fast = sortList(fast);
-		return merge(slow, fast);
-	}
+  public ListNode sortList(ListNode head) {
+    if (head == null || head.next == null) return head;
+    ListNode fast = head;
+    ListNode slow = head;
+    while (fast.next != null && fast.next.next != null) {
+      fast = fast.next.next;
+      slow = slow.next;
+    }
+    fast = slow.next;
+    slow.next = null;
+    slow = sortList(head);
+    fast = sortList(fast);
+    return merge(slow, fast);
+  }
 
-	private ListNode merge(ListNode slow, ListNode fast) {
-		ListNode head = new ListNode(0);
-		ListNode cur = head;
-		while (slow != null && fast != null) {
-			if (slow.val < fast.val) {
-				cur.next = slow;
-				slow = slow.next;
-			} else {
-				cur.next = fast;
-				fast = fast.next;
-			}
-			cur = cur.next;
-		}
-		if (slow != null) {
-			cur.next = slow;
-		} else if (fast != null) {
-			cur.next = fast;
-		}
-		return head.next;
-	}
+  private ListNode merge(ListNode slow, ListNode fast) {
+    ListNode head = new ListNode(0);
+    ListNode cur = head;
+    while (slow != null && fast != null) {
+      if (slow.val < fast.val) {
+        cur.next = slow;
+        slow = slow.next;
+      } else {
+        cur.next = fast;
+        fast = fast.next;
+      }
+      cur = cur.next;
+    }
+    if (slow != null) {
+      cur.next = slow;
+    } else if (fast != null) {
+      cur.next = fast;
+    }
+    return head.next;
+  }
 }
diff --git a/SpiralMatrix.java b/SpiralMatrix.java
index 74d0eb1..2766786 100644
--- a/SpiralMatrix.java
+++ b/SpiralMatrix.java
@@ -1,51 +1,39 @@
-
-
 import java.util.ArrayList;
 
 /**
- * Given a matrix of m x n elements (m rows, n columns), return all elements of
- * the matrix in spiral order.
- * 
- * For example, Given the following matrix:
- * 
- * [ 
- *   [ 1, 2, 3 ],
- *   [ 4, 5, 6 ],
- *   [ 7, 8, 9 ]
- * ]
- * 
- * You should return [1,2,3,6,9,8,7,4,5].
+ * Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral
+ * order.
+ *
+ * <p>For example, Given the following matrix:
+ *
+ * <p>[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]
+ *
+ * <p>You should return [1,2,3,6,9,8,7,4,5].
  */
-
 public class SpiralMatrix {
-	public ArrayList<Integer> spiralOrder(int[][] matrix) {
-		ArrayList<Integer> list = new ArrayList<Integer>();
-		if (matrix.length == 0)
-			return list;
-		int beginX = 0, endX = matrix.length - 1;
-		int beginY = 0, endY = matrix[0].length - 1;
-		while (true) {
-			for (int i = beginY; i <= endY; i++) {
-				list.add(matrix[beginX][i]);
-			}
-			if (++beginX > endX)
-				break;
-			for (int i = beginX; i <= endX; i++) {
-				list.add(matrix[i][endY]);
-			}
-			if (beginY > --endY)
-				break;
-			for (int i = endY; i >= beginY; i--) {
-				list.add(matrix[endX][i]);
-			}
-			if (beginX > --endX)
-				break;
-			for (int i = endX; i >= beginX; i--) {
-				list.add(matrix[i][beginY]);
-			}
-			if (++beginY > endY)
-				break;
-		}
-		return list;
-	}
-}
\ No newline at end of file
+  public ArrayList<Integer> spiralOrder(int[][] matrix) {
+    ArrayList<Integer> list = new ArrayList<Integer>();
+    if (matrix.length == 0) return list;
+    int beginX = 0, endX = matrix.length - 1;
+    int beginY = 0, endY = matrix[0].length - 1;
+    while (true) {
+      for (int i = beginY; i <= endY; i++) {
+        list.add(matrix[beginX][i]);
+      }
+      if (++beginX > endX) break;
+      for (int i = beginX; i <= endX; i++) {
+        list.add(matrix[i][endY]);
+      }
+      if (beginY > --endY) break;
+      for (int i = endY; i >= beginY; i--) {
+        list.add(matrix[endX][i]);
+      }
+      if (beginX > --endX) break;
+      for (int i = endX; i >= beginX; i--) {
+        list.add(matrix[i][beginY]);
+      }
+      if (++beginY > endY) break;
+    }
+    return list;
+  }
+}
diff --git a/Sqrtx.java b/Sqrtx.java
index 95e120e..614f791 100644
--- a/Sqrtx.java
+++ b/Sqrtx.java
@@ -1,26 +1,25 @@
 /**
  * Implement int sqrt(int x).
- * 
- * Compute and return the square root of x.
+ *
+ * <p>Compute and return the square root of x.
  */
-
 public class Sqrtx {
-	public int sqrt(int x) {
-        if (x == 0 || x == 1) return x;
-        long low = 1;
-        long high = x;
-        long mid = 0;
-        while (low <= high) {
-            mid = (low + high) / 2;
-            if (mid * mid <= x && (mid + 1) * (mid + 1) > x) {
-            	break;
-            }
-            if (mid * mid > x) {
-                high = mid - 1;
-            } else {
-                low = mid + 1;
-            }
-        }
-        return new Long(mid).intValue();
+  public int sqrt(int x) {
+    if (x == 0 || x == 1) return x;
+    long low = 1;
+    long high = x;
+    long mid = 0;
+    while (low <= high) {
+      mid = (low + high) / 2;
+      if (mid * mid <= x && (mid + 1) * (mid + 1) > x) {
+        break;
+      }
+      if (mid * mid > x) {
+        high = mid - 1;
+      } else {
+        low = mid + 1;
+      }
     }
-}
\ No newline at end of file
+    return new Long(mid).intValue();
+  }
+}
diff --git a/StringtoIntegerAtoi.java b/StringtoIntegerAtoi.java
index c8d7803..eeb0057 100644
--- a/StringtoIntegerAtoi.java
+++ b/StringtoIntegerAtoi.java
@@ -1,70 +1,64 @@
-
-
 /**
  * Implement atoi to convert a string to an integer.
- * 
- * Hint: 
- * 
- * Carefully consider all possible input cases. If you want a challenge,
- * please do not see below and ask yourself what are the possible input cases.
- * 
- * Notes: 
- * 
- * It is intended for this problem to be specified vaguely (ie, no given
- * input specs). You are responsible to gather all the input requirements up front.
- * 
- * Requirements for atoi: The function first discards as many whitespace
- * characters as necessary until the first non-whitespace character is found.
- * Then, starting from this character, takes an optional initial plus or minus
- * sign followed by as many numerical digits as possible, and interprets them as
- * a numerical value.
- * 
- * The string can contain additional characters after those that form the
- * integral number, which are ignored and have no effect on the behavior of this
- * function.
- * 
- * If the first sequence of non-whitespace characters in str is not a valid
- * integral number, or if no such sequence exists because either str is empty or
- * it contains only whitespace characters, no conversion is performed.
- * 
- * If no valid conversion could be performed, a zero value is returned. If the
- * correct value is out of the range of representable values, INT_MAX
- * (2147483647) or INT_MIN (-2147483648) is returned.
+ *
+ * <p>Hint:
+ *
+ * <p>Carefully consider all possible input cases. If you want a challenge, please do not see below
+ * and ask yourself what are the possible input cases.
+ *
+ * <p>Notes:
+ *
+ * <p>It is intended for this problem to be specified vaguely (ie, no given input specs). You are
+ * responsible to gather all the input requirements up front.
+ *
+ * <p>Requirements for atoi: The function first discards as many whitespace characters as necessary
+ * until the first non-whitespace character is found. Then, starting from this character, takes an
+ * optional initial plus or minus sign followed by as many numerical digits as possible, and
+ * interprets them as a numerical value.
+ *
+ * <p>The string can contain additional characters after those that form the integral number, which
+ * are ignored and have no effect on the behavior of this function.
+ *
+ * <p>If the first sequence of non-whitespace characters in str is not a valid integral number, or
+ * if no such sequence exists because either str is empty or it contains only whitespace characters,
+ * no conversion is performed.
+ *
+ * <p>If no valid conversion could be performed, a zero value is returned. If the correct value is
+ * out of the range of representable values, INT_MAX (2147483647) or INT_MIN (-2147483648) is
+ * returned.
  */
-
 public class StringtoIntegerAtoi {
-	public int atoi(String str) {
-		str = str.trim();
-		int length = str.length();
-		if (length == 0)
-			return 0;
-		int i = 0;
-		boolean minus = false;
-		if (str.charAt(0) == '-') {
-			minus = true;
-			i++;
-		} else if (str.charAt(0) == '+') {
-			i++;
-		}
-		long MIN_VALUE = Integer.MIN_VALUE;
-		long MAX_VALUE = Integer.MAX_VALUE;
-		long num = 0;
-		boolean finished = false;
-		for (; i < length && !finished; i++) {
-			char c = str.charAt(i);
-			if (c >= '0' && c <= '9') {
-				num *= 10;
-				num += c - '0';
-			} else {
-				finished = true;
-			}
-			if (minus && 0 - num < MIN_VALUE) {
-				return Integer.MIN_VALUE;
-			}
-			if (!minus && num > MAX_VALUE) {
-				return Integer.MAX_VALUE;
-			}
-		}
-		return minus ? new Long(0 - num).intValue() : new Long(num).intValue();
-	}
-}
\ No newline at end of file
+  public int atoi(String str) {
+    str = str.trim();
+    int length = str.length();
+    if (length == 0) return 0;
+    int i = 0;
+    boolean minus = false;
+    if (str.charAt(0) == '-') {
+      minus = true;
+      i++;
+    } else if (str.charAt(0) == '+') {
+      i++;
+    }
+    long MIN_VALUE = Integer.MIN_VALUE;
+    long MAX_VALUE = Integer.MAX_VALUE;
+    long num = 0;
+    boolean finished = false;
+    for (; i < length && !finished; i++) {
+      char c = str.charAt(i);
+      if (c >= '0' && c <= '9') {
+        num *= 10;
+        num += c - '0';
+      } else {
+        finished = true;
+      }
+      if (minus && 0 - num < MIN_VALUE) {
+        return Integer.MIN_VALUE;
+      }
+      if (!minus && num > MAX_VALUE) {
+        return Integer.MAX_VALUE;
+      }
+    }
+    return minus ? new Long(0 - num).intValue() : new Long(num).intValue();
+  }
+}
diff --git a/Subsets.java b/Subsets.java
index 646f6e5..7e6811d 100644
--- a/Subsets.java
+++ b/Subsets.java
@@ -1,32 +1,27 @@
-
-
 import java.util.ArrayList;
 import java.util.Arrays;
 
 /**
  * Given a set of distinct integers, S, return all possible subsets.
- * 
- * Note: Elements in a subset must be in non-descending order. The solution set
- * must not contain duplicate subsets. For example, If S = [1,2,3], a solution
- * is:
- * 
- * [ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], [] ]
+ *
+ * <p>Note: Elements in a subset must be in non-descending order. The solution set must not contain
+ * duplicate subsets. For example, If S = [1,2,3], a solution is:
+ *
+ * <p>[ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], [] ]
  */
-
 public class Subsets {
-	public ArrayList<ArrayList<Integer>> subsets(int[] S) {
-		Arrays.sort(S);
-		ArrayList<ArrayList<Integer>> subsets = new ArrayList<ArrayList<Integer>>();
-		subsets.add(new ArrayList<Integer>());
-		for (int i = 0; i < S.length; i++) {
-			int size = subsets.size();
-			for (int j = 0; j < size; j++) {
-				ArrayList<Integer> subset = new ArrayList<Integer>(
-						subsets.get(j));
-				subset.add(S[i]);
-				subsets.add(subset);
-			}
-		}
-		return subsets;
-	}
-}
\ No newline at end of file
+  public ArrayList<ArrayList<Integer>> subsets(int[] S) {
+    Arrays.sort(S);
+    ArrayList<ArrayList<Integer>> subsets = new ArrayList<ArrayList<Integer>>();
+    subsets.add(new ArrayList<Integer>());
+    for (int i = 0; i < S.length; i++) {
+      int size = subsets.size();
+      for (int j = 0; j < size; j++) {
+        ArrayList<Integer> subset = new ArrayList<Integer>(subsets.get(j));
+        subset.add(S[i]);
+        subsets.add(subset);
+      }
+    }
+    return subsets;
+  }
+}
diff --git a/SubsetsII.java b/SubsetsII.java
index cf17ed5..8724d78 100644
--- a/SubsetsII.java
+++ b/SubsetsII.java
@@ -2,35 +2,32 @@
 import java.util.Arrays;
 
 /**
- * Given a collection of integers that might contain duplicates, S, return all
- * possible subsets.
- * 
- * Note: 
- * 
- * Elements in a subset must be in non-descending order. The solution set
- * must not contain duplicate subsets. For example, If S = [1,2,2], a solution
- * is:
- * 
- * [ [2], [1], [1,2,2], [2,2], [1,2], [] ]
+ * Given a collection of integers that might contain duplicates, S, return all possible subsets.
+ *
+ * <p>Note:
+ *
+ * <p>Elements in a subset must be in non-descending order. The solution set must not contain
+ * duplicate subsets. For example, If S = [1,2,2], a solution is:
+ *
+ * <p>[ [2], [1], [1,2,2], [2,2], [1,2], [] ]
  */
-
 public class SubsetsII {
-	public ArrayList<ArrayList<Integer>> subsetsWithDup(int[] num) {
-		ArrayList<ArrayList<Integer>> ret = new ArrayList<ArrayList<Integer>>();
-		ArrayList<ArrayList<Integer>> lastLevel = null;
-		ret.add(new ArrayList<Integer>());
-		Arrays.sort(num);
-		for (int i = 0; i < num.length; i++) {
-			ArrayList<ArrayList<Integer>> tmp = new ArrayList<ArrayList<Integer>>();
-			ArrayList<ArrayList<Integer>> prev = i == 0 || num[i] != num[i - 1] ? ret : lastLevel;
-			for (ArrayList<Integer> s : prev) {
-				ArrayList<Integer> newSet = new ArrayList<Integer>(s);
-				newSet.add(num[i]);
-				tmp.add(newSet);
-			}
-			ret.addAll(tmp);
-			lastLevel = tmp;
-		}
-		return ret;
-	}
-}
\ No newline at end of file
+  public ArrayList<ArrayList<Integer>> subsetsWithDup(int[] num) {
+    ArrayList<ArrayList<Integer>> ret = new ArrayList<ArrayList<Integer>>();
+    ArrayList<ArrayList<Integer>> lastLevel = null;
+    ret.add(new ArrayList<Integer>());
+    Arrays.sort(num);
+    for (int i = 0; i < num.length; i++) {
+      ArrayList<ArrayList<Integer>> tmp = new ArrayList<ArrayList<Integer>>();
+      ArrayList<ArrayList<Integer>> prev = i == 0 || num[i] != num[i - 1] ? ret : lastLevel;
+      for (ArrayList<Integer> s : prev) {
+        ArrayList<Integer> newSet = new ArrayList<Integer>(s);
+        newSet.add(num[i]);
+        tmp.add(newSet);
+      }
+      ret.addAll(tmp);
+      lastLevel = tmp;
+    }
+    return ret;
+  }
+}
diff --git a/SubstringwithConcatenationofAllWords.java b/SubstringwithConcatenationofAllWords.java
index 1cc5567..03aa60e 100644
--- a/SubstringwithConcatenationofAllWords.java
+++ b/SubstringwithConcatenationofAllWords.java
@@ -1,71 +1,63 @@
-
-
 import java.util.ArrayList;
 import java.util.HashMap;
 
 /**
- * You are given a string, S, and a list of words, L, that are all of the same
- * length. Find all starting indices of substring(s) in S that is a
- * concatenation of each word in L exactly once and without any intervening
- * characters.
- * 
- * For example, given: S: "barfoothefoobarman" L: ["foo", "bar"]
- * 
- * You should return the indices: [0,9]. (order does not matter).
+ * You are given a string, S, and a list of words, L, that are all of the same length. Find all
+ * starting indices of substring(s) in S that is a concatenation of each word in L exactly once and
+ * without any intervening characters.
+ *
+ * <p>For example, given: S: "barfoothefoobarman" L: ["foo", "bar"]
+ *
+ * <p>You should return the indices: [0,9]. (order does not matter).
  */
-
 public class SubstringwithConcatenationofAllWords {
-	public ArrayList<Integer> findSubstring(String S, String[] L) {
-		int slen = S.length();
-		int m = L.length;
-		ArrayList<Integer> ret = new ArrayList<Integer>();
-		if (m == 0)
-			return ret;
-		int n = L[0].length();
-		HashMap<String, Integer> smap = new HashMap<String, Integer>();
-		for (String s : L) {
-			if (smap.containsKey(s)) {
-				smap.put(s, smap.get(s).intValue() + 1);
-			} else {
-				smap.put(s, 1);
-			}
-		}
-		if (m * n > slen)
-			return ret;
-		int start = 0, end = m * n - 1;
-		int index = 0;
-		while (end < slen) {
-			index = check(S, start, end, m, n, L, smap);
-			if (index >= 0)
-				ret.add(index);
-			start++;
-			end++;
-		}
-		return ret;
-	}
+  public ArrayList<Integer> findSubstring(String S, String[] L) {
+    int slen = S.length();
+    int m = L.length;
+    ArrayList<Integer> ret = new ArrayList<Integer>();
+    if (m == 0) return ret;
+    int n = L[0].length();
+    HashMap<String, Integer> smap = new HashMap<String, Integer>();
+    for (String s : L) {
+      if (smap.containsKey(s)) {
+        smap.put(s, smap.get(s).intValue() + 1);
+      } else {
+        smap.put(s, 1);
+      }
+    }
+    if (m * n > slen) return ret;
+    int start = 0, end = m * n - 1;
+    int index = 0;
+    while (end < slen) {
+      index = check(S, start, end, m, n, L, smap);
+      if (index >= 0) ret.add(index);
+      start++;
+      end++;
+    }
+    return ret;
+  }
 
-	private int check(String s, int start, int end, int m, int n, String[] L,
-			HashMap<String, Integer> smap) {
-		HashMap<String, Integer> exitMap = new HashMap<String, Integer>();
-		int sidx = start;
-		while (sidx <= end) {
-			String k = s.substring(sidx, sidx + n);
-			if (smap.containsKey(k)) {
-				if (exitMap.containsKey(k)) {
-					Integer i = exitMap.get(k);
-					if (i == smap.get(k))
-						return -1;
-					else {
-						exitMap.put(k, i + 1);
-					}
-				} else {
-					exitMap.put(k, 1);
-				}
-				sidx += n;
-			} else {
-				return -1;
-			}
-		}
-		return start;
-	}
-}
\ No newline at end of file
+  private int check(
+      String s, int start, int end, int m, int n, String[] L, HashMap<String, Integer> smap) {
+    HashMap<String, Integer> exitMap = new HashMap<String, Integer>();
+    int sidx = start;
+    while (sidx <= end) {
+      String k = s.substring(sidx, sidx + n);
+      if (smap.containsKey(k)) {
+        if (exitMap.containsKey(k)) {
+          Integer i = exitMap.get(k);
+          if (i == smap.get(k)) return -1;
+          else {
+            exitMap.put(k, i + 1);
+          }
+        } else {
+          exitMap.put(k, 1);
+        }
+        sidx += n;
+      } else {
+        return -1;
+      }
+    }
+    return start;
+  }
+}
diff --git a/SumRoottoLeafNumbers.java b/SumRoottoLeafNumbers.java
index c2d0d8b..5f8536a 100644
--- a/SumRoottoLeafNumbers.java
+++ b/SumRoottoLeafNumbers.java
@@ -1,42 +1,36 @@
-
-
-/** 
- * Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.
+/**
+ * Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a
+ * number.
  *
- * An example is the root-to-leaf path 1->2->3 which represents the number 123.
+ * <p>An example is the root-to-leaf path 1->2->3 which represents the number 123.
  *
- * Find the total sum of all root-to-leaf numbers.
+ * <p>Find the total sum of all root-to-leaf numbers.
  *
- * For example,
+ * <p>For example,
  *
- *   1
- *  / \
- * 2   3
- * The root-to-leaf path 1->2 represents the number 12.
- * The root-to-leaf path 1->3 represents the number 13.
+ * <p>1 / \ 2 3 The root-to-leaf path 1->2 represents the number 12. The root-to-leaf path 1->3
+ * represents the number 13.
  *
- * Return the sum = 12 + 13 = 25.
+ * <p>Return the sum = 12 + 13 = 25.
  */
-
 public class SumRoottoLeafNumbers {
-	public int sumNumbers(TreeNode root) {
-		if (root == null) {
-			return 0;
-		} else {
-			return sum(root, 0);
-		}
-	}
+  public int sumNumbers(TreeNode root) {
+    if (root == null) {
+      return 0;
+    } else {
+      return sum(root, 0);
+    }
+  }
 
-	public int sum(TreeNode root, int prev) {
-		if (root.left == null && root.right == null) {
-			return 10 * prev + root.val;
-		} else if (root.left != null && root.right != null) {
-			return sum(root.left, 10 * prev + root.val)
-					+ sum(root.right, 10 * prev + root.val);
-		} else if (root.left != null) {
-			return sum(root.left, 10 * prev + root.val);
-		} else {
-			return sum(root.right, 10 * prev + root.val);
-		}
-	}
-}
\ No newline at end of file
+  public int sum(TreeNode root, int prev) {
+    if (root.left == null && root.right == null) {
+      return 10 * prev + root.val;
+    } else if (root.left != null && root.right != null) {
+      return sum(root.left, 10 * prev + root.val) + sum(root.right, 10 * prev + root.val);
+    } else if (root.left != null) {
+      return sum(root.left, 10 * prev + root.val);
+    } else {
+      return sum(root.right, 10 * prev + root.val);
+    }
+  }
+}
diff --git a/SurroundedRegions.java b/SurroundedRegions.java
index 287bb83..8597a5e 100644
--- a/SurroundedRegions.java
+++ b/SurroundedRegions.java
@@ -1,73 +1,61 @@
-
-
 import java.util.LinkedList;
 import java.util.Queue;
 
-/** 
+/**
  * Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.
  *
- * A region is captured by flipping all 'O's into 'X's in that surrounded region .
+ * <p>A region is captured by flipping all 'O's into 'X's in that surrounded region .
  *
- * For example,
+ * <p>For example,
  *
- * X X X X
- * X O O X
- * X X O X
- * X O X X
- * After running your function, the board should be:
+ * <p>X X X X X O O X X X O X X O X X After running your function, the board should be:
  *
- * X X X X
- * X X X X
- * X X X X
- * X O X X
+ * <p>X X X X X X X X X X X X X O X X
  */
-
 public class SurroundedRegions {
-	public void solve(char[][] board) {
-		int row = board.length;
-		if (row == 0)
-			return;
-		int col = board[0].length;
-		Queue<Integer> qx = new LinkedList<Integer>();
-		Queue<Integer> qy = new LinkedList<Integer>();
-		for (int i = 0; i < row; i++) {
-			for (int j = 0; j < col; j++) {
-				if ((i == 0 || i == row - 1 || j == 0 || j == col - 1)
-						&& board[i][j] == 'O') {
-					qx.add(i);
-					qy.add(j);
-				}
-			}
-		}
-		while (!qx.isEmpty()) {
-			int x = qx.remove();
-			int y = qy.remove();
-			board[x][y] = '@';
-			if (x > 0 && board[x - 1][y] == 'O') {
-				qx.add(x - 1);
-				qy.add(y);
-			}
-			if (x < row - 1 && board[x + 1][y] == 'O') {
-				qx.add(x + 1);
-				qy.add(y);
-			}
-			if (y > 0 && board[x][y - 1] == 'O') {
-				qx.add(x);
-				qy.add(y - 1);
-			}
-			if (y < col - 1 && board[x][y + 1] == 'O') {
-				qx.add(x);
-				qy.add(y + 1);
-			}
-		}
-		for (int i = 0; i < row; i++) {
-			for (int j = 0; j < col; j++) {
-				if (board[i][j] == '@') {
-					board[i][j] = 'O';
-				} else {
-					board[i][j] = 'X';
-				}
-			}
-		}
-	}
-}
\ No newline at end of file
+  public void solve(char[][] board) {
+    int row = board.length;
+    if (row == 0) return;
+    int col = board[0].length;
+    Queue<Integer> qx = new LinkedList<Integer>();
+    Queue<Integer> qy = new LinkedList<Integer>();
+    for (int i = 0; i < row; i++) {
+      for (int j = 0; j < col; j++) {
+        if ((i == 0 || i == row - 1 || j == 0 || j == col - 1) && board[i][j] == 'O') {
+          qx.add(i);
+          qy.add(j);
+        }
+      }
+    }
+    while (!qx.isEmpty()) {
+      int x = qx.remove();
+      int y = qy.remove();
+      board[x][y] = '@';
+      if (x > 0 && board[x - 1][y] == 'O') {
+        qx.add(x - 1);
+        qy.add(y);
+      }
+      if (x < row - 1 && board[x + 1][y] == 'O') {
+        qx.add(x + 1);
+        qy.add(y);
+      }
+      if (y > 0 && board[x][y - 1] == 'O') {
+        qx.add(x);
+        qy.add(y - 1);
+      }
+      if (y < col - 1 && board[x][y + 1] == 'O') {
+        qx.add(x);
+        qy.add(y + 1);
+      }
+    }
+    for (int i = 0; i < row; i++) {
+      for (int j = 0; j < col; j++) {
+        if (board[i][j] == '@') {
+          board[i][j] = 'O';
+        } else {
+          board[i][j] = 'X';
+        }
+      }
+    }
+  }
+}
diff --git a/SwapNodesinPairs.java b/SwapNodesinPairs.java
index 50ae596..58b39d1 100644
--- a/SwapNodesinPairs.java
+++ b/SwapNodesinPairs.java
@@ -1,27 +1,24 @@
-
-
-/** 
+/**
  * Given a linked list, swap every two adjacent nodes and return its head.
  *
- * For example,
- * 
- * Given 1->2->3->4, you should return the list as 2->1->4->3.
+ * <p>For example,
  *
- * Your algorithm should use only constant space. You may not modify the values in the list, only nodes itself can be changed.
+ * <p>Given 1->2->3->4, you should return the list as 2->1->4->3.
+ *
+ * <p>Your algorithm should use only constant space. You may not modify the values in the list, only
+ * nodes itself can be changed.
  */
-
 public class SwapNodesinPairs {
-	public ListNode swapPairs(ListNode head) {
-		if (head == null)
-			return null;
-		else if (head.next == null) {
-			return head;
-		} else {
-			ListNode nextList = swapPairs(head.next.next);
-			ListNode tmp = head.next;
-			head.next = nextList;
-			tmp.next = head;
-			return tmp;
-		}
-	}
-}
\ No newline at end of file
+  public ListNode swapPairs(ListNode head) {
+    if (head == null) return null;
+    else if (head.next == null) {
+      return head;
+    } else {
+      ListNode nextList = swapPairs(head.next.next);
+      ListNode tmp = head.next;
+      head.next = nextList;
+      tmp.next = head;
+      return tmp;
+    }
+  }
+}
diff --git a/SymmetricTree.java b/SymmetricTree.java
index 8101192..f2730c3 100644
--- a/SymmetricTree.java
+++ b/SymmetricTree.java
@@ -3,48 +3,35 @@
 /**
  * Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
  *
- * For example, this binary tree is symmetric:
+ * <p>For example, this binary tree is symmetric:
  *
- *     1
- *    / \
- *   2   2
- *  / \ / \
- * 3  4 4  3
- * But the following is not:
- *     1
- *    / \
- *   2   2
- *   \   \
- *   3    3
- * Note:
- * 
- * Bonus points if you could solve it both recursively and iteratively.
+ * <p>1 / \ 2 2 / \ / \ 3 4 4 3 But the following is not: 1 / \ 2 2 \ \ 3 3 Note:
+ *
+ * <p>Bonus points if you could solve it both recursively and iteratively.
  */
-
 public class SymmetricTree {
-	public boolean isSymmetric(TreeNode root) {
-		if (root == null)
-			return true;
-		Stack<TreeNode> s1 = new Stack<TreeNode>();
-		Stack<TreeNode> s2 = new Stack<TreeNode>();
-		s1.push(root.left);
-		s2.push(root.right);
-		while (!s1.isEmpty() && !s2.isEmpty()) {
-			TreeNode n1 = s1.pop();
-			TreeNode n2 = s2.pop();
-			if (n1 == null && n2 == null) {
-				continue;
-			} else if (n1 == null || n2 == null) {
-				return false;
-			} else if (n1.val != n2.val) {
-				return false;
-			} else {
-				s1.push(n1.left);
-				s1.push(n1.right);
-				s2.push(n2.right);
-				s2.push(n2.left);
-			}
-		}
-		return true;
-	}
-}
\ No newline at end of file
+  public boolean isSymmetric(TreeNode root) {
+    if (root == null) return true;
+    Stack<TreeNode> s1 = new Stack<TreeNode>();
+    Stack<TreeNode> s2 = new Stack<TreeNode>();
+    s1.push(root.left);
+    s2.push(root.right);
+    while (!s1.isEmpty() && !s2.isEmpty()) {
+      TreeNode n1 = s1.pop();
+      TreeNode n2 = s2.pop();
+      if (n1 == null && n2 == null) {
+        continue;
+      } else if (n1 == null || n2 == null) {
+        return false;
+      } else if (n1.val != n2.val) {
+        return false;
+      } else {
+        s1.push(n1.left);
+        s1.push(n1.right);
+        s2.push(n2.right);
+        s2.push(n2.left);
+      }
+    }
+    return true;
+  }
+}
diff --git a/TextJustification.java b/TextJustification.java
index 1a8c522..4c0f1b7 100644
--- a/TextJustification.java
+++ b/TextJustification.java
@@ -1,59 +1,59 @@
 import java.util.ArrayList;
 
 public class TextJustification {
-	public ArrayList<String> fullJustify(String[] words, int L) {
-		ArrayList<String> ret = new ArrayList<String>();
-		int length = words.length;
-		if (length == 0) return ret;
-		int start = 0, end = start;
-		int len = 0;
-		while (start < length) {
-			StringBuffer line = new StringBuffer();
-			while (end < length) {
-				int sl = words[end].length();
-				if (len + (end - start) + sl > L) {
-					break;
-				}
-				len += sl;
-				end++;
-			}
-			end--;
-			if (end < start) {
-				end = start;
-			}
-			if (start == end) {
-				line.append(words[start]);
-				int spaceCount = L - words[start].length();
-				for (int i = 0; i < spaceCount; i++) {
-					line.append(' ');
-				}
-				ret.add(line.toString());
-			} else {
-				boolean lastLine = end == length - 1;
-				int spaceBase = lastLine ? 1 : (L - len) / (end - start);
-				int bonus = lastLine ? 0 : L - len - spaceBase * (end - start);
-				line.append(words[start]);
-				for (int i = start + 1; i <= end; i++) {
-					for (int j = 0; j < spaceBase; j++) {
-						line.append(' ');
-					}
-					if (bonus > 0) {
-						line.append(' ');
-						bonus--;
-					}
-					line.append(words[i]);
-				}
-				if (lastLine) {
-					for (int i = 0; i < L - len - (end - start); i++) {
-						line.append(' ');
-					}
-				}
-				ret.add(line.toString());
-			}
-			start = end + 1;
-			end = start;
-			len = 0;
-		}
-		return ret;
-	}
+  public ArrayList<String> fullJustify(String[] words, int L) {
+    ArrayList<String> ret = new ArrayList<String>();
+    int length = words.length;
+    if (length == 0) return ret;
+    int start = 0, end = start;
+    int len = 0;
+    while (start < length) {
+      StringBuffer line = new StringBuffer();
+      while (end < length) {
+        int sl = words[end].length();
+        if (len + (end - start) + sl > L) {
+          break;
+        }
+        len += sl;
+        end++;
+      }
+      end--;
+      if (end < start) {
+        end = start;
+      }
+      if (start == end) {
+        line.append(words[start]);
+        int spaceCount = L - words[start].length();
+        for (int i = 0; i < spaceCount; i++) {
+          line.append(' ');
+        }
+        ret.add(line.toString());
+      } else {
+        boolean lastLine = end == length - 1;
+        int spaceBase = lastLine ? 1 : (L - len) / (end - start);
+        int bonus = lastLine ? 0 : L - len - spaceBase * (end - start);
+        line.append(words[start]);
+        for (int i = start + 1; i <= end; i++) {
+          for (int j = 0; j < spaceBase; j++) {
+            line.append(' ');
+          }
+          if (bonus > 0) {
+            line.append(' ');
+            bonus--;
+          }
+          line.append(words[i]);
+        }
+        if (lastLine) {
+          for (int i = 0; i < L - len - (end - start); i++) {
+            line.append(' ');
+          }
+        }
+        ret.add(line.toString());
+      }
+      start = end + 1;
+      end = start;
+      len = 0;
+    }
+    return ret;
+  }
 }
diff --git a/ThreeSum.java b/ThreeSum.java
index 3d1f784..1cd3315 100644
--- a/ThreeSum.java
+++ b/ThreeSum.java
@@ -1,59 +1,55 @@
-
-
 import java.util.ArrayList;
 import java.util.Arrays;
 
 /**
- * Given an array S of n integers, are there elements a, b, c in S such that a +
- * b + c = 0? Find all unique triplets in the array which gives the sum of zero.
- * 
- * Note:
- * 
- * Elements in a triplet (a,b,c) must be in non-descending order. (ie, a ? b ?
- * c) The solution set must not contain duplicate triplets.
- * 
- * For example, given array S = {-1 0 1 2 -1 -4},
- * 
- * A solution set is: (-1, 0, 1) (-1, -1, 2)
+ * Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all
+ * unique triplets in the array which gives the sum of zero.
+ *
+ * <p>Note:
+ *
+ * <p>Elements in a triplet (a,b,c) must be in non-descending order. (ie, a ? b ? c) The solution
+ * set must not contain duplicate triplets.
+ *
+ * <p>For example, given array S = {-1 0 1 2 -1 -4},
+ *
+ * <p>A solution set is: (-1, 0, 1) (-1, -1, 2)
  */
-
 public class ThreeSum {
-	public ArrayList<ArrayList<Integer>> threeSum(int[] num) {
-		ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>();
-		Arrays.sort(num);
-		int a, b, c, k, l;
-		for (int i = 0; i <= num.length - 3; i++) {
-			if (i > 0 && num[i] == num[i - 1])
-				continue;
-			a = num[i];
-			k = i + 1;
-			l = num.length - 1;
-			while (k < l) {
-				b = num[k];
-				c = num[l];
-				if (a + b + c == 0) {
-					if (k != i + 1 && num[k] == num[k - 1]) {
-						k++;
-						continue;
-					}
-					if (l != num.length - 1 && num[l] == num[l + 1]) {
-						l--;
-						continue;
-					}
-					ArrayList<Integer> item = new ArrayList<Integer>();
-					item.add(a);
-					item.add(b);
-					item.add(c);
-					result.add(item);
-					l--;
-					k++;
-				} else if (a + b + c > 0) {
-					l--;
-				} else {
-					k++;
-				}
-			}
-		}
-		return result;
-	}
-}
\ No newline at end of file
+  public ArrayList<ArrayList<Integer>> threeSum(int[] num) {
+    ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>();
+    Arrays.sort(num);
+    int a, b, c, k, l;
+    for (int i = 0; i <= num.length - 3; i++) {
+      if (i > 0 && num[i] == num[i - 1]) continue;
+      a = num[i];
+      k = i + 1;
+      l = num.length - 1;
+      while (k < l) {
+        b = num[k];
+        c = num[l];
+        if (a + b + c == 0) {
+          if (k != i + 1 && num[k] == num[k - 1]) {
+            k++;
+            continue;
+          }
+          if (l != num.length - 1 && num[l] == num[l + 1]) {
+            l--;
+            continue;
+          }
+          ArrayList<Integer> item = new ArrayList<Integer>();
+          item.add(a);
+          item.add(b);
+          item.add(c);
+          result.add(item);
+          l--;
+          k++;
+        } else if (a + b + c > 0) {
+          l--;
+        } else {
+          k++;
+        }
+      }
+    }
+    return result;
+  }
+}
diff --git a/ThreeSumClosest.java b/ThreeSumClosest.java
index b4df24c..95f2ecc 100644
--- a/ThreeSumClosest.java
+++ b/ThreeSumClosest.java
@@ -1,48 +1,46 @@
 import java.util.Arrays;
 
 /**
- * Given an array S of n integers, find three integers in S such that the sum is
- * closest to a given number, target. Return the sum of the three integers. You
- * may assume that each input would have exactly one solution.
- * 
- * For example, given array S = {-1 2 1 -4}, and target = 1. The sum that is
- * closest to the target is 2. (-1 + 2 + 1 = 2).
- * 
+ * Given an array S of n integers, find three integers in S such that the sum is closest to a given
+ * number, target. Return the sum of the three integers. You may assume that each input would have
+ * exactly one solution.
+ *
+ * <p>For example, given array S = {-1 2 1 -4}, and target = 1. The sum that is closest to the
+ * target is 2. (-1 + 2 + 1 = 2).
  */
 public class ThreeSumClosest {
-	public int threeSumClosest(int[] num, int target) {
-		int dis = Integer.MAX_VALUE;
-		int ret = 0;
-		Arrays.sort(num);
-		int length = num.length;
-		for (int i = 0; i < length - 2; i++) {
-			int j = i + 1;
-			int k = length - 1;
-			while (j < k) {
-				if (j > i + 1 && num[j] == num[j - 1]) {
-					j++;
-					continue;
-				}
-				if (k < length - 1 && num[k] == num[k + 1]) {
-					k--;
-					continue;
-				}
-				int sum = num[i] + num[j] + num[k];
-				int minus = sum - target;
-				int d = Math.abs(minus);
-				if (d < dis) {
-					dis = d;
-					ret = sum;
-				}
-				if (minus == 0)
-					return target;
-				if (minus < 0) {
-					j++;
-				} else {
-					k--;
-				}
-			}
-		}
-		return ret;
-	}
+  public int threeSumClosest(int[] num, int target) {
+    int dis = Integer.MAX_VALUE;
+    int ret = 0;
+    Arrays.sort(num);
+    int length = num.length;
+    for (int i = 0; i < length - 2; i++) {
+      int j = i + 1;
+      int k = length - 1;
+      while (j < k) {
+        if (j > i + 1 && num[j] == num[j - 1]) {
+          j++;
+          continue;
+        }
+        if (k < length - 1 && num[k] == num[k + 1]) {
+          k--;
+          continue;
+        }
+        int sum = num[i] + num[j] + num[k];
+        int minus = sum - target;
+        int d = Math.abs(minus);
+        if (d < dis) {
+          dis = d;
+          ret = sum;
+        }
+        if (minus == 0) return target;
+        if (minus < 0) {
+          j++;
+        } else {
+          k--;
+        }
+      }
+    }
+    return ret;
+  }
 }
diff --git a/TrappingRainWater.java b/TrappingRainWater.java
index 02989ec..3a070ef 100644
--- a/TrappingRainWater.java
+++ b/TrappingRainWater.java
@@ -1,42 +1,36 @@
 /**
- * Given n non-negative integers representing an elevation map where the width
- * of each bar is 1, compute how much water it is able to trap after raining.
- * 
- * For example,
- * 
- * Given [0,1,0,2,1,0,1,3,2,1,2,1], return 6.
- * 
- * The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In
- * this case, 6 units of rain water (blue section) are being trapped. Thanks
- * Marcos for contributing this image!
- * 
+ * Given n non-negative integers representing an elevation map where the width of each bar is 1,
+ * compute how much water it is able to trap after raining.
+ *
+ * <p>For example,
+ *
+ * <p>Given [0,1,0,2,1,0,1,3,2,1,2,1], return 6.
+ *
+ * <p>The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6
+ * units of rain water (blue section) are being trapped. Thanks Marcos for contributing this image!
  */
-
 public class TrappingRainWater {
-	public int trap(int A[], int n) {
-		if (n <= 2)
-			return 0;
+  public int trap(int A[], int n) {
+    if (n <= 2) return 0;
 
-		int[] lmh = new int[n];
-		lmh[0] = 0;
-		int maxh = A[0];
-		for (int i = 1; i < n; ++i) {
-			lmh[i] = maxh;
-			if (maxh < A[i])
-				maxh = A[i];
-		}
-		int trapped = 0;
-		maxh = A[n - 1];
-		for (int i = n - 2; i > 0; --i) {
-			int left = lmh[i];
-			int right = maxh;
-			int container = Math.min(left, right);
-			if (container > A[i]) {
-				trapped += container - A[i];
-			}
-			if (maxh < A[i])
-				maxh = A[i];
-		}
-		return trapped;
-	}
+    int[] lmh = new int[n];
+    lmh[0] = 0;
+    int maxh = A[0];
+    for (int i = 1; i < n; ++i) {
+      lmh[i] = maxh;
+      if (maxh < A[i]) maxh = A[i];
+    }
+    int trapped = 0;
+    maxh = A[n - 1];
+    for (int i = n - 2; i > 0; --i) {
+      int left = lmh[i];
+      int right = maxh;
+      int container = Math.min(left, right);
+      if (container > A[i]) {
+        trapped += container - A[i];
+      }
+      if (maxh < A[i]) maxh = A[i];
+    }
+    return trapped;
+  }
 }
diff --git a/TreeLinkNode.java b/TreeLinkNode.java
index 4911e0b..0f5ab17 100644
--- a/TreeLinkNode.java
+++ b/TreeLinkNode.java
@@ -1,10 +1,8 @@
-
-
 public class TreeLinkNode {
-	int val;
-	TreeLinkNode left, right, next;
+  int val;
+  TreeLinkNode left, right, next;
 
-	TreeLinkNode(int x) {
-		val = x;
-	}
+  TreeLinkNode(int x) {
+    val = x;
+  }
 }
diff --git a/TreeNode.java b/TreeNode.java
index a5a980f..59f58de 100644
--- a/TreeNode.java
+++ b/TreeNode.java
@@ -1,11 +1,9 @@
-
-
 public class TreeNode {
-	int val;
-	TreeNode left;
-	TreeNode right;
+  int val;
+  TreeNode left;
+  TreeNode right;
 
-	TreeNode(int x) {
-		val = x;
-	}
-}
\ No newline at end of file
+  TreeNode(int x) {
+    val = x;
+  }
+}
diff --git a/Triangle.java b/Triangle.java
index c8aef8e..6580aae 100644
--- a/Triangle.java
+++ b/Triangle.java
@@ -1,40 +1,31 @@
-
-
 import java.util.ArrayList;
 
 /**
- * Given a triangle, find the minimum path sum from top to bottom. 
- * 
- * Each step you may move to adjacent numbers on the row below. 
- * 
- * For example, given the following triangle 
- * [   
- *     [2], 
- *    [3,4], 
- *   [6,5,7], 
- *  [4,1,8,3] 
- * ]
- * 
- * The minimum path sum from top to bottom is 11 (i.e., 2 + 3 + 5 + 1 = 11).
- * 
- * Note: 
- * 
- * Bonus point if you are able to do this using only O(n) extra space, where n is the total number of rows in the triangle.
+ * Given a triangle, find the minimum path sum from top to bottom.
+ *
+ * <p>Each step you may move to adjacent numbers on the row below.
+ *
+ * <p>For example, given the following triangle [ [2], [3,4], [6,5,7], [4,1,8,3] ]
+ *
+ * <p>The minimum path sum from top to bottom is 11 (i.e., 2 + 3 + 5 + 1 = 11).
+ *
+ * <p>Note:
+ *
+ * <p>Bonus point if you are able to do this using only O(n) extra space, where n is the total
+ * number of rows in the triangle.
  */
-
 public class Triangle {
-	public int minimumTotal(ArrayList<ArrayList<Integer>> triangle) {
-		int n = triangle.size() - 1;
-		int[] path = new int[triangle.size()];
-		for (int o = 0; o < triangle.get(n).size(); o++) {
-			path[o] = triangle.get(n).get(o);
-		}
-		for (int i = triangle.size() - 2; i >= 0; i--) {
-			for (int j = 0, t = 0; j < triangle.get(i + 1).size() - 1; j++, t++) {
-				path[t] = triangle.get(i).get(t)
-						+ Math.min(path[j], path[j + 1]);
-			}
-		}
-		return path[0];
-	}
-}
\ No newline at end of file
+  public int minimumTotal(ArrayList<ArrayList<Integer>> triangle) {
+    int n = triangle.size() - 1;
+    int[] path = new int[triangle.size()];
+    for (int o = 0; o < triangle.get(n).size(); o++) {
+      path[o] = triangle.get(n).get(o);
+    }
+    for (int i = triangle.size() - 2; i >= 0; i--) {
+      for (int j = 0, t = 0; j < triangle.get(i + 1).size() - 1; j++, t++) {
+        path[t] = triangle.get(i).get(t) + Math.min(path[j], path[j + 1]);
+      }
+    }
+    return path[0];
+  }
+}
diff --git a/TwoSum.java b/TwoSum.java
index e52d66a..c6a03b2 100644
--- a/TwoSum.java
+++ b/TwoSum.java
@@ -1,79 +1,73 @@
-
-
 import java.util.Arrays;
 import java.util.Comparator;
 
 /**
- * Given an array of integers, find two numbers such that they add up to a
- * specific target number.
- * 
- * The function twoSum should return indices of the two numbers such that they
- * add up to the target, where index1 must be less than index2. Please note that
- * your returned answers (both index1 and index2) are not zero-based.
- * 
- * You may assume that each input would have exactly one solution.
- * 
- * Input: numbers={2, 7, 11, 15}, target=9 Output: index1=1, index2=2
+ * Given an array of integers, find two numbers such that they add up to a specific target number.
+ *
+ * <p>The function twoSum should return indices of the two numbers such that they add up to the
+ * target, where index1 must be less than index2. Please note that your returned answers (both
+ * index1 and index2) are not zero-based.
+ *
+ * <p>You may assume that each input would have exactly one solution.
+ *
+ * <p>Input: numbers={2, 7, 11, 15}, target=9 Output: index1=1, index2=2
  */
-
 public class TwoSum {
-	public class Num {
-		private int value;
-		private int index;
+  public class Num {
+    private int value;
+    private int index;
 
-		public Num(int value, int index) {
-			super();
-			this.value = value;
-			this.index = index;
-		}
+    public Num(int value, int index) {
+      super();
+      this.value = value;
+      this.index = index;
+    }
 
-		public int getIndex() {
-			return index;
-		}
+    public int getIndex() {
+      return index;
+    }
 
-		public void setIndex(int index) {
-			this.index = index;
-		}
+    public void setIndex(int index) {
+      this.index = index;
+    }
 
-		public int getValue() {
-			return value;
-		}
+    public int getValue() {
+      return value;
+    }
 
-		public void setValue(int value) {
-			this.value = value;
-		}
-	}
+    public void setValue(int value) {
+      this.value = value;
+    }
+  }
 
-	public int[] twoSum(int[] numbers, int target) {
-		Num[] newArray = new Num[numbers.length];
-		for (int i = 0; i < numbers.length; i++) {
-			newArray[i] = new Num(numbers[i], i);
-		}
-		Arrays.sort(newArray, new Comparator<Num>() {
-			public int compare(Num n1, Num n2) {
-				if (n1.getValue() == n2.getValue())
-					return 0;
-				if (n1.getValue() > n2.getValue())
-					return 1;
-				return -1;
-			}
-		});
-		int[] result = new int[2];
-		int i = 0, j = numbers.length - 1;
-		while (i < j) {
-			int tmp = newArray[i].getValue() + newArray[j].getValue();
-			if (tmp == target) {
-				result[0] = Math.min(newArray[i].getIndex() + 1,
-						newArray[j].getIndex() + 1);
-				result[1] = Math.max(newArray[i].getIndex() + 1,
-						newArray[j].getIndex() + 1);
-				break;
-			} else if (tmp > target) {
-				j--;
-			} else {
-				i++;
-			}
-		}
-		return result;
-	}
-}
\ No newline at end of file
+  public int[] twoSum(int[] numbers, int target) {
+    Num[] newArray = new Num[numbers.length];
+    for (int i = 0; i < numbers.length; i++) {
+      newArray[i] = new Num(numbers[i], i);
+    }
+    Arrays.sort(
+        newArray,
+        new Comparator<Num>() {
+          public int compare(Num n1, Num n2) {
+            if (n1.getValue() == n2.getValue()) return 0;
+            if (n1.getValue() > n2.getValue()) return 1;
+            return -1;
+          }
+        });
+    int[] result = new int[2];
+    int i = 0, j = numbers.length - 1;
+    while (i < j) {
+      int tmp = newArray[i].getValue() + newArray[j].getValue();
+      if (tmp == target) {
+        result[0] = Math.min(newArray[i].getIndex() + 1, newArray[j].getIndex() + 1);
+        result[1] = Math.max(newArray[i].getIndex() + 1, newArray[j].getIndex() + 1);
+        break;
+      } else if (tmp > target) {
+        j--;
+      } else {
+        i++;
+      }
+    }
+    return result;
+  }
+}
diff --git a/TwoSumV2.java b/TwoSumV2.java
index f7555ff..ce5df82 100644
--- a/TwoSumV2.java
+++ b/TwoSumV2.java
@@ -1,70 +1,66 @@
-
-
 /**
- * Given an array of integers, find two numbers such that they add up to a
- * specific target number.
- * 
- * The function twoSum should return indices of the two numbers such that they
- * add up to the target, where index1 must be less than index2. Please note that
- * your returned answers (both index1 and index2) are not zero-based. You may
- * assume that each input would have exactly one solution.
- * 
- * Input: numbers={2, 7, 11, 15}, target=9 Output: index1=1, index2=2
+ * Given an array of integers, find two numbers such that they add up to a specific target number.
+ *
+ * <p>The function twoSum should return indices of the two numbers such that they add up to the
+ * target, where index1 must be less than index2. Please note that your returned answers (both
+ * index1 and index2) are not zero-based. You may assume that each input would have exactly one
+ * solution.
+ *
+ * <p>Input: numbers={2, 7, 11, 15}, target=9 Output: index1=1, index2=2
  */
-
 public class TwoSumV2 {
-	private void quickSort(int[] numbers, int[] indexs, int start, int end) {
-		if (start < end) {
-			int p = partition(numbers, indexs, start, end);
-			quickSort(numbers, indexs, start, p - 1);
-			quickSort(numbers, indexs, p + 1, end);
-		}
-	}
+  private void quickSort(int[] numbers, int[] indexs, int start, int end) {
+    if (start < end) {
+      int p = partition(numbers, indexs, start, end);
+      quickSort(numbers, indexs, start, p - 1);
+      quickSort(numbers, indexs, p + 1, end);
+    }
+  }
 
-	private int partition(int[] numbers, int[] indexs, int start, int end) {
-		swap(numbers, (start + end) / 2, end);
-		swap(indexs, (start + end) / 2, end);
-		int x = numbers[end];
-		int i = start - 1;
-		for (int k = start; k < end; k++) {
-			if (numbers[k] < x) {
-				i++;
-				swap(numbers, i, k);
-				swap(indexs, i, k);
-			}
-		}
-		swap(numbers, i + 1, end);
-		swap(indexs, i + 1, end);
-		return i + 1;
-	}
+  private int partition(int[] numbers, int[] indexs, int start, int end) {
+    swap(numbers, (start + end) / 2, end);
+    swap(indexs, (start + end) / 2, end);
+    int x = numbers[end];
+    int i = start - 1;
+    for (int k = start; k < end; k++) {
+      if (numbers[k] < x) {
+        i++;
+        swap(numbers, i, k);
+        swap(indexs, i, k);
+      }
+    }
+    swap(numbers, i + 1, end);
+    swap(indexs, i + 1, end);
+    return i + 1;
+  }
 
-	private void swap(int[] a, int i, int j) {
-		int tmp = a[i];
-		a[i] = a[j];
-		a[j] = tmp;
-	}
+  private void swap(int[] a, int i, int j) {
+    int tmp = a[i];
+    a[i] = a[j];
+    a[j] = tmp;
+  }
 
-	public int[] twoSum(int[] numbers, int target) {
-		int len = numbers.length;
-		int[] indexs = new int[len];
-		int[] ret = new int[2];
-		for (int i = 0; i < len; i++) {
-			indexs[i] = i + 1;
-		}
-		quickSort(numbers, indexs, 0, len - 1);
-		int start = 0;
-		int end = len - 1;
-		while (start < end) {
-			if (numbers[start] + numbers[end] == target) {
-				ret[0] = Math.min(indexs[start], indexs[end]);
-				ret[1] = Math.max(indexs[start], indexs[end]);
-				break;
-			} else if (numbers[start] + numbers[end] > target) {
-				end--;
-			} else {
-				start++;
-			}
-		}
-		return ret;
-	}
+  public int[] twoSum(int[] numbers, int target) {
+    int len = numbers.length;
+    int[] indexs = new int[len];
+    int[] ret = new int[2];
+    for (int i = 0; i < len; i++) {
+      indexs[i] = i + 1;
+    }
+    quickSort(numbers, indexs, 0, len - 1);
+    int start = 0;
+    int end = len - 1;
+    while (start < end) {
+      if (numbers[start] + numbers[end] == target) {
+        ret[0] = Math.min(indexs[start], indexs[end]);
+        ret[1] = Math.max(indexs[start], indexs[end]);
+        break;
+      } else if (numbers[start] + numbers[end] > target) {
+        end--;
+      } else {
+        start++;
+      }
+    }
+    return ret;
+  }
 }
diff --git a/UndirectedGraphNode.java b/UndirectedGraphNode.java
index ae6fde3..884e138 100644
--- a/UndirectedGraphNode.java
+++ b/UndirectedGraphNode.java
@@ -1,11 +1,11 @@
 import java.util.ArrayList;
 
 class UndirectedGraphNode {
-	int label;
-	ArrayList<UndirectedGraphNode> neighbors;
+  int label;
+  ArrayList<UndirectedGraphNode> neighbors;
 
-	UndirectedGraphNode(int x) {
-		label = x;
-		neighbors = new ArrayList<UndirectedGraphNode>();
-	}
-}
\ No newline at end of file
+  UndirectedGraphNode(int x) {
+    label = x;
+    neighbors = new ArrayList<UndirectedGraphNode>();
+  }
+}
diff --git a/UniqueBinarySearchTrees.java b/UniqueBinarySearchTrees.java
index 21052e4..ab82441 100644
--- a/UniqueBinarySearchTrees.java
+++ b/UniqueBinarySearchTrees.java
@@ -1,36 +1,27 @@
-
-
-/** 
+/**
  * Given n, how many structurally unique BST's (binary search trees) that store values 1...n?
  *
- * For example,
- * 
- * Given n = 3, there are a total of 5 unique BST's.
+ * <p>For example,
  *
- *  1         3     3      2      1
- *   \       /     /      / \      \
- *    3     2     1      1   3      2
- *   /     /       \                 \
- *  2     1         2                 3
+ * <p>Given n = 3, there are a total of 5 unique BST's.
+ *
+ * <p>1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ \ 2 1 2 3
  */
-
 public class UniqueBinarySearchTrees {
-	public int numTrees(int n) {
-		if (n == 1)
-			return 1;
-		if (n == 2)
-			return 2;
-		int[] record = new int[n + 1];
-		record[0] = 1;
-		record[1] = 1;
-		record[2] = 2;
-		for (int i = 3; i <= n; i++) {
-			int tmp = 0;
-			for (int k = 0; k < i; k++) {
-				tmp += (record[k] * record[i - k - 1]);
-			}
-			record[i] = tmp;
-		}
-		return record[n];
-	}
-}
\ No newline at end of file
+  public int numTrees(int n) {
+    if (n == 1) return 1;
+    if (n == 2) return 2;
+    int[] record = new int[n + 1];
+    record[0] = 1;
+    record[1] = 1;
+    record[2] = 2;
+    for (int i = 3; i <= n; i++) {
+      int tmp = 0;
+      for (int k = 0; k < i; k++) {
+        tmp += (record[k] * record[i - k - 1]);
+      }
+      record[i] = tmp;
+    }
+    return record[n];
+  }
+}
diff --git a/UniqueBinarySearchTreesII.java b/UniqueBinarySearchTreesII.java
index ad930b9..035fb17 100644
--- a/UniqueBinarySearchTreesII.java
+++ b/UniqueBinarySearchTreesII.java
@@ -1,45 +1,40 @@
 /**
  * Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.
  *
- * For example,
- * Given n = 3, your program should return all 5 unique BST's shown below.
+ * <p>For example, Given n = 3, your program should return all 5 unique BST's shown below.
  *
- *  1         3     3      2      1
- *   \       /     /      / \      \
- *    3     2     1      1   3      2
- *   /     /       \                 \
- *  2     1         2                 3
+ * <p>1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ \ 2 1 2 3
  */
 
 import java.util.ArrayList;
 
 public class UniqueBinarySearchTreesII {
-	public ArrayList<TreeNode> generateTrees(int n) {
-		return buildBST(1, n);
-	}
+  public ArrayList<TreeNode> generateTrees(int n) {
+    return buildBST(1, n);
+  }
 
-	private ArrayList<TreeNode> buildBST(int min, int max) {
-		ArrayList<TreeNode> ret = new ArrayList<TreeNode>();
-		if (min > max) {
-			ret.add(null);
-			return ret;
-		}
-		if (min == max) {
-			ret.add(new TreeNode(min));
-			return ret;
-		}
-		for (int i = min; i <= max; i++) {
-			ArrayList<TreeNode> leftTrees = buildBST(min, i - 1);
-			ArrayList<TreeNode> rightTrees = buildBST(i + 1, max);
-			for (TreeNode l : leftTrees) {
-				for (TreeNode r : rightTrees) {
-					TreeNode root = new TreeNode(i);
-					root.left = l;
-					root.right = r;
-					ret.add(root);
-				}
-			}
-		}
-		return ret;
-	}
+  private ArrayList<TreeNode> buildBST(int min, int max) {
+    ArrayList<TreeNode> ret = new ArrayList<TreeNode>();
+    if (min > max) {
+      ret.add(null);
+      return ret;
+    }
+    if (min == max) {
+      ret.add(new TreeNode(min));
+      return ret;
+    }
+    for (int i = min; i <= max; i++) {
+      ArrayList<TreeNode> leftTrees = buildBST(min, i - 1);
+      ArrayList<TreeNode> rightTrees = buildBST(i + 1, max);
+      for (TreeNode l : leftTrees) {
+        for (TreeNode r : rightTrees) {
+          TreeNode root = new TreeNode(i);
+          root.left = l;
+          root.right = r;
+          ret.add(root);
+        }
+      }
+    }
+    return ret;
+  }
 }
diff --git a/UniquePaths.java b/UniquePaths.java
index d8d2e5a..63c3a61 100644
--- a/UniquePaths.java
+++ b/UniquePaths.java
@@ -1,35 +1,30 @@
 /**
- * A robot is located at the top-left corner of a m x n grid (marked 'Start' in
- * the diagram below).
- * 
- * The robot can only move either down or right at any point in time. The robot
- * is trying to reach the bottom-right corner of the grid (marked 'Finish' in
- * the diagram below).
- * 
- * How many possible unique paths are there?
- * 
- * Above is a 3 x 7 grid. How many possible unique paths are there?
- * 
- * Note: m and n will be at most 100.
- * 
+ * A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).
+ *
+ * <p>The robot can only move either down or right at any point in time. The robot is trying to
+ * reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).
+ *
+ * <p>How many possible unique paths are there?
+ *
+ * <p>Above is a 3 x 7 grid. How many possible unique paths are there?
+ *
+ * <p>Note: m and n will be at most 100.
  */
-
 public class UniquePaths {
-	public int uniquePaths(int m, int n) {
-		if (m == 0 || n == 0)
-			return 0;
-		int[][] map = new int[m][n];
-		for (int i = 0; i < m; i++) {
-			map[i][0] = 1;
-		}
-		for (int j = 0; j < n; j++) {
-			map[0][j] = 1;
-		}
-		for (int i = 1; i < m; i++) {
-			for (int j = 1; j < n; j++) {
-				map[i][j] = map[i - 1][j] + map[i][j - 1];
-			}
-		}
-		return map[m - 1][n - 1];
-	}
+  public int uniquePaths(int m, int n) {
+    if (m == 0 || n == 0) return 0;
+    int[][] map = new int[m][n];
+    for (int i = 0; i < m; i++) {
+      map[i][0] = 1;
+    }
+    for (int j = 0; j < n; j++) {
+      map[0][j] = 1;
+    }
+    for (int i = 1; i < m; i++) {
+      for (int j = 1; j < n; j++) {
+        map[i][j] = map[i - 1][j] + map[i][j - 1];
+      }
+    }
+    return map[m - 1][n - 1];
+  }
 }
diff --git a/UniquePathsII.java b/UniquePathsII.java
index 3ef0ce1..040cbef 100644
--- a/UniquePathsII.java
+++ b/UniquePathsII.java
@@ -1,44 +1,36 @@
 /**
  * Follow up for "Unique Paths":
  *
- * Now consider if some obstacles are added to the grids. How many unique paths would there be?
+ * <p>Now consider if some obstacles are added to the grids. How many unique paths would there be?
  *
- * An obstacle and empty space is marked as 1 and 0 respectively in the grid.
+ * <p>An obstacle and empty space is marked as 1 and 0 respectively in the grid.
  *
- * For example,
- * There is one obstacle in the middle of a 3x3 grid as illustrated below.
+ * <p>For example, There is one obstacle in the middle of a 3x3 grid as illustrated below.
  *
- * [
- *  [0,0,0],
- *  [0,1,0],
- *  [0,0,0]
- * ]
- * 
- * The total number of unique paths is 2.
+ * <p>[ [0,0,0], [0,1,0], [0,0,0] ]
  *
- * Note: m and n will be at most 100.
+ * <p>The total number of unique paths is 2.
  *
+ * <p>Note: m and n will be at most 100.
  */
 public class UniquePathsII {
-	public int uniquePathsWithObstacles(int[][] obstacleGrid) {
-		int m = obstacleGrid.length;
-		if (m == 0)
-			return 0;
-		int n = obstacleGrid[0].length;
-		int[][] map = new int[m][n];
-		map[0][0] = obstacleGrid[0][0] == 1 ? 0 : 1;
-		for (int i = 1; i < m; i++) {
-			map[i][0] = obstacleGrid[i][0] == 1 ? 0 : map[i - 1][0];
-		}
-		for (int j = 1; j < n; j++) {
-			map[0][j] = obstacleGrid[0][j] == 1 ? 0 : map[0][j - 1];
-		}
-		for (int i = 1; i < m; i++) {
-			for (int j = 1; j < n; j++) {
-				map[i][j] = obstacleGrid[i][j] == 1 ? 0 : map[i - 1][j]
-						+ map[i][j - 1];
-			}
-		}
-		return map[m - 1][n - 1];
-	}
+  public int uniquePathsWithObstacles(int[][] obstacleGrid) {
+    int m = obstacleGrid.length;
+    if (m == 0) return 0;
+    int n = obstacleGrid[0].length;
+    int[][] map = new int[m][n];
+    map[0][0] = obstacleGrid[0][0] == 1 ? 0 : 1;
+    for (int i = 1; i < m; i++) {
+      map[i][0] = obstacleGrid[i][0] == 1 ? 0 : map[i - 1][0];
+    }
+    for (int j = 1; j < n; j++) {
+      map[0][j] = obstacleGrid[0][j] == 1 ? 0 : map[0][j - 1];
+    }
+    for (int i = 1; i < m; i++) {
+      for (int j = 1; j < n; j++) {
+        map[i][j] = obstacleGrid[i][j] == 1 ? 0 : map[i - 1][j] + map[i][j - 1];
+      }
+    }
+    return map[m - 1][n - 1];
+  }
 }
diff --git a/ValidNumber.java b/ValidNumber.java
index 302c072..40cab80 100644
--- a/ValidNumber.java
+++ b/ValidNumber.java
@@ -1,85 +1,76 @@
 /**
  * Validate if a given string is numeric.
- * 
- * Some examples:
- * 
- * "0" => true
- * " 0.1 " => true
- * "abc" => false
- * "1 a" => false
- * "2e10" => true
- * 
- * Note: It is intended for the problem statement to be ambiguous. 
- * You should gather all requirements up front before implementing one.
  *
+ * <p>Some examples:
+ *
+ * <p>"0" => true " 0.1 " => true "abc" => false "1 a" => false "2e10" => true
+ *
+ * <p>Note: It is intended for the problem statement to be ambiguous. You should gather all
+ * requirements up front before implementing one.
  */
 public class ValidNumber {
-	public boolean isNumber(String s) {
-		StringBuffer sb = new StringBuffer(s.trim());
-		int i = sb.length() - 1;
-		while (i >= 0 && sb.charAt(i) == ' ') {
-			i--;
-		}
-		sb.delete(i + 1, sb.length());
-		s = sb.toString();
-		int length = s.length();
-		if (length == 0)
-			return false;
-		i = 0;
-		int start = 0;
-		if (s.charAt(i) == '-' || s.charAt(i) == '+') {
-			i++;
-			start++;
-		}
-		for (; i < length; i++) {
-			char c = s.charAt(i);
-			if (c == 'e' || c == 'E') {
-				return isDouble(s.substring(start, i)) && isDigitals(s.substring(i + 1, s.length()));
-			} else if (c != '.' && (c < '0' || c > '9')) {
-				return false;
-			}
-		}
-		return isDouble(s.substring(start));
-	}
+  public boolean isNumber(String s) {
+    StringBuffer sb = new StringBuffer(s.trim());
+    int i = sb.length() - 1;
+    while (i >= 0 && sb.charAt(i) == ' ') {
+      i--;
+    }
+    sb.delete(i + 1, sb.length());
+    s = sb.toString();
+    int length = s.length();
+    if (length == 0) return false;
+    i = 0;
+    int start = 0;
+    if (s.charAt(i) == '-' || s.charAt(i) == '+') {
+      i++;
+      start++;
+    }
+    for (; i < length; i++) {
+      char c = s.charAt(i);
+      if (c == 'e' || c == 'E') {
+        return isDouble(s.substring(start, i)) && isDigitals(s.substring(i + 1, s.length()));
+      } else if (c != '.' && (c < '0' || c > '9')) {
+        return false;
+      }
+    }
+    return isDouble(s.substring(start));
+  }
 
-	private boolean isDouble(String s) {
-		int length = s.length();
-		if (length == 0 || ((s.charAt(0) == '-' || s.charAt(0) == '+') && length == 1))
-			return false;
-		int i = 0, start = 0;
-		if (s.charAt(i) == '-' || s.charAt(i) == '+') {
-			i++;
-			start++;
-		}
-		for (; i < length; i++) {
-			char c = s.charAt(i);
-			if (c == '.') {
-				if (i == start && s.length() - i - 1 == 0)
-					return false;
-				boolean left = i == start ? true : isDigitals(s.substring(0, i));
-				boolean right = s.length() - i - 1 == 0 ? true : isDigitals(s.substring(i + 1, s.length()));
-				return left && right;
-			} else if (c < '0' || c > '9') {
-				return false;
-			}
-		}
-		return true;
-	}
+  private boolean isDouble(String s) {
+    int length = s.length();
+    if (length == 0 || ((s.charAt(0) == '-' || s.charAt(0) == '+') && length == 1)) return false;
+    int i = 0, start = 0;
+    if (s.charAt(i) == '-' || s.charAt(i) == '+') {
+      i++;
+      start++;
+    }
+    for (; i < length; i++) {
+      char c = s.charAt(i);
+      if (c == '.') {
+        if (i == start && s.length() - i - 1 == 0) return false;
+        boolean left = i == start ? true : isDigitals(s.substring(0, i));
+        boolean right = s.length() - i - 1 == 0 ? true : isDigitals(s.substring(i + 1, s.length()));
+        return left && right;
+      } else if (c < '0' || c > '9') {
+        return false;
+      }
+    }
+    return true;
+  }
 
-	private boolean isDigitals(String s) {
-		int length = s.length();
-		if (length == 0 || ((s.charAt(0) == '-' || s.charAt(0) == '+') && length == 1))
-			return false;
-		int i = 0;
-		if (s.charAt(i) == '-' || s.charAt(i) == '+') {
-			i++;
-		}
-		for (; i < length; i++) {
-			char c = s.charAt(i);
-			if (c < '0' || c > '9') {
-				return false;
-			}
-		}
-		return true;
-	}
-}
\ No newline at end of file
+  private boolean isDigitals(String s) {
+    int length = s.length();
+    if (length == 0 || ((s.charAt(0) == '-' || s.charAt(0) == '+') && length == 1)) return false;
+    int i = 0;
+    if (s.charAt(i) == '-' || s.charAt(i) == '+') {
+      i++;
+    }
+    for (; i < length; i++) {
+      char c = s.charAt(i);
+      if (c < '0' || c > '9') {
+        return false;
+      }
+    }
+    return true;
+  }
+}
diff --git a/ValidPalindrome.java b/ValidPalindrome.java
index 71d42fe..706be2d 100644
--- a/ValidPalindrome.java
+++ b/ValidPalindrome.java
@@ -1,39 +1,37 @@
-
 /**
- * Given a string, determine if it is a palindrome, considering only
- * alphanumeric characters and ignoring cases.
- * 
- * For example, "A man, a plan, a canal: Panama" is a palindrome. "race a car"
- * is not a palindrome.
- * 
- * Note:
- * 
- * Have you consider that the string might be empty? This is a good question to
- * ask during an interview.
- * 
- * For the purpose of this problem, we define empty string as valid palindrome.
+ * Given a string, determine if it is a palindrome, considering only alphanumeric characters and
+ * ignoring cases.
+ *
+ * <p>For example, "A man, a plan, a canal: Panama" is a palindrome. "race a car" is not a
+ * palindrome.
+ *
+ * <p>Note:
+ *
+ * <p>Have you consider that the string might be empty? This is a good question to ask during an
+ * interview.
+ *
+ * <p>For the purpose of this problem, we define empty string as valid palindrome.
  */
-
 public class ValidPalindrome {
-	public boolean isPalindrome(String s) {
-		s = s.toUpperCase();
-		int i = 0, j = s.length() - 1;
-		while (i < j) {
-			if (!isAlphabet(s.charAt(i))) {
-				i++;
-			} else if(!isAlphabet(s.charAt(j))) {
-				j--;
-			} else if (s.charAt(i) != s.charAt(j)) {
-				return false;
-			} else {
-				i++;
-				j--;
-			}
-		}
-		return true;
-	}
-	
-	private boolean isAlphabet(char c) {
-		return (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9');
-	}
-}
\ No newline at end of file
+  public boolean isPalindrome(String s) {
+    s = s.toUpperCase();
+    int i = 0, j = s.length() - 1;
+    while (i < j) {
+      if (!isAlphabet(s.charAt(i))) {
+        i++;
+      } else if (!isAlphabet(s.charAt(j))) {
+        j--;
+      } else if (s.charAt(i) != s.charAt(j)) {
+        return false;
+      } else {
+        i++;
+        j--;
+      }
+    }
+    return true;
+  }
+
+  private boolean isAlphabet(char c) {
+    return (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9');
+  }
+}
diff --git a/ValidParentheses.java b/ValidParentheses.java
index 1554bed..9f8455e 100644
--- a/ValidParentheses.java
+++ b/ValidParentheses.java
@@ -1,56 +1,54 @@
-
-
 import java.util.Stack;
 
 /**
- * Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
- * 
- * The brackets must close in the correct order, "()" and "()[]{}" are all valid but "(]" and "([)]" are not.
+ * Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the
+ * input string is valid.
+ *
+ * <p>The brackets must close in the correct order, "()" and "()[]{}" are all valid but "(]" and
+ * "([)]" are not.
  */
-
 public class ValidParentheses {
-	public boolean isValid(String s) {
-		int len = s.length();
-		if (len == 0)
-			return true;
-		Stack<Character> st = new Stack<Character>();
-		st.add(s.charAt(0));
-		int i = 1;
-		while (i < len) {
-			switch (s.charAt(i)) {
-			case '(':
-				st.add('(');
-				break;
-			case ')':
-				if (!st.empty() && st.peek() == '(') {
-					st.pop();
-				} else {
-					return false;
-				}
-				break;
-			case '{':
-				st.add('{');
-				break;
-			case '}':
-				if (!st.empty() && st.peek() == '{') {
-					st.pop();
-				} else {
-					return false;
-				}
-				break;
-			case '[':
-				st.add('[');
-				break;
-			case ']':
-				if (!st.empty() && st.peek() == '[') {
-					st.pop();
-				} else {
-					return false;
-				}
-				break;
-			}
-			i++;
-		}
-		return st.empty();
-	}
-}
\ No newline at end of file
+  public boolean isValid(String s) {
+    int len = s.length();
+    if (len == 0) return true;
+    Stack<Character> st = new Stack<Character>();
+    st.add(s.charAt(0));
+    int i = 1;
+    while (i < len) {
+      switch (s.charAt(i)) {
+        case '(':
+          st.add('(');
+          break;
+        case ')':
+          if (!st.empty() && st.peek() == '(') {
+            st.pop();
+          } else {
+            return false;
+          }
+          break;
+        case '{':
+          st.add('{');
+          break;
+        case '}':
+          if (!st.empty() && st.peek() == '{') {
+            st.pop();
+          } else {
+            return false;
+          }
+          break;
+        case '[':
+          st.add('[');
+          break;
+        case ']':
+          if (!st.empty() && st.peek() == '[') {
+            st.pop();
+          } else {
+            return false;
+          }
+          break;
+      }
+      i++;
+    }
+    return st.empty();
+  }
+}
diff --git a/ValidateBinarySearchTree.java b/ValidateBinarySearchTree.java
index 062098d..c6026c1 100644
--- a/ValidateBinarySearchTree.java
+++ b/ValidateBinarySearchTree.java
@@ -1,31 +1,25 @@
-
-
-/** 
+/**
  * Given a binary tree, determine if it is a valid binary search tree (BST).
  *
- * Assume a BST is defined as follows:
+ * <p>Assume a BST is defined as follows:
  *
- * The left subtree of a node contains only nodes with keys less than the node's key.
- * The right subtree of a node contains only nodes with keys greater than the node's key.
- * Both the left and right subtrees must also be binary search trees.
+ * <p>The left subtree of a node contains only nodes with keys less than the node's key. The right
+ * subtree of a node contains only nodes with keys greater than the node's key. Both the left and
+ * right subtrees must also be binary search trees.
  */
-
 public class ValidateBinarySearchTree {
-	public boolean isValidBST(TreeNode root) {
-		if (root == null)
-			return true;
-		return validate(root.left, Integer.MIN_VALUE, root.val)
-				&& validate(root.right, root.val, Integer.MAX_VALUE);
-	}
+  public boolean isValidBST(TreeNode root) {
+    if (root == null) return true;
+    return validate(root.left, Integer.MIN_VALUE, root.val)
+        && validate(root.right, root.val, Integer.MAX_VALUE);
+  }
 
-	private boolean validate(TreeNode root, int min, int max) {
-		if (root == null)
-			return true;
-		if (root.val > min && root.val < max) {
-			return validate(root.left, min, root.val)
-					&& validate(root.right, root.val, max);
-		} else {
-			return false;
-		}
-	}
-}
\ No newline at end of file
+  private boolean validate(TreeNode root, int min, int max) {
+    if (root == null) return true;
+    if (root.val > min && root.val < max) {
+      return validate(root.left, min, root.val) && validate(root.right, root.val, max);
+    } else {
+      return false;
+    }
+  }
+}
diff --git a/WordBreak.java b/WordBreak.java
index e07967d..d42b3ca 100644
--- a/WordBreak.java
+++ b/WordBreak.java
@@ -1,34 +1,31 @@
-
-
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
 
 /**
- * Given a string s and a dictionary of words dict, determine if s can be
- * segmented into a space-separated sequence of one or more dictionary words.
- * 
- * For example, given s = "leetcode", dict = ["leet", "code"].
- * 
- * Return true because "leetcode" can be segmented as "leet code".
+ * Given a string s and a dictionary of words dict, determine if s can be segmented into a
+ * space-separated sequence of one or more dictionary words.
+ *
+ * <p>For example, given s = "leetcode", dict = ["leet", "code"].
+ *
+ * <p>Return true because "leetcode" can be segmented as "leet code".
  */
-
 public class WordBreak {
-	public boolean wordBreak(String s, Set<String> dict) {
-		Map<String, Boolean> wordMap = new HashMap<String, Boolean>();
-		for (String w : dict) {
-			wordMap.put(w, true);
-		}
-		int len = s.length();
-		boolean[] strMap = new boolean[len + 1];
-		strMap[0] = true;
-		for (int i = 1; i <= len; i++) {
-			for (int j = 0; j < i; j++) {
-				if (strMap[j] && wordMap.containsKey(s.substring(j, i))) {
-					strMap[i] = true;
-				}
-			}
-		}
-		return strMap[len];
-	}
+  public boolean wordBreak(String s, Set<String> dict) {
+    Map<String, Boolean> wordMap = new HashMap<String, Boolean>();
+    for (String w : dict) {
+      wordMap.put(w, true);
+    }
+    int len = s.length();
+    boolean[] strMap = new boolean[len + 1];
+    strMap[0] = true;
+    for (int i = 1; i <= len; i++) {
+      for (int j = 0; j < i; j++) {
+        if (strMap[j] && wordMap.containsKey(s.substring(j, i))) {
+          strMap[i] = true;
+        }
+      }
+    }
+    return strMap[len];
+  }
 }
diff --git a/WordBreakII.java b/WordBreakII.java
index dd11662..a0b62ad 100644
--- a/WordBreakII.java
+++ b/WordBreakII.java
@@ -1,5 +1,3 @@
-
-
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.LinkedList;
@@ -8,61 +6,65 @@
 import java.util.Set;
 
 /**
- * Given a string s and a dictionary of words dict, add spaces in s to construct
- * a sentence where each word is a valid dictionary word.
- * 
- * Return all such possible sentences.
- * 
- * For example, given s = "catsanddog", dict = ["cat", "cats", "and", "sand", "dog"].
- * 
- * A solution is ["cats and dog", "cat sand dog"].
+ * Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where
+ * each word is a valid dictionary word.
+ *
+ * <p>Return all such possible sentences.
+ *
+ * <p>For example, given s = "catsanddog", dict = ["cat", "cats", "and", "sand", "dog"].
+ *
+ * <p>A solution is ["cats and dog", "cat sand dog"].
  */
-
 public class WordBreakII {
-	public ArrayList<String> wordBreak(String s, Set<String> dict) {
-		Map<String, Boolean> wordMap = new HashMap<String, Boolean>();
-		for (String w : dict) {
-			wordMap.put(w, true);
-		}
-		int len = s.length();
-		boolean[] strMap = new boolean[len + 1];
-		ArrayList<String> sols = new ArrayList<String>();
-		strMap[0] = true;
-		for (int i = 1; i <= len; i++) {
-			for (int j = 0; j < i; j++) {
-				String ww = s.substring(j, i);
-				if (strMap[j] && wordMap.containsKey(ww)) {
-					strMap[i] = true;
-				}
-			}
-		}
-		if (!strMap[len])
-			return sols;
-		List<String> sb = new LinkedList<String>();
-		search(s, dict, 0, len, strMap, sb, sols);
+  public ArrayList<String> wordBreak(String s, Set<String> dict) {
+    Map<String, Boolean> wordMap = new HashMap<String, Boolean>();
+    for (String w : dict) {
+      wordMap.put(w, true);
+    }
+    int len = s.length();
+    boolean[] strMap = new boolean[len + 1];
+    ArrayList<String> sols = new ArrayList<String>();
+    strMap[0] = true;
+    for (int i = 1; i <= len; i++) {
+      for (int j = 0; j < i; j++) {
+        String ww = s.substring(j, i);
+        if (strMap[j] && wordMap.containsKey(ww)) {
+          strMap[i] = true;
+        }
+      }
+    }
+    if (!strMap[len]) return sols;
+    List<String> sb = new LinkedList<String>();
+    search(s, dict, 0, len, strMap, sb, sols);
 
-		return sols;
-	}
+    return sols;
+  }
 
-	private void search(String s, Set<String> dict, int st, int len,
-			boolean[] strMap, List<String> sb, ArrayList<String> sols) {
-		if (st >= len) {
-			StringBuffer sbf = new StringBuffer();
-			for (String ss : sb) {
-				sbf.append(" ");
-				sbf.append(ss);
-			}
-			sols.add(sbf.toString().trim());
-		} else {
-			for (int ll = st + 1; ll <= len; ll++) {
-				String tmp = s.substring(st, ll);
-				if (strMap[st] && dict.contains(tmp)) {
-					sb.add(tmp);
-					int last = sb.size() - 1;
-					search(s, dict, ll, len, strMap, sb, sols);
-					sb.remove(last);
-				}
-			}
-		}
-	}
+  private void search(
+      String s,
+      Set<String> dict,
+      int st,
+      int len,
+      boolean[] strMap,
+      List<String> sb,
+      ArrayList<String> sols) {
+    if (st >= len) {
+      StringBuffer sbf = new StringBuffer();
+      for (String ss : sb) {
+        sbf.append(" ");
+        sbf.append(ss);
+      }
+      sols.add(sbf.toString().trim());
+    } else {
+      for (int ll = st + 1; ll <= len; ll++) {
+        String tmp = s.substring(st, ll);
+        if (strMap[st] && dict.contains(tmp)) {
+          sb.add(tmp);
+          int last = sb.size() - 1;
+          search(s, dict, ll, len, strMap, sb, sols);
+          sb.remove(last);
+        }
+      }
+    }
+  }
 }
diff --git a/WordLadder.java b/WordLadder.java
index 6e5a462..16a5293 100644
--- a/WordLadder.java
+++ b/WordLadder.java
@@ -1,79 +1,74 @@
-
-
 import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.Queue;
 
 /**
- * Given two words (start and end), and a dictionary, find the length of
- * shortest transformation sequence from start to end, such that:
- * 
- * Only one letter can be changed at a time Each intermediate word must exist in
- * the dictionary For example,
- * 
- * Given: start = "hit" end = "cog" dict = ["hot","dot","dog","lot","log"]
- * 
- * As one shortest transformation is "hit" -> "hot" -> "dot" -> "dog" -> "cog",
- * return its length 5.
- * 
- * Note:
- * 
- * Return 0 if there is no such transformation sequence. All words have the same
- * length. All words contain only lowercase alphabetic characters.
+ * Given two words (start and end), and a dictionary, find the length of shortest transformation
+ * sequence from start to end, such that:
+ *
+ * <p>Only one letter can be changed at a time Each intermediate word must exist in the dictionary
+ * For example,
+ *
+ * <p>Given: start = "hit" end = "cog" dict = ["hot","dot","dog","lot","log"]
+ *
+ * <p>As one shortest transformation is "hit" -> "hot" -> "dot" -> "dog" -> "cog", return its length
+ * 5.
+ *
+ * <p>Note:
+ *
+ * <p>Return 0 if there is no such transformation sequence. All words have the same length. All
+ * words contain only lowercase alphabetic characters.
  */
-
 public class WordLadder {
-	public int ladderLength(String start, String end, HashSet<String> dict) {
-		if (dict.size() == 0)
-			return 0;
-		int currentLevel = 1;
-		int nextLevel = 0;
-		int step = 1;
-		boolean found = false;
-		Queue<String> st = new LinkedList<String>();
-		HashSet<String> visited = new HashSet<String>();
-		st.add(start);
-		while (!st.isEmpty()) {
-			String s = st.remove();
-			currentLevel--;
-			if (stringDiff(s, end) == 1) {
-				found = true;
-				step++;
-				break;
-			} else {
-				int length = s.length();
-				StringBuffer sb = new StringBuffer(s);
-				for (int i = 0; i < length; i++) {
-					for (int j = 0; j < 26; j++) {
-						char c = sb.charAt(i);
-						sb.setCharAt(i, (char) ('a' + j));
-						if (dict.contains(sb.toString())
-								&& !visited.contains(sb.toString())) {
-							nextLevel++;
-							st.add(sb.toString());
-							visited.add(sb.toString());
-						}
-						sb.setCharAt(i, c);
-					}
-				}
-			}
-			if (currentLevel == 0) {
-				currentLevel = nextLevel;
-				nextLevel = 0;
-				step++;
-			}
-		}
-		return found ? step : 0;
-	}
+  public int ladderLength(String start, String end, HashSet<String> dict) {
+    if (dict.size() == 0) return 0;
+    int currentLevel = 1;
+    int nextLevel = 0;
+    int step = 1;
+    boolean found = false;
+    Queue<String> st = new LinkedList<String>();
+    HashSet<String> visited = new HashSet<String>();
+    st.add(start);
+    while (!st.isEmpty()) {
+      String s = st.remove();
+      currentLevel--;
+      if (stringDiff(s, end) == 1) {
+        found = true;
+        step++;
+        break;
+      } else {
+        int length = s.length();
+        StringBuffer sb = new StringBuffer(s);
+        for (int i = 0; i < length; i++) {
+          for (int j = 0; j < 26; j++) {
+            char c = sb.charAt(i);
+            sb.setCharAt(i, (char) ('a' + j));
+            if (dict.contains(sb.toString()) && !visited.contains(sb.toString())) {
+              nextLevel++;
+              st.add(sb.toString());
+              visited.add(sb.toString());
+            }
+            sb.setCharAt(i, c);
+          }
+        }
+      }
+      if (currentLevel == 0) {
+        currentLevel = nextLevel;
+        nextLevel = 0;
+        step++;
+      }
+    }
+    return found ? step : 0;
+  }
 
-	private int stringDiff(String s1, String s2) {
-		int diff = 0;
-		int length = s1.length();
-		for (int i = 0; i < length; i++) {
-			if (s1.charAt(i) != s2.charAt(i)) {
-				diff++;
-			}
-		}
-		return diff;
-	}
-}
\ No newline at end of file
+  private int stringDiff(String s1, String s2) {
+    int diff = 0;
+    int length = s1.length();
+    for (int i = 0; i < length; i++) {
+      if (s1.charAt(i) != s2.charAt(i)) {
+        diff++;
+      }
+    }
+    return diff;
+  }
+}
diff --git a/WordLadderII.java b/WordLadderII.java
index cb92304..52bec8d 100644
--- a/WordLadderII.java
+++ b/WordLadderII.java
@@ -4,92 +4,91 @@
 import java.util.Map;
 
 /**
- * Given two words (start and end), and a dictionary, find all shortest
- * transformation sequence(s) from start to end, such that:
- * 
- * Only one letter can be changed at a time Each intermediate word must exist in
- * the dictionary For example,
- * 
- * Given: start = "hit" end = "cog" dict = ["hot","dot","dog","lot","log"]
- * 
- * Return:
- * 
- * [ ["hit","hot","dot","dog","cog"], ["hit","hot","lot","log","cog"] ] Note:
- * 
- * All words have the same length. All words contain only lowercase alphabetic
- * characters.
+ * Given two words (start and end), and a dictionary, find all shortest transformation sequence(s)
+ * from start to end, such that:
+ *
+ * <p>Only one letter can be changed at a time Each intermediate word must exist in the dictionary
+ * For example,
+ *
+ * <p>Given: start = "hit" end = "cog" dict = ["hot","dot","dog","lot","log"]
+ *
+ * <p>Return:
+ *
+ * <p>[ ["hit","hot","dot","dog","cog"], ["hit","hot","lot","log","cog"] ] Note:
+ *
+ * <p>All words have the same length. All words contain only lowercase alphabetic characters.
  */
-
 public class WordLadderII {
-	private void GeneratePath(Map<String, ArrayList<String>> prevMap,
-			ArrayList<String> path, String word,
-			ArrayList<ArrayList<String>> ret) {
-		if (prevMap.get(word).size() == 0) {
-			path.add(0, word);
-			ArrayList<String> curPath = new ArrayList<String>(path);
-			ret.add(curPath);
-			path.remove(0);
-			return;
-		}
+  private void GeneratePath(
+      Map<String, ArrayList<String>> prevMap,
+      ArrayList<String> path,
+      String word,
+      ArrayList<ArrayList<String>> ret) {
+    if (prevMap.get(word).size() == 0) {
+      path.add(0, word);
+      ArrayList<String> curPath = new ArrayList<String>(path);
+      ret.add(curPath);
+      path.remove(0);
+      return;
+    }
 
-		path.add(0, word);
-		for (String pt : prevMap.get(word)) {
-			GeneratePath(prevMap, path, pt, ret);
-		}
-		path.remove(0);
-	}
+    path.add(0, word);
+    for (String pt : prevMap.get(word)) {
+      GeneratePath(prevMap, path, pt, ret);
+    }
+    path.remove(0);
+  }
 
-	public ArrayList<ArrayList<String>> findLadders(String start, String end,
-			HashSet<String> dict) {
-		ArrayList<ArrayList<String>> ret = new ArrayList<ArrayList<String>>();
-		Map<String, ArrayList<String>> prevMap = new HashMap<String, ArrayList<String>>();
-		dict.add(start);
-		dict.add(end);
-		for (String d : dict) {
-			prevMap.put(d, new ArrayList<String>());
-		}
-		ArrayList<HashSet<String>> candidates = new ArrayList<HashSet<String>>();
-		candidates.add(new HashSet<String>());
-		candidates.add(new HashSet<String>());
-		int current = 0;
-		int previous = 1;
-		candidates.get(current).add(start);
-		while (true) {
-			current = current == 0 ? 1 : 0;
-			previous = previous == 0 ? 1 : 0;
-			for (String d : candidates.get(previous)) {
-				dict.remove(d);
-			}
-			candidates.get(current).clear();
-			for (String wd : candidates.get(previous)) {
-				for (int pos = 0; pos < wd.length(); ++pos) {
-					StringBuffer word = new StringBuffer(wd);
-					for (int i = 'a'; i <= 'z'; ++i) {
-						if (wd.charAt(pos) == i) {
-							continue;
-						}
+  public ArrayList<ArrayList<String>> findLadders(String start, String end, HashSet<String> dict) {
+    ArrayList<ArrayList<String>> ret = new ArrayList<ArrayList<String>>();
+    Map<String, ArrayList<String>> prevMap = new HashMap<String, ArrayList<String>>();
+    dict.add(start);
+    dict.add(end);
+    for (String d : dict) {
+      prevMap.put(d, new ArrayList<String>());
+    }
+    ArrayList<HashSet<String>> candidates = new ArrayList<HashSet<String>>();
+    candidates.add(new HashSet<String>());
+    candidates.add(new HashSet<String>());
+    int current = 0;
+    int previous = 1;
+    candidates.get(current).add(start);
+    while (true) {
+      current = current == 0 ? 1 : 0;
+      previous = previous == 0 ? 1 : 0;
+      for (String d : candidates.get(previous)) {
+        dict.remove(d);
+      }
+      candidates.get(current).clear();
+      for (String wd : candidates.get(previous)) {
+        for (int pos = 0; pos < wd.length(); ++pos) {
+          StringBuffer word = new StringBuffer(wd);
+          for (int i = 'a'; i <= 'z'; ++i) {
+            if (wd.charAt(pos) == i) {
+              continue;
+            }
 
-						word.setCharAt(pos, (char) i);
+            word.setCharAt(pos, (char) i);
 
-						if (dict.contains(word.toString())) {
-							prevMap.get(word.toString()).add(wd);
-							candidates.get(current).add(word.toString());
-						}
-					}
-				}
-			}
+            if (dict.contains(word.toString())) {
+              prevMap.get(word.toString()).add(wd);
+              candidates.get(current).add(word.toString());
+            }
+          }
+        }
+      }
 
-			if (candidates.get(current).size() == 0) {
-				return ret;
-			}
-			if (candidates.get(current).contains(end)) {
-				break;
-			}
-		}
+      if (candidates.get(current).size() == 0) {
+        return ret;
+      }
+      if (candidates.get(current).contains(end)) {
+        break;
+      }
+    }
 
-		ArrayList<String> path = new ArrayList<String>();
-		GeneratePath(prevMap, path, end, ret);
+    ArrayList<String> path = new ArrayList<String>();
+    GeneratePath(prevMap, path, end, ret);
 
-		return ret;
-	}
-}
\ No newline at end of file
+    return ret;
+  }
+}
diff --git a/WordSearch.java b/WordSearch.java
index 3e88014..dfd6002 100644
--- a/WordSearch.java
+++ b/WordSearch.java
@@ -1,74 +1,62 @@
-
-
 /**
  * Given a 2D board and a word, find if the word exists in the grid.
- * 
- * The word can be constructed from letters of sequentially adjacent cell, where
- * "adjacent" cells are those horizontally or vertically neighboring. The same
- * letter cell may not be used more than once.
- * 
- * For example, Given board =
- * 
- * [ ["ABCE"], 
- *   ["SFCS"], 
- *   ["ADEE"] 
- * ] 
- * 
- * word = "ABCCED", -> returns true, 
- * word = "SEE", -> returns true, 
- * word = "ABCB", -> returns false.
+ *
+ * <p>The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells
+ * are those horizontally or vertically neighboring. The same letter cell may not be used more than
+ * once.
+ *
+ * <p>For example, Given board =
+ *
+ * <p>[ ["ABCE"], ["SFCS"], ["ADEE"] ]
+ *
+ * <p>word = "ABCCED", -> returns true, word = "SEE", -> returns true, word = "ABCB", -> returns
+ * false.
  */
-
 public class WordSearch {
-	public boolean exist(char[][] board, String word) {
-		int height = board.length;
-		int width = board[0].length;
-		boolean[][] map = new boolean[height][width];
-		for (int i = 0; i < height; i++) {
-			for (int j = 0; j < width; j++) {
-				if (search(board, map, i, j, word, 0)) {
-					return true;
-				}
-			}
-		}
-		return false;
-	}
-
-	private boolean search(char[][] board, boolean[][] map, int x, int y,
-			String word, int index) {
-		if (word.charAt(index) != board[x][y]) {
-			return false;
-		}
-		if (index == word.length() - 1) {
-			return true;
-		}
-
-		int height = board.length;
-		int width = board[0].length;
-		map[x][y] = true;
-
-		if (x > 0 && !map[x - 1][y]
-				&& search(board, map, x - 1, y, word, index + 1)) {
-			return true;
-		}
-
-		if (x < height - 1 && !map[x + 1][y]
-				&& search(board, map, x + 1, y, word, index + 1)) {
-			return true;
-		}
-
-		if (y > 0 && !map[x][y - 1]
-				&& search(board, map, x, y - 1, word, index + 1)) {
-			return true;
-		}
-
-		if (y < width - 1 && !map[x][y + 1]
-				&& search(board, map, x, y + 1, word, index + 1)) {
-			return true;
-		}
-
-		map[x][y] = false;
-
-		return false;
-	}
-}
\ No newline at end of file
+  public boolean exist(char[][] board, String word) {
+    int height = board.length;
+    int width = board[0].length;
+    boolean[][] map = new boolean[height][width];
+    for (int i = 0; i < height; i++) {
+      for (int j = 0; j < width; j++) {
+        if (search(board, map, i, j, word, 0)) {
+          return true;
+        }
+      }
+    }
+    return false;
+  }
+
+  private boolean search(char[][] board, boolean[][] map, int x, int y, String word, int index) {
+    if (word.charAt(index) != board[x][y]) {
+      return false;
+    }
+    if (index == word.length() - 1) {
+      return true;
+    }
+
+    int height = board.length;
+    int width = board[0].length;
+    map[x][y] = true;
+
+    if (x > 0 && !map[x - 1][y] && search(board, map, x - 1, y, word, index + 1)) {
+      return true;
+    }
+
+    if (x < height - 1 && !map[x + 1][y] && search(board, map, x + 1, y, word, index + 1)) {
+      return true;
+    }
+
+    if (y > 0 && !map[x][y - 1] && search(board, map, x, y - 1, word, index + 1)) {
+      return true;
+    }
+
+    if (y < width - 1 && !map[x][y + 1] && search(board, map, x, y + 1, word, index + 1)) {
+      return true;
+    }
+
+    map[x][y] = false;
+
+    return false;
+  }
+}
diff --git a/WordSubsets.java b/WordSubsets.java
new file mode 100644
index 0000000..2e1f49e
--- /dev/null
+++ b/WordSubsets.java
@@ -0,0 +1,46 @@
+/**
+ * We are given two arrays A and B of words.  Each word is a string of lowercase letters.
+ *
+ * Now, say that word b is a subset of word a if every letter in b occurs in a, including multiplicity.
+ * For example, "wrr" is a subset of "warrior", but is not a subset of "world".
+ *
+ * Now say a word a from A is universal if for every b in B, b is a subset of a. 
+ *
+ * Return a list of all universal words in A.  You can return the words in any order.
+ */
+class Solution {
+  public List<String> wordSubsets(String[] A, String[] B) {
+    int[][] aMap = new int[10000][26];
+    for (int i = 0; i < A.length; i++) {
+      for (int j = 0; j < A[i].length(); j++) {
+        aMap[i][A[i].charAt(j) - 'a']++;
+      }
+    }
+    int[][] bMap = new int[10000][26];
+    for (int i = 0; i < B.length; i++) {
+      for (int j = 0; j < B[i].length(); j++) {
+        bMap[i][B[i].charAt(j) - 'a']++;
+      }
+    }
+    int[] bCount = new int[26];
+    for (int i = 0; i < 26; i++) {
+      for (int j = 0; j < B.length; j++) {
+        bCount[i] = Math.max(bCount[i], bMap[j][i]);
+      }
+    }
+    List<String> ret = new LinkedList<>();
+    for (int i = 0; i < A.length; i++) {
+      boolean result = true;
+      for (int k = 0; k < 26; k++) {
+        if (bCount[k] > aMap[i][k]) {
+          result = false;
+          break;
+        }
+      }
+      if (result) {
+        ret.add(A[i]);
+      }
+    }
+    return ret;
+  }
+}
diff --git a/ZigZagConversion.java b/ZigZagConversion.java
index c1b11ac..525a07e 100644
--- a/ZigZagConversion.java
+++ b/ZigZagConversion.java
@@ -1,39 +1,49 @@
 
-
-import java.util.ArrayList;
-
 /**
- * The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: 
+ * The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this:
  * (you may want to display this pattern in a fixed font for better legibility)
  *
- * P   A   H   N
- * A P L S I I G
- * Y   I   R
- * 
- * And then read line by line: "PAHNAPLSIIGYIR"
- * Write the code that will take a string and make this conversion given a number of rows:
+ * <p>P A H N A P L S I I G Y I R
  *
- * string convert(string text, int nRows);
- * convert("PAYPALISHIRING", 3) should return "PAHNAPLSIIGYIR".
+ * <p>And then read line by line: "PAHNAPLSIIGYIR" Write the code that will take a string and make
+ * this conversion given a number of rows:
+ *
+ * <p>string convert(string text, int nRows); convert("PAYPALISHIRING", 3) should return
+ * "PAHNAPLSIIGYIR".
  */
-
-public class ZigZagConversion {
-	public String convert(String s, int nRows) {
-		if (nRows <= 1 || s.length() < 2)
-			return s;
-		ArrayList<StringBuilder> sbs = new ArrayList<StringBuilder>();
-		for (int k = 0; k < nRows; k++) {
-			sbs.add(new StringBuilder());
-		}
-		int nCount = 2 * (nRows - 1);
-		for (int i = 0; i < s.length(); i++) {
-			sbs.get(nRows - 1 - Math.abs(nRows - 1 - (i % nCount))).append(
-					s.charAt(i));
-		}
-		StringBuilder sb = new StringBuilder();
-		for (int j = 0; j < nRows; j++) {
-			sb.append(sbs.get(j));
-		}
-		return sb.toString();
-	}
-}
\ No newline at end of file
+class ZigZagConversion {
+  public String convert(String s, int numRows) {
+    if (numRows <= 1) {
+      return s;
+    }
+    // Row index of each char in ZigZag form
+    int[] rowIndex = new int[s.length()];
+    int row = -1;
+    // Simlate the movement of ZigZag, up or down
+    boolean down = true;
+    for (int i = 0; i < rowIndex.length; i++) {
+      if (down) {
+        row += 1;
+        rowIndex[i] = row;
+        if (row == numRows - 1) {
+          down = false;
+        }
+      } else {
+        row -= 1;
+        rowIndex[i] = row;
+        if (row == 0) {
+          down = true;
+        }
+      }
+    }
+    StringBuilder sb = new StringBuilder();
+    for (int c = 0; c < numRows; c++) {
+      for (int i = 0; i < rowIndex.length; i++) {
+        if (rowIndex[i] == c) {
+          sb.append(s.charAt(i));
+        }
+      }
+    }
+    return sb.toString();
+  }
+}
