diff --git a/.idea/dictionaries/devel.xml b/.idea/dictionaries/devel.xml
new file mode 100644
index 0000000..dd319fa
--- /dev/null
+++ b/.idea/dictionaries/devel.xml
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..6560a98
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml
new file mode 100644
index 0000000..3c50bd3
--- /dev/null
+++ b/.idea/kotlinc.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/KotlinJavaRuntime.xml b/.idea/libraries/KotlinJavaRuntime.xml
new file mode 100644
index 0000000..1a7265d
--- /dev/null
+++ b/.idea/libraries/KotlinJavaRuntime.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/KotlinJavaRuntime__2_.xml b/.idea/libraries/KotlinJavaRuntime__2_.xml
new file mode 100644
index 0000000..a626dfe
--- /dev/null
+++ b/.idea/libraries/KotlinJavaRuntime__2_.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/KotlinJavaRuntime__3_.xml b/.idea/libraries/KotlinJavaRuntime__3_.xml
new file mode 100644
index 0000000..c688076
--- /dev/null
+++ b/.idea/libraries/KotlinJavaRuntime__3_.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Week_01/.idea/Week_01.iml b/Week_01/.idea/Week_01.iml
new file mode 100644
index 0000000..d6ebd48
--- /dev/null
+++ b/Week_01/.idea/Week_01.iml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Week_01/.idea/compiler.xml b/Week_01/.idea/compiler.xml
new file mode 100644
index 0000000..f8d1dda
--- /dev/null
+++ b/Week_01/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Week_01/.idea/dictionaries/devel.xml b/Week_01/.idea/dictionaries/devel.xml
new file mode 100644
index 0000000..dd319fa
--- /dev/null
+++ b/Week_01/.idea/dictionaries/devel.xml
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/Week_01/.idea/encodings.xml b/Week_01/.idea/encodings.xml
new file mode 100644
index 0000000..d7865d5
--- /dev/null
+++ b/Week_01/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Week_01/.idea/inspectionProfiles/Project_Default.xml b/Week_01/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..6560a98
--- /dev/null
+++ b/Week_01/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Week_01/.idea/kotlinc.xml b/Week_01/.idea/kotlinc.xml
new file mode 100644
index 0000000..3c50bd3
--- /dev/null
+++ b/Week_01/.idea/kotlinc.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Week_01/.idea/libraries/KotlinJavaRuntime.xml b/Week_01/.idea/libraries/KotlinJavaRuntime.xml
new file mode 100644
index 0000000..1a7265d
--- /dev/null
+++ b/Week_01/.idea/libraries/KotlinJavaRuntime.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Week_01/.idea/misc.xml b/Week_01/.idea/misc.xml
new file mode 100644
index 0000000..84efc80
--- /dev/null
+++ b/Week_01/.idea/misc.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Week_01/.idea/modules.xml b/Week_01/.idea/modules.xml
new file mode 100644
index 0000000..8cab903
--- /dev/null
+++ b/Week_01/.idea/modules.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Week_01/.idea/uiDesigner.xml b/Week_01/.idea/uiDesigner.xml
new file mode 100644
index 0000000..e96534f
--- /dev/null
+++ b/Week_01/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/Week_01/.idea/workspace.xml b/Week_01/.idea/workspace.xml
new file mode 100644
index 0000000..99d739c
--- /dev/null
+++ b/Week_01/.idea/workspace.xml
@@ -0,0 +1,400 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1597582841691
+
+
+ 1597582841691
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ No facets are configured
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1.8
+
+
+
+
+
+
+
+
+
+
+
+ week01
+
+
+
+
+
+
+
+
+
+
+
+
+ 1.8
+
+
+
+
+
+
+
+
+
+
+
+ KotlinJavaRuntime
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Week_01/README.md b/Week_01/README.md
index 50de304..114762a 100644
--- a/Week_01/README.md
+++ b/Week_01/README.md
@@ -1 +1,20 @@
-学习笔记
\ No newline at end of file
+学习笔记
+
+本周作业
+
+简单:
+用 add first 或 add last 这套新的 API 改写 Deque 的代码 --没思路
+分析 Queue 和 Priority Queue 的源码
+删除排序数组中的重复项(Facebook、字节跳动、微软在半年内面试中考过)--做过3遍忘记了
+旋转数组(微软、亚马逊、PayPal 在半年内面试中考过)--抄了一遍
+合并两个有序链表(亚马逊、字节跳动在半年内面试常考)--抄了一遍
+合并两个有序数组(Facebook 在半年内面试常考)--抄了一遍
+两数之和(亚马逊、字节跳动、谷歌、Facebook、苹果、微软在半年内面试中高频常考)--有错误
+移动零(Facebook、亚马逊、苹果在半年内面试中考过)--记忆写出来的
+加一(谷歌、字节跳动、Facebook 在半年内面试中考过)----抄了一遍
+
+中等:
+设计循环双端队列(Facebook 在 1 年内面试中考过)--没思路。抄了一遍
+
+困难:
+接雨水(亚马逊、字节跳动、高盛集团、Facebook 在半年内面试常考)--看着和盛最多的水有点像,但是不会,抄了一遍
\ No newline at end of file
diff --git a/Week_01/week01/src/HomeWorkCyq.java b/Week_01/week01/src/HomeWorkCyq.java
new file mode 100644
index 0000000..5457b28
--- /dev/null
+++ b/Week_01/week01/src/HomeWorkCyq.java
@@ -0,0 +1,243 @@
+import java.util.Stack;
+
+public class HomeWorkCyq {
+ /*
+ * 1.ɾеظ
+ * */
+ public int deleteRepeat(int[] nums){
+
+ if(nums.length == 0 ){
+ return 0;
+ }
+ if(nums.length == 1){
+ return 1;
+ }
+ int i = 0;
+ for(int j=1 ; j= 0 && len2 >= 0){
+ nums1[len--] = nums1[len1]>nums2[len2]?nums1[len1--]:nums2[len2--];
+ }
+ System.arraycopy(nums2,0,nums1,0,len2+1);
+ }
+
+ /*
+ * 5.֮
+ * */
+ public int[] twoSum(int[] nums, int target){
+ if(nums.length == 0){
+ return null;
+ }
+ int[] res = new int[];
+ for(int i = 0;i= 0; i--){
+ digits[i]++;
+ digits[i] %= 10;
+ if(digits[i] != 0){
+ return digits;
+ }
+ }
+ digits = new int[digits.length + 1];
+ digits[0] = 1;
+ return digits;
+// if(digits == [0]){
+// return [1];
+// }
+//
+// for(int i = 0 ; i s = new Stack();
+ int i = 0, maxWater = 0, maxBotWater = 0;
+ while(i
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Week_02/README.md b/Week_02/README.md
index 50de304..b9770ae 100644
--- a/Week_02/README.md
+++ b/Week_02/README.md
@@ -1 +1,69 @@
-学习笔记
\ No newline at end of file
+学习笔记
+1.HashMap的小结
+1.1 大背景:先说一下java中的集合"List、Set、Map",继承结构如下,Map没有继承Collection
+Collection
+├List
+│├LinkedList,LinkedList实现了List接口,允许null元素。此外LinkedList提供额外的get,remove,insert方法在 LinkedList的首部或尾部。这些操作使LinkedList可被用作堆栈(stack),队列(queue)或双向队列(deque)。特点是寻址困难、插入和删除容易
+│├ArrayList,ArrayList实现了可变大小的数组(允许null)
+│└Vector Vector非常类似ArrayList,但是Vector是同步的。由Vector创建的Iterator,虽然和ArrayList创建的 Iterator是同一接口,但是,因为Vector是同步的,当一个Iterator被创建而且正在被使用,另一个线程改变了Vector的状态(例 如,添加或删除了一些元素),这时调用Iterator的方法时将抛出ConcurrentModificationException,因此必须捕获该 异常。
+│ └Stack Stack继承自Vector,实现一个后进先出的堆栈。Stack提供5个额外的方法使得 Vector得以被当作堆栈使用。基本的push和pop 方法,还有peek方法得到栈顶的元素,empty方法测试堆栈是否为空,search方法检测一个元素在堆栈中的位置。Stack刚创建后是空栈。
+└Set
+ |-HashSet 基于Hash算法实现,性能优于TreeSet;不允许出现重复元素;不保证集合顺序;允许null元素但由于不重复性最多允许一个;不同步的
+ └TreeSet 按照升序排列,根据构造方法的不同实现,肯能会按照元素的自然顺序排序,或者按照创建set时所提供的比较器进行排序。
+LinkedList和ArrayList的区别:1、ArrayList的实现是基于数组,LinkedList的实现是基于双向链表。2、对于随机访问,ArrayList优于LinkedList 3、对于插入和删除操作,LinkedList优于ArrayList 4、LinkedList比ArrayList更占内存,因为LinkedList的节点除了存储数据,还存储了两个引用,一个指向前一个元素,一个指向后一个元素。
+Map
+├Hashtable 1.Hashtable继承Map接口,实现一个key-value映射的哈希表。任何非空(non-null)的对象都可作为key或者value。添加数据使用put(key, value),取出数据使用get(key),这两个基本操作的时间开销为常数。2.Hashtable 通过initial capacity和load factor两个参数调整性能。通常缺省的load factor 0.75较好地实现了时间和空间的均衡。增大load factor可以节省空间但相应的查找时间将增大,这会影响像get和put这样的操作。3.作为key的对象将通过计算其散列函数来确定与之对应的value的位置,因此任何作为key的对象都必须实现hashCode和equals方法。4.Hashtable是同步的。
+├HashMap HashMap和Hashtable类似,不同之处在于HashMap是非同步的,并且允许null(即null value和null key)。capacity和load factor两个参数影响性能
+└WeakHashMap WeakHashMap是一种改进的HashMap,它对key实行“弱引用”,如果一个key不再被外部所引用,那么该key可以被GC回收。
+
+HashMap的两种遍历方式,推荐使用entrySet(效率高).
+Map map = new HashMap();
+ Iterator iter = map.entrySet().iterator();
+ while (iter.hasNext()) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ Object key = entry.getKey();
+ Object val = entry.getValue();
+ }
+Map map = new HashMap();
+ Iterator iter = map.keySet().iterator();
+ while (iter.hasNext()) {
+ Object key = iter.next();
+ Object val = map.get(key);
+ }
+1.2 小背景
+java.util.Map 接口,分别被AbstractMap、SortedMap、Hashtable(同时继承自Dictionary)实现;分别被AbstractMap被HashMap继承,LikedHashMap又继承自HashMap,TreeMap继承自AbstractMap同时实现了NavigableMap接口(继承自SortedMap)
+
+(1) HashMap:它根据键的hashCode值存储数据,大多数情况下可以直接定位到它的值,因而具有很快的访问速度,但遍历顺序却是不确定的。 HashMap最多只允许一条记录的键为null,允许多条记录的值为null。HashMap非线程安全,即任一时刻可以有多个线程同时写HashMap,可能会导致数据的不一致。如果需要满足线程安全,可以用 Collections的synchronizedMap方法使HashMap具有线程安全的能力,或者使用ConcurrentHashMap。
+(2) Hashtable:Hashtable是遗留类,很多映射的常用功能与HashMap类似,不同的是它承自Dictionary类,并且是线程安全的,任一时间只有一个线程能写Hashtable,并发性不如ConcurrentHashMap,因为ConcurrentHashMap引入了分段锁。Hashtable不建议在新代码中使用,不需要线程安全的场合可以用HashMap替换,需要线程安全的场合可以用ConcurrentHashMap替换。
+(3) LinkedHashMap:LinkedHashMap是HashMap的一个子类,保存了记录的插入顺序,在用Iterator遍历LinkedHashMap时,先得到的记录肯定是先插入的,也可以在构造时带参数,按照访问次序排序。
+(4) TreeMap:TreeMap实现SortedMap接口,能够把它保存的记录根据键排序,默认是按键值的升序排序,也可以指定排序的比较器,当用Iterator遍历TreeMap时,得到的记录是排过序的。如果使用排序的映射,建议使用TreeMap。在使用TreeMap时,key必须实现Comparable接口或者在构造TreeMap传入自定义的Comparator,否则会在运行时抛出java.lang.ClassCastException类型的异常。
+
+1.3 HashMap分析
+hashmap中存储的是健值对,从源码的结构看,Hash桶数组中存储的是Node对象(健值对的映射)。当存储Node到数组中时候通过hashCode()方法用key对数组长度取膜,发生Hash碰撞(多个不同key经过hashcode之后需要放在数组的同一个位置)则在数组当前位置扩展出来链表,当链表长度大于8时候转换成红黑树。
+
+static class Node implements Map.Entry {
+ final int hash; //用来定位数组索引位置
+ final K key;
+ V value;
+ Node next; //链表的下一个node
+
+ Node(int hash, K key, V value, Node next) { ... }
+ public final K getKey(){ ... }
+ public final V getValue() { ... }
+ public final String toString() { ... }
+ public final int hashCode() { ... }
+ public final V setValue(V newValue) { ... }
+ public final boolean equals(Object o) { ... }
+}
+// HashMap默认构造函数源码
+int threshold; // 所能容纳的key-value对极限 threshold = length * Load factor,Node[] table的初始化长度length(默认值是16,这个值总是2的n次方),Load factor为负载因子(默认值是0.75)
+final float loadFactor; // 负载因子,平衡空间和时间的因子,如果内存空间很多而又对时间效率要求很高,可以降低负载因子Load factor的值;相反,如果内存空间紧张而对时间效率要求不高,可以增加负载因子loadFactor的值,这个值可以大于1。
+int modCount; //用来记录HashMap内部结构发生变化的次数,主要用于迭代的快速失败。强调一点,内部结构发生变化指的是结构发生变化,例如put新键值对,但是某个key对应的value值被覆盖不属于结构变化。
+int size; //是HashMap中实际存在的键值对数量
+
+当length总是2的n次方时,h& (length-1)运算等价于对length取模,也就是h%length,但是&比%具有更高的效率。"在JDK1.8的实现中,优化了高位运算的算法,通过hashCode()的高16位异或低16位实现的:(h = k.hashCode()) ^ (h >>> 16),主要是从速度、功效、质量来考虑的,这么做可以在数组table的length比较小的时候,也能保证考虑到高低Bit都参与到Hash的计算中,同时不会有太大的开销。"没太理解其好处
+
+
+
+
+
diff --git a/Week_02/src/HomeWorkCyq.java b/Week_02/src/HomeWorkCyq.java
new file mode 100644
index 0000000..e960f19
--- /dev/null
+++ b/Week_02/src/HomeWorkCyq.java
@@ -0,0 +1,172 @@
+import java.util.Stack;
+
+/**
+ * ڶҵ
+ * 1.дһ HashMap Сܽᡣ
+ * дReadME.md
+ * 2.ЧĸλʣѷFacebookȸڰп
+ * 3.֮ͣڣѷﵽ 216 Ρֽ 147 Ρȸ 104 ΣFacebookƻѶҲڽԳ
+ * 4.N ǰѷڰп
+ * 5.HeapSort ѧ https://www.geeksforgeeks.org/heap-sort/
+ * еȣ
+ * 1.ĸλʷ飨ѷڰг
+ * 2.ѷֽڰп
+ * 3.ǰֽȸ衢Ѷڰп
+ * 4.N IJѷڰп
+ * 5.ֽڰп
+ * 6.ǰ K ƵԪأѷڰг
+ * Ԥϰ
+ * ԤϰĿ
+ * 1.¥
+ * 2.
+ * 3.Pow(x, n)
+ * 4.Ӽ
+ * 5.N ʺ
+ */
+public class HomeWorkCyq {
+ /**
+ *2.Чĸλ
+ */
+ public boolean isAnagram(String s, String t) {
+ if (s.length() != t.length()) {
+ return false;
+ }
+ char[] str1 = s.toCharArray();
+ char[] str2 = t.toCharArray();
+
+ Arrays.sort(str1);
+ Arrays.sort(str2);
+
+ return Arrays.euqals(str1, str2);
+ }
+ /**
+ * ֮
+ */
+ public int[] twoSum(int[] nums, int target) {
+ if(nums.length == 0){
+ return null;
+ }
+ //hashmap
+ HashMap mp = new HashMap<>();
+ int[] res = new int[2];
+ for(int i=0;i preorder(Node root) {
+ List res = new LinkedList<>();
+ Stack stack = new Stack<>();
+ if(root == null){
+ return res;
+ }
+ while(!stack.isEmpty()){
+ Node cur = stack.pop();
+ res.add(cur.val);
+ for(int i=cur.children.size()-1;i>=0;i--){
+ stack.push(cur.children.get(i));
+ }
+ }
+ return res;
+ }
+
+ /**
+ * ĸλʷ
+ */
+ public List> groupAnagrams(String[] strs) {
+ HashMap> hp = new HashMap<>();
+ for(int i = 0;i < strs.length;i++){
+ char[] s_arr = strs[i].toCharArray();
+ //
+ Arrays.sort(s_arr);
+ //ӳ
+ Sting key = String.value(s_arr);
+ if(hp.containsKey(key){
+ hp.get(key).add(strs[i]);
+ }else{
+ List l = new LinkedList<>();
+ l.add(strs[i]);
+ hp.put(key,l);
+ }
+ }
+ return new ArrayList>(hp.values());
+// if(strs.length == null) return new int[0];
+// List> l = new ArrayList<>();
+// for(int i=0;i inorderTraversal(TreeNode root) {
+ List res = new ArrayList();
+ TreeNode pre =null;
+ while(root != null){
+ if(root.left != null){
+ pre = root.left;
+ while(pre.right != null){
+ pre= pre.right;
+ }
+ pre.right = root;
+ TreeNode temp =root;
+ root = root.left;
+ temp.left = null;
+ }else{
+ res.add(root.val);
+ root = root.right;
+ }
+ }
+ return res;
+ }
+
+ /**
+ * N
+ */
+
+ /**
+ *
+ * */
+ public int nthUglyNumber(int n) {
+
+ }
+
+ /**
+ * ǰ K ƵԪ
+ */
+ public int[] topKFrequent(int[] nums, int k) {
+
+ }
+
+}
+
diff --git a/Week_02/src/test.java b/Week_02/src/test.java
new file mode 100644
index 0000000..a4143bd
--- /dev/null
+++ b/Week_02/src/test.java
@@ -0,0 +1,5 @@
+public class test {
+ public static void main(String args[]) {
+ System.out.println("Hello World!");
+ }
+}
diff --git a/Week_03/README.md b/Week_03/README.md
index 50de304..4e73461 100644
--- a/Week_03/README.md
+++ b/Week_03/README.md
@@ -1 +1,14 @@
-学习笔记
\ No newline at end of file
+学习笔记
+递归:4步骤:终结条件-》处理当前层逻辑-〉下钻下一层逻辑-》清扫当前层
+ 找最近重复子问题,找最间断的原型(不漏且不重复)
+ 模版
+ Public void recur(int level,int param){
+ if(level > MAX_LEVEL){
+ return;
+ }
+
+ process(level,param);
+
+ recur(level:level+1;newParam);
+
+ }
diff --git a/Week_03/Week_03.iml b/Week_03/Week_03.iml
new file mode 100644
index 0000000..245d342
--- /dev/null
+++ b/Week_03/Week_03.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Week_03/src/Solution.java b/Week_03/src/Solution.java
new file mode 100644
index 0000000..d4262a3
--- /dev/null
+++ b/Week_03/src/Solution.java
@@ -0,0 +1,42 @@
+import java.util.ArrayList;
+import java.util.List;
+
+class Solution {
+ public List generateParenthesis(int n) {
+ //ȿ2nӷ
+ //ڿɿЧ
+ ArrayList res = new ArrayList();
+ _generator(0, 0, n, "");
+ //_generator(0,n, "");
+ return res;
+ }
+
+// private void _generator(int level, int max, String s) {
+ private void _generator(int left, int right, int n, String s) {
+ //terminate
+ if(left == n && right ==n ){
+ System.out.println(s);
+ return;;
+ }
+ //process
+// String s1 = s + "(";
+// String s2 = s + ")";
+
+ //drill donw
+// _generator(level+1,max,s+"(");
+//// _generator(level+1,max,s+")");
+ if(left < n){
+ _generator(left+1,right,n,s+"(");
+ }
+ if(left > right ){
+ _generator(left,right+1,n,s+")");
+ }
+
+ //revers
+ }
+
+ public static void main(String[] args){
+ Solution sol = new Solution();
+ System.out.println(sol.generateParenthesis(3));
+ }
+}
\ No newline at end of file
diff --git a/Week_04/README.md b/Week_04/README.md
index 50de304..8873942 100644
--- a/Week_04/README.md
+++ b/Week_04/README.md
@@ -1 +1,35 @@
-学习笔记
\ No newline at end of file
+学习笔记
+*寻找最近可重复项,就可以考虑递归、分治和回溯
+1.递归
+模版
+public void recur(int level, int param) {
+ // 1.terminator --终结条件
+ if (level > MAX_LEVEL) {
+ // process result
+ return;
+ }
+ // 2.process current logic --当前处理逻辑
+ process(level, param);
+ // 3.drill down --下钻
+ recur( level: level + 1, newParam);
+ // 4.restore current status --清空状态,如果是全局变量或者入参的清空下需要清空
+
+}
+2.分治
+private static int divide_conquer(Problem problem) {
+ //1.terminal ---终结条件
+ if (problem == NULL) {
+ int res = process_last_result();
+ return res;
+ }
+ //2.大问题分解为子问题
+ subProblems = split_problem(problem)
+ //3.分别处理每一个子问题
+ res0 = divide_conquer(subProblems[0])
+ res1 = divide_conquer(subProblems[1])
+ //4.合并
+ result = process_result(res0, res1);
+
+ return result;
+}
+3.回溯,当下一层不符合期望的时候,回退上一层的结果并重新开始新一轮遍历
\ No newline at end of file
diff --git a/Week_04/src.iml b/Week_04/src.iml
new file mode 100644
index 0000000..4a3ded1
--- /dev/null
+++ b/Week_04/src.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Week_04/src/HomeWork.java b/Week_04/src/HomeWork.java
new file mode 100644
index 0000000..bf207ac
--- /dev/null
+++ b/Week_04/src/HomeWork.java
@@ -0,0 +1,259 @@
+import javax.swing.tree.TreeNode;
+import java.util.*;
+
+public class HomeWork {
+/**
+ * 1.
+ * һҵڵȣڵԼ
+ * ˼·ͨݹԶкڵ pp qq ʱءӵݣڵ p, qp,q ڽڵ rootroot ʱ(ֱУ)ڵ rootroot ΪȣϷ rootroot
+ *ֹ
+ * ԽҶڵ㣬ֱӷ null
+ * root p, qֱӷ root
+ * ƹ
+ * ݹӽڵ㣬ֵΪ leftleft
+ * ݹӽڵ㣬ֵΪ rightright
+ * ֵ leftleft rightright չΪ
+ * leftleft rightright ͬʱΪ ˵ rootroot / ж p,qp,q nullnull
+ * leftleft rightright ͬʱΪ ˵ p, qp,q rootroot ֱ / rootroot Ϊȣ rootroot
+ * leftleft Ϊ rightright Ϊ p,qp,q rootroot Уֱӷ rightright ɷΪ
+ * p,qp,q һ rootroot Уʱ rightright ָ ppΪ pp
+ * p,qp,q ڵ㶼 rootroot Уʱ rightright ָ Ƚڵ
+ * leftleft Ϊ rightright Ϊ 3. ͬ
+ *
+ * /
+ /**
+ * Definition for a binary tree node.
+ * public class TreeNode {
+ * int val;
+ * TreeNode left;
+ * TreeNode right;
+ * TreeNode(int x) { val = x; }
+ * }
+ */
+
+ public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
+
+ //1.terminal
+ if(root == null ||root == p || root == q){
+ return root;
+ }
+ //2.current logical
+ TreeNode left = lowestCommonAncestor(root.left,p,q);
+ TreeNode right = lowestCommonAncestor(root.right,p,q);
+ //3.drill down
+ if(left == null && right ==null ){
+ return null;
+ }
+ if(left == null){
+ return right;
+ }
+ if(right == null){
+ return left;
+ }
+ return root;
+ //4.reverse state
+ }
+
+ /**
+ * 2.ǰйûظԪ
+ * ǰ preorder = [3,9,20,15,7]
+ * inorder = [9,3,15,20,7]
+ * ˼·
+ * ǰصǣ ڵ ʼճĵһλ ڵ мλá
+ * 飬ǾͿƴ ڵ㣬 1
+ * Ŀ˵вظԪأô 1 ͿԶλмλã 1 ߵIJ־1 ұ߲־
+ *ǰ +ڵ 1,2,4,5 +ڵ 4,2,5,1ߵ鳤һġ
+ * ǿԸмλ 1ȷǰҲ֣ǰһǸڵ㣬
+ * ߲ǣ[1:mid_index]Ұ벿 [mid_index+1:]
+ * mid_index м±λá
+ * ݹ麯ʵ£
+ * ֹ:ǰΪ
+ * ǰһԪأƴڵ㣬ٽǰֳ룬ݹĴǰߺߣݹĴǰұߺұߡ
+ */
+ /**
+ * Definition for a binary tree node.
+ * public class TreeNode {
+ * int val;
+ * TreeNode left;
+ * TreeNode right;
+ * TreeNode(int x) { val = x; }
+ * }
+ */
+ public TreeNode buildTree(int[] preorder, int[] inorder) {
+ //1.terminal
+ if(preorder.length == 0 || inorder.length == 0){
+ return null;
+ }
+ //ǰһԪȷڵ
+ TreeNode root = new TreeNode(preorder[0]);
+ //2.current logical
+ //ѭҵǰȵԪأзΪ
+ for(int i = 0;i> output = new LinkedList();
+ int n,k;
+
+ public List> combine(int n, int k) {
+ // List> res = new ArrayList<>();
+ // dfs(n,k,res,0,new ArrayList());
+ // return res;
+ this.n = n;
+ this.k = k;
+ backtrack(1,new LinkedList());
+ return output;
+ }
+ public void backtrack(int first,LinkedList curr){
+ //1.ֹ
+ if(curr.size() == k){
+ output.add(new LinkedList(curr));
+ }
+ for(int i=first;i<=n;++i){
+ //2.current logical
+ curr.add(i);
+ //3.drill down
+ backtrack(i+1,curr);
+ //4.revsers state
+ curr.removeLast();
+ }
+ }
+ // public void dfs(int n,int k,List> res,int index,List temp){
+ // //1.terminal
+ // if(index == n){
+ // res.add(temp);
+ // return;
+ // }
+
+ // //2.current logical
+
+ // //3.drill down
+ // //ѡ
+ // dfs(n,k,res,index+1,temp);
+ // //ѡ
+
+ // for(int i=0;i> permute(int[] nums) {
+ List> res = new ArrayList<>();
+ int[] visit = new int[nums.length];
+ backtrack(res,nums,new ArrayList(),visit);
+ return res;
+ // if(nums.length == 0){
+ // return res;
+ // }
+ // dfs(nums,res,0, new LinkedList());
+ // return res;
+
+ }
+ public void backtrack(List> res,int[] nums,ArrayList temp,int[] visit){
+ //visitΪӷֹгظ
+ if(temp.size() == nums.length){
+ res.add(new ArrayList<>(temp));
+ return;
+ }
+ for(int i=0;i> res,int index,List temp){
+ // //1.terminal
+ // if(index == nums.length){
+ // res.add(temp);
+ // return;
+ // }
+ // //2.current logical
+
+ // //3.drill down
+ // //ѡ
+ // //dfs(nums,res,index+1,temp);
+ // //ѡ
+ // temp.add(nums[index]);
+ // dfs(nums,res,index+1,temp);
+ // //4.reverse state
+ // te
+ //}
+ /**
+ * 5.ȫ2
+ * һɰظֵУвظȫС
+ * ֧˼·Ҫڿʱû
+ */
+ public List> permuteUnique(int[] nums) {
+ int len = nums.length;
+ List> res = new ArrayList<>();
+ if(len == 0){
+ return res;
+ }
+
+ Arrays.sort(nums);
+
+ boolean[] used = new boolean[len];
+ Deque path = new ArrayDeque<>(len);
+ dfs(nums,res,len,0,path,used);
+ return res;
+ }
+ public void dfs(int[] nums,List> res,int len,int depth,Deque path,boolean[] used){
+ if(depth == len){
+ res.add(new ArrayList<>(path));
+ return ;
+ }
+ for(int i=0;i0 && nums[i] == nums[i-1] && used[i-1] == false){
+ continue;
+ }
+ path.addLast(nums[i]);
+ used[i] = true;
+ dfs(nums,res,len,depth+1,path,used);
+
+ used[i] = false;
+ path.removeLast();
+
+ }
+ }
+}
diff --git a/Week_05/README.md b/Week_05/README.md
index 50de304..e6d442b 100644
--- a/Week_05/README.md
+++ b/Week_05/README.md
@@ -1 +1,53 @@
-学习笔记
\ No newline at end of file
+学习笔记
+1.BFS
+pubulic class TreeNode{
+ int val;
+ TreeNode left;
+ TreeNode right;
+
+ TreeNode(int x){
+ val =x;
+ }
+}
+public List> levelOrder(TreeNode root){
+ List> allresults = new ArrayList<>();
+ if(root == null){
+ return allResults;
+ }
+ Queue nodes = new LinkedList<>();
+ nodes.add(root);
+ while(!nodes.isEmpty()){
+ int size = nodes.size();
+ List results = new ArrayList<>();
+ for(int i =0;itarget){
+ right = mid-1;
+ }else{
+ left = mid+1;
+ }
+ }
+ return right;
+}
+
diff --git a/Week_05/Week_05.iml b/Week_05/Week_05.iml
new file mode 100644
index 0000000..b2682d2
--- /dev/null
+++ b/Week_05/Week_05.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Week_05/src/homeWork.java b/Week_05/src/homeWork.java
new file mode 100644
index 0000000..f024b3f
--- /dev/null
+++ b/Week_05/src/homeWork.java
@@ -0,0 +1,201 @@
+import java.util.Arrays;
+
+public class homeWork {
+ /**
+ * ƽ
+ * @param x
+ * @return
+ */
+ public int mySqrt(int x) {
+ //ֲңy=x^2,½(0-x)
+ if(x==0||x==1){
+ return x;
+ }
+ long left=1,right=x,mid=1;
+ while(left<=right){
+ mid = left+(right-left)/2;
+ if(mid*mid == x){
+ return (int)mid;
+ }else if(mid*mid>x){
+ right=mid-1;
+ }else{
+ left=mid+1;
+ }
+ }
+ return (int)right;
+ }
+ /**
+ * ţٵ
+ * бʹʽƵres=(cur+a/cur)/2
+ */
+ public int mySqrt(int x){
+ long cur=x;
+ while(cur*cur>x){
+ cur=(x+x/cur)/2;
+ }
+ return (int)cur;
+ }
+ /**
+ * 1. ˮ
+ * https://leetcode-cn.com/problems/lemonade-change/description/
+ */
+ public boolean lemonadeChange(int[] bills) {
+ //ջֵ5ֱӷ룬552pop֮ǰ5ڷ룬4pop53ڷ
+ //ֻ5102010000(bills.length<10000)
+ int five =0,ten=0;
+ //1
+ // if(bills.length == 0){
+ // return true;
+ // }
+ // if(bills.length == 1 && bills[0] ==5){
+ // return true;
+ // }else if(bills.length == 1 && (bills[0] == 10 || bills[0] == 20)){
+ // return false;
+ // }
+ // //2.̰㷨жѭݣ20105ȫ5
+ // for(int i=1;i0){
+ // five--;
+ // ten++;
+ // }else{
+ // return false;
+ // }
+ // }
+ // if(bills[i] == 20){
+ // if(five>0 && ten>0){
+ // five--;
+ // ten--;
+ // }else if(five>2){
+ // five -= 3;
+ // }else{
+ // return false;
+ // }
+ // }
+ // }
+ // return true;
+
+ //ύʧܺд˵
+ //1.
+ if(bills.length < 1){
+ return true;
+ }
+ if(bills[0] != 5){
+ return false;
+ }
+ for(int i=0;i0 && ten >0){
+ five--;
+ ten--;
+ }else if(five>2){
+ five-=3;
+ }else{
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+ /**
+ * Ʊʱ
+ * ˼·̰㷨ȡֲŽ⣬ȻֻԾֲ
+ */
+ public int maxProfit(int[] prices) {
+ //̰㷨ֲţֲΪ룬
+ int res=0;
+ for(int i=0;i=children[greedchild]){
+ // greedchild++;
+ // }
+ // cooke++;
+ // }
+ return greedchild;
+ }
+ /**
+ *ģ
+ * ˼·
+ * ⶼû
+ */
+ public int robotSim(int[] commands, int[][] obstacles) {
+
+ }
+
+ /**
+ * ʹöֲңѰһ [4, 5, 6, 7, 0, 1, 2] мĵط
+ * ˼·ֲңȽмֵԪشСģȽмԪغβԪشСжλһ
+ */
+ public int findInorder(int[] nums){
+ //
+ if(nums.length <= 2){
+ return -1;
+ }
+ int left=0,right=nums.length-1,mid;
+ while(leftnums[mid+1] && nums[mid] nums[mid-1]){
+ //жҲ
+ if(nums[mid]>nums[left]){
+ left = mid+1;
+ }else {
+ right=mid-1;
+ }
+ }else if(nums[mid] < nums[mid+1]){
+ //ж
+ if(nums[mid]