+ * 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
+ *
+ * 题目大意
+ * 给定一个整数数组,找出其中两个数满足相加等于你指定的目标数字。
+ * 要求:这个函数twoSum必须要返回能够相加等于目标数字的两个数的索引,且index1必须要小于index2。
+ * 请注意一点,你返回的结果(包括index1和index2)都不是基于0开始的。你可以假设每一个输入肯定只有一个结果。
+ *
+ * 解题思路
+ * 创建一个辅助类数组,对辅助类进行排序,使用两个指针,开始时分别指向数组的两端,看这两个下标对应的值是否
+ * 等于目标值,如果等于就从辅助类中找出记录的下标,构造好返回结果,返回。如果大于就让右边的下标向左移,
+ * 进入下一次匹配,如果小于就让左边的下标向右移动,进入下一次匹配,直到所有的数据都处理完
+ *
+ *
+ * @param nums
+ * @param target
+ * @return
+ */
+
+ public int[] twoSum(int[] nums, int target) {
+ int[] result = {0, 0};
+
+ // 因为无素可能会重复,用于记录元素出现的下标
+ Map> map = new HashMap<>(nums.length);
+
+ for (int i = 0; i < nums.length; i++) {
+ if (map.containsKey(nums[i])) {
+ map.get(nums[i]).add(i);
+ } else {
+ List list = new ArrayList<>();
+ list.add(i);
+ map.put(nums[i], list);
+ }
+ }
+
+ for (int num : nums) {
+ int gap = target - num;
+ if (map.containsKey(gap)) {
+ // 同样的元素最多只可以有两个
+ if (gap == num && map.get(num).size() >= 2) {
+ List list = map.get(num);
+ result[0] = Math.min(list.get(0), list.get(1));
+ result[1] = Math.max(list.get(0), list.get(1));
+ } else if (gap != num) {
+ result[0] = Math.min(map.get(num).get(0), map.get(gap).get(0));
+ result[1] = Math.max(map.get(num).get(0), map.get(gap).get(0));
+ }
+ }
+ }
+
+ return result;
+ }
+}
diff --git a/[0001][Two Sum]/src/Solution2.java b/[0001][Two Sum]/src/Solution2.java
new file mode 100644
index 0000000..37103d1
--- /dev/null
+++ b/[0001][Two Sum]/src/Solution2.java
@@ -0,0 +1,94 @@
+import java.util.Arrays;
+
+/**
+ * Author: 王俊超
+ * Date: 2015-06-17
+ * Time: 20:27
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution2 {
+ private static class Node implements Comparable {
+ int val;
+ int idx;
+
+ public Node() {
+ }
+
+ public Node(int val, int idx) {
+ this.val = val;
+ this.idx = idx;
+ }
+
+ @Override
+ public int compareTo(Node o) {
+ if (o == null) {
+ return -1;
+ }
+ return this.val - o.val;
+ }
+ }
+
+
+ /**
+ *
+ * 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
+ *
+ * 题目大意
+ * 给定一个整数数组,找出其中两个数满足相加等于你指定的目标数字。
+ * 要求:这个函数twoSum必须要返回能够相加等于目标数字的两个数的索引,且index1必须要小于index2。
+ * 请注意一点,你返回的结果(包括index1和index2)都不是基于0开始的。你可以假设每一个输入肯定只有一个结果。
+ *
+ * 解题思路
+ * 创建一个辅助类数组,对辅助类进行排序,使用两个指针,开始时分别指向数组的两端,看这两个下标对应的值是否
+ * 等于目标值,如果等于就从辅助类中找出记录的下标,构造好返回结果,返回。如果大于就让右边的下标向左移,
+ * 进入下一次匹配,如果小于就让左边的下标向右移动,进入下一次匹配,直到所有的数据都处理完
+ *
+ *
+ * @param nums
+ * @param target
+ * @return
+ */
+
+ public int[] twoSum(int[] nums, int target) {
+ int[] result = {0, 0};
+
+ Node[] tmp = new Node[nums.length];
+ for (int i = 0; i < nums.length; i++) {
+ tmp[i] = new Node(nums[i], i);
+ }
+
+ // 先排序,然后左右夹逼,排序O(n log n),左右夹逼O(n),最终O(n log n)。但是注
+ // 意,这题需要返回的是下标,而不是数字本身,因此这个方法不好。
+ Arrays.sort(tmp);
+
+ int lo = 0;
+ int hi = nums.length - 1;
+
+
+ while (lo < hi) {
+ if (tmp[lo].val + tmp[hi].val == target) {
+
+ if (tmp[lo].idx > tmp[hi].idx) {
+ result[0] = tmp[hi].idx + 1;
+ result[1] = tmp[lo].idx + 1;
+ } else {
+ result[0] = tmp[lo].idx + 1;
+ result[1] = tmp[hi].idx + 1;
+ }
+ break;
+ } else if (tmp[lo].val + tmp[hi].val > target) {
+ hi--;
+ } else {
+ lo++;
+ }
+ }
+ return result;
+ }
+}
diff --git a/[0002][Add Two Numbers]/[0002][Add Two Numbers].iml b/[0002][Add Two Numbers]/[0002][Add Two Numbers].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0002][Add Two Numbers]/[0002][Add Two Numbers].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0002][Add Two Numbers]/[0002][AddTwoNumbers].iml b/[0002][Add Two Numbers]/[0002][AddTwoNumbers].iml
new file mode 100644
index 0000000..bdc5d75
--- /dev/null
+++ b/[0002][Add Two Numbers]/[0002][AddTwoNumbers].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220002\343\200\221\343\200\220AddTwoNumbers\343\200\221/src/ListNode.java" b/[0002][Add Two Numbers]/src/ListNode.java
similarity index 100%
rename from "\343\200\220002\343\200\221\343\200\220AddTwoNumbers\343\200\221/src/ListNode.java"
rename to [0002][Add Two Numbers]/src/ListNode.java
diff --git a/[0002][Add Two Numbers]/src/Solution.java b/[0002][Add Two Numbers]/src/Solution.java
new file mode 100644
index 0000000..f785707
--- /dev/null
+++ b/[0002][Add Two Numbers]/src/Solution.java
@@ -0,0 +1,89 @@
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 16:04
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * ԭ
+ * 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. Add the two numbers and return it as a linked list.
+ * Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
+ * Output: 7 -> 0 -> 8
+ *
+ * Ŀ
+ * ǸÿһڵһλǷ洢ģ
+ * һʾλһʾλӺͣʽء
+ *
+ * ˼·
+ * ӵһʼӣٳ10̣ΪһλӵĽλ
+ * ͬʱ¼ΪλĽһֱֱеĽ㶼ꡣ
+ *
+ *
+ * @param l1 һ
+ * @param l2 ڶ
+ * @return
+ */
+ public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
+
+ if (l1 == null) {
+ return l2;
+ }
+
+ if (l2 == null) {
+ return l1;
+ }
+
+ ListNode p1 = l1;
+ ListNode p2 = l2;
+ // ͷ
+ ListNode root = new ListNode(0);
+ ListNode r = root;
+ root.next = l1;
+
+ // ʼλ
+ int carry = 0;
+ int sum;
+ while (p1 != null && p2 != null) {
+ sum = p1.val + p2.val + carry;
+ // λĽ
+ p1.val = sum % 10;
+ // νλ
+ carry = sum / 10;
+
+ r.next = p1;
+ // ָһӵĽ
+ r = p1;
+ p1 = p1.next;
+ p2 = p2.next;
+
+ }
+
+ if (p1 == null) {
+ r.next = p2;
+ } else {
+ r.next = p1;
+ }
+
+ // һӻнλ
+ if (carry == 1) {
+ // ʼʱr.nextǵһҪӵĽ
+ while (r.next != null && carry != 0) {
+ sum = r.next.val + carry;
+ r.next.val = sum % 10;
+ carry = sum / 10;
+ r = r.next;
+ }
+
+ // ˻нλҪһµĽ
+ if (carry == 1) {
+ r.next = new ListNode(1);
+ }
+ }
+
+ return root.next;
+ }
+}
diff --git a/[0003][Longest Substring Without Repeating Characters]/[0003][Longest Substring Without Repeating Characters].iml b/[0003][Longest Substring Without Repeating Characters]/[0003][Longest Substring Without Repeating Characters].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0003][Longest Substring Without Repeating Characters]/[0003][Longest Substring Without Repeating Characters].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0003][Longest Substring Without Repeating Characters]/src/Solution.java b/[0003][Longest Substring Without Repeating Characters]/src/Solution.java
new file mode 100644
index 0000000..eac3c22
--- /dev/null
+++ b/[0003][Longest Substring Without Repeating Characters]/src/Solution.java
@@ -0,0 +1,94 @@
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Author:
+ * Date: 2015-06-17
+ * Time: 20:46
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * 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.
+ *
+ * Ŀ⣺
+ * һַַеظӴ
+ *
+ * ˼·
+ * start¼Ŀʼλ
+ * ַǰַӿʼλstartʼѾֹʱӴʼλ+1mapеhashֵΪǰλá
+ *
+ * ԴеUTF-8ַ
+ *
+ *
+ * @param s
+ * @return
+ */
+ public int lengthOfLongestSubstring(String s) {
+ // ַ벻Ϸ
+ if (s == null) {
+ return 0;
+ }
+
+ // ǰĿʼλ
+ int start = 0;
+ //
+ int result = 0;
+ // ʱǣ¼һηʵַλ
+ Map map = new HashMap<>(s.length());
+
+ for (int i = 0; i < s.length(); i++) {
+ char ch = s.charAt(i);
+ // ַѾֹ(ڱǿλ)±start
+ if (map.containsKey(ch) && map.get(ch) >= start) {
+ start = map.get(ch) + 1;
+ }
+ // ûгֹķظӴij
+ else {
+ result = Math.max(result, i - start + 1);
+ }
+
+ // ·ʼ¼
+ map.put(ch, i);
+ }
+ return result;
+ }
+
+ /**
+ * ֻASCIIַ
+ */
+ public int lengthOfLongestSubstring2(String s) {
+ // ַ벻Ϸ
+ if (s == null) {
+ return 0;
+ }
+
+ // ַǷֹҼ¼ǵһηʵԪصλ
+ int[] appear = new int[256];
+ // ʼΪ-1
+ Arrays.fill(appear, -1);
+ // ǰĿʼλ
+ int start = 0;
+ //
+ int result = 0;
+
+ for (int i = 0; i < s.length(); i++) {
+ // ַѾֹ(ڱǿλ)±start
+ if (appear[s.charAt(i)] >= start) {
+ start = i + 1;
+ }
+ // ûгֹķظӴij
+ else {
+ result = Math.max(result, i - start + 1);
+ }
+ // ǵiַѾʹǵiλã
+ appear[s.charAt(i)] = i;
+ }
+
+ return result;
+ }
+}
diff --git a/[0004][Median of Two Sorted Arrays]/[0004][Median of Two Sorted Arrays].iml b/[0004][Median of Two Sorted Arrays]/[0004][Median of Two Sorted Arrays].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0004][Median of Two Sorted Arrays]/[0004][Median of Two Sorted Arrays].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0004][Median of Two Sorted Arrays]/src/Main.java b/[0004][Median of Two Sorted Arrays]/src/Main.java
new file mode 100644
index 0000000..06c2105
--- /dev/null
+++ b/[0004][Median of Two Sorted Arrays]/src/Main.java
@@ -0,0 +1,35 @@
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-14 13:21
+ **/
+public class Main {
+
+ @Test
+ public void test() {
+ int[] nums1 = {1, 3};
+ int[] nums2 = {2};
+ Solution solution = new Solution();
+ Assert.assertEquals(2, solution.findMedianSortedArrays(nums1, nums2), 0.000001);
+ }
+
+ @Test
+ public void test2() {
+ int[] nums1 = {1, 2};
+ int[] nums2 = {3, 4};
+ Solution solution = new Solution();
+ Assert.assertEquals(2.5, solution.findMedianSortedArrays(nums1, nums2), 0.000001);
+ }
+
+ @Test
+ public void test3() {
+ int[] nums1 = {6};
+ int[] nums2 = {1, 2, 3, 4, 5};
+ Solution solution = new Solution();
+ Assert.assertEquals(3.5, solution.findMedianSortedArrays(nums1, nums2), 0.000001);
+ }
+
+
+}
diff --git a/[0004][Median of Two Sorted Arrays]/src/Solution.java b/[0004][Median of Two Sorted Arrays]/src/Solution.java
new file mode 100644
index 0000000..9547a99
--- /dev/null
+++ b/[0004][Median of Two Sorted Arrays]/src/Solution.java
@@ -0,0 +1,92 @@
+/**
+ * Author:
+ * Date: 2015-06-17
+ * Time: 20:54
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * There are two sorted arrays nums1 and nums2 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)).
+ *
+ * Ŀ⣺
+ * 飬λʱ临ӶΪO(log(m+n))
+ *
+ * ˼·
+ * ݹ
+ *
+ *
+ * @param nums1
+ * @param nums2
+ * @return
+ */
+ public double findMedianSortedArrays(int[] nums1, int[] nums2) {
+ int total = nums1.length + nums2.length;
+ if (total % 2 != 0) {
+ return findKth(nums1, 0, nums2, 0, total / 2 + 1);
+ } else {
+ return (findKth(nums1, 0, nums2, 0, total / 2)
+ + findKth(nums1, 0, nums2, 0, total / 2 + 1)
+ ) / 2.0;
+ }
+ }
+
+ /**
+ * ҵkԪأk=1, 2, 3, ...
+ *
+ * @param nums1 1
+ * @param start1 ʼλ1
+ * @param nums2 2
+ * @param start2 ʼλ2
+ * @param k Ҫҵλλ
+ * @return
+ */
+ public int findKth(int[] nums1, final int start1,
+ int[] nums2, final int start2,
+ final int k) {
+ // ҪҳСķǰ
+ if (nums1.length - start1 > nums2.length - start2) {
+ return findKth(nums2, start2, nums1, start1, k);
+ }
+
+ // ԪصѾﵽĩβ
+ if (nums1.length == start1) {
+ return nums2[start2 + k - 1];
+ }
+
+ // һбȽС
+ if (k == 1) {
+ return Math.min(nums1[start1], nums2[start2]);
+ }
+
+
+ // num1, nums2иһ൱ÿζҪ1/4
+ int half = Math.min(k / 2, nums1.length - start1);
+ // nums2пҵλ
+ int ia = half + start1;
+ // nums2пҵλ
+ int ib = k - half + start2;
+
+ // nums1[start, ..., ia-1, ia, ..., nums1.length]
+ // nums2[start, ..., ib-1, ib, ..., nums2.length]
+ // ˵nums1[start, ..., ia-1]ˣҪҵֵnums1[ia, ..., nums1.length]
+ // nums2[start, ..., ib-1, ib, ..., nums2.length]
+ if (nums1[ia - 1] < nums2[ib - 1]) {
+ // k - (ia - start1) = k - (half + start1 - start1) = k - half
+ return findKth(nums1, ia, nums2, start2, k - (ia - start1));
+ }
+
+ // ˵nums2[start, ..., ib-1]ˣҪҵֵnums2[ib, ..., nums2.length]
+ // nums1[start, ..., ia-1, ia, ..., nums1.length]
+ else if (nums1[ia - 1] > nums2[ib - 1]) {
+ // k - (ib - start2) = k - (k - half + start2 - start2)
+ return findKth(nums1, start1, nums2, ib, half);
+ }
+ // ֵ˵ҵˣ
+ else {
+ return nums1[ia - 1];
+ }
+ }
+}
diff --git a/[0004][Median of Two Sorted Arrays]/src/Solution2.java b/[0004][Median of Two Sorted Arrays]/src/Solution2.java
new file mode 100644
index 0000000..601e821
--- /dev/null
+++ b/[0004][Median of Two Sorted Arrays]/src/Solution2.java
@@ -0,0 +1,79 @@
+/**
+ * Author:
+ * Date: 2015-06-17
+ * Time: 20:54
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution2 {
+ /**
+ *
+ * There are two sorted arrays nums1 and nums2 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)).
+ *
+ * Ŀ⣺
+ * 飬λʱ临ӶΪO(log(m+n))
+ *
+ * ˼·
+ * ݹ
+ *
+ * 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.
+ *
+ * Ŀ⣺
+ * һַSҳĻӴԼַ1000
+ * ҴΨһӴ
+ *
+ * ˼·
+ * ̬滮
+ * dp[ i ][ j ]ֵΪtrueʾַs± i j ַɵӴǻĴôƳ
+ * dp[ i ][ j ] = dp[ i + 1][ j - 1] && s[ i ] == s[ j ]
+ * һҪi+1, j -1п i + 1 = j -1, i +1 = (j - 1) -1
+ * ҪϵĹʽ
+ *
+ * a. i + 1 = j -1ijΪ1ʱdp[ i ][ i ] = true;
+ * b. i +1 = (j - 1) -1ijΪ2ʱdp[ i ][ i + 1] = (s[ i ] == s[ i + 1])
+ *
+ * ϷͿдˡҪעǶ̬滮ҪO(n^2)Ŀռ䡣
+ *
+ *
+ * @param s
+ * @return
+ */
+ public String longestPalindrome(String s) {
+
+ if (s == null || s.length() < 2) {
+ return s;
+ }
+
+ int maxLength = 0;
+ String longest = null;
+
+ int length = s.length();
+ boolean[][] table = new boolean[length][length];
+
+ // ַǻ
+ for (int i = 0; i < length; i++) {
+ table[i][i] = true;
+ longest = s.substring(i, i + 1);
+ maxLength = 1;
+ }
+
+ // жַǷǻ
+ for (int i = 0; i < length - 1; i++) {
+ if (s.charAt(i) == s.charAt(i + 1)) {
+ table[i][i + 1] = true;
+ longest = s.substring(i, i + 2);
+ maxLength = 2;
+ }
+ }
+
+
+ // ȴ2ӴǷǻĴ
+ for (int len = 3; len <= length; len++) {
+ for (int i = 0, j; (j = i + len - 1) <= length - 1; i++) {
+ if (s.charAt(i) == s.charAt(j)) {
+ table[i][j] = table[i + 1][j - 1];
+ if (table[i][j] && maxLength < len) {
+ longest = s.substring(i, j + 1);
+ maxLength = len;
+ }
+ } else {
+ table[i][j] = false;
+ }
+ }
+ }
+
+ return longest;
+ }
+
+
+}
diff --git a/[0006][Zig Zag Conversion]/[0006][Zig Zag Conversion].iml b/[0006][Zig Zag Conversion]/[0006][Zig Zag Conversion].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0006][Zig Zag Conversion]/[0006][Zig Zag Conversion].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0006][Zig Zag Conversion]/src/Solution.java b/[0006][Zig Zag Conversion]/src/Solution.java
new file mode 100644
index 0000000..0d5a31a
--- /dev/null
+++ b/[0006][Zig Zag Conversion]/src/Solution.java
@@ -0,0 +1,94 @@
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 16:08
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * ԭ
+ * 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
+ * APLSIIG
+ * 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:
+ * string convert(string text, int nRows);
+ * convert(PAYPALISHIRING,3) should return PAHNAPLSIIGYIR.
+ * Ŀ
+ * һַַָZ
+ *
+ * ˼·
+ * ַһһά飬ټÿַһάеλã
+ * ٶһάеַнղؽ
+ *
+ *
+ * @param s
+ * @param nRows
+ * @return
+ */
+ public String convert(String s, int nRows) {
+
+ if (s == null || s.length() <= nRows || nRows == 1) {
+ return s;
+ }
+
+ int index = s.length();
+ int rowLength = 0; // еijȣַ
+
+ int slash = nRows - 2; // һб߳ȥβռõ
+
+ while (index > 0) {
+ // εһ
+ index -= nRows;
+ rowLength++;
+
+ // бŵ
+ for (int i = 0; i < slash && index > 0; i++) {
+ rowLength++;
+ index--;
+ }
+ }
+
+ char[] result = new char[nRows * rowLength]; // 飬һڱ滻з
+ for (int i = 0; i < result.length; i++) { // ʼΪո
+ result[i] = ' ';
+ }
+
+ int curColumn = 0; // ǰ
+ index = 0;
+ while (index < s.length()) {
+ //
+ for (int i = 0; i < nRows && index < s.length(); i++) {
+ result[rowLength * i + curColumn] = s.charAt(index);
+ index++;
+ }
+ curColumn++;
+ // б
+ for (int i = nRows - 2; i > 0 && index < s.length(); i--) {
+ result[rowLength * i + curColumn] = s.charAt(index);
+ curColumn++;
+ index++;
+ }
+ }
+
+ // ַнղ
+ index = 0;
+ while (index < s.length() && result[index] != ' ') { // ҵһǿոַλ
+ index++;
+ }
+ int next = index + 1;
+ while (index < s.length()) {
+ while (next < result.length && result[next] == ' ') { // ҲǿոԪ
+ next++;
+ }
+ result[index] = result[next];
+ index++;
+ next++;
+ }
+ return new String(result, 0, index);
+ }
+}
diff --git a/[0007][Reverse Integer]/[0007][Reverse Integer].iml b/[0007][Reverse Integer]/[0007][Reverse Integer].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0007][Reverse Integer]/[0007][Reverse Integer].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220007\343\200\221\343\200\220ReverseInteger\343\200\221/src/Solution.java" b/[0007][Reverse Integer]/src/Solution.java
similarity index 100%
rename from "\343\200\220007\343\200\221\343\200\220ReverseInteger\343\200\221/src/Solution.java"
rename to [0007][Reverse Integer]/src/Solution.java
diff --git a/[0008][String To Integer (atoi)]/[0008][String To Integer (atoi)].iml b/[0008][String To Integer (atoi)]/[0008][String To Integer (atoi)].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0008][String To Integer (atoi)]/[0008][String To Integer (atoi)].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0008][String To Integer (atoi)]/src/Solution.java b/[0008][String To Integer (atoi)]/src/Solution.java
new file mode 100644
index 0000000..5e1e1e1
--- /dev/null
+++ b/[0008][String To Integer (atoi)]/src/Solution.java
@@ -0,0 +1,104 @@
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 16:13
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * ԭ
+ * 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.
+ *
+ * Ŀ
+ * ʵһatoiַת
+ * Ҫ㣺е
+ *
+ * ˼·
+ * ǰַ+-ûУֲ֣ܱʾС
+ * ͷضӦССֵ
+ *
+ * ԭ
+ * Determine whether an integer is a palindrome. Do this without extra space.
+ *
+ * Ŀ
+ * жһǷǻطҪʹöĿռ䡣
+ *
+ * ˼·
+ * Ϊ˲ʹöĿռ䣬οĽЩⷨisPalindromeûʹö
+ * ȴʹ˷ãһĵĿռ ûдﵽĿҪǼٵʵ֣
+ * ԱȻһĿռʵ֡
+ * ȣǻ֣ζֽת123321任˵ǻ֡
+ *
+ *
+ * @param x
+ * @return
+ */
+ public boolean isPalindrome(int x) {
+
+ // ǻ
+ if (x < 0) {
+ return false;
+ }
+
+ // תֵΪ˲ʹlong
+ long reverse = 0;
+ int tmp = x;
+
+ // תֵ
+ while (tmp != 0) {
+ reverse = reverse * 10 + tmp % 10;
+ tmp /= 10;
+ }
+
+ // жǷǻ
+ return x == reverse;
+ }
+}
diff --git a/[0010][Regular Expression Matching]/[0010][Regular Expression Matching].iml b/[0010][Regular Expression Matching]/[0010][Regular Expression Matching].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0010][Regular Expression Matching]/[0010][Regular Expression Matching].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220010\343\200\221\343\200\220RegularExpressionMatching\343\200\221/src/Main.java" b/[0010][Regular Expression Matching]/src/Main.java
similarity index 100%
rename from "\343\200\220010\343\200\221\343\200\220RegularExpressionMatching\343\200\221/src/Main.java"
rename to [0010][Regular Expression Matching]/src/Main.java
diff --git a/[0010][Regular Expression Matching]/src/Solution.java b/[0010][Regular Expression Matching]/src/Solution.java
new file mode 100644
index 0000000..8116492
--- /dev/null
+++ b/[0010][Regular Expression Matching]/src/Solution.java
@@ -0,0 +1,120 @@
+import java.util.Arrays;
+
+/**
+ * Author:
+ * Date: 2015-06-24
+ * Time: 20:42
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * 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
+ *
+ * Ŀ⣺
+ * ʵһʽƥ㷨.ƥһַ*ƥ0߶ǰַ
+ *
+ * Կ˼·
+ * ע
+ *
+ *
+ *
+ * @param s
+ * @param p
+ * @return
+ */
+ public boolean isMatch(String s, String p) {
+ boolean[] match = new boolean[s.length() + 1];
+ Arrays.fill(match, false);
+ match[s.length()] = true;
+ for (int i = p.length() - 1; i >= 0; i--) {
+ if (p.charAt(i) == '*') {
+ for (int j = s.length() - 1; j >= 0; j--) {
+ match[j] = match[j] || match[j + 1]
+ && (p.charAt(i - 1) == '.' || s.charAt(j) == p.charAt(i - 1));
+ }
+ i--;
+ } else {
+ for (int j = 0; j < s.length(); j++) {
+ match[j] = match[j + 1]
+ && (p.charAt(i) == '.' || p.charAt(i) == s.charAt(j));
+ }
+
+ match[s.length()] = false;
+ }
+ }
+ return match[0];
+ }
+
+ // ĴʱȽϳ
+ public boolean isMatch2(String s, String p) {
+ // 붼Ϊnull
+ if (s == null && p == null) {
+ return true;
+ }
+ // һΪnull
+ else if (s == null || p == null) {
+ return false;
+ }
+
+ return isMatch(s, 0, p, 0);
+ }
+
+ /**
+ * ʽƥ
+ *
+ * @param s ƥ䴮
+ * @param sIdx ǰƥλ
+ * @param p ģʽ
+ * @param pIdx ģʽƥλ
+ * @return ƥ
+ */
+ public boolean isMatch(String s, int sIdx, String p, int pIdx) {
+ // ͬʱԵĩβ
+ if (s.length() == sIdx && p.length() == pIdx) {
+ return true;
+ }
+ // ƥ䴮ûеĩβģʽѾĩβ
+ else if (s.length() != sIdx && p.length() == pIdx) {
+ return false;
+ }
+ //
+ else {
+ // ǰƥһַ*
+ if (pIdx < p.length() - 1 && p.charAt(pIdx + 1) == '*') {
+ // ƥ䴮δҵǰַƥ䣨ַȻ.ţ
+ if (sIdx < s.length() && (s.charAt(sIdx) == p.charAt(pIdx) || p.charAt(pIdx) == '.')) {
+ return isMatch(s, sIdx + 1, p, pIdx + 2) // ƥ䴮ǰƶһַֻƥһΣ
+ || isMatch(s, sIdx + 1, p, pIdx) // ƥ䴮ǰƶһַһƥͬģģʽ
+ || isMatch(s, sIdx, p, pIdx + 2); // ƥģʽ
+ } else {
+ // *
+ return isMatch(s, sIdx, p, pIdx + 2);
+ }
+ }
+
+ // ƥһַ
+ if (sIdx < s.length() && (s.charAt(sIdx) == p.charAt(pIdx) || p.charAt(pIdx) == '.')) {
+ return isMatch(s, sIdx + 1, p, pIdx + 1);
+ }
+ }
+
+ return false;
+ }
+
+}
diff --git a/[0011][Container With Most Water]/[0011][Container With Most Water].iml b/[0011][Container With Most Water]/[0011][Container With Most Water].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0011][Container With Most Water]/[0011][Container With Most Water].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0011][Container With Most Water]/src/Solution.java b/[0011][Container With Most Water]/src/Solution.java
new file mode 100644
index 0000000..88407f0
--- /dev/null
+++ b/[0011][Container With Most Water]/src/Solution.java
@@ -0,0 +1,88 @@
+/**
+ * Author:
+ * Date: 2015-06-30
+ * Time: 07:25
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * 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.
+ *
+ * Ŀ⣺
+ * ȻԼXṹɵˮ
+ *
+ * ˼·
+ * ʹ̰㷨
+ * 1.ȼҵȡݻΪ i, j (ٶi < j)
+ * ôõݻ C = min( ai , aj ) * ( j- i)
+ *
+ * 2.ǿôһʣ
+ * : j Ҷûһߣ k |( j < k && ak > aj)
+ * ô ak > aj min(ai, aj, ak) =min(ai, aj)
+ * i, kɵݻC' = min(ai, aj) * (k - i) > C
+ * CֵìܣԵ֤jĺ߲бߵߣ
+ *
+ * :ͬiҲбߵߣ˵ʲôأ
+ * Ŀǰõĺѡ Ϊ x, yߣx< y)ôܹõ
+ * ݻµ߱Ȼ[x, y]ڲ ax' >= ax , ay' >= ay;
+ *
+ * 3.Ǵͷм俿£ͬʱºѡֵʱȴ
+ * x, yнСı߿ʼ
+ *
+ *
+ * @param height
+ * @return
+ */
+ public int maxArea(int[] height) {
+
+ // У
+ if (height == null || height.length < 2) {
+ return 0;
+ }
+
+
+ // ¼Ľ
+ int result = 0;
+
+ // ߵ
+ int left = 0;
+ // ұߵ
+ int right = height.length - 1;
+
+ while (left < right) {
+ // 㵱ǰֵ
+ result = Math.max(result, Math.min(height[left], height[right]) * (right - left));
+ // ұ߸
+ if (height[left] < height[right]) {
+ int k = left;
+ // [left, right - 1]Уңҵһ߶ȱheight[left]ߵλ
+ while (k < right && height[k] <= height[left]) {
+ k++;
+ }
+
+ // [left, right - 1]У¼һԭheight[left]ߵλ
+ left = k;
+ }
+ // ߵ߸
+ else {
+ int k = right;
+ // [left + 1, right]Уңҵһ߶ȱheight[right]ߵλ
+ while (k > left && height[k] <= height[right]) {
+ k--;
+ }
+
+ // [left, right - 1]У¼һԭheight[right]ߵλ
+ right = k;
+ }
+ }
+
+ return result;
+ }
+}
diff --git a/[0011][Container With Most Water]/src/Solution2.java b/[0011][Container With Most Water]/src/Solution2.java
new file mode 100644
index 0000000..556a26a
--- /dev/null
+++ b/[0011][Container With Most Water]/src/Solution2.java
@@ -0,0 +1,74 @@
+/**
+ * Author:
+ * Date: 2015-06-30
+ * Time: 07:25
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution2 {
+ /**
+ *
+ * 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.
+ *
+ * Ŀ⣺
+ * ȻԼXṹɵˮ
+ *
+ * ˼·
+ * ʹ̰㷨
+ * 1.ȼҵȡݻΪ i, j (ٶi aj)
+ * ô ak > aj min(ai, aj, ak) =min(ai, aj)
+ * i, kɵݻC' = min(ai, aj) * (k - i) > C
+ * CֵìܣԵ֤jĺ߲бߵߣ
+ *
+ * :ͬiҲбߵߣ˵ʲôأ
+ * Ŀǰõĺѡ Ϊ x, yߣx< y)ôܹõ
+ * ݻµ߱Ȼ[x, y]ڲ ax' >= ax , ay' >= ay;
+ *
+ * 3.Ǵͷм俿£ͬʱºѡֵʱȴ
+ * x, yнСı߿ʼ
+ *
+ *
+ * @param height
+ * @return
+ */
+ public int maxArea(int[] height) {
+
+ // У
+ if (height == null || height.length < 2) {
+ return 0;
+ }
+
+
+ // ¼Ľ
+ int result = 0;
+
+ // ߵ
+ int left = 0;
+ // ұߵ
+ int right = height.length - 1;
+
+ while (left < right) {
+ // 㵱ǰֵ
+ result = Math.max(result, Math.min(height[left], height[right]) * (right - left));
+ // ұ߸
+ if (height[left] < height[right]) {
+ left++;
+ }
+ // ߵ߸
+ else {
+ right--;
+ }
+ }
+
+ return result;
+ }
+}
diff --git a/[0012][Integer To Roman]/[0012][Integer To Roman].iml b/[0012][Integer To Roman]/[0012][Integer To Roman].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0012][Integer To Roman]/[0012][Integer To Roman].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0012][Integer To Roman]/src/Main.java b/[0012][Integer To Roman]/src/Main.java
new file mode 100644
index 0000000..395df1b
--- /dev/null
+++ b/[0012][Integer To Roman]/src/Main.java
@@ -0,0 +1,39 @@
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-17 14:03
+ **/
+public class Main {
+
+ @Test
+ public void test1() {
+ Solution2 solution = new Solution2();
+ Assert.assertEquals("III", solution.intToRoman(3));
+ }
+
+ @Test
+ public void test2() {
+ Solution2 solution = new Solution2();
+ Assert.assertEquals("IV", solution.intToRoman(4));
+ }
+
+ @Test
+ public void test3() {
+ Solution2 solution = new Solution2();
+ Assert.assertEquals("IX", solution.intToRoman(9));
+ }
+
+ @Test
+ public void test4() {
+ Solution2 solution = new Solution2();
+ Assert.assertEquals("LVIII", solution.intToRoman(58));
+ }
+
+ @Test
+ public void test5() {
+ Solution2 solution = new Solution2();
+ Assert.assertEquals("MCMXCIV", solution.intToRoman(1994));
+ }
+}
diff --git "a/\343\200\220012\343\200\221\343\200\220IntegerToRoman\343\200\221/src/Solution.java" b/[0012][Integer To Roman]/src/Solution.java
similarity index 100%
rename from "\343\200\220012\343\200\221\343\200\220IntegerToRoman\343\200\221/src/Solution.java"
rename to [0012][Integer To Roman]/src/Solution.java
diff --git a/[0012][Integer To Roman]/src/Solution2.java b/[0012][Integer To Roman]/src/Solution2.java
new file mode 100644
index 0000000..f13fad7
--- /dev/null
+++ b/[0012][Integer To Roman]/src/Solution2.java
@@ -0,0 +1,56 @@
+/**
+ * Author:
+ * Date: 2015-06-30
+ * Time: 14:28
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution2 {
+ /**
+ *
+ *
+ * @param num
+ * @return
+ */
+ public String intToRoman(int num) {
+
+ final int[] radix = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
+ final String[] symbol = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
+ String roman = "";
+ for (int i = 0; num > 0; ++i) {
+ int count = num / radix[i];
+ num %= radix[i];
+ for (; count > 0; --count) {
+ roman += symbol[i];
+ }
+ }
+ return roman;
+ }
+}
diff --git a/[0013][Roman To Integer]/[0013][Roman To Integer].iml b/[0013][Roman To Integer]/[0013][Roman To Integer].iml
new file mode 100644
index 0000000..73f33e3
--- /dev/null
+++ b/[0013][Roman To Integer]/[0013][Roman To Integer].iml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0013][Roman To Integer]/src/Main.java b/[0013][Roman To Integer]/src/Main.java
new file mode 100644
index 0000000..5d7ae8a
--- /dev/null
+++ b/[0013][Roman To Integer]/src/Main.java
@@ -0,0 +1,37 @@
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Author: 王俊超
+ * Date: 2015-03-01
+ * Time: 16:35
+ * Declaration: All Rights Reserved !!!
+ */
+public class Main {
+ public static void main(String[] args) {
+ Solution solution = new Solution();
+
+ System.out.println(solution.romanToInt("I"));
+ System.out.println(solution.romanToInt("II"));
+ System.out.println(solution.romanToInt("III"));
+ System.out.println(solution.romanToInt("IV"));
+ System.out.println(solution.romanToInt("V"));
+ System.out.println(solution.romanToInt("VI"));
+
+ System.out.println(solution.romanToInt("XCVIII"));
+ System.out.println(solution.romanToInt("XCIX"));
+
+ System.out.println(solution.romanToInt("CM"));
+ System.out.println(solution.romanToInt("CMXCIX"));
+
+ System.out.println(solution.romanToInt("MDCLXVI"));
+ System.out.println(solution.romanToInt("MCMLXXVI"));
+ System.out.println(solution.romanToInt("MMMCMXCIX"));
+ }
+
+ @Test
+ public void test1() {
+ Solution solution = new Solution();
+ Assert.assertEquals(1994, solution.romanToInt("MCMXCIV"));
+ }
+}
diff --git a/[0013][Roman To Integer]/src/Solution.java b/[0013][Roman To Integer]/src/Solution.java
new file mode 100644
index 0000000..eee8be3
--- /dev/null
+++ b/[0013][Roman To Integer]/src/Solution.java
@@ -0,0 +1,64 @@
+/**
+ * Author: 王俊超
+ * Date: 2015-03-01
+ * Time: 16:09
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * 原题
+ * Given a roman numeral, convert it to an integer.
+ * Input is guaranteed to be within the range from 1 to 3999.
+ *
+ * 题目大意
+ * 给定一个罗马数字,将其转换成对应的整数。
+ * 输入的数字在1-3999之间。
+ *
+ * 解题思路
+ * 从前往后扫描,用一个临时变量记录分段数字。
+ * 如果当前比前一个大,说明这一段的值应该是当前这个值减去上一个值。比如IV = 5 – 1;否
+ * 则,将当前值加入到结果中,然后开始下一段记录。比如VI = 5 + 1, II=1+1
+ *
+ *
+ * @param s
+ * @return
+ */
+ public int romanToInt(String s) {
+
+ int result = 0;
+
+ for (int i = 0; i < s.length(); i++) {
+ // 当前的值比前一个值大,说明[i-1, i]组成一个值,并且值是s[i-1]-s[i]
+ if (i > 0 && charToInt(s.charAt(i)) > charToInt(s.charAt(i - 1))) {
+ // 要减去两倍之前前值才能回到真实值
+ result += charToInt(s.charAt(i)) - 2 * charToInt(s.charAt(i - 1));
+ } else {
+ result += charToInt(s.charAt(i));
+ }
+ }
+
+ return result;
+ }
+
+ private int charToInt(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/[0013][Roman To Integer]/src/Solution2.java b/[0013][Roman To Integer]/src/Solution2.java
new file mode 100644
index 0000000..9d08f55
--- /dev/null
+++ b/[0013][Roman To Integer]/src/Solution2.java
@@ -0,0 +1,98 @@
+/**
+ * Author: 王俊超
+ * Date: 2015-03-01
+ * Time: 16:09
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution2 {
+ /**
+ *
+ * 原题
+ * Given a roman numeral, convert it to an integer.
+ * Input is guaranteed to be within the range from 1 to 3999.
+ *
+ * 题目大意
+ * 给定一个罗马数字,将其转换成对应的整数。
+ * 输入的数字在1-3999之间。
+ *
+ * 解题思路
+ * 根据罗马数字与整数数字对应关系进行加法操作,如果前一个数字比后一个大就相减,否则进行相加。
+ *
+ *
+ * @param s
+ * @return
+ */
+ public int romanToInt(String s) {
+
+ int result = 0;
+ int prev = 0; // 记录前一个数字的值
+
+ for (int i = s.length() - 1; i > -1; i--) {
+ switch (s.charAt(i)) {
+ case 'I': // 1
+ if (1 < prev) {
+ result -= 1;
+ } else {
+ result += 1;
+
+ }
+ prev = 1;
+ break;
+
+ case 'V': // 5
+
+ if (5 < prev) {
+ result -= 5;
+ } else {
+ result += 5;
+ }
+
+ prev = 5;
+
+ break;
+ case 'X': // 10
+ if (10 < prev) {
+ result -= 10;
+ } else {
+ result += 10;
+ }
+
+ prev = 10;
+ break;
+ case 'L': // 50
+ if (50 < prev) {
+ result -= 50;
+ } else {
+ result += 50;
+ }
+
+ prev = 50;
+ break;
+ case 'C': // 100
+ if (100 < prev) {
+ result -= 100;
+ } else {
+ result += 100;
+ }
+
+ prev = 100;
+ break;
+ case 'D': // 500
+ if (500 < prev) {
+ result -= 500;
+ } else {
+ result += 500;
+ }
+
+ prev = 500;
+ break;
+ case 'M': // 1000
+ result += 1000;
+ prev = 1000;
+ break;
+ }
+ }
+
+ return result;
+ }
+}
diff --git a/[0014][Longest Common Prefix]/[0014][Longest Common Prefix].iml b/[0014][Longest Common Prefix]/[0014][Longest Common Prefix].iml
new file mode 100644
index 0000000..73f33e3
--- /dev/null
+++ b/[0014][Longest Common Prefix]/[0014][Longest Common Prefix].iml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0014][Longest Common Prefix]/src/Main.java b/[0014][Longest Common Prefix]/src/Main.java
new file mode 100644
index 0000000..8b1b6f7
--- /dev/null
+++ b/[0014][Longest Common Prefix]/src/Main.java
@@ -0,0 +1,20 @@
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-17 13:05
+ **/
+public class Main {
+ @Test
+ public void test1() {
+ Solution solution = new Solution();
+ Assert.assertEquals("fl", solution.longestCommonPrefix(new String[]{"flower", "flow", "flight"}));
+ }
+
+ @Test
+ public void test2() {
+ Solution solution = new Solution();
+ Assert.assertEquals("", solution.longestCommonPrefix(new String[]{"dog", "racecar", "car"}));
+ }
+}
diff --git a/[0014][Longest Common Prefix]/src/Solution.java b/[0014][Longest Common Prefix]/src/Solution.java
new file mode 100644
index 0000000..05c3523
--- /dev/null
+++ b/[0014][Longest Common Prefix]/src/Solution.java
@@ -0,0 +1,59 @@
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 16:19
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * ԭ
+ * Write a function to find the longest common prefix string amongst an array of strings.
+ *
+ * Ŀ
+ * дһҳһִеĹǰ
+ *
+ * ˼·
+ * һҳСַȻַַҳ̵ǰ
+ *
+ *
+ * @param strs
+ * @return
+ */
+ public String longestCommonPrefix(String[] strs) {
+ if (strs == null) {
+ return null;
+ }
+
+ if (strs.length == 0) {
+ return "";
+ }
+
+ // ¼̵ַij
+ int min = Integer.MAX_VALUE;
+
+ // Ҷַij
+ String result = "";
+ for (String str : strs) {
+
+ if (str == null || str.length() == 0) {
+ return "";
+ }
+
+ if (min > str.length()) {
+ min = str.length();
+ result = str;
+ }
+ }
+
+ for (String s : strs) {
+ for (int i = 0; i < result.length(); i++) {
+ if (result.charAt(i) != s.charAt(i)) {
+ result = result.substring(0, i);
+ }
+ }
+ }
+
+ return result;
+ }
+}
diff --git a/[0014][Longest Common Prefix]/src/Solution2.java b/[0014][Longest Common Prefix]/src/Solution2.java
new file mode 100644
index 0000000..17eb282
--- /dev/null
+++ b/[0014][Longest Common Prefix]/src/Solution2.java
@@ -0,0 +1,65 @@
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 16:19
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution2 {
+ /**
+ *
+ * ԭ
+ * Write a function to find the longest common prefix string amongst an array of strings.
+ *
+ * Ŀ
+ * дһҳһִеĹǰ
+ *
+ * ˼·
+ * һҳСַȻַַҳ̵ǰ
+ *
+ * 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)
+ *
+ * Ŀ⣺
+ *
+ *
+ *
+ * @param nums
+ * @return
+ */
+ public List> threeSum(int[] nums) {
+ List> result = new LinkedList<>();
+
+ if (nums == null || nums.length < 3) {
+ return result;
+ }
+
+ Arrays.sort(nums);
+ int target = 0;
+
+ int a = 0;
+ while (a < nums.length - 2) {
+ int b = a + 1;
+ int c = nums.length - 1;
+ while (b < c) {
+ if (nums[a] + nums[b] + nums[c] < target) {
+ do {
+ ++b;
+ } while (b < c && nums[b] == nums[b - 1]);
+ } else if (nums[a] + nums[b] + nums[c] > target) {
+ do {
+ --c;
+ } while (b < c && nums[c] == nums[c + 1]);
+ } else {
+ List idxs = new ArrayList<>();
+ idxs.add(nums[a]);
+ idxs.add(nums[b]);
+ idxs.add(nums[c]);
+ result.add(idxs);
+
+ do {
+ ++b;
+ } while (b < c && nums[b] == nums[b - 1]);
+ do {
+ --c;
+ } while (b < c && nums[c] == nums[c + 1]);
+ }
+ }
+
+ // nums[a-1]Ѿѡˣѡ
+ do {
+ ++a;
+ } while (a < nums.length - 2 && nums[a - 1] == nums[a]);
+ }
+ return result;
+ }
+
+}
diff --git a/[0015][3 Sum]/src/Solution2.java b/[0015][3 Sum]/src/Solution2.java
new file mode 100644
index 0000000..f840265
--- /dev/null
+++ b/[0015][3 Sum]/src/Solution2.java
@@ -0,0 +1,119 @@
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Author:
+ * Date: 2015-06-20
+ * Time: 21:46
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution2 {
+ /**
+ *
+ * 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)
+ *
+ * Ŀ⣺
+ * һnԪص飬ǷabcԪأʹõa+b+c=0ҳзԪ
+ *
+ * ע⣺
+ * - ԪеԪرǷǵݼ
+ * - ܰظԪ
+ *
+ * ˼·
+ * 2sum Ļ3sum⣬3sumĿtargetÿδѡһk
+ * ʣµĿtarget-k2sum⡣ҪעиСtrickǴѡ
+ * iʱֻҪֵдӵi+1һΧ2sum⡣
+ *
+ * ѡһ͵ڶΪA[],ܹnԪA1A2....AnȻѡA1ʱ
+ * [A2~An]Ŀλtarget-A12sum⣬Ҫ֤ǵѡA2ʱֻҪ
+ * [A3~An]мĿλtarget-A22sum⣬[A1,A3~An]У֤£
+ * [A1,A3~An]Ŀλtarget-A22sumУA1 + m = target-A2mΪA3~An
+ * ijA2 + m = target-A1պǡ[A3~An],Ŀλtarget-A12sum⡱
+ * һ⡣൱ڶ3sumA1+A2+m = targetظˡΪ˱ظ㣬
+ * [A1A3~An]УA1ȥĿtarget-A22sum⡣
+ *
+ * ڱҪӽ⣬ֻҪ浱ǰԼǰĿľ룬µĽӽ½⡣
+ * 㷨ӶΪOn^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.
+ *
+ * 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)
+ *
+ * 题目大意:
+ *
+ *
+ *
+ * @param nums
+ * @return
+ */
+ public List> threeSum(int[] nums) {
+ List> result = new LinkedList<>();
+
+ if (nums == null || nums.length < 3) {
+ return result;
+ }
+
+ Arrays.sort(nums);
+ int target = 0;
+ for (int a = 0; a < nums.length - 2; ++a) {
+
+ int b = a + 1;
+ int c = nums.length - 1;
+ while (b < c) {
+ if (nums[a] + nums[b] + nums[c] < target) {
+ ++b;
+ } else if (nums[a] + nums[b] + nums[c] > target) {
+ --c;
+ } else {
+ List idxs = new ArrayList<>();
+ idxs.add(nums[a]);
+ idxs.add(nums[b]);
+ idxs.add(nums[c]);
+ if (!result.contains(idxs)) {
+ result.add(idxs);
+ }
+ ++b;
+ --c;
+ }
+ }
+ }
+ return result;
+ }
+
+}
\ No newline at end of file
diff --git a/[0016][3 Sum Closest]/[0016][3 Sum Closest].iml b/[0016][3 Sum Closest]/[0016][3 Sum Closest].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0016][3 Sum Closest]/[0016][3 Sum Closest].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0016][3 Sum Closest]/[0016][3SumClosest].iml b/[0016][3 Sum Closest]/[0016][3SumClosest].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0016][3 Sum Closest]/[0016][3SumClosest].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0016][3 Sum Closest]/src/Main.java b/[0016][3 Sum Closest]/src/Main.java
new file mode 100644
index 0000000..86ada0f
--- /dev/null
+++ b/[0016][3 Sum Closest]/src/Main.java
@@ -0,0 +1,12 @@
+/**
+ * Author:
+ * Date: 2015-06-21
+ * Time: 09:58
+ * Declaration: All Rights Reserved !!!
+ */
+public class Main {
+ public static void main(String[] args) {
+ Solution solution = new Solution();
+ System.out.println(solution.threeSumClosest(new int[]{0, 1, 2}, 3));
+ }
+}
diff --git a/[0016][3 Sum Closest]/src/Solution.java b/[0016][3 Sum Closest]/src/Solution.java
new file mode 100644
index 0000000..42019e7
--- /dev/null
+++ b/[0016][3 Sum Closest]/src/Solution.java
@@ -0,0 +1,96 @@
+import java.util.Arrays;
+
+/**
+ * Author:
+ * Date: 2015-06-21
+ * Time: 09:29
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * 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).
+ *
+ * Ŀ⣺
+ * nSҵSеӶʹ֮ӽ
+ * ܺ͡Լÿ뽫һȷеĽ
+ *
+ * ˼·
+ * 3sum
+ *
+ *
+ * @param nums
+ * @param target
+ * @return
+ */
+ public int threeSumClosest(int[] nums, int target) {
+
+ // ¼СIJֵ
+ long minDiff = Long.MAX_VALUE;
+ // ¼СֵӦͺ
+ long result = 0;
+ // ÿõIJֵ
+ long diff;
+ // ÿõĺ
+ long sum;
+
+ // ȶ
+ Arrays.sort(nums);
+
+
+ // iʾȡiΪ
+ for (int i = 0; i < nums.length - 2; ) {
+ // ڶܵʼλ
+ int j = i + 1;
+ // ǽλ
+ int k = nums.length - 1;
+
+ while (j < k) {
+ // ǰĺ
+ sum = nums[j] + nums[k] + nums[i];
+ // ǰĿ֮IJֵ
+ diff = Math.abs(target - sum);
+
+ // ֵΪ0ֱӷ
+ if (diff == 0) {
+ return (int) sum;
+ }
+
+ // ǰIJֵ֮ǰ¼IJֵС
+ if (diff < minDiff) {
+ // СIJֵ
+ minDiff = diff;
+ // СֵӦĺ
+ result = sum;
+
+ // ϵһԪشʱЧ
+ }
+
+ // ʹtarget
+ if (sum > target) {
+ do {
+ k--; // ҵֵͬ
+ } while (j < k && nums[k] == nums[k + 1]);
+ }
+ // Сtarget
+ else {
+ do {
+ j++;
+ } while (j < k && nums[j - 1] == nums[j]);
+ }
+ }
+
+ do {
+ i++;
+ } while (i < nums.length - 2 && nums[i - 1] == nums[i]);
+ }
+
+ return (int) result;
+ }
+}
diff --git a/[0016][3 Sum Closest]/src/Solution2.java b/[0016][3 Sum Closest]/src/Solution2.java
new file mode 100644
index 0000000..1ed9f61
--- /dev/null
+++ b/[0016][3 Sum Closest]/src/Solution2.java
@@ -0,0 +1,89 @@
+import java.util.Arrays;
+
+/**
+ * Author:
+ * Date: 2015-06-21
+ * Time: 09:29
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution2 {
+ /**
+ *
+ * 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).
+ *
+ * Ŀ⣺
+ * nSҵSеӶʹ֮ӽ
+ * ܺ͡Լÿ뽫һȷеĽ
+ *
+ * ˼·
+ * 3sum
+ *
+ *
+ * @param nums
+ * @param target
+ * @return
+ */
+ public int threeSumClosest(int[] nums, int target) {
+
+ // ¼СIJֵ
+ long minDiff = Long.MAX_VALUE;
+ // ¼СֵӦͺ
+ long result = 0;
+ // ÿõIJֵ
+ long diff;
+ // ÿõĺ
+ long sum;
+
+ // ȶ
+ Arrays.sort(nums);
+
+
+ // iʾȡiΪ
+ for (int i = 0; i < nums.length - 2; i++) {
+ // ڶܵʼλ
+ int j = i + 1;
+ // ǽλ
+ int k = nums.length - 1;
+
+ while (j < k) {
+ // ǰĺ
+ sum = nums[j] + nums[k] + nums[i];
+ // ǰĿ֮IJֵ
+ diff = Math.abs(target - sum);
+
+ // ֵΪ0ֱӷ
+ if (diff == 0) {
+ return (int) sum;
+ }
+
+ // ǰIJֵ֮ǰ¼IJֵС
+ if (diff < minDiff) {
+ // СIJֵ
+ minDiff = diff;
+ // СֵӦĺ
+ result = sum;
+
+ // ϵһԪشʱЧ
+ }
+
+
+ // ʹtarget
+ if (sum > target) {
+ k--;
+ }
+ // Сtarget
+ else {
+ j++;
+ }
+ }
+ }
+
+ return (int) result;
+ }
+}
diff --git a/[0017][Letter Combinations Of A Phone Number/[0017][Letter Combinations Of A Phone Number.iml b/[0017][Letter Combinations Of A Phone Number/[0017][Letter Combinations Of A Phone Number.iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0017][Letter Combinations Of A Phone Number/[0017][Letter Combinations Of A Phone Number.iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0017][Letter Combinations Of A Phone Number/src/Main.java b/[0017][Letter Combinations Of A Phone Number/src/Main.java
new file mode 100644
index 0000000..d120486
--- /dev/null
+++ b/[0017][Letter Combinations Of A Phone Number/src/Main.java
@@ -0,0 +1,14 @@
+import org.junit.Test;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-19 19:26
+ **/
+public class Main {
+ @Test
+ public void test1() {
+ Solution solution = new Solution();
+
+ System.out.println(solution.letterCombinations("23"));
+ }
+}
diff --git a/[0017][Letter Combinations Of A Phone Number/src/Solution.java b/[0017][Letter Combinations Of A Phone Number/src/Solution.java
new file mode 100644
index 0000000..d9ec4a0
--- /dev/null
+++ b/[0017][Letter Combinations Of A Phone Number/src/Solution.java
@@ -0,0 +1,74 @@
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 16:23
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+
+ private final static String[] S = {
+ "abc",
+ "def",
+ "ghi",
+ "jkl",
+ "mno",
+ "pqrs",
+ "tuv",
+ "wxyz",
+ };
+
+
+ /**
+ *
+ * ԭ
+ * 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"].
+ *
+ * Note: Although the above answer is in lexicographical order, your answer
+ * could be in any order you want.
+ *
+ * Ŀ
+ * һִַϣֵַӳͼʾ
+ * ע⣺ Ľַ˳еģκ˳ؽ
+ *
+ * ˼·
+ * һ鱣ֵֺӳϵִ룬ҵӦַϽ
+ *
+ *
+ * @param digits
+ * @return
+ */
+ public List letterCombinations(String digits) {
+ List result = new LinkedList<>();
+
+ if (digits == null || digits.length() < 1) {
+ return result;
+ }
+
+ StringBuilder builder = new StringBuilder();
+ letterCombinations(digits, 0, builder, result);
+
+ return result;
+ }
+
+ private void letterCombinations(String digits, int index, StringBuilder builder, List result) {
+ if (index == digits.length()) {
+ result.add(builder.toString());
+ return;
+ }
+
+ String t = S[digits.charAt(index) - '2'];
+
+ for (int i = 0; i < t.length(); i++) {
+ builder.append(t.charAt(i));
+ letterCombinations(digits, index + 1, builder, result);
+ builder.deleteCharAt(builder.length() - 1);
+ }
+ }
+}
diff --git a/[0017][Letter Combinations Of A Phone Number/src/Solution2.java b/[0017][Letter Combinations Of A Phone Number/src/Solution2.java
new file mode 100644
index 0000000..4dc400d
--- /dev/null
+++ b/[0017][Letter Combinations Of A Phone Number/src/Solution2.java
@@ -0,0 +1,95 @@
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 16:23
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution2 {
+
+ private String[] map = {
+ "abc",
+ "def",
+ "ghi",
+ "jkl",
+ "mno",
+ "pqrs",
+ "tuv",
+ "wxyz",
+ };
+ private List result; // 洢ս
+ private char[] chars; // ȥ01ַĽ
+ private char[] curResult; // 洢м
+ private int end = 0; // ַеĵһδʹõλ
+ private int handle = 0; // ǰǵڼַ
+
+ /**
+ *
+ * ԭ
+ * 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"].
+ *
+ * Note: Although the above answer is in lexicographical order, your answer
+ * could be in any order you want.
+ *
+ * Ŀ
+ * һִַϣֵַӳͼʾ
+ * ע⣺ Ľַ˳еģκ˳ؽ
+ *
+ * ˼·
+ * һ鱣ֵֺӳϵִ룬ҵӦַϽ
+ *
+ *
+ * @param digits
+ * @return
+ */
+ public List letterCombinations(String digits) {
+ result = new LinkedList<>();
+
+ if (digits != null && digits.length() > 0) {
+
+ chars = digits.toCharArray();
+
+ // ַдȥ01
+ // ҵһ01λ
+ while (end < digits.length() && chars[end] != '0' && chars[end] != '1') {
+ end++;
+ }
+
+ handle = end + 1;
+ while (handle < chars.length) {
+ if (chars[handle] != '0' && chars[handle] != '1') {
+ chars[end] = chars[handle];
+ end++;
+ }
+ handle++;
+ }
+
+ curResult = new char[end];
+ // whileendΪЧַij
+ handle = 0; // ָһЧַλ
+
+ letterCombinations();
+ }
+ return result;
+ }
+
+ private void letterCombinations() {
+ if (handle >= end) {
+ result.add(new String(curResult));
+ } else {
+ int num = chars[handle] - '2';
+ for (int i = 0; i < map[num].length(); i++) {
+ curResult[handle] = map[num].charAt(i);
+ handle++;
+ letterCombinations();
+ handle--;
+ }
+ }
+ }
+}
diff --git "a/\343\200\220017\343\200\221\343\200\220LetterCombinationsOfAPhonNumber \343\200\221/src/phone-number.png" b/[0017][Letter Combinations Of A Phone Number/src/phone-number.png
similarity index 100%
rename from "\343\200\220017\343\200\221\343\200\220LetterCombinationsOfAPhonNumber \343\200\221/src/phone-number.png"
rename to [0017][Letter Combinations Of A Phone Number/src/phone-number.png
diff --git a/[0018][4 Sum]/[0018][4 Sum].iml b/[0018][4 Sum]/[0018][4 Sum].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0018][4 Sum]/[0018][4 Sum].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0018][4 Sum]/src/Solution.java b/[0018][4 Sum]/src/Solution.java
new file mode 100644
index 0000000..6d14161
--- /dev/null
+++ b/[0018][4 Sum]/src/Solution.java
@@ -0,0 +1,105 @@
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 16:28
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * ԭ
+ * 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)
+ *
+ * Ŀ
+ * һ飬ҳa + b + c + d = targetΨһ⡣
+ *
+ * ˼·
+ * ȷadadͬʱظʹáȻȷbcͬҲ
+ * ͬʱظʹáҳĽ⣬ͬʱԱ֤ⲻظ
+ *
+ *
+ * @param num
+ * @param target
+ * @return
+ */
+ public List> fourSum(int[] num, int target) {
+ List> result = new LinkedList<>();
+ if (num == null || num.length < 4) {
+ return result;
+ }
+
+ //
+ Arrays.sort(num);
+
+ // һ
+ for (int i = 0; i < num.length - 3; ) {
+ // ĸ
+ for (int j = num.length - 1; j > i + 2; j--) {
+ // ĸʹòظ
+ if (j < num.length - 1 && num[j] == num[j + 1]) {
+ continue;
+ }
+
+ // ڶ
+ int start = i + 1;
+ //
+ int end = j - 1;
+ int n = target - num[i] - num[j];
+
+ while (start < end) {
+ if (num[start] + num[end] == n) {
+ List four = new ArrayList<>(4);
+ four.add(num[i]);
+ four.add(num[start]);
+ four.add(num[end]);
+ four.add(num[j]);
+
+ result.add(four);
+
+ do {
+ start++;
+ // ֤ٴʹõڶظ
+ } while (start < end && num[start] == num[start - 1]);
+ do {
+ end--;
+ // ֤ٴʹõظ
+ } while (start < end && num[end] == num[end + 1]);
+ } else if (num[start] + num[end] < n) {
+ do {
+ start++;
+ // ֤ٴʹõڶظ
+ } while (start < end && num[start] == num[start - 1]);
+ } else {
+ do {
+ end--;
+ // ֤ٴʹõظ
+ } while (start < end && num[end] == num[end + 1]);
+ }
+ }
+ }
+
+ // ͬΪֻʹһ
+ do {
+ i++;
+ } while (i < num.length - 2 && num[i - 1] == num[i]);
+ }
+ return result;
+ }
+}
diff --git a/[0019][Remove Nth Node From End Of List]/[0019][Remove Nth Node From End Of List].iml b/[0019][Remove Nth Node From End Of List]/[0019][Remove Nth Node From End Of List].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0019][Remove Nth Node From End Of List]/[0019][Remove Nth Node From End Of List].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220019\343\200\221\343\200\220RemoveNthNodeFromEndOfList\343\200\221/src/ListNode.java" b/[0019][Remove Nth Node From End Of List]/src/ListNode.java
similarity index 100%
rename from "\343\200\220019\343\200\221\343\200\220RemoveNthNodeFromEndOfList\343\200\221/src/ListNode.java"
rename to [0019][Remove Nth Node From End Of List]/src/ListNode.java
diff --git a/[0019][Remove Nth Node From End Of List]/src/Solution.java b/[0019][Remove Nth Node From End Of List]/src/Solution.java
new file mode 100644
index 0000000..84fefb7
--- /dev/null
+++ b/[0019][Remove Nth Node From End Of List]/src/Solution.java
@@ -0,0 +1,60 @@
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 16:30
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * ԭ
+ * Given a linked list, remove the nth node from the end of list and return its head.
+ * For example,
+ *
+ * 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.
+ *
+ * Ŀ
+ * ɾĵڣθ㣬ע⣺ģζǺϷһαɲ
+ *
+ * ˼·
+ * һָҵNڵ㣬Ȼһָָͷ㣬Ȼָһߣ
+ * ֱǰһֱָĩβһָǵN+1㣬ɾNͿˡ
+ *
+ *
+ * @param head
+ * @param n
+ * @return
+ */
+ public ListNode removeNthFromEnd(ListNode head, int n) {
+ ListNode pa = head;
+ ListNode pb = head;
+
+ // ҵn
+ for (int i = 0; i < n && pa != null; i++) {
+ pa = pa.next;
+ }
+
+
+ // ˵Ҫɾһڵ
+ if (pa == null) {
+ head = head.next;
+ return head;
+ }
+
+ // pbpan-1
+ // pa.nextΪnullpbڵn+1λ
+ while (pa.next != null) {
+ pa = pa.next;
+ pb = pb.next;
+ }
+
+ pb.next = pb.next.next;
+
+ return head;
+ }
+}
diff --git a/[0020][Valid Parentheses]/[0020][Valid Parentheses].iml b/[0020][Valid Parentheses]/[0020][Valid Parentheses].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0020][Valid Parentheses]/[0020][Valid Parentheses].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0020][Valid Parentheses]/src/Main.java b/[0020][Valid Parentheses]/src/Main.java
new file mode 100644
index 0000000..4fda8c6
--- /dev/null
+++ b/[0020][Valid Parentheses]/src/Main.java
@@ -0,0 +1,22 @@
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-17 14:46
+ **/
+public class Main {
+ @Test
+ public void test1() {
+ Solution solution = new Solution();
+
+ Assert.assertEquals(true, solution.isValid("()"));
+ }
+
+ @Test
+ public void test2() {
+ Solution solution = new Solution();
+
+ Assert.assertEquals(false, solution.isValid("(]"));
+ }
+}
diff --git a/[0020][Valid Parentheses]/src/Solution.java b/[0020][Valid Parentheses]/src/Solution.java
new file mode 100644
index 0000000..86445bc
--- /dev/null
+++ b/[0020][Valid Parentheses]/src/Solution.java
@@ -0,0 +1,55 @@
+import java.util.Deque;
+import java.util.LinkedList;
+
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 16:32
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * ԭ
+ * 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.
+ *
+ * Ŀ
+ * һֻ(, ), {, }, [ ͡]ַ֤ǷЧġ
+ * űԣҪȷ˳
+ *
+ * ˼·
+ * һջŴдžջžջԪؿǷһţ
+ * ɾ͵Ҵһţƥֱӷؽ
+ *
+ *
+ * @param s
+ * @return
+ */
+ public boolean isValid(String s) {
+ Deque stack = new LinkedList<>();
+ final String left = "([{";
+ final String right = ")]}";
+
+ for (int index = 0; index < s.length(); index++) {
+ char c = s.charAt(index);
+
+ // žջ
+ if (left.indexOf(c) > -1) {
+ stack.push(c);
+ } else {
+ // žͿջԪ
+ // ջΪջջԪزƥͷfalse
+ if (stack.isEmpty() || right.indexOf(c) != left.indexOf(stack.peek())) {
+ return false;
+ } else {
+ stack.pop();
+ }
+ }
+ }
+
+ return stack.isEmpty();
+ }
+}
diff --git a/[0020][Valid Parentheses]/src/Solution2.java b/[0020][Valid Parentheses]/src/Solution2.java
new file mode 100644
index 0000000..84aaaa5
--- /dev/null
+++ b/[0020][Valid Parentheses]/src/Solution2.java
@@ -0,0 +1,97 @@
+import java.util.Deque;
+import java.util.LinkedList;
+
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 16:32
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution2 {
+ /**
+ *
+ * ԭ
+ * 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.
+ *
+ * Ŀ
+ * һֻ(, ), {, }, [ ͡]ַ֤ǷЧġ
+ * űԣҪȷ˳
+ *
+ * ˼·
+ * һջŴдžջžջԪؿǷһţ
+ * ɾ͵Ҵһţƥֱӷؽ
+ *
+ *
+ * @param s
+ * @return
+ */
+ public boolean isValid(String s) {
+ Deque stack = new LinkedList<>();
+ int index = 0;
+ Character top;
+ while (index < s.length()) {
+ Character c = s.charAt(index);
+ switch (c) {
+ case '(':
+ case '[':
+ case '{':
+ stack.addFirst(c);
+ break;
+ case ')':
+
+ if (stack.isEmpty()) {
+ return false;
+ }
+
+ top = stack.getFirst();
+ if (top == '(') {
+ stack.removeFirst();
+ } else if (top == '[' || top == '{') {
+ return false;
+ } else {
+ stack.addFirst(c);
+ }
+ break;
+ case ']':
+
+ if (stack.isEmpty()) {
+ return false;
+ }
+
+ top = stack.getFirst();
+ if (top == '[') {
+ stack.removeFirst();
+ } else if (top == '(' || top == '{') {
+ return false;
+ } else {
+ stack.addFirst(c);
+ }
+ break;
+ case '}':
+
+ if (stack.isEmpty()) {
+ return false;
+ }
+
+ top = stack.getFirst();
+ if (top == '{') {
+ stack.removeFirst();
+ } else if (top == '[' || top == '(') {
+ return false;
+ } else {
+ stack.addFirst(c);
+ }
+ break;
+ default:
+ return false;
+ }
+
+ index++;
+ }
+
+ return stack.isEmpty();
+ }
+}
diff --git a/[0021][Merge Two Sorted Lists]/[0021][Merge Two Sorted Lists].iml b/[0021][Merge Two Sorted Lists]/[0021][Merge Two Sorted Lists].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0021][Merge Two Sorted Lists]/[0021][Merge Two Sorted Lists].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220021\343\200\221\343\200\220MergeTwoSortedLists\343\200\221/src/ListNode.java" b/[0021][Merge Two Sorted Lists]/src/ListNode.java
similarity index 100%
rename from "\343\200\220021\343\200\221\343\200\220MergeTwoSortedLists\343\200\221/src/ListNode.java"
rename to [0021][Merge Two Sorted Lists]/src/ListNode.java
diff --git a/[0021][Merge Two Sorted Lists]/src/Solution.java b/[0021][Merge Two Sorted Lists]/src/Solution.java
new file mode 100644
index 0000000..3d7e574
--- /dev/null
+++ b/[0021][Merge Two Sorted Lists]/src/Solution.java
@@ -0,0 +1,53 @@
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 16:35
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * ԭ
+ * 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.
+ *
+ * Ŀ
+ * ϲһµбµĽԭȵɣ
+ * ҲDzܺϲܰ´Ľ㡣
+ *
+ * ˼·
+ * ʹͷrootиһͷ㣬ʹָͷ㣬
+ * СĽֵĽժӵrootĩβͬʱժͷƶһ㣬
+ * һֱԭһΪգٽʣµĽӵrootĩβ
+ * rootһ㣬Ϊµͷ
+ *
+ * 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:
+ * "((()))", "(()())", "(())()", "()(())", "()()()"
+ *
+ * Ŀ⣺
+ * nţȷ
+ *
+ * ˼·
+ * õݹ
+ *
+ *
+ * @param n
+ * @return
+ */
+ public List generateParenthesis(int n) {
+ // Ķ
+ List result = new ArrayList<>();
+ // 0
+ if (n > 0) {
+ //
+ char[] parentheses = new char[2 * n];
+ //
+ solve(n, n, parentheses, result);
+ }
+ return result;
+ }
+
+ /**
+ * @param left ʣõ
+ * @param right ʣõ
+ * @param parentheses һΪֹʹõ
+ * @param result Žļ
+ */
+ public void solve(int left, int right, char[] parentheses, List result) {
+
+ // ʣµС0ÿʣµС
+ if (left < 0 || right < 0 || right < left) {
+ // ʲô
+ return;
+ }
+ // Ŷʹ
+ else if (left == 0 && right == 0) {
+ result.add(new String(parentheses));
+ }
+ // ʹ
+ else {
+ // ǰʹõλ
+ int idx = parentheses.length - left - right;
+ // ʹ
+ parentheses[idx] = '(';
+ // ݹ
+ solve(left - 1, right, parentheses, result);
+ // ʹ
+ parentheses[idx] = ')';
+ solve(left, right - 1, parentheses, result);
+ }
+ }
+}
diff --git a/[0023][Merge K Sorted Lists]/[0023][Merge K Sorted Lists].iml b/[0023][Merge K Sorted Lists]/[0023][Merge K Sorted Lists].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0023][Merge K Sorted Lists]/[0023][Merge K Sorted Lists].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220023\343\200\221\343\200\220MergeKSortedLists\343\200\221/src/ListNode.java" b/[0023][Merge K Sorted Lists]/src/ListNode.java
similarity index 100%
rename from "\343\200\220023\343\200\221\343\200\220MergeKSortedLists\343\200\221/src/ListNode.java"
rename to [0023][Merge K Sorted Lists]/src/ListNode.java
diff --git a/[0023][Merge K Sorted Lists]/src/Solution.java b/[0023][Merge K Sorted Lists]/src/Solution.java
new file mode 100644
index 0000000..ef06cbb
--- /dev/null
+++ b/[0023][Merge K Sorted Lists]/src/Solution.java
@@ -0,0 +1,82 @@
+import java.util.Comparator;
+import java.util.PriorityQueue;
+
+/**
+ * Author:
+ * Date: 2015-06-30
+ * Time: 19:21
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * Merge k sorted linked lists and return it as one sorted list.
+ * Analyze and describe its complexity.
+ *
+ * Ŀ⣺
+ * ϲkźõĵĵ
+ *
+ * ˼·
+ * ʹһСвȽkĵһѣȡеСأΪСԪأ
+ * ԪصһѣȡСģβֱΪ
+ *
+ * ԭ
+ * 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.
+ * Your algorithm should use only constant space. You may not modify the values in the list, only nodes itself can be changed.
+ *
+ * Ŀ
+ * һɶԽڵĽ㡣㷨Ӧռ䣬ܸĽֵֻܽ㡣
+ *
+ * ˼·
+ * ʹһͷrootҪнÿλýн
+ * ҰѽĽӵrootϣֱеĽ㶼ꡣ
+ *
+ *
+ * @param head
+ * @return
+ */
+ public ListNode swapPairs(ListNode head) {
+ // ͷ
+ ListNode node = new ListNode(0);
+ node.next = head;
+
+ // pָµβ㣬pָõĽ㣬ӵͷΪѾ
+ ListNode p = node;
+ ListNode tmp;
+
+ // ÿв
+ while (p.next != null && p.next.next != null) {
+ // ¼һҪдλ
+ tmp = p.next.next;
+ // 㽻
+ p.next.next = tmp.next;
+ tmp.next = p.next;
+ p.next = tmp;
+ // ָµβ
+ p = tmp.next;
+ }
+
+ head = node.next;
+ node.next = null;
+
+ return head;
+ }
+}
diff --git a/[0025][Reverse Nodes In K-Group]/[0025][Reverse Nodes In K-Group].iml b/[0025][Reverse Nodes In K-Group]/[0025][Reverse Nodes In K-Group].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0025][Reverse Nodes In K-Group]/[0025][Reverse Nodes In K-Group].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221/src/ListNode.java" b/[0025][Reverse Nodes In K-Group]/src/ListNode.java
similarity index 100%
rename from "\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221/src/ListNode.java"
rename to [0025][Reverse Nodes In K-Group]/src/ListNode.java
diff --git "a/\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221/src/Main.java" b/[0025][Reverse Nodes In K-Group]/src/Main.java
similarity index 100%
rename from "\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221/src/Main.java"
rename to [0025][Reverse Nodes In K-Group]/src/Main.java
diff --git "a/\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221/src/Solution.java" b/[0025][Reverse Nodes In K-Group]/src/Solution.java
similarity index 100%
rename from "\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221/src/Solution.java"
rename to [0025][Reverse Nodes In K-Group]/src/Solution.java
diff --git a/[0026][Remove Duplicates from Sorted Array]/[0026][Remove Duplicates from Sorted Array].iml b/[0026][Remove Duplicates from Sorted Array]/[0026][Remove Duplicates from Sorted Array].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0026][Remove Duplicates from Sorted Array]/[0026][Remove Duplicates from Sorted Array].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0026][Remove Duplicates from Sorted Array]/src/Solution.java b/[0026][Remove Duplicates from Sorted Array]/src/Solution.java
new file mode 100644
index 0000000..9131cb0
--- /dev/null
+++ b/[0026][Remove Duplicates from Sorted Array]/src/Solution.java
@@ -0,0 +1,54 @@
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 16:40
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * ԭ
+ * 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 nums = [1,1,2],
+ * Your function should return length = 2, with the first two elements of nums
+ * being 1 and 2 respectively. It doesnt matter what you leave beyond the new length.
+ *
+ * Ŀ
+ * һ飬еظԪȥֻͬһҷµԪظ
+ * Ҫһµڳʱڽ
+ *
+ * ˼·
+ * ӵڶԪؿʼΪǰԪأǰԪǰһԪͬɾԪأ
+ * ͬͽƶȷλãԪ˸
+ *
+ *
+ * @param A
+ * @return
+ */
+ public int removeDuplicates(int[] A) {
+
+ if (A == null) {
+ return 0;
+ }
+
+ if (A.length < 2) {
+ return A.length;
+ }
+
+ // ָһλ
+ int index = 1;
+ for (int i = 1; i < A.length; i++) {
+ // index - 1ʾǰһźõλ
+ if (A[index - 1] < A[i]) {
+ A[index] = A[i];
+ index++;
+ }
+ }
+
+ return index;
+ }
+}
diff --git a/[0026][Remove Duplicates from Sorted Array]/src/Solution2.java b/[0026][Remove Duplicates from Sorted Array]/src/Solution2.java
new file mode 100644
index 0000000..fc801b2
--- /dev/null
+++ b/[0026][Remove Duplicates from Sorted Array]/src/Solution2.java
@@ -0,0 +1,57 @@
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 16:40
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution2 {
+ /**
+ *
+ * ԭ
+ * 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 nums = [1,1,2],
+ * Your function should return length = 2, with the first two elements of nums
+ * being 1 and 2 respectively. It doesnt matter what you leave beyond the new length.
+ *
+ * Ŀ
+ * һ飬еظԪȥֻͬһҷµԪظ
+ * Ҫһµڳʱڽ
+ *
+ * ˼·
+ * ӵڶԪؿʼΪǰԪأǰԪǰһԪͬɾԪأ
+ * ͬͽƶȷλãԪ˸
+ *
+ *
+ * @param A
+ * @return
+ */
+ public int removeDuplicates(int[] A) {
+
+ if (A.length == 0) {
+ return 0;
+ }
+
+ int index = 0;//[0,index]ֻ¼гֵİСΨһһѾź
+ int next = 1;
+
+ // 㷨˼룺index֮ıA[index]ҵƶA[index+1]
+ // indexƶһλãnextƶһλãұA[index]
+
+ while (next < A.length) {
+ while (next < A.length && A[index] == A[next]) { // Ҳ
+ next++;
+ }
+
+ if (next < A.length) {
+ index++;
+ A[index] = A[next];
+ next++;
+ }
+ }
+ return index + 1;
+ }
+}
diff --git a/[0027][Remove Element]/[0027][Remove Element].iml b/[0027][Remove Element]/[0027][Remove Element].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0027][Remove Element]/[0027][Remove Element].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0027][Remove Element]/src/Solution.java b/[0027][Remove Element]/src/Solution.java
new file mode 100644
index 0000000..bfdcaf6
--- /dev/null
+++ b/[0027][Remove Element]/src/Solution.java
@@ -0,0 +1,52 @@
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 16:43
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * ԭ
+ * 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 doesnt matter what you leave beyond the new length.
+ *
+ * Ŀ
+ * һһֵɾֵȵԪأҷµijȡ
+ *
+ * ˼·
+ * ֵΪelemԪصλãjұֵΪelemԪصλãȻjλõֵƶiλá
+ *
+ * ԭ
+ * 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 doesnt matter what you leave beyond the new length.
+ *
+ * Ŀ
+ * һһֵɾֵȵԪأҷµijȡ
+ *
+ * ˼·
+ *
+ *
+ *
+ * @param nums
+ * @param val
+ * @return
+ */
+ public int removeElement(int[] nums, int val) {
+
+ // [0, ..., index - 1]ʾѾųvalֵ飬indexʾ֮ԷԪصλã
+ // Ҳʾij
+ int index = 0;
+ for (int i = 0; i < nums.length; i++) {
+ // Ⱦƶ
+ if (nums[i] != val) {
+ nums[index] = nums[i];
+ ++index;
+ }
+ }
+
+ return index;
+ }
+}
diff --git a/[0028][Implement-strStr()]/[0028][Implement-strStr()].iml b/[0028][Implement-strStr()]/[0028][Implement-strStr()].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0028][Implement-strStr()]/[0028][Implement-strStr()].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220028\343\200\221\343\200\220Implement-strStr()\343\200\221/src/Solution.java" b/[0028][Implement-strStr()]/src/Solution.java
similarity index 100%
rename from "\343\200\220028\343\200\221\343\200\220Implement-strStr()\343\200\221/src/Solution.java"
rename to [0028][Implement-strStr()]/src/Solution.java
diff --git a/[0029][Divide Two Integers]/[0029][Divide Two Integers].iml b/[0029][Divide Two Integers]/[0029][Divide Two Integers].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0029][Divide Two Integers]/[0029][Divide Two Integers].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0029][Divide Two Integers]/[0029][DivideTwoIntegers].iml b/[0029][Divide Two Integers]/[0029][DivideTwoIntegers].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0029][Divide Two Integers]/[0029][DivideTwoIntegers].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220029\343\200\221\343\200\220DivideTwoIntegers\343\200\221/src/Main.java" b/[0029][Divide Two Integers]/src/Main.java
similarity index 100%
rename from "\343\200\220029\343\200\221\343\200\220DivideTwoIntegers\343\200\221/src/Main.java"
rename to [0029][Divide Two Integers]/src/Main.java
diff --git "a/\343\200\220029\343\200\221\343\200\220DivideTwoIntegers\343\200\221/src/Solution.java" b/[0029][Divide Two Integers]/src/Solution.java
similarity index 100%
rename from "\343\200\220029\343\200\221\343\200\220DivideTwoIntegers\343\200\221/src/Solution.java"
rename to [0029][Divide Two Integers]/src/Solution.java
diff --git a/[0030][Substring With Concatenation Of All Words]/[0030][Substring With Concatenation Of All Words].iml b/[0030][Substring With Concatenation Of All Words]/[0030][Substring With Concatenation Of All Words].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0030][Substring With Concatenation Of All Words]/[0030][Substring With Concatenation Of All Words].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0030][Substring With Concatenation Of All Words]/src/Solution.java b/[0030][Substring With Concatenation Of All Words]/src/Solution.java
new file mode 100644
index 0000000..83d5e29
--- /dev/null
+++ b/[0030][Substring With Concatenation Of All Words]/src/Solution.java
@@ -0,0 +1,33 @@
+import java.util.List;
+
+/**
+ * Author:
+ * Date: 2015-07-01
+ * Time: 08:23
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * You are given a string, s, and a list of words, words,
+ * that are all of the same length. Find all starting indices
+ * of substring(s) in s that is a concatenation of each word
+ * in words exactly once and without any intervening characters.
+ *
+ * For example, given:
+ * s: "barfoothefoobarman"
+ * words: ["foo", "bar"]
+ * You should return the indices: [0,9].
+ * (order does not matter).
+ *
+ * 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 and use only constant 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
+ *
+ * 1.首先从最尾端开始往前寻找一个元素,满足nums[i] < nums[i+1]。
+ * 如果没有找到即i < 0, 说明整个数组是递增的,已经到了最大值,此时只要反转数组即可
+ * 如果i >= 0
+ *
+ * 2.再从最尾端开始往前检验,找出第一个大于nums[i]的元素nums[j] 并且,j >= i
+ * 将nums[i],nums[j]元素对调(swap)。
+ *
+ * 3.再将i位置之后的所有元素颠倒(reverse)排序。
+ *
+ *
+ * @param nums
+ */
+ public void nextPermutation(int[] nums) {
+ int i = nums.length - 2;
+ // 从后向前查找第一个元素i,并且使用nums[i] >= nums[i+1]不成立。
+ while (i >= 0 && nums[i] >= nums[i + 1]) {
+ i--;
+ }
+
+ // 此时nums[i+1, ..., last]是递增的
+
+
+ if (i >= 0) {
+ int j = nums.length - 1;
+ // 从右开始向左找,找第一个大于等num[i]的元素
+ // 如果找到i==j,说明没有找到
+ while (j > i && nums[j] <= nums[i]) {
+ j--;
+ }
+
+ // 交换两者之间的值,当j == i时,交换也没有问题
+ swap(nums, i, j);
+
+ // 将nums[i+1, last]进行反转
+ reverse(nums, i + 1);
+ } else {
+ // 说明整个序列是非递增的
+ // 对子数组进行翻转
+ reverse(nums, 0);
+ }
+
+
+ }
+
+ private void reverse(int[] nums, int start) {
+ int i = start;
+ int j = nums.length - 1;
+ while (i < j) {
+ swap(nums, i, j);
+ i++;
+ j--;
+ }
+ }
+
+ private void swap(int[] nums, int i, int j) {
+ int temp = nums[i];
+ nums[i] = nums[j];
+ nums[j] = temp;
+ }
+}
diff --git a/[0032][Longest Valid Parentheses]/[0032][Longest Valid Parentheses].iml b/[0032][Longest Valid Parentheses]/[0032][Longest Valid Parentheses].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0032][Longest Valid Parentheses]/[0032][Longest Valid Parentheses].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220032\343\200\221\343\200\220LongestValidParentheses\343\200\221/src/Main.java" b/[0032][Longest Valid Parentheses]/src/Main.java
similarity index 100%
rename from "\343\200\220032\343\200\221\343\200\220LongestValidParentheses\343\200\221/src/Main.java"
rename to [0032][Longest Valid Parentheses]/src/Main.java
diff --git a/[0032][Longest Valid Parentheses]/src/Solution.java b/[0032][Longest Valid Parentheses]/src/Solution.java
new file mode 100644
index 0000000..ba8947c
--- /dev/null
+++ b/[0032][Longest Valid Parentheses]/src/Solution.java
@@ -0,0 +1,52 @@
+import java.util.Stack;
+
+/**
+ * Author:
+ * Date: 2015-06-25
+ * Time: 09:12
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * 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.
+ *
+ * Ŀ⣺
+ * һַֻСźţĺϷСŵĿ
+ *
+ * ˼·
+ * ʹջʵ
+ *
+ *
+ * @param s
+ * @return
+ */
+ public int longestValidParentheses(String s) {
+ // ڼ¼ƥźŵλ
+ Stack st = new Stack<>();
+ int max = 0;
+ for (int i = 0; i < s.length(); i++) {
+
+ // ǵǰַţҼ¼ջǿգǰһַ
+ if (s.charAt(i) == ')' && !st.isEmpty() && s.charAt(st.peek()) == '(') {
+ // ųջ
+ st.pop();
+ // ֵ
+ // ʱ(ƥ)ѾջջҪôΪգҪô뵱ǰ))
+ // Ҫô뵱ǰ)ڶ(
+ max = Math.max(max, i - ((st.isEmpty()) ? -1 : st.peek()));
+ }
+ // ͽַջ
+ else {
+ st.push(i);
+ }
+ }
+
+ return max;
+ }
+}
diff --git a/[0032][Longest Valid Parentheses]/src/Solution2.java b/[0032][Longest Valid Parentheses]/src/Solution2.java
new file mode 100644
index 0000000..fb9b995
--- /dev/null
+++ b/[0032][Longest Valid Parentheses]/src/Solution2.java
@@ -0,0 +1,59 @@
+import java.util.Deque;
+import java.util.LinkedList;
+
+/**
+ * Author:
+ * Date: 2015-06-25
+ * Time: 09:12
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution2 {
+ /**
+ *
+ * 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.
+ *
+ * Ŀ⣺
+ * һַֻСźţĺϷСŵĿ
+ *
+ * ˼·
+ * ʹջʵ
+ *
+ *
+ * @param s
+ * @return
+ */
+ public int longestValidParentheses(String s) {
+ int result = 0;
+ int start = 0;
+ // ¼ŵλ
+ Deque m = new LinkedList<>();
+ for (int i = 0; i < s.length(); ++i) {
+ // žͼ¼λ
+ if (s.charAt(i) == '(') {
+ m.push(i);
+ }
+ //
+ else if (s.charAt(i) == ')') {
+ // ֮ǰŶѾԣߴû
+ if (m.isEmpty()) {
+ // ǰλѾЧˣ¼һλǿʼԵλ
+ start = i + 1;
+ } else {
+ // ջӦ
+ m.pop();
+ // ջΪգ˵startʼһֱƥ䣬ûֶţ
+ // ǣMath.max(result, i - start + 1)
+ // ջǿգ˵жţһŵλþm.peek()
+ // ƥž: Math.max(result, i - m.peek())
+ result = m.isEmpty() ? Math.max(result, i - start + 1) : Math.max(result, i - m.peek());
+ }
+ }
+ }
+ return result;
+ }
+}
diff --git a/[0033][Search In Rotated Sorted Array]/[0033][Search In Rotated Sorted Array].iml b/[0033][Search In Rotated Sorted Array]/[0033][Search In Rotated Sorted Array].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0033][Search In Rotated Sorted Array]/[0033][Search In Rotated Sorted Array].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0033][Search In Rotated Sorted Array]/[0033][SearchInRotatedSortedArray].iml b/[0033][Search In Rotated Sorted Array]/[0033][SearchInRotatedSortedArray].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0033][Search In Rotated Sorted Array]/[0033][SearchInRotatedSortedArray].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0033][Search In Rotated Sorted Array]/src/Main.java b/[0033][Search In Rotated Sorted Array]/src/Main.java
new file mode 100644
index 0000000..d522524
--- /dev/null
+++ b/[0033][Search In Rotated Sorted Array]/src/Main.java
@@ -0,0 +1,13 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-12 23:22
+ **/
+public class Main {
+ public static void main(String[] args) {
+ int[] nums = {4, 5, 6, 7, 0, 1, 2};
+ Solution2 solution = new Solution2();
+
+ System.out.println(solution.search(nums, 4));
+ System.out.println(solution.search(nums, 3));
+ }
+}
diff --git a/[0033][Search In Rotated Sorted Array]/src/Solution.java b/[0033][Search In Rotated Sorted Array]/src/Solution.java
new file mode 100644
index 0000000..4f3e4eb
--- /dev/null
+++ b/[0033][Search In Rotated Sorted Array]/src/Solution.java
@@ -0,0 +1,120 @@
+/**
+ * Author: 王俊超
+ * Date: 2015-06-21
+ * Time: 14:48
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * 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.
+ *
+ * 题目大意:
+ * 假设一个排序的数组以一个未知的的枢轴旋转。(即,0 1 2 4 5 6 7可能成为4 5 6 7 0 1 2)。
+ * 给定一个目标值,在数组中搜寻。如果存在就返回其对应的下标,否则返回-1。
+ * 假设数组中不存在重复值。
+ *
+ * 解题思路:
+ * 找旋转数组最小值的位置minIndex(见LeetCode第153题 ),如果minIndex不为,说明其在分隔成
+ * 两个有序数组,并且前一个中的第一个元素都大于后一个数组的每一个元素,判断target中哪一个数组区
+ * 间中使用二叉搜索算法查找,如果minIndex=0,说明全局有序,对整个数组进行二叉查找,返回查找结果
+ *
+ * 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.
+ *
+ * 题目大意:
+ * 假设一个排序的数组以一个未知的的枢轴旋转。(即,0 1 2 4 5 6 7可能成为4 5 6 7 0 1 2)。
+ * 给定一个目标值,在数组中搜寻。如果存在就返回其对应的下标,否则返回-1。
+ * 假设数组中不存在重复值。
+ *
+ * 解题思路:
+ * 找旋转数组最小值的位置minIndex(见LeetCode第153题 ),如果minIndex不为,说明其在分隔成
+ * 两个有序数组,并且前一个中的第一个元素都大于后一个数组的每一个元素,判断target中哪一个数组区
+ * 间中使用二叉搜索算法查找,如果minIndex=0,说明全局有序,对整个数组进行二叉查找,返回查找结果
+ *
+ *
+ * @param nums
+ * @param target
+ * @return
+ */
+ public int search(int[] nums, int target) {
+ if (nums == null || nums.length == 0) {
+ return -1;
+ }
+
+ int left = 0;
+ int right = nums.length - 1;
+ int mid;
+ while (left <= right) {
+ mid = left + (right - left) / 2;
+ if (nums[mid] == target) {
+ return mid;
+ }
+
+ // 说明first,mid都在同一个递增子序列中
+ if (nums[left] <= nums[mid]) {
+ if (nums[left] <= target && target < nums[mid]) {
+ right = mid - 1;
+ } else {
+ left = mid + 1;
+ }
+ } else {
+ if (nums[mid] < target && target <= nums[right]) {
+ left = mid + 1;
+ } else {
+ right = mid - 1;
+ }
+ }
+ }
+
+ return -1;
+ }
+
+}
diff --git a/[0034][Search For A Range]/[0034][Search For A Range].iml b/[0034][Search For A Range]/[0034][Search For A Range].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0034][Search For A Range]/[0034][Search For A Range].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0034][Search For A Range]/[0034][SearchForARange].iml b/[0034][Search For A Range]/[0034][SearchForARange].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0034][Search For A Range]/[0034][SearchForARange].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220034\343\200\221\343\200\220SearchForARange\343\200\221/src/Solution.java" b/[0034][Search For A Range]/src/Solution.java
similarity index 100%
rename from "\343\200\220034\343\200\221\343\200\220SearchForARange\343\200\221/src/Solution.java"
rename to [0034][Search For A Range]/src/Solution.java
diff --git a/[0035][Search Insert Position]/[0035][Search Insert Position].iml b/[0035][Search Insert Position]/[0035][Search Insert Position].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0035][Search Insert Position]/[0035][Search Insert Position].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0035][Search Insert Position]/[0035][SearchInsertPosition].iml b/[0035][Search Insert Position]/[0035][SearchInsertPosition].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0035][Search Insert Position]/[0035][SearchInsertPosition].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220035\343\200\221\343\200\220SearchInsertPosition\343\200\221/src/Solution.java" b/[0035][Search Insert Position]/src/Solution.java
similarity index 100%
rename from "\343\200\220035\343\200\221\343\200\220SearchInsertPosition\343\200\221/src/Solution.java"
rename to [0035][Search Insert Position]/src/Solution.java
diff --git a/[0036][Valid Sudoku]/[0036][Valid Sudoku].iml b/[0036][Valid Sudoku]/[0036][Valid Sudoku].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0036][Valid Sudoku]/[0036][Valid Sudoku].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0036][Valid Sudoku]/src/Solution.java b/[0036][Valid Sudoku]/src/Solution.java
new file mode 100644
index 0000000..80b5bcd
--- /dev/null
+++ b/[0036][Valid Sudoku]/src/Solution.java
@@ -0,0 +1,108 @@
+import java.util.Arrays;
+
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 16:59
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * ԭ
+ * Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.
+ * The Sudoku board could be partially filled, where empty cells are filled
+ * with the character '.'.
+ *
+ * A partially filled sudoku which is valid.
+ * Note:
+ * A valid Sudoku board (partially filled) is not necessarily solvable.
+ * Only the filled cells need to be validated.
+ *
+ * Ŀ
+ * ֤һǷϷ̵֤ӶӦҳ档
+ * Dzģյλʹõ档
+ * ע⣺Ϸ̲һҪĿɽģֻҪҪͿԡ
+ *
+ * ˼·
+ * ȶнм飬ٶнм飬飳*ķ
+ *
+ *
+ * @param board
+ * @return
+ */
+ public boolean isValidSudoku(char[][] board) {
+ // .ASCIIֵ460ASCIIֵ48/ASCIIֵ47
+ int number = board[0].length;
+ int[] record = new int[10 + 2]; //.9ֵݵλ[2, 10]
+ boolean isValid;
+ reset(record);
+
+ // нм
+ for (int i = 0; i < number; i++) {
+ for (int j = 0; j < number; j++) {
+ record[board[i][j] - '.']++;
+ }
+
+ // Ǽʧ
+ if (!check(record)) {
+ return false;
+ }
+ // ɹ
+ else {
+ reset(record);
+ }
+ }
+
+ // нм
+ for (int i = 0; i < number; i++) {
+ for (int j = 0; j < number; j++) {
+ record[board[j][i] - '.']++;
+ }
+
+ if (!check(record)) { // Ǽʧ
+ return false;
+ } else { // ɹ
+ reset(record);
+ }
+ }
+
+ // 3*3
+ for (int i = 0; i < 3; i++) {
+ for (int j = 0; j < 3; j++) {
+
+ for (int k = i * 3; k < (i + 1) * 3; k++) {
+ for (int l = j * 3; l < (j + 1) * 3; l++) {
+ record[board[k][l] - '.']++;
+ }
+ }
+
+ if (!check(record)) { // Ǽʧ
+ return false;
+ } else { // ɹ
+ reset(record);
+ }
+ }
+ }
+ return true;
+ }
+
+ private void reset(int[] a) {
+ Arrays.fill(a, 0);
+ }
+
+ /**
+ * һУһУ3*3ķǷϷ1-9еָ1ͲϷ
+ *
+ * @param a ֤
+ * @return ؽ
+ */
+ private boolean check(int[] a) {
+ for (int i = 2; i < a.length; i++) {
+ if (a[i] > 1) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
diff --git "a/\343\200\220036\343\200\221\343\200\220Valid Sudoku\343\200\221/src/sodoku.png" b/[0036][Valid Sudoku]/src/sodoku.png
similarity index 100%
rename from "\343\200\220036\343\200\221\343\200\220Valid Sudoku\343\200\221/src/sodoku.png"
rename to [0036][Valid Sudoku]/src/sodoku.png
diff --git a/[0037][Sudoku Solver]/[0037][Sudoku Solver].iml b/[0037][Sudoku Solver]/[0037][Sudoku Solver].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0037][Sudoku Solver]/[0037][Sudoku Solver].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0037][Sudoku Solver]/src/Solution.java b/[0037][Sudoku Solver]/src/Solution.java
new file mode 100644
index 0000000..8485787
--- /dev/null
+++ b/[0037][Sudoku Solver]/src/Solution.java
@@ -0,0 +1,56 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-09-28 15:06
+ **/
+public class Solution {
+ public void solveSudoku(char[][] board) {
+ if (board == null || board.length == 0) {
+ return;
+ }
+ solve(board);
+ }
+
+ public boolean solve(char[][] board) {
+ for (int i = 0; i < board.length; i++) {
+ for (int j = 0; j < board[0].length; j++) {
+ if (board[i][j] == '.') {
+ // 尝试1到9的数字
+ for (char c = '1'; c <= '9'; c++) {
+ if (isValid(board, i, j, c)) {
+ // 将字符放入单元格
+ board[i][j] = c;
+
+ // 如果字符可以放入单元格返回true
+ if (solve(board)) {
+ return true;
+ } else { // 如果字符不能放入单元格就是还原成点号
+ board[i][j] = '.';
+ }
+ }
+ }
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ private boolean isValid(char[][] board, int row, int col, char c) {
+ for (int i = 0; i < 9; i++) {
+ // 检查行
+ if (board[i][col] != '.' && board[i][col] == c) {
+ return false;
+ }
+ // 检查列
+ if (board[row][i] != '.' && board[row][i] == c) {
+ return false;
+ }
+ // 检查3*3的单元格
+ if (board[3 * (row / 3) + i / 3][3 * (col / 3) + i % 3] != '.'
+ && board[3 * (row / 3) + i / 3][3 * (col / 3) + i % 3] == c) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
diff --git a/[0038][Count And Say]/[0038][Count And Say].iml b/[0038][Count And Say]/[0038][Count And Say].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0038][Count And Say]/[0038][Count And Say].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220038\343\200\221\343\200\220CountAndSay\343\200\221/src/Solution.java" b/[0038][Count And Say]/src/Solution.java
similarity index 100%
rename from "\343\200\220038\343\200\221\343\200\220CountAndSay\343\200\221/src/Solution.java"
rename to [0038][Count And Say]/src/Solution.java
diff --git a/[0039][Combination Sum]/[0039][Combination Sum].iml b/[0039][Combination Sum]/[0039][Combination Sum].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0039][Combination Sum]/[0039][Combination Sum].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0039][Combination Sum]/src/Solution.java b/[0039][Combination Sum]/src/Solution.java
new file mode 100644
index 0000000..48c86b6
--- /dev/null
+++ b/[0039][Combination Sum]/src/Solution.java
@@ -0,0 +1,43 @@
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-09-28 15:11
+ **/
+public class Solution {
+ public List> combinationSum(int[] nums, int target) {
+ // 用于保存结果
+ List> list = new LinkedList<>();
+ Arrays.sort(nums);
+ backtrack(list, new ArrayList<>(), nums, target, 0);
+ return list;
+ }
+
+ // 回溯法
+ // list:保存总的结果
+ // tempList:保存临时结果
+ // nums:输入的数组
+ // remain:剩下的值
+ // start:可用的值在数组中的起始位置
+ private void backtrack(List> list, List tempList, int[] nums, int remain, int start) {
+ // 不够减
+ if (remain < 0) {
+ return;
+ } else if (remain == 0) { // 刚好够减
+ list.add(new LinkedList<>(tempList));
+ } else {
+ // 从剩下的数中一个一个尝试
+ for (int i = start; i < nums.length; i++) {
+ // 假设这个值是临时结果中的一个值
+ tempList.add(nums[i]);
+ // 处理下一步
+ backtrack(list, tempList, nums, remain - nums[i], i);
+ // 现场还原
+ tempList.remove(tempList.size() - 1);
+ }
+ }
+ }
+}
diff --git a/[0040][Combination Sum II]/[0040][Combination Sum II].iml b/[0040][Combination Sum II]/[0040][Combination Sum II].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0040][Combination Sum II]/[0040][Combination Sum II].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0040][Combination Sum II]/src/Solution.java b/[0040][Combination Sum II]/src/Solution.java
new file mode 100644
index 0000000..c766df0
--- /dev/null
+++ b/[0040][Combination Sum II]/src/Solution.java
@@ -0,0 +1,44 @@
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-09-28 15:15
+ **/
+public class Solution {
+ public List> combinationSum2(int[] nums, int target) {
+ List> list = new LinkedList<>();
+ Arrays.sort(nums);
+ backtrack(list, new LinkedList<>(), nums, target, 0);
+ return list;
+
+ }
+
+ /**
+ * @param list 结果集
+ * @param tempList 临时结果集
+ * @param nums 可选值数组
+ * @param remain 剩余值
+ * @param start 可选值的起始下标
+ */
+ private void backtrack(List> list, List tempList, int[] nums, int remain, int start) {
+ if (remain < 0) {
+ return;
+ } else if (remain == 0) {
+ list.add(new LinkedList<>(tempList));
+ } else {
+ for (int i = start; i < nums.length; i++) {
+ // 如果上一轮循环没有选nums[i],则本次循环就不能再选nums[i],
+ // 确保nums[i] 最多只用一次
+ if (i > start && nums[i] == nums[i - 1]) {
+ continue;
+ }
+ tempList.add(nums[i]);
+ // 数值不可以被重用
+ backtrack(list, tempList, nums, remain - nums[i], i + 1);
+ tempList.remove(tempList.size() - 1);
+ }
+ }
+ }
+}
diff --git a/[0041][First Missing Positive]/[0041][First Missing Positive].iml b/[0041][First Missing Positive]/[0041][First Missing Positive].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0041][First Missing Positive]/[0041][First Missing Positive].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0041][First Missing Positive]/src/Main.java b/[0041][First Missing Positive]/src/Main.java
new file mode 100644
index 0000000..3a25e0e
--- /dev/null
+++ b/[0041][First Missing Positive]/src/Main.java
@@ -0,0 +1,20 @@
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Arrays;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-19 14:38
+ **/
+public class Main {
+
+ @Test
+ public void test1() {
+ Solution solution = new Solution();
+ int[] arr = {1, 4, 3, 3, 2};
+ int result = solution.firstMissingPositive(arr);
+ System.out.println(Arrays.toString(arr));
+ Assert.assertEquals(5, result);
+ }
+}
diff --git a/[0041][First Missing Positive]/src/Solution.java b/[0041][First Missing Positive]/src/Solution.java
new file mode 100644
index 0000000..d8f7546
--- /dev/null
+++ b/[0041][First Missing Positive]/src/Solution.java
@@ -0,0 +1,52 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-09-28 15:18
+ **/
+public class Solution {
+ /**
+ *
+ *
+ * @param height
+ * @return
+ */
+ int trap4(int[] height) {
+ int left = 0;
+ int right = height.length - 1;
+ int ans = 0;
+ int leftMax = 0;
+ int rightMax = 0;
+
+ while (left < right) {
+ if (height[left] < height[right]) {
+ if (height[left] >= leftMax) {
+ leftMax = height[left];
+ } else {
+ ans += leftMax - height[left];
+ }
+
+ ++left;
+ } else {
+ if (height[right] >= rightMax) {
+ rightMax = height[right];
+ } else {
+ ans += rightMax - height[right];
+ }
+
+ --right;
+ }
+ }
+ return ans;
+ }
+}
diff --git a/[0043][Multiply Strings]/[0043][Multiply Strings].iml b/[0043][Multiply Strings]/[0043][Multiply Strings].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0043][Multiply Strings]/[0043][Multiply Strings].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0043][Multiply Strings]/src/Solution.java b/[0043][Multiply Strings]/src/Solution.java
new file mode 100644
index 0000000..04cfb1c
--- /dev/null
+++ b/[0043][Multiply Strings]/src/Solution.java
@@ -0,0 +1,44 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-09-28 15:23
+ **/
+public class Solution {
+ public String multiply(String num1, String num2) {
+ int m = num1.length(), n = num2.length();
+ int[] pos = new int[m + n];
+
+ int mul;
+ int index;
+ int temp;
+ for (int i = m - 1; i >= 0; i--) {
+ for (int j = n - 1; j >= 0; j--) {
+ // 求积
+ mul = (num1.charAt(i) - '0') * (num2.charAt(j) - '0');
+ // 积的最低位所在的位置
+ index = i + j + 1;
+
+ // 最低低求和
+ pos[index] += mul;
+
+ // 做进位处理
+ while (pos[index] > 9) {
+ temp = pos[index];
+ pos[index] = temp % 10;
+ --index;
+ pos[index] += temp / 10;
+ }
+
+ }
+ }
+
+
+ StringBuilder sb = new StringBuilder();
+
+ for (int p : pos) {
+ if (!(sb.length() == 0 && p == 0)) {
+ sb.append(p);
+ }
+ }
+ return sb.length() == 0 ? "0" : sb.toString();
+ }
+}
diff --git a/[0044][Wildcard Matching]/[0044][Wildcard Matching].iml b/[0044][Wildcard Matching]/[0044][Wildcard Matching].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0044][Wildcard Matching]/[0044][Wildcard Matching].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0044][Wildcard Matching]/src/Solution.java b/[0044][Wildcard Matching]/src/Solution.java
new file mode 100644
index 0000000..2f5d7e2
--- /dev/null
+++ b/[0044][Wildcard Matching]/src/Solution.java
@@ -0,0 +1,54 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-09-28 15:25
+ **/
+public class Solution {
+ public boolean isMatch(String str, String pattern) {
+ // 匹配串的索引
+ int s = 0;
+ // 模式串的索引
+ int p = 0;
+ // 记录匹配的匹配位置
+ int match = 0;
+ // 星号的起始索引
+ int starIdx = -1;
+ while (s < str.length()) {
+ // 两个指针都往前推进
+ if (p < pattern.length() && (pattern.charAt(p) == '?' || str.charAt(s) == pattern.charAt(p))) {
+ s++;
+ p++;
+ }
+ // 发现一个*,只前进模式串索引
+ else if (p < pattern.length() && pattern.charAt(p) == '*') {
+ // 记录最后一次发现*的位置
+ starIdx = p;
+ // 记录在匹配串中匹配*时的位置
+ match = s;
+ // 模式串索引向前推进
+ p++;
+ }
+ // last pattern pointer was *, advancing string pointer
+ // 最后的模式串索引是*,匹配串索引向前推进。这个条件隐含p >= pattern.length(),再加上starIdx != -1
+ // 说明存在*号匹配,在星号匹配的
+ else if (starIdx != -1) {
+ // 记录模式串最后处理的*号的下一个位置
+ p = starIdx + 1;
+ // 记录在匹配串中匹配*时的位置
+ match++;
+ // 匹配串索引向前推进
+ s = match;
+ }
+ // 当前的模式索引指向的不是*号,最后一个模式索引指向的也不是*号,说明不匹配
+ else {
+ return false;
+ }
+ }
+
+ // 检查余下的模式串,模式串必须全都是*号才行
+ while (p < pattern.length() && pattern.charAt(p) == '*') {
+ p++;
+ }
+
+ return p == pattern.length();
+ }
+}
diff --git a/[0045][Jump Game II]/[0045][Jump Game II].iml b/[0045][Jump Game II]/[0045][Jump Game II].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0045][Jump Game II]/[0045][Jump Game II].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0045][Jump Game II]/src/Solution.java b/[0045][Jump Game II]/src/Solution.java
new file mode 100644
index 0000000..3f11ba2
--- /dev/null
+++ b/[0045][Jump Game II]/src/Solution.java
@@ -0,0 +1,49 @@
+/**
+ * 使用贪心算法,每次都移动最远的距离
+ *
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-09-28 15:27
+ **/
+public class Solution {
+
+ public int jump(int[] nums) {
+
+ if (nums == null || nums.length < 2) {
+ return 0;
+ }
+
+ // 记录跳跃次数
+ int jump = 0;
+ // 记录当前可以到达的最远的位置
+ int currentMax = 0;
+ // 下一次可以到达的最远的位置
+ int nextMax = 0;
+ // 记录处理的位置
+ int i = 0;
+
+ // 还没有到最未位置,还可以移动
+ while (currentMax - i + 1 > 0) {
+ // 跳数增加
+ jump++;
+ // 找下一次最远可以移动的位置
+ for (; i <= currentMax; i++) {
+ nextMax = Math.max(nextMax, nums[i] + i);
+ // 如果下一次可以移动到最末的位置,则返回跳数
+ if (nextMax >= nums.length - 1) {
+ return jump;
+ }
+ }
+
+ // 本次处理不能使移动位增加,并且不能到达最末位置,说明永远到不了最后的位置
+ if (currentMax == nextMax) {
+ return Integer.MAX_VALUE;
+ }
+
+ // 更新当前可以移动的最远位置
+ currentMax = nextMax;
+ }
+
+ return 0;
+ }
+
+}
diff --git a/[0046][Permutations]/[0046][Permutations].iml b/[0046][Permutations]/[0046][Permutations].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0046][Permutations]/[0046][Permutations].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0046][Permutations]/src/Solution.java b/[0046][Permutations]/src/Solution.java
new file mode 100644
index 0000000..4f8f1ad
--- /dev/null
+++ b/[0046][Permutations]/src/Solution.java
@@ -0,0 +1,65 @@
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 16:50
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ private List> result;
+
+ /**
+ *
+ * ԭ
+ * Given a collection of numbers, return all possible permutations.
+ * For example,
+ * [1,2,3] have the following permutations:
+ * [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].
+ *
+ * Ŀ
+ * һ飬С
+ *
+ * ˼·
+ * ʹ÷η⡣
+ *
+ *
+ * @param num
+ * @return
+ */
+ public List> permute(int[] num) {
+
+ result = new LinkedList<>();
+ if (num != null) {
+ permute(0, num);
+ }
+
+ return result;
+ }
+
+ private void permute(int i, int[] nums) {
+
+ if (i == nums.length) {
+ List l = new ArrayList<>();
+ for (int n : nums) {
+ l.add(n);
+ }
+ result.add(l);
+ } else {
+
+ for (int j = i; j < nums.length; j++) {
+ swap(nums, j, i);
+ permute(i + 1, nums);
+ swap(nums, j, i);
+ }
+ }
+ }
+
+ private void swap(int[] nums, int x, int y) {
+ int tmp = nums[x];
+ nums[x] = nums[y];
+ nums[y] = tmp;
+ }
+}
diff --git a/[0047][Permutations II]/[0047][Permutations II].iml b/[0047][Permutations II]/[0047][Permutations II].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0047][Permutations II]/[0047][Permutations II].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0047][Permutations II]/src/Main.java b/[0047][Permutations II]/src/Main.java
new file mode 100644
index 0000000..050363c
--- /dev/null
+++ b/[0047][Permutations II]/src/Main.java
@@ -0,0 +1,14 @@
+import org.junit.Test;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-19 18:01
+ **/
+public class Main {
+ @Test
+ public void test1() {
+ Solution solution = new Solution();
+ int[] nums = {1, 1, 2};
+ System.out.println(solution.permuteUnique(nums));
+ }
+}
diff --git a/[0047][Permutations II]/src/Solution.java b/[0047][Permutations II]/src/Solution.java
new file mode 100644
index 0000000..8775cef
--- /dev/null
+++ b/[0047][Permutations II]/src/Solution.java
@@ -0,0 +1,63 @@
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-09-28 15:29
+ **/
+public class Solution {
+
+ public List> permuteUnique(int[] nums) {
+ List> res = new ArrayList<>();
+
+ if (nums == null || nums.length == 0) {
+ return res;
+ }
+
+ boolean[] used = new boolean[nums.length];
+ List list = new ArrayList<>();
+
+ Arrays.sort(nums);
+
+ permuteUnique(nums, used, list, res);
+ return res;
+ }
+
+ /**
+ * 时间复杂度:n!
+ *
+ * @param nums
+ * @param used
+ * @param list
+ * @param res
+ */
+ private void permuteUnique(int[] nums, boolean[] used, List list, List> res) {
+ if (list.size() == nums.length) {
+ res.add(new ArrayList<>(list));
+ return;
+ }
+
+ for (int i = 0; i < nums.length; i++) {
+ // 第i个数值已经被使用过
+ if (used[i]) {
+ continue;
+ }
+
+ // 第i个字符与前一个字符相等,并且第i-1个字符没有使用,说明此次不应该交换
+ if (i > 0 && nums[i - 1] == nums[i] && !used[i - 1]) {
+ continue;
+ }
+
+ // 标记第i个字符已经被使用
+ used[i] = true;
+ // 添加到临时结果中
+ list.add(nums[i]);
+ // 下一次处理
+ permuteUnique(nums, used, list, res);
+ // 现场还原
+ used[i] = false;
+ list.remove(list.size() - 1);
+ }
+ }
+}
diff --git a/[0048][Rotate Image]/[0048][Rotate Image].iml b/[0048][Rotate Image]/[0048][Rotate Image].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0048][Rotate Image]/[0048][Rotate Image].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0048][Rotate Image]/src/Solution.java b/[0048][Rotate Image]/src/Solution.java
new file mode 100644
index 0000000..bba7234
--- /dev/null
+++ b/[0048][Rotate Image]/src/Solution.java
@@ -0,0 +1,28 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-09-28 15:31
+ **/
+public class Solution {
+ public void rotate(int[][] matrix) {
+ int temp;
+
+ // 先做y=x对称转换
+ for (int i = 0; i < matrix.length; i++) {
+ for (int j = i; j < matrix.length; j++) {
+ temp = matrix[i][j];
+ matrix[i][j] = matrix[j][i];
+ matrix[j][i] = temp;
+ }
+ }
+
+ // 再对行进行垂直转换
+ int half = matrix.length / 2;
+ for (int i = 0; i < matrix.length; i++) {
+ for (int j = 0; j < half; j++) {
+ temp = matrix[i][j];
+ matrix[i][j] = matrix[i][matrix.length - 1 - j];
+ matrix[i][matrix.length - 1 - j] = temp;
+ }
+ }
+ }
+}
diff --git a/[0049][Group Anagrams]/[0049][Group Anagrams].iml b/[0049][Group Anagrams]/[0049][Group Anagrams].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0049][Group Anagrams]/[0049][Group Anagrams].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0049][Group Anagrams]/src/Solution.java b/[0049][Group Anagrams]/src/Solution.java
new file mode 100644
index 0000000..ef5973e
--- /dev/null
+++ b/[0049][Group Anagrams]/src/Solution.java
@@ -0,0 +1,76 @@
+import java.util.*;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-09-28 15:33
+ **/
+public class Solution {
+
+ public List> groupAnagrams(String[] strs) {
+ return groupAnagrams2(strs);
+ }
+
+ /**
+ * 算法原理:对字符串进行排序,相同类型的字符串排序后的字符串都是一样的
+ *
+ * @param strs
+ * @return
+ */
+ public List> groupAnagrams1(String[] strs) {
+ if (strs.length == 0) {
+ return new ArrayList();
+ }
+ Map ans = new HashMap<>();
+ // 处理每一个字符串
+ for (String s : strs) {
+ char[] ca = s.toCharArray();
+ // 对象字符串对应的字符数组进行排序,再转成排序后的字符串
+ Arrays.sort(ca);
+ String key = String.valueOf(ca);
+ // 如果map中不包含已经排序后的字符串,那么就创建一个新容器要放入结果
+ if (!ans.containsKey(key)) {
+ ans.put(key, new ArrayList());
+ }
+
+ // 结果放入对应的集合中
+ ans.get(key).add(s);
+ }
+ return new ArrayList(ans.values());
+ }
+
+ /**
+ * 算法原理:统计每个字符出现的次数,然后使用#字符将每个字符出现的次数拼成一个字符串,
+ * 相同类型的字符串通过上面的方式拼出来的字符串都是一样的
+ *
+ * @param strs
+ * @return
+ */
+ public List> groupAnagrams2(String[] strs) {
+ if (strs.length == 0) {
+ return new ArrayList();
+ }
+ Map ans = new HashMap<>();
+ int[] count = new int[26];
+
+ for (String s : strs) {
+ // 清零操作
+ Arrays.fill(count, 0);
+ for (char c : s.toCharArray()) {
+ count[c - 'a']++;
+ }
+
+ // 字符串拼接
+ StringBuilder sb = new StringBuilder("");
+ for (int i = 0; i < 26; i++) {
+ sb.append('#');
+ sb.append(count[i]);
+ }
+ String key = sb.toString();
+ if (!ans.containsKey(key)) {
+ ans.put(key, new ArrayList());
+ }
+ ans.get(key).add(s);
+ }
+ return new ArrayList(ans.values());
+ }
+}
diff --git a/[0050][Pow(x,n)]/[0050][Pow(x,n)].iml b/[0050][Pow(x,n)]/[0050][Pow(x,n)].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0050][Pow(x,n)]/[0050][Pow(x,n)].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220050\343\200\221\343\200\220Pow(x,n)\343\200\221/src/Solution.java" b/[0050][Pow(x,n)]/src/Solution.java
similarity index 100%
rename from "\343\200\220050\343\200\221\343\200\220Pow(x,n)\343\200\221/src/Solution.java"
rename to [0050][Pow(x,n)]/src/Solution.java
diff --git a/[0051][N-Queens]/[0051][N-Queens].iml b/[0051][N-Queens]/[0051][N-Queens].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0051][N-Queens]/[0051][N-Queens].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0051][N-Queens]/src/Solution.java b/[0051][N-Queens]/src/Solution.java
new file mode 100644
index 0000000..7d31661
--- /dev/null
+++ b/[0051][N-Queens]/src/Solution.java
@@ -0,0 +1,69 @@
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-09-28 15:36
+ **/
+public class Solution {
+ public List> solveNQueens(int n) {
+ List> result = new ArrayList<>();
+
+ if (n < 1) {
+ return result;
+ }
+
+ char[][] board = new char[n][];
+ for (int i = 0; i < n; i++) {
+ board[i] = new char[n];
+ Arrays.fill(board[i], '.');
+ }
+
+ solveNQueens(board, 0, result);
+ return result;
+ }
+
+ private void solveNQueens(char[][] board, int row, List> result) {
+ if (board.length == row) {
+ List list = new ArrayList<>();
+ for (char[] chs : board) {
+ list.add(new String(chs));
+ }
+ result.add(list);
+ }
+
+ for (int col = 0; col < board.length; col++) {
+ if (canPlace(board, row, col)) {
+ board[row][col] = 'Q';
+ solveNQueens(board, row + 1, result);
+ board[row][col] = '.';
+ }
+ }
+ }
+
+ private boolean canPlace(char[][] board, int row, int col) {
+ // 检测之前的列上是否已经放过皇后
+ for (int i = 0; i < row; ++i) {
+ if (board[i][col] == 'Q') {
+ return false;
+ }
+ }
+
+ // 45度角(左下角)上是否已经存在过皇后
+ for (int i = row - 1, j = col - 1; i >= 0 && j >= 0; --i, --j) {
+ if (board[i][j] == 'Q') {
+ return false;
+ }
+ }
+
+ // 135度角上(左上角)是否已经存在过皇后
+ for (int i = row - 1, j = col + 1; i >= 0 && j < board.length; --i, ++j) {
+ if (board[i][j] == 'Q') {
+ return false;
+ }
+ }
+
+ return true;
+ }
+}
diff --git a/[0052][N-Queens II]/[0052][N-Queens II].iml b/[0052][N-Queens II]/[0052][N-Queens II].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0052][N-Queens II]/[0052][N-Queens II].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0052][N-Queens II]/src/Solution.java b/[0052][N-Queens II]/src/Solution.java
new file mode 100644
index 0000000..5638da5
--- /dev/null
+++ b/[0052][N-Queens II]/src/Solution.java
@@ -0,0 +1,63 @@
+import java.util.Arrays;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-09-28 15:38
+ **/
+public class Solution {
+ public int totalNQueens(int n) {
+ int[] result = {0};
+
+ if (n < 1) {
+ return result[0];
+ }
+
+ char[][] board = new char[n][];
+ for (int i = 0; i < n; i++) {
+ board[i] = new char[n];
+ Arrays.fill(board[i], '.');
+ }
+
+ solveNQueens(board, 0, result);
+ return result[0];
+ }
+
+ private void solveNQueens(char[][] board, int row, int[] result) {
+ if (board.length == row) {
+ result[0]++;
+ }
+
+ for (int col = 0; col < board.length; col++) {
+ if (canPlace(board, row, col)) {
+ board[row][col] = 'Q';
+ solveNQueens(board, row + 1, result);
+ board[row][col] = '.';
+ }
+ }
+ }
+
+ private boolean canPlace(char[][] board, int row, int col) {
+ // 检测之前的列上是否已经放过皇后
+ for (int i = 0; i < row; ++i) {
+ if (board[i][col] == 'Q') {
+ return false;
+ }
+ }
+
+ // 45度角(左下角)上是否已经存在过皇后
+ for (int i = row - 1, j = col - 1; i >= 0 && j >= 0; --i, --j) {
+ if (board[i][j] == 'Q') {
+ return false;
+ }
+ }
+
+ // 135度角上(左上角)是否已经存在过皇后
+ for (int i = row - 1, j = col + 1; i >= 0 && j < board.length; --i, ++j) {
+ if (board[i][j] == 'Q') {
+ return false;
+ }
+ }
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/[0053][Maximum Subarray]/[0053][Maximum Subarray].iml b/[0053][Maximum Subarray]/[0053][Maximum Subarray].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0053][Maximum Subarray]/[0053][Maximum Subarray].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0053][Maximum Subarray]/src/Solution.java b/[0053][Maximum Subarray]/src/Solution.java
new file mode 100644
index 0000000..4b97536
--- /dev/null
+++ b/[0053][Maximum Subarray]/src/Solution.java
@@ -0,0 +1,75 @@
+/**
+ * Author:
+ * Date: 2015-06-22
+ * Time: 12:05
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * Given an integer array nums, find the contiguous subarray (containing at least one number)
+ * which has the largest sum and return its sum.
+ *
+ * Example:
+ *
+ * Input: [-2,1,-3,4,-1,2,1,-5,4],
+ * Output: 6
+ * Explanation: [4,-1,2,1] has the largest sum = 6.
+ * Follow up:
+ *
+ * If you have figured out the O(n) solution, try coding another solution using the divide and
+ * conquer approach, which is more subtle.
+ *
+ * Ŀ⣺
+ * ĺ
+ * ˼·
+ * ̬滮⣬֪ǰkԪصкΪmaxSubѾ¼ˣԼһʱsum
+ * ˵k+1Ԫأƣk+1Ԫ֮ǰĺС0ģ
+ * ôk+1ԪشӶȥûйģԿsum 0
+ *
+ * Ǵͷβʱһмѡأֻ
+ * ѡ1֮ǰSubArray2. ԼһSubArrayʲôʱأ
+ * ֮ǰSubArray ʹ0 ĻΪԺйġ
+ * ѡ֮ǰSubArray
+ * ֮ǰSubArray Ϊ0 С0 ĻΪԺûйף
+ * кģС0 ʱѡֿʼһSubArray
+ * ״̬Ϊf[j]ʾS[j] βкͣ״̬תƷ£
+ * f[j] = max {f[j - 1] + S[j]; S[j]} ; 1 <= j <= n
+ * target = max {f[j]}; 1 <= j <= n
+ * £
+ * һS[j] ǰijЩһУкΪf[j - 1] + S[j]
+ * S[j] ֳΪһΣнһS[j]кΪS[j]
+ *
+ *
+ *
+ * @param nums
+ * @return
+ */
+ public int maxSubArray(int[] nums) {
+ // У
+ if (nums == null || nums.length < 1) {
+ throw new IllegalArgumentException();
+ }
+
+ int max = Integer.MIN_VALUE;
+ int curSum = 0;
+
+ for (int i : nums) {
+ // ǰС0ͽǰֵcurSum
+ if (curSum <= 0) {
+ curSum = i;
+ }
+ // ۼ
+ else {
+ curSum += i;
+ }
+
+ // ϴֵ
+ if (max < curSum) {
+ max = curSum;
+ }
+ }
+
+ return max;
+ }
+}
diff --git a/[0054][Spiral Matrix]/[0054][Spiral Matrix].iml b/[0054][Spiral Matrix]/[0054][Spiral Matrix].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0054][Spiral Matrix]/[0054][Spiral Matrix].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0054][Spiral Matrix]/[0054][SpiralMatrix].iml b/[0054][Spiral Matrix]/[0054][SpiralMatrix].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0054][Spiral Matrix]/[0054][SpiralMatrix].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220054\343\200\221\343\200\220SpiralMatrix\343\200\221/src/Solution.java" b/[0054][Spiral Matrix]/src/Solution.java
similarity index 100%
rename from "\343\200\220054\343\200\221\343\200\220SpiralMatrix\343\200\221/src/Solution.java"
rename to [0054][Spiral Matrix]/src/Solution.java
diff --git a/[0055][Jump Game]/[0055][Jump Game].iml b/[0055][Jump Game]/[0055][Jump Game].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0055][Jump Game]/[0055][Jump Game].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0055][Jump Game]/src/Solution.java b/[0055][Jump Game]/src/Solution.java
new file mode 100644
index 0000000..73b2d82
--- /dev/null
+++ b/[0055][Jump Game]/src/Solution.java
@@ -0,0 +1,72 @@
+/**
+ * Author: 王俊超
+ * Date: 2015-06-19
+ * Time: 19:29
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * 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.
+ *
+ * 题目大意:
+ * 给定的非负整数的数组,则最初定位在数组的第一个位置。数组中的每个元素都代表你的最大跳跃长度在那个位置。
+ * 决定你是否能到达最后一个索引。
+ *
+ *
+ *
+ * @param nums
+ * @return
+ */
+ public boolean canJump(int[] nums) {
+ return canJump2(nums);
+ }
+
+ public boolean canJump1(int[] nums) {
+ if (nums == null || nums.length < 2) {
+ return true;
+ }
+
+ // 最后可以移动的位置
+ int lastPos = 0;
+
+ // 处理每一个位置
+ for (int i = 0; i < nums.length; i++) {
+ // i不能比lastPos大,否则说明不能走到i,走不到i也就不能走到最后
+ // 如果在i位置可以移动的距离比已经记录到的最大距离还要大,那么更新最大的移动距离
+ if (i <= lastPos && i + nums[i] > lastPos) {
+ lastPos = i + nums[i];
+ } else if (i > lastPos) {
+ return false;
+ }
+ }
+
+ // 最后的位置必然可以达到最后
+ return lastPos >= nums.length - 1;
+ }
+
+ /**
+ * 逆向,从最高层下楼梯,一层一层下降,看最后能不能下降到第0 层。
+ *
+ * @param nums
+ * @return
+ */
+ public boolean canJump2(int[] nums) {
+ int lastPos = nums.length - 1;
+ for (int i = nums.length - 1; i >= 0; i--) {
+ if (i + nums[i] >= lastPos) {
+ lastPos = i;
+ }
+ }
+ return lastPos == 0;
+ }
+}
diff --git a/[0056][Merge Intervals]/[0056][Merge Intervals].iml b/[0056][Merge Intervals]/[0056][Merge Intervals].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0056][Merge Intervals]/[0056][Merge Intervals].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220056\343\200\221\343\200\220MergeIntervals\343\200\221/src/Interval.java" b/[0056][Merge Intervals]/src/Interval.java
similarity index 100%
rename from "\343\200\220056\343\200\221\343\200\220MergeIntervals\343\200\221/src/Interval.java"
rename to [0056][Merge Intervals]/src/Interval.java
diff --git a/[0056][Merge Intervals]/src/Solution.java b/[0056][Merge Intervals]/src/Solution.java
new file mode 100644
index 0000000..7f0df6a
--- /dev/null
+++ b/[0056][Merge Intervals]/src/Solution.java
@@ -0,0 +1,63 @@
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Author:
+ * Date: 2015-06-23
+ * Time: 19:39
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * 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].
+ *
+ * Ŀ⣬
+ * һ伯ϣϲص
+ *
+ * ˼·
+ * ȶʼһһкϲ
+ *
+ *
+ * @param intervals
+ * @return
+ */
+ public List merge(List intervals) {
+ List result = new LinkedList<>();
+
+ if (intervals == null || intervals.size() < 1) {
+ return result;
+ }
+
+ // ȶʹһڲ
+ Collections.sort(intervals, new Comparator() {
+ @Override
+ public int compare(Interval o1, Interval o2) {
+ return o1.start - o2.start;
+ }
+ });
+
+ // һԪأΪnextstartһDzСǰһΪprevstartģ
+ // ӵ䣬next.startprev.end˵ǷֿģҪ
+ // һµ䣬˵next.start[prev.start, prev.end]ڣֻҪ
+ // next.endǷǴprev.endھҪϲ䣨
+ Interval prev = null;
+ for (Interval item : intervals) {
+
+ if (prev == null || prev.end < item.start) {
+ result.add(item);
+ prev = item;
+ } else if (prev.end < item.end) {
+ prev.end = item.end;
+ }
+ }
+
+ return result;
+ }
+}
diff --git a/[0057][Insert Interval]/[0057][Insert Interval].iml b/[0057][Insert Interval]/[0057][Insert Interval].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0057][Insert Interval]/[0057][Insert Interval].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220057\343\200\221\343\200\220InsertInterval\343\200\221/src/Interval.java" b/[0057][Insert Interval]/src/Interval.java
similarity index 100%
rename from "\343\200\220057\343\200\221\343\200\220InsertInterval\343\200\221/src/Interval.java"
rename to [0057][Insert Interval]/src/Interval.java
diff --git a/[0057][Insert Interval]/src/Solution.java b/[0057][Insert Interval]/src/Solution.java
new file mode 100644
index 0000000..7486cdb
--- /dev/null
+++ b/[0057][Insert Interval]/src/Solution.java
@@ -0,0 +1,74 @@
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Author:
+ * Date: 2015-06-24
+ * Time: 19:33
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * 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.
+ *
+ * Example 1:
+ * Given intervals [1,3],[6,9], insert and merge [2,5] in as [1,5],[6,9].
+ *
+ * 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].
+ *
+ * This is because the new interval [4,9] overlaps with [3,5],[6,7],[8,10].
+ *
+ * Ŀ⣺
+ * һϵзǸǵ䣬һµ䣬бҪʱϲ
+ * 俪ʼʼʱкϲ
+ *
+ * ˼·
+ * ԭȲСͲص²䣬
+ * Сԭ䣬Ȳ䣬Ӵ
+ *
+ *
+ * @param intervals
+ * @param newInterval
+ * @return
+ */
+ public List insert(List intervals, Interval newInterval) {
+
+ // ļ
+ List result = new LinkedList<>();
+
+ // 뼯ǿ
+ if (intervals != null) {
+ // Ԫ
+ for (Interval item : intervals) {
+ // newInterval == null ʾѾ
+ // ȲС
+ if (newInterval == null || item.end < newInterval.start) {
+ result.add(item);
+ }
+ // ȲУͬʱ
+ else if (item.start > newInterval.end) {
+ result.add(newInterval);
+ result.add(item);
+ newInterval = null;
+ }
+ // ص²
+ else {
+ newInterval.start = Math.min(newInterval.start, item.start);
+ newInterval.end = Math.max(newInterval.end, item.end);
+ }
+ }
+ }
+
+ // ǿ˵仹δ
+ if (newInterval != null) {
+ result.add(newInterval);
+ }
+
+ return result;
+ }
+}
diff --git a/[0058][Length Of Last Word]/[0058][Length Of Last Word].iml b/[0058][Length Of Last Word]/[0058][Length Of Last Word].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0058][Length Of Last Word]/[0058][Length Of Last Word].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220058\343\200\221\343\200\220LengthOfLastWord\343\200\221/src/Solution.java" b/[0058][Length Of Last Word]/src/Solution.java
similarity index 100%
rename from "\343\200\220058\343\200\221\343\200\220LengthOfLastWord\343\200\221/src/Solution.java"
rename to [0058][Length Of Last Word]/src/Solution.java
diff --git a/[0059][Spiral Matrix II]/[0059][Spiral Matrix II].iml b/[0059][Spiral Matrix II]/[0059][Spiral Matrix II].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0059][Spiral Matrix II]/[0059][Spiral Matrix II].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0059][Spiral Matrix II]/[0059][SpiralMatrixII].iml b/[0059][Spiral Matrix II]/[0059][SpiralMatrixII].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0059][Spiral Matrix II]/[0059][SpiralMatrixII].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220059\343\200\221\343\200\220SpiralMatrixII\343\200\221/src/Solution.java" b/[0059][Spiral Matrix II]/src/Solution.java
similarity index 100%
rename from "\343\200\220059\343\200\221\343\200\220SpiralMatrixII\343\200\221/src/Solution.java"
rename to [0059][Spiral Matrix II]/src/Solution.java
diff --git a/[0060][Permutation Sequence]/[0060][Permutation Sequence].iml b/[0060][Permutation Sequence]/[0060][Permutation Sequence].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0060][Permutation Sequence]/[0060][Permutation Sequence].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0060][Permutation Sequence]/src/Solution.java b/[0060][Permutation Sequence]/src/Solution.java
new file mode 100644
index 0000000..3bc2edf
--- /dev/null
+++ b/[0060][Permutation Sequence]/src/Solution.java
@@ -0,0 +1,57 @@
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-09-28 15:45
+ **/
+public class Solution {
+ /**
+ *
+ *
+ * @param n
+ * @param k
+ * @return
+ */
+ public String getPermutation(int n, int k) {
+
+ StringBuilder sb = new StringBuilder();
+ List num = new ArrayList<>();
+ // 用于计录最大的阶乘数
+ int fact = 1;
+ for (int i = 1; i <= n; i++) {
+ fact *= i;
+ num.add(i);
+ }
+
+ // l = k - 1;为了方便从0开始计数
+ int index;
+ for (int i = 0, l = k - 1; i < n; i++) {
+ // 从最大的阶乘数开始减少
+ // fact的值说明,如果从 __1____ -> _2____ 至少要经过fact次变换
+ fact /= (n - i);
+ // 计算剩下的数据中的索引
+ // 说明类似 __1____ -> _2____ 的变化可以做 index 次,0表示不用变
+ index = (l / fact);
+ // 将索引值添加到结果中
+ // 每做一次__1____ -> _2____ 的变化,表示在num中取后一个更大的值
+ sb.append(num.remove(index));
+ // 余下要处理的数
+ l -= index * fact;
+ }
+
+ return sb.toString();
+ }
+}
diff --git a/[0061][Rotate List]/[0061][Rotate List].iml b/[0061][Rotate List]/[0061][Rotate List].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0061][Rotate List]/[0061][Rotate List].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220061\343\200\221\343\200\220RotateList\343\200\221/src/ListNode.java" b/[0061][Rotate List]/src/ListNode.java
similarity index 100%
rename from "\343\200\220061\343\200\221\343\200\220RotateList\343\200\221/src/ListNode.java"
rename to [0061][Rotate List]/src/ListNode.java
diff --git a/[0061][Rotate List]/src/Solution.java b/[0061][Rotate List]/src/Solution.java
new file mode 100644
index 0000000..9f4e91d
--- /dev/null
+++ b/[0061][Rotate List]/src/Solution.java
@@ -0,0 +1,34 @@
+/**
+ * Author:
+ * Date: 2015-07-21
+ * Time: 18:46
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ public ListNode rotateRight(ListNode head, int n) {
+
+ if (head == null || n < 1) {
+ return head;
+ }
+
+ int length = 1;
+ ListNode p = head;
+ while (p.next != null) {
+ p = p.next;
+ length++;
+ }
+
+ // ҪĽڵΪheadǰһڵ
+ n = length - n % length;
+
+ // β
+ p.next = head;
+ for (int i = 0; i < n; i++) {
+ p = p.next;
+ }
+
+ head = p.next;
+ p.next = null;
+ return head;
+ }
+}
diff --git a/[0061][Rotate List]/src/Solution2.java b/[0061][Rotate List]/src/Solution2.java
new file mode 100644
index 0000000..00ca18f
--- /dev/null
+++ b/[0061][Rotate List]/src/Solution2.java
@@ -0,0 +1,62 @@
+/**
+ * Author:
+ * Date: 2015-07-21
+ * Time: 18:46
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution2 {
+ public ListNode rotateRight(ListNode head, int n) {
+
+ if (head == null || n < 1) {
+ return head;
+ }
+
+ ListNode root = new ListNode(0);
+ root.next = head;
+ ListNode p = root;
+ ListNode q = root;
+
+ // תλÿܱ
+ int count = 0;
+ for (int i = 0; i <= n; i++) {
+ p = p.next;
+ count++;
+ if (p == null) {
+ // гͷݸ
+ count--;
+ // ʵҪλõλ
+ n = n % count;
+ // Ϊ¿ʼλ
+ i = 0;
+ p = head;
+ }
+ }
+
+ // ҵһҪĽǰ
+ // qΪһҪĽǰ
+ while (p != null) {
+ p = p.next;
+ q = q.next;
+
+ }
+
+ p = q;
+ q = root;
+ // ҪλƵĽ
+ if (p != null && p.next != null) {
+ ListNode node;
+ while (p.next != null) {
+ // ժ
+ node = p.next;
+ p.next = node.next;
+ // Ͻ
+ node.next = q.next;
+ q.next = node;
+ // һƶĽڵ
+ q = node;
+ }
+ }
+
+ return root.next;
+ }
+}
diff --git a/[0062][Unique Paths]/[0062][Unique Paths].iml b/[0062][Unique Paths]/[0062][Unique Paths].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0062][Unique Paths]/[0062][Unique Paths].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0062][Unique Paths]/[0062][UniquePaths].iml b/[0062][Unique Paths]/[0062][UniquePaths].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0062][Unique Paths]/[0062][UniquePaths].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0062][Unique Paths]/src/Solution.java b/[0062][Unique Paths]/src/Solution.java
new file mode 100644
index 0000000..43be774
--- /dev/null
+++ b/[0062][Unique Paths]/src/Solution.java
@@ -0,0 +1,63 @@
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 19:30
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * ԭ
+ * 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.
+ *
+ * Ŀ
+ * һһm*nķϽǡ
+ * ֻһһҪ½ǵķ
+ * һжΨһ·
+ * ע⣺ͣ100
+ *
+ * ˼·
+ * ͵Ķ̬滮⣬ʹö̬滮ķ⡣
+ * һm*nA
+ * AеԪС
+ * 1x=0y=0ʱA[x][y] = 1
+ * 2x>=1y>=1ʱA[x][y] = A[x-1][y]+A[x][y-1]
+ * 3ĽA[m-1][n-1]
+ *
+ *
+ * @param m
+ * @param n
+ * @return
+ */
+ public int uniquePaths(int m, int n) {
+ int[][] result = new int[m][n];
+
+ // һеĽ
+ for (int i = 0; i < m; i++) {
+ result[i][0] = 1;
+ }
+
+ // һеĽ
+ for (int i = 1; i < n; i++) {
+ result[0][i] = 1;
+ }
+
+ // λõĽ
+ for (int i = 1; i < m; i++) {
+ for (int j = 1; j < n; j++) {
+ result[i][j] = result[i - 1][j] + result[i][j - 1];
+ }
+ }
+
+ // Ľ
+ return result[m - 1][n - 1];
+ }
+}
diff --git a/[0063][Unique Paths II]/[0063][Unique Paths II].iml b/[0063][Unique Paths II]/[0063][Unique Paths II].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0063][Unique Paths II]/[0063][Unique Paths II].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0063][Unique Paths II]/[0063][UniquePathsII].iml b/[0063][Unique Paths II]/[0063][UniquePathsII].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0063][Unique Paths II]/[0063][UniquePathsII].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220063\343\200\221\343\200\220UniquePathsII\343\200\221/src/Solution.java" b/[0063][Unique Paths II]/src/Solution.java
similarity index 100%
rename from "\343\200\220063\343\200\221\343\200\220UniquePathsII\343\200\221/src/Solution.java"
rename to [0063][Unique Paths II]/src/Solution.java
diff --git a/[0064][Minimum Path Sum]/[0064][Minimum Path Sum].iml b/[0064][Minimum Path Sum]/[0064][Minimum Path Sum].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0064][Minimum Path Sum]/[0064][Minimum Path Sum].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0064][Minimum Path Sum]/[0064][MinimumPathSum].iml b/[0064][Minimum Path Sum]/[0064][MinimumPathSum].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0064][Minimum Path Sum]/[0064][MinimumPathSum].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220064\343\200\221\343\200\220MinimumPathSum\343\200\221/src/Main.java" b/[0064][Minimum Path Sum]/src/Main.java
similarity index 100%
rename from "\343\200\220064\343\200\221\343\200\220MinimumPathSum\343\200\221/src/Main.java"
rename to [0064][Minimum Path Sum]/src/Main.java
diff --git "a/\343\200\220064\343\200\221\343\200\220MinimumPathSum\343\200\221/src/Solution.java" b/[0064][Minimum Path Sum]/src/Solution.java
similarity index 100%
rename from "\343\200\220064\343\200\221\343\200\220MinimumPathSum\343\200\221/src/Solution.java"
rename to [0064][Minimum Path Sum]/src/Solution.java
diff --git a/[0065][Valid Number]/[0065][Valid Number].iml b/[0065][Valid Number]/[0065][Valid Number].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0065][Valid Number]/[0065][Valid Number].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0065][Valid Number]/src/Main.java b/[0065][Valid Number]/src/Main.java
new file mode 100644
index 0000000..c039e9e
--- /dev/null
+++ b/[0065][Valid Number]/src/Main.java
@@ -0,0 +1,95 @@
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-17 13:32
+ **/
+public class Main {
+ @Test
+ public void test1() {
+ Solution solution = new Solution();
+ Assert.assertEquals(true, solution.isNumber("0"));
+ }
+
+ @Test
+ public void test2() {
+ Solution solution = new Solution();
+ Assert.assertEquals(true, solution.isNumber(" 0.1 "));
+ }
+
+ @Test
+ public void test3() {
+ Solution solution = new Solution();
+ Assert.assertEquals(false, solution.isNumber("abc"));
+ }
+
+ @Test
+ public void test4() {
+ Solution solution = new Solution();
+ Assert.assertEquals(false, solution.isNumber("1 a"));
+ }
+
+ @Test
+ public void test41() {
+ Solution solution = new Solution();
+ Assert.assertEquals(true, solution.isNumber("2e10"));
+ }
+
+ @Test
+ public void test42() {
+ Solution solution = new Solution();
+ Assert.assertEquals(true, solution.isNumber(" -90e3 "));
+ }
+
+ @Test
+ public void test5() {
+ Solution solution = new Solution();
+ Assert.assertEquals(false, solution.isNumber(" 1e"));
+ }
+
+ @Test
+ public void test6() {
+ Solution solution = new Solution();
+ Assert.assertEquals(false, solution.isNumber("e3"));
+ }
+
+
+ @Test
+ public void test7() {
+ Solution solution = new Solution();
+ Assert.assertEquals(true, solution.isNumber(" 6e-1"));
+ }
+
+ @Test
+ public void test8() {
+ Solution solution = new Solution();
+ Assert.assertEquals(false, solution.isNumber(" 99e2.5 "));
+ }
+
+
+ @Test
+ public void test9() {
+ Solution solution = new Solution();
+ Assert.assertEquals(true, solution.isNumber("53.5e93"));
+ }
+
+ @Test
+ public void test10() {
+ Solution solution = new Solution();
+ Assert.assertEquals(false, solution.isNumber(" --6 "));
+ }
+
+ @Test
+ public void test11() {
+ Solution solution = new Solution();
+ Assert.assertEquals(false, solution.isNumber("-+3"));
+ }
+
+ @Test
+ public void test12() {
+ Solution solution = new Solution();
+ Assert.assertEquals(false, solution.isNumber("95a54e53"));
+ }
+
+}
diff --git a/[0065][Valid Number]/src/Solution.java b/[0065][Valid Number]/src/Solution.java
new file mode 100644
index 0000000..3f6d642
--- /dev/null
+++ b/[0065][Valid Number]/src/Solution.java
@@ -0,0 +1,100 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-17 13:20
+ **/
+public class Solution {
+
+ /**
+ * 序数就分别为0, 1, 2, 3, 4, 5, 6
+ */
+ private enum InputType {
+ INVALID,
+ SPACE,
+ SIGN,
+ DIGIT,
+ DOT,
+ EXPONENT
+ }
+
+ // 状态转表 TODO 每个状态是什么意思?
+ private final static int[][] TRANSITION_TABLE = {
+ {-1, 0, 3, 1, 2, -1}, // next states for state 0
+ {-1, 8, -1, 1, 4, 5}, // next states for state 1
+ {-1, -1, -1, 4, -1, -1},// next states for state 2
+ {-1, -1, -1, 1, 2, -1,},// next states for state 3
+ {-1, 8, -1, 4, -1, 5},// next states for state 4
+ {-1, -1, 6, 7, -1, -1},// next states for state 5
+ {-1, -1, -1, 7, -1, -1},// next states for state 6
+ {-1, 8, -1, 7, -1, -1},// next states for state 7
+ {-1, 8, -1, -1, -1, -1},// next states for state 8
+ };
+
+ /**
+ *
+ * Validate if a given string can be interpreted as a decimal number.
+ *
+ * Some examples:
+ * "0" => true
+ * " 0.1 " => true
+ * "abc" => false
+ * "1 a" => false
+ * "2e10" => true
+ * " -90e3 " => true
+ * " 1e" => false
+ * "e3" => false
+ * " 6e-1" => true
+ * " 99e2.5 " => false
+ * "53.5e93" => true
+ * " --6 " => false
+ * "-+3" => false
+ * "95a54e53" => false
+ *
+ * Note: It is intended for the problem statement to be ambiguous. You should gather all requirements
+ * up front before implementing one. However, here is a list of characters that can be in a valid decimal number:
+ *
+ * Numbers 0-9
+ * Exponent - "e"
+ * Positive/negative sign - "+"/"-"
+ * Decimal point - "."
+ * Of course, the context of these characters also matters in the input.
+ *
+ *
+ * @param s
+ * @return
+ */
+ public boolean isNumber(String s) {
+ int state = 0;
+ for (int i = 0; i < s.length(); i++) {
+ InputType inputType = InputType.INVALID;
+ if (Character.isSpaceChar(s.charAt(i))) {
+ inputType = InputType.SPACE;
+ } else if (s.charAt(i) == '+' || s.charAt(i) == '-') {
+ inputType = InputType.SIGN;
+ } else if (Character.isDigit(s.charAt(i))) {
+ inputType = InputType.DIGIT;
+ } else if (s.charAt(i) == '.') {
+ inputType = InputType.DOT;
+ } else if (s.charAt(i) == 'e' || s.charAt(i) == 'E') {
+ inputType = InputType.EXPONENT;
+ }
+ // Get next state from current state and input symbol
+ state = TRANSITION_TABLE[state][inputType.ordinal()];
+
+ // Invalid input
+ if (state == -1) {
+ return false;
+ }
+ }
+ // If the current state belongs to one of the accepting (final) states,
+ // then the number is valid
+ return state == 1 || state == 4 || state == 7 || state == 8;
+ }
+
+ private boolean isDigit(char charAt) {
+ return charAt >= '0' && charAt <= '9';
+ }
+
+ private boolean isSpace(char charAt) {
+ return charAt == ' ';
+ }
+}
diff --git a/[0066][Plus One]/[0066][Plus One].iml b/[0066][Plus One]/[0066][Plus One].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0066][Plus One]/[0066][Plus One].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0066][Plus One]/src/Solution.java b/[0066][Plus One]/src/Solution.java
new file mode 100644
index 0000000..efc7195
--- /dev/null
+++ b/[0066][Plus One]/src/Solution.java
@@ -0,0 +1,55 @@
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 19:32
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * ԭ
+ * Given a non-negative number represented as an array of digits, plus one to the number.
+ * The digits are stored such that the most significant digit is at the head of the list.
+ *
+ * Ŀ
+ * һʾһмһ
+ * ÿһλ洢һλϡ±ӴСʾλӵλλ
+ *
+ * ˼·
+ * ֱ⣬һλ־carryֵΪ1ʾ1λʼtmp = a[x] + carry
+ * a[x] = tmp%10carry = tmp/10carryΪ0һλٽвֱеλcarray
+ * Ϊ0˳carrayΪ0˵Ҫչһλ
+ *
+ *
+ * @param digits
+ * @return
+ */
+ public int[] plusOne(int[] digits) {
+
+ // λ־һλĽλ־
+ int carry = 1;
+ int tmp;
+ for (int i = digits.length - 1; i >= 0; i--) {
+ tmp = digits[i];
+ // 㵱ǰλֵ
+ digits[i] = (tmp + carry) % 10;
+ // µĽλ
+ carry = (tmp + carry) / 10;
+
+ // ûнλ˾Ϳ˳
+ if (carry == 0) {
+ break;
+ }
+ }
+
+ // һλ
+ if (carry == 1) {
+ int[] result = new int[digits.length + 1];
+ System.arraycopy(digits, 0, result, 1, digits.length);
+ result[0] = carry;
+ return result;
+ } else {
+ return digits;
+ }
+ }
+}
diff --git a/[0067][Add Binary]/[0067][Add Binary].iml b/[0067][Add Binary]/[0067][Add Binary].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0067][Add Binary]/[0067][Add Binary].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220067\343\200\221\343\200\220AddBinary\343\200\221/src/Solution.java" b/[0067][Add Binary]/src/Solution.java
similarity index 100%
rename from "\343\200\220067\343\200\221\343\200\220AddBinary\343\200\221/src/Solution.java"
rename to [0067][Add Binary]/src/Solution.java
diff --git a/[0069][Sqrt(x)]/[0069][Sqrt(x)].iml b/[0069][Sqrt(x)]/[0069][Sqrt(x)].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0069][Sqrt(x)]/[0069][Sqrt(x)].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0069][Sqrt(x)]/src/Solution.java b/[0069][Sqrt(x)]/src/Solution.java
new file mode 100644
index 0000000..d1cc9c3
--- /dev/null
+++ b/[0069][Sqrt(x)]/src/Solution.java
@@ -0,0 +1,87 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-23 15:09
+ **/
+public class Solution {
+ /**
+ *
+ * Implement int sqrt(int x).
+ *
+ * Compute and return the square root of x, where x is guaranteed to be a non-negative integer.
+ *
+ * Since the return type is an integer, the decimal digits are truncated and only the integer
+ * part of the result is returned.
+ *
+ * Example 1:
+ *
+ * Input: 4
+ * Output: 2
+ * Example 2:
+ *
+ * Input: 8
+ * Output: 2
+ * Explanation: The square root of 8 is 2.82842..., and since
+ * the decimal part is truncated, 2 is returned.
+ *
+ *
+ * @param x
+ * @return
+ */
+ public int mySqrt(int x) {
+ return mySqrt2(x);
+ }
+
+ /**
+ * 使用二分法
+ *
+ *
+ * @param n
+ * @return
+ */
+ public int climbStairs(int n) {
+
+ int result = 0;
+
+ // ֻһ
+ if (n == 1) {
+ result = 1;
+ }
+ // ֻ
+ else if (n == 2) {
+ result = 2;
+ }
+ // ¥ݽ2
+ else if (n > 2) {
+ // еĽⷨ
+ int[] ways = new int[n];
+
+ ways[0] = 1;
+ ways[1] = 2;
+
+ for (int i = 2; i < ways.length; i++) {
+ ways[i] = ways[i - 1] + ways[i - 2];
+ }
+
+ result = ways[ways.length - 1];
+ }
+
+ return result;
+ }
+}
diff --git a/[0071][Simplify Path]/[0071][Simplify Path].iml b/[0071][Simplify Path]/[0071][Simplify Path].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0071][Simplify Path]/[0071][Simplify Path].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0071][Simplify Path]/src/Solution.java b/[0071][Simplify Path]/src/Solution.java
new file mode 100644
index 0000000..c17fc59
--- /dev/null
+++ b/[0071][Simplify Path]/src/Solution.java
@@ -0,0 +1,32 @@
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-09-28 15:50
+ **/
+public class Solution {
+ public String simplifyPath(String path) {
+ String[] ss = path.split("/");
+ List result = new LinkedList<>();
+
+ for (String part : ss) {
+ if (".".equals(part)) {
+ continue;
+ } else if ("..".equals(part)) {
+ if (result.size() > 0) {
+ result.remove(result.size() - 1);
+ }
+ } else if (!"".equals(part.trim())) {
+ result.add(part);
+ }
+ }
+
+ StringBuilder builder = new StringBuilder();
+ for (String part : result) {
+ builder.append("/").append(part);
+ }
+
+ return builder.length() == 0 ? "/" : builder.toString();
+ }
+}
diff --git a/[0073][Set Matrix Zeroes]/[0073][Set Matrix Zeroes].iml b/[0073][Set Matrix Zeroes]/[0073][Set Matrix Zeroes].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0073][Set Matrix Zeroes]/[0073][Set Matrix Zeroes].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0073][Set Matrix Zeroes]/[0073][SetMatrixZeroes].iml b/[0073][Set Matrix Zeroes]/[0073][SetMatrixZeroes].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0073][Set Matrix Zeroes]/[0073][SetMatrixZeroes].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0073][Set Matrix Zeroes]/src/Solution.java b/[0073][Set Matrix Zeroes]/src/Solution.java
new file mode 100644
index 0000000..e0d6ab2
--- /dev/null
+++ b/[0073][Set Matrix Zeroes]/src/Solution.java
@@ -0,0 +1,58 @@
+/**
+ * Author:
+ * Date: 2015-07-25
+ * Time: 09:27
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ public void setZeroes(int[][] matrix) {
+ // һбõı־
+ boolean rowFlag = false;
+ // һбõı־
+ boolean colFlag = false;
+
+ for (int i = 0; i < matrix.length; i++) {
+ for (int j = 0; j < matrix[0].length; j++) {
+ if (matrix[i][j] == 0) {
+ // ǵһҪ
+ if (i == 0) {
+ rowFlag = true;
+ }
+
+ // ǵһҪ
+ if (j == 0) {
+ colFlag = true;
+ }
+
+ // ڱҪΪ0к
+ matrix[0][j] = 0;
+ matrix[i][0] = 0;
+ }
+ }
+ }
+
+ // ԵڶеڶпʼԪ0
+ for (int i = 1; i < matrix.length; i++) {
+ for (int j = 1; j < matrix[0].length; j++) {
+ if (matrix[i][0] == 0 || matrix[0][j] == 0) {
+ matrix[i][j] = 0;
+ }
+ }
+ }
+
+ // õһΪ0
+ if (rowFlag) {
+ for (int j = 0; j < matrix[0].length; j++) {
+ matrix[0][j] = 0;
+ }
+ }
+
+ // õһΪ0
+ if (colFlag) {
+ for (int i = 0; i < matrix.length; i++) {
+ matrix[i][0] = 0;
+ }
+ }
+
+ }
+}
diff --git a/[0074][Search A 2D Matrix]/[0074][Search A 2D Matrix].iml b/[0074][Search A 2D Matrix]/[0074][Search A 2D Matrix].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0074][Search A 2D Matrix]/[0074][Search A 2D Matrix].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0074][Search A 2D Matrix]/[0074][SearchA2DMatrix].iml b/[0074][Search A 2D Matrix]/[0074][SearchA2DMatrix].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0074][Search A 2D Matrix]/[0074][SearchA2DMatrix].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0074][Search A 2D Matrix]/src/Main.java b/[0074][Search A 2D Matrix]/src/Main.java
new file mode 100644
index 0000000..4206b6b
--- /dev/null
+++ b/[0074][Search A 2D Matrix]/src/Main.java
@@ -0,0 +1,16 @@
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-19 16:11
+ **/
+public class Main {
+ @Test
+ public void test1() {
+ Solution solution = new Solution();
+
+ int[][] matrix = {{1, 3}};
+ Assert.assertEquals(true, solution.searchMatrix(matrix, 3));
+ }
+}
diff --git a/[0074][Search A 2D Matrix]/src/Solution.java b/[0074][Search A 2D Matrix]/src/Solution.java
new file mode 100644
index 0000000..4942ee4
--- /dev/null
+++ b/[0074][Search A 2D Matrix]/src/Solution.java
@@ -0,0 +1,62 @@
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 19:36
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * ԭ
+ * 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,
+ * Consider the following matrix:Given target = 3, return true.
+ *
+ * [
+ * [1, 3, 5, 7],
+ * [10, 11, 16, 20],
+ * [23, 30, 34, 50]
+ * ]
+ *
+ * Ŀ
+ * һάʵһ㷨ھʵֿkھk
+ * ʣÿһÿһжźģÿһеĵһһеһ
+ *
+ * ˼·
+ * ⷨһö鿴㷨ҵڵУö㷨ڵСҵͷtruefalse
+ *
+ *
+ * @param matrix
+ * @param target
+ * @return
+ */
+ public boolean searchMatrix(int[][] matrix, int target) {
+
+ if (matrix == null || matrix.length == 0 || matrix[0].length == 0) {
+ return false;
+ }
+
+ int row = matrix.length;
+ int column = matrix[0].length;
+ int low = 0;
+ int high = row * column - 1;
+ int mid;
+
+ // ҽڵ
+ while (low <= high) {
+ mid = low + (high - low) / 2;
+ int value = matrix[mid / column][mid % column];
+ if (value == target) {
+ return true;
+ } else if (value < target) {
+ low = mid + 1;
+ } else {
+ high = mid - 1;
+ }
+ }
+
+ return false;
+ }
+}
diff --git a/[0074][Search A 2D Matrix]/src/Solution2.java b/[0074][Search A 2D Matrix]/src/Solution2.java
new file mode 100644
index 0000000..0a5ed46
--- /dev/null
+++ b/[0074][Search A 2D Matrix]/src/Solution2.java
@@ -0,0 +1,88 @@
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 19:36
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution2 {
+ /**
+ *
+ * ԭ
+ * 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,
+ * Consider the following matrix:Given target = 3, return true.
+ *
+ * [
+ * [1, 3, 5, 7],
+ * [10, 11, 16, 20],
+ * [23, 30, 34, 50]
+ * ]
+ *
+ * Ŀ
+ * һάʵһ㷨ھʵֿkھk
+ * ʣÿһÿһжźģÿһеĵһһеһ
+ *
+ * ˼·
+ * ⷨһö鿴㷨ҵڵУö㷨ڵСҵͷtruefalse
+ *
+ * ԭ
+ * 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 librarys sort function for this problem.
+ *
+ * Ŀ
+ * һ飬Ǻɫɫɫɫ죬ף
+ * ʹ012ֱ죬ף
+ * ע⣺ʹÿ⺯
+ *
+ * ˼·
+ * һֱ012ֵĴٽ鸳ֵ
+ *
+ *
+ * @param nums
+ */
+ public void sortColors(int[] nums) {
+
+ if (nums == null) {
+ return;
+ }
+
+ int[] count = new int[3];
+
+ for (int n : nums) {
+ count[n]++;
+ }
+
+ int start = 0;
+ int end = 0;
+ for (int i = 0; i < count.length; i++) {
+ if (i == 0) {
+ start = 0;
+ } else {
+ start += count[i - 1];
+ }
+ end += count[i];
+ for (int j = start; j < end; j++) {
+ nums[j] = i;
+ }
+ }
+
+ // ϶ĸĽ
+// for (int i = 0; i < count[0]; i++) {
+// nums[i] = 0;
+// }
+//
+// for (int i = count[0]; i < count[0] + count[1]; i++) {
+// nums[i] = 1;
+// }
+//
+// for (int i = count[0] + count[1]; i < nums.length; i++) {
+// nums[i] = 2;
+// }
+ }
+}
diff --git a/[0075][Sort Colors]/src/Solution2.java b/[0075][Sort Colors]/src/Solution2.java
new file mode 100644
index 0000000..ac7b270
--- /dev/null
+++ b/[0075][Sort Colors]/src/Solution2.java
@@ -0,0 +1,71 @@
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 19:37
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution2 {
+ /**
+ *
+ * ԭ
+ * 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 librarys sort function for this problem.
+ *
+ * Ŀ
+ * һ飬Ǻɫɫɫɫ죬ף
+ * ʹ012ֱ죬ף
+ * ע⣺ʹÿ⺯
+ *
+ * ˼·
+ * ɨ裬¼1ĸĺ͡ɨԵó1Ŀt2Ŀ(sum-t)/2
+ * Եó0ĿӸ012Ŀٶֵ
+ *
+ *
+ * @param A
+ */
+ public void sortColors(int[] A) {
+
+ if (A == null) {
+ return;
+ }
+
+ // ͳ1ĸ
+ int count = 0;
+
+ // ͳĺ
+ int sum = 0;
+
+ for (int i : A) {
+ if (i == 1) {
+ count++;
+ }
+
+ sum += i;
+ }
+
+ // 2Ŀ
+ sum = (sum - count) / 2;
+
+ // 1ʼֵλ
+ count = A.length - count - sum;
+
+ // 2ʼֵλ
+ sum = A.length - sum;
+
+ for (int i = 0; i < count; i++) {
+ A[i] = 0;
+ }
+
+ for (int i = count; i < sum; i++) {
+ A[i] = 1;
+ }
+
+ for (int i = sum; i < A.length; i++) {
+ A[i] = 2;
+ }
+ }
+}
diff --git a/[0077][Combinations]/[0077][Combinations].iml b/[0077][Combinations]/[0077][Combinations].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0077][Combinations]/[0077][Combinations].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0077][Combinations]/src/Main.java b/[0077][Combinations]/src/Main.java
new file mode 100644
index 0000000..e4021a1
--- /dev/null
+++ b/[0077][Combinations]/src/Main.java
@@ -0,0 +1,15 @@
+import org.junit.Test;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-19 19:04
+ **/
+public class Main {
+ @Test
+ public void test1() {
+ Solution solution = new Solution();
+
+ System.out.println(solution.combine(4, 2));
+ }
+
+}
diff --git a/[0077][Combinations]/src/Solution.java b/[0077][Combinations]/src/Solution.java
new file mode 100644
index 0000000..7d055e8
--- /dev/null
+++ b/[0077][Combinations]/src/Solution.java
@@ -0,0 +1,62 @@
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 19:39
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+
+ /**
+ *
+ * ԭ
+ * 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],
+ * ]
+ *
+ * Ŀ
+ * nk1-nkϡ
+ *
+ * ˼·
+ * ʹùŻ㷨
+ *
+ *
+ * @param n
+ * @param k
+ * @return
+ */
+ public List> combine(int n, int k) {
+ List> result = new LinkedList<>();
+ List current = new LinkedList<>();
+
+ dfs(1, n, k, current, result);
+
+ return result;
+ }
+
+ private void dfs(int start, int end, int k, List current, List> result) {
+ if (k == current.size()) {
+ result.add(new LinkedList<>(current));
+ return;
+ }
+
+ for (int i = start; i <= end; i++) {
+ current.add(i);
+ dfs(i + 1, end, k, current, result);
+ current.remove((Integer) i);
+ }
+ }
+
+
+}
diff --git a/[0077][Combinations]/src/Solution2.java b/[0077][Combinations]/src/Solution2.java
new file mode 100644
index 0000000..8e1fb2f
--- /dev/null
+++ b/[0077][Combinations]/src/Solution2.java
@@ -0,0 +1,80 @@
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 19:39
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution2 {
+ private List> result;
+ private List l;
+
+ /**
+ *
+ * ԭ
+ * 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],
+ * ]
+ *
+ * Ŀ
+ * nk1-nkϡ
+ *
+ * ˼·
+ * õݹη⣬롣
+ *
+ *
+ * @param n
+ * @param k
+ * @return
+ */
+ public List> combine(int n, int k) {
+ result = new LinkedList<>();
+
+ if (n > 0 && k > 0 && n >= k) {
+ l = new LinkedList<>();
+ combine(1, n, k);
+ }
+
+ return result;
+ }
+
+ /**
+ *
+ *
+ * @param start ѡʼλ
+ * @param end ѡĽλ
+ * @param num [start, end]ѡĿ
+ */
+ private void combine(int start, int end, int num) {
+
+ if (num == 0) {
+ List tmp = new ArrayList<>();
+ for (Integer i : l) {
+ tmp.add(i);
+ }
+
+ result.add(tmp);
+ return;
+ }
+
+ // һѡֵ
+ int endFirst = end - num + 1;
+ for (int i = start; i <= endFirst; i++) {
+ l.add(i);
+ combine(i + 1, end, num - 1);
+ l.remove(new Integer(i));
+ }
+ }
+}
diff --git a/[0078][Subsets]/[0078][Subsets].iml b/[0078][Subsets]/[0078][Subsets].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0078][Subsets]/[0078][Subsets].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0078][Subsets]/src/Main.java b/[0078][Subsets]/src/Main.java
new file mode 100644
index 0000000..9295524
--- /dev/null
+++ b/[0078][Subsets]/src/Main.java
@@ -0,0 +1,16 @@
+import org.junit.Test;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-19 16:27
+ **/
+public class Main {
+ @Test
+ public void test1() {
+ int[] nums = {1, 2, 3};
+
+ Solution solution = new Solution();
+
+ System.out.println(solution.subsets(nums));
+ }
+}
diff --git a/[0078][Subsets]/src/Solution.java b/[0078][Subsets]/src/Solution.java
new file mode 100644
index 0000000..9db75ec
--- /dev/null
+++ b/[0078][Subsets]/src/Solution.java
@@ -0,0 +1,71 @@
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 19:41
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+
+ /**
+ *
+ * ԭ
+ * Given a set of distinct integers, nums, 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 nums = [1,2,3], a solution is:
+ *
+ * [
+ * [3],
+ * [1],
+ * [2],
+ * [1,2,3],
+ * [1,3],
+ * [2,3],
+ * [1,2],
+ * []
+ * ]
+ *
+ * Ŀ
+ * һֵͬ飬Ӽ
+ *
+ * ˼·
+ * ȶеԪؽȻʹùŻ
+ *
+ * ԭ
+ * Given a set of distinct integers, nums, 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 nums = [1,2,3], a solution is:
+ *
+ * [
+ * [3],
+ * [1],
+ * [2],
+ * [1,2,3],
+ * [1,3],
+ * [2,3],
+ * [1,2],
+ * []
+ * ]
+ *
+ * Ŀ
+ * һֵͬ飬Ӽ
+ *
+ * ˼·
+ * ȶеԪؽȻõݹη⡣
+ *
+ *
+ * @param S
+ * @return
+ */
+ public List> subsets(int[] S) {
+ result = new LinkedList<>();
+
+ if (S != null) {
+ l = new ArrayList<>();
+
+ // S
+ quickSort(S, 0, S.length - 1);
+
+ set = S;
+ for (int i = 0; i <= S.length; i++) {
+ num = i;
+ subset(0);
+ }
+ }
+
+ // գӿ
+ set = null;
+ l = null;
+
+ return result;
+ }
+
+ /**
+ * ԪظnumӼ
+ *
+ * @param start ʣҪѡnumԪУһС±
+ */
+ public void subset(int start) {
+ if (num == 0) {
+ List tmp = new ArrayList<>();
+ for (Integer i : l) {
+ tmp.add(i);
+ }
+
+ result.add(tmp);
+ return;
+ }
+
+ int endFirst = set.length - num; // ʣҪѡnumԪУһ±
+ for (int i = start; i <= endFirst; i++) {
+ l.add(set[i]);
+ num--;
+ subset(i + 1);
+ num++;
+ l.remove(new Integer(set[i]));
+ }
+ }
+
+ private void quickSort(int[] arr, int lo, int hi) {
+ if (lo < hi) {
+ int mid = getMid(arr, lo, hi);
+ quickSort(arr, lo, mid - 1);
+ quickSort(arr, mid + 1, hi);
+ }
+ }
+
+ private int getMid(int[] arr, int lo, int hi) {
+ int tmp = arr[lo];
+ while (lo < hi) {
+ while (lo < hi && arr[hi] > tmp) {
+ hi--;
+ }
+ arr[lo] = arr[hi];
+
+ while (lo < hi && arr[lo] < tmp) {
+ lo++;
+ }
+
+ arr[hi] = arr[lo];
+ }
+
+ arr[lo] = tmp;
+ return lo;
+ }
+}
diff --git a/[0078][Subsets]/src/Solution3.java b/[0078][Subsets]/src/Solution3.java
new file mode 100644
index 0000000..4ad1f20
--- /dev/null
+++ b/[0078][Subsets]/src/Solution3.java
@@ -0,0 +1,86 @@
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 19:41
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution3 {
+
+ /**
+ *
+ * ԭ
+ * Given a set of distinct integers, nums, 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 nums = [1,2,3], a solution is:
+ *
+ * [
+ * [3],
+ * [1],
+ * [2],
+ * [1,2,3],
+ * [1,3],
+ * [2,3],
+ * [1,2],
+ * []
+ * ]
+ *
+ * Ŀ
+ * һֵͬ飬Ӽ
+ *
+ * ˼·
+ * ȶеԪؽȻõݹη⡣
+ *
+ *
+ * @param nums
+ * @return
+ */
+ public List> subsets(int[] nums) {
+ List> result = new LinkedList<>();
+ List curr = new LinkedList<>();
+ if (nums != null) {
+
+ // S
+ Arrays.sort(nums);
+ // iʾӼԪظ
+ for (int i = 0; i <= nums.length; i++) {
+ subset(nums, 0, i, result, curr);
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * ԪnӼ
+ *
+ * @param nums Ԫؼ
+ * @param idx ȡԪصʼλ
+ * @param n Ԫظ
+ * @param result
+ * @param curr ʱ
+ */
+ private void subset(int[] nums, int idx, int n, List> result, List curr) {
+
+ // Ѿĩβˣ˵һ
+ if (n == 0) {
+ result.add(new LinkedList<>(curr));
+ return;
+ }
+
+ // ûд꣬ݹ鴦һԪ
+ for (int i = idx; i < nums.length - n + 1; i++) {
+ curr.add(nums[i]);
+ subset(nums, i + 1, n - 1, result, curr);
+ curr.remove((Integer) nums[i]);
+ }
+ }
+
+
+}
diff --git a/[0079][Word Search]/[0079][Word Search].iml b/[0079][Word Search]/[0079][Word Search].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0079][Word Search]/[0079][Word Search].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0079][Word Search]/[0079][WordSearch].iml b/[0079][Word Search]/[0079][WordSearch].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0079][Word Search]/[0079][WordSearch].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0079][Word Search]/src/Main.java b/[0079][Word Search]/src/Main.java
new file mode 100644
index 0000000..52d523d
--- /dev/null
+++ b/[0079][Word Search]/src/Main.java
@@ -0,0 +1,14 @@
+/**
+ * Author: ������
+ * Date: 2015-06-20
+ * Time: 08:02
+ * Declaration: All Rights Reserved !!!
+ */
+public class Main {
+ public static void main(String[] args) {
+ Solution solution = new Solution();
+ System.out.println(solution.exist(new char[][]{
+ "abc".toCharArray(), "aed".toCharArray(), "afg".toCharArray()
+ }, "abcdefg"));
+ }
+}
diff --git a/[0079][Word Search]/src/Solution.java b/[0079][Word Search]/src/Solution.java
new file mode 100644
index 0000000..ad373b1
--- /dev/null
+++ b/[0079][Word Search]/src/Solution.java
@@ -0,0 +1,113 @@
+/**
+ * Author:
+ * Date: 2015-06-20
+ * Time: 07:19
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * 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.
+ *
+ * Ŀ⣺
+ * һboardַԴһ㿪ʼҵķʽߣÿֻһΣ
+ * һ·߹ַڸַôtrue
+ *
+ * ˼·
+ * ÿһΪ㣬ʹûݷ
+ *
+ *
+ * @param board
+ * @param word
+ * @return
+ */
+ public boolean exist(char[][] board, String word) {
+ // עǼٶIJǺϷ
+
+ // ʱǾʼֵĬϻΪfalse
+ boolean[][] visited = new boolean[board.length][board[0].length];
+
+ // ÿһλΪҵһ·ֹͣ
+ for (int i = 0; i < board.length; i++) {
+ for (int j = 0; j < board[0].length; j++) {
+ if (search(board, visited, i, j, word, new int[]{0})) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * @param board ַ
+ * @param visited ʱǾ
+ * @param row ʵк
+ * @param col ʵк
+ * @param word ƥַ
+ * @param idx ƥλãȡǸºֵԱ
+ * @return
+ */
+ private boolean search(char[][] board, boolean[][] visited, int row, int col, String word, int[] idx) {
+ // λõִijȣ˵Ѿҵҵƥ
+ if (idx[0] == word.length()) {
+ return true;
+ }
+
+ boolean hasPath = false;
+ // ǰλúϷ
+ if (check(board, visited, row, col, word, idx[0])) {
+ // λñʹ
+ visited[row][col] = true;
+ idx[0]++;
+ // ϣң£ĸ
+ hasPath = search(board, visited, row - 1, col, word, idx) //
+ || search(board, visited, row, col + 1, word, idx) //
+ || search(board, visited, row + 1, col, word, idx) //
+ || search(board, visited, row, col - 1, word, idx); //
+
+
+ // ûҵ·ͻ
+ if (!hasPath) {
+ visited[row][col] = false;
+ idx[0]--;
+ }
+ }
+
+ return hasPath;
+ }
+
+ /**
+ * жʵλǷϷ
+ *
+ * @param board ַ
+ * @param visited ʱǾ
+ * @param row ʵк
+ * @param col ʵк
+ * @param word ƥַ
+ * @param idx ƥλ
+ * @return
+ */
+
+ public boolean check(char[][] board, boolean[][] visited, int row, int col, String word, int idx) {
+ return row >= 0 && row < board.length // кźϷ
+ && col >= 0 && col < board[0].length // кźϷ
+ && !visited[row][col] // ûбʹ
+ && board[row][col] == word.charAt(idx); // ַ
+ }
+}
diff --git a/[0080][Remove Duplicates from Sorted Array II]/[0080][Remove Duplicates from Sorted Array II].iml b/[0080][Remove Duplicates from Sorted Array II]/[0080][Remove Duplicates from Sorted Array II].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0080][Remove Duplicates from Sorted Array II]/[0080][Remove Duplicates from Sorted Array II].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0080][Remove Duplicates from Sorted Array II]/src/Main.java b/[0080][Remove Duplicates from Sorted Array II]/src/Main.java
new file mode 100644
index 0000000..db6c257
--- /dev/null
+++ b/[0080][Remove Duplicates from Sorted Array II]/src/Main.java
@@ -0,0 +1,15 @@
+import java.util.Arrays;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-12 22:29
+ **/
+public class Main {
+ public static void main(String[] args) {
+ Solution solution = new Solution();
+ int[] nums = {1, 1, 1, 2, 2, 3};
+ int i = solution.removeDuplicates(nums);
+ System.out.println(i + ": " + Arrays.toString(nums));
+
+ }
+}
diff --git a/[0080][Remove Duplicates from Sorted Array II]/src/Solution.java b/[0080][Remove Duplicates from Sorted Array II]/src/Solution.java
new file mode 100644
index 0000000..ecd3151
--- /dev/null
+++ b/[0080][Remove Duplicates from Sorted Array II]/src/Solution.java
@@ -0,0 +1,24 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-12 22:29
+ **/
+public class Solution {
+ public int removeDuplicates(int[] nums) {
+ if (nums == null) {
+ return 0;
+ }
+ if (nums.length < 3) {
+ return nums.length;
+ }
+
+ int index = 2;
+ for (int i = 2; i < nums.length; i++) {
+ if (nums[index - 2] < nums[i]) {
+ nums[index] = nums[i];
+ index++;
+ }
+ }
+
+ return index;
+ }
+}
diff --git a/[0080][Remove Duplicates from Sorted Array II]/src/Solution2.java b/[0080][Remove Duplicates from Sorted Array II]/src/Solution2.java
new file mode 100644
index 0000000..449987a
--- /dev/null
+++ b/[0080][Remove Duplicates from Sorted Array II]/src/Solution2.java
@@ -0,0 +1,25 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-12 22:53
+ **/
+
+/**
+ * 删除重复出现的数字,使之最多出现两次
+ */
+public class Solution2 {
+ public int removeDuplicates(int[] nums) {
+ int i = 0;
+
+ // 处理每一个数字
+ for (int n : nums) {
+ // i < 2 处理前两个数字
+ // n > nums[i - 2]说明n不与nums[i - 2]重复,并且因为数组有序,那么必然n > nums[i - 2]
+ if (i < 2 || n > nums[i - 2]) {
+ nums[i++] = n;
+ }
+ }
+
+ return i;
+ }
+}
+
diff --git a/[0081][Search In Rotated Sorted Array II]/[0081][Search In Rotated Sorted Array II].iml b/[0081][Search In Rotated Sorted Array II]/[0081][Search In Rotated Sorted Array II].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0081][Search In Rotated Sorted Array II]/[0081][Search In Rotated Sorted Array II].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0081][Search In Rotated Sorted Array II]/src/Main.java b/[0081][Search In Rotated Sorted Array II]/src/Main.java
new file mode 100644
index 0000000..be94e08
--- /dev/null
+++ b/[0081][Search In Rotated Sorted Array II]/src/Main.java
@@ -0,0 +1,13 @@
+/**
+ * Author: 王俊超
+ * Date: 2015-06-21
+ * Time: 16:38
+ * Declaration: All Rights Reserved !!!
+ */
+public class Main {
+ public static void main(String[] args) {
+ Solution2 solution = new Solution2();
+ System.out.println(solution.search(new int[]{1, 1, 3, 1}, 3));
+ System.out.println(solution.search(new int[]{5, 1, 3}, 3));
+ }
+}
diff --git a/[0081][Search In Rotated Sorted Array II]/src/Solution.java b/[0081][Search In Rotated Sorted Array II]/src/Solution.java
new file mode 100644
index 0000000..1c71ba1
--- /dev/null
+++ b/[0081][Search In Rotated Sorted Array II]/src/Solution.java
@@ -0,0 +1,137 @@
+/**
+ * Author:
+ * Date: 2015-06-21
+ * Time: 14:46
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * 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
+ *
+ * Ŀ⣺
+ * "תֵ"ĺеֵظ
+ * дһȷһֵǷ
+ *
+ *
+ * @param nums
+ * @param target
+ * @return
+ */
+ public boolean search(int[] nums, int target) {
+ if (nums != null && nums.length > 0) {
+ // СԪضӦ±
+ int minIndex = findMinIndex(nums);
+
+ // ȫ
+ if (minIndex == 0) {
+ return binarySearch(nums, 0, nums.length - 1, target);
+ }
+ // ֲ, 4 5 6 7 8 9 0 1 2 3
+ else {
+ // úͺһһԪȣضӦ±
+ if (nums[nums.length - 1] == target) {
+ return true;
+ }
+ // targetںһ
+ else if (nums[nums.length - 1] > target) {
+ return binarySearch(nums, minIndex, nums.length - 1, target);
+ }
+ // targetǰһ
+ else {
+ return binarySearch(nums, 0, minIndex - 1, target);
+ }
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ *
+ *
+ * @param nums
+ * @param start ʼλ
+ * @param end λ
+ * @param target Ŀ
+ * @return trueҵfalseûҵ
+ */
+ public boolean binarySearch(int[] nums, int start, int end, int target) {
+
+ int mid;
+ while (start <= end) {
+ mid = start + ((end - start) >> 1);
+
+ if (nums[mid] == target) {
+ return true;
+ } else if (nums[mid] > target) {
+ end = mid - 1;
+ } else {
+ start = mid + 1;
+ }
+ }
+
+ return false;
+ }
+
+
+ public int findMinIndex(int[] nums) {
+ // У
+ if (nums == null || nums.length < 1) {
+ throw new IllegalArgumentException();
+ }
+
+ int lo = 0;
+ int hi = nums.length - 1;
+ int mid = 0;
+
+ // ųȫ
+ while (nums[lo] >= nums[hi]) {
+ // ֻԪأغһ
+ if (hi - lo == 1) {
+ mid = hi;
+ break;
+ }
+
+ mid = lo + ((hi - lo) >> 1);
+
+ if (nums[mid] == nums[lo] && nums[mid] == nums[hi]) {
+ // ֻܲ˳ܲlo++hi--ķʽ
+ // Ϊloǰһһ
+ // hiҲǺһĵһ
+ return sequenceSearchMinIndex(nums, lo, hi);
+ }
+
+ // midǰһ
+ if (nums[mid] >= nums[lo]) {
+ lo = mid;
+ }
+ // midںһ
+ else if (nums[mid] <= nums[hi]) {
+ hi = mid;
+ }
+ }
+
+ return mid;
+ }
+
+ /**
+ * ˳еСֵ±꣬nums鰴ijת
+ *
+ * @param nums
+ * @param start ʼλ
+ * @param end λ
+ * @return Сֵ±
+ */
+ public int sequenceSearchMinIndex(int[] nums, int start, int end) {
+ for (int i = start; i < end; i++) {
+ if (nums[i] > nums[i + 1]) {
+ return i + 1;
+ }
+ }
+ return start;
+ }
+}
diff --git a/[0081][Search In Rotated Sorted Array II]/src/Solution2.java b/[0081][Search In Rotated Sorted Array II]/src/Solution2.java
new file mode 100644
index 0000000..9e48b6c
--- /dev/null
+++ b/[0081][Search In Rotated Sorted Array II]/src/Solution2.java
@@ -0,0 +1,56 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-13 06:19
+ **/
+public class Solution2 {
+ /**
+ * 分析
+ * 允许重复元素,则上一题中如果A[mid]>=A[left], 那么[left,mid] 为递增序列的假设就不能成立了,比
+ * 如[1,3,1,1,1]。
+ * 如果A[mid]>=A[left] 不能确定递增,那就把它拆分成两个条件:
+ * • 若A[mid]>A[left],则区间[left,mid] 一定递增
+ * • 若A[mid]==A[left] 确定不了,那就l++,往下看一步即可。
+ *
+ * @param nums
+ * @param target
+ * @return
+ */
+ public boolean search(int[] nums, int target) {
+ if (nums == null || nums.length < 1) {
+ return false;
+ }
+
+ int left = 0;
+ int right = nums.length - 1;
+ int mid;
+ while (left <= right) {
+ mid = left + (right - left) / 2;
+ if (nums[mid] == target) {
+ return true;
+ }
+
+ // [left, mid]区间递增
+ if (nums[left] < nums[mid]) {
+ // target在[nums[left], nums[mid]]之间
+ if (nums[left] <= target && target < nums[mid]) {
+ right = mid - 1;
+ } else {
+ left = mid + 1;
+ }
+ } else if (nums[left] > nums[mid]) { // [mid, right]区间递增
+ // target在[nums[mid], nums[right]]之间
+ if (nums[mid] < target && target <= nums[right]) {
+ left = mid + 1;
+ } else {
+ right = mid - 1;
+ }
+ } else {
+ // 无法区分递增区间,向右移动一个位置
+ left++;
+ }
+ }
+
+
+ return false;
+ }
+}
diff --git a/[0082][Remove Duplicates From Sorted List II]/[0082][Remove Duplicates From Sorted List II].iml b/[0082][Remove Duplicates From Sorted List II]/[0082][Remove Duplicates From Sorted List II].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0082][Remove Duplicates From Sorted List II]/[0082][Remove Duplicates From Sorted List II].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0082][Remove Duplicates From Sorted List II]/[0082][RemoveDuplicatesFromSortedListII].iml b/[0082][Remove Duplicates From Sorted List II]/[0082][RemoveDuplicatesFromSortedListII].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0082][Remove Duplicates From Sorted List II]/[0082][RemoveDuplicatesFromSortedListII].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220082\343\200\221\343\200\220RemoveDuplicatesFromSortedListII\343\200\221/src/ListNode.java" b/[0082][Remove Duplicates From Sorted List II]/src/ListNode.java
similarity index 100%
rename from "\343\200\220082\343\200\221\343\200\220RemoveDuplicatesFromSortedListII\343\200\221/src/ListNode.java"
rename to [0082][Remove Duplicates From Sorted List II]/src/ListNode.java
diff --git a/[0082][Remove Duplicates From Sorted List II]/src/Solution.java b/[0082][Remove Duplicates From Sorted List II]/src/Solution.java
new file mode 100644
index 0000000..8e69cf6
--- /dev/null
+++ b/[0082][Remove Duplicates From Sorted List II]/src/Solution.java
@@ -0,0 +1,80 @@
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 19:43
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * ԭ
+ * 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.
+ *
+ * Ŀ
+ * һźĵɾظԪءֻֻһֵԪء
+ *
+ * ˼·
+ * һrootrootӵԭͷͷָ룬صԪؽɾ
+ *
+ *
+ * @param head
+ * @return
+ */
+ public ListNode deleteDuplicates(ListNode head) {
+
+ // ͷ
+ ListNode root = new ListNode(0);
+ root.next = head;
+ ListNode p = head;
+ // ¼һûظԪأʼָͷ
+ ListNode q = root;
+
+ // Ԫظ
+ int delta = 0;
+
+ while (p != null && p.next != null) {
+ // ͬ
+ if (p.val == p.next.val) {
+ delta++;
+ // ƶһ
+ p = p.next;
+ }
+ // 㲻ͬ
+ else {
+ // ֵΪp.valĽûظ
+ if (delta == 0) {
+ // ӵûиԪ
+ q.next = p;
+ // ָһδظԪ
+ q = p;
+ // ƶһ
+ p = p.next;
+ }
+ // ֵΪp.valĽظ
+ else {
+ // ƶһԪ
+ p = p.next;
+ // ȥظԪ
+ q.next = p.next;
+ // ԪظΪ0
+ delta = 0;
+ }
+ }
+ }
+
+ // һԪǸľȥ
+ if (delta != 0) {
+ q.next = null;
+ }
+ // ûظͿӵβ
+ else {
+ q.next = p;
+ }
+
+ return root.next;
+ }
+}
diff --git a/[0083][Remove Duplicates From Sorted List]/[0083][Remove Duplicates From Sorted List].iml b/[0083][Remove Duplicates From Sorted List]/[0083][Remove Duplicates From Sorted List].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0083][Remove Duplicates From Sorted List]/[0083][Remove Duplicates From Sorted List].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220083\343\200\221\343\200\220RemoveDuplicatesFromSortedList\343\200\221/src/ListNode.java" b/[0083][Remove Duplicates From Sorted List]/src/ListNode.java
similarity index 100%
rename from "\343\200\220083\343\200\221\343\200\220RemoveDuplicatesFromSortedList\343\200\221/src/ListNode.java"
rename to [0083][Remove Duplicates From Sorted List]/src/ListNode.java
diff --git a/[0083][Remove Duplicates From Sorted List]/src/Solution.java b/[0083][Remove Duplicates From Sorted List]/src/Solution.java
new file mode 100644
index 0000000..97b28f2
--- /dev/null
+++ b/[0083][Remove Duplicates From Sorted List]/src/Solution.java
@@ -0,0 +1,55 @@
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 19:45
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * ԭ
+ * 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.
+ *
+ * Ŀ
+ * һɾظԪأֻͬһ
+ *
+ * ˼·
+ * ʹһָָͷһ뵱ǰĽɾֱһͬģָָ
+ * µĽ㣬ظֱеĽ㶼ꡣ
+ *
+ *
+ * @param head
+ * @return
+ */
+ public ListNode deleteDuplicates(ListNode head) {
+ ListNode point;
+ // ָ½βʼʱֻһԪأͷ
+ ListNode tail = head;
+
+ if (head != null) {
+ // ָͷһԪ
+ point = head.next;
+ // δĩβ
+ while (point != null) {
+
+ // βڵ㲻ͬͽͬĽڵӵtailһλ
+ if (tail.val != point.val) {
+ tail.next = point;
+ // ָβ
+ tail = tail.next;
+ }
+
+ // ƶһλ
+ point = point.next;
+ }
+
+ // βָ
+ tail.next = null;
+ }
+
+ return head;
+ }
+}
diff --git a/[0084][Largest Rectangle in Histogram]/[0084][Largest Rectangle in Histogram].iml b/[0084][Largest Rectangle in Histogram]/[0084][Largest Rectangle in Histogram].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0084][Largest Rectangle in Histogram]/[0084][Largest Rectangle in Histogram].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0084][Largest Rectangle in Histogram]/src/Solution.java b/[0084][Largest Rectangle in Histogram]/src/Solution.java
new file mode 100644
index 0000000..72f516d
--- /dev/null
+++ b/[0084][Largest Rectangle in Histogram]/src/Solution.java
@@ -0,0 +1,71 @@
+import java.util.Arrays;
+import java.util.Deque;
+import java.util.LinkedList;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-17 15:29
+ **/
+public class Solution {
+ /**
+ *
+ * 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.
+ * -
+ * ==
+ * ==
+ * == -
+ * - ==--
+ * --==--
+ * Example:
+ * Input: [2,1,5,6,2,3]
+ * Output: 10
+ *
+ * https://leetcode.com/problems/largest-rectangle-in-histogram/
+ *
+ */
+ public int largestRectangleArea(int[] heights) {
+ if (heights == null || heights.length < 1) {
+ return 0;
+ }
+ // 记录位置
+ Deque stack = new LinkedList<>();
+
+ int i = 0;
+ int result = 0;
+
+ // 复制数组,最后位置补0,方便计算
+ int[] h = Arrays.copyOf(heights, heights.length + 1);
+
+ while (i < h.length) {
+ // 之前的元素小于等于当前元素
+ if (stack.isEmpty() || h[stack.peek()] <= h[i]) {
+ // 当前元素入栈
+ stack.push(i);
+ i++;
+ } else {
+ // 栈顶元素位置出栈
+ int t = stack.pop();
+ // 高度是height[t]
+ // stack.isEmpty(): 说明栈里的所有元素都比height[i]大,i位置之前有i个元素,序列就是[0 ,1, ..., i-1]
+ // 所求的长度就是i
+ // stack不为空,说明计算的位置是[stack.peek(), ..., i-1] 长度
+ result = Math.max(result, h[t] * (stack.isEmpty() ? i : i - stack.peek() - 1));
+ }
+ }
+
+
+ return result;
+
+ }
+}
diff --git a/[0086][Partition List]/[0086][Partition List].iml b/[0086][Partition List]/[0086][Partition List].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0086][Partition List]/[0086][Partition List].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0086][Partition List]/[0086][PartitionList].iml b/[0086][Partition List]/[0086][PartitionList].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0086][Partition List]/[0086][PartitionList].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0086][Partition List]/src/ListNode.java b/[0086][Partition List]/src/ListNode.java
new file mode 100644
index 0000000..63ee591
--- /dev/null
+++ b/[0086][Partition List]/src/ListNode.java
@@ -0,0 +1,14 @@
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 17:18
+ * Declaration: All Rights Reserved !!!
+ */
+public class ListNode {
+ int val;
+ ListNode next;
+
+ ListNode(int x) {
+ val = x;
+ }
+}
diff --git a/[0086][Partition List]/src/Solution.java b/[0086][Partition List]/src/Solution.java
new file mode 100644
index 0000000..c241a4b
--- /dev/null
+++ b/[0086][Partition List]/src/Solution.java
@@ -0,0 +1,64 @@
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 17:18
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * ԭ
+ * 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.
+ *
+ * For example,
+ * Given 1->4->3->2->5->2 and x = 3,
+ * return 1->2->2->4->3->5.
+ *
+ * Ŀ
+ * һһֵxֳСڵxIJֺʹxIJ֡ͬʱԭ˳
+ *
+ * ˼·
+ * abԭеÿ㣬СڵxĽaĩβǴھͷb
+ * ĩβbͷӵaĩβ
+ *
+ *
+ * @param head
+ * @param x
+ * @return
+ */
+ public ListNode partition(ListNode head, int x) {
+
+ ListNode le = new ListNode(0); // Сx
+ ListNode ge = new ListNode(0); // ڵx
+ ListNode t1 = le;
+ ListNode t2 = ge;
+ ListNode p = head;
+
+ while (p != null) {
+ if (p.val < x) {
+ t1.next = p;
+ t1 = p;
+ } else {
+ t2.next = p;
+ t2 = p;
+ }
+ p = p.next;
+ }
+
+ t2.next = null;
+
+ // пt1û
+ // t1ƶ˵Сڵ
+ if (t1 != le) {
+ t1.next = ge.next;
+ head = le.next;
+ } else {
+ head = ge.next;
+ }
+
+ return head;
+ }
+}
diff --git a/[0088][Merge Sorted Array]/[0088][Merge Sorted Array].iml b/[0088][Merge Sorted Array]/[0088][Merge Sorted Array].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0088][Merge Sorted Array]/[0088][Merge Sorted Array].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0088][Merge Sorted Array]/src/Solution.java b/[0088][Merge Sorted Array]/src/Solution.java
new file mode 100644
index 0000000..d25ea04
--- /dev/null
+++ b/[0088][Merge Sorted Array]/src/Solution.java
@@ -0,0 +1,51 @@
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 17:20
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * ԭ
+ * Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.
+ * Note:
+ * You may assume that nums1 has enough space (size that is greater or equal to m + n) to
+ * hold additional elements from nums2. The number of elements initialized in nums1 and
+ * nums2 are m and n respectively.
+ *
+ * Ŀ
+ * 飬кϲϲҲģϲnums1С
+ * nums1㹻Ŀռnums2
+ *
+ * ˼·
+ * еһλÿʼкϲнϴƶλãǸ
+ * λֵǰƶһλãٽͬIJֱеԪشꡣ
+ *
+ *
+ * @param arr
+ * @param m
+ * @param brr
+ * @param n
+ */
+ public void merge(int arr[], int m, int brr[], int n) {
+ int pa = m - 1;
+ int pb = n - 1;
+ int index = m + n - 1;
+
+ while (pa >= 0 && pb >= 0) {
+ if (arr[pa] >= brr[pb]) {
+ arr[index--] = arr[pa--];
+ } else {
+ arr[index--] = brr[pb--];
+ }
+ }
+
+ // ˵paһΪ0
+ while (pb >= 0) {
+ arr[index--] = brr[pb--];
+ }
+
+ // pa >= 0˵[0, pa]ûнжϣΪ[0, pa]arrУԲҪƶ
+ }
+}
diff --git a/[0089][Gray Code]/[0089][Gray Code].iml b/[0089][Gray Code]/[0089][Gray Code].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0089][Gray Code]/[0089][Gray Code].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0089][Gray Code]/src/Main.java b/[0089][Gray Code]/src/Main.java
new file mode 100644
index 0000000..6349221
--- /dev/null
+++ b/[0089][Gray Code]/src/Main.java
@@ -0,0 +1,18 @@
+import java.util.List;
+
+/**
+ * Author:
+ * Date: 2015-06-22
+ * Time: 13:27
+ * Declaration: All Rights Reserved !!!
+ */
+public class Main {
+ public static void main(String[] args) {
+ Solution solution = new Solution();
+ List result = solution.grayCode(2);
+
+ for (Integer i : result) {
+ System.out.printf("%s\n", Integer.toBinaryString(i));
+ }
+ }
+}
diff --git a/[0089][Gray Code]/src/Solution.java b/[0089][Gray Code]/src/Solution.java
new file mode 100644
index 0000000..4af4a3c
--- /dev/null
+++ b/[0089][Gray Code]/src/Solution.java
@@ -0,0 +1,82 @@
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Author:
+ * Date: 2015-06-22
+ * Time: 13:16
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * The nums[c] 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.
+ *
+ * Ŀ⣺
+ * nΪnĸ
+ *
+ * (Gray Code) Ķοhttp://en.wikipedia.org/wiki/Gray_code
+ * ȻתΪ룺g0 = b0; gi = bi^b(i-1)
+ * ȻλΪλθλΪĸλθλ
+ * λθλơ磬Ȼ1001תΪĹǣ
+ * λȻ1 λ1 ͵2 λ0 õ1Ϊĵ2 λ2 λ0 ͵3 λ
+ * 0 õ0Ϊĵ3 λ3 λ0 ͵4 λ1 õ1Ϊ
+ * 4 λգΪ1101
+ * תΪȻ룺b0 = g0; bi = gi^b(i-1)
+ * λΪȻλθλΪȻƸλθλ
+ * λθλơ磬1000 תΪȻĹǣ
+ * λ1ΪȻλȻȻĵ1 λ1 ĵ2 λ0
+ * 1ΪȻĵ2 λȻĵ2 λ1 ĵ3 λ0 õ1
+ * ΪȻĵ3 λȻĵ3 λ1 ĵ4 λ0 õ1Ϊ
+ * Ȼĵ4 λգȻΪ1111
+ * ѧʽn ĸn^(n/2)
+ * Ҫn صи롣
+ * 1ķѧʽԴ0 ~2^n-1 תΪ롣
+ * 2nصĸ룬Եݹشn - 1 صĸɡ
+ *
+ * ˼·
+ * ݹ
+ * ַڸǷʵõݹ¹죺
+ * 1λ
+ * (n+1)λеǰ2^nֵnλ֣˳дǰ0
+ * (n+1)λеĺ2^nֵnλ֣дǰ1
+ *
+ *
+ * @param n
+ * @return
+ */
+ public List grayCode(int n) {
+ List result = new LinkedList<>();
+ if (n >= 0) {
+ // ǰ벿
+ result.add(0);
+ // λֵ0ʱ
+ int t = 1;
+ // ÿһѭλi+1λĸ൱ڳΪi+1λĸǰ벿
+ for (int i = 0; i < n; i++) {
+ // ijΪi+1λĺ벿֣ǰ벿ɳΪiλĸ
+ for (int j = result.size() - 1; j >= 0; j--) {
+ result.add(result.get(j) ^ t);
+ }
+ // λ
+ t <<= 1;
+ }
+ }
+ return result;
+ }
+}
diff --git a/[0090][Subsets II]/[0090][Subsets II].iml b/[0090][Subsets II]/[0090][Subsets II].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0090][Subsets II]/[0090][Subsets II].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0090][Subsets II]/src/Main.java b/[0090][Subsets II]/src/Main.java
new file mode 100644
index 0000000..4af3b37
--- /dev/null
+++ b/[0090][Subsets II]/src/Main.java
@@ -0,0 +1,21 @@
+import org.junit.Test;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-19 17:33
+ **/
+public class Main {
+ @Test
+ public void test1() {
+ Solution solution = new Solution();
+ int[] nums = {1, 2, 2};
+ System.out.println(solution.subsetsWithDup(nums));
+ }
+
+ @Test
+ public void test2() {
+ Solution solution = new Solution();
+ int[] nums = {1, 2, 2};
+ System.out.println(solution.subsetsWithDup(nums));
+ }
+}
diff --git a/[0090][Subsets II]/src/Solution.java b/[0090][Subsets II]/src/Solution.java
new file mode 100644
index 0000000..7593613
--- /dev/null
+++ b/[0090][Subsets II]/src/Solution.java
@@ -0,0 +1,66 @@
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-19 16:43
+ **/
+public class Solution {
+
+ /**
+ *
+ * Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set).
+ *
+ * Note: The solution set must not contain duplicate subsets.
+ *
+ * Example:
+ *
+ * Input: [1,2,2]
+ * Output:
+ * [
+ * [2],
+ * [1],
+ * [1,2,2],
+ * [2,2],
+ * [1,2],
+ * []
+ * ]
+ *
+ *
+ * @param nums
+ * @return
+ */
+ public List> subsetsWithDup(int[] nums) {
+ List> result = new LinkedList<>();
+ List curr = new LinkedList<>();
+ if (nums != null) {
+ // 对S进行排序处理
+ Arrays.sort(nums);
+ dfs(nums, 0, result, curr);
+ }
+
+ return result;
+ }
+
+ private void dfs(int[] nums, int index, List> result, List curr) {
+
+
+ // 添加到结果中,说明有一种新的结产生
+ result.add(new LinkedList<>(curr));
+
+
+ for (int j = index; j < nums.length; j++) {
+ // 在当前可选择的范围内,相同的只能选择一次
+ if (j > index && nums[j] == nums[j - 1]) {
+ continue;
+ }
+
+ // 添加元素
+ curr.add(nums[j]);
+ dfs(nums, j + 1, result, curr);
+ // 还原
+ curr.remove((Integer) nums[j]);
+ }
+ }
+}
diff --git a/[0091][Decode Ways]/[0091][Decode Ways].iml b/[0091][Decode Ways]/[0091][Decode Ways].iml
new file mode 100644
index 0000000..c8cb479
--- /dev/null
+++ b/[0091][Decode Ways]/[0091][Decode Ways].iml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0091][Decode Ways]/src/Main.java b/[0091][Decode Ways]/src/Main.java
new file mode 100644
index 0000000..c12f921
--- /dev/null
+++ b/[0091][Decode Ways]/src/Main.java
@@ -0,0 +1,15 @@
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-25 19:22
+ **/
+public class Main {
+ @Test
+ public void test1() {
+ Solution solution = new Solution();
+
+ Assert.assertEquals(3, solution.numDecodings("226"));
+ }
+}
diff --git a/[0091][Decode Ways]/src/Solution.java b/[0091][Decode Ways]/src/Solution.java
new file mode 100644
index 0000000..7fc1faa
--- /dev/null
+++ b/[0091][Decode Ways]/src/Solution.java
@@ -0,0 +1,51 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-25 19:17
+ **/
+public class Solution {
+ /**
+ * A message containing letters from A-Z is being encoded to numbers using the following mapping:
+ *
+ * 'A' -> 1
+ * 'B' -> 2
+ * ...
+ * 'Z' -> 26
+ * Given a non-empty string containing only digits, determine the total number of ways to decode it.
+ *
+ * Example 1:
+ *
+ * Input: "12"
+ * Output: 2
+ * Explanation: It could be decoded as "AB" (1 2) or "L" (12).
+ * Example 2:
+ *
+ * Input: "226"
+ * Output: 3
+ * Explanation: It could be decoded as "BZ" (2 26), "VF" (22 6), or "BBF" (2 2 6).
+ *
+ * @param s
+ * @return
+ */
+ public int numDecodings(String s) {
+ if (s.isEmpty() || s.charAt(0) == '0') {
+ return 0;
+ }
+ int prev = 0;
+ int cur = 1;
+ // 长度为n 的字符串,有n+1 个阶梯
+ for (int i = 1; i <= s.length(); ++i) {
+ if (s.charAt(i - 1) == '0') {
+ cur = 0;
+ }
+ if (i < 2 || !(s.charAt(i - 2) == '1' || (s.charAt(i - 2) == '2' && s.charAt(i - 1) <= '6'))) {
+ prev = 0;
+ }
+
+ int tmp = cur;
+ cur = prev + cur;
+ prev = tmp;
+ }
+ return cur;
+ }
+
+}
\ No newline at end of file
diff --git a/[0091][Decode Ways]/src/Solution2.java b/[0091][Decode Ways]/src/Solution2.java
new file mode 100644
index 0000000..3c3ccdf
--- /dev/null
+++ b/[0091][Decode Ways]/src/Solution2.java
@@ -0,0 +1,96 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-25 19:17
+ **/
+public class Solution2 {
+ /**
+ * A message containing letters from A-Z is being encoded to numbers using the following mapping:
+ *
+ * 'A' -> 1
+ * 'B' -> 2
+ * ...
+ * 'Z' -> 26
+ * Given a non-empty string containing only digits, determine the total number of ways to decode it.
+ *
+ * Example 1:
+ *
+ * Input: "12"
+ * Output: 2
+ * Explanation: It could be decoded as "AB" (1 2) or "L" (12).
+ * Example 2:
+ *
+ * Input: "226"
+ * Output: 3
+ * Explanation: It could be decoded as "BZ" (2 26), "VF" (22 6), or "BBF" (2 2 6).
+ *
+ * @param s
+ * @return
+ */
+ public int numDecodings(String s) {
+ int n = s.length();
+ if (n == 0) {
+ return 0;
+ }
+
+ int[] memo = new int[n + 1];
+ memo[n] = 1;
+ memo[n - 1] = s.charAt(n - 1) != '0' ? 1 : 0;
+
+ for (int i = n - 2; i >= 0; i--) {
+ if (s.charAt(i) == '0') {
+ continue;
+ } else {
+ memo[i] = (Integer.parseInt(s.substring(i, i + 2)) <= 26) ? memo[i + 1] + memo[i + 2] : memo[i + 1];
+ }
+ }
+ return memo[0];
+ }
+
+ // 太慢
+ public int numDecodings2(String s) {
+ // 如是不是纯数字的字符串就返回0
+ if (s == null || !s.matches("^\\d+$")) {
+ return 0;
+ }
+
+ // 第一位以0开头,没有可以匹配的
+ if (s.charAt(0) == '0') {
+ return 0;
+ }
+
+ // 如果只一位
+ if (s.length() == 1) {
+ return handle(s);
+ }
+
+ // 如果有两位
+ if (s.length() == 2) {
+ int v = Integer.parseInt(s);
+ // 如果拆成个一位的有几种可能
+ int r = handle(s.substring(s.length() - 1));
+
+ // 如是两位组成一个,1~26才可以算一种可能
+ if (v > 0 && v < 27) {
+ r++;
+ }
+ return r;
+ }
+
+ // 字符串长度大于3,f(s)=(0 or 1)*f(s-1) + (0 or 1)*f(s-2)
+ // 对于f(s-1),如果首位是0,取0
+ // 对于f(s-2),如果首位是0或者首两位的值小于1或者大于26,取0
+
+ int v = numDecodings(s.substring(1));
+ int t = Integer.parseInt(s.substring(0, 2));
+
+ if (t > 0 && t < 27) {
+ v += numDecodings(s.substring(2));
+ }
+
+ return v;
+ }
+
+ private int handle(String s) {
+ return Integer.parseInt(s) == 0 ? 0 : 1;
+ }
+}
\ No newline at end of file
diff --git a/[0092][Reverse Linked List II]/[0092][Reverse Linked List II].iml b/[0092][Reverse Linked List II]/[0092][Reverse Linked List II].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0092][Reverse Linked List II]/[0092][Reverse Linked List II].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0092][Reverse Linked List II]/src/ListNode.java b/[0092][Reverse Linked List II]/src/ListNode.java
new file mode 100644
index 0000000..8f1581b
--- /dev/null
+++ b/[0092][Reverse Linked List II]/src/ListNode.java
@@ -0,0 +1,14 @@
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 17:23
+ * Declaration: All Rights Reserved !!!
+ */
+public class ListNode {
+ int val;
+ ListNode next;
+
+ ListNode(int x) {
+ val = x;
+ }
+}
diff --git a/[0092][Reverse Linked List II]/src/Solution.java b/[0092][Reverse Linked List II]/src/Solution.java
new file mode 100644
index 0000000..e1a7587
--- /dev/null
+++ b/[0092][Reverse Linked List II]/src/Solution.java
@@ -0,0 +1,70 @@
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 17:23
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * ԭ
+ * 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.
+ * Note:
+ * Given m, n satisfy the following condition:
+ * 1 m n length of list.
+ *
+ * Ŀ
+ * һmn֮Ԫؽת
+ * nmǺϷģʹԭطнʹóռ䣩
+ *
+ * ˼·
+ * ҵһҪתԪصǰprevټҪзתԪظԪؽͷ巨
+ * prev棬ͬʱϿ
+ *
+ *
+ * @param head
+ * @param m
+ * @param n
+ * @return
+ */
+ public ListNode reverseBetween(ListNode head, int m, int n) {
+
+ ListNode root = new ListNode(0);
+ ListNode p = root;
+ root.next = head;
+
+ for (int i = 1; i < m && p != null; i++) {
+ p = p.next;
+ }
+
+ if (p != null) {
+ ListNode q = p.next;
+ ListNode r;
+
+ // mΪΪǴӵһʼ
+ if (m < 1) {
+ m = 1;
+ }
+
+ // nΪҪĽĿ
+ n = n - m + 1;
+ // ʱҪʹβ巨βĸΪn-1
+ for (int i = 1; i < n && q.next != null; i++) {
+ // ΪҪβĽ
+ r = q.next;
+
+ // qĺβ
+ q.next = r.next;
+ r.next = p.next;
+ p.next = r;
+ }
+
+ head = root.next;
+ }
+
+ return head;
+ }
+}
diff --git a/[0093][Restore IP Addresses]/[0093][Restore IP Addresses].iml b/[0093][Restore IP Addresses]/[0093][Restore IP Addresses].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0093][Restore IP Addresses]/[0093][Restore IP Addresses].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0093][Restore IP Addresses]/src/Solution.java b/[0093][Restore IP Addresses]/src/Solution.java
new file mode 100644
index 0000000..ad998bc
--- /dev/null
+++ b/[0093][Restore IP Addresses]/src/Solution.java
@@ -0,0 +1,32 @@
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-23 06:48
+ **/
+public class Solution {
+ public List restoreIpAddresses(String s) {
+ List result = new ArrayList<>();
+ doRestore(result, "", s, 0);
+ return result;
+ }
+
+ private void doRestore(List result, String path, String s, int k) {
+ if (s.isEmpty() || k == 4) {
+ if (s.isEmpty() && k == 4) {
+ result.add(path.substring(1));
+ }
+ return;
+ }
+
+ int length = (s.charAt(0) == '0' ? 1 : 3); // 避免前导0
+ length = length < s.length() ? length : s.length();
+ for (int i = 1; i <= length; i++) {
+ String part = s.substring(0, i);
+ if (Integer.valueOf(part) <= 255) {
+ doRestore(result, path + "." + part, s.substring(i), k + 1);
+ }
+ }
+ }
+}
diff --git a/[0094][Binary Tree Inorder Traversal]/[0094][Binary Tree Inorder Traversal].iml b/[0094][Binary Tree Inorder Traversal]/[0094][Binary Tree Inorder Traversal].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0094][Binary Tree Inorder Traversal]/[0094][Binary Tree Inorder Traversal].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0094][Binary Tree Inorder Traversal]/[0094][BinaryTree InorderTraversal].iml b/[0094][Binary Tree Inorder Traversal]/[0094][BinaryTree InorderTraversal].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0094][Binary Tree Inorder Traversal]/[0094][BinaryTree InorderTraversal].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221/src/Main.java" b/[0094][Binary Tree Inorder Traversal]/src/Main.java
similarity index 100%
rename from "\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221/src/Main.java"
rename to [0094][Binary Tree Inorder Traversal]/src/Main.java
diff --git a/[0094][Binary Tree Inorder Traversal]/src/Solution.java b/[0094][Binary Tree Inorder Traversal]/src/Solution.java
new file mode 100644
index 0000000..5af0019
--- /dev/null
+++ b/[0094][Binary Tree Inorder Traversal]/src/Solution.java
@@ -0,0 +1,38 @@
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Author:
+ * Date: 2015-07-25
+ * Time: 18:19
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ public List inorderTraversal(TreeNode root) {
+
+ List result = new LinkedList<>();
+ LinkedList stack = new LinkedList<>();
+
+ // ڼ¼ǰҪԪ
+ TreeNode node = root;
+
+ // node1root㣬2Һ
+ while (node != null || !stack.isEmpty()) {
+ // ջ
+ while (node != null) {
+ stack.addLast(node);
+ node = node.left;
+ }
+
+ // ʱջеջԪһûӵ
+ if (!stack.isEmpty()) {
+ // ɾջԪ
+ node = stack.removeLast();
+ result.add(node.val);
+ // ָҺ
+ node = node.right;
+ }
+ }
+ return result;
+ }
+}
diff --git "a/\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221/src/TreeNode.java" b/[0094][Binary Tree Inorder Traversal]/src/TreeNode.java
similarity index 100%
rename from "\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221/src/TreeNode.java"
rename to [0094][Binary Tree Inorder Traversal]/src/TreeNode.java
diff --git a/[0095][Unique Binary Search Trees II]/[0095][Unique Binary Search Trees II].iml b/[0095][Unique Binary Search Trees II]/[0095][Unique Binary Search Trees II].iml
new file mode 100644
index 0000000..c8cb479
--- /dev/null
+++ b/[0095][Unique Binary Search Trees II]/[0095][Unique Binary Search Trees II].iml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0095][Unique Binary Search Trees II]/src/Main.java b/[0095][Unique Binary Search Trees II]/src/Main.java
new file mode 100644
index 0000000..de39bd8
--- /dev/null
+++ b/[0095][Unique Binary Search Trees II]/src/Main.java
@@ -0,0 +1,44 @@
+import org.junit.Test;
+
+import java.util.List;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-28 16:29
+ **/
+public class Main {
+ @Test
+ public void test1() {
+ Solution solution = new Solution();
+
+ print(solution.generateTrees(3));
+ }
+
+ private void print(List generateTrees) {
+ for (TreeNode node : generateTrees) {
+ print(node);
+ System.out.println();
+ }
+ }
+
+ private void print(TreeNode node) {
+ if (node != null) {
+ System.out.print(node + ", ");
+
+ if (node.left == null && node.right == null) {
+ return;
+ }
+
+ if (node.left == null) {
+ System.out.print("null, ");
+ } else {
+ print(node.left);
+ }
+ if (node.right == null) {
+ System.out.print("null, ");
+ } else {
+ print(node.right);
+ }
+ }
+ }
+}
diff --git a/[0095][Unique Binary Search Trees II]/src/Solution.java b/[0095][Unique Binary Search Trees II]/src/Solution.java
new file mode 100644
index 0000000..d3ca6f6
--- /dev/null
+++ b/[0095][Unique Binary Search Trees II]/src/Solution.java
@@ -0,0 +1,48 @@
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-28 16:14
+ **/
+public class Solution {
+ public List generateTrees(int n) {
+
+ if (n == 0) {
+ return new LinkedList<>();
+ }
+
+ return trees(1, n);
+ }
+
+ private List trees(int start, int end) {
+ List result = new LinkedList<>();
+ if (start == end) {
+ result.add(new TreeNode(start));
+ return result;
+ }
+
+ if (start > end) {
+ result.add(null);
+ return result;
+ }
+
+ for (int i = start; i <= end; i++) {
+ List left = trees(start, i - 1);
+ List right = trees(i + 1, end);
+
+ for (TreeNode l : left) {
+ for (TreeNode r : right) {
+ TreeNode root = new TreeNode(i);
+ root.left = l;
+ root.right = r;
+ result.add(root);
+ }
+ }
+ }
+
+ return result;
+ }
+
+
+}
diff --git a/[0095][Unique Binary Search Trees II]/src/TreeNode.java b/[0095][Unique Binary Search Trees II]/src/TreeNode.java
new file mode 100644
index 0000000..2878b91
--- /dev/null
+++ b/[0095][Unique Binary Search Trees II]/src/TreeNode.java
@@ -0,0 +1,18 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-28 16:14
+ **/
+public class TreeNode {
+ int val;
+ TreeNode left;
+ TreeNode right;
+
+ TreeNode(int x) {
+ val = x;
+ }
+
+ @Override
+ public String toString() {
+ return val + "";
+ }
+}
diff --git a/[0096][Unique Binary Search Trees]/[0096][Unique Binary Search Trees].iml b/[0096][Unique Binary Search Trees]/[0096][Unique Binary Search Trees].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0096][Unique Binary Search Trees]/[0096][Unique Binary Search Trees].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220096\343\200\221\343\200\220UniqueBinarySearchTrees\343\200\221/src/Main.java" b/[0096][Unique Binary Search Trees]/src/Main.java
similarity index 100%
rename from "\343\200\220096\343\200\221\343\200\220UniqueBinarySearchTrees\343\200\221/src/Main.java"
rename to [0096][Unique Binary Search Trees]/src/Main.java
diff --git a/[0096][Unique Binary Search Trees]/src/Solution.java b/[0096][Unique Binary Search Trees]/src/Solution.java
new file mode 100644
index 0000000..ab0f547
--- /dev/null
+++ b/[0096][Unique Binary Search Trees]/src/Solution.java
@@ -0,0 +1,49 @@
+/**
+ * Author:
+ * Date: 2015-06-18
+ * Time: 17:36
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ * 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.
+ * 1 3 3 2 1
+ * \ / / / \ \
+ * 3 2 1 1 3 2
+ * / / \ \
+ * 2 1 2 3
+ *
+ * ƹʽ
+ * f(0) = 1
+ * f(1) = 1
+ * f(i) = f(0)f(i-1) + f(1)f(i-1) + ... + f(i-1)f(0)
+ *
+ * @param n
+ * @return
+ */
+ public int numTrees(int n) {
+
+ if (n <= 0) {
+ return 1;
+ } else if (n == 1) {
+ return 1;
+ }
+
+ int[] result = new int[n + 1];
+ result[0] = 1;
+ result[1] = 1;
+
+
+ // f(2)...f(n)
+ for (int i = 2; i <= n; i++) {
+ for (int j = 1; j <= i; j++) {
+ result[i] += result[j - 1] * result[i - j];
+ }
+
+ }
+ return result[n];
+ }
+}
diff --git a/[0096][Unique Binary Search Trees]/src/Solution2.java b/[0096][Unique Binary Search Trees]/src/Solution2.java
new file mode 100644
index 0000000..31624d1
--- /dev/null
+++ b/[0096][Unique Binary Search Trees]/src/Solution2.java
@@ -0,0 +1,51 @@
+/**
+ * Author:
+ * Date: 2015-06-18
+ * Time: 17:36
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution2 {
+ /**
+ * 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.
+ * 1 3 3 2 1
+ * \ / / / \ \
+ * 3 2 1 1 3 2
+ * / / \ \
+ * 2 1 2 3
+ *
+ * f(n) = 2*f(n-1) + f(1)*f(n-2) + f(2)f(n-3) + f(3)f(n-4) + ... +f(n-2)*f(1)
+ *
+ * @param n
+ * @return
+ */
+ public int numTrees(int n) {
+
+ if (n <= 0) {
+ return 1;
+ } else if (n == 1) {
+ return 1;
+ }
+
+ int[] result = new int[n + 1];
+ result[0] = 0;
+ result[1] = 1;
+
+
+ // f(2)...f(n)
+ for (int i = 2; i <= n; i++) {
+ // f(i)
+ result[i] = 2 * result[i - 1];
+ for (int j = 1; j <= i - 1; j++) {
+ result[i] += result[j] * result[i - 1 - j];
+ }
+
+ }
+ return result[n];
+ }
+}
diff --git a/[0098][Validate Binary Search Tree]/[0098][Validate Binary Search Tree].iml b/[0098][Validate Binary Search Tree]/[0098][Validate Binary Search Tree].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0098][Validate Binary Search Tree]/[0098][Validate Binary Search Tree].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0098][Validate Binary Search Tree]/[0098][ValidateBinarySearchTree].iml b/[0098][Validate Binary Search Tree]/[0098][ValidateBinarySearchTree].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0098][Validate Binary Search Tree]/[0098][ValidateBinarySearchTree].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220098\343\200\221\343\200\220ValidateBinarySearchTree\343\200\221/src/Solution.java" b/[0098][Validate Binary Search Tree]/src/Solution.java
similarity index 100%
rename from "\343\200\220098\343\200\221\343\200\220ValidateBinarySearchTree\343\200\221/src/Solution.java"
rename to [0098][Validate Binary Search Tree]/src/Solution.java
diff --git "a/\343\200\220098\343\200\221\343\200\220ValidateBinarySearchTree\343\200\221/src/TreeNode.java" b/[0098][Validate Binary Search Tree]/src/TreeNode.java
similarity index 100%
rename from "\343\200\220098\343\200\221\343\200\220ValidateBinarySearchTree\343\200\221/src/TreeNode.java"
rename to [0098][Validate Binary Search Tree]/src/TreeNode.java
diff --git a/[0100][Same Tree]/[0100][Same Tree].iml b/[0100][Same Tree]/[0100][Same Tree].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0100][Same Tree]/[0100][Same Tree].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0100][Same Tree]/[0100][SameTree].iml b/[0100][Same Tree]/[0100][SameTree].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0100][Same Tree]/[0100][SameTree].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220100\343\200\221\343\200\220SameTree\343\200\221/src/Solution.java" b/[0100][Same Tree]/src/Solution.java
similarity index 100%
rename from "\343\200\220100\343\200\221\343\200\220SameTree\343\200\221/src/Solution.java"
rename to [0100][Same Tree]/src/Solution.java
diff --git a/[0100][Same Tree]/src/TreeNode.java b/[0100][Same Tree]/src/TreeNode.java
new file mode 100644
index 0000000..a4b81b6
--- /dev/null
+++ b/[0100][Same Tree]/src/TreeNode.java
@@ -0,0 +1,15 @@
+/**
+ * Author: ������
+ * Date: 2015-08-21
+ * Time: 18:40
+ * Declaration: All Rights Reserved !!!
+ */
+public class TreeNode {
+ int val;
+ TreeNode left;
+ TreeNode right;
+
+ TreeNode(int x) {
+ val = x;
+ }
+}
diff --git a/[0101][Symmetric Tree]/[0101][Symmetric Tree].iml b/[0101][Symmetric Tree]/[0101][Symmetric Tree].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0101][Symmetric Tree]/[0101][Symmetric Tree].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0101][Symmetric Tree]/[0101][SymmetricTree].iml b/[0101][Symmetric Tree]/[0101][SymmetricTree].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0101][Symmetric Tree]/[0101][SymmetricTree].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220101\343\200\221\343\200\220SymmetricTree\343\200\221/src/Solution.java" b/[0101][Symmetric Tree]/src/Solution.java
similarity index 100%
rename from "\343\200\220101\343\200\221\343\200\220SymmetricTree\343\200\221/src/Solution.java"
rename to [0101][Symmetric Tree]/src/Solution.java
diff --git "a/\343\200\220101\343\200\221\343\200\220SymmetricTree\343\200\221/src/TreeNode.java" b/[0101][Symmetric Tree]/src/TreeNode.java
similarity index 100%
rename from "\343\200\220101\343\200\221\343\200\220SymmetricTree\343\200\221/src/TreeNode.java"
rename to [0101][Symmetric Tree]/src/TreeNode.java
diff --git a/[0102][Binary Tree Level Order Traversal]/[0102][Binary Tree Level Order Traversal].iml b/[0102][Binary Tree Level Order Traversal]/[0102][Binary Tree Level Order Traversal].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0102][Binary Tree Level Order Traversal]/[0102][Binary Tree Level Order Traversal].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0102][Binary Tree Level Order Traversal]/[0102][BinaryTreeLevelOrderTraversal].iml b/[0102][Binary Tree Level Order Traversal]/[0102][BinaryTreeLevelOrderTraversal].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0102][Binary Tree Level Order Traversal]/[0102][BinaryTreeLevelOrderTraversal].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220102\343\200\221\343\200\220BinaryTreeLevelOrderTraversal\343\200\221/src/Solution.java" b/[0102][Binary Tree Level Order Traversal]/src/Solution.java
similarity index 100%
rename from "\343\200\220102\343\200\221\343\200\220BinaryTreeLevelOrderTraversal\343\200\221/src/Solution.java"
rename to [0102][Binary Tree Level Order Traversal]/src/Solution.java
diff --git "a/\343\200\220102\343\200\221\343\200\220BinaryTreeLevelOrderTraversal\343\200\221/src/TreeNode.java" b/[0102][Binary Tree Level Order Traversal]/src/TreeNode.java
similarity index 100%
rename from "\343\200\220102\343\200\221\343\200\220BinaryTreeLevelOrderTraversal\343\200\221/src/TreeNode.java"
rename to [0102][Binary Tree Level Order Traversal]/src/TreeNode.java
diff --git a/[0103][Binary Tree Zigzag LevelOrder Traversal]/[0103][Binary Tree Zigzag LevelOrder Traversal].iml b/[0103][Binary Tree Zigzag LevelOrder Traversal]/[0103][Binary Tree Zigzag LevelOrder Traversal].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0103][Binary Tree Zigzag LevelOrder Traversal]/[0103][Binary Tree Zigzag LevelOrder Traversal].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0103][Binary Tree Zigzag LevelOrder Traversal]/[0103][BinaryTreeZigzagLevelOrderTraversal].iml b/[0103][Binary Tree Zigzag LevelOrder Traversal]/[0103][BinaryTreeZigzagLevelOrderTraversal].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0103][Binary Tree Zigzag LevelOrder Traversal]/[0103][BinaryTreeZigzagLevelOrderTraversal].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221/src/Main.java" b/[0103][Binary Tree Zigzag LevelOrder Traversal]/src/Main.java
similarity index 100%
rename from "\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221/src/Main.java"
rename to [0103][Binary Tree Zigzag LevelOrder Traversal]/src/Main.java
diff --git "a/\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221/src/Solution.java" b/[0103][Binary Tree Zigzag LevelOrder Traversal]/src/Solution.java
similarity index 100%
rename from "\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221/src/Solution.java"
rename to [0103][Binary Tree Zigzag LevelOrder Traversal]/src/Solution.java
diff --git "a/\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221/src/TreeNode.java" b/[0103][Binary Tree Zigzag LevelOrder Traversal]/src/TreeNode.java
similarity index 100%
rename from "\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221/src/TreeNode.java"
rename to [0103][Binary Tree Zigzag LevelOrder Traversal]/src/TreeNode.java
diff --git a/[0104][Maximum Depth Of Binary Tree]/[0104][Maximum Depth Of Binary Tree].iml b/[0104][Maximum Depth Of Binary Tree]/[0104][Maximum Depth Of Binary Tree].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0104][Maximum Depth Of Binary Tree]/[0104][Maximum Depth Of Binary Tree].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220104\343\200\221\343\200\220MaximumDepthOfBinaryTree\343\200\221/src/Solution.java" b/[0104][Maximum Depth Of Binary Tree]/src/Solution.java
similarity index 100%
rename from "\343\200\220104\343\200\221\343\200\220MaximumDepthOfBinaryTree\343\200\221/src/Solution.java"
rename to [0104][Maximum Depth Of Binary Tree]/src/Solution.java
diff --git "a/\343\200\220104\343\200\221\343\200\220MaximumDepthOfBinaryTree\343\200\221/src/TreeNode.java" b/[0104][Maximum Depth Of Binary Tree]/src/TreeNode.java
similarity index 100%
rename from "\343\200\220104\343\200\221\343\200\220MaximumDepthOfBinaryTree\343\200\221/src/TreeNode.java"
rename to [0104][Maximum Depth Of Binary Tree]/src/TreeNode.java
diff --git a/[0105][Construct Binary Tree From Preorder And Inorder Traversal]/[0105][Construct Binary Tree From Preorder And Inorder Traversal].iml b/[0105][Construct Binary Tree From Preorder And Inorder Traversal]/[0105][Construct Binary Tree From Preorder And Inorder Traversal].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0105][Construct Binary Tree From Preorder And Inorder Traversal]/[0105][Construct Binary Tree From Preorder And Inorder Traversal].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0105][Construct Binary Tree From Preorder And Inorder Traversal]/src/Solution.java b/[0105][Construct Binary Tree From Preorder And Inorder Traversal]/src/Solution.java
new file mode 100644
index 0000000..5922420
--- /dev/null
+++ b/[0105][Construct Binary Tree From Preorder And Inorder Traversal]/src/Solution.java
@@ -0,0 +1,89 @@
+/**
+ * Author:
+ * Date: 2015-06-23
+ * Time: 14:04
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * Given preorder and inorder traversal of a tree, construct the binary tree.
+ *
+ * Note:
+ * You may assume that duplicates do not exist in the tree.
+ *
+ * Ŀ⣺
+ * һǰУһ
+ * ע⣺
+ * - ԪظԪ
+ *
+ * ˼·
+ * ǰһԪǸ㣨kֵΪk±idx
+ * idxзֳǰҲһɽеݹ
+ *
+ *
+ * @param preorder
+ * @param inorder
+ * @return
+ */
+ public TreeNode buildTree(int[] preorder, int[] inorder) {
+
+ // У
+ if (preorder == null || inorder == null || preorder.length == 0 || preorder.length != inorder.length) {
+ return null;
+ }
+ return solve(preorder, 0, preorder.length - 1, inorder, 0, inorder.length - 1);
+ }
+
+ /**
+ * ȷԼ֤
+ *
+ * @param preorder Ľ
+ * @param x Ŀʼλ
+ * @param y Ľλ
+ * @param inorder Ľ
+ * @param i Ŀʼλ
+ * @param j Ľλ
+ * @return ĸ
+ */
+ public TreeNode solve(int[] preorder, int x, int y, int[] inorder, int i, int j) {
+
+ if (x >= 0 && x <= y && i >= 0 && i <= j) {
+ // ֻһԪ
+ if (x == y) {
+ return new TreeNode(preorder[x]);
+ }
+ // xܴy
+ else if (x < y) {
+ // ¼
+ int idx = i;
+ while (idx <= j && inorder[idx] != preorder[x]) {
+ idx++;
+ }
+
+ //
+ TreeNode root = new TreeNode(inorder[idx]);
+
+ // Ľ
+ //[i, i+1, ..., idx - 1] -> ܼidx - i
+ int leftLength = idx - i;
+ //
+ if (leftLength > 0) {
+ // x + 1, x + leftLengthʼͽλ
+ root.left = solve(preorder, x + 1, x + leftLength, inorder, i, idx - 1);
+ }
+
+ // Ľ
+ // [idx+1, idx+2, ..., j] -> ܼƣj - idx
+ int rightLength = j - idx;
+ if (rightLength > 0) {
+ // x + leftLength + 1, yʼͽλ
+ root.right = solve(preorder, x + leftLength + 1, y, inorder, idx + 1, j);
+ }
+ return root;
+ }
+ }
+
+ return null;
+ }
+}
diff --git "a/\343\200\220105\343\200\221\343\200\220ConstructBinaryTreeFromPreorderAndInorderTraversal\343\200\221/src/TreeNode.java" b/[0105][Construct Binary Tree From Preorder And Inorder Traversal]/src/TreeNode.java
similarity index 100%
rename from "\343\200\220105\343\200\221\343\200\220ConstructBinaryTreeFromPreorderAndInorderTraversal\343\200\221/src/TreeNode.java"
rename to [0105][Construct Binary Tree From Preorder And Inorder Traversal]/src/TreeNode.java
diff --git a/[0106][Construct Binary Tree From Inorder And Postorder Traversal]/[0106][Construct Binary Tree From Inorder And Postorder Traversal].iml b/[0106][Construct Binary Tree From Inorder And Postorder Traversal]/[0106][Construct Binary Tree From Inorder And Postorder Traversal].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0106][Construct Binary Tree From Inorder And Postorder Traversal]/[0106][Construct Binary Tree From Inorder And Postorder Traversal].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0106][Construct Binary Tree From Inorder And Postorder Traversal]/src/Main.java b/[0106][Construct Binary Tree From Inorder And Postorder Traversal]/src/Main.java
new file mode 100644
index 0000000..c3569f8
--- /dev/null
+++ b/[0106][Construct Binary Tree From Inorder And Postorder Traversal]/src/Main.java
@@ -0,0 +1,24 @@
+/**
+ * Author: ������
+ * Date: 2015-06-23
+ * Time: 10:32
+ * Declaration: All Rights Reserved !!!
+ */
+public class Main {
+ public static void main(String[] args) {
+ Solution solution = new Solution();
+ int[] inorder = {1, 2, 3, 4};
+ int[] postorder = {3, 2, 4, 1};
+
+ TreeNode root = solution.buildTree(inorder, postorder);
+ print(root);
+ }
+
+ public static void print(TreeNode root) {
+ if (root != null) {
+ print(root.left);
+ System.out.print(root.val + " ");
+ print(root.right);
+ }
+ }
+}
diff --git a/[0106][Construct Binary Tree From Inorder And Postorder Traversal]/src/Solution.java b/[0106][Construct Binary Tree From Inorder And Postorder Traversal]/src/Solution.java
new file mode 100644
index 0000000..d6415c7
--- /dev/null
+++ b/[0106][Construct Binary Tree From Inorder And Postorder Traversal]/src/Solution.java
@@ -0,0 +1,92 @@
+/**
+ * Author:
+ * Date: 2015-06-23
+ * Time: 10:05
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * Given inorder and postorder traversal of a tree, construct the binary tree.
+ *
+ * Note:
+ * You may assume that duplicates do not exist in the tree.
+ *
+ * Ŀ⣺
+ * һͺУһö
+ * ע⣺
+ * ûظԪ
+ *
+ * ˼·
+ * һԪؾĸ(ֵΪr)
+ * ֵΪrλidxidxзΪ
+ * ӦԽзݹ
+ *
+ *
+ * @param inorder
+ * @param postorder
+ * @return
+ */
+ public TreeNode buildTree(int[] inorder, int[] postorder) {
+
+ //
+ if (inorder == null || postorder == null || inorder.length == 0 || inorder.length != postorder.length) {
+ return null;
+ }
+
+ //
+ return solve(inorder, 0, inorder.length - 1, postorder, 0, postorder.length - 1);
+ }
+
+ /**
+ *
+ *
+ * @param inorder Ľ
+ * @param x Ŀʼλ
+ * @param y Ľλ
+ * @param postorder Ľ
+ * @param i Ŀʼλ
+ * @param j Ľλ
+ * @return
+ */
+ public TreeNode solve(int[] inorder, int x, int y, int[] postorder, int i, int j) {
+
+ if (x >= 0 && x <= y && i >= 0 && i <= j) {
+ // ֻһԪأʱҲi=jɣ
+ if (x == y) {
+ return new TreeNode(postorder[j]);
+ }
+ // һԪأʱҲi ܼ idx-x
+ int leftLength = idx - x;
+ if (leftLength > 0) {
+ // i, i + leftLength - 1ǰʼλ
+ root.left = solve(inorder, x, idx - 1, postorder, i, i + leftLength - 1);
+ }
+
+ // ǿգ
+ // [idx+1, idx+2, ..., y] -> ܼ y-idx
+ int rightLength = y - idx;
+ if (rightLength > 0) {
+ // i + leftLength, j - 1ǰʼλ
+ root.right = solve(inorder, idx + 1, y, postorder, i + leftLength, j - 1);
+ }
+
+ return root;
+ }
+ }
+
+ return null;
+ }
+}
diff --git "a/\343\200\220106\343\200\221\343\200\220ConstructBinaryTreeFromInorderAndPostorderTraversal\343\200\221/src/TreeNode.java" b/[0106][Construct Binary Tree From Inorder And Postorder Traversal]/src/TreeNode.java
similarity index 100%
rename from "\343\200\220106\343\200\221\343\200\220ConstructBinaryTreeFromInorderAndPostorderTraversal\343\200\221/src/TreeNode.java"
rename to [0106][Construct Binary Tree From Inorder And Postorder Traversal]/src/TreeNode.java
diff --git a/[0107][Binary Tree Level Order Traversa lII]/[0107][Binary Tree Level Order Traversa lII].iml b/[0107][Binary Tree Level Order Traversa lII]/[0107][Binary Tree Level Order Traversa lII].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0107][Binary Tree Level Order Traversa lII]/[0107][Binary Tree Level Order Traversa lII].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0107][Binary Tree Level Order Traversa lII]/[0107][BinaryTreeLevelOrderTraversalII].iml b/[0107][Binary Tree Level Order Traversa lII]/[0107][BinaryTreeLevelOrderTraversalII].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0107][Binary Tree Level Order Traversa lII]/[0107][BinaryTreeLevelOrderTraversalII].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220107\343\200\221\343\200\220BinaryTreeLevelOrderTraversalII\343\200\221/src/Solution.java" b/[0107][Binary Tree Level Order Traversa lII]/src/Solution.java
similarity index 100%
rename from "\343\200\220107\343\200\221\343\200\220BinaryTreeLevelOrderTraversalII\343\200\221/src/Solution.java"
rename to [0107][Binary Tree Level Order Traversa lII]/src/Solution.java
diff --git "a/\343\200\220107\343\200\221\343\200\220BinaryTreeLevelOrderTraversalII\343\200\221/src/TreeNode.java" b/[0107][Binary Tree Level Order Traversa lII]/src/TreeNode.java
similarity index 100%
rename from "\343\200\220107\343\200\221\343\200\220BinaryTreeLevelOrderTraversalII\343\200\221/src/TreeNode.java"
rename to [0107][Binary Tree Level Order Traversa lII]/src/TreeNode.java
diff --git a/[0108][Convert Sorted Array To Binary Search Tree]/[0108][Convert Sorted Array To Binary Search Tree].iml b/[0108][Convert Sorted Array To Binary Search Tree]/[0108][Convert Sorted Array To Binary Search Tree].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0108][Convert Sorted Array To Binary Search Tree]/[0108][Convert Sorted Array To Binary Search Tree].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0108][Convert Sorted Array To Binary Search Tree]/[0108][ConvertSortedArrayToBinarySearchTree].iml b/[0108][Convert Sorted Array To Binary Search Tree]/[0108][ConvertSortedArrayToBinarySearchTree].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0108][Convert Sorted Array To Binary Search Tree]/[0108][ConvertSortedArrayToBinarySearchTree].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220108\343\200\221\343\200\220ConvertSortedArrayToBinarySearchTree\343\200\221/src/Solution.java" b/[0108][Convert Sorted Array To Binary Search Tree]/src/Solution.java
similarity index 100%
rename from "\343\200\220108\343\200\221\343\200\220ConvertSortedArrayToBinarySearchTree\343\200\221/src/Solution.java"
rename to [0108][Convert Sorted Array To Binary Search Tree]/src/Solution.java
diff --git "a/\343\200\220108\343\200\221\343\200\220ConvertSortedArrayToBinarySearchTree\343\200\221/src/TreeNode.java" b/[0108][Convert Sorted Array To Binary Search Tree]/src/TreeNode.java
similarity index 100%
rename from "\343\200\220108\343\200\221\343\200\220ConvertSortedArrayToBinarySearchTree\343\200\221/src/TreeNode.java"
rename to [0108][Convert Sorted Array To Binary Search Tree]/src/TreeNode.java
diff --git a/[0109][Convert Sorted List To Binary Search Tree]/[0109][Convert Sorted List To Binary Search Tree].iml b/[0109][Convert Sorted List To Binary Search Tree]/[0109][Convert Sorted List To Binary Search Tree].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0109][Convert Sorted List To Binary Search Tree]/[0109][Convert Sorted List To Binary Search Tree].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0109][Convert Sorted List To Binary Search Tree]/[0109][ConvertSortedListToBinarySearchTree].iml b/[0109][Convert Sorted List To Binary Search Tree]/[0109][ConvertSortedListToBinarySearchTree].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0109][Convert Sorted List To Binary Search Tree]/[0109][ConvertSortedListToBinarySearchTree].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/src/ListNode.java" b/[0109][Convert Sorted List To Binary Search Tree]/src/ListNode.java
similarity index 100%
rename from "\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/src/ListNode.java"
rename to [0109][Convert Sorted List To Binary Search Tree]/src/ListNode.java
diff --git "a/\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/src/Main.java" b/[0109][Convert Sorted List To Binary Search Tree]/src/Main.java
similarity index 100%
rename from "\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/src/Main.java"
rename to [0109][Convert Sorted List To Binary Search Tree]/src/Main.java
diff --git "a/\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/src/Solution.java" b/[0109][Convert Sorted List To Binary Search Tree]/src/Solution.java
similarity index 100%
rename from "\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/src/Solution.java"
rename to [0109][Convert Sorted List To Binary Search Tree]/src/Solution.java
diff --git "a/\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/src/TreeNode.java" b/[0109][Convert Sorted List To Binary Search Tree]/src/TreeNode.java
similarity index 100%
rename from "\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/src/TreeNode.java"
rename to [0109][Convert Sorted List To Binary Search Tree]/src/TreeNode.java
diff --git a/[0110][Balanced Binary Tree]/[0110][Balanced Binary Tree].iml b/[0110][Balanced Binary Tree]/[0110][Balanced Binary Tree].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0110][Balanced Binary Tree]/[0110][Balanced Binary Tree].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0110][Balanced Binary Tree]/[0110][BalancedBinaryTree].iml b/[0110][Balanced Binary Tree]/[0110][BalancedBinaryTree].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0110][Balanced Binary Tree]/[0110][BalancedBinaryTree].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220110\343\200\221\343\200\220BalancedBinaryTree\343\200\221/src/Solution.java" b/[0110][Balanced Binary Tree]/src/Solution.java
similarity index 100%
rename from "\343\200\220110\343\200\221\343\200\220BalancedBinaryTree\343\200\221/src/Solution.java"
rename to [0110][Balanced Binary Tree]/src/Solution.java
diff --git "a/\343\200\220110\343\200\221\343\200\220BalancedBinaryTree\343\200\221/src/TreeNode.java" b/[0110][Balanced Binary Tree]/src/TreeNode.java
similarity index 100%
rename from "\343\200\220110\343\200\221\343\200\220BalancedBinaryTree\343\200\221/src/TreeNode.java"
rename to [0110][Balanced Binary Tree]/src/TreeNode.java
diff --git a/[0111][Minimum Depth Of Binary Tree]/[0111][Minimum Depth Of Binary Tree].iml b/[0111][Minimum Depth Of Binary Tree]/[0111][Minimum Depth Of Binary Tree].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0111][Minimum Depth Of Binary Tree]/[0111][Minimum Depth Of Binary Tree].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0111][Minimum Depth Of Binary Tree]/src/Solution.java b/[0111][Minimum Depth Of Binary Tree]/src/Solution.java
new file mode 100644
index 0000000..836fb49
--- /dev/null
+++ b/[0111][Minimum Depth Of Binary Tree]/src/Solution.java
@@ -0,0 +1,40 @@
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 18:51
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * ԭ
+ * 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.
+ *
+ * Ŀ
+ * һСȡ
+ *
+ * ˼·
+ * бҳСȡ
+ *
+ *
+ * @param root
+ * @return
+ */
+ public int minDepth(TreeNode root) {
+ return minDepth(root, false);
+ }
+
+ public int minDepth(TreeNode root, boolean hasBrother) {
+ if (root == null) {
+ // ԼΪnullֵܲΪnullϲӽ㣬˵ǰûҵС
+ // ûֵܣ˵ǰʱֲСѾҵ
+ return hasBrother ? Integer.MAX_VALUE : 0;
+ }
+
+ return 1 + Math.min(minDepth(root.left, root.right != null),
+ minDepth(root.right, root.left != null));
+ }
+
+}
diff --git a/[0111][Minimum Depth Of Binary Tree]/src/Solution2.java b/[0111][Minimum Depth Of Binary Tree]/src/Solution2.java
new file mode 100644
index 0000000..6dfcd46
--- /dev/null
+++ b/[0111][Minimum Depth Of Binary Tree]/src/Solution2.java
@@ -0,0 +1,64 @@
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 18:51
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution2 {
+ private int min = Integer.MAX_VALUE; // ¼С
+ private int cur = 0; // iǰij
+
+ /**
+ *
+ * ԭ
+ * 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.
+ *
+ * Ŀ
+ * һСȡ
+ *
+ * ˼·
+ * бҳСȡ
+ *
+ *
+ * @param root
+ * @return
+ */
+ public int minDepth(TreeNode root) {
+
+ depth(root);
+ return min;
+ }
+
+ /**
+ *
+ *
+ * @param node ǰ
+ */
+ private void depth(TreeNode node) {
+
+ if (node == null) {
+ min = cur;
+ return;
+ }
+
+ cur++; // ǰIJμ1
+ // Ҷڵ㣬·ȼ¼СС
+ if (node.left == null && node.right == null && cur < min) {
+ min = cur; // Сֵ
+ }
+ //
+ if (node.left != null) {
+ depth(node.left);
+ }
+
+ //
+ if (node.right != null) {
+ depth(node.right);
+ }
+
+ cur--; // ԭ
+
+ }
+}
diff --git "a/\343\200\220111\343\200\221\343\200\220MinimumDepthOfBinaryTree\343\200\221/src/TreeNode.java" b/[0111][Minimum Depth Of Binary Tree]/src/TreeNode.java
similarity index 100%
rename from "\343\200\220111\343\200\221\343\200\220MinimumDepthOfBinaryTree\343\200\221/src/TreeNode.java"
rename to [0111][Minimum Depth Of Binary Tree]/src/TreeNode.java
diff --git a/[0112][Path Sum]/[0112][Path Sum].iml b/[0112][Path Sum]/[0112][Path Sum].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0112][Path Sum]/[0112][Path Sum].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0112][Path Sum]/[0112][PathSum].iml b/[0112][Path Sum]/[0112][PathSum].iml
new file mode 100644
index 0000000..86622ab
--- /dev/null
+++ b/[0112][Path Sum]/[0112][PathSum].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220112\343\200\221\343\200\220PathSum\343\200\221/src/Solution.java" b/[0112][Path Sum]/src/Solution.java
similarity index 100%
rename from "\343\200\220112\343\200\221\343\200\220PathSum\343\200\221/src/Solution.java"
rename to [0112][Path Sum]/src/Solution.java
diff --git "a/\343\200\220112\343\200\221\343\200\220PathSum\343\200\221/src/TreeNode.java" b/[0112][Path Sum]/src/TreeNode.java
similarity index 100%
rename from "\343\200\220112\343\200\221\343\200\220PathSum\343\200\221/src/TreeNode.java"
rename to [0112][Path Sum]/src/TreeNode.java
diff --git a/[0113][Path Sum II]/[0113][Path Sum II].iml b/[0113][Path Sum II]/[0113][Path Sum II].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0113][Path Sum II]/[0113][Path Sum II].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0113][Path Sum II]/[0113][PathSumII].iml b/[0113][Path Sum II]/[0113][PathSumII].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0113][Path Sum II]/[0113][PathSumII].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220113\343\200\221\343\200\220PathSumII\343\200\221/src/Solution.java" b/[0113][Path Sum II]/src/Solution.java
similarity index 100%
rename from "\343\200\220113\343\200\221\343\200\220PathSumII\343\200\221/src/Solution.java"
rename to [0113][Path Sum II]/src/Solution.java
diff --git "a/\343\200\220113\343\200\221\343\200\220PathSumII\343\200\221/src/TreeNode.java" b/[0113][Path Sum II]/src/TreeNode.java
similarity index 100%
rename from "\343\200\220113\343\200\221\343\200\220PathSumII\343\200\221/src/TreeNode.java"
rename to [0113][Path Sum II]/src/TreeNode.java
diff --git a/[0114][Flatten Binary Tree To Linked List]/[0114][Flatten Binary Tree To Linked List].iml b/[0114][Flatten Binary Tree To Linked List]/[0114][Flatten Binary Tree To Linked List].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0114][Flatten Binary Tree To Linked List]/[0114][Flatten Binary Tree To Linked List].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0114][Flatten Binary Tree To Linked List]/[0114][FlattenBinaryTreeToLinkedList].iml b/[0114][Flatten Binary Tree To Linked List]/[0114][FlattenBinaryTreeToLinkedList].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0114][Flatten Binary Tree To Linked List]/[0114][FlattenBinaryTreeToLinkedList].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220114\343\200\221\343\200\220FlattenBinaryTreeToLinkedList\343\200\221/src/Solution.java" b/[0114][Flatten Binary Tree To Linked List]/src/Solution.java
similarity index 100%
rename from "\343\200\220114\343\200\221\343\200\220FlattenBinaryTreeToLinkedList\343\200\221/src/Solution.java"
rename to [0114][Flatten Binary Tree To Linked List]/src/Solution.java
diff --git a/[0114][Flatten Binary Tree To Linked List]/src/TreeNode.java b/[0114][Flatten Binary Tree To Linked List]/src/TreeNode.java
new file mode 100644
index 0000000..463b6fe
--- /dev/null
+++ b/[0114][Flatten Binary Tree To Linked List]/src/TreeNode.java
@@ -0,0 +1,15 @@
+/**
+ * Author: ������
+ * Date: 2015-08-21
+ * Time: 19:02
+ * Declaration: All Rights Reserved !!!
+ */
+public class TreeNode {
+ int val;
+ TreeNode left;
+ TreeNode right;
+
+ TreeNode(int x) {
+ val = x;
+ }
+}
diff --git a/[0116][Populating Next Right Pointersin Each Node]/[0116][Populating Next Right Pointersin Each Node].iml b/[0116][Populating Next Right Pointersin Each Node]/[0116][Populating Next Right Pointersin Each Node].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0116][Populating Next Right Pointersin Each Node]/[0116][Populating Next Right Pointersin Each Node].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0116][Populating Next Right Pointersin Each Node]/[0116][PopulatingNextRightPointersinEachNode ].iml b/[0116][Populating Next Right Pointersin Each Node]/[0116][PopulatingNextRightPointersinEachNode ].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0116][Populating Next Right Pointersin Each Node]/[0116][PopulatingNextRightPointersinEachNode ].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220116\343\200\221\343\200\220PopulatingNextRightPointersinEachNode \343\200\221/src/Solution.java" b/[0116][Populating Next Right Pointersin Each Node]/src/Solution.java
similarity index 100%
rename from "\343\200\220116\343\200\221\343\200\220PopulatingNextRightPointersinEachNode \343\200\221/src/Solution.java"
rename to [0116][Populating Next Right Pointersin Each Node]/src/Solution.java
diff --git "a/\343\200\220116\343\200\221\343\200\220PopulatingNextRightPointersinEachNode \343\200\221/src/TreeLinkNode.java" b/[0116][Populating Next Right Pointersin Each Node]/src/TreeLinkNode.java
similarity index 100%
rename from "\343\200\220116\343\200\221\343\200\220PopulatingNextRightPointersinEachNode \343\200\221/src/TreeLinkNode.java"
rename to [0116][Populating Next Right Pointersin Each Node]/src/TreeLinkNode.java
diff --git a/[0117][Populating Next Right Pointers In Each Node II]/[0117][Populating Next Right Pointers In Each Node II].iml b/[0117][Populating Next Right Pointers In Each Node II]/[0117][Populating Next Right Pointers In Each Node II].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0117][Populating Next Right Pointers In Each Node II]/[0117][Populating Next Right Pointers In Each Node II].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0117][Populating Next Right Pointers In Each Node II]/[0117][PopulatingNextRightPointersInEachNodeII].iml b/[0117][Populating Next Right Pointers In Each Node II]/[0117][PopulatingNextRightPointersInEachNodeII].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0117][Populating Next Right Pointers In Each Node II]/[0117][PopulatingNextRightPointersInEachNodeII].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221/src/Main.java" b/[0117][Populating Next Right Pointers In Each Node II]/src/Main.java
similarity index 100%
rename from "\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221/src/Main.java"
rename to [0117][Populating Next Right Pointers In Each Node II]/src/Main.java
diff --git "a/\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221/src/Solution.java" b/[0117][Populating Next Right Pointers In Each Node II]/src/Solution.java
similarity index 100%
rename from "\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221/src/Solution.java"
rename to [0117][Populating Next Right Pointers In Each Node II]/src/Solution.java
diff --git "a/\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221/src/TreeLinkNode.java" b/[0117][Populating Next Right Pointers In Each Node II]/src/TreeLinkNode.java
similarity index 100%
rename from "\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221/src/TreeLinkNode.java"
rename to [0117][Populating Next Right Pointers In Each Node II]/src/TreeLinkNode.java
diff --git a/[0118][Pascal's Triangle]/[0118][Pascal's Triangle].iml b/[0118][Pascal's Triangle]/[0118][Pascal's Triangle].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0118][Pascal's Triangle]/[0118][Pascal's Triangle].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0118][Pascal's Triangle]/[0118][Pascal'sTriangle].iml b/[0118][Pascal's Triangle]/[0118][Pascal'sTriangle].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0118][Pascal's Triangle]/[0118][Pascal'sTriangle].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220118\343\200\221\343\200\220Pascal'sTriangle\343\200\221/src/Solution.java" b/[0118][Pascal's Triangle]/src/Solution.java
similarity index 100%
rename from "\343\200\220118\343\200\221\343\200\220Pascal'sTriangle\343\200\221/src/Solution.java"
rename to [0118][Pascal's Triangle]/src/Solution.java
diff --git a/[0119][Pascal's Triangle II]/[0119][Pascal's Triangle II].iml b/[0119][Pascal's Triangle II]/[0119][Pascal's Triangle II].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0119][Pascal's Triangle II]/[0119][Pascal's Triangle II].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0119][Pascal's Triangle II]/[0119][Pascal'sTriangleII].iml b/[0119][Pascal's Triangle II]/[0119][Pascal'sTriangleII].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0119][Pascal's Triangle II]/[0119][Pascal'sTriangleII].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220119\343\200\221\343\200\220Pascal'sTriangleII\343\200\221/src/Solution.java" b/[0119][Pascal's Triangle II]/src/Solution.java
similarity index 100%
rename from "\343\200\220119\343\200\221\343\200\220Pascal'sTriangleII\343\200\221/src/Solution.java"
rename to [0119][Pascal's Triangle II]/src/Solution.java
diff --git a/[0120][Triangle]/[0120][Triangle].iml b/[0120][Triangle]/[0120][Triangle].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0120][Triangle]/[0120][Triangle].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220120\343\200\221\343\200\220Triangle\343\200\221/src/Main.java" b/[0120][Triangle]/src/Main.java
similarity index 100%
rename from "\343\200\220120\343\200\221\343\200\220Triangle\343\200\221/src/Main.java"
rename to [0120][Triangle]/src/Main.java
diff --git "a/\343\200\220120\343\200\221\343\200\220Triangle\343\200\221/src/Solution.java" b/[0120][Triangle]/src/Solution.java
similarity index 100%
rename from "\343\200\220120\343\200\221\343\200\220Triangle\343\200\221/src/Solution.java"
rename to [0120][Triangle]/src/Solution.java
diff --git a/[0121][Best Time To Buy And Sell Stock]/[0121][Best Time To Buy And Sell Stock].iml b/[0121][Best Time To Buy And Sell Stock]/[0121][Best Time To Buy And Sell Stock].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0121][Best Time To Buy And Sell Stock]/[0121][Best Time To Buy And Sell Stock].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0121][Best Time To Buy And Sell Stock]/src/Solution.java b/[0121][Best Time To Buy And Sell Stock]/src/Solution.java
new file mode 100644
index 0000000..6809bcf
--- /dev/null
+++ b/[0121][Best Time To Buy And Sell Stock]/src/Solution.java
@@ -0,0 +1,58 @@
+/**
+ * Author:
+ * Date: 2015-06-22
+ * Time: 15:42
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * 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.
+ *
+ * Ŀ⣺
+ * һprices[]prices[i]Ʊڵiۼֻۣһν(һ)ܵõ档
+ *
+ * ˼·
+ *
+ * ̰ķֱҵ۸ͺߵһ죬ͽ߳ע͵һҪߵһ֮ǰ
+ * ԭʼ۸бɲУҲmӶκͣm = 1
+ *
+ * ֻҪҳIJֵɣ max(prices[j], prices[i]) i < jһαɣڱʱñ
+ * low¼ prices[0, ..., i] еСֵǵǰΪֹۼۣʱ临ӶΪ O(n)
+ *
+ *
+ * @param prices
+ * @return
+ */
+ public int maxProfit(int[] prices) {
+
+ if (prices == null || prices.length < 1) {
+ return 0;
+ }
+
+ int min = prices[0];
+ int profit = 0;
+
+ // iļ۸ԿҲԿ
+ for (int i = 1; i < prices.length; i++) {
+ // ҵ͵
+ if (min > prices[i]) {
+ //
+ min = prices[i];
+ }
+ // ļ۸
+ else {
+ // ļ۸֮ǰļ۸
+ if (profit < prices[i] - min) {
+ //
+ profit = prices[i] - min;
+ }
+ }
+ }
+
+ return profit;
+ }
+}
diff --git a/[0122][Best Time to Buy and Sell Stock II]/[0122][Best Time to Buy and Sell Stock II].iml b/[0122][Best Time to Buy and Sell Stock II]/[0122][Best Time to Buy and Sell Stock II].iml
new file mode 100644
index 0000000..c8cb479
--- /dev/null
+++ b/[0122][Best Time to Buy and Sell Stock II]/[0122][Best Time to Buy and Sell Stock II].iml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0122][Best Time to Buy and Sell Stock II]/src/Main.java b/[0122][Best Time to Buy and Sell Stock II]/src/Main.java
new file mode 100644
index 0000000..b0a9f62
--- /dev/null
+++ b/[0122][Best Time to Buy and Sell Stock II]/src/Main.java
@@ -0,0 +1,37 @@
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-10-09 09:13
+ **/
+public class Main {
+
+ @Test
+ public void test1() {
+ int[] prices = {7, 1, 5, 3, 6, 4};
+ Solution solution = new Solution();
+ Assert.assertEquals(7, solution.maxProfit(prices));
+ }
+
+ @Test
+ public void test2() {
+ int[] prices = {1, 2, 3, 4, 5};
+ Solution solution = new Solution();
+ Assert.assertEquals(4, solution.maxProfit(prices));
+ }
+
+ @Test
+ public void test3() {
+ int[] prices = {7, 6, 4, 3, 1};
+ Solution solution = new Solution();
+ Assert.assertEquals(0, solution.maxProfit(prices));
+ }
+
+ @Test
+ public void test4() {
+ int[] prices = {3, 2, 9, 1, 7, 4};
+ Solution2 solution = new Solution2();
+ Assert.assertEquals(13, solution.maxProfit(prices));
+ }
+}
diff --git a/[0122][Best Time to Buy and Sell Stock II]/src/Solution.java b/[0122][Best Time to Buy and Sell Stock II]/src/Solution.java
new file mode 100644
index 0000000..baed796
--- /dev/null
+++ b/[0122][Best Time to Buy and Sell Stock II]/src/Solution.java
@@ -0,0 +1,58 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-10-09 08:46
+ **/
+public class Solution {
+ /**
+ *
+ * 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 (i.e., buy one and sell one share of the stock multiple times).
+ *
+ * Note: You may not engage in multiple transactions at the same time (i.e., you must sell the
+ * stock before you buy again).
+ *
+ * Example 1:
+ *
+ * Input: [7,1,5,3,6,4]
+ * Output: 7
+ * Explanation: Buy on day 2 (price = 1) and sell on day 3 (price = 5), profit = 5-1 = 4.
+ * Then buy on day 4 (price = 3) and sell on day 5 (price = 6), profit = 6-3 = 3.
+ * Example 2:
+ *
+ * Input: [1,2,3,4,5]
+ * Output: 4
+ * Explanation: Buy on day 1 (price = 1) and sell on day 5 (price = 5), profit = 5-1 = 4.
+ * Note that you cannot buy on day 1, buy on day 2 and sell them later, as you are
+ * engaging multiple transactions at the same time. You must sell before buying again.
+ * Example 3:
+ *
+ * Input: [7,6,4,3,1]
+ * Output: 0
+ * Explanation: In this case, no transaction is done, i.e. max profit = 0.
+ *
+ *
+ *
+ * @param prices
+ * @return
+ */
+ public int maxProfit(int[] prices) {
+
+ if (prices == null || prices.length < 2) {
+ return 0;
+ }
+
+ int sum = 0;
+ int diff;
+ for (int i = 1; i < prices.length; i++) {
+ // 如果后一天的价格比前一天高就卖出
+ diff = prices[i] - prices[i - 1];
+ if (diff > 0) {
+ sum += diff;
+ }
+ }
+
+ return sum;
+ }
+}
diff --git a/[0122][Best Time to Buy and Sell Stock II]/src/Solution2.java b/[0122][Best Time to Buy and Sell Stock II]/src/Solution2.java
new file mode 100644
index 0000000..cef7e3c
--- /dev/null
+++ b/[0122][Best Time to Buy and Sell Stock II]/src/Solution2.java
@@ -0,0 +1,71 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-10-09 08:46
+ **/
+public class Solution2 {
+ /**
+ *
+ * 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 (i.e., buy one and sell one share of the stock multiple times).
+ *
+ * Note: You may not engage in multiple transactions at the same time (i.e., you must sell the
+ * stock before you buy again).
+ *
+ * Example 1:
+ *
+ * Input: [7,1,5,3,6,4]
+ * Output: 7
+ * Explanation: Buy on day 2 (price = 1) and sell on day 3 (price = 5), profit = 5-1 = 4.
+ * Then buy on day 4 (price = 3) and sell on day 5 (price = 6), profit = 6-3 = 3.
+ * Example 2:
+ *
+ * Input: [1,2,3,4,5]
+ * Output: 4
+ * Explanation: Buy on day 1 (price = 1) and sell on day 5 (price = 5), profit = 5-1 = 4.
+ * Note that you cannot buy on day 1, buy on day 2 and sell them later, as you are
+ * engaging multiple transactions at the same time. You must sell before buying again.
+ * Example 3:
+ *
+ * Input: [7,6,4,3,1]
+ * Output: 0
+ * Explanation: In this case, no transaction is done, i.e. max profit = 0.
+ *
+ *
+ * Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:
+ *
+ * Only one letter can be changed at a time
+ * Each transformed word must exist in the word list. Note that beginWord is not a transformed word.
+ * Note:
+ *
+ * Return an empty list if there is no such transformation sequence.
+ * All words have the same length.
+ * All words contain only lowercase alphabetic characters.
+ * You may assume no duplicates in the word list.
+ * You may assume beginWord and endWord are non-empty and are not the same.
+ * Example 1:
+ *
+ * Input:
+ * beginWord = "hit",
+ * endWord = "cog",
+ * wordList = ["hot","dot","dog","lot","log","cog"]
+ *
+ * Output:
+ * [
+ * ["hit","hot","dot","dog","cog"],
+ * ["hit","hot","lot","log","cog"]
+ * ]
+ * Example 2:
+ *
+ * Input:
+ * beginWord = "hit"
+ * endWord = "cog"
+ * wordList = ["hot","dot","dog","lot","log"]
+ *
+ * Output: []
+ *
+ * Explanation: The endWord "cog" is not in wordList, therefore no possible transformation.
+ *
+ * 使用了图的遍历
+ * https://www.cnblogs.com/splash/p/4102786.html
+ *
+ *
+ * @param beginWord
+ * @param endWord
+ * @param wordList
+ * @return
+ */
+ HashMap> nodeSet = new HashMap<>();
+
+ public List> findLadders(String start, String end, List wordList) {
+ Set wordDict = new HashSet<>(wordList);
+
+ List> result = new ArrayList>();
+
+ if (!wordDict.contains(end)) {
+ return result;
+ }
+
+ Queue q = new LinkedList();
+ HashSet hs = new HashSet();
+ HashMap dist = new HashMap();
+ q.add(start);
+ nodeSet.put(start, new ArrayList());
+ nodeSet.put(end, new ArrayList());
+ dist.put(start, 1);
+
+ while (!q.isEmpty()) {
+ String temp = q.poll();
+ int l = dist.get(temp);
+ hs.add(temp);
+ for (int i = 0; i < temp.length(); i++) {
+ for (char c = 'a'; c <= 'z'; c++) {
+ if (temp.charAt(i) == c) {
+ continue;
+ }
+ StringBuilder sb = new StringBuilder(temp);
+ sb.setCharAt(i, c);
+ String next = sb.toString();
+ if (next.equals(end)) {
+ if (!dist.containsKey(end)) {
+ dist.put(end, l + 1);
+ nodeSet.get(end).add(temp);
+ } else if (dist.get(end) == l + 1) {
+ nodeSet.get(end).add(temp);
+ }
+ } else if (wordDict.contains(next) && !hs.contains(next)) {
+ if (!dist.containsKey(next)) {
+ q.add(next);
+ dist.put(next, l + 1);
+ ArrayList arr = new ArrayList();
+ arr.add(temp);
+ nodeSet.put(next, arr);
+ } else if (dist.get(next) == l + 1) {
+ nodeSet.get(next).add(temp);
+ }
+ }
+ }
+ }
+ }
+ List path = new ArrayList();
+ path.add(end);
+
+ collect(start, result, path, nodeSet.get(end));
+ return result;
+ }
+
+ public void collect(String start, List> re, List path, ArrayList prevNodes) {
+ for (int i = 0; i < prevNodes.size(); i++) {
+ path.add(0, prevNodes.get(i));
+ if (prevNodes.get(i).equals(start)) {
+ List pathCopy = new ArrayList(path);
+ re.add(pathCopy);
+ } else {
+ collect(start, re, path, nodeSet.get(prevNodes.get(i)));
+ }
+ path.remove(0);
+ }
+ }
+}
diff --git a/[0126][Word Ladder II]/src/Solution2.java b/[0126][Word Ladder II]/src/Solution2.java
new file mode 100644
index 0000000..206bddb
--- /dev/null
+++ b/[0126][Word Ladder II]/src/Solution2.java
@@ -0,0 +1,109 @@
+import java.util.*;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-20 08:42
+ **/
+public class Solution2 {
+ /**
+ *
+ * Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:
+ *
+ * Only one letter can be changed at a time
+ * Each transformed word must exist in the word list. Note that beginWord is not a transformed word.
+ * Note:
+ *
+ * Return an empty list if there is no such transformation sequence.
+ * All words have the same length.
+ * All words contain only lowercase alphabetic characters.
+ * You may assume no duplicates in the word list.
+ * You may assume beginWord and endWord are non-empty and are not the same.
+ * Example 1:
+ *
+ * Input:
+ * beginWord = "hit",
+ * endWord = "cog",
+ * wordList = ["hot","dot","dog","lot","log","cog"]
+ *
+ * Output:
+ * [
+ * ["hit","hot","dot","dog","cog"],
+ * ["hit","hot","lot","log","cog"]
+ * ]
+ * Example 2:
+ *
+ * Input:
+ * beginWord = "hit"
+ * endWord = "cog"
+ * wordList = ["hot","dot","dog","lot","log"]
+ *
+ * Output: []
+ *
+ * Explanation: The endWord "cog" is not in wordList, therefore no possible transformation.
+ *
+ * 使用了深度优化遍历方案,会超时
+ *
+ * Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:
+ *
+ * Only one letter can be changed at a time
+ * Each transformed word must exist in the word list. Note that beginWord is not a transformed word.
+ * Note:
+ *
+ * Return an empty list if there is no such transformation sequence.
+ * All words have the same length.
+ * All words contain only lowercase alphabetic characters.
+ * You may assume no duplicates in the word list.
+ * You may assume beginWord and endWord are non-empty and are not the same.
+ * Example 1:
+ *
+ * Input:
+ * beginWord = "hit",
+ * endWord = "cog",
+ * wordList = ["hot","dot","dog","lot","log","cog"]
+ *
+ * Output:
+ * [
+ * ["hit","hot","dot","dog","cog"],
+ * ["hit","hot","lot","log","cog"]
+ * ]
+ * Example 2:
+ *
+ * Input:
+ * beginWord = "hit"
+ * endWord = "cog"
+ * wordList = ["hot","dot","dog","lot","log"]
+ *
+ * Output: []
+ *
+ * Explanation: The endWord "cog" is not in wordList, therefore no possible transformation.
+ *
+ * 使用了广度优化遍历方案,会超时
+ *
+ *
+ * @param beginWord
+ * @param endWord
+ * @param wordList
+ * @return
+ */
+ public List> findLadders(String beginWord, String endWord, List wordList) {
+
+
+ Set wordDict = new HashSet<>(wordList);
+ List> result = new LinkedList<>();
+ // 用于保存所有中间结果
+ Deque> paths = new LinkedList<>();
+
+
+ Deque deque = new LinkedList<>();
+ deque.addLast(beginWord);
+ paths.addLast(deque);
+
+ boolean find = false;
+
+ while (!paths.isEmpty() && !find) {
+ // 先遍历看是否找到结果,如果找到了,一定是最优化解
+ for (Deque path : paths) {
+ if (path.getLast().equals(endWord)) {
+ result.add(new LinkedList<>(path));
+ find = true;
+ }
+ }
+
+ // find表示已经找到了
+ // paths.getFirst().size() >=beginWord.length()说明不可能找到结果,path最
+ System.out.println(paths.getFirst().size());
+ if (find || paths.getFirst().size() >= wordDict.size()) {
+ break;
+ }
+
+ // TODO 什么时候判断找不到,path中可能形成环
+
+
+ // 没有找到最优化解,构建下一层
+ for (int k = paths.size(); k > 0; k--) {
+
+ // 取路径的最后一个元素
+ Deque path = paths.removeFirst();
+ String s = path.getLast();
+
+ // 当前路径下,还可以使用的字词
+ Set set = new HashSet<>(wordDict);
+ set.removeAll(path);
+
+ System.out.println(set);
+
+ // 找出当前层的每个元素经过一次变化后,是否在剩余的wordDict中找到,
+ // 如果找到就放到下一层的处理中
+ char[] chars = s.toCharArray();
+ for (int i = 0; i < beginWord.length(); i++) {
+ for (char j = 'a'; j <= 'z'; j++) {
+ char temp = chars[i];
+ chars[i] = j;
+ String t = new String(chars);
+
+ // 一次变换后可以找到单词,放到下一层处理中
+ if (set.contains(t) && !t.equals(s)) {
+ path.addLast(t);
+ paths.addLast(new LinkedList<>(path));
+ path.removeLast();
+ }
+ // 还原
+ chars[i] = temp;
+ }
+ }
+
+ }
+ }
+
+ return result;
+ }
+}
diff --git a/[0127][Word Ladder]/[0127][Word Ladder].iml b/[0127][Word Ladder]/[0127][Word Ladder].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0127][Word Ladder]/[0127][Word Ladder].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0127][Word Ladder]/[0127][WordLadder].iml b/[0127][Word Ladder]/[0127][WordLadder].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0127][Word Ladder]/[0127][WordLadder].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0127][Word Ladder]/src/Main.java b/[0127][Word Ladder]/src/Main.java
new file mode 100644
index 0000000..2a6d29a
--- /dev/null
+++ b/[0127][Word Ladder]/src/Main.java
@@ -0,0 +1,21 @@
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-20 08:17
+ **/
+public class Main {
+ @Test
+ public void test1() {
+ Solution solution = new Solution();
+ String beginWord = "hit";
+ String endWord = "cog";
+ List wordList = new LinkedList<>(Arrays.asList("hot", "dot", "dog", "lot", "log", "cog"));
+ Assert.assertEquals(5, solution.ladderLength(beginWord, endWord, wordList));
+ }
+}
diff --git a/[0127][Word Ladder]/src/Solution.java b/[0127][Word Ladder]/src/Solution.java
new file mode 100644
index 0000000..4cb9ab8
--- /dev/null
+++ b/[0127][Word Ladder]/src/Solution.java
@@ -0,0 +1,96 @@
+import java.util.*;
+
+/**
+ * Author:
+ * Date: 2015-06-20
+ * Time: 08:11
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * Given two words (beginWord and endWord), and a dictionary, find the length
+ * of shortest transformation sequence from beginWord to endWord, 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.
+ *
+ * Ŀ⣺
+ * ʣbeginWordendWordһֵ䣬ҴbeginWordת͵endWord̳ȣ
+ * - һֻһĸԱı
+ * - ÿмֱڴʵ
+ *
+ * ע⣺
+ * - ı任У0
+ * - еʾͬijȡ
+ * - еֻСдĸַ
+ *
+ * ˼·
+ * Ż
+ *
+ *
+ * @param beginWord
+ * @param endWord
+ * @param wordList
+ * @return
+ */
+ public int ladderLength(String beginWord, String endWord, List wordList) {
+
+ Set wordDict = new HashSet<>(wordList);
+
+ char[] chars;
+ Deque deque = new LinkedList<>();
+ deque.addLast(beginWord);
+ int result = 0;
+ String s;
+ String t;
+ while (!deque.isEmpty()) {
+
+ // ǰ
+ for (int k = deque.size(); k > 0; k--) {
+ s = deque.removeFirst();
+
+ if (s.equalsIgnoreCase(endWord)) {
+ return result + 1;
+ }
+
+ // ҳǰÿԪؾһα仯ǷʣwordDictҵ
+ // ҵͷŵһĴ
+ chars = s.toCharArray();
+ for (int i = 0; i < beginWord.length(); i++) {
+ for (char j = 'a'; j <= 'z'; j++) {
+ char temp = chars[i];
+ chars[i] = j;
+ t = new String(chars);
+ // һα任ҵʣŵһ㴦УwordDictɾ¼
+ if (wordDict.contains(t) && !t.equals(s)) {
+ deque.addLast(t);
+ wordDict.remove(t);
+ }
+ // ԭ
+ chars[i] = temp;
+ }
+ }
+ }
+
+
+ result++;
+ }
+
+ return 0;
+ }
+}
diff --git a/[0128][Longest Consecutive Sequence]/[0128][Longest Consecutive Sequence].iml b/[0128][Longest Consecutive Sequence]/[0128][Longest Consecutive Sequence].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0128][Longest Consecutive Sequence]/[0128][Longest Consecutive Sequence].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0128][Longest Consecutive Sequence]/src/Main.java b/[0128][Longest Consecutive Sequence]/src/Main.java
new file mode 100644
index 0000000..d6d2e5c
--- /dev/null
+++ b/[0128][Longest Consecutive Sequence]/src/Main.java
@@ -0,0 +1,17 @@
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-14 15:02
+ **/
+public class Main {
+ @Test
+ public void test() {
+ int[] nums = {100, 4, 200, 1, 3, 2};
+
+ Solution solution = new Solution();
+
+ Assert.assertEquals(4, solution.longestConsecutive(nums));
+ }
+}
diff --git a/[0128][Longest Consecutive Sequence]/src/Solution.java b/[0128][Longest Consecutive Sequence]/src/Solution.java
new file mode 100644
index 0000000..b41b5ec
--- /dev/null
+++ b/[0128][Longest Consecutive Sequence]/src/Solution.java
@@ -0,0 +1,59 @@
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-14 14:48
+ **/
+class Solution {
+ /**
+ *
+ * Given an unsorted array of integers, find the length of the longest consecutive elements sequence.
+ *
+ * Your algorithm should run in O(n) complexity.
+ *
+ * Example:
+ *
+ * Input: [100, 4, 200, 1, 3, 2]
+ * Output: 4
+ * Explanation: The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4.
+ *
+ * 这道题要求求最长连续序列,并给定了O(n)复杂度限制,我们的思路是,使用一个集合HashSet存入所有的数字,
+ * 然后遍历数组中的每个数字,如果其在集合中存在,那么将其移除,然后分别用两个变量pre和next算出其前一个
+ * 数跟后一个数,然后在集合中循环查找,如果pre在集合中,那么将pre移除集合,然后pre再自减1,直至pre不在
+ * 集合之中,对next采用同样的方法,那么next-pre-1就是当前数字的最长连续序列,更新res即可。这里再说下,
+ * 为啥当检测某数字在集合中存在当时候,都要移除数字。这是为了避免大量的重复计算,就拿题目中的例子来说吧,
+ * 我们在遍历到4的时候,会向下遍历3,2,1,如果都不移除数字的话,遍历到1的时候,还会遍历2,3,4。同样,
+ * 遍历到3的时候,向上遍历4,向下遍历2,1,等等等。如果数组中有大量的连续数字的话,那么就有大量的重复计算,
+ * 十分的不高效,所以我们要从HashSet中移除数字
+ *
+ *
+ * @param nums
+ * @return
+ */
+ public int longestConsecutive(int[] nums) {
+ int res = 0;
+ Set set = new HashSet<>();
+
+ for (int i : nums) {
+ set.add(i);
+ }
+
+ for (int i : nums) {
+ if (set.remove(i)) {
+ int prev = i - 1;
+ int next = i + 1;
+ while (set.remove(prev)) {
+ --prev;
+ }
+ while (set.remove(next)) {
+ ++next;
+ }
+
+ res = Math.max(res, next - prev - 1);
+ }
+ }
+
+ return res;
+ }
+}
diff --git a/[0129][Sum Root To Leaf Numbers]/[0129][Sum Root To Leaf Numbers].iml b/[0129][Sum Root To Leaf Numbers]/[0129][Sum Root To Leaf Numbers].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0129][Sum Root To Leaf Numbers]/[0129][Sum Root To Leaf Numbers].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0129][Sum Root To Leaf Numbers]/[0129][SumRootToLeafNumbers].iml b/[0129][Sum Root To Leaf Numbers]/[0129][SumRootToLeafNumbers].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0129][Sum Root To Leaf Numbers]/[0129][SumRootToLeafNumbers].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220129\343\200\221\343\200\220SumRootToLeafNumbers\343\200\221/src/Solution.java" b/[0129][Sum Root To Leaf Numbers]/src/Solution.java
similarity index 100%
rename from "\343\200\220129\343\200\221\343\200\220SumRootToLeafNumbers\343\200\221/src/Solution.java"
rename to [0129][Sum Root To Leaf Numbers]/src/Solution.java
diff --git "a/\343\200\220129\343\200\221\343\200\220SumRootToLeafNumbers\343\200\221/src/TreeNode.java" b/[0129][Sum Root To Leaf Numbers]/src/TreeNode.java
similarity index 100%
rename from "\343\200\220129\343\200\221\343\200\220SumRootToLeafNumbers\343\200\221/src/TreeNode.java"
rename to [0129][Sum Root To Leaf Numbers]/src/TreeNode.java
diff --git a/[0130][Surrounded Regions]/[0130][Surrounded Regions].iml b/[0130][Surrounded Regions]/[0130][Surrounded Regions].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0130][Surrounded Regions]/[0130][Surrounded Regions].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0130][Surrounded Regions]/[0130][SurroundedRegions].iml b/[0130][Surrounded Regions]/[0130][SurroundedRegions].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0130][Surrounded Regions]/[0130][SurroundedRegions].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0130][Surrounded Regions]/src/Main.java b/[0130][Surrounded Regions]/src/Main.java
new file mode 100644
index 0000000..6c22ca8
--- /dev/null
+++ b/[0130][Surrounded Regions]/src/Main.java
@@ -0,0 +1,81 @@
+import org.junit.Test;
+
+/**
+ * Author:
+ * Date: 2015-06-22
+ * Time: 10:02
+ * Declaration: All Rights Reserved !!!
+ */
+public class Main {
+
+ @Test
+ public void test01() {
+ Solution solution = new Solution();
+ char[][] board = {
+ "XXXX".toCharArray(),
+ "XOOX".toCharArray(),
+ "XXOX".toCharArray(),
+ "XOXX".toCharArray()
+ };
+
+ solution.solve(board);
+
+ for (char[] line : board) {
+ System.out.println(new String(line));
+ }
+ System.out.println();
+ }
+
+ @Test
+ public void test02() {
+ Solution solution = new Solution();
+ char[][] board = {
+ "XOXX".toCharArray(),
+ "OXOX".toCharArray(),
+ "XOXO".toCharArray(),
+ "OXOX".toCharArray(),
+ "XOXO".toCharArray(),
+ "OXOX".toCharArray()
+ };
+
+ solution.solve(board);
+
+ for (char[] line : board) {
+ System.out.println(new String(line));
+ }
+ System.out.println();
+ }
+
+ @Test
+ public void test03() {
+ Solution solution = new Solution();
+ char[][] board = {
+ "OO".toCharArray(),
+ "OO".toCharArray()
+ };
+
+ solution.solve(board);
+
+ for (char[] line : board) {
+ System.out.println(new String(line));
+ }
+ System.out.println();
+ }
+
+ @Test
+ public void test04() {
+ Solution solution = new Solution();
+ char[][] board = {
+ "OOO".toCharArray(),
+ "OOO".toCharArray(),
+ "OOO".toCharArray()
+ };
+
+ solution.solve(board);
+
+ for (char[] line : board) {
+ System.out.println(new String(line));
+ }
+ System.out.println();
+ }
+}
diff --git a/[0130][Surrounded Regions]/src/Solution.java b/[0130][Surrounded Regions]/src/Solution.java
new file mode 100644
index 0000000..4f7cf47
--- /dev/null
+++ b/[0130][Surrounded Regions]/src/Solution.java
@@ -0,0 +1,82 @@
+/**
+ * Author:
+ * Date: 2015-06-22
+ * Time: 08:51
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * 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.
+ *
+ * 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:
+ * X X X X
+ * X X X X
+ * X X X X
+ * X O X X
+ *
+ * Ŀ⣺
+ * һά'X''O'ԱXΧOX
+ * ˼·
+ * ȶȱķʽҳXΧOΪ$
+ *
+ *
+ * @param board
+ */
+ void solve(char[][] board) {
+
+ // У
+ if (board == null || board.length < 1 || board[0].length < 1) {
+ return;
+ }
+
+ // һк
+ for (int i = 0; i < board[0].length; i++) {
+ dfs(board, 0, i);
+ dfs(board, board.length - 1, i);
+ }
+
+ // һкһ
+ for (int i = 1; i < board.length - 1; i++) {
+ dfs(board, i, 0);
+ dfs(board, i, board[0].length - 1);
+ }
+
+
+ for (int i = 0; i < board.length; ++i) {
+ for (int j = 0; j < board[i].length; ++j) {
+ if (board[i][j] == 'O') {
+ board[i][j] = 'X';
+ }
+ if (board[i][j] == '$') {
+ board[i][j] = 'O';
+ }
+ }
+ }
+ }
+
+ void dfs(char[][] board, int i, int j) {
+ if (board[i][j] == 'O') {
+ board[i][j] = '$';
+ if (i > 0 && board[i - 1][j] == 'O') {
+ dfs(board, i - 1, j);
+ }
+ if (j < board[i].length - 1 && board[i][j + 1] == 'O') {
+ dfs(board, i, j + 1);
+ }
+ if (i < board.length - 1 && board[i + 1][j] == 'O') {
+ dfs(board, i + 1, j);
+ }
+ if (j > 1 && board[i][j - 1] == 'O') {
+ dfs(board, i, j - 1);
+ }
+ }
+ }
+}
diff --git a/[0130][Surrounded Regions]/src/Solution2.java b/[0130][Surrounded Regions]/src/Solution2.java
new file mode 100644
index 0000000..3308a10
--- /dev/null
+++ b/[0130][Surrounded Regions]/src/Solution2.java
@@ -0,0 +1,258 @@
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Author:
+ * Date: 2015-06-22
+ * Time: 08:51
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution2 {
+ /**
+ *
+ * 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.
+ *
+ * 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:
+ * X X X X
+ * X X X X
+ * X X X X
+ * X O X X
+ *
+ * Ŀ⣺
+ * һά'X''O'ԱXΧOX
+ * ˼·
+ * ùȱķʽҲԲóȵķʽջ,dzеıΧĵ㣬ʣµľDzΧĵ
+ *
+ * Given a string s, partition s such that every substring of the partition is a palindrome.
+ *
+ * Return all possible palindrome partitioning of s.
+ *
+ * Example:
+ *
+ * Input: "aab"
+ * Output:
+ * [
+ * ["aa","b"],
+ * ["a","a","b"]
+ * ]
+ *
+ * 解决方案:可以使用回溯法
+ * TODO : 可以构建一个回文表,再进行判定
+ *
+ *
+ * @param s
+ * @return
+ */
+ public List> partition(String s) {
+ List> result = new LinkedList<>();
+ Deque current = new LinkedList<>();
+
+ partition(s, 0, current, result);
+
+ return result;
+ }
+
+ private void partition(String s, int index, Deque current, List> result) {
+ if (index == s.length()) {
+ result.add(new LinkedList<>(current));
+ return;
+ }
+
+ for (int i = index; i < s.length(); i++) {
+ String t = s.substring(index, i + 1);
+ if (isPalindrome(s, index, i)) {
+ current.addLast(t);
+ partition(s, i + 1, current, result);
+ // 还原
+ current.removeLast();
+ }
+ }
+ }
+
+ private boolean isPalindrome(String s, int start, int end) {
+ while (start < end) {
+
+ if (s.charAt(start) != s.charAt(end)) {
+ return false;
+ } else {
+ start++;
+ end--;
+ }
+ }
+ return true;
+ }
+}
diff --git a/[0132][Palindrome Partitioning II]/[0132][Palindrome Partitioning II].iml b/[0132][Palindrome Partitioning II]/[0132][Palindrome Partitioning II].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0132][Palindrome Partitioning II]/[0132][Palindrome Partitioning II].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0132][Palindrome Partitioning II]/src/Solution.java b/[0132][Palindrome Partitioning II]/src/Solution.java
new file mode 100644
index 0000000..6eddbef
--- /dev/null
+++ b/[0132][Palindrome Partitioning II]/src/Solution.java
@@ -0,0 +1,56 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-24 19:22
+ **/
+public class Solution {
+ /**
+ *
+ * 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.
+ *
+ * Example:
+ *
+ * Input: "aab"
+ * Output: 1
+ * Explanation: The palindrome partitioning ["aa","b"] could be produced using 1 cut.
+ *
+ * 分析
+ * 定义状态f(i,j) 表示区间[i,j] 之间最小的cut 数,则状态转移方程为
+ * f(i; j) = min {f(i; k) + f(k + 1; j)} ; i k j; 0 i j < n
+ * 这是一个二维函数,实际写代码比较麻烦。
+ * 所以要转换成一维DP。如果每次,从i 往右扫描,每找到一个回文就算一次DP 的话,就可以
+ * 转换为f(i)= 区间[i, n-1] 之间最小的cut 数,n 为字符串长度,则状态转移方程为
+ * f(i) = min {f(j + 1) + 1} ; i <= j < n TODO 怎么理解?
+ * 一个问题出现了,就是如何判断[i,j] 是否是回文?每次都从i 到j 比较一遍?太浪费了,这
+ * 里也是一个DP 问题。
+ * 定义状态P[i][j] = true if [i,j] 为回文,那么
+ * P[i][j] = str[i] == str[j] && P[i+1][j-1]
+ *
+ * https://www.cnblogs.com/grandyang/p/4271456.html
+ *
+ *
+ * @param s
+ * @return
+ */
+ public int minCut(String s) {
+ final int n = s.length();
+
+ int[] dp = new int[n];
+ boolean[][] p = new boolean[n][];
+
+ for (int i = 0; i < n; ++i) {
+ dp[i] = i;
+ p[i] = new boolean[n];
+
+ for (int j = 0; j <= i; ++j) {
+ if (s.charAt(i) == s.charAt(j) && (i - j < 2 || p[j + 1][i - 1])) {
+ p[j][i] = true;
+ dp[i] = (j == 0) ? 0 : Math.min(dp[i], dp[j - 1] + 1);
+ }
+ }
+ }
+
+ return dp[n - 1];
+ }
+}
diff --git a/[0132][Palindrome Partitioning II]/src/Solution2.java b/[0132][Palindrome Partitioning II]/src/Solution2.java
new file mode 100644
index 0000000..c0611da
--- /dev/null
+++ b/[0132][Palindrome Partitioning II]/src/Solution2.java
@@ -0,0 +1,62 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-24 19:22
+ **/
+public class Solution2 {
+ /**
+ *
+ * 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.
+ *
+ * Example:
+ *
+ * Input: "aab"
+ * Output: 1
+ * Explanation: The palindrome partitioning ["aa","b"] could be produced using 1 cut.
+ *
+ * 分析
+ * 定义状态f(i,j) 表示区间[i,j] 之间最小的cut 数,则状态转移方程为
+ * f(i; j) = min {f(i; k) + f(k + 1; j)} ; i k j; 0 i j < n
+ * 这是一个二维函数,实际写代码比较麻烦。
+ * 所以要转换成一维DP。如果每次,从i 往右扫描,每找到一个回文就算一次DP 的话,就可以
+ * 转换为f(i)= 区间[i, n-1] 之间最小的cut 数,n 为字符串长度,则状态转移方程为
+ * f(i) = min {f(j + 1) + 1} ; i <= j < n TODO 怎么理解?
+ * 一个问题出现了,就是如何判断[i,j] 是否是回文?每次都从i 到j 比较一遍?太浪费了,这
+ * 里也是一个DP 问题。
+ * 定义状态P[i][j] = true if [i,j] 为回文,那么
+ * P[i][j] = str[i] == str[j] && P[i+1][j-1]
+ *
+ * https://www.cnblogs.com/grandyang/p/4271456.html
+ *
+ *
+ * @param s
+ * @return
+ */
+ public int minCut(String s) {
+ final int n = s.length();
+
+ int[] f = new int[n + 1];
+ boolean[][] p = new boolean[n][];
+ //the worst case is cutting by each char
+ // 最后一个f[n]=-1
+ for (int i = 0; i <= n; i++) {
+ // [n-1, n-2, ..., 1, 0, -1],为了后面做切分
+ f[i] = n - 1 - i;
+ }
+ for (int i = n - 1; i >= 0; i--) {
+ p[i] = new boolean[n];
+
+ for (int j = i; j < n; j++) {
+ // j - i < 2 : 表示j在i位置或者j在i之后一个位置
+ // p[i + 1][j - 1] : [i+1, j-1]是回文
+ if (s.charAt(i) == s.charAt(j) && (j - i < 2 || p[i + 1][j - 1])) {
+ p[i][j] = true;
+ f[i] = Math.min(f[i], f[j + 1] + 1);
+ }
+ }
+ }
+
+ return f[0];
+ }
+}
diff --git a/[0134][Gas Station]/[0134][Gas Station].iml b/[0134][Gas Station]/[0134][Gas Station].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0134][Gas Station]/[0134][Gas Station].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0134][Gas Station]/[0134][GasStation].iml b/[0134][Gas Station]/[0134][GasStation].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0134][Gas Station]/[0134][GasStation].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0134][Gas Station]/src/Main.java b/[0134][Gas Station]/src/Main.java
new file mode 100644
index 0000000..250a219
--- /dev/null
+++ b/[0134][Gas Station]/src/Main.java
@@ -0,0 +1,17 @@
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-16 11:06
+ **/
+public class Main {
+ @Test
+ public void test1() {
+ Solution solution = new Solution();
+ int[] gas = {1, 2, 3, 4, 5};
+ int[] cost = {3, 4, 5, 1, 2};
+ int pos = solution.canCompleteCircuit(gas, cost);
+ Assert.assertEquals(3, pos);
+ }
+}
diff --git a/[0134][Gas Station]/src/Solution.java b/[0134][Gas Station]/src/Solution.java
new file mode 100644
index 0000000..213926c
--- /dev/null
+++ b/[0134][Gas Station]/src/Solution.java
@@ -0,0 +1,146 @@
+/**
+ * Author:
+ * Date: 2015-06-21
+ * Time: 10:11
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * 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.
+ *
+ * Ŀ⣺
+ * ػ·Nվڳվigas[i]
+ * гޣӼվiһվվi+1Ҫcost[i]塣
+ * 㿪ʼóʱǿյġصʼվָѡһ㿪ʼΣ
+ * ΧһΣͷؿʼļվ-1
+ *
+ * ע⣺
+ * - 𰸱֤Ψһ
+ *
+ * ˼·
+ * վ i վ k ֮ǰȻܱ֤ûk ˡ
+ * ô˵ diff[i] + diff[i+1] + ... + diff[k] < 0diff[k]⣬diff[i]
+ * ʼۼӶ >= 0ġҲ˵diff[i] Ҳ >= 0ģʱǻбҪվ i + 1
+ * ϸһ֪ҪǴվ i+1վkûվkͼ
+ * ˣΪټվ i ͡
+ *
+ * ˣǷֵk վi k Щվ㶼Ϊˣ϶
+ * ֻҪk+1վ㳢Լɣ˽ⷨʱ临ӶȴO(n2) O(2n)֮
+ * O(2n)Ϊk+1վΪʼվȦk֤k+1Ƿ㡣
+ *
+ * ȵȣҪ
+ * ģһ¹̣
+ * a. ʼվ0ʼվ賵վpˣ
+ * sum1 = diff[0] +diff[1] + ... + diff[p]֪sum1 < 0
+ *
+ * b. ǽp+1Ϊʼվqվֿˣ
+ * sum2 = diff[p+1] +diff[p+2] + ... + diff[q]֪sum2 < 0
+ *
+ * c. q+1Ϊʼվһֱδѭĩվû
+ * sum3 = diff[q+1] +diff[q+2] + ... + diff[size-1]֪sum3 >= 0
+ *
+ * Ҫ֪ܷ q վʵsum3 Ļϣμ diff[0] diff[q]
+ * sum3ǷС0֮ǰѾ֪ diff[0] diff[p-1] ·
+ * һֱַǸֻҪsum3 + sum1Ƿ <0֪ܲܿ p+1վˡ
+ * ܴp+1վֻҪsum3 + sum1 + sum2 Ƿ < 0֪ܲܿqվˡ
+ *
+ * Ϊ sum1, sum2 < 0 sum3 + sum1 + sum2 >=0 ô
+ * sum3 + sum1 Ȼ >= 0Ҳ˵ֻҪsum3 + sum1 + sum2 >=0Ȼܿqվ
+ * sum3 + sum1 + sum2 ʵ diffܺ TotalԪѾˡ
+ * Total ܷ >= 0Ƿվ ֱҪ
+ *
+ * ʱ临ӶȽһO(2n) O(n)
+ *
+ *
+ * @param gas
+ * @param cost
+ * @return
+ */
+ public int canCompleteCircuit(int[] gas, int[] cost) {
+ //
+ if (gas == null || cost == null || gas.length == 0 || gas.length != cost.length) {
+ return -1;
+ }
+
+ // ¼ʵʼ
+ int start = 0;
+ // ӵĵֵܲ
+ int total = 0;
+ // startλÿʼӵĵֵܲ
+ int sum = 0;
+
+ for (int i = 0; i < gas.length; i++) {
+ total += (gas[i] - cost[i]);
+
+ // û
+ if (sum < 0) {
+ // е
+ sum = gas[i] - cost[i];
+ // ¼µλ
+ start = i;
+ } else {
+ // лͣе
+ sum += (gas[i] - cost[i]);
+ }
+ }
+
+ return total >= 0 ? start : -1;
+ }
+
+
+ /**
+ * ķᳬʱO(N^2)ʱ临Ӷ
+ */
+ public int canCompleteCircuit2(int[] gas, int[] cost) {
+ //
+ if (gas == null || cost == null || gas.length == 0 || gas.length != cost.length) {
+ return -1;
+ }
+
+ // ʣµ壬ʼʱΪ0
+ int leftGas = 0;
+ // ʼվ
+ int start = 0;
+ // վ
+ int end = 1;
+
+ // δһ
+ while (start < gas.length) {
+
+ // һվ
+ leftGas = gas[start] - cost[start];
+
+ // ߵһվ
+ if (leftGas > 0) {
+ // ¼һվ
+ end = (start + 1) % gas.length;
+
+ // һֱԵһվͳв
+ while (start != end && (leftGas += (gas[end] - cost[end])) >= 0) {
+ end = (end + 1) % gas.length;
+ }
+
+ // ˵Ѿһ
+ if (start == end) {
+ return start;
+ }
+ }
+
+ start++;
+ }
+
+ return -1;
+ }
+}
diff --git a/[0135][Candy]/[0135][Candy].iml b/[0135][Candy]/[0135][Candy].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0135][Candy]/[0135][Candy].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0135][Candy]/src/Main.java b/[0135][Candy]/src/Main.java
new file mode 100644
index 0000000..54ea1af
--- /dev/null
+++ b/[0135][Candy]/src/Main.java
@@ -0,0 +1,14 @@
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-16 11:37
+ **/
+public class Main {
+ @Test
+ public void test1() {
+ Solution solution = new Solution();
+ Assert.assertEquals(5, solution.candy(new int[]{1, 0, 2}));
+ }
+}
diff --git a/[0135][Candy]/src/Solution.java b/[0135][Candy]/src/Solution.java
new file mode 100644
index 0000000..ea602e0
--- /dev/null
+++ b/[0135][Candy]/src/Solution.java
@@ -0,0 +1,77 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-16 11:27
+ **/
+public class Solution {
+ /**
+ *
+ * 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:
+ *
+ * 1. Each child must have at least one candy.
+ * 2. Children with a higher rating get more candies than their neighbors.
+ * What is the minimum candies you must give?
+ *
+ * Example 1:
+ *
+ * Input: [1,0,2]
+ * Output: 5
+ * Explanation: You can allocate to the first, second and third child with 2, 1, 2 candies respectively.
+ * Example 2:
+ *
+ * Input: [1,2,2]
+ * Output: 4
+ * Explanation: You can allocate to the first, second and third child with 1, 2, 1 candies respectively.
+ * The third child gets 1 candy because it satisfies the above two conditions.
+ *
+ *
+ * @param ratings
+ * @return
+ */
+ public int candy(int[] ratings) {
+ if (ratings == null || ratings.length < 1) {
+ return 0;
+ }
+
+
+ int[] increment = new int[ratings.length];
+ // 左右各扫描一遍
+ for (int i = 1, inc = 1; i < ratings.length; i++) {
+ // 右边的孩子分数比左边的孩子分数高
+ if (ratings[i] > ratings[i - 1]) {
+ // 右边的孩子比左边的孩子多发至少一个糖果
+ increment[i] = increment[i - 1] + 1;
+ }
+// // 右边的孩子分数与左边的孩子分数相等,相等可以少发
+// else if (ratings[i] == ratings[i - 1]) {
+// // 右边和左边的孩子增同样多颗糖
+// increment[i] = increment[i - 1];
+// }
+ // 可以不处理
+// else{
+// increment[i] = 0;
+// }
+ }
+
+ // 从右到左进行处理
+ for (int i = ratings.length - 2, inc = 1; i >= 0; i--) {
+ // 左边的孩子分数比右边高
+ if (ratings[i] > ratings[i + 1]) {
+ increment[i] = Math.max(increment[i], increment[i + 1] + 1);
+ }
+ //
+// else if (ratings[i] == ratings[i + 1]) {
+// // 总是成立了
+// increment[i] = increment[i - 1];
+// }
+ // ratings[i] < ratings[i + 1] 不需要操作
+ }
+
+ int sum = ratings.length;
+ for (int n : increment) {
+ sum += n;
+ }
+ return sum;
+ }
+}
diff --git a/[0136][Single Number]/[0136][Single Number].iml b/[0136][Single Number]/[0136][Single Number].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0136][Single Number]/[0136][Single Number].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0136][Single Number]/src/Solution.java b/[0136][Single Number]/src/Solution.java
new file mode 100644
index 0000000..b32b8a7
--- /dev/null
+++ b/[0136][Single Number]/src/Solution.java
@@ -0,0 +1,35 @@
+/**
+ * Author:
+ * Date: 2015-06-18
+ * Time: 10:29
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ * 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?
+ *
+ * һ飬ÿԪض2γеһҳֻһε
+ * ע⣺㷨ʱ临ӶȣԲʹöռʵ
+ *
+ * ˼·ʹ
+ *
+ * @param nums
+ * @return
+ */
+ public int singleNumber(int[] nums) {
+
+ if (nums == null || nums.length < 1) {
+ throw new IllegalArgumentException("nums should contain at least one element");
+ }
+
+
+ for (int i = 1; i < nums.length; i++) {
+ nums[0] ^= nums[i];
+ }
+ return nums[0];
+ }
+}
diff --git a/[0137][Single Number II]/[0137][Single Number II].iml b/[0137][Single Number II]/[0137][Single Number II].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0137][Single Number II]/[0137][Single Number II].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220137\343\200\221\343\200\220SingleNumberII\343\200\221/src/Solution.java" b/[0137][Single Number II]/src/Solution.java
similarity index 100%
rename from "\343\200\220137\343\200\221\343\200\220SingleNumberII\343\200\221/src/Solution.java"
rename to [0137][Single Number II]/src/Solution.java
diff --git a/[0138][Copy List With Random Pointer]/[0138][Copy List With Random Pointer].iml b/[0138][Copy List With Random Pointer]/[0138][Copy List With Random Pointer].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0138][Copy List With Random Pointer]/[0138][Copy List With Random Pointer].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0138][Copy List With Random Pointer]/src/Main.java b/[0138][Copy List With Random Pointer]/src/Main.java
new file mode 100644
index 0000000..92f5099
--- /dev/null
+++ b/[0138][Copy List With Random Pointer]/src/Main.java
@@ -0,0 +1,32 @@
+/**
+ * Author: ������
+ * Date: 2015-06-24
+ * Time: 09:18
+ * Declaration: All Rights Reserved !!!
+ */
+public class Main {
+ public static void main(String[] args) {
+ RandomListNode n1 = new RandomListNode(1);
+ RandomListNode n2 = new RandomListNode(2);
+ RandomListNode n3 = new RandomListNode(3);
+ RandomListNode n4 = new RandomListNode(4);
+ n1.next = n2;
+ n2.next = n3;
+ n3.next = n4;
+
+ Solution solution = new Solution();
+ RandomListNode copy = solution.copyRandomList(n1);
+
+ print(copy);
+
+ }
+
+ public static void print(RandomListNode head) {
+ while (head != null) {
+ System.out.print(head.label + "->");
+ head = head.next;
+ }
+
+ System.out.println("null");
+ }
+}
diff --git "a/\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/src/RandomListNode.java" b/[0138][Copy List With Random Pointer]/src/RandomListNode.java
similarity index 100%
rename from "\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/src/RandomListNode.java"
rename to [0138][Copy List With Random Pointer]/src/RandomListNode.java
diff --git a/[0138][Copy List With Random Pointer]/src/Solution.java b/[0138][Copy List With Random Pointer]/src/Solution.java
new file mode 100644
index 0000000..f392526
--- /dev/null
+++ b/[0138][Copy List With Random Pointer]/src/Solution.java
@@ -0,0 +1,108 @@
+/**
+ * Author:
+ * Date: 2015-06-24
+ * Time: 08:48
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * 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.
+ *
+ * Ŀ⣺
+ * һһָnullĽָ룬
+ *
+ * ˼·
+ * һƽ㣬ƵĽڴƵĽȻһ
+ * ڶָ
+ * ָƺ
+ *
+ *
+ * @param head
+ * @return
+ */
+ public RandomListNode copyRandomList(RandomListNode head) {
+ if (head == null) {
+ return null;
+ }
+
+ copyNode(head);
+ linkRandomPointer(head);
+
+ return splitList(head);
+ }
+
+ /**
+ * ƽ㣬ƵĽڴƵĽȻһ
+ *
+ * @param head ͷ
+ */
+ public void copyNode(RandomListNode head) {
+ // ¼ǰҪƵ
+ RandomListNode node = head;
+ while (node != null) {
+ // һµĽ
+ RandomListNode copyNode = new RandomListNode(node.label);
+ // 㴮ӵƵĽȻɵ
+ copyNode.next = node.next;
+ node.next = copyNode;
+ node = copyNode.next;
+ }
+ }
+
+ /**
+ * ָ
+ *
+ * @param head ͷ
+ */
+ public void linkRandomPointer(RandomListNode head) {
+ // ¼ǰҪƵ
+ RandomListNode node = head;
+ while (node != null) {
+ // ָָijĽ
+ if (node.random != null) {
+ // nodeƽָ
+ node.next.random = node.random.next;
+ }
+
+ // ָһƵĽ
+ node = node.next.next;
+ }
+ }
+
+ /**
+ * ֣ԭԭװ
+ *
+ * @param head ͷ
+ * @return ͷ
+ */
+ public RandomListNode splitList(RandomListNode head) {
+ // ͷ
+ RandomListNode copyHead = head.next;
+ // ǰıƵĽ
+ RandomListNode node = head;
+ // ǰƵĽ
+ RandomListNode copy;
+
+ while (node != null) {
+ // ָƽ
+ copy = node.next;
+
+ // node.nextָһƵĽ
+ node.next = copy.next;
+
+ // һƵĽ㲻Ϊnull
+ if (node.next != null) {
+ // copy.nextָһƵĽ
+ copy.next = node.next.next;
+ }
+
+ // nodeָһҪıƽ
+ node = node.next;
+ }
+ return copyHead;
+ }
+}
diff --git a/[0139][Word Break]/[0139][Word Break].iml b/[0139][Word Break]/[0139][Word Break].iml
new file mode 100644
index 0000000..73f33e3
--- /dev/null
+++ b/[0139][Word Break]/[0139][Word Break].iml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0139][Word Break]/src/Main.java b/[0139][Word Break]/src/Main.java
new file mode 100644
index 0000000..adb7df9
--- /dev/null
+++ b/[0139][Word Break]/src/Main.java
@@ -0,0 +1,59 @@
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Author:
+ * Date: 2015-06-21
+ * Time: 08:48
+ * Declaration: All Rights Reserved !!!
+ */
+public class Main {
+
+
+ @Test
+ public void test01() {
+ Solution solution = new Solution();
+ Set set = new HashSet<>();
+ set.add("leet");
+ set.add("code");
+ System.out.println(solution.wordBreak("leetcode", set));
+ }
+
+ @Test
+ public void test02() {
+ Solution solution = new Solution();
+ Set set = new HashSet<>();
+ System.out.println(solution.wordBreak("a", set));
+ }
+
+ @Test
+ public void test03() {
+ Solution solution = new Solution();
+ Set set = new HashSet<>();
+ set.add("b");
+ set.add("a");
+ set.add("aa");
+ set.add("aaa");
+ set.add("aaaa");
+ set.add("aaaaa");
+ set.add("aaaaaa");
+ set.add("aaaaaaa");
+ set.add("aaaaaaaa");
+ set.add("aaaaaaaaa");
+ set.add("aaaaaaaaaa");
+ System.out.println(solution.wordBreak("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
+ "aaaaaaaaaaaaaaaaaaaaaaaaab", set));
+ }
+
+ @Test
+ public void test04() {
+ Solution solution = new Solution();
+ Set set = new HashSet<>(Arrays.asList("cats", "dog", "sand", "and", "cat"));
+
+ System.out.println(solution.wordBreak("catsandog", set));
+ }
+}
diff --git "a/\343\200\220139\343\200\221\343\200\220WordBreak\343\200\221/src/Solution.java" b/[0139][Word Break]/src/Solution.java
similarity index 100%
rename from "\343\200\220139\343\200\221\343\200\220WordBreak\343\200\221/src/Solution.java"
rename to [0139][Word Break]/src/Solution.java
diff --git a/[0141][Linked List Cycle]/[0141][Linked List Cycle].iml b/[0141][Linked List Cycle]/[0141][Linked List Cycle].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0141][Linked List Cycle]/[0141][Linked List Cycle].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0141][Linked List Cycle]/src/ListNode.java b/[0141][Linked List Cycle]/src/ListNode.java
new file mode 100644
index 0000000..8892796
--- /dev/null
+++ b/[0141][Linked List Cycle]/src/ListNode.java
@@ -0,0 +1,15 @@
+/**
+ * Author: ������
+ * Date: 2015-08-21
+ * Time: 19:17
+ * Declaration: All Rights Reserved !!!
+ */
+public class ListNode {
+ int val;
+ ListNode next;
+
+ ListNode(int x) {
+ val = x;
+ next = null;
+ }
+}
diff --git a/[0141][Linked List Cycle]/src/Solution.java b/[0141][Linked List Cycle]/src/Solution.java
new file mode 100644
index 0000000..1bac274
--- /dev/null
+++ b/[0141][Linked List Cycle]/src/Solution.java
@@ -0,0 +1,57 @@
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 19:16
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * ԭ
+ * Given a linked list, determine if it has a cycle in it.
+ * Follow up:
+ * Can you solve it without using extra space?
+ *
+ * Ŀ
+ * һжǷл
+ *
+ * ˼·
+ * ָ(fast, slow)ʼֵָͷslowÿǰһfastÿǰڻ
+ * fastضȽ뻷slow뻷ָض
+ *
+ *
+ * @param head
+ * @return
+ */
+ public boolean hasCycle(ListNode head) {
+
+ ListNode fast = head;
+ ListNode slow = head;
+
+ while (fast != null && fast.next != null) {
+ fast = fast.next.next;
+ slow = slow.next;
+ if (slow == fast) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public boolean hasCycle2(ListNode head) {
+
+ ListNode fast = head;
+ ListNode slow = head;
+
+ while (fast != null && fast.next != null) {
+ fast = fast.next.next;
+ slow = slow.next;
+ if (slow == fast) {
+ break;
+ }
+ }
+
+ return !(fast == null || fast.next == null);
+ }
+}
diff --git a/[0142][Linked List Cycle II]/[0142][Linked List Cycle II].iml b/[0142][Linked List Cycle II]/[0142][Linked List Cycle II].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0142][Linked List Cycle II]/[0142][Linked List Cycle II].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0142][Linked List Cycle II]/[0142][LinkedListCycleII].iml b/[0142][Linked List Cycle II]/[0142][LinkedListCycleII].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0142][Linked List Cycle II]/[0142][LinkedListCycleII].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0142][Linked List Cycle II]/src/ListNode.java b/[0142][Linked List Cycle II]/src/ListNode.java
new file mode 100644
index 0000000..c9da456
--- /dev/null
+++ b/[0142][Linked List Cycle II]/src/ListNode.java
@@ -0,0 +1,15 @@
+/**
+ * Author: ������
+ * Date: 2015-08-21
+ * Time: 19:19
+ * Declaration: All Rights Reserved !!!
+ */
+public class ListNode {
+ int val;
+ ListNode next;
+
+ ListNode(int x) {
+ val = x;
+ next = null;
+ }
+}
diff --git "a/\343\200\220142\343\200\221\343\200\220LinkedListCycleII\343\200\221/src/Solution.java" b/[0142][Linked List Cycle II]/src/Solution.java
similarity index 100%
rename from "\343\200\220142\343\200\221\343\200\220LinkedListCycleII\343\200\221/src/Solution.java"
rename to [0142][Linked List Cycle II]/src/Solution.java
diff --git a/[0143][Reorder List]/[0143][CopyListWithRandomPointer].iml b/[0143][Reorder List]/[0143][CopyListWithRandomPointer].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0143][Reorder List]/[0143][CopyListWithRandomPointer].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0143][Reorder List]/[0143][Reorder List].iml b/[0143][Reorder List]/[0143][Reorder List].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0143][Reorder List]/[0143][Reorder List].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0143][Reorder List]/src/ListNode.java b/[0143][Reorder List]/src/ListNode.java
new file mode 100644
index 0000000..dc97875
--- /dev/null
+++ b/[0143][Reorder List]/src/ListNode.java
@@ -0,0 +1,14 @@
+/**
+ * Author: 王俊超
+ * Date: 2015-08-21
+ * Time: 19:22
+ * Declaration: All Rights Reserved !!!
+ */
+public class ListNode {
+ int val;
+ ListNode next;
+
+ ListNode(int x) {
+ val = x;
+ }
+}
diff --git a/[0143][Reorder List]/src/Solution.java b/[0143][Reorder List]/src/Solution.java
new file mode 100644
index 0000000..c4f61a9
--- /dev/null
+++ b/[0143][Reorder List]/src/Solution.java
@@ -0,0 +1,79 @@
+/**
+ * Author:
+ * Date: 2015-08-21
+ * Time: 19:21
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * Given a singly linked list L: L0L1Ln-1Ln,
+ * reorder it to: L0LnL1Ln-1L2Ln-2
+ *
+ * You may not modify the values in the list's nodes, only nodes itself may be changed.
+ *
+ * Example 1:
+ *
+ * Given 1->2->3->4, reorder it to 1->4->2->3.
+ * Example 2:
+ *
+ * Given 1->2->3->4->5, reorder it to 1->5->2->4->3.
+ *
+ * ˼·
+ * 1ҵм
+ * 2㣬ͽм֮в֣
+ *
+ *
+ *
+ * @param head
+ */
+ public void reorderList(ListNode head) {
+ if (head == null || head.next == null) {
+ return;
+ }
+
+ ListNode root = new ListNode(-1);
+ root.next = head;
+ ListNode fast = head;
+ // мǰ
+ ListNode slow = root;
+
+ while (fast != null && fast.next != null) {
+ fast = fast.next.next;
+ slow = slow.next;
+ }
+
+ // ˵żڵ
+ if (fast == null) {
+ root.next = slow.next;
+ slow.next = null;
+
+ } else { //
+ slow = slow.next;
+ root.next = slow.next;
+ slow.next = null;
+ }
+
+ // һҪͷ巨
+ fast = root.next;
+ ListNode tmp;
+ // 벿
+ while (fast.next != null) {
+ tmp = fast.next;
+ fast.next = tmp.next;
+ tmp.next = root.next;
+ root.next = tmp;
+ }
+
+ slow = head;
+ fast = root.next;
+
+ while (fast != null) {
+ tmp = fast.next;
+ fast.next = slow.next;
+ slow.next = fast;
+ slow = slow.next.next;
+ fast = tmp;
+ }
+ }
+}
diff --git a/[0144][Binary Tree Preorder Traversal]/[0144][Binary Tree Preorder Traversal].iml b/[0144][Binary Tree Preorder Traversal]/[0144][Binary Tree Preorder Traversal].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0144][Binary Tree Preorder Traversal]/[0144][Binary Tree Preorder Traversal].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220144\343\200\221\343\200\220BinaryTreePreorderTraversal\343\200\221/src/Solution.java" b/[0144][Binary Tree Preorder Traversal]/src/Solution.java
similarity index 100%
rename from "\343\200\220144\343\200\221\343\200\220BinaryTreePreorderTraversal\343\200\221/src/Solution.java"
rename to [0144][Binary Tree Preorder Traversal]/src/Solution.java
diff --git "a/\343\200\220144\343\200\221\343\200\220BinaryTreePreorderTraversal\343\200\221/src/TreeNode.java" b/[0144][Binary Tree Preorder Traversal]/src/TreeNode.java
similarity index 100%
rename from "\343\200\220144\343\200\221\343\200\220BinaryTreePreorderTraversal\343\200\221/src/TreeNode.java"
rename to [0144][Binary Tree Preorder Traversal]/src/TreeNode.java
diff --git a/[0145][Binary Tree Postorder Traversal]/[0145][Binary Tree Postorder Traversal].iml b/[0145][Binary Tree Postorder Traversal]/[0145][Binary Tree Postorder Traversal].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0145][Binary Tree Postorder Traversal]/[0145][Binary Tree Postorder Traversal].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0145][Binary Tree Postorder Traversal]/[0145][BinaryTreePostorderTraversal].iml b/[0145][Binary Tree Postorder Traversal]/[0145][BinaryTreePostorderTraversal].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0145][Binary Tree Postorder Traversal]/[0145][BinaryTreePostorderTraversal].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0145][Binary Tree Postorder Traversal]/src/Solution.java b/[0145][Binary Tree Postorder Traversal]/src/Solution.java
new file mode 100644
index 0000000..2adec07
--- /dev/null
+++ b/[0145][Binary Tree Postorder Traversal]/src/Solution.java
@@ -0,0 +1,93 @@
+import java.util.Deque;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Author:
+ * Date: 2015-06-22
+ * Time: 14:54
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * 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].
+ *
+ * Note: Recursive solution is trivial, could you do it iteratively?
+ *
+ * Ŀ⣺
+ * һŶĺĽֵ
+ *
+ * ע⣺
+ * - ݹⷨף볢ʽ
+ *
+ * ˼·
+ * ǵݹ
+ * ݺ˳ȷٷʸڵ㣬ÿ˵
+ * ְͬķ˳бķǵݹʵ˵ҪһЩҪ֤
+ * ʺܷʣ˼·£
+ *
+ * һڵP
+ * 1ȽڵPջ
+ * 2PӺҺӣPӻҺӣҺѾ
+ * ֱڵPջջڵPΪһĽڵ㣬ٽʱ
+ * ջΪǰڵ㣻
+ * 32еPҺӺջǰڵΪջ㣬
+ * ֮ظ2
+ * 4ֱջգ
+ *
+ * Design and implement a data structure for Least Recently Used (LRU) cache.
+ * It should support the following operations: get and put.
+ *
+ * get(key) - Get the value (will always be positive) of the key if the key exists
+ * in the cache, otherwise return -1.
+ * put(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.
+ *
+ * The cache is initialized with a positive capacity.
+ *
+ * Follow up:
+ * Could you do both operations in O(1) time complexity?
+ *
+ * Example:
+ *
+ * LRUCache cache = new LRUCache( 2 );// capacity
+ *
+ * cache.put(1,1);
+ * cache.put(2,2);
+ * cache.get(1); // returns 1
+ * cache.put(3,3); // evicts key 2
+ * cache.get(2); // returns -1 (not found)
+ * cache.put(4,4); // evicts key 1
+ * cache.get(1); // returns -1 (not found)
+ * cache.get(3); // returns 3
+ * cache.get(4); // returns 4
+ *
+ * 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
+ *
+ * Ŀ⣺
+ * 沨ʽֵЧǣ+-*/ÿҪôһҪôһʽ
+ *
+ * ˼·
+ * ʹջв
+ *
+ *
+ * @param tokens
+ * @return
+ */
+ public int evalRPN(String[] tokens) {
+ // У
+ if (tokens == null || tokens.length < 1) {
+ throw new IllegalArgumentException();
+ }
+
+ int op1;
+ int op2;
+ // ջ
+ Stack stack = new Stack<>();
+
+ for (String token : tokens) {
+ // ˵ҪȡջԪؽ
+ if ("+".equals(token) || "-".equals(token) || "*".equals(token) || "/".equals(token)) {
+ // ȡջԪ
+ op2 = stack.pop();
+ op1 = stack.pop();
+
+ //
+ switch (token.charAt(0)) {
+ case '+':
+ op1 += op2;
+ break;
+ case '-':
+ op1 -= op2;
+ break;
+ case '*':
+ op1 *= op2;
+ break;
+ case '/':
+ op1 /= op2;
+ break;
+ }
+ // ջ
+ stack.push(op1);
+ }
+ // ˵Dzջ
+ else {
+ stack.push(Integer.parseInt(token));
+ }
+ }
+
+ // ջֻʣһԪأǾĽ
+ return stack.pop();
+ }
+}
diff --git a/[0151][Reverse Words In A String]/[0151][Reverse Words In A String].iml b/[0151][Reverse Words In A String]/[0151][Reverse Words In A String].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0151][Reverse Words In A String]/[0151][Reverse Words In A String].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0151][Reverse Words In A String]/[0151][ReverseWordsInAString].iml b/[0151][Reverse Words In A String]/[0151][ReverseWordsInAString].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0151][Reverse Words In A String]/[0151][ReverseWordsInAString].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220151\343\200\221\343\200\220ReverseWordsInAString\343\200\221/src/Main.java" b/[0151][Reverse Words In A String]/src/Main.java
similarity index 100%
rename from "\343\200\220151\343\200\221\343\200\220ReverseWordsInAString\343\200\221/src/Main.java"
rename to [0151][Reverse Words In A String]/src/Main.java
diff --git "a/\343\200\220151\343\200\221\343\200\220ReverseWordsInAString\343\200\221/src/Solution.java" b/[0151][Reverse Words In A String]/src/Solution.java
similarity index 100%
rename from "\343\200\220151\343\200\221\343\200\220ReverseWordsInAString\343\200\221/src/Solution.java"
rename to [0151][Reverse Words In A String]/src/Solution.java
diff --git a/[0152][Maximum Product Subarray]/[0152][Maximum Product Subarray].iml b/[0152][Maximum Product Subarray]/[0152][Maximum Product Subarray].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0152][Maximum Product Subarray]/[0152][Maximum Product Subarray].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0152][Maximum Product Subarray]/[0152][MaximumProductSubarray].iml b/[0152][Maximum Product Subarray]/[0152][MaximumProductSubarray].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0152][Maximum Product Subarray]/[0152][MaximumProductSubarray].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220152\343\200\221\343\200\220MaximumProductSubarray\343\200\221/src/Main.java" b/[0152][Maximum Product Subarray]/src/Main.java
similarity index 100%
rename from "\343\200\220152\343\200\221\343\200\220MaximumProductSubarray\343\200\221/src/Main.java"
rename to [0152][Maximum Product Subarray]/src/Main.java
diff --git "a/\343\200\220152\343\200\221\343\200\220MaximumProductSubarray\343\200\221/src/Solution.java" b/[0152][Maximum Product Subarray]/src/Solution.java
similarity index 100%
rename from "\343\200\220152\343\200\221\343\200\220MaximumProductSubarray\343\200\221/src/Solution.java"
rename to [0152][Maximum Product Subarray]/src/Solution.java
diff --git a/[0153][Find Minimum In Rotated Sorted Array]/[0153][Find Minimum In Rotated Sorted Array].iml b/[0153][Find Minimum In Rotated Sorted Array]/[0153][Find Minimum In Rotated Sorted Array].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0153][Find Minimum In Rotated Sorted Array]/[0153][Find Minimum In Rotated Sorted Array].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0153][Find Minimum In Rotated Sorted Array]/[0153][FindMinimumInRotatedSortedArray].iml b/[0153][Find Minimum In Rotated Sorted Array]/[0153][FindMinimumInRotatedSortedArray].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0153][Find Minimum In Rotated Sorted Array]/[0153][FindMinimumInRotatedSortedArray].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220153\343\200\221\343\200\220FindMinimumInRotatedSortedArray\343\200\221/src/Main.java" b/[0153][Find Minimum In Rotated Sorted Array]/src/Main.java
similarity index 100%
rename from "\343\200\220153\343\200\221\343\200\220FindMinimumInRotatedSortedArray\343\200\221/src/Main.java"
rename to [0153][Find Minimum In Rotated Sorted Array]/src/Main.java
diff --git "a/\343\200\220153\343\200\221\343\200\220FindMinimumInRotatedSortedArray\343\200\221/src/Solution.java" b/[0153][Find Minimum In Rotated Sorted Array]/src/Solution.java
similarity index 100%
rename from "\343\200\220153\343\200\221\343\200\220FindMinimumInRotatedSortedArray\343\200\221/src/Solution.java"
rename to [0153][Find Minimum In Rotated Sorted Array]/src/Solution.java
diff --git a/[0154][Find Minimum In Rotated Sorted Array II]/[0154][Find Minimum In Rotated Sorted Array II].iml b/[0154][Find Minimum In Rotated Sorted Array II]/[0154][Find Minimum In Rotated Sorted Array II].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0154][Find Minimum In Rotated Sorted Array II]/[0154][Find Minimum In Rotated Sorted Array II].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0154][Find Minimum In Rotated Sorted Array II]/[0154][FindMinimumInRotatedSortedArrayII].iml b/[0154][Find Minimum In Rotated Sorted Array II]/[0154][FindMinimumInRotatedSortedArrayII].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0154][Find Minimum In Rotated Sorted Array II]/[0154][FindMinimumInRotatedSortedArrayII].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220154\343\200\221\343\200\220FindMinimumInRotatedSortedArrayII\343\200\221/src/Main.java" b/[0154][Find Minimum In Rotated Sorted Array II]/src/Main.java
similarity index 100%
rename from "\343\200\220154\343\200\221\343\200\220FindMinimumInRotatedSortedArrayII\343\200\221/src/Main.java"
rename to [0154][Find Minimum In Rotated Sorted Array II]/src/Main.java
diff --git "a/\343\200\220154\343\200\221\343\200\220FindMinimumInRotatedSortedArrayII\343\200\221/src/Solution.java" b/[0154][Find Minimum In Rotated Sorted Array II]/src/Solution.java
similarity index 100%
rename from "\343\200\220154\343\200\221\343\200\220FindMinimumInRotatedSortedArrayII\343\200\221/src/Solution.java"
rename to [0154][Find Minimum In Rotated Sorted Array II]/src/Solution.java
diff --git a/[0155][Min Stack]/[0155][Min Stack].iml b/[0155][Min Stack]/[0155][Min Stack].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0155][Min Stack]/[0155][Min Stack].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0155][Min Stack]/[0155][MinStack].iml b/[0155][Min Stack]/[0155][MinStack].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0155][Min Stack]/[0155][MinStack].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220155\343\200\221\343\200\220MinStack\343\200\221/src/MinStack.java" b/[0155][Min Stack]/src/MinStack.java
similarity index 100%
rename from "\343\200\220155\343\200\221\343\200\220MinStack\343\200\221/src/MinStack.java"
rename to [0155][Min Stack]/src/MinStack.java
diff --git "a/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221.iml" b/[0160][Intersection of Two Linked Lists]/[0160][Intersection of Two Linked Lists].iml
similarity index 100%
rename from "\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221.iml"
rename to [0160][Intersection of Two Linked Lists]/[0160][Intersection of Two Linked Lists].iml
diff --git a/[0160][Intersection of Two Linked Lists]/src/ListNode.java b/[0160][Intersection of Two Linked Lists]/src/ListNode.java
new file mode 100644
index 0000000..e49628e
--- /dev/null
+++ b/[0160][Intersection of Two Linked Lists]/src/ListNode.java
@@ -0,0 +1,9 @@
+public class ListNode {
+ int val;
+ ListNode next;
+
+ ListNode(int x) {
+ val = x;
+ next = null;
+ }
+}
diff --git a/[0160][Intersection of Two Linked Lists]/src/Solution.java b/[0160][Intersection of Two Linked Lists]/src/Solution.java
new file mode 100644
index 0000000..72f8e1a
--- /dev/null
+++ b/[0160][Intersection of Two Linked Lists]/src/Solution.java
@@ -0,0 +1,130 @@
+//Write a program to find the node at which the intersection of two singly linke
+//d lists begins.
+//
+// For example, the following two linked lists:
+//
+//
+// begin to intersect at node c1.
+//
+//
+//
+// Example 1:
+//
+//
+//
+//Input: intersectVal = 8, listA = [4,1,8,4,5], listB = [5,0,1,8,4,5], skipA = 2
+//, skipB = 3
+//Output: Reference of the node with value = 8
+//Input Explanation: The intersected node's value is 8 (note that this must not
+//be 0 if the two lists intersect). From the head of A, it reads as [4,1,8,4,5]. F
+//rom the head of B, it reads as [5,0,1,8,4,5]. There are 2 nodes before the inter
+//sected node in A; There are 3 nodes before the intersected node in B.
+//
+//
+//
+// Example 2:
+//
+//
+//
+//Input: intersectVal = 2, listA = [0,9,1,2,4], listB = [3,2,4], skipA = 3, skip
+//B = 1
+//Output: Reference of the node with value = 2
+//Input Explanation: The intersected node's value is 2 (note that this must not
+//be 0 if the two lists intersect). From the head of A, it reads as [0,9,1,2,4]. F
+//rom the head of B, it reads as [3,2,4]. There are 3 nodes before the intersected
+// node in A; There are 1 node before the intersected node in B.
+//
+//
+//
+//
+// Example 3:
+//
+//
+//
+//Input: intersectVal = 0, listA = [2,6,4], listB = [1,5], skipA = 3, skipB = 2
+//Output: null
+//Input Explanation: From the head of A, it reads as [2,6,4]. From the head of B
+//, it reads as [1,5]. Since the two lists do not intersect, intersectVal must be
+//0, while skipA and skipB can be arbitrary values.
+//Explanation: The two lists do not intersect, so return null.
+//
+//
+//
+//
+// Notes:
+//
+//
+// If the two linked lists have no intersection at all, return null.
+// The linked lists must retain their original structure after the function returns.
+// You may assume there are no cycles anywhere in the entire linked structure.
+// Your code should preferably run in O(n) time and use only O(1) memory.
+//
+// Related Topics Linked List
+
+
+//leetcode submit region begin(Prohibit modification and deletion)
+
+/**
+ * Definition for singly-linked list.
+ * public class ListNode {
+ * int val;
+ * ListNode next;
+ * ListNode(int x) {
+ * val = x;
+ * next = null;
+ * }
+ * }
+ */
+public class Solution {
+ /**
+ * 解题思路:将headA链表的尾结点链接到headB的头部,问题等价于求链表中环的入口节点,最后再还原两个表
+ */
+ public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
+
+ if (headA == null || headB == null) {
+ return null;
+ }
+
+ if (headA == headB) {
+ return headA;
+ }
+
+ ListNode tailA = headA;
+ while (tailA.next != null) {
+ tailA = tailA.next;
+ }
+
+ tailA.next = headB;
+
+ // 定义快慢指针
+ ListNode fast = headA;
+ ListNode slow = headA;
+
+ while (fast.next != null && fast.next.next != null) {
+ slow = slow.next;
+ fast = fast.next.next;
+
+ //如果有环,想遇于环中某点
+ if (fast == slow) {
+ break;
+ }
+ }
+
+ //如果没有环,return null
+ if (fast.next == null || fast.next.next == null) {
+ tailA.next = null; // 还原链表
+ return null;
+ }
+
+ slow = headA;
+ while (slow != fast) {
+ slow = slow.next;
+ fast = fast.next;
+ }
+
+
+ tailA.next = null; // 还原链表
+ return fast;
+ }
+}
+//leetcode submit region end(Prohibit modification and deletion)
diff --git a/[0162][Find Peak Element]/[0162][Find Peak Element].iml b/[0162][Find Peak Element]/[0162][Find Peak Element].iml
new file mode 100644
index 0000000..73f33e3
--- /dev/null
+++ b/[0162][Find Peak Element]/[0162][Find Peak Element].iml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0162][Find Peak Element]/src/Main.java b/[0162][Find Peak Element]/src/Main.java
new file mode 100644
index 0000000..9112882
--- /dev/null
+++ b/[0162][Find Peak Element]/src/Main.java
@@ -0,0 +1,20 @@
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-28 16:44
+ **/
+public class Main {
+ @Test
+ public void test1() {
+ Solution solution = new Solution();
+ Assert.assertEquals(2, solution.findPeakElement(new int[]{1, 2, 3, 1}));
+ }
+
+ @Test
+ public void test2() {
+ Solution solution = new Solution();
+ Assert.assertEquals(1, solution.findPeakElement(new int[]{1, 2, 1, 3, 5, 6, 4}));
+ }
+}
diff --git a/[0162][Find Peak Element]/src/Solution.java b/[0162][Find Peak Element]/src/Solution.java
new file mode 100644
index 0000000..fc64ef2
--- /dev/null
+++ b/[0162][Find Peak Element]/src/Solution.java
@@ -0,0 +1,68 @@
+/**
+ * Author:
+ * Date: 2015-06-19
+ * Time: 17:30
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * A peak element is an element that is greater than its neighbors.
+ *
+ * Given an input array where num[i] num[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 num[-1] = num[n] = -.
+ *
+ * For example, in array [1, 2, 3, 1], 3 is a peak element and your function should return
+ * the index number 2.
+ *
+ * Note:
+ * Your solution should be in logarithmic complexity.
+ *
+ * Ŀ⣺
+ * ֵԪءֵָھӵԪ
+ *
+ * һnum[i] num[i+1]ҵһֵԪز±ꡣ
+ *
+ * ֵܰ·һɡ
+ *
+ * Լnum[-1] = num[n] = -ޣʼԪصĩβԪصҲΪ
+ *
+ * 磬[1, 2, 3, 1]У3ǷֵԪأĺӦ÷±2
+ *
+ * ע⣺
+ * ΪӶȡ
+ *
+ *
+ * @param nums
+ * @return
+ */
+ public int findPeakElement(int[] nums) {
+
+ if (nums == null || nums.length < 1) {
+ return -1;
+ }
+
+ if (nums.length == 1) {
+ return 0;
+ }
+
+ if (nums[0] > nums[1]) {
+ return 0;
+ } else if (nums[nums.length - 1] > nums[nums.length - 2]) {
+ return nums.length - 1;
+ }
+
+
+ for (int i = 1; i < nums.length - 1; i++) {
+ if (nums[i] > nums[i - 1] && nums[i] > nums[i + 1]) {
+ return i;
+ }
+ }
+
+ return -1;
+ }
+
+}
diff --git a/[0167][Two Sum II - Input array is sorted]/[0167][Two Sum II - Input array is sorted].iml b/[0167][Two Sum II - Input array is sorted]/[0167][Two Sum II - Input array is sorted].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0167][Two Sum II - Input array is sorted]/[0167][Two Sum II - Input array is sorted].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0167][Two Sum II - Input array is sorted]/src/Solution.java b/[0167][Two Sum II - Input array is sorted]/src/Solution.java
new file mode 100644
index 0000000..fd34284
--- /dev/null
+++ b/[0167][Two Sum II - Input array is sorted]/src/Solution.java
@@ -0,0 +1,59 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-09-28 16:17
+ **/
+public class Solution {
+ /**
+ * 如果数组很大,target很小,可以考虑先用二分查找法找到不大于target元素的下标,再作处理
+ *
+ * @param numbers
+ * @param target
+ * @return
+ */
+ public int[] twoSum(int[] numbers, int target) {
+// int idx = search(numbers, target);
+ int idx = numbers.length - 1;
+ return twoSum(numbers, target, idx);
+ }
+
+ public int[] twoSum(int[] numbers, int target, int end) {
+ int[] result = {0, 0};
+
+ int lo = 0;
+ int hi = end;
+
+ while (lo < hi) {
+ if (numbers[lo] + numbers[hi] == target) {
+ result[0] = lo;
+ result[1] = hi;
+ break;
+ } else if (numbers[lo] + numbers[hi] > target) {
+ hi--;
+ } else {
+ lo++;
+ }
+ }
+
+ return result;
+ }
+
+ public int search(int[] numbers, int target) {
+
+ int lo = 0;
+ int hi = numbers.length - 1;
+ int mid;
+
+ while (lo <= hi) {
+ mid = lo + (hi - lo) / 2;
+ if (numbers[mid] == target) {
+ return mid;
+ } else if (numbers[mid] > target) {
+ hi = mid - 1;
+ } else {
+ lo = mid + 1;
+ }
+
+ }
+ return hi;
+ }
+}
diff --git a/[0173][Binary Search Tree Iterator]/[0173][Binary Search Tree Iterator].iml b/[0173][Binary Search Tree Iterator]/[0173][Binary Search Tree Iterator].iml
new file mode 100644
index 0000000..c8cb479
--- /dev/null
+++ b/[0173][Binary Search Tree Iterator]/[0173][Binary Search Tree Iterator].iml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0173][Binary Search Tree Iterator]/src/BSTIterator.java b/[0173][Binary Search Tree Iterator]/src/BSTIterator.java
new file mode 100644
index 0000000..8465ef7
--- /dev/null
+++ b/[0173][Binary Search Tree Iterator]/src/BSTIterator.java
@@ -0,0 +1,53 @@
+import java.util.Deque;
+import java.util.LinkedList;
+import java.util.NoSuchElementException;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-28 16:54
+ **/
+public class BSTIterator {
+ private TreeNode root;
+ private TreeNode prev = null;
+ // 最后一个元素表示next元素的值
+ private Deque deque = new LinkedList<>();
+
+ public BSTIterator(TreeNode root) {
+ this.root = root;
+ TreeNode temp = root;
+ // 找最左的子结点,并且将经过的路径都记录下来
+ while (temp != null) {
+ deque.addLast(temp);
+ temp = temp.left;
+ }
+ }
+
+ /**
+ * @return the next smallest number
+ */
+ public int next() {
+
+ if (deque.isEmpty()) {
+ throw new NoSuchElementException();
+ }
+
+ TreeNode temp = deque.removeLast();
+
+ if (temp.right != null) {
+ TreeNode n = temp.right;
+ while (n != null) {
+ deque.addLast(n);
+ n = n.left;
+ }
+ }
+
+ return temp.val;
+ }
+
+ /**
+ * @return whether we have a next smallest number
+ */
+ public boolean hasNext() {
+ return !deque.isEmpty();
+ }
+}
diff --git a/[0173][Binary Search Tree Iterator]/src/Solution.java b/[0173][Binary Search Tree Iterator]/src/Solution.java
new file mode 100644
index 0000000..6fb2141
--- /dev/null
+++ b/[0173][Binary Search Tree Iterator]/src/Solution.java
@@ -0,0 +1,49 @@
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-28 17:06
+ **/
+public class Solution {
+ @Test
+ public void test1() {
+ TreeNode root = new TreeNode(7);
+ root.left = new TreeNode(3);
+ root.right = new TreeNode(15);
+ root.right.left = new TreeNode(9);
+ root.right.right = new TreeNode(20);
+
+ BSTIterator iterator = new BSTIterator(root);
+ Assert.assertEquals(3, iterator.next()); // return 3
+ Assert.assertEquals(7, iterator.next()); // return 7
+ Assert.assertEquals(true, iterator.hasNext()); // return true
+ Assert.assertEquals(9, iterator.next()); // return 9
+ Assert.assertEquals(true, iterator.hasNext()); // return true
+ Assert.assertEquals(15, iterator.next()); // return 15
+ Assert.assertEquals(true, iterator.hasNext()); // return true
+ Assert.assertEquals(20, iterator.next()); // return 20
+ Assert.assertEquals(false, iterator.hasNext()); // return false
+ }
+
+ @Test
+ public void test2() {
+ TreeNode root = new TreeNode(7);
+ BSTIterator iterator = new BSTIterator(root);
+ Assert.assertEquals(7, iterator.next()); // return 3
+ Assert.assertEquals(false, iterator.hasNext()); // return false
+ Assert.assertEquals(false, iterator.hasNext()); // return false
+ }
+
+ @Test
+ public void test3() {
+ TreeNode root = new TreeNode(1);
+ root.right = new TreeNode(2);
+ BSTIterator iterator = new BSTIterator(root);
+ Assert.assertEquals(true, iterator.hasNext()); // return 3
+ Assert.assertEquals(1, iterator.next()); // return 3
+ Assert.assertEquals(true, iterator.hasNext()); // return false
+ Assert.assertEquals(2, iterator.next()); // return false
+ Assert.assertEquals(false, iterator.hasNext()); // return false
+ }
+}
diff --git a/[0173][Binary Search Tree Iterator]/src/TreeNode.java b/[0173][Binary Search Tree Iterator]/src/TreeNode.java
new file mode 100644
index 0000000..9aec4dd
--- /dev/null
+++ b/[0173][Binary Search Tree Iterator]/src/TreeNode.java
@@ -0,0 +1,15 @@
+/**
+ * Author:
+ * Date: 2015-08-19
+ * Time: 06:45
+ * Declaration: All Rights Reserved !!!
+ */
+public class TreeNode {
+ int val;
+ TreeNode left;
+ TreeNode right;
+
+ TreeNode(int x) {
+ val = x;
+ }
+}
diff --git a/[0191][Number Of 1 Bits]/[0191][Number Of 1 Bits].iml b/[0191][Number Of 1 Bits]/[0191][Number Of 1 Bits].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0191][Number Of 1 Bits]/[0191][Number Of 1 Bits].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0191][Number Of 1 Bits]/[0191][NumberOf1Bits].iml b/[0191][Number Of 1 Bits]/[0191][NumberOf1Bits].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0191][Number Of 1 Bits]/[0191][NumberOf1Bits].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220191\343\200\221\343\200\220NumberOf1Bits\343\200\221/src/Main.java" b/[0191][Number Of 1 Bits]/src/Main.java
similarity index 100%
rename from "\343\200\220191\343\200\221\343\200\220NumberOf1Bits\343\200\221/src/Main.java"
rename to [0191][Number Of 1 Bits]/src/Main.java
diff --git a/[0191][Number Of 1 Bits]/src/Solution.java b/[0191][Number Of 1 Bits]/src/Solution.java
new file mode 100644
index 0000000..3e63a99
--- /dev/null
+++ b/[0191][Number Of 1 Bits]/src/Solution.java
@@ -0,0 +1,30 @@
+/**
+ * Author: ������
+ * Date: 2015-06-17
+ * Time: 21:51
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ * Write a function that takes an unsigned integer and returns the number of ��1' bits it has
+ * (also known as the Hamming weight).
+ *
+ * For example, the 32-bit integer ��11' has binary representation 00000000000000000000000000001011,
+ * so the function should return 3.
+ *
+ * ���������е�λ��
+ *
+ * @param n
+ * @return
+ */
+ // you need to treat n as an unsigned value
+ public int hammingWeight(int n) {
+
+ int count = 0;
+ while (n != 0) {
+ count++;
+ n = (n - 1) & n;
+ }
+ return count;
+ }
+}
diff --git a/[0198][House Robber]/[0198][House Robber].iml b/[0198][House Robber]/[0198][House Robber].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0198][House Robber]/[0198][House Robber].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0198][House Robber]/[0198][HouseRobber].iml b/[0198][House Robber]/[0198][HouseRobber].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0198][House Robber]/[0198][HouseRobber].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220198\343\200\221\343\200\220HouseRobber\343\200\221/src/Main.java" b/[0198][House Robber]/src/Main.java
similarity index 100%
rename from "\343\200\220198\343\200\221\343\200\220HouseRobber\343\200\221/src/Main.java"
rename to [0198][House Robber]/src/Main.java
diff --git "a/\343\200\220198\343\200\221\343\200\220HouseRobber\343\200\221/src/Solution.java" b/[0198][House Robber]/src/Solution.java
similarity index 100%
rename from "\343\200\220198\343\200\221\343\200\220HouseRobber\343\200\221/src/Solution.java"
rename to [0198][House Robber]/src/Solution.java
diff --git a/[0199][Binary Tree Right Side View]/[0199][Binary Tree Right Side View].iml b/[0199][Binary Tree Right Side View]/[0199][Binary Tree Right Side View].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0199][Binary Tree Right Side View]/[0199][Binary Tree Right Side View].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0199][Binary Tree Right Side View]/[0199][BinaryTreeRightSideView].iml b/[0199][Binary Tree Right Side View]/[0199][BinaryTreeRightSideView].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0199][Binary Tree Right Side View]/[0199][BinaryTreeRightSideView].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220199\343\200\221\343\200\220BinaryTreeRightSideView\343\200\221/src/Solution.java" b/[0199][Binary Tree Right Side View]/src/Solution.java
similarity index 100%
rename from "\343\200\220199\343\200\221\343\200\220BinaryTreeRightSideView\343\200\221/src/Solution.java"
rename to [0199][Binary Tree Right Side View]/src/Solution.java
diff --git "a/\343\200\220199\343\200\221\343\200\220BinaryTreeRightSideView\343\200\221/src/TreeNode.java" b/[0199][Binary Tree Right Side View]/src/TreeNode.java
similarity index 100%
rename from "\343\200\220199\343\200\221\343\200\220BinaryTreeRightSideView\343\200\221/src/TreeNode.java"
rename to [0199][Binary Tree Right Side View]/src/TreeNode.java
diff --git a/[0200][Number Of Islands]/[0200][Number Of Islands].iml b/[0200][Number Of Islands]/[0200][Number Of Islands].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0200][Number Of Islands]/[0200][Number Of Islands].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0200][Number Of Islands]/[0200][NumberOfIslands].iml b/[0200][Number Of Islands]/[0200][NumberOfIslands].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0200][Number Of Islands]/[0200][NumberOfIslands].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0200][Number Of Islands]/src/Solution.java b/[0200][Number Of Islands]/src/Solution.java
new file mode 100644
index 0000000..ff8698a
--- /dev/null
+++ b/[0200][Number Of Islands]/src/Solution.java
@@ -0,0 +1,90 @@
+/**
+ * Author: ������
+ * Date: 2015-06-20
+ * Time: 11:00
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * Given a 2d grid map of '1's (land) and '0's (water), count the number of islands.
+ * An island is surrounded by water and is formed by connecting adjacent lands horizontally
+ * or vertically. You may assume all four edges of the grid are all surrounded by water.
+ *
+ * Example 1:
+ * 11110
+ * 11010
+ * 11000
+ * 00000
+ * Answer: 1
+ *
+ * Example 2:
+ * 11000
+ * 11000
+ * 00100
+ * 00011
+ * Answer: 3
+ *
+ * ��Ŀ���⣺
+ * ������һ����ά����ĵ�ͼ��'1'��½�أ���0��ˮ�����������������������������滷ˮ��
+ * �������ڵ�½��ˮƽ��ֱ���Ӷ��γɵġ�����Լ��������������ĸ��߶���ˮ��Χ��
+ *
+ * ����˼·��
+ * һ��������һ����Ӧ�ķ��ʱ�Ǿ�������ÿ��Ԫ��ʱ�й�����ȱ���������������ȱ�������ͳ�Ƶ�����Ŀ
+ *
+ *
+ *
+ * @param grid
+ * @return
+ */
+ public int numIslands(char[][] grid) {
+ // ������
+ if (grid == null || grid.length == 0 || grid[0].length == 0) {
+ return 0;
+ }
+
+ // Ԫ��Ĭ��ֵ��false
+ boolean[][] visited = new boolean[grid.length][grid[0].length];
+
+ int result = 0;
+ for (int i = 0; i < grid.length; i++) {
+ for (int j = 0; j < grid[0].length; j++) {
+ // �����λ��û�б����ʹ������Ҵ�λ���ǵ�������¹�����ȱ���
+ if (!visited[i][j] && grid[i][j] == '1') {
+ result++;
+ bfs(grid, visited, i, j);
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * �����������
+ *
+ * @param grid ����
+ * @param visited ���ʱ�Ǿ���
+ * @param row ������
+ * @param col ������
+ */
+ private void bfs(char[][] grid, boolean[][] visited, int row, int col) {
+
+ if (row >= 0 && row < grid.length // �кϷ�
+ && col >= 0 && col < grid[0].length // �кϷ�
+ && !visited[row][col] // û�з��ʹ�
+ && grid[row][col] == '1') { // �ǵ���½��
+
+ // ��Ǵ�λ���Ѿ����ʹ���
+ visited[row][col] = true;
+
+ // ��
+ bfs(grid, visited, row - 1, col);
+ // ��
+ bfs(grid, visited, row, col + 1);
+ // ��
+ bfs(grid, visited, row + 1, col);
+ // ��
+ bfs(grid, visited, row, col - 1);
+ }
+ }
+}
diff --git a/[0201][Bitwise AND Of Numbers Range]/[0201][Bitwise AND Of Numbers Range].iml b/[0201][Bitwise AND Of Numbers Range]/[0201][Bitwise AND Of Numbers Range].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0201][Bitwise AND Of Numbers Range]/[0201][Bitwise AND Of Numbers Range].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0201][Bitwise AND Of Numbers Range]/[0201][BitwiseANDOfNumbersRange].iml b/[0201][Bitwise AND Of Numbers Range]/[0201][BitwiseANDOfNumbersRange].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0201][Bitwise AND Of Numbers Range]/[0201][BitwiseANDOfNumbersRange].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220201\343\200\221\343\200\220BitwiseANDOfNumbersRange\343\200\221/src/Solution.java" b/[0201][Bitwise AND Of Numbers Range]/src/Solution.java
similarity index 100%
rename from "\343\200\220201\343\200\221\343\200\220BitwiseANDOfNumbersRange\343\200\221/src/Solution.java"
rename to [0201][Bitwise AND Of Numbers Range]/src/Solution.java
diff --git a/[0202][Happy Number ]/[0202][Happy Number ].iml b/[0202][Happy Number ]/[0202][Happy Number ].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0202][Happy Number ]/[0202][Happy Number ].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0202][Happy Number ]/[0202][HappyNumber ].iml b/[0202][Happy Number ]/[0202][HappyNumber ].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0202][Happy Number ]/[0202][HappyNumber ].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220202\343\200\221\343\200\220HappyNumber \343\200\221/src/Main.java" b/[0202][Happy Number ]/src/Main.java
similarity index 100%
rename from "\343\200\220202\343\200\221\343\200\220HappyNumber \343\200\221/src/Main.java"
rename to [0202][Happy Number ]/src/Main.java
diff --git a/[0202][Happy Number ]/src/Solution.java b/[0202][Happy Number ]/src/Solution.java
new file mode 100644
index 0000000..46f562d
--- /dev/null
+++ b/[0202][Happy Number ]/src/Solution.java
@@ -0,0 +1,51 @@
+import java.util.HashSet;
+
+/**
+ * Author: ������
+ * Date: 2015-06-17
+ * Time: 21:36
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ * Write an algorithm to determine if a number is "happy".
+ * A happy number is a number defined by the following process: Starting with any positive integer,
+ * replace the number by the sum of the squares of its digits, and repeat the process until the number
+ * equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those
+ * numbers for which this process ends in 1 are happy numbers.
+ *
+ * ��ĿҪ�������һ�������������ϸ�����λ�����ֵ�ƽ���ͣ�����������Ϊ1���������Ϊhappy number��
+ * ���������ܴ�ij������ʼ����ѭ����
+ *
+ * @param n
+ * @return
+ */
+ public boolean isHappy(int n) {
+
+ if (n < 1) {
+ return false;
+ }
+
+ // ���ڱ����м���ֵĽ��
+ HashSet set = new HashSet<>(32);
+
+ int tmp;
+ int newN;
+
+ // n��Ϊ1������n��ֵ�����ظ����֣��������ѭ��
+ while (n != 1 && !set.contains(n)) {
+ set.add(n);
+ newN = 0;
+ while (n > 0) {
+ tmp = n % 10;
+ n /= 10;
+ newN += tmp * tmp;
+ }
+
+ n = newN;
+ }
+
+ return n == 1;
+ }
+
+}
diff --git a/[0203][Remove Linked List Elements]/[0203][Remove Linked List Elements].iml b/[0203][Remove Linked List Elements]/[0203][Remove Linked List Elements].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0203][Remove Linked List Elements]/[0203][Remove Linked List Elements].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0203][Remove Linked List Elements]/[0203][RemoveLinkedList Elements].iml b/[0203][Remove Linked List Elements]/[0203][RemoveLinkedList Elements].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0203][Remove Linked List Elements]/[0203][RemoveLinkedList Elements].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220203\343\200\221\343\200\220RemoveLinkedList Elements\343\200\221/src/ListNode.java" b/[0203][Remove Linked List Elements]/src/ListNode.java
similarity index 100%
rename from "\343\200\220203\343\200\221\343\200\220RemoveLinkedList Elements\343\200\221/src/ListNode.java"
rename to [0203][Remove Linked List Elements]/src/ListNode.java
diff --git "a/\343\200\220203\343\200\221\343\200\220RemoveLinkedList Elements\343\200\221/src/Solution.java" b/[0203][Remove Linked List Elements]/src/Solution.java
similarity index 100%
rename from "\343\200\220203\343\200\221\343\200\220RemoveLinkedList Elements\343\200\221/src/Solution.java"
rename to [0203][Remove Linked List Elements]/src/Solution.java
diff --git a/[0204][Count Primes]/[0204][Count Primes].iml b/[0204][Count Primes]/[0204][Count Primes].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0204][Count Primes]/[0204][Count Primes].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0204][Count Primes]/[0204][CountPrimes].iml b/[0204][Count Primes]/[0204][CountPrimes].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0204][Count Primes]/[0204][CountPrimes].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220204\343\200\221\343\200\220CountPrimes\343\200\221/src/Solution.java" b/[0204][Count Primes]/src/Solution.java
similarity index 100%
rename from "\343\200\220204\343\200\221\343\200\220CountPrimes\343\200\221/src/Solution.java"
rename to [0204][Count Primes]/src/Solution.java
diff --git a/[0205][Isomorphic Strings]/[0205][Isomorphic Strings].iml b/[0205][Isomorphic Strings]/[0205][Isomorphic Strings].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0205][Isomorphic Strings]/[0205][Isomorphic Strings].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0205][Isomorphic Strings]/[0205][IsomorphicStrings].iml b/[0205][Isomorphic Strings]/[0205][IsomorphicStrings].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0205][Isomorphic Strings]/[0205][IsomorphicStrings].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220205\343\200\221\343\200\220IsomorphicStrings\343\200\221/src/Solution.java" b/[0205][Isomorphic Strings]/src/Solution.java
similarity index 100%
rename from "\343\200\220205\343\200\221\343\200\220IsomorphicStrings\343\200\221/src/Solution.java"
rename to [0205][Isomorphic Strings]/src/Solution.java
diff --git a/[0206][Reverse Linked List]/[0206][Reverse Linked List].iml b/[0206][Reverse Linked List]/[0206][Reverse Linked List].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0206][Reverse Linked List]/[0206][Reverse Linked List].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220206\343\200\221\343\200\220ReverseLinkedList\343\200\221/src/ListNode.java" b/[0206][Reverse Linked List]/src/ListNode.java
similarity index 100%
rename from "\343\200\220206\343\200\221\343\200\220ReverseLinkedList\343\200\221/src/ListNode.java"
rename to [0206][Reverse Linked List]/src/ListNode.java
diff --git "a/\343\200\220206\343\200\221\343\200\220ReverseLinkedList\343\200\221/src/Main.java" b/[0206][Reverse Linked List]/src/Main.java
similarity index 100%
rename from "\343\200\220206\343\200\221\343\200\220ReverseLinkedList\343\200\221/src/Main.java"
rename to [0206][Reverse Linked List]/src/Main.java
diff --git a/[0206][Reverse Linked List]/src/Solution.java b/[0206][Reverse Linked List]/src/Solution.java
new file mode 100644
index 0000000..360bebd
--- /dev/null
+++ b/[0206][Reverse Linked List]/src/Solution.java
@@ -0,0 +1,48 @@
+/**
+ * Author:
+ * Date: 2015-06-19
+ * Time: 11:17
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ * Reverse a singly linked list.
+ * ת
+ * ʹͷ巨
+ *
+ * @param head
+ * @return
+ */
+ public ListNode reverseList(ListNode head) {
+ // ͷ
+ ListNode root = new ListNode(0);
+ ListNode nextNode;
+ while (head != null) {
+ nextNode = head.next;
+ head.next = root.next;
+ root.next = head;
+ head = nextNode;
+ }
+
+ head = root.next;
+ root.next = null;
+
+ return head;
+ }
+
+ /**
+ * TODO ʹõݹⷨ
+ *
+ * @param head
+ * @return
+ */
+ public ListNode reverseList2(ListNode head) {
+ if (head == null) {
+ return null;
+ }
+
+ reverseList2(head.next).next = head;
+
+ return null;
+ }
+}
diff --git a/[0207][Course Schedule]/[0207][Course Schedule].iml b/[0207][Course Schedule]/[0207][Course Schedule].iml
new file mode 100644
index 0000000..c8cb479
--- /dev/null
+++ b/[0207][Course Schedule]/[0207][Course Schedule].iml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0207][Course Schedule]/src/Main.java b/[0207][Course Schedule]/src/Main.java
new file mode 100644
index 0000000..a94abab
--- /dev/null
+++ b/[0207][Course Schedule]/src/Main.java
@@ -0,0 +1,45 @@
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-07-07 11:35
+ **/
+public class Main {
+ @Test
+ public void test1() {
+ Solution solution = new Solution();
+ int[][] arr = {{1, 0}};
+ Assert.assertEquals(true, solution.canFinish(2, arr));
+ }
+
+ @Test
+ public void test2() {
+ Solution solution = new Solution();
+ int[][] arr = {{1, 0}, {0, 1}};
+ Assert.assertEquals(false, solution.canFinish(2, arr));
+ }
+
+
+ @Test
+ public void test3() {
+ Solution solution = new Solution();
+ int[][] arr = {{0, 1}, {0, 2}, {1, 2}};
+ Assert.assertEquals(true, solution.canFinish(3, arr));
+ }
+
+ @Test
+ public void test4() {
+ Solution solution = new Solution();
+ int[][] arr = {{2, 0}, {1, 0}, {3, 1}, {3, 2}, {1, 3}};
+ Assert.assertEquals(false, solution.canFinish(4, arr));
+ }
+
+
+ @Test
+ public void test5() {
+ Solution solution = new Solution();
+ int[][] arr = {{1, 0}, {2, 6}, {1, 7}, {6, 4}, {7, 0}, {0, 5}};
+ Assert.assertEquals(true, solution.canFinish(8, arr));
+ }
+}
diff --git a/[0207][Course Schedule]/src/Solution.java b/[0207][Course Schedule]/src/Solution.java
new file mode 100644
index 0000000..208c49e
--- /dev/null
+++ b/[0207][Course Schedule]/src/Solution.java
@@ -0,0 +1,104 @@
+import java.util.*;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-07-07 11:23
+ **/
+public class Solution {
+ /**
+ *
+ * There are a total of n courses you have to take, labeled from 0 to n-1.
+ *
+ * Some courses may have prerequisites, for example to take course 0 you have to first take
+ * course 1, which is expressed as a pair: [0,1]
+ *
+ * Given the total number of courses and a list of prerequisite pairs, is it possible for
+ * you to finish all courses?
+ *
+ * Example 1:
+ *
+ * Input: 2, [[1,0]]
+ * Output: true
+ * Explanation: There are a total of 2 courses to take.
+ * To take course 1 you should have finished course 0. So it is possible.
+ * Example 2:
+ *
+ * Input: 2, [[1,0],[0,1]]
+ * Output: false
+ * Explanation: There are a total of 2 courses to take.
+ * To take course 1 you should have finished course 0, and to take course 0 you should
+ * also have finished course 1. So it is impossible.
+ * Note:
+ *
+ * The input prerequisites is a graph represented by a list of edges, not adjacency matrices. Read
+ * more about how a graph is represented.
+ * You may assume that there are no duplicate edges in the input prerequisites.
+ *
+ * 解题思路:
+ * 使用深度度优先遍历,记录每个访问过的点,如果遍历过程中再次遍历到了已经访问过的点,
+ * 说明有环状依赖,课程安排不合理
+ *
+ */
+
+ public boolean canFinish(int numCourses, int[][] prerequisites) {
+ // 说明没有课程依赖
+ if (prerequisites == null || prerequisites.length == 0) {
+ return true;
+ }
+
+
+ Map> dependencies = new HashMap<>();
+
+ for (int[] arr : prerequisites) {
+ List val = dependencies.computeIfAbsent(arr[0], k -> new LinkedList<>());
+ val.add(arr[1]);
+ }
+
+ boolean[] visit = new boolean[numCourses];
+ Deque path = new LinkedList<>();
+ for (int i = 0; i < visit.length; i++) {
+ if (!visit[i]) {
+ if (!dfs(i, dependencies, visit, path)) {
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * 判断从i课程序开始,是否存在环
+ *
+ * @param course
+ * @param dependencies
+ * @param visit
+ * @return
+ */
+ private boolean dfs(int course, Map> dependencies, boolean[] visit, Deque path) {
+ List dependency = dependencies.get(course);
+
+ if (dependency == null) {
+ return true;
+ }
+
+ if (path.contains(course)) {
+ return false;
+ }
+
+ path.addLast(course);
+
+
+ for (int i : dependency) {
+ boolean result = dfs(i, dependencies, visit, path);
+ if (!result) {
+ return false;
+ }
+ }
+
+ visit[course] = true;
+ path.removeLast();
+
+ return true;
+ }
+}
diff --git a/[0215][Kth Largest Element In An Array]/[0215][Kth Largest Element In An Array].iml b/[0215][Kth Largest Element In An Array]/[0215][Kth Largest Element In An Array].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0215][Kth Largest Element In An Array]/[0215][Kth Largest Element In An Array].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0215][Kth Largest Element In An Array]/[0215][KthLargestElementInAnArray].iml b/[0215][Kth Largest Element In An Array]/[0215][KthLargestElementInAnArray].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0215][Kth Largest Element In An Array]/[0215][KthLargestElementInAnArray].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0215][Kth Largest Element In An Array]/src/Main.java b/[0215][Kth Largest Element In An Array]/src/Main.java
new file mode 100644
index 0000000..ec1a203
--- /dev/null
+++ b/[0215][Kth Largest Element In An Array]/src/Main.java
@@ -0,0 +1,12 @@
+/**
+ * Author: ������
+ * Date: 2015-06-19
+ * Time: 20:01
+ * Declaration: All Rights Reserved !!!
+ */
+public class Main {
+ public static void main(String[] args) {
+ Solution solution = new Solution();
+ System.out.println(solution.findKthLargest(new int[]{2, 1}, 2));
+ }
+}
diff --git a/[0215][Kth Largest Element In An Array]/src/Solution.java b/[0215][Kth Largest Element In An Array]/src/Solution.java
new file mode 100644
index 0000000..7648127
--- /dev/null
+++ b/[0215][Kth Largest Element In An Array]/src/Solution.java
@@ -0,0 +1,79 @@
+/**
+ * Author: ������
+ * Date: 2015-06-19
+ * Time: 19:36
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * 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.
+ *
+ * For example,
+ * Given [3,2,1,5,6,4] and k = 2, return 5.
+ *
+ * Note:
+ * You may assume k is always valid, 1 �� k �� array's length.
+ *
+ * ��Ŀ���⣺
+ * ��һ��δ��������������ҳ���k���Ԫ�ء�ע��������֮��ĵ�k���ǵ�k�����ظ���Ԫ��
+ * ���Լ���kһ������Ч�ģ� 1 �� k �� ���鳤��
+ *
+ * ����˼·��
+ * O(n)�ⷨ������ѡ��QuickSelect���㷨
+ *
+ *
+ * @param nums
+ * @param k
+ * @return
+ */
+ public int findKthLargest(int[] nums, int k) {
+
+ if (k < 1 || nums == null || nums.length < k) {
+ throw new IllegalArgumentException();
+ }
+
+ return findKthLargest(nums, 0, nums.length - 1, k);
+ }
+
+ public int findKthLargest(int[] nums, int start, int end, int k) {
+
+ // ����ֵ
+ int pivot = nums[start];
+ int lo = start;
+ int hi = end;
+
+ while (lo < hi) {
+ // ��С������ֵ�����ƶ����������
+ while (lo < hi && nums[hi] >= pivot) {
+ hi--;
+ }
+ nums[lo] = nums[hi];
+
+ // ����������ֵ�����ƶ��������ұ�
+ while (lo < hi && nums[lo] <= pivot) {
+ lo++;
+ }
+ nums[hi] = nums[lo];
+ }
+
+ nums[lo] = pivot;
+
+ // ����Ѿ��ҵ���
+ if (end - lo + 1 == k) {
+ return pivot;
+ }
+ // ��k�������loλ�õ��ұ�
+ else if (end - lo + 1 > k) {
+ return findKthLargest(nums, lo + 1, end, k);
+ }
+ // ��k�������loλ�õ����
+ else {
+ // k-(end-lo+1)
+ // (end-lo+1)����ʾ��loλ�ÿ�ʼ��endλ�õ�Ԫ�ظ�������������Ұ벿��
+ // ԭ���ĵ�k����k-(end-lo+1)��
+ return findKthLargest(nums, start, lo - 1, k - (end - lo + 1));
+ }
+ }
+}
diff --git a/[0216][Combination Sum III]/[0216][Combination Sum III].iml b/[0216][Combination Sum III]/[0216][Combination Sum III].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0216][Combination Sum III]/[0216][Combination Sum III].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0216][Combination Sum III]/[0216][CombinationSumIII].iml b/[0216][Combination Sum III]/[0216][CombinationSumIII].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0216][Combination Sum III]/[0216][CombinationSumIII].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220216\343\200\221\343\200\220CombinationSumIII\343\200\221/src/Main.java" b/[0216][Combination Sum III]/src/Main.java
similarity index 100%
rename from "\343\200\220216\343\200\221\343\200\220CombinationSumIII\343\200\221/src/Main.java"
rename to [0216][Combination Sum III]/src/Main.java
diff --git a/[0216][Combination Sum III]/src/Solution.java b/[0216][Combination Sum III]/src/Solution.java
new file mode 100644
index 0000000..563a5f7
--- /dev/null
+++ b/[0216][Combination Sum III]/src/Solution.java
@@ -0,0 +1,100 @@
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Author: ������
+ * Date: 2015-06-21
+ * Time: 21:31
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+ /**
+ *
+ * Find all possible combinations of k numbers that add up to a number n,
+ * given that only numbers from 1 to 9 can be used and each combination
+ * should be a unique set of numbers.
+ *
+ * Ensure that numbers within the set are sorted in ascending order.
+ *
+ * Example 1:
+ * Input: k = 3, n = 7
+ * Output:
+ * [[1,2,4]]
+ *
+ * Example 2:
+ * Input: k = 3, n = 9
+ * Output:
+ * [[1,2,6], [1,3,5], [2,3,4]]
+ *
+ * ��Ŀ���⣺
+ * Ѱ����������k����֮�͵���n����ϣ�ֻ����ʹ������1-9������ÿһ������е�����Ӧ����Ψһ�ġ�
+ * ȷ������е������Ե���˳�����С�
+ *
+ * ����˼·��
+ * ���ݷ�
+ *
+ *
+ * @param k
+ * @param n
+ * @return
+ */
+ public List> combinationSum3(int k, int n) {
+ // ���ڱ������н��
+ List> result = new LinkedList<>();
+ // ���ڱ����м���
+ List list = new LinkedList<>();
+ // ��������ͽ��н������
+ if (k > 0 && k <= 9) {
+ solve(k, 1, n, 0, list, result);
+ }
+
+ // ���ؽ��
+ return result;
+ }
+
+ /**
+ * ��ⷽ��
+ *
+ * @param k ÿ�����Ԫ�ظ���
+ * @param cur ��ǰ�����k��Ԫ��
+ * @param remainder k - cur + 1��Ԫ�صĺ�
+ * @param prevVal ��cur-1��Ԫ�ص�ȡֵ
+ * @param list �����Ԫ�صļ�����
+ * @param result ��������������
+ */
+ public void solve(int k, int cur, int remainder, int prevVal, List list, List> result) {
+ // �������һ��Ԫ��
+ if (cur == k) {
+ // remainderΪ���һ����Ԫ�ص�ֵ�����������ǰһ����Ԫ�ص�ֵ�����Ҳ��ܳ���9
+ if (remainder > prevVal && remainder <= 9) {
+ // ���Ԫ��ֵ
+ list.add(remainder);
+
+ // ����������µĶ�����
+ List one = new LinkedList<>();
+ for (Integer i : list) {
+ one.add(i);
+ }
+
+ // ������
+ result.add(one);
+ // ɾ�����һ��Ԫ�أ������ֳ���ԭ
+ list.remove(list.size() - 1);
+ }
+ }
+ // �������һ��Ԫ��
+ else if (cur < k) {
+ for (int i = prevVal + 1; i <= 9 - (k - cur); i++) {
+ // ���Ԫ��
+ list.add(i);
+ // �ݹ����
+ solve(k, cur + 1, remainder - i, i, list, result);
+ // �ֳ���ԭ
+ list.remove(list.size() - 1);
+
+ }
+ }
+
+
+ }
+}
diff --git a/[0217][Contains Duplicate ]/[0217][Contains Duplicate ].iml b/[0217][Contains Duplicate ]/[0217][Contains Duplicate ].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0217][Contains Duplicate ]/[0217][Contains Duplicate ].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0217][Contains Duplicate ]/[0217][ContainsDuplicate ].iml b/[0217][Contains Duplicate ]/[0217][ContainsDuplicate ].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0217][Contains Duplicate ]/[0217][ContainsDuplicate ].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/\343\200\220217\343\200\221\343\200\220ContainsDuplicate \343\200\221/src/Main.java" b/[0217][Contains Duplicate ]/src/Main.java
similarity index 100%
rename from "\343\200\220217\343\200\221\343\200\220ContainsDuplicate \343\200\221/src/Main.java"
rename to [0217][Contains Duplicate ]/src/Main.java
diff --git a/[0217][Contains Duplicate ]/src/Solution.java b/[0217][Contains Duplicate ]/src/Solution.java
new file mode 100644
index 0000000..d144b96
--- /dev/null
+++ b/[0217][Contains Duplicate ]/src/Solution.java
@@ -0,0 +1,46 @@
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Author: ������
+ * Date: 2015-06-18
+ * Time: 09:40
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+
+
+ /**
+ * Given an array of integers, find if the array contains any duplicates.
+ * Your function should return true if any value appears at least twice in the
+ * array, and it should return false if every element is distinct.
+ *
+ *
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-10-09 11:02
+ **/
+public class Solution {
+ public boolean isPalindrome(ListNode head) {
+
+ // 没有节点或者只有一个结点
+ if (head == null || head.next == null) {
+ return true;
+ }
+
+ int count = 0;
+ ListNode node = head;
+ while (node != null) {
+ count++;
+ node = node.next;
+ }
+
+ // 找反向链的起始位置
+ count = (count + 1) / 2;
+ node = head;
+ while (count > 0) {
+ count--;
+ node = node.next;
+ }
+
+
+ ListNode reverseHead = new ListNode(0);
+ ListNode temp;
+ while (node != null) {
+ temp = node.next;
+ node.next = reverseHead.next;
+ reverseHead.next = node;
+ node = temp;
+ }
+
+ reverseHead = reverseHead.next;
+
+ while (reverseHead != null) {
+ if (head.val != reverseHead.val) {
+ return false;
+ }
+
+ reverseHead = reverseHead.next;
+ head = head.next;
+ }
+
+ return true;
+ }
+}
diff --git a/[0234][Palindrome Linked List]/src/Solution2.java b/[0234][Palindrome Linked List]/src/Solution2.java
new file mode 100644
index 0000000..f6138f7
--- /dev/null
+++ b/[0234][Palindrome Linked List]/src/Solution2.java
@@ -0,0 +1,38 @@
+/**
+ * O(n) time and O(n) space
+ *
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-10-09 11:02
+ **/
+public class Solution2 {
+ public boolean isPalindrome(ListNode head) {
+
+ if (head == null) {
+ return true;
+ }
+
+ // 反向链的头
+ ListNode reverseHead = new ListNode(-1);
+
+ ListNode temp = head;
+ ListNode node;
+ // 头插法构建反向链
+ while (temp != null) {
+ node = new ListNode(temp.val);
+ node.next = reverseHead.next;
+ reverseHead.next = node;
+ temp = temp.next;
+ }
+
+ reverseHead = reverseHead.next;
+ while (head != null) {
+ if (head.val != reverseHead.val) {
+ return false;
+ }
+
+ head = head.next;
+ reverseHead = reverseHead.next;
+ }
+ return true;
+ }
+}
diff --git a/[0234][Palindrome Linked List]/src/Test.java b/[0234][Palindrome Linked List]/src/Test.java
new file mode 100644
index 0000000..28f5ec5
--- /dev/null
+++ b/[0234][Palindrome Linked List]/src/Test.java
@@ -0,0 +1,42 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-10-09 11:10
+ **/
+public class Test {
+ public static void main(String[] args) {
+ test1();
+ test2();
+ test3();
+ }
+
+ public static void test1() {
+ Solution solution = new Solution();
+ ListNode head = new ListNode(1);
+ head.next = new ListNode(2);
+ System.out.println(solution.isPalindrome(head));
+ }
+
+ public static void test2() {
+ Solution solution = new Solution();
+
+ ListNode head = new ListNode(1);
+ head.next = new ListNode(2);
+ head.next.next = new ListNode(2);
+ head.next.next.next = new ListNode(1);
+ head.next.next.next.next = new ListNode(2);
+ head.next.next.next.next.next = new ListNode(2);
+ head.next.next.next.next.next.next = new ListNode(1);
+ System.out.println(solution.isPalindrome(head));
+ }
+
+ public static void test3() {
+ Solution solution = new Solution();
+
+ ListNode head = new ListNode(1);
+ head.next = new ListNode(2);
+ head.next.next = new ListNode(2);
+ head.next.next.next = new ListNode(1);
+
+ System.out.println(solution.isPalindrome(head));
+ }
+}
diff --git a/[0235][Lowest Common Ancestor of a Binary Search Tree]/[0235][Lowest Common Ancestor of a Binary Search Tree].iml b/[0235][Lowest Common Ancestor of a Binary Search Tree]/[0235][Lowest Common Ancestor of a Binary Search Tree].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0235][Lowest Common Ancestor of a Binary Search Tree]/[0235][Lowest Common Ancestor of a Binary Search Tree].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0235][Lowest Common Ancestor of a Binary Search Tree]/src/Solution.java b/[0235][Lowest Common Ancestor of a Binary Search Tree]/src/Solution.java
new file mode 100644
index 0000000..632cf2f
--- /dev/null
+++ b/[0235][Lowest Common Ancestor of a Binary Search Tree]/src/Solution.java
@@ -0,0 +1,56 @@
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Definition for a binary tree node.
+ *
+ * public class TreeNode {
+ * int val;
+ * TreeNode left;
+ * TreeNode right;
+ * TreeNode(int x) { val = x; }
+ * }
+ *
+ *
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-10-09 11:32
+ */
+class Solution {
+ public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
+
+ List pPath = new ArrayList<>();
+ List qPath = new ArrayList<>();
+
+ search(pPath, root, p);
+ search(qPath, root, q);
+
+ TreeNode ancestor = pPath.get(0);
+
+ int idx = 1;
+ while (idx < pPath.size() && idx < qPath.size()) {
+ p = pPath.get(idx);
+ q = qPath.get(idx);
+ if (p != null && q != null && p.val == q.val) {
+ ancestor = pPath.get(idx);
+ idx++;
+ } else {
+ break;
+ }
+ }
+
+ return ancestor;
+ }
+
+ public void search(List path, TreeNode root, TreeNode node) {
+ path.add(root);
+
+ if (root != null) {
+ if (root.val > node.val) {
+ search(path, root.left, node);
+ }
+ if (root.val < node.val) {
+ search(path, root.right, node);
+ }
+ }
+ }
+}
diff --git a/[0235][Lowest Common Ancestor of a Binary Search Tree]/src/TreeNode.java b/[0235][Lowest Common Ancestor of a Binary Search Tree]/src/TreeNode.java
new file mode 100644
index 0000000..141d430
--- /dev/null
+++ b/[0235][Lowest Common Ancestor of a Binary Search Tree]/src/TreeNode.java
@@ -0,0 +1,13 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-10-09 11:33
+ **/
+public class TreeNode {
+ int val;
+ TreeNode left;
+ TreeNode right;
+
+ TreeNode(int x) {
+ val = x;
+ }
+}
diff --git a/[0237][Delete Node in a Linked List]/[0237][Delete Node in a Linked List].iml b/[0237][Delete Node in a Linked List]/[0237][Delete Node in a Linked List].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0237][Delete Node in a Linked List]/[0237][Delete Node in a Linked List].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0237][Delete Node in a Linked List]/src/ListNode.java b/[0237][Delete Node in a Linked List]/src/ListNode.java
new file mode 100644
index 0000000..9e0f1da
--- /dev/null
+++ b/[0237][Delete Node in a Linked List]/src/ListNode.java
@@ -0,0 +1,12 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-10-10 09:58
+ **/
+public class ListNode {
+ int val;
+ ListNode next;
+
+ ListNode(int x) {
+ val = x;
+ }
+}
diff --git a/[0237][Delete Node in a Linked List]/src/Solution.java b/[0237][Delete Node in a Linked List]/src/Solution.java
new file mode 100644
index 0000000..6c60753
--- /dev/null
+++ b/[0237][Delete Node in a Linked List]/src/Solution.java
@@ -0,0 +1,32 @@
+/**
+ *
+ * Definition for singly-linked list.
+ * public class ListNode {
+ * int val;
+ * ListNode next;
+ * ListNode(int x) { val = x; }
+ * }
+ *
+ *
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-10-10 09:57
+ **/
+class Solution {
+ public void deleteNode(ListNode node) {
+
+ if (node == null || node.next == null) {
+ return;
+ }
+
+ ListNode prev = node;
+ while (node.next != null) {
+ node.val = node.next.val;
+ prev = node;
+ node = node.next;
+
+
+ }
+
+ prev.next = null;
+ }
+}
\ No newline at end of file
diff --git a/[0237][Delete Node in a Linked List]/src/Test.java b/[0237][Delete Node in a Linked List]/src/Test.java
new file mode 100644
index 0000000..a6ee290
--- /dev/null
+++ b/[0237][Delete Node in a Linked List]/src/Test.java
@@ -0,0 +1,32 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-10-10 10:01
+ **/
+public class Test {
+ public static void main(String[] args) {
+ ListNode node = new ListNode(4);
+ node.next = new ListNode(5);
+ node.next.next = new ListNode(1);
+ node.next.next.next = new ListNode(9);
+
+ Solution solution = new Solution();
+ solution.deleteNode(node.next);
+
+ print(node);
+ }
+
+ private static void print(ListNode node) {
+ do {
+ if (node == null) {
+ System.out.println("null");
+ } else if (node.next != null) {
+ System.out.print(node.val + "->");
+ node = node.next;
+ } else {
+ System.out.println(node.val + "->null");
+ node = node.next;
+ }
+
+ } while (node != null);
+ }
+}
diff --git a/[0238][Product of Array Except Self]/[0238][Product of Array Except Self].iml b/[0238][Product of Array Except Self]/[0238][Product of Array Except Self].iml
new file mode 100644
index 0000000..c8cb479
--- /dev/null
+++ b/[0238][Product of Array Except Self]/[0238][Product of Array Except Self].iml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0238][Product of Array Except Self]/src/Main.java b/[0238][Product of Array Except Self]/src/Main.java
new file mode 100644
index 0000000..b2097c4
--- /dev/null
+++ b/[0238][Product of Array Except Self]/src/Main.java
@@ -0,0 +1,26 @@
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-30 14:31
+ **/
+public class Main {
+ @Test
+ public void test1() {
+ Solution solution = new Solution();
+ Assert.assertArrayEquals(new int[]{24, 12, 8, 6}, solution.productExceptSelf(new int[]{1, 2, 3, 4}));
+ }
+
+ @Test
+ public void test2() {
+ Solution solution = new Solution();
+ Assert.assertArrayEquals(new int[]{0, 0}, solution.productExceptSelf(new int[]{0, 0}));
+ }
+
+ @Test
+ public void test3() {
+ Solution solution = new Solution();
+ Assert.assertArrayEquals(new int[]{1, 0}, solution.productExceptSelf(new int[]{0, 1}));
+ }
+}
diff --git a/[0238][Product of Array Except Self]/src/Solution.java b/[0238][Product of Array Except Self]/src/Solution.java
new file mode 100644
index 0000000..e0c6b32
--- /dev/null
+++ b/[0238][Product of Array Except Self]/src/Solution.java
@@ -0,0 +1,71 @@
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-30 14:29
+ **/
+public class Solution {
+ /**
+ *
+ * Given an array nums of n integers where n > 1,
+ * return an array output such that output[i] is equal to the product of all the
+ * elements of nums except nums[i].
+ *
+ * Example:
+ *
+ * Input: [1,2,3,4]
+ * Output: [24,12,8,6]
+ * Note: Please solve it without division and in O(n).
+ *
+ * Follow up:
+ * Could you solve it with constant space complexity? (The output array does not count as
+ * extra space for the purpose of space complexity analysis.)
+ *
+ *
+ * @param nums
+ * @return
+ */
+ public int[] productExceptSelf(int[] nums) {
+ int[] result = new int[nums.length];
+
+ // 记录为0的下票
+ Set zero = new HashSet<>();
+
+
+ long product = 1;
+ for (int i = 0; i < nums.length; i++) {
+ product *= nums[i];
+ if (nums[i] == 0) {
+ zero.add(i);
+ }
+ }
+
+ // 0的个数大于1个
+ if (zero.size() > 1) {
+ return result;
+ } else if (zero.size() == 1) {
+ int firstZeroIndex = 0;
+ for (Integer i : zero) {
+ firstZeroIndex = i;
+ }
+
+ result[firstZeroIndex] = 1;
+ for (int i = 0; i < nums.length; i++) {
+ if (i != firstZeroIndex) {
+ result[firstZeroIndex] *= nums[i];
+ }
+ }
+
+ return result;
+ } else {
+ // 没有0
+ for (int i = 0; i < nums.length; i++) {
+ result[i] = (int) (product / nums[i]);
+ }
+
+ return result;
+ }
+
+ }
+}
diff --git a/[0240][Search a 2D Matrix II]/[0240][Search a 2D Matrix II].iml b/[0240][Search a 2D Matrix II]/[0240][Search a 2D Matrix II].iml
new file mode 100644
index 0000000..c8cb479
--- /dev/null
+++ b/[0240][Search a 2D Matrix II]/[0240][Search a 2D Matrix II].iml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0240][Search a 2D Matrix II]/src/Main.java b/[0240][Search a 2D Matrix II]/src/Main.java
new file mode 100644
index 0000000..33fcd80
--- /dev/null
+++ b/[0240][Search a 2D Matrix II]/src/Main.java
@@ -0,0 +1,23 @@
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-07-06 20:12
+ **/
+public class Main {
+ @Test
+ public void test1() {
+ int[][] matrix = {
+ {1, 4, 7, 11, 15},
+ {2, 5, 8, 12, 19},
+ {3, 6, 9, 16, 22},
+ {10, 13, 14, 17, 24},
+ {18, 21, 23, 26, 30}
+ };
+ Solution solution = new Solution();
+
+ Assert.assertEquals(true, solution.searchMatrix(matrix, 5));
+ Assert.assertEquals(false, solution.searchMatrix(matrix, 20));
+ }
+}
diff --git a/[0240][Search a 2D Matrix II]/src/Solution.java b/[0240][Search a 2D Matrix II]/src/Solution.java
new file mode 100644
index 0000000..4b780fe
--- /dev/null
+++ b/[0240][Search a 2D Matrix II]/src/Solution.java
@@ -0,0 +1,53 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-07-06 20:06
+ **/
+public class Solution {
+ /**
+ *
+ * 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 in ascending from left to right.
+ * Integers in each column are sorted in ascending from top to bottom.
+ * Example:
+ *
+ * Consider the following matrix:
+ *
+ * [
+ * [1, 4, 7, 11, 15],
+ * [2, 5, 8, 12, 19],
+ * [3, 6, 9, 16, 22],
+ * [10, 13, 14, 17, 24],
+ * [18, 21, 23, 26, 30]
+ * ]
+ * Given target = 5, return true.
+ *
+ * Given target = 20, return false.
+ *
+ *
+ * @param matrix
+ * @param target
+ * @return
+ */
+ public boolean searchMatrix(int[][] matrix, int target) {
+
+ if (matrix == null || matrix.length == 0) {
+ return false;
+ }
+
+ int i = 0;
+ int j = matrix[0].length - 1;
+ while (i < matrix.length && j > -1) {
+ if (matrix[i][j] == target) {
+ return true;
+ } else if (target < matrix[i][j]) {
+ j--;
+ } else {
+ i++;
+ }
+ }
+
+ return false;
+ }
+}
diff --git a/[0241][Different Ways to Add Parentheses]/[0241][Different Ways to Add Parentheses].iml b/[0241][Different Ways to Add Parentheses]/[0241][Different Ways to Add Parentheses].iml
new file mode 100644
index 0000000..c8cb479
--- /dev/null
+++ b/[0241][Different Ways to Add Parentheses]/[0241][Different Ways to Add Parentheses].iml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0241][Different Ways to Add Parentheses]/src/Main.java b/[0241][Different Ways to Add Parentheses]/src/Main.java
new file mode 100644
index 0000000..e2c34b5
--- /dev/null
+++ b/[0241][Different Ways to Add Parentheses]/src/Main.java
@@ -0,0 +1,25 @@
+import org.junit.Test;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-07-06 20:59
+ **/
+public class Main {
+ @Test
+ public void test1() {
+ Solution solution = new Solution();
+ System.out.println(solution.diffWaysToCompute("2-1-1"));
+ }
+
+ @Test
+ public void test2() {
+ Solution solution = new Solution();
+ System.out.println(solution.diffWaysToCompute("2*3-4*5"));
+ }
+
+ @Test
+ public void test3() {
+ Solution solution = new Solution();
+ System.out.println(solution.diffWaysToCompute("2"));
+ }
+}
diff --git a/[0241][Different Ways to Add Parentheses]/src/Solution.java b/[0241][Different Ways to Add Parentheses]/src/Solution.java
new file mode 100644
index 0000000..d996d4c
--- /dev/null
+++ b/[0241][Different Ways to Add Parentheses]/src/Solution.java
@@ -0,0 +1,113 @@
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-07-06 20:25
+ **/
+public class Solution {
+ /**
+ *
+ * Given a string of numbers and operators, return all possible results from computing all the
+ * different possible ways to group numbers and operators. The valid operators are +, - and *.
+ *
+ * Example 1:
+ *
+ * Input: "2-1-1"
+ * Output: [0, 2]
+ * Explanation:
+ * ((2-1)-1) = 0
+ * (2-(1-1)) = 2
+ * Example 2:
+ *
+ * Input: "2*3-4*5"
+ * Output: [-34, -14, -10, -10, 10]
+ * Explanation:
+ * (2*(3-(4*5))) = -34
+ * ((2*3)-(4*5)) = -14
+ * ((2*(3-4))*5) = -10
+ * (2*((3-4)*5)) = -10
+ * (((2*3)-4)*5) = 10
+ *
+ *
+ * @param input
+ * @return
+ */
+ public List diffWaysToCompute(String input) {
+ List operator = new ArrayList<>();
+ List operand = new ArrayList<>();
+
+ int start = 0;
+ int end;
+ while (start < input.length()) {
+ end = start + 1;
+ while (end < input.length()
+ && input.charAt(end) >= '0'
+ && input.charAt(end) <= '9') {
+ end++;
+ }
+ operand.add(Integer.parseInt(input.substring(start, end)));
+
+ if (end < input.length()) {
+ operator.add(input.charAt(end));
+ }
+ start = end + 1;
+ }
+
+ return diffWaysToCompute(operand, operator);
+ }
+
+ /**
+ * @param operand
+ * @param operator
+ * @return
+ */
+ private List diffWaysToCompute(List operand, List operator) {
+
+ List result = new LinkedList<>();
+
+ if (operator.isEmpty()) {
+ result.addAll(operand);
+ return result;
+ }
+
+
+ if (operator.size() == 1) {
+ result.add(calculate(operand.get(0), operand.get(1), operator.get(0)));
+ return result;
+ }
+
+ for (int i = 0; i < operator.size(); i++) {
+ List left = diffWaysToCompute(
+ new ArrayList<>(operand.subList(0, i + 1)),
+ new ArrayList<>(operator.subList(0, i)));
+ List right = diffWaysToCompute(
+ new ArrayList<>(operand.subList(i + 1, operand.size())),
+ new ArrayList<>(operator.subList(i + 1, operator.size())));
+
+ for (int x : left) {
+ for (int y : right) {
+ result.add(calculate(x, y, operator.get(i)));
+ }
+ }
+ }
+
+ return result;
+
+ }
+
+ private Integer calculate(Integer a, Integer b, Character op) {
+
+ switch (op) {
+ case '+':
+ return a + b;
+ case '-':
+ return a - b;
+ case '*':
+ return a * b;
+ default:
+ throw new RuntimeException("no such " + a + op + b + " option exception");
+ }
+ }
+}
diff --git a/[0242][Valid Anagram]/[0242][Valid Anagram].iml b/[0242][Valid Anagram]/[0242][Valid Anagram].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0242][Valid Anagram]/[0242][Valid Anagram].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0242][Valid Anagram]/src/Solution.java b/[0242][Valid Anagram]/src/Solution.java
new file mode 100644
index 0000000..ace39c8
--- /dev/null
+++ b/[0242][Valid Anagram]/src/Solution.java
@@ -0,0 +1,48 @@
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-10-10 10:28
+ **/
+public class Solution {
+ public boolean isAnagram(String s, String t) {
+
+ if (s == null && t == null) {
+ return true;
+ } else if (s == null || t == null) {
+ return false;
+ }
+
+ Map map = new HashMap<>();
+
+ for (int i = 0; i < s.length(); i++) {
+ Character c = s.charAt(i);
+ if (map.containsKey(c)) {
+ map.put(c, map.get(c) + 1);
+ } else {
+ map.put(c, 1);
+ }
+ }
+
+ for (int i = 0; i < t.length(); i++) {
+ Character c = t.charAt(i);
+ Integer count = map.get(c);
+ // t有s中不包含的字符串
+ if (count == null) {
+ return false;
+ } else {
+ map.put(c, count - 1);
+ }
+ }
+
+ // map中的值有非0的说明不合法
+ for (Integer i : map.values()) {
+ if (i != 0) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+}
diff --git a/[0242][Valid Anagram]/src/Test.java b/[0242][Valid Anagram]/src/Test.java
new file mode 100644
index 0000000..5282683
--- /dev/null
+++ b/[0242][Valid Anagram]/src/Test.java
@@ -0,0 +1,12 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-10-10 10:35
+ **/
+public class Test {
+ public static void main(String[] args) {
+ Solution solution = new Solution();
+
+ System.out.println(solution.isAnagram("anagram", "nagaram"));
+ System.out.println(solution.isAnagram("rat", "car"));
+ }
+}
diff --git a/[0257][Binary Tree Paths]/[0257][Binary Tree Paths].iml b/[0257][Binary Tree Paths]/[0257][Binary Tree Paths].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0257][Binary Tree Paths]/[0257][Binary Tree Paths].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0257][Binary Tree Paths]/src/Solution.java b/[0257][Binary Tree Paths]/src/Solution.java
new file mode 100644
index 0000000..6480a96
--- /dev/null
+++ b/[0257][Binary Tree Paths]/src/Solution.java
@@ -0,0 +1,56 @@
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ *
+ * Definition for a binary tree node.
+ * public class TreeNode {
+ * int val;
+ * TreeNode left;
+ * TreeNode right;
+ * TreeNode(int x) { val = x; }
+ * }
+ *
+ *
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-10-10 11:16
+ **/
+public class Solution {
+ public List binaryTreePaths(TreeNode root) {
+ List result = new LinkedList<>();
+ binaryTreePaths(root, new LinkedList<>(), result);
+
+ return result;
+ }
+
+ private void binaryTreePaths(TreeNode root, LinkedList path, List result) {
+
+ if (root == null) {
+ return;
+ }
+
+ path.add(root);
+
+ if (root.left == null && root.right == null) {
+ addResult(path, result);
+ } else {
+ binaryTreePaths(root.left, path, result);
+ binaryTreePaths(root.right, path, result);
+ }
+
+ path.remove(path.size() - 1);
+ }
+
+ private void addResult(LinkedList path, List result) {
+ StringBuilder builder = new StringBuilder();
+ if (path != null) {
+ for (TreeNode node : path) {
+ builder.append("->").append(node.val);
+ }
+ }
+
+ if (builder.length() > 0) {
+ result.add(builder.substring(2));
+ }
+ }
+}
diff --git a/[0257][Binary Tree Paths]/src/Test.java b/[0257][Binary Tree Paths]/src/Test.java
new file mode 100644
index 0000000..318a15c
--- /dev/null
+++ b/[0257][Binary Tree Paths]/src/Test.java
@@ -0,0 +1,16 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-10-10 11:25
+ **/
+public class Test {
+ public static void main(String[] args) {
+ Solution solution = new Solution();
+
+ TreeNode root = new TreeNode(1);
+ root.left = new TreeNode(2);
+ root.right = new TreeNode(3);
+ root.left.right = new TreeNode(5);
+
+ System.out.println(solution.binaryTreePaths(root));
+ }
+}
diff --git a/[0257][Binary Tree Paths]/src/TreeNode.java b/[0257][Binary Tree Paths]/src/TreeNode.java
new file mode 100644
index 0000000..2e248fe
--- /dev/null
+++ b/[0257][Binary Tree Paths]/src/TreeNode.java
@@ -0,0 +1,15 @@
+/**
+ * Author: 王俊超
+ * Date: 2015-06-18
+ * Time: 10:02
+ * Declaration: All Rights Reserved !!!
+ */
+public class TreeNode {
+ int val;
+ TreeNode left;
+ TreeNode right;
+
+ TreeNode(int x) {
+ val = x;
+ }
+}
diff --git a/[0258][Add Digits]/[0258][Add Digits].iml b/[0258][Add Digits]/[0258][Add Digits].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0258][Add Digits]/[0258][Add Digits].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0258][Add Digits]/src/Solution.java b/[0258][Add Digits]/src/Solution.java
new file mode 100644
index 0000000..ff595f5
--- /dev/null
+++ b/[0258][Add Digits]/src/Solution.java
@@ -0,0 +1,27 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-10-10 13:28
+ **/
+public class Solution {
+ public int addDigits(int num) {
+
+ if (num < 0) {
+ throw new IllegalArgumentException("input num :" + num + ", must not be negative");
+ }
+
+ int result = 0;
+
+ while (num > 0) {
+ result += num % 10;
+ num /= 10;
+
+ // 需要重新进行位相加
+ if (num == 0 && result > 9) {
+ num = result;
+ result = 0;
+ }
+ }
+
+ return result;
+ }
+}
diff --git a/[0258][Add Digits]/src/Test.java b/[0258][Add Digits]/src/Test.java
new file mode 100644
index 0000000..d3afaa3
--- /dev/null
+++ b/[0258][Add Digits]/src/Test.java
@@ -0,0 +1,13 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-10-10 13:35
+ **/
+public class Test {
+ public static void main(String[] args) {
+ Solution solution = new Solution();
+
+ System.out.println(solution.addDigits(38));
+ System.out.println(solution.addDigits(999999999));
+ System.out.println(solution.addDigits(100000000));
+ }
+}
diff --git a/[0260][Single Number III]/[0260][Single Number III].iml b/[0260][Single Number III]/[0260][Single Number III].iml
new file mode 100644
index 0000000..c8cb479
--- /dev/null
+++ b/[0260][Single Number III]/[0260][Single Number III].iml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0260][Single Number III]/src/Main.java b/[0260][Single Number III]/src/Main.java
new file mode 100644
index 0000000..4341777
--- /dev/null
+++ b/[0260][Single Number III]/src/Main.java
@@ -0,0 +1,17 @@
+import org.junit.Test;
+
+import java.util.Arrays;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-07-03 18:56
+ **/
+public class Main {
+ @Test
+ public void test1() {
+
+ Solution solution = new Solution();
+ int[] diff = solution.singleNumber(new int[]{1, 2, 1, 3, 2, 5});
+ System.out.println(Arrays.toString(diff));
+ }
+}
diff --git a/[0260][Single Number III]/src/Solution.java b/[0260][Single Number III]/src/Solution.java
new file mode 100644
index 0000000..03c702c
--- /dev/null
+++ b/[0260][Single Number III]/src/Solution.java
@@ -0,0 +1,51 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-07-03 18:46
+ **/
+public class Solution {
+ /**
+ *
+ * Given an array of numbers nums, in which exactly two elements appear only
+ * once and all the other elements appear exactly twice. Find the two elements that appear only once.
+ *
+ * Example:
+ *
+ * Input: [1,2,1,3,2,5]
+ * Output: [3,5]
+ * Note:
+ *
+ * The order of the result is not important. So in the above example, [5, 3] is also correct.
+ * Your algorithm should run in linear runtime complexity. Could you implement it using
+ * only constant space complexity?
+ *
+ *
+ * @param nums
+ * @return
+ */
+ public int[] singleNumber(int[] nums) {
+ int xor = nums[0];
+ for (int i = 1; i < nums.length; i++) {
+ xor ^= nums[i];
+ }
+
+ int temp = xor;
+ int count = 0;
+ while ((1 & (temp % 2)) != 1) {
+ count++;
+ temp >>>= 1;
+ }
+
+ int x = 0;
+ int y = 0;
+
+ for (int i : nums) {
+ if (((i >> count) & 1) == 1) {
+ x ^= i;
+ } else {
+ y ^= i;
+ }
+ }
+
+ return new int[]{x, y};
+ }
+}
diff --git a/[0263][Ugly Number]/[0263][Ugly Number].iml b/[0263][Ugly Number]/[0263][Ugly Number].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0263][Ugly Number]/[0263][Ugly Number].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0263][Ugly Number]/src/Solution.java b/[0263][Ugly Number]/src/Solution.java
new file mode 100644
index 0000000..a05b03c
--- /dev/null
+++ b/[0263][Ugly Number]/src/Solution.java
@@ -0,0 +1,28 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-10-10 13:45
+ **/
+public class Solution {
+ public boolean isUgly(int num) {
+
+ if (num < 1) {
+ return false;
+ } else if (num == 1) {
+ return true;
+ }
+
+ while ((num % 2) == 0) {
+ num /= 2;
+ }
+
+ while ((num % 3) == 0) {
+ num /= 3;
+ }
+
+ while ((num % 5) == 0) {
+ num /= 5;
+ }
+
+ return num == 1;
+ }
+}
diff --git a/[0263][Ugly Number]/src/Test.java b/[0263][Ugly Number]/src/Test.java
new file mode 100644
index 0000000..dccb247
--- /dev/null
+++ b/[0263][Ugly Number]/src/Test.java
@@ -0,0 +1,16 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-10-10 13:50
+ **/
+public class Test {
+ public static void main(String[] args) {
+ Solution solution = new Solution();
+
+ System.out.println(solution.isUgly(-1));
+ System.out.println(solution.isUgly(0));
+ System.out.println(solution.isUgly(1));
+ System.out.println(solution.isUgly(6));
+ System.out.println(solution.isUgly(8));
+ System.out.println(solution.isUgly(14));
+ }
+}
diff --git a/[0268][Missing Number]/[0268][Missing Number].iml b/[0268][Missing Number]/[0268][Missing Number].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0268][Missing Number]/[0268][Missing Number].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0268][Missing Number]/src/Solution.java b/[0268][Missing Number]/src/Solution.java
new file mode 100644
index 0000000..0ad6903
--- /dev/null
+++ b/[0268][Missing Number]/src/Solution.java
@@ -0,0 +1,39 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-10-10 14:02
+ **/
+public class Solution {
+ public int missingNumber(int[] nums) {
+
+ if (nums == null || nums.length < 1) {
+ throw new IllegalArgumentException("array should contain at least one element");
+ }
+
+ for (int i = 0; i < nums.length; i++) {
+ // 只会存在一个大于nums.length的数,将其放在数组最后一个位置
+ if (nums[i] > nums.length) {
+ swap(nums, i, nums.length - 1);
+ }
+
+ // 交换位置,直到nums[i] = i
+ while (nums[i] != i && nums[i] < nums.length) {
+ swap(nums, i, nums[i]);
+ }
+ }
+
+ // 找出丢失的元素
+ for (int i = 0; i < nums.length; i++) {
+ if (nums[i] != i) {
+ return i;
+ }
+ }
+
+ return nums.length;
+ }
+
+ private void swap(int[] nums, int x, int y) {
+ int temp = nums[x];
+ nums[x] = nums[y];
+ nums[y] = temp;
+ }
+}
diff --git a/[0268][Missing Number]/src/Test.java b/[0268][Missing Number]/src/Test.java
new file mode 100644
index 0000000..a4452e8
--- /dev/null
+++ b/[0268][Missing Number]/src/Test.java
@@ -0,0 +1,21 @@
+import java.util.Arrays;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-10-10 14:14
+ **/
+public class Test {
+ public static void main(String[] args) {
+ Solution solution = new Solution();
+
+ missingNumber(solution, new int[]{0});
+ missingNumber(solution, new int[]{3, 0, 1});
+ missingNumber(solution, new int[]{9, 6, 4, 2, 3, 5, 7, 0, 1});
+ missingNumber(solution, new int[]{8, 6, 4, 2, 3, 5, 7, 0, 1});
+ }
+
+ private static void missingNumber(Solution solution, int[] array) {
+ System.out.println(solution.missingNumber(array));
+ System.out.println(Arrays.toString(array));
+ }
+}
diff --git a/[0278][First Bad Version]/[0278][First Bad Version].iml b/[0278][First Bad Version]/[0278][First Bad Version].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0278][First Bad Version]/[0278][First Bad Version].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0278][First Bad Version]/src/Solution.java b/[0278][First Bad Version]/src/Solution.java
new file mode 100644
index 0000000..2f344d1
--- /dev/null
+++ b/[0278][First Bad Version]/src/Solution.java
@@ -0,0 +1,39 @@
+/**
+ *
+ * The isBadVersion API is defined in the parent class VersionControl.
+ * boolean isBadVersion(int version);
+ *
+ *
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-10-10 14:26
+ **/
+public class Solution extends VersionControl {
+ public int firstBadVersion(int n) {
+
+ if (!isBadVersion(n)) {
+ return 0;
+ }
+
+ int hi = n;
+ int lo = 1;
+ int mid;
+
+ while (hi >= lo) {
+ mid = lo + (hi - lo) / 2;
+ if (isBadVersion(mid)) {
+ // 当前是1号版本,或者前一个是合法版本,那么当前版本就是第一个非法的版本
+ if (mid == 1 || (mid > 1 && !isBadVersion(mid - 1))) {
+ return mid;
+ } else {
+ // 非法的版本在[lo, mid-1]间
+ hi = mid - 1;
+ }
+ } else {
+ // 非法版本在[mid + 1, hi]间
+ lo = mid + 1;
+ }
+ }
+
+ return 0;
+ }
+}
diff --git a/[0278][First Bad Version]/src/Test.java b/[0278][First Bad Version]/src/Test.java
new file mode 100644
index 0000000..3a57cd6
--- /dev/null
+++ b/[0278][First Bad Version]/src/Test.java
@@ -0,0 +1,12 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-10-10 16:55
+ **/
+public class Test {
+ public static void main(String[] args) {
+ Solution solution = new Solution();
+
+ solution.setBadVersion(new boolean[]{false, false, false, true, true});
+ System.out.println(solution.firstBadVersion(5));
+ }
+}
diff --git a/[0278][First Bad Version]/src/VersionControl.java b/[0278][First Bad Version]/src/VersionControl.java
new file mode 100644
index 0000000..327bc14
--- /dev/null
+++ b/[0278][First Bad Version]/src/VersionControl.java
@@ -0,0 +1,20 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-10-10 14:27
+ **/
+public class VersionControl {
+
+ private boolean[] badVersion;
+
+ public boolean isBadVersion(int version) {
+ return badVersion[version - 1];
+ }
+
+ public boolean[] getBadVersion() {
+ return badVersion;
+ }
+
+ public void setBadVersion(boolean[] badVersion) {
+ this.badVersion = badVersion;
+ }
+}
diff --git a/[0283][Move Zeroes]/[0283][Move Zeroes].iml b/[0283][Move Zeroes]/[0283][Move Zeroes].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0283][Move Zeroes]/[0283][Move Zeroes].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0283][Move Zeroes]/src/Solution.java b/[0283][Move Zeroes]/src/Solution.java
new file mode 100644
index 0000000..4afeb4a
--- /dev/null
+++ b/[0283][Move Zeroes]/src/Solution.java
@@ -0,0 +1,44 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-10-10 17:04
+ **/
+public class Solution {
+ public void moveZeroes(int[] nums) {
+
+ if (nums == null || nums.length < 1) {
+ return;
+ }
+
+ int idx = 0;
+ // 找第一个0的位置
+ while (idx < nums.length && nums[idx] != 0) {
+ idx++;
+ }
+
+ // 数组的值都非0
+ if (idx >= nums.length) {
+ return;
+ }
+
+ int temp = idx + 1;
+
+ while (temp < nums.length) {
+ // 找temp开始第一个非0的位置
+ while (temp < nums.length && nums[temp] == 0) {
+ temp++;
+ }
+
+ // 找到非0值,移动到idx位置
+ if (temp < nums.length) {
+ nums[idx] = nums[temp];
+ idx++;
+ temp++;
+ }
+ }
+
+ // 从[idx, nums.length-1]的长度都设置为0
+ for (int i = idx; i < nums.length; i++) {
+ nums[i] = 0;
+ }
+ }
+}
diff --git a/[0283][Move Zeroes]/src/Test.java b/[0283][Move Zeroes]/src/Test.java
new file mode 100644
index 0000000..1c5d20c
--- /dev/null
+++ b/[0283][Move Zeroes]/src/Test.java
@@ -0,0 +1,20 @@
+import java.util.Arrays;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-10-10 17:11
+ **/
+public class Test {
+ public static void main(String[] args) {
+ moveZeros(new int[]{0, 1, 0, 3, 12});
+ moveZeros(new int[]{2, 1, 6, 3, 12});
+ moveZeros(new int[]{2});
+ moveZeros(new int[]{0});
+ }
+
+ private static void moveZeros(int[] a1) {
+ Solution solution = new Solution();
+ solution.moveZeroes(a1);
+ System.out.println(Arrays.toString(a1));
+ }
+}
diff --git a/[0287][Find the Duplicate Number]/[0287][Find the Duplicate Number].iml b/[0287][Find the Duplicate Number]/[0287][Find the Duplicate Number].iml
new file mode 100644
index 0000000..c8cb479
--- /dev/null
+++ b/[0287][Find the Duplicate Number]/[0287][Find the Duplicate Number].iml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0287][Find the Duplicate Number]/src/Main.java b/[0287][Find the Duplicate Number]/src/Main.java
new file mode 100644
index 0000000..b69e3e5
--- /dev/null
+++ b/[0287][Find the Duplicate Number]/src/Main.java
@@ -0,0 +1,20 @@
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-07-03 19:08
+ **/
+public class Main {
+ @Test
+ public void test1() {
+ Solution solution = new Solution();
+ Assert.assertEquals(2, solution.findDuplicate(new int[]{1, 3, 4, 2, 2}));
+ }
+
+ @Test
+ public void test2() {
+ Solution solution = new Solution();
+ Assert.assertEquals(3, solution.findDuplicate(new int[]{3, 1, 3, 4, 2}));
+ }
+}
diff --git a/[0287][Find the Duplicate Number]/src/Solution.java b/[0287][Find the Duplicate Number]/src/Solution.java
new file mode 100644
index 0000000..4ab1587
--- /dev/null
+++ b/[0287][Find the Duplicate Number]/src/Solution.java
@@ -0,0 +1,55 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-07-03 19:04
+ **/
+public class Solution {
+ /**
+ *
+ * Given an array nums containing n + 1 integers where each integer is between 1
+ * and n (inclusive), prove that at least one duplicate number must exist. Assume
+ * that there is only one duplicate number, find the duplicate one.
+ *
+ * Example 1:
+ *
+ * Input: [1,3,4,2,2]
+ * Output: 2
+ * Example 2:
+ *
+ * Input: [3,1,3,4,2]
+ * Output: 3
+ * Note:
+ *
+ * You must not modify the array (assume the array is read only).
+ * You must use only constant, O(1) extra space.
+ * Your runtime complexity should be less than O(n2).
+ * There is only one duplicate number in the array, but it could be repeated more than once.
+ *
+ *
+ * @param nums
+ * @return
+ */
+ public int findDuplicate(int[] nums) {
+
+ for (int i = 1; i <= nums.length; i++) {
+ // nums[i - 1] != i ; 当 num[8] = 9 的情况
+ // nums[i - 1] != nums[nums[i - 1] - 1] ; 两个相同的数,位置被占用
+ while (nums[i - 1] != i && nums[i - 1] != nums[nums[i - 1] - 1]) {
+ swap(nums, i - 1, nums[i - 1] - 1);
+ }
+ }
+
+ for (int i = 1; i <= nums.length; i++) {
+ if (nums[i - 1] != i) {
+ return nums[i - 1];
+ }
+ }
+
+ return -1;
+ }
+
+ private void swap(int[] nums, int x, int y) {
+ int temp = nums[x];
+ nums[x] = nums[y];
+ nums[y] = temp;
+ }
+}
diff --git a/[0290][Word Pattern]/[0290][Word Pattern].iml b/[0290][Word Pattern]/[0290][Word Pattern].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0290][Word Pattern]/[0290][Word Pattern].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0290][Word Pattern]/src/Solution.java b/[0290][Word Pattern]/src/Solution.java
new file mode 100644
index 0000000..580d1c2
--- /dev/null
+++ b/[0290][Word Pattern]/src/Solution.java
@@ -0,0 +1,48 @@
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-10-10 17:24
+ **/
+public class Solution {
+ public boolean wordPattern(String pattern, String str) {
+
+ if (pattern == null && str == null) {
+ return true;
+ } else if (pattern == null || str == null) {
+ return false;
+ }
+
+ String[] parts = str.split("\\s+");
+
+ if (pattern.length() != parts.length) {
+ return false;
+ }
+
+ Map map = new HashMap<>();
+ Map rmap = new HashMap<>();
+
+ Character c;
+ for (int i = 0; i < pattern.length(); i++) {
+ c = pattern.charAt(i);
+ if (!map.containsKey(c)) {
+ map.put(c, parts[i]);
+ } else {
+ if (!parts[i].equals(map.get(c))) {
+ return false;
+ }
+ }
+ // 双射,两边都要验证
+ if (!rmap.containsKey(parts[i])) {
+ rmap.put(parts[i], c);
+ } else {
+ if (!c.equals(rmap.get(parts[i]))) {
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
+}
diff --git a/[0290][Word Pattern]/src/Test.java b/[0290][Word Pattern]/src/Test.java
new file mode 100644
index 0000000..6c75500
--- /dev/null
+++ b/[0290][Word Pattern]/src/Test.java
@@ -0,0 +1,14 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-10-10 17:29
+ **/
+public class Test {
+ public static void main(String[] args) {
+ Solution solution = new Solution();
+
+ System.out.println(solution.wordPattern("abba", "dog cat cat dog"));
+ System.out.println(solution.wordPattern("abba", "dog cat cat fish"));
+ System.out.println(solution.wordPattern("aaaa", "dog cat cat dog"));
+ System.out.println(solution.wordPattern("abba", "dog dog dog dog"));
+ }
+}
diff --git a/[0292][Nim Game]/[0292][Nim Game].iml b/[0292][Nim Game]/[0292][Nim Game].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0292][Nim Game]/[0292][Nim Game].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0292][Nim Game]/src/Solution.java b/[0292][Nim Game]/src/Solution.java
new file mode 100644
index 0000000..a6fa330
--- /dev/null
+++ b/[0292][Nim Game]/src/Solution.java
@@ -0,0 +1,41 @@
+/**
+ * https://leetcode.com/problems/nim-game/
+ *
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-07-08 18:39
+ **/
+public class Solution {
+ /**
+ *
+ * You are playing the following Nim Game with your friend: There is a heap of stones on the table,
+ * each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will
+ * be the winner. You will take the first turn to remove the stones.
+ *
+ * Both of you are very clever and have optimal strategies for the game. Write a function to determine
+ * whether you can win the game given the number of stones in the heap.
+ *
+ * Example:
+ *
+ * Input: 4
+ * Output: false
+ * Explanation: If there are 4 stones in the heap, then you will never win the game;
+ * No matter 1, 2, or 3 stones you remove, the last stone will always be
+ * removed by your friend.
+ *
+ * 这题往小说可以追溯到小学奥数或者脑筋急转弯的书中,往大说可以深究到博弈论。然而编程在这里并没有卵用,
+ * 策略在于,因为每个人都取不到4个,假设自己后走,要保证每轮自己和对方取得数量的和是4,这样就能确保每
+ * 轮完后都有4的倍数个石头被取走。这样,如果我们先走的话,先把n除4的余数个石头拿走,这样不管怎样,到最
+ * 后都会留4个下来,对方取1个你就取3个,对方取2个你就取2个,就必赢了。
+ *
+ *
+ * @param n
+ * @return
+ */
+ public boolean canWinNim(int n) {
+ return (n & 0b11) > 0;
+ }
+
+ public boolean canWinNim2(int n) {
+ return n % 4 != 0;
+ }
+}
diff --git a/[0299][Bulls and Cows]/[0299][Bulls and Cows].iml b/[0299][Bulls and Cows]/[0299][Bulls and Cows].iml
new file mode 100644
index 0000000..c70cbf1
--- /dev/null
+++ b/[0299][Bulls and Cows]/[0299][Bulls and Cows].iml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0299][Bulls and Cows]/src/Solution.java b/[0299][Bulls and Cows]/src/Solution.java
new file mode 100644
index 0000000..cb785ab
--- /dev/null
+++ b/[0299][Bulls and Cows]/src/Solution.java
@@ -0,0 +1,85 @@
+//You are playing the following Bulls and Cows game with your friend: You write
+//down a number and ask your friend to guess what the number is. Each time your fr
+//iend makes a guess, you provide a hint that indicates how many digits in said gu
+//ess match your secret number exactly in both digit and position (called "bulls")
+// and how many digits match the secret number but locate in the wrong position (c
+//alled "cows"). Your friend will use successive guesses and hints to eventually d
+//erive the secret number.
+//
+// Write a function to return a hint according to the secret number and friend's
+// guess, use A to indicate the bulls and B to indicate the cows.
+//
+// Please note that both secret number and friend's guess may contain duplicate
+//digits.
+//
+// Example 1:
+//
+//
+//Input: secret = "1807", guess = "7810"
+//
+//Output: "1A3B"
+//
+//Explanation: 1 bull and 3 cows. The bull is 8, the cows are 0, 1 and 7.
+//
+// Example 2:
+//
+//
+//Input: secret = "1123", guess = "0111"
+//
+//Output: "1A1B"
+//
+//Explanation: The 1st 1 in friend's guess is a bull, the 2nd or 3rd 1 is a cow.
+//
+//
+// Note: You may assume that the secret number and your friend's guess only cont
+//ain digits, and their lengths are always equal. Related Topics Hash Table
+
+
+import java.util.HashMap;
+import java.util.Map;
+
+//leetcode submit region begin(Prohibit modification and deletion)
+class Solution {
+ public String getHint(String secret, String guess) {
+
+ // 假如参数不合法
+ if (secret == null || guess == null || secret.length() != guess.length()) {
+ throw new IllegalArgumentException("secret: " + secret + ", guess: " + guess);
+ }
+
+ Map indexMap = new HashMap<>();
+ Map countMap = new HashMap<>();
+
+ for (int i = 0; i < secret.length(); i++) {
+ char c = secret.charAt(i);
+ indexMap.put(i, c);
+ countMap.put(c, 1 + countMap.getOrDefault(c, 0)); // 记录字符出现的次数
+ }
+
+ int bull = 0;
+ int cows = 0;
+
+ // 先计算bull
+ for (int i = 0; i < guess.length(); i++) {
+ char c = guess.charAt(i);
+ if (indexMap.get(i) == c) {
+ bull++;
+ indexMap.remove(i); // 删除已经匹配过的位置
+ countMap.put(c, countMap.get(c) - 1);
+ }
+ }
+
+ // 再计算cows
+ for (int i = 0; i < guess.length(); i++) {
+ char c = guess.charAt(i);
+ // 位置没有被匹配过,并且值大于0,说明猜测的值是有的,但是位置错误了
+ if (indexMap.containsKey(i) && countMap.getOrDefault(c, 0) > 0) {
+ cows++;
+ countMap.put(c, countMap.get(c) - 1);
+ }
+ }
+
+ return bull + "A" + cows + "B";
+ }
+}
+//leetcode submit region end(Prohibit modification and deletion)
diff --git a/[0299][Bulls and Cows]/src/TestSolution.java b/[0299][Bulls and Cows]/src/TestSolution.java
new file mode 100644
index 0000000..edc42ed
--- /dev/null
+++ b/[0299][Bulls and Cows]/src/TestSolution.java
@@ -0,0 +1,14 @@
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestSolution {
+ @Test
+ public void test1() {
+ String[][] data = {{"1807", "7810", "1A3B"}, {"1123", "0111", "1A1B"}, {"11", "10", "1A0B"}};
+
+ for (String[] datum : data) {
+ String result = new Solution().getHint(datum[0], datum[1]);
+ Assert.assertEquals(result, datum[2]);
+ }
+ }
+}
diff --git a/[0303][Range Sum Query - Immutable]/[0303][Range Sum Query - Immutable].iml b/[0303][Range Sum Query - Immutable]/[0303][Range Sum Query - Immutable].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0303][Range Sum Query - Immutable]/[0303][Range Sum Query - Immutable].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0303][Range Sum Query - Immutable]/src/NumArray.java b/[0303][Range Sum Query - Immutable]/src/NumArray.java
new file mode 100644
index 0000000..c64d89d
--- /dev/null
+++ b/[0303][Range Sum Query - Immutable]/src/NumArray.java
@@ -0,0 +1,34 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-10-12 13:53
+ **/
+public class NumArray {
+ private int[] nums;
+
+ public NumArray(int[] nums) {
+ this.nums = nums;
+ }
+
+ public int sumRange(int i, int j) {
+
+ if (i > j) {
+ throw new IllegalArgumentException("i = " + i + ", j = " + j + ", i must not greater than j");
+ }
+
+ if (j < 0) {
+ throw new IllegalArgumentException("i = " + i + ", j = " + j + ", i must not less than 0");
+ }
+
+ i = i < 0 ? 0 : i;
+ j = j >= nums.length ? nums.length - 1 : j;
+
+ int sum = 0;
+
+
+ for (int k = i; k <= j; k++) {
+ sum += nums[k];
+ }
+
+ return sum;
+ }
+}
diff --git a/[0303][Range Sum Query - Immutable]/src/Test.java b/[0303][Range Sum Query - Immutable]/src/Test.java
new file mode 100644
index 0000000..470204f
--- /dev/null
+++ b/[0303][Range Sum Query - Immutable]/src/Test.java
@@ -0,0 +1,12 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-10-12 14:17
+ **/
+public class Test {
+ public static void main(String[] args) {
+ NumArray array = new NumArray(new int[]{-2, 0, 3, -5, 2, -1});
+ System.out.println(array.sumRange(0, 2));
+ System.out.println(array.sumRange(2, 5));
+ System.out.println(array.sumRange(0, 5));
+ }
+}
diff --git a/[0326][Power of Three]/[0326][Power of Three].iml b/[0326][Power of Three]/[0326][Power of Three].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0326][Power of Three]/[0326][Power of Three].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0326][Power of Three]/src/Solution.java b/[0326][Power of Three]/src/Solution.java
new file mode 100644
index 0000000..71d743c
--- /dev/null
+++ b/[0326][Power of Three]/src/Solution.java
@@ -0,0 +1,25 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-11-16 15:21
+ **/
+public class Solution {
+
+ public boolean isPowerOfThree(int n) {
+ double rst = (Math.log10(n) / Math.log10(3));
+ return n > 0 && Double.doubleToLongBits((int) rst) == Double.doubleToLongBits(rst);
+ }
+
+ public boolean isPowerOfThree2(int n) {
+ return (n > 0 && 1162261467 % n == 0);
+ }
+
+ public boolean isPowerOfThree1(int n) {
+ while (n > 1 && n % 3 == 0) {
+ n /= 3;
+ }
+
+ return n == 1;
+ }
+
+
+}
diff --git a/[0326][Power of Three]/src/Test.java b/[0326][Power of Three]/src/Test.java
new file mode 100644
index 0000000..9cb8806
--- /dev/null
+++ b/[0326][Power of Three]/src/Test.java
@@ -0,0 +1,13 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-11-16 15:31
+ **/
+public class Test {
+ public static void main(String[] args) {
+ System.out.println(Double.doubleToLongBits((int) 1.00000000001)
+ == Double.doubleToLongBits(1.00000000001));
+
+ System.out.println(Double.doubleToLongBits((int) 1.00000000000)
+ == Double.doubleToLongBits(1.00000000000));
+ }
+}
diff --git a/[0338][Counting Bits ]/[0338][Counting Bits ].iml b/[0338][Counting Bits ]/[0338][Counting Bits ].iml
new file mode 100644
index 0000000..c8cb479
--- /dev/null
+++ b/[0338][Counting Bits ]/[0338][Counting Bits ].iml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0338][Counting Bits ]/src/Main.java b/[0338][Counting Bits ]/src/Main.java
new file mode 100644
index 0000000..6fe5d61
--- /dev/null
+++ b/[0338][Counting Bits ]/src/Main.java
@@ -0,0 +1,20 @@
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-07-03 20:50
+ **/
+public class Main {
+ @Test
+ public void test1() {
+ Solution solution = new Solution();
+ Assert.assertArrayEquals(new int[]{0, 1, 1}, solution.countBits(2));
+ }
+
+ @Test
+ public void test2() {
+ Solution solution = new Solution();
+ Assert.assertArrayEquals(new int[]{0, 1, 1, 2, 1, 2}, solution.countBits(5));
+ }
+}
diff --git a/[0338][Counting Bits ]/src/Solution.java b/[0338][Counting Bits ]/src/Solution.java
new file mode 100644
index 0000000..901792b
--- /dev/null
+++ b/[0338][Counting Bits ]/src/Solution.java
@@ -0,0 +1,60 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-07-03 20:38
+ **/
+public class Solution {
+
+ /**
+ *
+ * Given a non negative integer number num. For every numbers i in the range
+ * 0 ≤ i ≤ num calculate the number of 1's in their binary representation and
+ * return them as an array.
+ *
+ * Example 1:
+ *
+ * Input: 2
+ * Output: [0,1,1]
+ * Example 2:
+ *
+ * Input: 5
+ * Output: [0,1,1,2,1,2]
+ * Follow up:
+ *
+ * It is very easy to come up with a solution with run time O(n*sizeof(integer)).
+ * But can you do it in linear time O(n) /possibly in a single pass?
+ * Space complexity should be O(n).
+ * Can you do it like a boss? Do it without using any builtin function like
+ * __builtin_popcount in c++ or in any other language.
+ *
+ * 思路:
+ * 使用治法,
+ * i为偶数 bit(i) = bit(i/2)
+ * i为奇数 bit(i) = bit(i/2) + 1
+ *
+ *
+ * @param num
+ * @return
+ */
+ public int[] countBits(int num) {
+ if (num < 0) {
+ return new int[0];
+ } else if (num == 0) {
+ return new int[]{0};
+ } else if (num == 1) {
+ return new int[]{0, 1};
+ }
+
+ int[] dp = new int[num + 1];
+ dp[0] = 0;
+ dp[1] = 1;
+ for (int i = 2; i <= num; i++) {
+ dp[i] += dp[i / 2];
+ // 不是偶数,说明其比 i/2多一个一
+ if (i % 2 != 0) {
+ dp[i]++;
+ }
+ }
+
+ return dp;
+ }
+}
diff --git a/[0342][Power of Four]/[0342][Power of Four].iml b/[0342][Power of Four]/[0342][Power of Four].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0342][Power of Four]/[0342][Power of Four].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0342][Power of Four]/src/Solution.java b/[0342][Power of Four]/src/Solution.java
new file mode 100644
index 0000000..1466de8
--- /dev/null
+++ b/[0342][Power of Four]/src/Solution.java
@@ -0,0 +1,29 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-11-16 15:43
+ **/
+public class Solution {
+
+ public boolean isPowerOfFour(int num) {
+ return num > 0 && (num & (num - 1)) == 0 && (num - 1) % 3 == 0;
+ }
+
+
+ public boolean isPowerOfFour3(int num) {
+ int n = 0b1010101_01010101_01010101_01010101;
+// int n = 0x55555555;
+ return num > 0 && (num & (num - 1)) == 0 && (num & n) == num;
+ }
+
+ public boolean isPowerOfFour2(int num) {
+ double rst = (Math.log10(num) / Math.log10(4));
+ return num > 0 && Double.doubleToLongBits((int) rst) == Double.doubleToLongBits(rst);
+ }
+
+ public boolean isPowerOfFour1(int num) {
+ while (num > 1 && (num % 4 == 0)) {
+ num /= 4;
+ }
+ return num == 1;
+ }
+}
diff --git a/[0344][Reverse String]/[0344][Reverse String].iml b/[0344][Reverse String]/[0344][Reverse String].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0344][Reverse String]/[0344][Reverse String].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0344][Reverse String]/src/Solution.java b/[0344][Reverse String]/src/Solution.java
new file mode 100644
index 0000000..b7bc9c5
--- /dev/null
+++ b/[0344][Reverse String]/src/Solution.java
@@ -0,0 +1,25 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2018-11-16 16:04
+ **/
+public class Solution {
+ public String reverseString(String s) {
+ if (s == null || s.length() < 1) {
+ return s;
+ }
+
+ char[] chars = s.toCharArray();
+
+ for (int i = 0, j = chars.length - 1; i < j; i++, j--) {
+ swap(chars, i, j);
+ }
+
+ return new String(chars);
+ }
+
+ private void swap(char[] chars, int i, int j) {
+ char tmp = chars[i];
+ chars[i] = chars[j];
+ chars[j] = tmp;
+ }
+}
diff --git a/[0345][Reverse Vowels of a String]/[0345][Reverse Vowels of a String].iml b/[0345][Reverse Vowels of a String]/[0345][Reverse Vowels of a String].iml
new file mode 100644
index 0000000..c8cb479
--- /dev/null
+++ b/[0345][Reverse Vowels of a String]/[0345][Reverse Vowels of a String].iml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0345][Reverse Vowels of a String]/src/Main.java b/[0345][Reverse Vowels of a String]/src/Main.java
new file mode 100644
index 0000000..e2549b8
--- /dev/null
+++ b/[0345][Reverse Vowels of a String]/src/Main.java
@@ -0,0 +1,14 @@
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-27 20:03
+ **/
+public class Main {
+ @Test
+ public void test1() {
+ Solution solution = new Solution();
+ Assert.assertEquals("holle", solution.reverseVowels("hello"));
+ }
+}
diff --git a/[0345][Reverse Vowels of a String]/src/Solution.java b/[0345][Reverse Vowels of a String]/src/Solution.java
new file mode 100644
index 0000000..0704432
--- /dev/null
+++ b/[0345][Reverse Vowels of a String]/src/Solution.java
@@ -0,0 +1,47 @@
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-27 19:58
+ **/
+public class Solution {
+ public String reverseVowels(String s) {
+ if (s == null || s.length() == 0) {
+ return s;
+ }
+
+ char[] chars = s.toCharArray();
+
+ int left = 0;
+ int right = s.length() - 1;
+
+ String t = "aeiouAEIOU";
+
+ Set set = new HashSet<>(Arrays.asList('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'));
+
+ while (left < right) {
+ while (left < right && !set.contains(chars[left])) {
+ left++;
+ }
+ while (left < right && !set.contains(chars[right])) {
+ right--;
+ }
+
+ if (left < right) {
+ swap(chars, left, right);
+ left++;
+ right--;
+ }
+ }
+
+ return new String(chars);
+ }
+
+ private void swap(char[] chars, int left, int right) {
+ char temp = chars[left];
+ chars[left] = chars[right];
+ chars[right] = temp;
+ }
+}
diff --git a/[0347][Top K Frequent Elements]/[0347][Top K Frequent Elements].iml b/[0347][Top K Frequent Elements]/[0347][Top K Frequent Elements].iml
new file mode 100644
index 0000000..c8cb479
--- /dev/null
+++ b/[0347][Top K Frequent Elements]/[0347][Top K Frequent Elements].iml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0347][Top K Frequent Elements]/src/Main.java b/[0347][Top K Frequent Elements]/src/Main.java
new file mode 100644
index 0000000..a5c4d3e
--- /dev/null
+++ b/[0347][Top K Frequent Elements]/src/Main.java
@@ -0,0 +1,19 @@
+import org.junit.Test;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-07-03 21:13
+ **/
+public class Main {
+ @Test
+ public void test1() {
+ Solution solution = new Solution();
+ System.out.println(solution.topKFrequent(new int[]{1, 1, 1, 2, 2, 3}, 2));
+ }
+
+ @Test
+ public void test2() {
+ Solution solution = new Solution();
+ System.out.println(solution.topKFrequent(new int[]{4, 1, -1, 2, -1, 2, 3}, 2));
+ }
+}
diff --git a/[0347][Top K Frequent Elements]/src/Solution.java b/[0347][Top K Frequent Elements]/src/Solution.java
new file mode 100644
index 0000000..31cf516
--- /dev/null
+++ b/[0347][Top K Frequent Elements]/src/Solution.java
@@ -0,0 +1,72 @@
+import java.util.*;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-07-03 21:03
+ **/
+public class Solution {
+ /**
+ *
+ * Given a non-empty array of integers, return the k most frequent elements.
+ *
+ * Example 1:
+ *
+ * Input: nums = [1,1,1,2,2,3], k = 2
+ * Output: [1,2]
+ * Example 2:
+ *
+ * Input: nums = [1], k = 1
+ * Output: [1]
+ * Note:
+ *
+ * You may assume k is always valid, 1 ≤ k ≤ number of unique elements.
+ * Your algorithm's time complexity must be better than O(n log n), where n is the array's size.
+ *
+ *
+ *
+ * @param nums
+ * @param k
+ * @return
+ */
+ public List topKFrequent(int[] nums, int k) {
+ // 用于记录每个数出现的次数
+ Map map = new HashMap<>();
+ // 按出现次数降序,统计出现X的数字有哪些
+ SortedMap> counter = new TreeMap<>(new Comparator() {
+ @Override
+ public int compare(Integer o1, Integer o2) {
+ return o2 - o1;
+ }
+ });
+
+ // 记录每个数字出现的次数
+ for (int i : nums) {
+ map.merge(i, 1, Integer::sum);
+ }
+
+ // 记录出现X次的数字有哪些
+ for (Map.Entry entry : map.entrySet()) {
+ List list = counter.get(entry.getValue());
+ if (list == null) {
+ list = new LinkedList<>();
+ list.add(entry.getKey());
+ counter.put(entry.getValue(), list);
+ } else {
+ list.add(entry.getKey());
+ }
+ }
+
+ // 取K个结果
+ List result = new LinkedList<>();
+ for (List list : counter.values()) {
+ if (result.size() < k) {
+ int size = Math.min(k - result.size(), list.size());
+ result.addAll(list.subList(0, size));
+ } else {
+ break;
+ }
+ }
+
+ return result;
+ }
+}
diff --git a/[0349][Intersection of Two Arrays]/[0349][Intersection of Two Arrays].iml b/[0349][Intersection of Two Arrays]/[0349][Intersection of Two Arrays].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0349][Intersection of Two Arrays]/[0349][Intersection of Two Arrays].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[0349][Intersection of Two Arrays]/src/Solution.java b/[0349][Intersection of Two Arrays]/src/Solution.java
new file mode 100644
index 0000000..bf85d7c
--- /dev/null
+++ b/[0349][Intersection of Two Arrays]/src/Solution.java
@@ -0,0 +1,36 @@
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-28 14:42
+ **/
+public class Solution {
+ public int[] intersection(int[] nums1, int[] nums2) {
+
+ if (nums1 == null || nums1.length < 1 || nums2 == null || nums2.length < 1) {
+ return new int[0];
+ }
+
+ Set set = new HashSet<>();
+ Set result = new HashSet<>();
+
+ for (int i : nums1) {
+ set.add(i);
+ }
+
+ for (int i : nums2) {
+ if (set.contains(i)) {
+ result.add(i);
+ }
+ }
+
+ int[] r = new int[result.size()];
+ int i = 0;
+ for (int n : result) {
+ r[i++] = n;
+ }
+
+ return r;
+ }
+}
diff --git a/[0350][Intersection of Two Arrays II]/[0350][Intersection of Two Arrays II].iml b/[0350][Intersection of Two Arrays II]/[0350][Intersection of Two Arrays II].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0350][Intersection of Two Arrays II]/[0350][Intersection of Two Arrays II].iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+