diff --git a/.gitignore b/.gitignore
index c7c7f14..c88077a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,122 @@
*.json
*.sqlite
*.ipch
+.idea
+
+# 20181212 排骨
+# -------------------
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+*$py.class
+
+# C extensions
+*.so
+
+# Distribution / packaging
+.Python
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+wheels/
+share/python-wheels/
+*.egg-info/
+.installed.cfg
+*.egg
+MANIFEST
+
+# PyInstaller
+# Usually these files are written by a python script from a template
+# before PyInstaller builds the exe, so as to inject date/other infos into it.
+*.manifest
+*.spec
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+htmlcov/
+.tox/
+.nox/
+.coverage
+.coverage.*
+.cache
+nosetests.xml
+coverage.xml
+*.cover
+.hypothesis/
+.pytest_cache/
+
+# Translations
+*.mo
+*.pot
+
+# Django stuff:
+*.log
+local_settings.py
+db.sqlite3
+
+# Flask stuff:
+instance/
+.webassets-cache
+
+# Scrapy stuff:
+.scrapy
+
+# Sphinx documentation
+docs/_build/
+
+# PyBuilder
+target/
+
+# Jupyter Notebook
+.ipynb_checkpoints
+
+# IPython
+profile_default/
+ipython_config.py
+
+# pyenv
+.python-version
+
+# celery beat schedule file
+celerybeat-schedule
+
+# SageMath parsed files
+*.sage.py
+
+# Environments
+.env
+.venv
+env/
+venv/
+ENV/
+env.bak/
+venv.bak/
+
+# Spyder project settings
+.spyderproject
+.spyproject
+
+# Rope project settings
+.ropeproject
+
+# mkdocs documentation
+/site
+
+# mypy
+.mypy_cache/
+.dmypy.json
+dmypy.json
+
+# Pyre type checker
+.pyre/
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
deleted file mode 100644
index 15a15b2..0000000
--- a/.idea/encodings.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/.idea/learning-algorithm.iml b/.idea/learning-algorithm.iml
deleted file mode 100644
index f3d7bc9..0000000
--- a/.idea/learning-algorithm.iml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100644
index 8656114..0000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index 3627932..0000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index 94a25f7..0000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
deleted file mode 100644
index d2a73e8..0000000
--- a/.idea/workspace.xml
+++ /dev/null
@@ -1,362 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- true
- DEFINITION_ORDER
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1543997006208
-
-
- 1543997006208
-
-
- 1544177157562
-
-
-
- 1544177157562
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Archer/239. Sliding Window Maximum/239. Sliding Window Maximum.py b/Archer/239. Sliding Window Maximum/239. Sliding Window Maximum.py
new file mode 100644
index 0000000..63506be
--- /dev/null
+++ b/Archer/239. Sliding Window Maximum/239. Sliding Window Maximum.py
@@ -0,0 +1,102 @@
+#!/usr/bin/env python
+# -*- coding:utf-8 -*-
+
+
+# 方法一、利用队列的思想,先进先出,不断滑动窗口[i:i+k]
+class Solution(object):
+ def maxSlidingWindow(self, nums, k):
+ """
+ :type nums: List[int]
+ :type k: int
+ :rtype: List[int]
+ """
+
+ win = []
+ n = len(nums)
+
+ if nums != []:
+ for i in range(n - k + 1):
+ win.append(max(nums[i:i + k]))
+
+ return win
+
+# 利用hea实现队列操作,先进先出
+class Solution(object):
+ def maxSlidingWindow(self, nums, k):
+ """
+ :type nums: List[int]
+ :type k: int
+ :rtype: List[int]
+ """
+ import heapq
+
+ win = []
+ hea = []# 注意不能写成:win = hea = []
+
+ n = len(nums)
+
+ hea.append(0)
+
+ for num in nums[0:k - 1]:
+ hea.append(num)
+
+ if nums != []:
+ for i in range(k - 1, n):
+ hea.append(nums[i])
+ hea.pop(0)
+ win.append(max(hea))
+
+ return win
+# 方法三、利用双向队列(效率最高)
+class Solution(object):
+ def maxSlidingWindow(self, nums, k):
+ """
+ :type nums: List[int]
+ :type k: int
+ :rtype: List[int]
+ """
+ win = []
+ hea = []
+
+ n = len(nums)
+
+ for i in range(k - 1): # 先建立第一个窗口的前k-1个
+ while hea != [] and nums[hea[-1]] < nums[i]: # 一直比较新数及队尾元素,若队尾较小则出队
+ hea.pop()
+ hea.append(i) #新数的索引入队
+
+ if nums != []:
+ for i in range(k - 1, n):
+ if hea != [] and (i - hea[0]) == k: # 队列中最大值的索引与新数的索引如果溢出窗口k,则队头出队
+ hea.pop(0)
+ while hea != [] and nums[hea[-1]] < nums[i]:
+ hea.pop()
+ hea.append(i)
+ win.append(nums[hea[0]]) # 队头的索引指示该窗口下的最大值
+
+ return win
+
+# 方法四、利用堆思想,跟方法三雷同
+
+class Solution(object):
+ def maxSlidingWindow(self, nums, k):
+ """
+ :type nums: List[int]
+ :type k: int
+ :rtype: List[int]
+ """
+ import heapq # 需要这个模块建立堆
+
+ win = []
+ hea = []
+
+ n = len(nums)
+
+ for i in range(n):
+ while hea != [] and (i - hea[0][1]) > k - 1: # 如果堆顶点对应的索引溢出,删除堆顶点(即删除最大值)
+ heapq.heappop(hea)
+ heapq.heappush(hea, (-nums[i], i)) #同时将数值和索引输入堆,以便判断堆顶点的索引是否溢出
+ if i > k - 2: # 在堆至少为窗口大小时,才开始输出最大值
+ win.append(-hea[0][0])
+
+ return win
\ No newline at end of file
diff --git "a/Archer/239. Sliding Window Maximum/239. Sliding Window Maximum\350\257\264\346\230\216\345\217\212\345\244\215\347\233\230.md" "b/Archer/239. Sliding Window Maximum/239. Sliding Window Maximum\350\257\264\346\230\216\345\217\212\345\244\215\347\233\230.md"
new file mode 100644
index 0000000..7f0fc19
--- /dev/null
+++ "b/Archer/239. Sliding Window Maximum/239. Sliding Window Maximum\350\257\264\346\230\216\345\217\212\345\244\215\347\233\230.md"
@@ -0,0 +1,11 @@
+# 算法实现:(详细见代码文档) #
+
+#给定一个数组 nums,有一个大小为 k 的滑动窗口从数组的最左侧移动到数组的最右侧。你只可以看到在滑动窗口 k 内的数字。滑动窗口每次只向右移动一位。返回滑动窗口最大值。 #
+
+# 复盘 #
+
+1. 用索引i和j不断滑动数组:nums[i:j],然后max求最大值
+
+2. 用伪队列思想,设置一个队列,然后不断入队出队,然后求最大值
+3. 双向队列,比较巧妙,队列里存储的是索引,具体解析见代码文档(注意的是,因为一边比较一边出队,比最大值更前的索引已经出队了,所以索引溢出窗口时队头出队即可,)
+4. 用堆,跟双向队列的方法雷同(注意的是,与双向队列不同,因为堆就算溢出也没有出队,所以堆要同时保存索引和值,循环判断索引溢出窗口,将堆顶弹出)
\ No newline at end of file
diff --git a/Archer/Happy Number/Happy Number.py b/Archer/Happy Number/Happy Number.py
new file mode 100644
index 0000000..3e0be3d
--- /dev/null
+++ b/Archer/Happy Number/Happy Number.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+# -*- coding:utf-8 -*-
+
+class Solution(object):
+ def isHappy(self, n):
+ """
+ :type n: int
+ :rtype: bool
+ """
+
+ dict_1 = {}
+
+ while 1:
+ sum = 0
+
+ while n != 0: #计算平方之和
+ sum += (n % 10) ** 2
+ n /= 10
+
+ n = sum
+
+ if n == 1: #如果平方之和为1,证明n是快乐数,返回True
+ return True
+ elif dict_1.has_key(n): #若平方之和已出现过(循环计算),证明加法之和不可能为1,n不是快乐数,返回False
+ return False
+
+ dict_1[n] = 0
+
diff --git "a/Archer/Happy Number/Happy Number\350\257\264\346\230\216\345\217\212\345\244\215\347\233\230.md" "b/Archer/Happy Number/Happy Number\350\257\264\346\230\216\345\217\212\345\244\215\347\233\230.md"
new file mode 100644
index 0000000..05eb5af
--- /dev/null
+++ "b/Archer/Happy Number/Happy Number\350\257\264\346\230\216\345\217\212\345\244\215\347\233\230.md"
@@ -0,0 +1,9 @@
+# 算法实现:(详细见代码文档) #
+
+#编写一个算法来判断一个数是不是“快乐数”。一个“快乐数”定义为:对于一个正整数,每一次将该数替换为它每个位置上的数字的平方和,然后重复这个过程直到这个数变为 1,也可能是无限循环但始终变不到 1。如果可以变为 1,那么这个数就是快乐数。 #
+
+# 复盘 #
+
+1. 用两个字典,一个字典存储加法结果各位数的平方,另一个字典存储平方之和
+
+2. 用一个字典存储平方之和,判断有无循环即可,不需要存储各个平方,直接加在一起便是
\ No newline at end of file
diff --git a/Archer/lengthOfLongestSubstring/20181211-lengthOfLongestSubstring-Archer-1.py b/Archer/lengthOfLongestSubstring/20181211-lengthOfLongestSubstring-Archer-1.py
new file mode 100644
index 0000000..3986e2b
--- /dev/null
+++ b/Archer/lengthOfLongestSubstring/20181211-lengthOfLongestSubstring-Archer-1.py
@@ -0,0 +1,63 @@
+#!/usr/bin/env python
+# -*- coding:utf-8 -*-
+
+s = "vdlkdk"
+dict = {}
+num = 0
+out = 0
+flag = 0
+i = 0
+#暴力法1:找到所有不重复的字符串
+'''
+for i in range(0,len(s)) :
+ dict[s[i]] = i
+ num += 1
+ for j in range(i+1,len(s)) :
+ if s[j] in dict :
+ break
+ dict[s[j]] = j
+ num += 1
+ out = [num, out][out > num]
+ if out >= len(s) / 2 :
+ break
+ dict.clear()
+ num = 0
+'''
+
+#暴力法2:从输出长度out入手
+'''
+for out in range(0,len(s)):
+ for i in range(0,out+1):
+ for j in range(i,i+len(s)-out):
+ if s[j] in dict:
+ dict.clear()
+ break
+ dict[s[j]] = j
+ else:
+ flag = 1
+ if flag == 1:
+ break
+ if flag == 1:
+ break
+
+print len(s)-out
+'''
+#滑动法,当往右滑动到右重复字符时,从前面重复的那个字符后开始搜索,不断循环
+'''
+n = len(s)
+while i < n:
+ if s[i] in dict:
+ i = dict[s[i]] + 1
+ out = [num, out][out > num]
+ num = 0
+ dict.clear()
+ dict[s[i]] = i
+ num += 1
+ i += 1
+ continue
+ dict[s[i]] = i
+ num += 1
+ i += 1
+out = [num, out][out > num]
+'''
+
diff --git a/Archer/lengthOfLongestSubstring/20181214-lengthOfLongestSubstring-Archer-2.py b/Archer/lengthOfLongestSubstring/20181214-lengthOfLongestSubstring-Archer-2.py
new file mode 100644
index 0000000..62a4eed
--- /dev/null
+++ b/Archer/lengthOfLongestSubstring/20181214-lengthOfLongestSubstring-Archer-2.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+# -*- coding:utf-8 -*-
+
+
+s = ""
+set0 = set()
+dict = {}
+num = 0
+out = 0
+flag = 0
+i = 0
+j = 0
+
+n = len(s)
+
+
+# 索引i和j分别表示子字符串的起始和结束,如何有相同的字符,则一直把前面的删掉,知道没有重复为止
+'''
+while i(j-i)]
+ else :
+ del dict[s[i]]
+ i += 1
+'''
+# 直接找字符串,用find,如果找到,先得到字符串大小,再把索引i往前移到找到的索引,优点是不用一直把前面的删掉,进一步优化效率
+
+j = 1
+i = 0
+
+
+while j= 0 and end < n:
+ if s[start] == s[end]:
+ if end - start + 1 > max:
+ max = end - start + 1
+ maxL = start
+ maxR = end
+ start -= 1
+ end += 1
+ else:
+ break
+
+ # 长度为奇数的回文子串
+ start = i - 1
+ end = i + 1
+ while start >= 0 and end < n:
+ if s[start] == s[end]:
+ if end - start + 1 > max:
+ max = end - start + 1
+ maxL = start
+ maxR = end
+ start -= 1
+ end += 1
+ else:
+ break
+ return s[maxL:maxR+1]
+
+###遍历指针为i, j=i+1, i左移,j右移。判断是否相等将长度,下标赋给临时变量,最后切片返回。边界条件也需要处理好。
diff --git "a/HughGuo/C006_Z \345\255\227\345\275\242\345\217\230\346\215\242.py" "b/HughGuo/C006_Z \345\255\227\345\275\242\345\217\230\346\215\242.py"
new file mode 100644
index 0000000..a816c0e
--- /dev/null
+++ "b/HughGuo/C006_Z \345\255\227\345\275\242\345\217\230\346\215\242.py"
@@ -0,0 +1,20 @@
+class Solution:
+ def convert(self, s, numRows):
+ """
+ :type s: str
+ :type numRows: int
+ :rtype: str
+ """
+ if len(s)<=numRows or numRows == 1:
+ return s
+ k = 2*numRows-2
+ ans = ['']*numRows
+ change = -1
+ i = 0
+ for char in s:
+ if i == 0 or i == numRows -1:
+ change = -change
+ ans[i] += char
+ i=i+change
+
+ return ''.join(ans)
diff --git "a/HughGuo/C007_\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260 (atoi).py" "b/HughGuo/C007_\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260 (atoi).py"
new file mode 100644
index 0000000..b041465
--- /dev/null
+++ "b/HughGuo/C007_\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260 (atoi).py"
@@ -0,0 +1,27 @@
+class Solution:
+ def myAtoi(self, str):
+ """
+ :type str: str
+ :rtype: int
+ """
+ import re
+ ret = re.findall(r"^[-+]?\d+", str.strip()) # strip()字符串去空格
+ if ret:
+ ret_str = ret[0] # 匹配的数字的字符串
+ ret_str2 = "" # 记录去符号的字符串,ret_str后面还要使用,所以定义一个新的变量记录
+ # 判断是否带有符号 + or -
+ if ret_str[0] == "-" or ret_str[0] == "+":
+ ret_str2 = ret_str[1:]
+ else:
+ ret_str2 = ret_str
+ # str转int
+ ret_int = int(ret_str2)
+ # 判断第一个字符是否为负号
+ if ret_str[0] == "-":
+ # 三目运算符,判断是否溢出
+ # 如果ret_int <= 2**31则返回-ret_int,否则返回-2**31
+ return -ret_int if ret_int <= 2**31 else -2**31
+ else:
+ return ret_int if ret_int < 2**31 else 2**31-1
+ else:
+ return 0
diff --git a/HughGuo/Leetcode-02/readme.md b/HughGuo/Leetcode-02/readme.md
deleted file mode 100644
index f909732..0000000
--- a/HughGuo/Leetcode-02/readme.md
+++ /dev/null
@@ -1,17 +0,0 @@
-# 两数相加
-
-给出两个 **非空** 的链表用来表示两个非负的整数。其中,它们各自的位数是按照 **逆序** 的方式存储的,并且它们的每个节点只能存储 **一位** 数字。
-
-如果,我们将这两个数相加起来,则会返回一个新的链表来表示它们的和。
-
-您可以假设除了数字 0 之外,这两个数都不会以 0 开头。
-
-
-
-## 思路
-
-1. 遍历,两元素相加,为和创建新链表元素,长度取短,考虑进位。 (弃用)
-
-2. sum=0,遍历时取sum%10为值,sum/10 为进位1,同时判断是否遍历结束
-
- ...Python真是慢...
\ No newline at end of file
diff --git a/HughGuo/readme.md b/HughGuo/readme.md
index 5d3aedf..d5b6dd4 100644
--- a/HughGuo/readme.md
+++ b/HughGuo/readme.md
@@ -1,4 +1 @@
-# HughGuo贡献内容
-
-- #2. 两数求和
-- #3. 无重复字符的最长子串
+# HughGuo贡献内容
\ No newline at end of file
diff --git a/ParkFeng/largest_tme_for_given_digits/Learn1.java b/ParkFeng/largest_tme_for_given_digits/Learn1.java
new file mode 100644
index 0000000..0d64ecd
--- /dev/null
+++ b/ParkFeng/largest_tme_for_given_digits/Learn1.java
@@ -0,0 +1,33 @@
+class Solution {
+
+ public String largestTimeFromDigits(int[] A) {
+ int res = -1;
+ for(int i = 0; i < 4; i ++){
+ for(int j = 0; j < 4; j ++){
+ if(i == j){
+ continue;
+ }
+ int hour = A[i] * 10 + A[j];
+ if(hour > 23){
+ continue;
+ }
+ for(int m = 0; m < 4; m ++){
+ if(m == i || m == j){
+ continue;
+ }
+ for(int n = 0; n < 4; n ++){
+ if(n == i || n == j || n ==m){
+ continue;
+ }
+ int minute = A[m] * 10 + A[n];
+ if(minute > 59){
+ continue;
+ }
+ res = Math.max(res, hour * 100 + minute);
+ }
+ }
+ }
+ }
+ return res == -1 ? "": (res/100 < 10 ? "0" + res/100: res/100) + ":" + (res % 100 < 10 ? "0" + res%100: res%100);
+ }
+}
\ No newline at end of file
diff --git a/ParkFeng/largest_tme_for_given_digits/readme.md b/ParkFeng/largest_tme_for_given_digits/readme.md
new file mode 100644
index 0000000..64130cc
--- /dev/null
+++ b/ParkFeng/largest_tme_for_given_digits/readme.md
@@ -0,0 +1,25 @@
+题目:
+
+给定一个由 4 位数字组成的数组,返回可以设置的符合 24 小时制的最大时间。
+
+最小的 24 小时制时间是 00:00,而最大的是 23:59。从 00:00 (午夜)开始算起,过得越久,时间越大。
+
+以长度为 5 的字符串返回答案。如果不能确定有效时间,则返回空字符串。
+
+示例 1:
+
+输入:[1,2,3,4]
+输出:"23:41"
+示例 2:
+
+输入:[5,5,5,5]
+输出:""
+
+
+提示:
+
+A.length == 4
+0 <= A[i] <= 9
+
+题目分析:
+在给定的四个数字中,找组成的最大时间,对于时间而言,时最大为23,分最大59
\ No newline at end of file
diff --git a/ParkFeng/leaf_similar_trees/Learn1.java b/ParkFeng/leaf_similar_trees/Learn1.java
new file mode 100644
index 0000000..3a4992c
--- /dev/null
+++ b/ParkFeng/leaf_similar_trees/Learn1.java
@@ -0,0 +1,32 @@
+class Solution {
+ public boolean leafSimilar(TreeNode root1, TreeNode root2) {
+ List l1 = new LinkedList<>();
+ List l2 = new LinkedList<>();
+
+ search(root1,l1);
+ search(root2,l2);
+
+ if(l1.size()!=l2.size()){
+ return false;
+ }
+
+ for(int i = 0;i < l1.size();i++) {
+ if(l1.get(i)!=l2.get(i)){
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public void search(TreeNode root,List res) {
+ if(root == null){
+ return;
+ }
+ search(root.left,res);
+ search(root.right,res);
+
+ if(root.left == null && root.right == null){
+ res.add(root.val);
+ }
+ }
+}
\ No newline at end of file
diff --git a/ParkFeng/leaf_similar_trees/readme.md b/ParkFeng/leaf_similar_trees/readme.md
new file mode 100644
index 0000000..7ab110a
--- /dev/null
+++ b/ParkFeng/leaf_similar_trees/readme.md
@@ -0,0 +1,23 @@
+题目:
+
+请考虑一颗二叉树上所有的叶子,这些叶子的值按从左到右的顺序排列形成一个 叶值序列 。
+
+
+
+举个例子,如上图所示,给定一颗叶值序列为 (6, 7, 4, 9, 8) 的树。
+
+如果有两颗二叉树的叶值序列是相同,那么我们就认为它们是 叶相似 的。
+
+如果给定的两个头结点分别为 root1 和 root2 的树是叶相似的,则返回 true;否则返回 false 。
+
+
+
+提示:
+
+给定的两颗树可能会有 1 到 100 个结点。
+
+题目分析:
+
+1、找出两棵树的叶值序列l1,l2
+
+2、按序比较l1和l2的叶子
\ No newline at end of file
diff --git a/ParkFeng/leaf_similar_trees/tree.png b/ParkFeng/leaf_similar_trees/tree.png
new file mode 100644
index 0000000..9298a57
Binary files /dev/null and b/ParkFeng/leaf_similar_trees/tree.png differ
diff --git a/ParkFeng/min_stack/Learn1.java b/ParkFeng/min_stack/Learn1.java
new file mode 100644
index 0000000..6b6a17f
--- /dev/null
+++ b/ParkFeng/min_stack/Learn1.java
@@ -0,0 +1,43 @@
+class MinStack {
+
+ private List stack = new ArrayList<>();
+ private List mins = new ArrayList<>();
+
+ /** initialize your data structure here. */
+ public MinStack() {
+ stack = new ArrayList<>();
+ mins = new ArrayList<>();
+ }
+
+ public void push(int x) {
+ stack.add(x);
+ if (mins.size() == 0){
+ mins.add(x);
+ } else {
+ mins.add(Math.min(x, mins.get(mins.size()-1)));
+ }
+ }
+
+ public void pop() {
+ int p = stack.get(stack.size()-1);
+ stack.remove(stack.size()-1);
+ mins.remove(mins.size()-1);
+ }
+
+ public int top() {
+ return stack.get(stack.size()-1);
+ }
+
+ public int getMin() {
+ return mins.get(mins.size()-1);
+ }
+}
+
+/**
+ * Your MinStack object will be instantiated and called as such:
+ * MinStack obj = new MinStack();
+ * obj.push(x);
+ * obj.pop();
+ * int param_3 = obj.top();
+ * int param_4 = obj.getMin();
+ */
\ No newline at end of file
diff --git a/ParkFeng/min_stack/readme.md b/ParkFeng/min_stack/readme.md
new file mode 100644
index 0000000..4bcd278
--- /dev/null
+++ b/ParkFeng/min_stack/readme.md
@@ -0,0 +1,19 @@
+题目:
+
+设计一个支持 push,pop,top 操作,并能在常数时间内检索到最小元素的栈。
+
+push(x) -- 将元素 x 推入栈中。
+pop() -- 删除栈顶的元素。
+top() -- 获取栈顶元素。
+getMin() -- 检索栈中的最小元素。
+示例:
+
+MinStack minStack = new MinStack();
+minStack.push(-2);
+minStack.push(0);
+minStack.push(-3);
+minStack.getMin(); --> 返回 -3.
+minStack.pop();
+minStack.top(); --> 返回 0.
+minStack.getMin(); --> 返回 -2.
+
diff --git a/ParkFeng/readme.md b/ParkFeng/readme.md
index e1d1353..1e6dfd1 100644
--- a/ParkFeng/readme.md
+++ b/ParkFeng/readme.md
@@ -4,4 +4,12 @@
1.对角线遍历分析
-2.按权重随机选择
\ No newline at end of file
+2.按权重随机选择
+
+3.最小栈
+
+4、给定数字能组成的最大时间
+
+5、叶子相似的树
+
+6、简化路径
\ No newline at end of file
diff --git a/ParkFeng/simplify_path/Learn1.java b/ParkFeng/simplify_path/Learn1.java
new file mode 100644
index 0000000..1624b6c
--- /dev/null
+++ b/ParkFeng/simplify_path/Learn1.java
@@ -0,0 +1,41 @@
+class Solution {
+ public String simplifyPath(String path) {
+ if(path == null || path.length()==0) {
+ return "";
+ }
+
+ LinkedList stack = new LinkedList();
+ StringBuilder res = new StringBuilder();
+ int i=0;
+
+ while(i=0;j--) {
+ res.append("/"+strs[j]);
+ }
+ }
+ if(res.length()==0) {
+ return "/";
+ }
+ return res.toString();
+ }
+}
\ No newline at end of file
diff --git a/ParkFeng/simplify_path/readme.md b/ParkFeng/simplify_path/readme.md
new file mode 100644
index 0000000..6ce038b
--- /dev/null
+++ b/ParkFeng/simplify_path/readme.md
@@ -0,0 +1,25 @@
+题目:
+
+给定一个文档 (Unix-style) 的完全路径,请进行路径简化。
+
+例如,
+path = "/home/", => "/home"
+path = "/a/./b/../../c/", => "/c"
+
+边界情况:
+
+你是否考虑了 路径 = "/../" 的情况?
+在这种情况下,你需返回 "/" 。
+此外,路径中也可能包含多个斜杠 '/' ,如 "/home//foo/" 。
+在这种情况下,你可忽略多余的斜杠,返回 "/home/foo"
+
+题目分析:
+
+此题目是Linux内核中比较常见的一个操作,就是对一个输入的文件的路径进行简化。
+
+具体思路:
+维护一个栈,对于每一个块(以‘/’作为分界)进行分析,
+如果遇到‘../’则表示要上一层,那么就是进行出栈操作,
+如果遇到‘./’则是停留当前,直接跳过,其他文件路径则直接进栈即可。
+最后根据栈中的内容转换成路径即可。
+时间上不会超过两次扫描,所以时间复杂度是O(n),空间上是栈的大小,也是O(n)
diff --git a/QianHu/LeetCode/207-CourseSchedule/__init__.py b/QianHu/LeetCode/207-CourseSchedule/__init__.py
new file mode 100644
index 0000000..7c68785
--- /dev/null
+++ b/QianHu/LeetCode/207-CourseSchedule/__init__.py
@@ -0,0 +1 @@
+# -*- coding: utf-8 -*-
\ No newline at end of file
diff --git a/QianHu/LeetCode/207-CourseSchedule/main.py b/QianHu/LeetCode/207-CourseSchedule/main.py
new file mode 100644
index 0000000..d6e1b4c
--- /dev/null
+++ b/QianHu/LeetCode/207-CourseSchedule/main.py
@@ -0,0 +1,34 @@
+# -*- coding: utf-8 -*-
+
+
+class Solution:
+ def canFinish(self, numCourses, prerequisites):
+ """
+ :type numCourses: int
+ :type prerequisites: List[List[int]]
+ :rtype: bool
+ """
+ all_nodes = {i: {'num': 0, 'node': []} for i in range(numCourses)}
+ for end, start in prerequisites:
+ all_nodes[start]['node'].append(end)
+ all_nodes[end]['num'] += 1
+
+ all_nodes_set = set([_ for _ in range(numCourses)])
+
+ while len(all_nodes_set) != 0:
+ flag = False
+ for start_node in all_nodes_set:
+ if all_nodes[start_node]['num'] == 0:
+ flag = True
+ break
+ if not flag:
+ return False
+ all_nodes_set.remove(start_node)
+ for end_node in all_nodes[start_node]['node']:
+ all_nodes[end_node]['num'] -= 1
+ return True
+
+
+if __name__ == '__main__':
+ solution = Solution()
+ assert solution.canFinish(2, [[1, 0]]) is True
diff --git a/QianHu/LeetCode/207-CourseSchedule/readme.md b/QianHu/LeetCode/207-CourseSchedule/readme.md
new file mode 100644
index 0000000..c045efc
--- /dev/null
+++ b/QianHu/LeetCode/207-CourseSchedule/readme.md
@@ -0,0 +1,101 @@
+LeetCode - 207.Course Schedule
+
+link: https://leetcode.com/problems/course-schedule/
+
+题目
+
+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:
+
+1. The input prerequisites is a graph represented by a list of edges, not adjacency matrices. Read more about how a graph is represented.
+2. You may assume that there are no duplicate edges in the input prerequisites.
+
+
+
+问题描述
+
+给出一系列的先修课程关系,判断如果按照这个关系,是否能顺利完成所有课程学习
+
+
+
+题目分析
+
+此题目实际是判断有向图中是否存在环,而拓扑排序的一个重要应用就是判断有向图中是否存在环,如果图中不存在环,那么是可以根据这个图求出一个拓扑序列
+
+- 根据拓扑排序的求取方式,我们先记录每个节点的入度数,以及以其为起始节点,对应的所有终止节点
+- 每次去选取入度数为0的节点,然后访问掉这个节点,如果节点不存在,那就是说这个图中剩余所有节点都有指向其的边,此时即存在环
+- 对应的,将其所指向的节点的入度数全部减1
+- 接下来接着去寻找入度为0的节点,已经访问过的节点不再检查,重复步骤,直至节点全部被访问,或者存在环
+
+
+
+代码实现
+
+ # -*- coding: utf-8 -*-
+
+
+ class Solution:
+ def canFinish(self, numCourses, prerequisites):
+ """
+ :type numCourses: int
+ :type prerequisites: List[List[int]]
+ :rtype: bool
+ """
+ all_nodes = {i: {'num': 0, 'node': []} for i in range(numCourses)}
+ for end, start in prerequisites:
+ all_nodes[start]['node'].append(end)
+ all_nodes[end]['num'] += 1
+
+ all_nodes_set = set([_ for _ in range(numCourses)])
+
+ while len(all_nodes_set) != 0:
+ flag = False
+ for start_node in all_nodes_set:
+ if all_nodes[start_node]['num'] == 0:
+ flag = True
+ break
+ if not flag:
+ return False
+ all_nodes_set.remove(start_node)
+ for end_node in all_nodes[start_node]['node']:
+ all_nodes[end_node]['num'] -= 1
+ return True
+
+
+ if __name__ == '__main__':
+ solution = Solution()
+ assert solution.canFinish(2, [[1, 0]]) is True
+
+
+
+
+运行结果
+
+ Time Submitted Status Runtime Language
+ a few seconds ago Accepted 268 ms python3
+
+
+
+吐槽
+
+LeetCode给出的模板,函数名和变量名没有按照PEP8规范来,正常是不应该驼峰命名的,而应该是小写加下划线形式
diff --git a/QianHu/LeetCode/readme.md b/QianHu/LeetCode/readme.md
new file mode 100644
index 0000000..c0e0c5c
--- /dev/null
+++ b/QianHu/LeetCode/readme.md
@@ -0,0 +1,4 @@
+## LeetCode Solution By Qian Hu
+
+### 33.Search in Rotated Sorted Array
+### 207.Course Schedule
diff --git a/QianHu/readme.md b/QianHu/readme.md
index e1bab37..b5a44fc 100644
--- a/QianHu/readme.md
+++ b/QianHu/readme.md
@@ -5,3 +5,4 @@
## LeetCode
### 33.Search in Rotated Sorted Array
+### 207.Course Schedule
diff --git a/Spareribs/0021 merge_two_sorted_lists/Readme.md b/Spareribs/0021 merge_two_sorted_lists/Readme.md
new file mode 100644
index 0000000..1894329
--- /dev/null
+++ b/Spareribs/0021 merge_two_sorted_lists/Readme.md
@@ -0,0 +1,91 @@
+**目录**
+- `题目: 合并两个有序链表`
+- `参考答案`
+ - `方案1 遍历法`
+- `问题`
+
+
+
+
+# 题目:合并两个有序链表 Merge Two Sorted Lists
+将两个有序链表合并为一个新的有序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。
+```
+示例:
+输入:1->2->4, 1->3->4
+输出:1->1->2->3->4->4
+```
+
+
+
+# 参考答案
+
+a href="#fa1">
+
+## 方案1 遍历法
+### 【思路】
+定义一个结果链表,判断两个链表中的数据大小,将结果存入结果链表中
+### 【实现】
+```python
+# Definition for singly-linked list.
+# class ListNode:
+# def __init__(self, x):
+# self.val = x
+# self.next = None
+
+class Solution:
+ def mergeTwoLists(self, l1, l2):
+ """
+ :type l1: ListNode
+ :type l2: ListNode
+ :rtype: ListNode
+ """
+ result = ListNode(0)
+ head = result # 神操作
+
+ # 确认 l1 和 l2 为空的场景, 直接返回
+ if l1 == None and l2 == None:
+ return None
+ elif l1 == None:
+ return l2
+ elif l2 == None:
+ return l1
+
+ while True:
+ # 比较 l1 和 l2 数据的大小
+ if l1.val < l2.val:
+ head.val = l1.val
+ l1 = l1.next
+ if l1 == None:
+ head.next = l2
+ break
+ head.next = ListNode(0)
+ head = head.next
+ else:
+ head.val = l2.val
+ l2 = l2.next
+ if l2 == None:
+ head.next = l1
+ break
+ head.next = ListNode(0)
+ head = head.next
+ return result
+```
+### 【分析】
+时间复杂度:假设一个是$n$个元素,对链表进行遍历($n$),最终链接所有元素($n+n$)
+
+空间复杂度:因为需要一个数组,所以需要额外的空间。这个空间的大小就是链表元素的个数 $O(n)$
+
+# 遇到的问题
+1. ListNode这种资源的操作的方法
+```
+# 获取 head.val 中的数据,此时的值为 0
+head = ListNode(0)
+head.val
+# 让 head的 next 也成为 ListNode 对象,值也为0
+head.next = ListNode(0)
+head = head.next
+```
+3. head = result 这样的神操作,在不改变原有数据的情况下,操作 result 中的 next 的数据
+
+-----------------------------
+欢迎提问,每天晚上都会定期回复~~
\ No newline at end of file
diff --git a/Spareribs/0023 merge_k_Sorted_lists/Readme.md b/Spareribs/0023 merge_k_Sorted_lists/Readme.md
new file mode 100644
index 0000000..880ccd2
--- /dev/null
+++ b/Spareribs/0023 merge_k_Sorted_lists/Readme.md
@@ -0,0 +1,82 @@
+**目录**
+- `题目: 合并K个排序链表`
+- `参考答案`
+ - `方案1 遍历法`
+- `问题`
+
+
+
+# 题目: 合并K个排序链表
+
+合并 k 个排序链表,返回合并后的排序链表。请分析和描述算法的复杂度。
+示例:
+```
+输入:
+[
+ 1->4->5,
+ 1->3->4,
+ 2->6
+]
+输出: 1->1->2->3->4->4->5->6
+```
+
+
+# 参考答案
+
+
+
+## 方案1 遍历法
+### 【思路】
+遍历 lists 中所有ListNode()数据,排序后创建链表。
+### 【实现】
+```python
+# Definition for singly-linked list.
+# class ListNode:
+# def __init__(self, x):
+# self.val = x
+# self.next = None
+
+class Solution:
+ def mergeKLists(self, lists):
+ """
+ :type lists: List[ListNode]
+ :rtype: ListNode
+ """
+ # 将所有的数存入一个空列表中
+ _nums = []
+ for _listnode in lists:
+ while _listnode:
+ _nums.append(_listnode.val)
+ _listnode = _listnode.next
+
+ # 如果列表为空, 直接返回
+ if _nums == []:
+ return []
+
+ # 对数据进行排序
+ _nums.sort()
+ print(_nums)
+
+ # 将结果整理到ListNode中
+ res = ListNode(0)
+ answer = res
+ for _num in _nums:
+ res.next = ListNode(0)
+ res = res.next
+ res.val =_num
+
+ # 需要去掉链表中第一个值
+ return answer.next
+```
+### 【分析】
+时间复杂度:假设一个是$n$个元素,对链表进行遍历($n$),对数组进行排序(排序算法可以达到$nlogn$),最终链接所有元素($n$),就是 ( $n+nlogn+n$),也就是 $O(nlogn)$
+
+空间复杂度:因为需要一个数组,所以需要额外的空间。这个空间的大小就是链表元素的个数 $O(n)$
+
+
+
+# 问题
+1. 需要总结一份ListNode(0) 这种结构的使用方式
+
+
+博客地址:[LeetCode刷题日记](https://blog.csdn.net/q370835062/column/info/30688) 欢迎关注,留言~~~
diff --git a/Spareribs/0053 merge_two_sorted_lists/Readme.md b/Spareribs/0053 maximums_subarray/Readme.md
similarity index 100%
rename from Spareribs/0053 merge_two_sorted_lists/Readme.md
rename to Spareribs/0053 maximums_subarray/Readme.md
diff --git a/Spareribs/readme.md b/Spareribs/readme.md
index c316253..904f23c 100644
--- a/Spareribs/readme.md
+++ b/Spareribs/readme.md
@@ -1,6 +1,14 @@
# Spareribs贡献日记
-## 难度简单
+## 简单
-53 最大子序和 merge_two_sorted_lists [点击跳转](https://github.com/guangcity/learning-algorithm/tree/master/Spareribs/0053%20merge_two_sorted_lists)
+0021 合并两个有序链表 0021 merge_two_sorted_lists [点击跳转](
+https://github.com/guangcity/learning-algorithm/tree/master/Spareribs/0021%merge_two_sorted_lists)
+0053 最大子序和 maximums_subarray [点击跳转](
+https://github.com/guangcity/learning-algorithm/tree/master/Spareribs/0053%maximums_subarray)
+
+
+## 困难
+0023 合并K个排序链表 merge_k_Sorted_lists [点击跳转](
+https://github.com/guangcity/learning-algorithm/tree/master/Spareribs/0023%merge_k_Sorted_lists)
\ No newline at end of file
diff --git "a/SugarChl/139.\345\215\225\350\257\215\346\213\206\345\210\206/139.\345\215\225\350\257\215\346\213\206\345\210\206.cpp" "b/SugarChl/139.\345\215\225\350\257\215\346\213\206\345\210\206/139.\345\215\225\350\257\215\346\213\206\345\210\206.cpp"
new file mode 100644
index 0000000..6aca263
--- /dev/null
+++ "b/SugarChl/139.\345\215\225\350\257\215\346\213\206\345\210\206/139.\345\215\225\350\257\215\346\213\206\345\210\206.cpp"
@@ -0,0 +1,16 @@
+class Solution {
+public:
+ bool wordBreak(string s, vector& wordDict) {
+ vector state(s.length()+1, false);
+ state[0] = true;
+ for (int i = 1; i <= s.length(); i++) {
+ //for (int j = 0; j <=i ; j++)
+ for (int j = i-1; j >=0 ; j--) {
+ if (state[j] && find(wordDict.begin(), wordDict.end(), s.substr(j, i-j)) != wordDict.end()) {
+ state[i] = true;
+ }
+ }
+ }
+ return state[s.length()];
+ }
+};
\ No newline at end of file
diff --git "a/SugarChl/\345\212\250\346\200\201\350\247\204\345\210\222/139.\345\215\225\350\257\215\346\213\206\345\210\206/139.\345\215\225\350\257\215\346\213\206\345\210\206.cpp" "b/SugarChl/\345\212\250\346\200\201\350\247\204\345\210\222/139.\345\215\225\350\257\215\346\213\206\345\210\206/139.\345\215\225\350\257\215\346\213\206\345\210\206.cpp"
new file mode 100644
index 0000000..5f8aae3
--- /dev/null
+++ "b/SugarChl/\345\212\250\346\200\201\350\247\204\345\210\222/139.\345\215\225\350\257\215\346\213\206\345\210\206/139.\345\215\225\350\257\215\346\213\206\345\210\206.cpp"
@@ -0,0 +1,16 @@
+class Solution {
+public:
+ bool wordBreak(string s, vector& wordDict) {
+ vector state(s.length()+1, false);
+ state[0] = true;
+ for (int i = 1; i <= s.length(); i++) {
+ //for (int j = 0; j <=i ; j++) 原代码
+ for (int j = i-1; j >=0 ; j--) {
+ if (state[j] && find(wordDict.begin(), wordDict.end(), s.substr(j, i-j)) != wordDict.end()) {
+ state[i] = true;
+ }
+ }
+ }
+ return state[s.length()];
+ }
+};
\ No newline at end of file
diff --git "a/SugarChl/\345\212\250\346\200\201\350\247\204\345\210\222/readme.md" "b/SugarChl/\345\212\250\346\200\201\350\247\204\345\210\222/readme.md"
index a454c19..b25cbec 100644
--- "a/SugarChl/\345\212\250\346\200\201\350\247\204\345\210\222/readme.md"
+++ "b/SugarChl/\345\212\250\346\200\201\350\247\204\345\210\222/readme.md"
@@ -1,29 +1,36 @@
-# 动态规划 个人归纳
-
-做了一些题目之后,就无法忍受暴力的方法来解题了。
-针对可以使用动态规划的题目,做一些总结,请各位大佬指正~
-
-
-当一个大规模问题可以被分解为小规模子问题,那么一般来说,这个问题就可以使用动态规划来求解。
-要使用动态规划,那么就要构建状态转移方程。
-“状态转移方程,是动态规划中本阶段的状态往往是上一阶段状态和上一阶段决策的结果”(来自百度百科)
-动态规划,是要将问题分解。
-那么,问题与子问题之间该怎么连接呢。
-这就要构建状态转移方程。
-
-
-## 221.最大正方形的问题。
->选取矩阵中的一个点。x[i][j]
->x点是否是最大正方形的右下角的点 与x[i-1][j] x[i][j-1] x[i-1][j-1]这三个点有关
->①若DP[i-1][j],DP[i][j-1],DP[i-1][j-1]三者中存在0值,则DP[i][j]一定为0;
->②若DP[i-1][j],DP[i][j-1],DP[i-1][j-1]均不为0,则DP[i][j]为三者中的最小值+1,因为三者中的最小值一定为三者所共有的不含0的部分,否则会造成缺角;
-
->因此对于某一点(i,j), 若matrix[i][j]=1,则动态规划表达式为DP[i][j] = min{DP[i-1][j],DP[i][j-1],DP[i-1][j-1]} + 1;
-
-## 5.最长回文子串
->对于字符串str,假设dp[i,j]=1表示str[i...j]是回文子串
->那么dp[i+1,j-1] 也必然是回文子串
->这样最长回文子串就被分解成了一系列规模小的子问题。这样就能求解了。
-
->状态转移方程: dp[i,j]={dp[i+1,j-1],str[i]==str[j];0,str[i]!=str[j]}
-
+# 动态规划 个人归纳
+
+做了一些题目之后,就无法忍受暴力的方法来解题了。
+针对可以使用动态规划的题目,做一些总结,请各位大佬指正~
+
+
+当一个大规模问题可以被分解为小规模子问题,那么一般来说,这个问题就可以使用动态规划来求解。
+要使用动态规划,那么就要构建状态转移方程。
+“状态转移方程,是动态规划中本阶段的状态往往是上一阶段状态和上一阶段决策的结果”(来自百度百科)
+动态规划,是要将问题分解。
+那么,问题与子问题之间该怎么连接呢。
+这就要构建状态转移方程。
+
+
+## 221.最大正方形的问题。
+>选取矩阵中的一个点。x[i][j]
+>x点是否是最大正方形的右下角的点 与x[i-1][j] x[i][j-1] x[i-1][j-1]这三个点有关
+>①若DP[i-1][j],DP[i][j-1],DP[i-1][j-1]三者中存在0值,则DP[i][j]一定为0;
+>②若DP[i-1][j],DP[i][j-1],DP[i-1][j-1]均不为0,则DP[i][j]为三者中的最小值+1,因为三者中的最小值一定为三者所共有的不含0的部分,否则会造成缺角;
+
+
+>因此对于某一点(i,j), 若matrix[i][j]=1,则动态规划表达式为DP[i][j] = min{DP[i-1][j],DP[i][j-1],DP[i-1][j-1]} + 1;
+
+## 5.最长回文子串
+>对于字符串str,假设dp[i,j]=1表示str[i...j]是回文子串
+>那么dp[i+1,j-1] 也必然是回文子串
+>这样最长回文子串就被分解成了一系列规模小的子问题。这样就能求解了。
+
+>状态转移方程: dp[i,j]={dp[i+1,j-1],str[i]==str[j];0,str[i]!=str[j]}
+
+
+## 139.单词拆分
+>对于这个问题来说,一整个字符串是否能被拆分成单词,只要看两个子字符串能否被拆分。
+>这段代码我是在网络上参考来的。运行时间需要20ms
+>经过深入的理解之后。
+>我将代码改了一部分细节。(见备注)运行时间缩短到了4ms
diff --git "a/codingling/LeetCode-03-LongestSubstringWithoutRepeatingCharacters/03.LongestSubstringWithoutRepeatingCharacters\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.py" "b/codingling/LeetCode-03-LongestSubstringWithoutRepeatingCharacters/03.LongestSubstringWithoutRepeatingCharacters\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.py"
new file mode 100644
index 0000000..acb2e1b
--- /dev/null
+++ "b/codingling/LeetCode-03-LongestSubstringWithoutRepeatingCharacters/03.LongestSubstringWithoutRepeatingCharacters\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.py"
@@ -0,0 +1,45 @@
+# -*- coding: utf-8 -*-
+# @Author: LiLing
+# @Date: 2018-10-02 19:20:50
+# @Last Modified by: Liling
+# @Last Modified time: 2018-12-12 20:39:03
+"""
+给定一个字符串,找出不含有重复字符的最长子串的长度。
+
+示例 1:
+
+输入: "abcabcbb"
+输出: 3
+解释: 无重复字符的最长子串是 "abc",其长度为 3。
+示例 2:
+
+输入: "bbbbb"
+输出: 1
+解释: 无重复字符的最长子串是 "b",其长度为 1。
+示例 3:
+
+输入: "pwwkew"
+输出: 3
+解释: 无重复字符的最长子串是 "wke",其长度为 3。
+ 请注意,答案必须是一个子串,"pwke" 是一个子序列 而不是子串
+"""
+class Solution(object):
+ def lengthOfLongestSubstring(self, s):
+ """
+ :type s: str
+ :rtype: int
+ """
+ if s == None or len(s) <= 0:
+ return 0
+ # charDict存储每个字符以及字符出现的最后的位置, res为当前最长的子串长度, st当前无重复子串的最左边字符的位置
+ charDict, res, st = {}, 0, 0
+ for i, ch in enumerate(s):
+ if ch not in charDict or charDict[ch] < st:
+ res = max(res, i - st + 1)
+ else:
+ st = charDict[ch] + 1
+ charDict[ch] = i
+ return res
+
+s = Solution()
+print(s.lengthOfLongestSubstring('pwwkew'))
\ No newline at end of file
diff --git a/codingling/LeetCode-03-LongestSubstringWithoutRepeatingCharacters/readme.md b/codingling/LeetCode-03-LongestSubstringWithoutRepeatingCharacters/readme.md
new file mode 100644
index 0000000..bd41a1a
--- /dev/null
+++ b/codingling/LeetCode-03-LongestSubstringWithoutRepeatingCharacters/readme.md
@@ -0,0 +1,69 @@
+## 03.Longest Substring Without Repeating Characters无重复字符的最长子串
+
+### 题目描述
+
+给定一个字符串,找出不含有重复字符的最长子串的长度。
+
+示例 1:
+
+输入: "abcabcbb"
+输出: 3
+解释: 无重复字符的最长子串是 "abc",其长度为 3。
+示例 2:
+
+输入: "bbbbb"
+输出: 1
+解释: 无重复字符的最长子串是 "b",其长度为 1。
+示例 3:
+
+输入: "pwwkew"
+输出: 3
+解释: 无重复字符的最长子串是 "wke",其长度为 3。
+ 请注意,答案必须是一个子串,"pwke" 是一个子序列 而不是子串
+
+### 思路
+
+第一种方法是暴力解法,检查所有的子串是不是有重复的字符,需要写一个检查字符串是否有重复字符的函数。这种方法的时间复杂度是$O(n^3)$,空间复杂度是O(min(n,m))。n是字符串长度,m是charset/alphabet长度。
+
+
+
+第二种方法。
+
+在第一种方法中,我们需要重复检查一个子串是不是有重复的字符,但这个步骤是不必要的。如果一个子串$s_{ij}$ 的i到j-1是不重复的子串,我们只需要检查s[j]是不是已经在前面的子串中就可以了。
+
+怎么检查呢?可以用哈希表作为滑动窗口来检查。用哈希表存储当前窗口[i,j)(初始时i=j)的字符,然后将索引j依次向右滑动,检查新的字符是否在哈希表中。如果不在,继续滑动。直到s[j]已经在哈希表中为止。这样就能找到以索引i开始的最长的无重复子串了。对于每个i重复上述操作就能得到结果。
+
+这种方法的时间复杂度是O(2n)=O(n),最坏情况下每个字符会被访问两次(i和j),空间复杂度不变,O(min(m,n))。
+
+
+
+上述方法还可以改进。
+
+如果s[j]在[i,j)有一个重复的字符,其索引是j',我们不需要一点一点地增大i,而是可以直接跳过[i, j']这个范围,直接让i=j'+1。
+
+我们可以不用哈希表来判断字符是否存在,我们可以定义一个字符到索引的映射字典。这样的话当我们遇到同样的字符时可以马上跳过这个字符。
+
+代码如下。当前窗口是[st, i)。如果当前字符不在字典中,或它的上一个索引不在当前扫描窗口内,说明还没有遇到重复的字符,更新当前最长的子串长度res;否则(当前字符是重复字符),更新扫描窗口(注意在上一个字符的时候已经更新了res,所以这里不用再更新)。记住不管什么情况都要更新字符的最新索引。
+
+```python
+class Solution(object):
+ def lengthOfLongestSubstring(self, s):
+ """
+ :type s: str
+ :rtype: int
+ """
+ if s == None or len(s) <= 0:
+ return 0
+ # charDict存储每个字符以及字符出现的最后的位置, res为当前最长的子串长度, st当前无重复子串的最左边字符的位置
+ charDict, res, st = {}, 0, 0
+ for i, ch in enumerate(s):
+ if ch not in charDict or charDict[ch] < st:
+ res = max(res, i - st + 1)
+ else:
+ st = charDict[ch] + 1
+ charDict[ch] = i
+ return res
+```
+
+
+
diff --git a/codingling/LeetCode-04/readme.md b/codingling/LeetCode-04/readme.md
new file mode 100644
index 0000000..30d74d2
--- /dev/null
+++ b/codingling/LeetCode-04/readme.md
@@ -0,0 +1 @@
+test
\ No newline at end of file
diff --git a/codingling/readme.md b/codingling/readme.md
index a76c870..014f4d8 100644
--- a/codingling/readme.md
+++ b/codingling/readme.md
@@ -1,5 +1,5 @@
# codingling贡献内容
-- AddTwoNumbers两数相加(链表),2018/12/04
-
-- TwoSum两数之和,2018/12/07
\ No newline at end of file
+- 02.AddTwoNumbers两数相加(链表),2018/12/04
+- 01.TwoSum两数之和,2018/12/07
+- 03.LongestSubstringWithoutRepeatingCharacters无重复字符的最长子串,2018/12/12
\ No newline at end of file
diff --git a/miss-ann/reverse/al/al.c b/miss-ann/reverse/al/al.c
new file mode 100644
index 0000000..38055c7
--- /dev/null
+++ b/miss-ann/reverse/al/al.c
@@ -0,0 +1,14 @@
+int reverse(int x) {
+ long res=0;
+ while(x!=0){
+ res=res*10+x%10;
+ x/=10;
+ }
+ int flog1=0x7fffffff;
+ int flog2=0x80000000;
+ if(resflog1){
+ return 0;
+ }
+ return (int)res;
+
+}
diff --git a/miss-ann/reverse/al/al.java b/miss-ann/reverse/al/al.java
new file mode 100644
index 0000000..eb49728
--- /dev/null
+++ b/miss-ann/reverse/al/al.java
@@ -0,0 +1,11 @@
+class Solution {
+ public int reverse(int x) {
+ long res=0;
+ while(x!=0){
+ res = res*10+x%10;
+ x/=10;
+ }
+ if(res>Integer.MAX_VALUE || res=0:
+ res = int(str(x)[::-1])
+ if -2**31 <= res <=2**31-1 :
+ return res
+ else:
+ return 0
+ else:
+ res = int(str(abs(x))[::-1])#非纯数字组成的字符串转换问题
+ if res<=2**31-1:
+ return -res
+ else:
+ return 0
diff --git a/miss-ann/reverse/readme.md b/miss-ann/reverse/readme.md
new file mode 100644
index 0000000..5f5d68d
--- /dev/null
+++ b/miss-ann/reverse/readme.md
@@ -0,0 +1,79 @@
+# 整数反转
+今天是小安开始Leetcode刷题的第七题,正文开始ing😎
+
+## 题目描述
+给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转。[题目原址](https://leetcode-cn.com/problems/reverse-integer/)
+**示例**
+【示例1】
+> 输入: 123
+> 输出:321
+
+【示例2】
+> 输入: -123
+> 输出:-321
+
+【示例3】
+> 输入: 120
+> 输出:21
+
+## 方法:暴力法
+
+### 思想
+利用x%10/x/10得到当前值,注意考虑的是负值情况以及值范围大小。
+### 代码实现
+
+【python3实现】
+```
+class Solution:
+ def reverse(self, x):
+ """
+ :type x: int
+ :rtype: int
+ """
+ if x>=0:
+ res = int(str(x)[::-1])
+ if -2**31 <= res <=2**31-1 :
+ return res
+ else:
+ return 0
+ else:
+ res = int(str(abs(x))[::-1])#非纯数字组成的字符串转换问题
+ if res<=2**31-1:
+ return -res
+ else:
+ return 0
+```
+【java实现】
+```
+class Solution {
+ public int reverse(int x) {
+ long res=0;
+ while(x!=0){
+ res = res*10+x%10;
+ x/=10;
+ }
+ if(res>Integer.MAX_VALUE || resflog1){
+ return 0;
+ }
+ return (int)res;
+
+}
+```
+
diff --git a/muchenchen/README.md b/muchenchen/README.md
new file mode 100644
index 0000000..ba62b3c
--- /dev/null
+++ b/muchenchen/README.md
@@ -0,0 +1,7 @@
+# muchenchen贡献内容
+
+
+
+### 1.从排序数组中删除重复项 delete_duplicates
+### 2.买卖股票的最佳时机 II best_time_to_stocks
+### 3.旋转数组 rotating_array
\ No newline at end of file
diff --git a/muchenchen/readme.md b/muchenchen/readme.md
deleted file mode 100644
index 43514b8..0000000
--- a/muchenchen/readme.md
+++ /dev/null
@@ -1,6 +0,0 @@
-# muchenchen贡献内容
-
-
-
-1.从排序数组中删除重复项 delete_duplicates
-2.买卖股票的最佳时机 II best_time_to_stocks
\ No newline at end of file
diff --git a/muchenchen/rotating_array/rotating_array.py b/muchenchen/rotating_array/rotating_array.py
new file mode 100644
index 0000000..d84da99
--- /dev/null
+++ b/muchenchen/rotating_array/rotating_array.py
@@ -0,0 +1,42 @@
+'''
+给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数。
+
+示例 1:
+
+输入: [1,2,3,4,5,6,7] 和 k = 3
+输出: [5,6,7,1,2,3,4]
+解释:
+向右旋转 1 步: [7,1,2,3,4,5,6]
+向右旋转 2 步: [6,7,1,2,3,4,5]
+向右旋转 3 步: [5,6,7,1,2,3,4]
+示例 2:
+
+输入: [-1,-100,3,99] 和 k = 2
+输出: [3,99,-1,-100]
+解释:
+向右旋转 1 步: [99,-1,-100,3]
+向右旋转 2 步: [3,99,-1,-100]
+说明:
+
+尽可能想出更多的解决方案,至少有三种不同的方法可以解决这个问题。
+要求使用空间复杂度为 O(1) 的原地算法。
+'''
+
+
+class Solution:
+ def rotate(self, nums, k):
+ """
+ :type nums: List[int]
+ :type k: int
+ :rtype: void Do not return anything, modify nums in-place instead.
+ """
+ num = len(nums)
+ k %= num
+ if k != 0:
+ for i in range(k):
+ j = num - 1
+ temp = nums[num - 1]
+ while j > 0:
+ nums[j] = nums[j - 1]
+ j -= 1
+ nums[0] = temp
diff --git a/readme.md b/readme.md
index 313017c..0710ca5 100644
--- a/readme.md
+++ b/readme.md
@@ -29,8 +29,8 @@
| woyaoyangguang | [直通点](https://github.com/guangcity/learning-algorithm/tree/master/woyaoyangguang) |
| 马晶敏 | [直通点](https://github.com/guangcity/learning-algorithm/tree/master/马晶敏) |
| 刘广月 | [直通车](https://github.com/guangcity/learning-algorithm/tree/master/刘广月) |
-| | |
-| | |
+| miss-ann | [直通车](https://github.com/guangcity/learning-algorithm/tree/master/miss-ann) |
+| 雪域小狼 | [直通车](https://github.com/guangcity/learning-algorithm/tree/master/雪域小狼) |
| | |
| | |
| | |
diff --git a/wangggong/readme.md b/wangggong/readme.md
index e0f9a2e..707cf71 100644
--- a/wangggong/readme.md
+++ b/wangggong/readme.md
@@ -1,4 +1,9 @@
# 王小炒贡献内容
1. 根据二叉树创建字符串 (20181204)
-
+2. 较大分组的位置 (20181206)
+3. 函数的独占时间 (20181210)
+4. 全局倒置与局部倒置 (20181213)
+5. 数组中重复的数据 (20181216)
+6. 插入区间 (20181219)
+7. 单词子集 (20181223)
\ No newline at end of file
diff --git "a/wangggong/\345\205\250\345\261\200\345\200\222\347\275\256\344\270\216\345\261\200\351\203\250\345\200\222\347\275\256.md" "b/wangggong/\345\205\250\345\261\200\345\200\222\347\275\256\344\270\216\345\261\200\351\203\250\345\200\222\347\275\256.md"
new file mode 100644
index 0000000..ad755a2
--- /dev/null
+++ "b/wangggong/\345\205\250\345\261\200\345\200\222\347\275\256\344\270\216\345\261\200\351\203\250\345\200\222\347\275\256.md"
@@ -0,0 +1,63 @@
+# 全局倒置与局部倒置
+
+学到了学到了.
+
+题目如下:
+
+数组 A 是 [0, 1, ..., N - 1] 的一种排列, N 是数组 A 的长度. 全局倒置指的是 i,j 满足 0 <= i < j < N 并且 A[i] > A[j] , 局部倒置指的是 i 满足 0 <= i < N 并且 A[i] > A[i+1] .
+
+当数组 A 中全局倒置的数量等于局部倒置的数量时, 返回 true .
+
+举个例子:
+
+> **输入**: A = [1,0,2]
+> **输出**: true
+> **解释**: 有 1 个全局倒置和 1 个局部倒置.
+
+反之,
+
+> **输入**: A = [1,2,0]
+> **输出**: false
+> **解释**: 有 2 个全局倒置和 1 个局部倒置.
+
+讲道理一开始的思路还挺对... 就是说题目本身其实问的是这么一件事:
+
+**如何判断数组里面存在*非局部倒置的全局倒置*?**
+
+也就是说:
+
+**如何判断数组里面存在*位置隔一个 (或以上) 的倒置*?**
+
+比如这个 [1,2,0], 其中的 1 和 0 就属于位置隔了一个的倒置.
+
+怎么判断呢? 有这么两个办法:
+
+办法 1. 判断数组前面 *i* 个元素的**最大值**比第 *i+2* 个元素大.
+
+就有这样的代码:
+
+```
+bool isIdealPermutation(vector& A) {
+ int maxVal = INT_MIN;
+ for (int i = 0; i+2 < A.size(); i++) {
+ maxVal = max(A[i], maxVal);
+ if (maxVal > A[i+2]) { return false; }
+ }
+ return true;
+}
+```
+
+办法 2. 如果数组里面存在一个元素, 元素值和索引值之间绝对值差距 > 1, 就说明存在非局部倒置的全局倒置.
+
+比如 [1,2,0], 我们说 0 哈... 由于它现在在第 2 个位置, 就导致 1 被挤到与 0 相隔一个的位置 (同理换了 2 也如此).
+
+因此这题有一个看上去及其简单的写法, 长这样:
+
+```
+bool isIdealPermutation(vector& A) {
+ for (int i = 0; i < A.size(); i++) {
+ if (abs(A[i] - i) > 1) { return false; }
+ }
+ return true;
+}
+```
\ No newline at end of file
diff --git "a/wangggong/\345\207\275\346\225\260\347\232\204\347\213\254\345\215\240\346\227\266\351\227\264.md" "b/wangggong/\345\207\275\346\225\260\347\232\204\347\213\254\345\215\240\346\227\266\351\227\264.md"
new file mode 100644
index 0000000..d7af02f
--- /dev/null
+++ "b/wangggong/\345\207\275\346\225\260\347\232\204\347\213\254\345\215\240\346\227\266\351\227\264.md"
@@ -0,0 +1,92 @@
+公粮.
+
+题目:
+
+给出一个非抢占单线程 CPU 的 *n* 个函数运行日志, 找到函数的独占时间.
+
+每个函数都有一个唯一的 Id, 从 0 到 n-1, 函数可能会递归调用或者被其他函数调用.
+
+日志是具有以下格式的字符串: *function_id: start_or_end: timestamp*. 例如: "0:start:0" 表示函数 0 从 0 时刻开始运行. "0:end:0" 表示函数 0 在 0 时刻结束.
+
+函数的独占时间定义是在该方法中花费的时间, 调用其他函数花费的时间不算该函数的独占时间. 你需要根据函数的 Id 有序地返回每个函数的独占时间.
+
+示例:
+
+> ** 输入: **
+> n = 2
+> logs =
+> ["0:start:0",
+> "1:start:2",
+> "1:end:5",
+> "0:end:6"]
+> ** 输出: [3, 4]**
+> ** 说明: **
+> 函数 0 在时刻 0 开始, 在执行了 2个时间单位结束于时刻 1.
+> 现在函数 0 调用函数 1, 函数 1 在时刻 2 开始, 执行 4 个时间单位后结束于时刻 5.
+> 函数 0 再次在时刻 6 开始执行, 并在时刻 6 结束运行, 从而执行了 1 个时间单位.
+> 所以函数 0 总共的执行了 2 + 1 = 3 个时间单位, 函数 1 总共执行了 4 个时间单位.
+
+挺重要的一点是 "**函数允许被递归调用**", 这个告诉我们可以考虑 *栈* 的结构. 划重点!
+
+问题是要往栈里面放啥呢? 首先你要放 *Id*. 然后还要放开始时间.
+
+那什么时候入栈什么时候出栈呢? 就先装作 **"start"** 的时候入栈, **"end"** 的时候出栈吧.
+
+然后模拟一下:
+
+ i | logs[i] | Stack | Result
+-----|-------------|------------------|----------
+ -1 | / | [] | []
+ 0 | "0:start:0" | [(0, 0)] | [0, 0]
+ 1 | "1:start:2" | [(0, 0), (1, 2)] | [0, 0]
+ 2 | "1:end:5" | [(0, 0)] | [0, (5-2)]
+ 3 | "0:end:6" | [] | [(6-0), 3]
+
+等等不对啊... 仔细看一下有两点需要注意:
+
+1. 出栈的时候更新时间, **结束时间 - 开始时间** 后是要 **+1s** 的 (简单的数学)
+2. 出栈的时候如果 **栈顶有东西**, 这代表 **当前结束的函数 (函数 1) 是栈顶的函数 (函数 0) 调用的**, 这时注意时间不要重复计算 (就像上面的 (6-0)).
+
+第一点好说, 第二点怎么办呢?
+
+```
+如果 栈里有东西(栈非空) {
+ 如果 入栈 (该命令为 ** start **) {
+ 栈顶函数对应时间 += 当前时间戳 - 栈内时间戳
+ }
+ 如果 出栈 (该命令为 ** end **) {
+ 栈内时间戳 = 当前时间戳 + 1
+ }
+}
+```
+
+综上, 能写出这么个东西:
+
+```
+vector exclusiveTime(int n, vector& logs) {
+ vector res(n);
+ stack> S;
+ for (string log : logs) {
+ size_t p = log.find(":");
+ size_t q = log.find(":", p+1);
+ int processId = stoi(log.substr(0, p));
+ int timestamp = stoi(log.substr(q+1));
+ if (log[p+1] == 's') {
+ if (!S.empty()) {
+ auto top = S.top();
+ res[top.first] += timestamp-top.second;
+ }
+ S.push(make_pair(processId, timestamp));
+ } else {
+ auto top = S.top(); S.pop();
+ res[top.first] += (timestamp+1) -top.second;
+ if (!S.empty()) {
+ auto top = S.top(); S.pop();
+ S.push(make_pair(top.first, timestamp+1));
+ }
+ }
+
+ }
+ return res;
+}
+```
diff --git "a/wangggong/\345\215\225\350\257\215\345\255\220\351\233\206.md" "b/wangggong/\345\215\225\350\257\215\345\255\220\351\233\206.md"
new file mode 100644
index 0000000..36d9f39
--- /dev/null
+++ "b/wangggong/\345\215\225\350\257\215\345\255\220\351\233\206.md"
@@ -0,0 +1,52 @@
+# 单词子集
+
+公粮.
+
+我们给出两个单词数组 A 和 B. 每个单词都是一串小写字母.
+
+现在, 如果 b 中的每个字母都出现在 a 中, 包括重复出现的字母, 那么称单词 b 是单词 a 的子集. 例如, "wrr" 是 "warrior" 的子集, 但不是 "world" 的子集.
+
+如果对 B 中的每一个单词 b, b 都是 a 的子集, 那么我们称 A 中的单词 a 是通用的.
+
+你可以按任意顺序以列表形式返回 A 中所有的通用单词.
+
+比如:
+
+> 输入: A = ["amazon","apple","facebook","google","leetcode"], B = ["l","e"]
+> 输出: ["apple","google","leetcode"]
+> 解释: 用这种方式把 LeetCode 和 Apple Google 并列这不是想瞎了心了...
+
+很简单的一点, 意识到就好.
+
+比如说, 如果 B = ["aaaaaabbbbbb", "aaabb", "aabbbb"], 那只要检测单词 B[0] 是否为单词 a 的子集就能判定 a 是不是通用的. 也就是说, 我们需要构造出这么一个"**完美**"的单词.
+
+怎么构造呢? 所有单词取并集吗? 对给出的例子就出现了 "le", 可以; 但对上面的例子就出现了 "aaaaaabbbbbbaaabbaabbbb", 显然不行.
+
+那应该咋办呢? 看代码:
+
+```
+const int NUM_ALPHABET = 26;
+
+vector wordSubsets(vector& A, vector& B) {
+ vector res;
+ vector count(NUM_ALPHABET);
+
+ for (string b : B) {
+ vector currcnt(NUM_ALPHABET);
+ for (char ch : b) { currcnt[ch - 'a']++; }
+ for (int i = 0; i < NUM_ALPHABET; i++) { count[i] = max(count[i], currcnt[i]); }
+ }
+
+ for (string a : A) {
+ vector currcnt(count.begin(), count.end());
+ for (char ch : a) {
+ if (currcnt[ch - 'a'] > 0) { currcnt[ch - 'a']--; }
+ }
+ int sum = 0;
+ for (int i = 0; i < NUM_ALPHABET; i++) { sum += currcnt[i]; }
+ if (sum == 0) { res.push_back(a); }
+ }
+
+ return res;
+}
+```
diff --git "a/wangggong/\346\217\222\345\205\245\345\214\272\351\227\264.md" "b/wangggong/\346\217\222\345\205\245\345\214\272\351\227\264.md"
new file mode 100644
index 0000000..f34accc
--- /dev/null
+++ "b/wangggong/\346\217\222\345\205\245\345\214\272\351\227\264.md"
@@ -0,0 +1,73 @@
+# 插入区间
+
+公粮.
+
+[原题见这里](https://leetcode-cn.com/problems/insert-interval/description/)
+
+给出一个*无重叠*的, 按照区间起始端点排序的区间列表.
+
+在列表中插入一个新的区间, 你需要确保列表中的区间仍然有序且不重叠 (如果有必要的话, 可以合并区间)
+
+比如:
+
+> 输入: intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8]
+> 输出: [[1,2],[3,10],[12,16]]
+> 解释: 这是因为新的区间 [4,8] 与 [3,5],[6,7],[8,10] 重叠.
+
+这个题目其实要注意的有这么一点:
+
+不原地操作的话, 可以**直接把 newInterval 依次插进区间列表**.
+
+那么对每个区间, 有两种情况:
+
+1. 和插入区间无重叠: 此时不需要任何改变.
+2. 和插入区间有重叠: 那么合并后的区间就是这两个区间的**并集**.
+
+那么什么是两个区间的并集呢? 举个例子, [1,3] 和 [2,4] 的并集是 [1,4], [1,3] 和 [0,2] 的并集是 [0,3], [1,4] 和 [2,3] 的并集是 [1,4]. 也就是说, [a,b] 和 [c,d] 的并集是 [min(a,c),max(b,d)].
+
+于是就有这样的代码:
+
+```
+struct Interval {
+ int start;
+ int end;
+ Interval() : start(0), end(0) {}
+ Interval(int s, int e) : start(s), end(e) {}
+};
+
+vector insert(vector& intervals, vector newInterval) {
+ int pos = 0; // 记录插入位置
+ vector res;
+ for (; intervals[pos].end < newInterval.start; pos++) { res.push_back(intervals[pos]); }
+ for (; intervals[pos].start <= newInterval.end; pos++) {
+ newInterval.start = min(newInterval.start, intervals[pos].start);
+ newInterval.end = max(newInterval.end, intervals[pos].end);
+ }
+ res.push_back(newInterval);
+ for (; pos < intervals.size(); pos++) { res.push_back(intervals[pos]); }
+ return res;
+}
+```
+
+对于 C++ 而言, 基于迭代器 (iterator) 我们可以写出这种东西 (虽然一个思路):
+
+```
+vector insert(vector& intervals, Interval newInterval) {
+ int pos = 0;
+ vector res;
+ for (auto it = intervals.begin(); it != intervals.end(); ++it) {
+ if (it->end < newInterval.start) {
+ res.push_back(*it);
+ pos++;
+ } else if (it->start > newInterval.end) {
+ res.push_back(*it);
+ } else {
+ newInterval.start = min(it->start, newInterval.start);
+ newInterval.end = max(it->end, newInterval.end);
+
+ }
+ }
+ res.insert(res.begin()+pos, newInterval);
+ return res;
+}
+```
diff --git "a/wangggong/\346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\346\215\256.md" "b/wangggong/\346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\346\215\256.md"
new file mode 100644
index 0000000..df5b6e2
--- /dev/null
+++ "b/wangggong/\346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\346\215\256.md"
@@ -0,0 +1,74 @@
+# 数组中重复的数据
+
+公粮.
+
+题目是这样的: 给定一个整数数组 *a*, 其中 **1 ≤ a[i] ≤ n** (n为数组长度), 其中有些元素出现两次而其他元素出现一次. 找到所有出现两次的元素.
+
+扩展问题如下: 你可以不用到任何额外空间并在O(n)时间复杂度内解决这个问题吗?
+
+题目本身很简单, 一个哈希就能解决了. 维护一个哈希集合, 如果元素在哈希集合里面存在, 也就说明该元素出现了两次.
+
+```
+vector findDuplicates(vector& nums) {
+ vector vec;
+ unordered_set S;
+ for (auto n : nums) {
+ if (S.count(n)) { vec.push_back(n); }
+ S.insert(n);
+ }
+ return vec;
+}
+```
+
+这个方法不用说, 时间复杂度 *O(n)*, 空间复杂度 *O(n)* (没有办法啊, 申请一个集合就到 *O(n)* 的复杂度了).
+
+所以就在想扩展问题该怎么办:
+
+1. 暴力? 时间是 *O(n^2)*. 两层循环. 太慢了.
+2. 排序? 空间复杂度低的时间复杂度高 (一般到 *O(n^2)* 时间复杂度, 比如**冒泡**, **插入**), 时间复杂度低的空间复杂度高 (比如**堆**, **归并**, **快排**), 特别的可以到 *O(n)* 的计数排序也要额外空间 (这个空间也是 *O(n)* 的... )
+3. 分治? 怎么分治? 顺带一提**有递归调用就算额外空间**了...
+4. 贪心? 人家是要求输出所有的结果的...
+5. 数据结构? 额外不允许申请空间, 怎么应用数据结构?
+
+结果想了半天, 突然发现: **1 ≤ a[i] ≤ n**, 这代表什么呢?
+
+这代表着**这个数组本身可以作为一个哈希表啊!**
+
+具体做法是这样: 对任意一个元素, 如果**它的值和它的位置不同**, 就**和它的值的位置上的元素交换** (强制让该元素的值和位置相同, 可以看做是做了一次哈希).
+
+(这里的 *index* 被定义为从 1 开始)
+
+比如:
+
+i 1 2 3 4
+a[i] 1 3 2 2
+
+第一个元素的位置和值相同, 不管. 交换第二个元素和第 (第二个元素值) 个元素 (就是第三个元素啦), 就变成了:
+
+i 1 2 3 4
+a[i] 1 2 3 2
+
+就发现这个数组本身就已经有哈希的属性了. 如果某个位置上的值和位置的 *index* 不同, 就说明这个元素重复了. (如上面的 a[4]. 想想为什么? )
+
+代码就变成了这样:
+
+```
+void swap(vector& V, int p, int q) {
+ int tmp = V[p];
+ V[p] = V[q];
+ V[q] = tmp;
+}
+
+vector findDuplicates(vector& nums) {
+ vector vec;
+ for (int i = 0; i < nums.size(); ) {
+ if (nums[i] != nums[nums[i]-1]) {
+ swap(nums, i, nums[i]-1);
+ } else { i++; }
+ }
+ for (int i = 0; i < nums.size(); i++) {
+ if (nums[i] != i+1) { vec.push_back(nums[i]); }
+ }
+ return vec;
+}
+```
diff --git a/woyaoyangguang/exist_duplicate/exist_duplicate.py b/woyaoyangguang/exist_duplicate/exist_duplicate.py
new file mode 100644
index 0000000..e577ae8
--- /dev/null
+++ b/woyaoyangguang/exist_duplicate/exist_duplicate.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+'''
+给定一个整数数组,判断是否存在重复元素.
+如果任何值在数组中出现至少两次,函数返回true.如果数组中每个元素不同,则返回false.
+
+示例 1:
+输入: [1,2,3,1]
+输出: true
+示例 2:
+输入: [1,2,3,4]
+输出: false
+'''
+
+'''
+思路:
+设定两个集合,通过循环数组判断元素是否在集合中,如果不在seen,将集合添加到seen集合中,
+如果在将元素,放入到另一集合duplicated中,这个集合中的元素都是数组中重复的元素,然后
+对其做一个判断,如果不为空,返回True,如果为空,返回False.
+'''
+class Solution:
+ def containsDuplicate(self, nums):
+ """
+ :type nums: List[int]
+ :rtype: bool
+ """
+ seen=set()
+ duplicated=set()
+ for x in nums:
+ if x not in seen:
+ seen.add(x)
+ else:
+ duplicated.add(x)
+ if duplicated:
+ return True
+ else:
+ return False
+
+
+
+a=Solution()
+print(a.containsDuplicate([1,2,3,4]))
diff --git a/woyaoyangguang/exist_duplicate/reademe.md b/woyaoyangguang/exist_duplicate/reademe.md
new file mode 100644
index 0000000..37ca395
--- /dev/null
+++ b/woyaoyangguang/exist_duplicate/reademe.md
@@ -0,0 +1 @@
+# 存在重复
\ No newline at end of file
diff --git a/yuhuacao/ReverseLinkedList.py b/yuhuacao/ReverseLinkedList.py
new file mode 100644
index 0000000..bf61522
--- /dev/null
+++ b/yuhuacao/ReverseLinkedList.py
@@ -0,0 +1,31 @@
+题目:
+给定一个链表,把这个链表反转过来。
+示例:
+输入: 1->2->3->4->5->NULL
+输出: 5->4->3->2->1->NULL
+解题思路:
+比较简单,对链表遍历,需保存上一个指针和下一个指针。在遍历过程中理清三者关系,注意不要互相覆盖即可。
+
+# Definition for singly-linked list.
+# class ListNode(object):
+# def __init__(self, x):
+# self.val = x
+# self.next = None
+
+class Solution(object):
+ def reverseList(self, head):
+ """
+ :type head: ListNode
+ :rtype: ListNode
+ """
+ if head==None:
+ return []
+ last_temp = None
+ temp = head
+ while(temp!=None):
+ temp_next = temp.next
+ temp.next = last_temp
+ last_temp = temp
+ temp = temp_next
+
+ return last_temp
diff --git a/yuhuacao/readme.md b/yuhuacao/readme.md
index 882fb90..341a097 100644
--- a/yuhuacao/readme.md
+++ b/yuhuacao/readme.md
@@ -2,3 +2,5 @@
1. Merge Sorted Array
2. Maximum Length of Repeated Subarray
+3. Reverse Linked List
+4. Three Sum
diff --git a/yuhuacao/threeSum.py b/yuhuacao/threeSum.py
new file mode 100644
index 0000000..91095fa
--- /dev/null
+++ b/yuhuacao/threeSum.py
@@ -0,0 +1,45 @@
+"""
+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: 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] ]
+"""
+"""
+解题思路:
+1,先将数组排序。
+2,排序后,可以按照TwoSum的思路来解题。怎么解呢?可以将num[i]的相反数即-num[i]作为target,然后从i+1到len(num)-1的数组元素中寻找两个数使它们的和为-num[i]就可以了。下标i的范围是从0到len(num)-3。
+3,这个过程要注意去重。
+4,时间复杂度为O(N^2)。
+"""
+
+
+class Solution(object):
+ def threeSum(self, nums):
+ """
+ :type nums: List[int]
+ :rtype: List[List[int]]
+ """
+ res = []
+ nums.sort()
+ for i in range(0, len(nums)):
+ if i > 0 and nums[i] == nums[i - 1]:
+ continue
+ target = 0 - nums[i]
+ start, end = i + 1, len(nums) - 1
+ while start < end:
+ if nums[start] + nums[end] > target:
+ end -= 1
+ elif nums[start] + nums[end] < target:
+ start += 1
+ else:
+ res.append((nums[i], nums[start], nums[end]))
+ end -= 1
+ start += 1
+ while start < end and nums[end] == nums[end + 1]:
+ end -= 1
+ while start < end and nums[start] == nums[start - 1]:
+ start += 1
+ return res
diff --git "a/\345\205\211\345\237\216/levelsearch1/bfs1.py" "b/\345\205\211\345\237\216/levelsearch1/bfs1.py"
new file mode 100644
index 0000000..462e47e
--- /dev/null
+++ "b/\345\205\211\345\237\216/levelsearch1/bfs1.py"
@@ -0,0 +1,28 @@
+class Solution:
+ def levelOrder(self, root):
+ # write your code here
+ res = []
+
+ if root is None:
+ return res
+ queue = [root]
+ # 列表为空时,循环终止
+ while queue and len(queue) != 0:
+ # 使用列表存储同层节点
+ level_val = []
+ # 同层节点的个数
+ length = len(queue)
+ for i in range(length):
+ # 将同层节点依次出队
+ h = queue.pop(0)
+ if h.left:
+ # 左孩子入队
+ queue.append(h.left)
+ if h.right:
+ # 右孩子入队
+ queue.append(h.right)
+ level_val.append(h.val)
+ res.append(level_val)
+ return res
+
+
diff --git "a/\345\205\211\345\237\216/levelsearch1/bfs2.py" "b/\345\205\211\345\237\216/levelsearch1/bfs2.py"
new file mode 100644
index 0000000..8c54967
--- /dev/null
+++ "b/\345\205\211\345\237\216/levelsearch1/bfs2.py"
@@ -0,0 +1,20 @@
+class Solution:
+ def levelOrder(self, root):
+ # write your code here
+ res = []
+ if not root:
+ return []
+ res_list = []
+ root_list = [root]
+ while root_list and len(root_list)!=0:
+ val_list = []
+ level_list = []
+ for node in root_list:
+ val_list.append(node.val)
+ if node.left:
+ level_list.append(node.left)
+ if node.right:
+ level_list.append(node.right)
+ root_list = level_list
+ res_list.append(val_list)
+ return res_list
\ No newline at end of file
diff --git "a/\345\205\211\345\237\216/levelsearch1/collection.py" "b/\345\205\211\345\237\216/levelsearch1/collection.py"
new file mode 100644
index 0000000..762a431
--- /dev/null
+++ "b/\345\205\211\345\237\216/levelsearch1/collection.py"
@@ -0,0 +1,22 @@
+class Solution:
+ def levelOrder(self, root):
+ # write your code here
+ res = []
+ if not root:
+ return res
+ import collections
+ queue = collections.deque()
+ queue.append(root)
+ # visited = set(root)
+ while queue:
+ length = len(queue)
+ level_val = []
+ for _ in range(length):
+ node = queue.popleft()
+ level_val.append(node.val)
+ if node.left:
+ queue.append(node.left)
+ if node.right:
+ queue.append(node.right)
+ res.append(level_val)
+ return res
\ No newline at end of file
diff --git "a/\345\205\211\345\237\216/levelsearch1/dfs.py" "b/\345\205\211\345\237\216/levelsearch1/dfs.py"
new file mode 100644
index 0000000..de75175
--- /dev/null
+++ "b/\345\205\211\345\237\216/levelsearch1/dfs.py"
@@ -0,0 +1,15 @@
+class Solution:
+ def levelOrder(self, root):
+ if not root:
+ return []
+ self.result = []
+ self.dfs(root, 0)
+ return self.result
+ def dfs(self, root, level):
+ if len(self.result) < level + 1:
+ self.result.append([])
+ self.result[level].append(root.val)
+ if root.left:
+ self.dfs(root.left, level + 1)
+ if root.right:
+ self.dfs(root.right, level + 1)
\ No newline at end of file
diff --git "a/\345\205\211\345\237\216/levelsearch2/bfs1.py" "b/\345\205\211\345\237\216/levelsearch2/bfs1.py"
new file mode 100644
index 0000000..76ebf85
--- /dev/null
+++ "b/\345\205\211\345\237\216/levelsearch2/bfs1.py"
@@ -0,0 +1,29 @@
+class Solution:
+ def levelOrderBottom(self, root):
+ """
+ :type root: TreeNode
+ :rtype: List[List[int]]
+ """
+ res = []
+
+ if root is None:
+ return res
+ queue = [root]
+ # 列表为空时,循环终止
+ while queue and len(queue) != 0:
+ # 使用列表存储同层节点
+ level_val = []
+ # 同层节点的个数
+ length = len(queue)
+ for i in range(length):
+ # 将同层节点依次出队
+ h = queue.pop(0)
+ if h.left:
+ # 左孩子入队
+ queue.append(h.left)
+ if h.right:
+ # 右孩子入队
+ queue.append(h.right)
+ level_val.append(h.val)
+ res.insert(0,level_val)
+ return res
\ No newline at end of file
diff --git "a/\345\205\211\345\237\216/levelsearch2/bfs2.py" "b/\345\205\211\345\237\216/levelsearch2/bfs2.py"
new file mode 100644
index 0000000..c0beaf1
--- /dev/null
+++ "b/\345\205\211\345\237\216/levelsearch2/bfs2.py"
@@ -0,0 +1,20 @@
+class Solution:
+ def levelOrderBottom(self, root):
+ # write your code here
+ res = []
+ if not root:
+ return []
+ res_list = []
+ root_list = [root]
+ while root_list and len(root_list)!=0:
+ val_list = []
+ level_list = []
+ for node in root_list:
+ val_list.append(node.val)
+ if node.left:
+ level_list.append(node.left)
+ if node.right:
+ level_list.append(node.right)
+ root_list = level_list
+ res_list.insert(0,val_list)
+ return res_list
\ No newline at end of file
diff --git "a/\345\205\211\345\237\216/levelsearch2/collection.py" "b/\345\205\211\345\237\216/levelsearch2/collection.py"
new file mode 100644
index 0000000..c4afcd7
--- /dev/null
+++ "b/\345\205\211\345\237\216/levelsearch2/collection.py"
@@ -0,0 +1,22 @@
+class Solution:
+ def levelOrderBottom(self, root):
+ # write your code here
+ res = []
+ if not root:
+ return res
+ import collections
+ queue = collections.deque()
+ queue.append(root)
+ # visited = set(root)
+ while queue:
+ length = len(queue)
+ level_val = []
+ for _ in range(length):
+ node = queue.popleft()
+ level_val.append(node.val)
+ if node.left:
+ queue.append(node.left)
+ if node.right:
+ queue.append(node.right)
+ res.insert(0,level_val)
+ return res
\ No newline at end of file
diff --git "a/\345\205\211\345\237\216/levelsearch2/dfs.py" "b/\345\205\211\345\237\216/levelsearch2/dfs.py"
new file mode 100644
index 0000000..b5d3bbd
--- /dev/null
+++ "b/\345\205\211\345\237\216/levelsearch2/dfs.py"
@@ -0,0 +1,19 @@
+class Solution:
+ def levelOrderBottom(self, root):
+ if not root:
+ return []
+ self.result = []
+ self.dfs(root, 0)
+ return self.result
+ def dfs(self, root, level):
+ if len(self.result) < level + 1:
+ self.result.append([])
+ self.result[level].append(root.val)
+ if root.left:
+ self.dfs(root.left, level + 1)
+ if root.right:
+ self.dfs(root.right, level + 1)
+
+t = [[3],[9,20],[15,7]]
+t =[2,1]
+print(t[::-1])
\ No newline at end of file
diff --git "a/\345\205\211\345\237\216/search/binary_search.py" "b/\345\205\211\345\237\216/search/binary_search.py"
new file mode 100644
index 0000000..24fc257
--- /dev/null
+++ "b/\345\205\211\345\237\216/search/binary_search.py"
@@ -0,0 +1,17 @@
+class BS:
+ def search(self,nums,target):
+ return self.bsearch(nums,0,len(nums)-1,target)
+ def bsearch(self,nums,low,high,target):
+ while(low<=high):
+ mid = (low+high)//2
+ if nums[mid] == target:
+ return mid
+ elif nums[mid] < target:
+ low=mid+1
+ elif nums[mid] > target:
+ high=mid-1
+ return None
+nums = [9,5,7,0,1,2,3,12]
+target = 0
+bs = BS()
+print(bs.search(nums,target))
\ No newline at end of file
diff --git "a/\345\205\211\345\237\216/search/search_bn.py" "b/\345\205\211\345\237\216/search/search_bn.py"
new file mode 100644
index 0000000..d3d4719
--- /dev/null
+++ "b/\345\205\211\345\237\216/search/search_bn.py"
@@ -0,0 +1,27 @@
+class Solution:
+ def search(self, nums, target):
+ """
+ :type nums: List[int]
+ :type target: int
+ :rtype: int
+ """
+ import sys
+ sys.setrecursionlimit(100000) # 这里设置为十万
+ return self.zheban(nums, target, 0, len(nums) - 1)
+
+ def zheban(self, nums, target, low, high):
+ if high < low:
+ return -1
+ mid = (low + high) // 2
+ if nums[mid] == target:
+ return mid
+ if nums[mid] >= nums[low]:
+ if nums[mid] >= target and target >= nums[low]:
+ return self.zheban(nums, target, low, mid - 1)
+ else:
+ return self.zheban(nums, target, mid + 1, high)
+ else:
+ if nums[mid] <= target and target <= nums[high]:
+ return self.zheban(nums, target, mid + 1, high)
+ else:
+ return self.zheban(nums, target, low, mid - 1)
\ No newline at end of file
diff --git "a/\345\272\225\345\261\202\346\220\254\347\240\226\345\267\245/leetcode544.py" "b/\345\272\225\345\261\202\346\220\254\347\240\226\345\267\245/leetcode544.py"
new file mode 100644
index 0000000..4b54c03
--- /dev/null
+++ "b/\345\272\225\345\261\202\346\220\254\347\240\226\345\267\245/leetcode544.py"
@@ -0,0 +1,26 @@
+class Solution(object):
+ def leastBricks(self, wall):
+ """
+ :type wall: List[List[int]]
+ :rtype: int
+ """
+ ans = []
+ for p in range(len(wall)):
+ x = wall[p]
+ sum = 0
+ for q in range(len(wall[p])):
+ sum+= wall[p][q]
+ if q != len(wall[p])-1:
+ ans.append(sum)
+ ans.sort()
+ ans2 = 0
+ nowmax = 0
+ before = -1
+ for i in range(len(ans)):
+ if before == ans[i]:
+ nowmax+=1
+ else:
+ nowmax=1
+ before = ans[i]
+ ans2= max(ans2,nowmax)
+ return len(wall)-ans2
\ No newline at end of file
diff --git "a/\345\272\225\345\261\202\346\220\254\347\240\226\345\267\245/leetcode822.py" "b/\345\272\225\345\261\202\346\220\254\347\240\226\345\267\245/leetcode822.py"
new file mode 100644
index 0000000..0b9b084
--- /dev/null
+++ "b/\345\272\225\345\261\202\346\220\254\347\240\226\345\267\245/leetcode822.py"
@@ -0,0 +1,23 @@
+class Solution(object):
+ def flipgame(self, fronts, backs):
+ """
+ :type fronts: List[int]
+ :type backs: List[int]
+ :rtype: int
+ """
+ lens = len(fronts)
+ ans = 9999
+ dictnone = {}
+ for i in range(lens):
+ if(fronts[i] == backs[i]):
+ dictnone[fronts[i]] = 1
+ for i in range(lens):
+ if not fronts[i] in dictnone.keys():
+ ans = min(ans,fronts[i])
+ for i in range(lens):
+ if not backs[i] in dictnone.keys():
+ ans = min(ans,backs[i])
+ if ans == 9999 :
+ return 0
+ else :
+ return ans
\ No newline at end of file
diff --git "a/\351\233\252\345\237\237\345\260\217\347\213\274/148. \346\216\222\345\272\217\351\223\276\350\241\250/code.cpp" "b/\351\233\252\345\237\237\345\260\217\347\213\274/148. \346\216\222\345\272\217\351\223\276\350\241\250/code.cpp"
new file mode 100644
index 0000000..0f7f167
--- /dev/null
+++ "b/\351\233\252\345\237\237\345\260\217\347\213\274/148. \346\216\222\345\272\217\351\223\276\350\241\250/code.cpp"
@@ -0,0 +1,49 @@
+/**
+ * Definition for singly-linked list.
+ * struct ListNode {
+ * int val;
+ * ListNode *next;
+ * ListNode(int x) : val(x), next(NULL) {}
+ * };
+ */
+class Solution {
+public:
+ ListNode* sortList(ListNode* head) {
+ if(head == NULL)
+ return NULL;
+ ListNode *right = head;
+ while(right->next)
+ right = right->next;
+ QuickSort(head, right);
+ return head;
+ }
+private:
+ void QuickSort(ListNode *left, ListNode *right)
+ {
+ if(left != right)
+ {
+ ListNode *partion = GetPartion(left, right);
+ QuickSort(left, partion);
+ if(partion->next)
+ QuickSort(partion->next, right);
+ }
+ }
+ ListNode *GetPartion(ListNode *left, ListNode *right)
+ {
+ int key = left->val;
+ ListNode *p = left;
+ ListNode *q = p->next;
+
+ while(q != right->next)
+ {
+ if(q->val < key)
+ {
+ p = p->next;
+ swap(p->val, q->val);
+ }
+ q = q->next;
+ }
+ swap(p->val, left->val);
+ return p;
+ }
+};
\ No newline at end of file
diff --git "a/\351\233\252\345\237\237\345\260\217\347\213\274/readme.md" "b/\351\233\252\345\237\237\345\260\217\347\213\274/readme.md"
new file mode 100644
index 0000000..52b677a
--- /dev/null
+++ "b/\351\233\252\345\237\237\345\260\217\347\213\274/readme.md"
@@ -0,0 +1,3 @@
+# 雪域小狼贡献内容
+
+- #1. 两数求和
diff --git "a/\351\251\254\346\231\266\346\225\217/matrixTranspose.txt" "b/\351\251\254\346\231\266\346\225\217/matrixTranspose.txt"
new file mode 100644
index 0000000..77afc85
--- /dev/null
+++ "b/\351\251\254\346\231\266\346\225\217/matrixTranspose.txt"
@@ -0,0 +1,17 @@
+class Solution:
+ def transpose(self, A):
+ """
+ :type A: List[List[int]]
+ :rtype: List[List[int]]
+ """
+ if(not A):
+ return A
+ A_vLen=len(A)
+ A_hLen=len(A[0])
+ B=[]
+ for i in range(A_hLen):
+ H=[]
+ for j in range(A_vLen):
+ H.append(A[j][i])
+ B.append(H)
+ return B
\ No newline at end of file