diff --git a/.gitignore b/.gitignore
new file mode 100644
index 000000000..df0b3ab78
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+.DS_Store
+*/.DS_Store
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 000000000..35eb1ddfb
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/018429.c b/018429.c
new file mode 100644
index 000000000..35d9bb74b
--- /dev/null
+++ b/018429.c
@@ -0,0 +1,18 @@
+int firstUniqChar(char* s) {
+ int ascii[256]={0};
+ int i=0,len;
+ while(s[i]!='\0')
+ {
+ i++;
+ }
+ len=i;
+ for(i=0;i> threeSum(int[] nums) {
+ final int length = nums.length;
+ List> result = new ArrayList<>();
+ HashMap hashMap = new HashMap();
+
+ if (length < 3) return result;
+
+ Arrays.sort(nums);
+
+ for (int i = 0; i < length - 2; i++) {
+ hashMap.clear();
+
+ if (i == 0 || nums[i] > nums[i - 1]) {
+ for (int j = i + 1; j < length; j++) {
+
+ if (hashMap.containsKey(nums[j])) {
+ ArrayList elem = new ArrayList(3);
+
+ elem.add(hashMap.get(nums[j])[0]);
+ elem.add(hashMap.get(nums[j])[1]);
+ elem.add(nums[j]);
+
+ result.add(elem);
+
+ while (j < (length - 1) && nums[j] == nums[j + 1]) j++;
+ } else {
+ int[] temp = new int[2];
+ temp[0] = nums[i];
+ temp[1] = nums[j];
+ hashMap.put(0 - (nums[i] + nums[j]), temp);
+ }
+ }
+ }
+ }
+ return result;
+ }
diff --git a/2018.11.19-leetcode15/Istoryforever.md b/2018.11.19-leetcode15/Istoryforever.md
new file mode 100644
index 000000000..a60b386e0
--- /dev/null
+++ b/2018.11.19-leetcode15/Istoryforever.md
@@ -0,0 +1,46 @@
+leetcode of 15
+```
+class Solution {
+public:
+ vector> threeSum(vector& nums) {
+
+ vector> res;
+ if(nums.size()==0) return res;
+ sort(nums.begin(),nums.end());
+ int i=0;
+ int p=0;
+ int q=0;
+ while(i0 &&nums[i-1]==nums[i]){
+ i++;
+ continue;
+ }
+ if(nums[i]>0) break;
+ int diff=0-nums[i];
+ p=i+1;
+ q=nums.size()-1;
+ while(pdiff && ptemp;
+ temp.push_back(nums[i]);
+ temp.push_back(nums[p]);
+ temp.push_back(nums[q]);
+ res.push_back(temp);
+ p++;
+ q--;
+ while(p> threeSum(vector& nums) {
+ vector> ans;
+ int n = nums.size();
+ sort(nums.begin(), nums.end()); //排序,从小到大
+ for(int i = 0 ; i < n - 2; i ++){
+ int j = i + 1;
+ int k = n - 1;
+ while(j < k){
+ if(nums[i] + nums[j] + nums[k] > 0){
+ k --;
+ }
+ else if(nums[i] + nums[j] + nums[k] < 0){
+ j ++;
+ }
+ else{
+ ans.push_back({nums[i], nums[j], nums[k]});
+ while(nums[j+1] == nums[j]) j++;
+ j ++;
+ }
+ }
+ while(nums[i+1] == nums[i]) i++;
+ }
+
+ return ans;
+ }
+};
+
+```
diff --git "a/2018.11.19-leetcode15/\346\243\225\346\246\210\346\240\221.md" "b/2018.11.19-leetcode15/\346\243\225\346\246\210\346\240\221.md"
new file mode 100644
index 000000000..04d48cf9c
--- /dev/null
+++ "b/2018.11.19-leetcode15/\346\243\225\346\246\210\346\240\221.md"
@@ -0,0 +1,30 @@
+```
+class Solution {
+ public List> threeSum(int[] nums) {
+ List> res = new ArrayList<>();
+ Arrays.sort(nums);
+ for(int i=0;i0&&nums[i]!=nums[i-1])){
+ while(lowhayStackLength) return -1; if (needleLength == 0) return 0;
+ for (int i = 0; i haystack.length()) {
+ return -1;
+ }
+ int hStart,nStart;
+ for (int i = 0; i < haystack.length(); i++) {
+ hStart=i;
+ nStart=0;
+ while (nStart < needle.length() && hStart < haystack.length()) {
+ if (haystack.charAt(hStart) == needle.charAt(nStart)) {
+ hStart++;
+ nStart++;
+ } else {
+ break;
+ }
+ if (nStart == needle.length()) {
+ return i;
+ }
+
+ }
+ }
+ return -1;
+ }
diff --git a/2018.11.24-leetcode28/syuan.md b/2018.11.24-leetcode28/syuan.md
new file mode 100644
index 000000000..9caed293c
--- /dev/null
+++ b/2018.11.24-leetcode28/syuan.md
@@ -0,0 +1,30 @@
+```
+class Solution {
+ public int strStr(String haystack, String needle) {
+ if(needle.length() == 0)
+ return 0;
+ char [] charArrayhaystack = haystack.toCharArray();
+ char [] charArrayneedle = needle.toCharArray();
+ for(int i =0;ilengthHay) {
+ return -1;
+ }else{
+ while(ilen(haystack):
+ return(-1)
+ match=0
+ for a in range(len(haystack)-lenNeedle+1):
+ m = a
+ match = 0
+ for i in range(lenNeedle):
+ if haystack[m]==needle[i]:
+ match+=1
+ m+=1
+ if match == lenNeedle:
+ break
+ if match == lenNeedle:
+ break
+ if match == lenNeedle:
+ return(a)
+ else:
+ return(-1)
+
diff --git a/2018.11.25-leetcode80/Istoryforever.md b/2018.11.25-leetcode80/Istoryforever.md
new file mode 100644
index 000000000..def5670f2
--- /dev/null
+++ b/2018.11.25-leetcode80/Istoryforever.md
@@ -0,0 +1,27 @@
+leetcode number 80
+```
+class Solution {
+public:
+ void swap(int &a,int &b){
+ int c = a;
+ a = b;
+ b = a;
+
+ }
+ int removeDuplicates(vector& nums) {
+ int j = -1;
+ int count = 0;
+ for(int i = 0;i < nums.size();i++){
+ if(i != 0 && nums[i] == nums[i-1]) {
+ if(count >= 1) continue;
+ ++count;
+ }
+ else
+ count = 0;
+ nums[++j]=nums[i];
+ }
+ return j+1;
+
+ }
+};
+```
diff --git a/2018.11.25-leetcode80/Tony the Cyclist.md b/2018.11.25-leetcode80/Tony the Cyclist.md
new file mode 100644
index 000000000..69a4759ac
--- /dev/null
+++ b/2018.11.25-leetcode80/Tony the Cyclist.md
@@ -0,0 +1,16 @@
+```
+
+class Solution {
+ public int removeDuplicates(int[] nums) {
+ if (nums.length < 3){
+ return nums.length;
+ }
+ int pos = 2;
+ for(int i = 2; i < nums.length; i++){
+ if(nums[i]!=nums[pos-2])
+ nums[pos++]=nums[i];
+ }
+ return pos;
+ }
+}
+```
diff --git a/2018.11.25-leetcode80/syuan.md b/2018.11.25-leetcode80/syuan.md
new file mode 100644
index 000000000..69087f2b6
--- /dev/null
+++ b/2018.11.25-leetcode80/syuan.md
@@ -0,0 +1,83 @@
+##### 题目
+
+```
+给定一个排序数组,你需要在原地删除重复出现的元素,使得每个元素最多出现两次,返回移除后数组的新长度。
+
+不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成。
+
+示例 1:
+
+给定 nums = [1,1,1,2,2,3],
+
+函数应返回新长度 length = 5, 并且原数组的前五个元素被修改为 1, 1, 2, 2, 3 。
+
+你不需要考虑数组中超出新长度后面的元素。
+
+示例 2:
+
+给定 nums = [0,0,1,1,1,1,2,3,3],
+
+函数应返回新长度 length = 7, 并且原数组的前五个元素被修改为 0, 0, 1, 1, 2, 3, 3 。
+
+你不需要考虑数组中超出新长度后面的元素。
+
+说明:
+
+为什么返回数值是整数,但输出的答案是数组呢?
+
+请注意,输入数组是以“引用”方式传递的,这意味着在函数里修改输入数组对于调用者是可见的。
+
+你可以想象内部操作如下:
+
+// nums 是以“引用”方式传递的。也就是说,不对实参做任何拷贝
+int len = removeDuplicates(nums);
+
+// 在函数里修改输入数组对于调用者是可见的。
+// 根据你的函数返回的长度, 它会打印出数组中该长度范围内的所有元素。
+for (int i = 0; i < len; i++) {
+ print(nums[i]);
+}
+```
+##### 代码
+
+```
+class Solution {
+ public int removeDuplicates(int[] nums) {
+ int count=0;
+ if (nums.length==1) {
+ return 1;
+ }
+ if (nums.length==0) {
+ return 0;
+ }
+ if (nums.length==2) {
+ return 2;
+ }
+ int i=0;
+ int j=i;
+ int tempCount=0;
+ while(i=2) {
+ count+=2;
+ nums[i+1]=nums[i];
+ i=i+2;
+ }else{
+ count++;
+ i++;
+ }
+ if (j>=nums.length) {
+ break;
+ }
+ nums[i]=nums[j];
+ tempCount=0;
+ }
+ }
+ return count;
+ }
+}
+```
diff --git "a/2018.11.25-leetcode80/\345\244\247\351\255\224\347\216\213\347\210\261\347\251\277\345\255\226\347\203\237\347\255\222.md" "b/2018.11.25-leetcode80/\345\244\247\351\255\224\347\216\213\347\210\261\347\251\277\345\255\226\347\203\237\347\255\222.md"
new file mode 100644
index 000000000..3428058c9
--- /dev/null
+++ "b/2018.11.25-leetcode80/\345\244\247\351\255\224\347\216\213\347\210\261\347\251\277\345\255\226\347\203\237\347\255\222.md"
@@ -0,0 +1,45 @@
+```
+class Solution {
+ public int removeDuplicates(int[] nums) {
+ int count=0;
+ if(nums.length==0){
+ return 0;
+ }
+ if(nums.length==0){
+ return 1;
+ }
+ int i=0;
+ int j=i;//用来遍历数组
+ int tempCount=0;
+ while(i=2){//统计每个位置数字出现的次数。
+ count+=2;
+ nums[i+1]=nums[i];//保存i的值,前后两个是相同的值,eg 1,1,2,。。
+ i=i+2;//i来到下一个的下一个位置。
+ }else{//相同的只有两个
+ count++;
+ i++;
+ }
+ if(j>=nums.length){
+ break;
+ }
+ nums[i]=nums[j];//
+ tempCount=0;//重新统计
+ }
+
+
+
+ }
+
+
+
+
+
+ return count;
+ }
+}
+```
diff --git a/2018.11.26-leetcode11/FFFro.md b/2018.11.26-leetcode11/FFFro.md
new file mode 100644
index 000000000..9d5886e51
--- /dev/null
+++ b/2018.11.26-leetcode11/FFFro.md
@@ -0,0 +1,25 @@
+class Solution {
+ public int maxArea(int[] height) {
+ int start = 0;
+ int end = height.length-1;
+ int tempHeight = 0;
+ int temp = 0;
+ int result = 0;
+ while (start < end){
+ int ju = end-start;
+ if (height[start] > height[end]){
+ tempHeight = height[end];
+ temp = ju*tempHeight;
+ end--;
+ }else{
+ tempHeight = height[start];
+ temp = ju*tempHeight;
+ start++;
+ }
+ if (result < temp){
+ result = temp;
+ }
+ }
+ return result;
+ }
+}
diff --git a/2018.11.26-leetcode11/Istoryforever.md b/2018.11.26-leetcode11/Istoryforever.md
index 184923184..ef7c06b15 100644
--- a/2018.11.26-leetcode11/Istoryforever.md
+++ b/2018.11.26-leetcode11/Istoryforever.md
@@ -1,3 +1,4 @@
+leetcode11
```
const int x=[]{
std::ios::sync_with_stdio(false);
diff --git a/2018.11.26-leetcode11/Ostrichcrab.md b/2018.11.26-leetcode11/Ostrichcrab.md
new file mode 100644
index 000000000..7fe18d55d
--- /dev/null
+++ b/2018.11.26-leetcode11/Ostrichcrab.md
@@ -0,0 +1,22 @@
+```
+class Solution {
+public:
+ int max(int a, int b){return a>b?a:b;}
+ int min(int a, int b){return a& height) {
+ int ans = 0;
+ int l = 0, r = height.size() - 1;
+ ans = max(ans,min(height[l],height[r])*(r-l));
+ while(lheight[r]){
+ r--;
+ ans = max(ans,min(height[l],height[r])*(r-l));
+ }else{
+ l++;
+ ans = max(ans,min(height[l],height[r])*(r-l));
+ }
+ }
+ return ans;
+ }
+};
+```
diff --git a/2018.11.26-leetcode11/Tony the Cyclist.md b/2018.11.26-leetcode11/Tony the Cyclist.md
new file mode 100644
index 000000000..bbf9e92b3
--- /dev/null
+++ b/2018.11.26-leetcode11/Tony the Cyclist.md
@@ -0,0 +1,45 @@
+## Java
+
+```
+class Solution {
+ public int maxArea(int[] height) {
+ int l = 0, r = height.length - 1;
+ int s = (r-l) * (height[l] > height[r]? height[r]: height[l]);
+ while (l < r){
+ if (height[l] < height[r]){
+ l++;
+ }
+ else {
+ r--;
+ }
+ s = Math.max(s, (r-l) * (height[l] > height[r]? height[r]: height[l]));
+ }
+ return s;
+
+ }
+}
+```
+
+
+
+## Python
+```
+class Solution(object):
+ def maxArea(self, height):
+ """
+ :type height: List[int]
+ :rtype:
+ """
+ l = 0
+ r = len(height) - 1
+ h = (height[r] if (height[l] > height[r]) else height[l])
+ s = h * (r - l)
+ while l < r:
+ if height[l] > height[r]:
+ r -= 1
+ else:
+ l += 1
+ h = (height[r] if (height[l] > height[r]) else height[l])
+ s = max(s, (r-l)*h)
+ return s
+```
diff --git a/2018.11.26-leetcode11/kiritocly.md b/2018.11.26-leetcode11/kiritocly.md
new file mode 100644
index 000000000..3ee9a6715
--- /dev/null
+++ b/2018.11.26-leetcode11/kiritocly.md
@@ -0,0 +1,29 @@
+
+
+ private static int solution(int[] array) {
+ //从左右两边同时遍历,每次都舍弃最短边
+ int left = 0;
+ int right = array.length - 1;
+ int resultTemp = 0;
+ int result = 0;
+ while (left < right) {
+ if (array[left] <= array[right]) {
+ //左边柱子低于右边
+ //计算临时盛水容量
+ resultTemp = array[left] * (right - left);
+ //矮柱子向中间移动
+ left++;
+ } else if (array[left] >= array[right]) {
+ //左边柱子高于右边
+ //计算临时盛水容量
+ resultTemp = array[right] * (right - left);
+ //矮柱子向中间移动
+ right--;
+ }
+ //判断临时盛水容量
+ if (resultTemp > result) {
+ result = resultTemp;
+ }
+ }
+ return result;
+ }
diff --git a/2018.11.26-leetcode11/str818.md b/2018.11.26-leetcode11/str818.md
new file mode 100644
index 000000000..d80ab9a94
--- /dev/null
+++ b/2018.11.26-leetcode11/str818.md
@@ -0,0 +1,24 @@
+# 乘最多水的容器
+
+[题目描述](https://leetcode-cn.com/problems/container-with-most-water/description/):给定 n 个非负数 a1,a2,...,an,每个数代表坐标中的一个点 (i,ai)。在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i,ai) 和 (i,0)。找出其中的两条线,使得它们与 x 轴共同构成的容器可以容纳最多的水。
+
+**示例:**
+```
+输入: [1,8,6,2,5,4,8,3,7]
+输出: 49
+```
+
+**解题思路:** 两线段之间形成的区域总是会受到其中较短那条长度的限制,同时,两线段距离越远,得到的面积就越大。使用两个指针,一个放在开始,一个放在末尾,更新存储的最大面积,将指向较短线段的指针向较长线段那端移动一步。
+
+```java
+public int maxArea(int[] height) {
+ int start = 0,end = height.length - 1;
+ int maxArea = 0;
+ while(end > start){
+ maxArea = Math.max(maxArea, Math.min(height[start], height[end]) * (end - start));
+ if(height[start] > height[end]) end--;
+ else start++;
+ }
+ return maxArea;
+}
+```
diff --git a/2018.11.26-leetcode11/syuan.md b/2018.11.26-leetcode11/syuan.md
new file mode 100644
index 000000000..9534da05a
--- /dev/null
+++ b/2018.11.26-leetcode11/syuan.md
@@ -0,0 +1,39 @@
+##### 题目
+
+```
+给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) 。在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0)。找出其中的两条线,使得它们与 x 轴共同构成的容器可以容纳最多的水。
+
+说明:你不能倾斜容器,且 n 的值至少为 2。
+```
+
+```
+图中垂直线代表输入数组 [1,8,6,2,5,4,8,3,7]。在此情况下,容器能够容纳水(表示为蓝色部分)的最大值为 49。
+示例:
+
+输入: [1,8,6,2,5,4,8,3,7]
+输出: 49
+```
+##### 思路
+双指针
+
+##### 代码
+
+```
+class Solution {
+ public int maxArea(int[] height){
+ int maxarea=0;
+ int i=0;
+ int j=height.length-1;
+
+ while(i
+#include
+using namespace std;
+
+//mysol:
+ int removeDuplicates(vector& nums) {
+ for (int i = 1; i < nums.size(); i++) {
+ if (nums[i] == nums[i-1])
+ nums.erase(nums.begin() + i);
+ }
+ return nums.size();
+ }
+//better sol:
+ int removeDuplicates(vector& nums) {
+ int i = 0;
+ for (int j = 1; j < nums.size(); j++) {
+ if (nums[i] != nums[j]) {
+ i++;
+ nums[i] = nums[j];
+ }
+ }
+ return i + 1;
+ }
+```
diff --git "a/2018.11.26-leetcode11/\343\200\202\343\200\202\343\200\202.md" "b/2018.11.26-leetcode11/\343\200\202\343\200\202\343\200\202.md"
new file mode 100644
index 000000000..26ea7d0fd
--- /dev/null
+++ "b/2018.11.26-leetcode11/\343\200\202\343\200\202\343\200\202.md"
@@ -0,0 +1,12 @@
+ public int maxArea(int[] height) {
+ int left=0,right=height.length-1,area = 0;
+ while (left < right){
+ area = Math.max(area,(right-left)*Math.min(height[left],height[right]));
+ if (height[left] < height[right]){
+ left++;
+ }else {
+ right--;
+ }
+ }
+ return area;
+ }
diff --git "a/2018.11.26-leetcode11/\345\244\247\351\255\224\347\216\213\347\210\261\347\251\277\345\255\226\347\203\237\347\255\222.md" "b/2018.11.26-leetcode11/\345\244\247\351\255\224\347\216\213\347\210\261\347\251\277\345\255\226\347\203\237\347\255\222.md"
new file mode 100644
index 000000000..6bb4f2be6
--- /dev/null
+++ "b/2018.11.26-leetcode11/\345\244\247\351\255\224\347\216\213\347\210\261\347\251\277\345\255\226\347\203\237\347\255\222.md"
@@ -0,0 +1,27 @@
+```
+class Solution {
+ public int maxArea(int[] height) {
+ int left=0;//从左边遍历
+ int right=height.length-1;//从右边遍历
+ int tempCha=0;
+ int sum=0;
+ int tempsum=0;
+ while(leftheight[left]){
+ tempsum=height[left]*tempCha; //短(短板)的边作为高,求出此时的面积
+ left++;
+ }else{
+ tempsum=height[right]*tempCha;
+ right--;
+ }
+ if(tempsum>sum){
+ sum=tempsum;
+ }
+
+
+ }
+ return sum;
+ }
+}
+```
diff --git "a/2018.11.26-leetcode11/\345\256\266.md" "b/2018.11.26-leetcode11/\345\256\266.md"
new file mode 100644
index 000000000..fde8ca303
--- /dev/null
+++ "b/2018.11.26-leetcode11/\345\256\266.md"
@@ -0,0 +1,16 @@
+```
+func maxArea(height []int) int {
+ l := len(height)-1
+ max,now := 0,0
+ for a:=0;a= height[l] {
+ now = height[l] * (l-a)
+ l--
+ }else {
+ now = height[a] * (l-a)
+ a++
+ }
+ if now > max {max = now}
+ }
+ return max
+}
diff --git "a/2018.11.26-leetcode11/\346\232\256\346\210\220\351\233\252.md" "b/2018.11.26-leetcode11/\346\232\256\346\210\220\351\233\252.md"
new file mode 100644
index 000000000..e8291a22e
--- /dev/null
+++ "b/2018.11.26-leetcode11/\346\232\256\346\210\220\351\233\252.md"
@@ -0,0 +1,22 @@
+class Solution {
+ public int maxArea(int[] height) {
+ if( height.length < 2 ){
+ return 0;
+ }
+ //双指针,复杂度O(n),5ms 91%
+ int max=0;
+ int i=0;
+ int j= height.length-1;
+ while(i < j){
+ int areaTmp= (j-i) * Math.min(height[i] , height[j]);
+ Boolean flag = height[i] > height[j] ? true : false;
+ if(max < areaTmp){
+ max = areaTmp;
+ }
+ if(flag == true){
+ j--;
+ }else{
+ i++;
+ }
+ }
+}
diff --git "a/2018.11.26-leetcode11/\347\247\215\350\212\261\345\256\266\347\232\204\351\204\202\345\205\224.md" "b/2018.11.26-leetcode11/\347\247\215\350\212\261\345\256\266\347\232\204\351\204\202\345\205\224.md"
new file mode 100644
index 000000000..977ebd09e
--- /dev/null
+++ "b/2018.11.26-leetcode11/\347\247\215\350\212\261\345\256\266\347\232\204\351\204\202\345\205\224.md"
@@ -0,0 +1,26 @@
+```
+public class Main {
+
+ public static void main(String[] args) {
+ int[] height = {2,3,10,5,7,8,9};
+ System.out.println(new Solution().maxArea(height));
+ }
+}
+
+public class Solution{
+ public int maxArea(int[] height){
+ int low = 0;
+ int high = height.length-1;
+ int max_area=0;
+ while (low < high){
+ int min_height = height[low]array[right]){
+ temparea=array[right]*len;
+ right--;
+ }else {
+ temparea=array[left]*len;
+ left++;
+ }
+ if(temparea>result){
+ result=temparea;
+ }
+ }
+ return result;
+ }
+
+ public static void main(String[] args) {
+ Solution1 s1 = new Solution1();
+ int[] a = {1,8,6,2,5,4,8,3,7};
+ int b = s1.MaxArea(a);
+ System.out.println("盛最多水的容器面积是:"+b);
+ }
+}
diff --git "a/2018.11.26-leetcode11/\351\273\216\346\230\216\345\210\235\351\206\222.md" "b/2018.11.26-leetcode11/\351\273\216\346\230\216\345\210\235\351\206\222.md"
new file mode 100644
index 000000000..34f38cb36
--- /dev/null
+++ "b/2018.11.26-leetcode11/\351\273\216\346\230\216\345\210\235\351\206\222.md"
@@ -0,0 +1,23 @@
+```
+class Solution {
+ public int maxArea(int[] height) {
+ int i=0,j=height.length-1;
+ int V=0,V1;
+ while(i<=j) {
+ if(height[i]<=height[j]) {
+ V1 = (j-i)*height[i];
+ i++;
+ }
+ else {
+ V1 = (j-i)*height[j];
+ j--;
+ }
+ if(V1>=V) {
+ V = V1;
+ }
+
+ }
+ return V;
+ }
+}
+```
diff --git a/2018.11.27-leetcode125/Avalon.md b/2018.11.27-leetcode125/Avalon.md
new file mode 100644
index 000000000..94e7b21a9
--- /dev/null
+++ b/2018.11.27-leetcode125/Avalon.md
@@ -0,0 +1,30 @@
+class Solution {
+ public boolean isPalindrome(String s) {
+ if (s.length() == 0)//空字符串为回文串
+ return true;
+ char[] chars = s.toCharArray();
+ int len = chars.length;
+ List list1 = new ArrayList<>();
+ for (int i= 0; i='a'&&chars[i]<='z'){//小写比大写更大 32
+ list1.add(chars[i]);
+ }else if (chars[i]>='A'&&chars[i]<='Z'){
+ list1.add((char)((int)chars[i]+32));//一句话转小写
+ }else if (chars[i]>='0'&&chars[i]<='9'){
+ list1.add(chars[i]);
+ }
+ }
+ int listlen = list1.size();
+ if (listlen == 0)
+ return true;
+ boolean flag = true;
+ for (int i = 0; i < listlen /2 +1;i++){
+ if (list1.get(i) != list1.get(listlen-1-i)){
+ return false;
+ }
+
+ }
+ return flag;
+ }
+}
diff --git a/2018.11.27-leetcode125/FFFro.md b/2018.11.27-leetcode125/FFFro.md
new file mode 100644
index 000000000..e65e559e5
--- /dev/null
+++ b/2018.11.27-leetcode125/FFFro.md
@@ -0,0 +1,25 @@
+class Solution {
+ public boolean isPalindrome(String s) {
+ s = s.toLowerCase();
+ char[] charArray = s.toCharArray();
+ String res = "";
+ for (int i = 0; i < charArray.length; i++) {
+ if ((int)charArray[i]>=48&&(int)charArray[i]<=57 || (int)charArray[i]>=97&&(int)charArray[i]<=122)
+ res+=charArray[i];
+ }
+ char[] array = res.toCharArray();
+ int start = 0;
+ int end = array.length-1;
+ while (end>start){
+
+ if(array[start] == array[end]){
+ start++;
+ end--;
+ }else {
+ return false;
+ }
+ }
+ return true;
+
+ }
+}
diff --git a/2018.11.27-leetcode125/Ostrichcrab.md b/2018.11.27-leetcode125/Ostrichcrab.md
new file mode 100644
index 000000000..6d9d19bbd
--- /dev/null
+++ b/2018.11.27-leetcode125/Ostrichcrab.md
@@ -0,0 +1,25 @@
+```
+class Solution {
+public:
+ bool isPalindrome(string s) {
+ if(s.length()==0) return true;
+ string t = "";
+ for(int i = 0; i < s.length(); i++){
+
+ if(s[i]>='a'&&s[i]<='z'){
+ t += s[i];
+ }else if(s[i]>='A'&&s[i]<='Z'){
+ t += 'a' + s[i] - 'A';
+ }else if(s[i]>='0'&&s[i]<='9'){
+ t += s[i];
+ }
+ }
+ string tt = t;
+ reverse(tt.begin(),tt.end());
+ for(int i = 0; i < t.length(); i++){
+ if(t[i]!=tt[i]) return false;
+ }
+ return true;
+ }
+};
+```
diff --git a/2018.11.27-leetcode125/TheRocket.md b/2018.11.27-leetcode125/TheRocket.md
new file mode 100644
index 000000000..af44b79cb
--- /dev/null
+++ b/2018.11.27-leetcode125/TheRocket.md
@@ -0,0 +1,21 @@
+```java
+class Solution {
+
+ public boolean isPalindrome(String s) {
+ int i = 0;
+ int j = s.length() - 1;
+ while (i < j) {
+ while (i < j && !Character.isLetterOrDigit(s.charAt(i))) {
+ ++i;
+ }
+ while (i < j && !Character.isLetterOrDigit(s.charAt(j))) {
+ --j;
+ }
+ if (Character.toLowerCase(s.charAt(i++)) != Character.toLowerCase(s.charAt(j--))) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
+```
diff --git a/2018.11.27-leetcode125/Tony the Cyclist.md b/2018.11.27-leetcode125/Tony the Cyclist.md
new file mode 100644
index 000000000..394291e2e
--- /dev/null
+++ b/2018.11.27-leetcode125/Tony the Cyclist.md
@@ -0,0 +1,9 @@
+```
+class Solution {
+ public boolean isPalindrome(String s) {
+ s = s.replaceAll("[ `~!@#$%^&*()+=|{}':;',\\\\[\\\\].<>/?~!@#¥%……&;*()\"——+|{}【】‘;:”“’。,、?|-]", "").toLowerCase();
+ StringBuffer sb = new StringBuffer(s);
+ return sb.toString().equals(sb.reverse().toString());
+ }
+}
+```
diff --git a/2018.11.27-leetcode125/WhiteNight.md b/2018.11.27-leetcode125/WhiteNight.md
new file mode 100644
index 000000000..f605ea232
--- /dev/null
+++ b/2018.11.27-leetcode125/WhiteNight.md
@@ -0,0 +1,50 @@
+java
+
+/**
+ * 验证回文串
+ *
+ */
+public class A7 {
+ public boolean isPalindrome(String s) {
+ if (s.isEmpty())
+ return true;
+
+ int begin = 0;
+ int end = s.length() - 1;
+
+ char beginChar, endChar;
+
+ while (begin <= end){
+ beginChar = s.charAt(begin);
+ endChar = s.charAt(end);
+ if (!Character.isLetterOrDigit(beginChar)){
+ begin++;
+ continue;
+ }
+ else if (!Character.isLetterOrDigit(endChar)){
+ end--;
+ continue;
+ }
+ else {
+ if (Character.toLowerCase(beginChar) != Character.toLowerCase(endChar))
+ return false;
+ else{
+ begin++;
+ end--;
+ }
+ }
+ }
+
+ return true;
+ }
+
+ public static void main(String[] args) {
+ A7 a = new A7();
+ String s1 = "A man, a plan, a canal: Panama";
+ String s2 = "race a car";
+ boolean res1 = a.isPalindrome(s1);
+ boolean res2 = a.isPalindrome(s2);
+ System.out.println(res1);
+ System.out.println(res2);
+ }
+}
diff --git a/2018.11.27-leetcode125/caroline.md b/2018.11.27-leetcode125/caroline.md
new file mode 100644
index 000000000..d09724dce
--- /dev/null
+++ b/2018.11.27-leetcode125/caroline.md
@@ -0,0 +1,25 @@
+题目详述
+大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项(从0开始,第0项为0)。
+n<=39
+(这里的字体怎么调呀,要下什么插件吗,另外,斐波那契数列的第0项怎么是0,百科里面是1,这样婶儿的,斐波那契数列指的是这样一个
+数列 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368........)
+
+public class Solution{
+ public int Fibonacci(int n){
+ int a = 0;
+ int b =1;
+ if(n == 0)
+ return 1;
+ if(n == 1)
+ return 1;
+ int i=2;
+ int sum=0;
+ while(i<=n){
+ sum = a+b;
+ a=b;
+ b=sum;
+ i++;
+ }
+ return sum;
+ }
+}
diff --git a/2018.11.27-leetcode125/cuiHlu.md b/2018.11.27-leetcode125/cuiHlu.md
new file mode 100644
index 000000000..2a1b1bc35
--- /dev/null
+++ b/2018.11.27-leetcode125/cuiHlu.md
@@ -0,0 +1,21 @@
+ //isalnum()判断是否为字母或者是数字
+ bool isPalindrome(string s) {
+ int length = s.size();
+ int start = 0;
+ int end = start + length - 1;
+ while (start <= end)
+ {
+ if (!isalnum(s[start]))
+ ++start;
+ else if (!isalnum(s[end]))
+ --end;
+ else
+ {
+ if (tolower(s[start]) != tolower(s[end]))
+ return false;
+ ++start;
+ --end;
+ }
+ }
+ return true;
+ }
diff --git a/2018.11.27-leetcode125/halfofwater.md b/2018.11.27-leetcode125/halfofwater.md
new file mode 100644
index 000000000..dc07943e2
--- /dev/null
+++ b/2018.11.27-leetcode125/halfofwater.md
@@ -0,0 +1,38 @@
+## leetcode 125
+
+```
+class Solution {
+public:
+ bool isPalindrome(string s) {
+ string::iterator it;
+ for (it = s.begin(); it != s.end(); it++)
+ {
+ //bool b1 = !(65 <= *it && *it <= 90);
+ //bool b2 = !(97 <= *it && *it <= 122);
+ //bool b3 = !(48 <= *it && *it <= 57);
+
+ if (!(65 <= *it && *it<= 90) && !(97 <= *it && *it <= 122) && !(48 <= *it && *it <= 57))
+ {
+ s.erase(it);
+ it--;
+ }
+ if (65 <= *it && *it <= 90)
+ {
+ *it += 32;
+ }
+ }
+ int len = s.size();
+ int i = 0, j = len - 1;
+ while (i < j)
+ {
+ if (s[i] != s[j])
+ {
+ return false;
+ }
+ i++;
+ j--;
+ }
+ return true;
+ }
+};
+```
diff --git a/2018.11.27-leetcode125/kiritocly.md b/2018.11.27-leetcode125/kiritocly.md
new file mode 100644
index 000000000..ac1693ab8
--- /dev/null
+++ b/2018.11.27-leetcode125/kiritocly.md
@@ -0,0 +1,34 @@
+ private static boolean solution(String input) {
+ if (input == null || "".equals(input)) {
+ return true;
+ }
+ char[] inputCharArray = input.toCharArray();
+ //定义两个指针,一个头指针一个尾指针
+ int head = 0;
+ int tail = inputCharArray.length - 1;
+ //判断字母和数字字符的正则表达式
+ String regex = "^[0-9a-zA-Z]$";
+ while (head <= tail) {
+ String headStr = inputCharArray[head] + "";
+ String tailStr = inputCharArray[tail] + "";
+ if (headStr.matches(regex) && tailStr.matches(regex)) {
+ if (headStr.toLowerCase().equals(tailStr.toLowerCase())) {
+ //比较下一个字符
+ head++;
+ tail--;
+ } else {
+ //如果未匹配则直接返回
+ return false;
+ }
+ } else {
+ //如果比较的字符不为字母或数字则不比较
+ if (!headStr.matches(regex)) {
+ head++;
+ }
+ if (!tailStr.matches(regex)) {
+ tail--;
+ }
+ }
+ }
+ return true;
+ }
diff --git a/2018.11.27-leetcode125/sourcema.md b/2018.11.27-leetcode125/sourcema.md
new file mode 100644
index 000000000..9548c477d
--- /dev/null
+++ b/2018.11.27-leetcode125/sourcema.md
@@ -0,0 +1,20 @@
+# leetcode 125
+ public static boolean isPalindrome(String s) {
+ if (s == null || s.length() == 0) {
+ return true;
+ }
+ String str = s.toLowerCase();
+ int left=0,right=s.length()-1;
+ while (left < right) {
+ while (left < right && !Character.isDigit(str.charAt(left)) && !Character.isAlphabetic(str.charAt(left))) {
+ left++;
+ }
+ while (left < right && !Character.isDigit(str.charAt(right)) && !Character.isAlphabetic(str.charAt(right))) {
+ right--;
+ }
+ if (str.charAt(left++) != str.charAt(right--)) {
+ return false;
+ }
+ }
+ return true;
+ }
diff --git a/2018.11.27-leetcode125/str818.md b/2018.11.27-leetcode125/str818.md
new file mode 100644
index 000000000..4ece6d309
--- /dev/null
+++ b/2018.11.27-leetcode125/str818.md
@@ -0,0 +1,23 @@
+```java
+public boolean isPalindrome(String s) {
+ if (s.isEmpty()) return true;
+ int head = 0, tail = s.length() - 1;
+ char cHead, cTail;
+ while(head <= tail) {
+ cHead = s.charAt(head);
+ cTail = s.charAt(tail);
+ if (!Character.isLetterOrDigit(cHead)) {
+ head++;
+ } else if(!Character.isLetterOrDigit(cTail)) {
+ tail--;
+ } else {
+ if (Character.toLowerCase(cHead) != Character.toLowerCase(cTail)) {
+ return false;
+ }
+ head++;
+ tail--;
+ }
+ }
+ return true;
+}
+```
diff --git a/2018.11.27-leetcode125/tongLuoWan.md b/2018.11.27-leetcode125/tongLuoWan.md
new file mode 100644
index 000000000..0f3eb1544
--- /dev/null
+++ b/2018.11.27-leetcode125/tongLuoWan.md
@@ -0,0 +1,24 @@
+>leetcode 125. Valid Palindrome
+
+```
+class Solution {
+
+ public boolean isPalindrome(String s) {
+ if(s.length()==0)
+ return true;
+ s=s.toLowerCase();
+ int i = 0, j = s.length()- 1;
+ while (i2018.11.27号打卡
diff --git a/2018.11.27-leetcode125/zjukk.md b/2018.11.27-leetcode125/zjukk.md
new file mode 100644
index 000000000..23568af19
--- /dev/null
+++ b/2018.11.27-leetcode125/zjukk.md
@@ -0,0 +1,37 @@
+```
+#include
+#include
+
+using namespace std;
+
+class Solution {
+public:
+ bool isPalindrome(string s) {
+ int l = 0, r = s.size() - 1;
+ bool flag = false;
+ while (l <= r) {
+ if (!isAlphaNum(s[l])) {
+ ++l; continue;
+ }
+ if (!isAlphaNum(s[r])) {
+ --r; continue;
+ }
+ if ((s[r] + 32 - 'a') % 32 != (s[l] + 32 - 'a') % 32) {flag = true; break;}
+ ++l; --r;
+ }
+ return !flag;
+ }
+ bool isAlphaNum(char c) {
+ if (c >= 'a' && c <= 'z') return true;
+ if (c >= 'A' && c <= 'Z') return true;
+ if (c >= '0' && c <= '9') return true;
+ return false;
+ }
+};
+
+int main() {
+ Solution s;
+ cout << s.isPalindrome("race a car");
+ //A man, a plan, a canal: Panama
+}
+```
diff --git "a/2018.11.27-leetcode125/\343\200\202\343\200\202\343\200\202.md" "b/2018.11.27-leetcode125/\343\200\202\343\200\202\343\200\202.md"
new file mode 100644
index 000000000..d31191b03
--- /dev/null
+++ "b/2018.11.27-leetcode125/\343\200\202\343\200\202\343\200\202.md"
@@ -0,0 +1,30 @@
+```
+public boolean isPalindrome(String s){
+ if (s.length() >= 2){
+ int left = 0,right = s.length()-1;
+ char leftChar,rightChar;
+ while (left <= right){
+ leftChar = s.charAt(left);rightChar = s.charAt(right);
+ if (leftChar>='A'&&leftChar<='Z'){//转换大写字母为小写
+ leftChar+=32;
+ }else if (rightChar>='A'&&rightChar<='Z'){
+ rightChar+=32;
+ }
+ if (leftChar == rightChar){
+ left++;right--;
+ continue;
+ }
+ //跳过非字母非数字的字符
+ if (!((leftChar>='0'&& leftChar<='9') || (leftChar>='a'&&leftChar<='z') || (leftChar>='A'&&leftChar<='Z'))){
+ left++;
+ continue;
+ }else if (!((rightChar>='0'&& rightChar<='9') || (rightChar>='a'&&rightChar<='z') || (rightChar>='A'&&rightChar<='Z'))){
+ right--;
+ continue;
+ }
+ if (leftChar != rightChar)return false;
+ }
+ }
+ return true;
+ }
+ ```
diff --git "a/2018.11.27-leetcode125/\345\210\230\346\266\246\346\263\275.md" "b/2018.11.27-leetcode125/\345\210\230\346\266\246\346\263\275.md"
new file mode 100644
index 000000000..5e95edf1b
--- /dev/null
+++ "b/2018.11.27-leetcode125/\345\210\230\346\266\246\346\263\275.md"
@@ -0,0 +1,49 @@
+## 判断字符串是否为回文字符串
+
+> lanague: java
+
+> vsersion: jdk1.7
+
+```
+public static boolean isPalindrome(String s) {
+ s = s.replaceAll("[^0-9a-zA-Z\u4e00-\u9fa5]+","").toLowerCase();
+ System.out.println(s);
+ char[] chars = s.toCharArray();
+ if (chars.length==0){
+ return false;
+ }
+ if (chars.length==1){
+ return true;
+ }
+ for (int i=0;i 输出结果
+
+>raceacar
+
+>false
+
+>amanaplanacanalpanama
+
+>true
+
+
+
+
+
+
+
+
diff --git "a/2018.11.27-leetcode125/\345\217\245\345\255\220.java" "b/2018.11.27-leetcode125/\345\217\245\345\255\220.java"
new file mode 100644
index 000000000..2da595f71
--- /dev/null
+++ "b/2018.11.27-leetcode125/\345\217\245\345\255\220.java"
@@ -0,0 +1,36 @@
+package Leetcode;
+
+public class for125 {
+ public boolean isPalindrome(String s) {
+ if(s.length()==0)
+ return true;
+ //s=s.toLowerCase();
+ char[] cs =s.toCharArray();
+ int i = 0, j = cs.length - 1;
+ while(i64&&cs[j]>64&&Math.abs(cs[i]-cs[j])==32)){
+ i++;
+ j--;
+ }
+ else
+ return false;
+
+ }
+ return true;
+ }
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+ String reg="[^a-zA-Z0-9]";
+ String s = "A man, a plan, a canal: Panama";
+ char x ='A';
+ x=Character.toLowerCase(x);
+ s=s.toLowerCase();
+ System.out.println(x);
+ }
+
+}
diff --git "a/2018.11.27-leetcode125/\345\244\247\351\255\224\347\216\213\347\210\261\347\251\277\345\255\226\347\203\237\347\255\222.md" "b/2018.11.27-leetcode125/\345\244\247\351\255\224\347\216\213\347\210\261\347\251\277\345\255\226\347\203\237\347\255\222.md"
new file mode 100644
index 000000000..82d6547e8
--- /dev/null
+++ "b/2018.11.27-leetcode125/\345\244\247\351\255\224\347\216\213\347\210\261\347\251\277\345\255\226\347\203\237\347\255\222.md"
@@ -0,0 +1,37 @@
+```
+class Solution {
+ public boolean isPalindrome(String s) {
+ s = s.toLowerCase();
+ char [] charArray = s.toCharArray();
+
+ int begin = 0;
+ int end = charArray.length - 1;
+ while(begin < end)
+
+ {
+ if (!isChar(charArray[begin])){//不是数字和小字母
+ begin++;
+ continue;
+ }
+ if (!isChar(charArray[end])){//不是数字和小字母
+ end--;
+ continue;
+ }
+ if(charArray[begin] == charArray[end])
+ {
+ begin++;
+ end--;
+ }else{
+ return false;
+ }
+ }
+ return true;
+ }
+ public boolean isChar(char c){//判断是否为数字或者字母
+ if (c<48||(c>57&&c<65)||(c>90&&c<97)||c>122){
+ return false;
+ }
+ return true;
+ }
+}
+```
diff --git "a/2018.11.27-leetcode125/\345\255\231\350\241\214\350\200\205.md" "b/2018.11.27-leetcode125/\345\255\231\350\241\214\350\200\205.md"
new file mode 100644
index 000000000..037bb68bc
--- /dev/null
+++ "b/2018.11.27-leetcode125/\345\255\231\350\241\214\350\200\205.md"
@@ -0,0 +1,30 @@
+
+class Solution{
+private:
+ int top;
+ char elem[MAXSIZE];
+public:
+ void push_sq(char *arr[],Solution *sq){
+ for(int i=0;itop=0;
+ }
+ void push(Solution *sq,char x){
+ sq->elem[sq->top]=x;
+ sq->top++;
+ }
+ char pop(Solution *sq){
+ return (sq->eelm[sq->--top]);
+ }
+};
+
diff --git "a/2018.11.27-leetcode125/\345\256\266.md" "b/2018.11.27-leetcode125/\345\256\266.md"
new file mode 100644
index 000000000..4ee794c1f
--- /dev/null
+++ "b/2018.11.27-leetcode125/\345\256\266.md"
@@ -0,0 +1,20 @@
+```
+func isPalindrome(s string) bool {
+ if len(s) <= 1 {return true}
+ low, hi := 0, len(s) - 1
+ for low < hi {
+ for ; low < hi && !isValid(s[low]); low++ {}
+ for ; low < hi && !isValid(s[hi]); hi--{}
+ x, y := s[low], s[hi]
+ if (x >= 'A' && x <= 'Z') {x = x - 'A' + 'a'}
+ if (y >= 'A' && y <= 'Z') {y = y - 'A' + 'a'}
+ if x != y {return false}
+ low, hi = low+1, hi-1
+ }
+ return true
+}
+
+func isValid(b byte) bool {
+ return (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || (b >= '0' && b <= '9')
+}
+```
diff --git "a/2018.11.27-leetcode125/\346\232\256\346\210\220\351\233\252.md" "b/2018.11.27-leetcode125/\346\232\256\346\210\220\351\233\252.md"
new file mode 100644
index 000000000..9ea2883eb
--- /dev/null
+++ "b/2018.11.27-leetcode125/\346\232\256\346\210\220\351\233\252.md"
@@ -0,0 +1,29 @@
+class Solution {
+ public boolean isPalindrome(String s) {
+
+ s = s.replaceAll("[^a-zA-Z]", "").toLowerCase();
+ s = s.toLowerCase();
+ char [] charArray = s.toCharArray();
+ String temp = "";
+ for(int i=0;i= 48 && (int)charArray[i] <= 57) || ((int)charArray[i] >= 97 && (int)charArray[i] <= 122))
+ {
+ temp += charArray[i];
+ }
+ }
+ char [] resultArray = temp.toCharArray();
+ int begin = 0;int end = resultArray.length - 1;
+ while(begin < end)
+ {
+ if(resultArray[begin] == resultArray[end])
+ {
+ begin++;
+ end--;
+ }else{
+ return false;
+ }
+ }
+ return true;
+ }
+}
diff --git "a/2018.11.27-leetcode125/\346\243\225\346\246\210\346\240\221.md" "b/2018.11.27-leetcode125/\346\243\225\346\246\210\346\240\221.md"
new file mode 100644
index 000000000..c37ae057d
--- /dev/null
+++ "b/2018.11.27-leetcode125/\346\243\225\346\246\210\346\240\221.md"
@@ -0,0 +1,30 @@
+
+public class TestisPalindrome {
+ public static boolean isPalindrome(String s){
+ s = s.toLowerCase();
+ char [] charArray = s.toCharArray();
+ String temp = "";
+ for(int i=0;i=60&&(int)charArray[i]<=71||(int)charArray[i]>=97&&(int)charArray[i]<=122){
+ temp += charArray[i];
+ }
+ }
+ char [] resultArray = temp.toCharArray();
+ int begin = 0;
+ int end = resultArray.length-1;
+ while(begin= 'A' && ch <= 'Z')
+ {
+ ch += 32;
+ return true;
+ }
+
+ if(ch >= 'a' && ch <= 'z')
+ return true;
+
+ if(ch >= '0' && ch <= '9')
+ return true;
+
+ return false;
+ }
+};
diff --git "a/2018.11.27-leetcode125/\351\223\201\347\224\267\347\245\236sama.java" "b/2018.11.27-leetcode125/\351\223\201\347\224\267\347\245\236sama.java"
new file mode 100644
index 000000000..96cd80151
--- /dev/null
+++ "b/2018.11.27-leetcode125/\351\223\201\347\224\267\347\245\236sama.java"
@@ -0,0 +1,12 @@
+char[] charArray = s.toCharArray();
+ StringBuilder sb = new StringBuilder();
+ for(char c:charArray){
+ if(Character.isDigit(c)||Character.isLetter(c)){
+ sb.append(c);
+ }
+
+ }
+
+ return sb.toString().toLowerCase().equals(sb.reverse().toString().toLowerCase());
+
+ }
diff --git "a/2018.11.27-leetcode125/\351\223\201\347\224\267\347\245\236sama.md" "b/2018.11.27-leetcode125/\351\223\201\347\224\267\347\245\236sama.md"
new file mode 100644
index 000000000..91888baef
--- /dev/null
+++ "b/2018.11.27-leetcode125/\351\223\201\347\224\267\347\245\236sama.md"
@@ -0,0 +1,31 @@
+```Java
+class Solution {
+ public boolean isPalindrome(String s) {
+ char[] charArray = s.toCharArray();
+ int index=0;
+ for(char c:charArray){
+ if(c>=65&&c<=90 ){
+ charArray[index++]=c;
+ }else if(c>=97&&c<=122){
+ charArray[index++]=(char)(c-32);
+ }else if(c>=48&&c<=57) {
+ charArray[index++]=c;
+ }
+ }
+ System.out.print(charArray);
+ int start=0;
+ int end=index-1;
+ while(start<=end){
+ if(charArray[start]==charArray[end]){
+ start++;
+ end--;
+ }else{
+ return false;
+ }
+
+ }
+ return true;
+ }
+}
+```
+
diff --git a/2018.11.28 b/2018.11.28
new file mode 100644
index 000000000..40c2c6e7b
--- /dev/null
+++ b/2018.11.28
@@ -0,0 +1,32 @@
+
+/**
+ * Created by zongjianwei
+ * DATE: 21:32 2018/11/28
+ * Desc: 压缩字符数组
+ */
+public class StringCompression {
+ public int compress(char[] chars){
+ int m = 0;
+ int n = 0;
+ for(int i=0;in){
+ for(int j=0;j<(""+(i-n+1)).toCharArray().length;j++){
+ chars[m++] = chars[j];
+ }
+ }
+ n = i +1;
+ }
+ }
+ return m;
+ }
+
+ public static void main(String[] args) {
+ char[] chars = {'a','a','b','b','c','c','c'};
+ StringCompression sc = new StringCompression();
+ int length = sc.compress(chars);
+ System.out.println(length);
+
+ }
+}
diff --git a/2018.11.28-leetcode151/-.md b/2018.11.28-leetcode151/-.md
new file mode 100644
index 000000000..47c11b099
--- /dev/null
+++ b/2018.11.28-leetcode151/-.md
@@ -0,0 +1,28 @@
+public class Solution {
+ public String reverseWords(String s) {
+ List list = new ArrayList<>();
+ StringBuffer buffer = new StringBuffer();
+ for (int i = 0; i < s.length(); i++) {
+ char c = s.charAt(i);
+ if (c != ' ') {
+ buffer.append(c);
+ }else{
+ if (buffer.length() != 0) {
+ list.add(buffer.toString());
+ buffer.setLength(0);
+ }
+ }
+ }
+ if (buffer.length() != 0) {
+ list.add(buffer.toString());
+ buffer.setLength(0);
+ }
+ for (int i = list.size(); i > 0; i--) {
+ if (buffer.length() != 0) {
+ buffer.append(" ");
+ }
+ buffer.append(list.get(i-1));
+ }
+ return buffer.toString();
+ }
+}
diff --git a/2018.11.28-leetcode151/018429.md b/2018.11.28-leetcode151/018429.md
new file mode 100644
index 000000000..350c263a7
--- /dev/null
+++ b/2018.11.28-leetcode151/018429.md
@@ -0,0 +1,48 @@
+int top=0;
+void push(char c,char* stack)
+{
+ stack[top++]=c;
+}
+char pop(char* stack)
+{
+ return stack[--top];//写入s1
+}
+void reverseWords(char *s) {
+ int i=0,j=0,flag=0;
+ while(s[i]!='\0') i++;
+ char* stack = (char*)malloc(i);
+ char* s1 = (char*)malloc(i+1);
+ i--;
+ while(i>=0)
+ {
+ if(s[i]==' ')
+ {
+ while(top!=0)//如果栈不为空
+ {
+ flag=1;
+ s1[j++]=pop(stack);
+ }
+ if(flag==1)
+ {
+ s1[j++]=' ';
+ flag=0;//重置flag
+ }
+ i--;
+ }
+ else
+ {
+ push(s[i--],stack);
+ }
+ }
+ if(s[++i]!=' ')
+ {
+ while(top!=0)//如果栈不为空
+ s1[j++]=pop(stack);
+ s[j]=' ';
+ }
+ else
+ j--;
+ s1[j]='\0';
+ s = strcpy(s,s1);
+ free(s1);
+}
diff --git a/2018.11.28-leetcode151/Avalon.md b/2018.11.28-leetcode151/Avalon.md
new file mode 100644
index 000000000..8063fcb02
--- /dev/null
+++ b/2018.11.28-leetcode151/Avalon.md
@@ -0,0 +1,20 @@
+public static String reverseWords(String input){
+
+ String[] arr = input.trim().split("\\s+");//"\\s+"
+ int len = arr.length;
+ /*
+ String[] result = new String[len];
+ for (int i = 0;i
+
+__说明__:
+* 无空格字符构成一个单词。
+* 输入字符串可以在前面或者后面包含多余的空格,但是反转后的字符不能包括。
+* 如果两个单词间有多余的空格,将反转后单词间的空格减少到只含一个。
+
+__进阶__:
+* 请选用C语言的用户尝试使用 O(1) 空间复杂度的原地解法。
+### 1.2 输入与输出
+输入:
+* string &s:给定的字符串s
+
+输出:
+* void:原地修改
+### 1.3 样例
+#### 1.3.1 样例1
+输入: "the sky is blue"
+输出: "blue is sky the"
+## 2 思路描述与代码
+### 2.1 思路描述(反转法)
+1. 先整体反转
+2. 按单词逐个反转
+
+比如输入: "the sky is blue"
+整体反转后为"elub si yks eht"
+按单词逐个反转后为"blue is sky the"
+### 2.2 代码
+```cpp
+void reverseWords(string &s) {
+ //强行头部加空格方便统一处理
+ s.insert(0, 1, ' ');
+ reverse(s.begin(), s.end());
+ int len = s.size();
+ //搜索的位置
+ int search = 0;
+ //搜索的当前单词的长度
+ int cnt_word = 0;
+ //搜索的当前单词的起始位置
+ int start_word = 0;
+ while( search < len ){
+ //在单词有效范围内
+ if(s[search] != ' ') ++search, ++cnt_word;
+ //在单词边界
+ else{
+ if(cnt_word != 0){
+ //翻转单词
+ reverse(s.begin() + start_word, s.begin() + start_word + cnt_word);
+ //去除多余的空格
+ search++;
+ while(search < len && s[search] == ' ') s.erase(s.begin() + search);
+ //设置下一个单词搜索的初始位置和长度
+ start_word = search;
+ cnt_word = 0;
+ }
+ //可以去除原字符串中开头和尾巴可能存在的连续空格
+ else s.erase(s.begin() + start_word);
+ }
+ }
+ //去除空格最后一个单词附带的空格
+ s.pop_back();
+}
+```
+## 3 思考与拓展
+### 3.1 思考
+#### 3.1.1 其他方法
+无。
+#### 3.1.2 复杂度分析
+方法|空间复杂度|时间复杂度
+--- | --- | ---
+反转法|O(1)|O(n)
+#### 3.1.3 难点分析
+1. 思路分析
+2. 原地修改
+### 3.2 拓展
+如果给你的是数组数据呢?
diff --git a/2018.11.28-leetcode151/FFFro.md b/2018.11.28-leetcode151/FFFro.md
new file mode 100644
index 000000000..404793a37
--- /dev/null
+++ b/2018.11.28-leetcode151/FFFro.md
@@ -0,0 +1,16 @@
+public class Solution {
+ public String reverseWords(String s) {
+ if(s == "")
+ return "";
+ String[] str = s.split(" ");
+ String res = "";
+ for (int i = str.length-1; i >=0; i--) {
+ if(!str[i].equals("")){
+ if (res.length()>0)
+ res += " ";
+ }
+ res += str[i];
+ }
+ return res;
+ }
+}
diff --git a/2018.11.28-leetcode151/GatesMa.md b/2018.11.28-leetcode151/GatesMa.md
new file mode 100644
index 000000000..0efbf6870
--- /dev/null
+++ b/2018.11.28-leetcode151/GatesMa.md
@@ -0,0 +1,29 @@
+```cpp
+class Solution {
+public:
+ void reverseWords(string &s) {
+ if(s.empty())
+ return ;
+ stringstream ss(s);
+ vector words;
+ string word;
+ while(ss>>word)
+ words.push_back(word+' ');
+ if(!words.empty())
+ {
+ s.clear();
+
+ for(int i=words.size()-1;i>=0;i--)
+ {
+ s+= words[i];
+ }
+ //s = s.substr(0,s.length()-1);
+ s.pop_back();
+ }
+ else
+ {
+ s.clear();
+ }
+ }
+};
+```
diff --git a/2018.11.28-leetcode151/Istoryforever.md b/2018.11.28-leetcode151/Istoryforever.md
new file mode 100644
index 000000000..56070c902
--- /dev/null
+++ b/2018.11.28-leetcode151/Istoryforever.md
@@ -0,0 +1,31 @@
+leetcode of 151
+```
+class Solution {
+public:
+ void reverseWords(string &s) {
+ vector ans;
+ string t="";
+ for(auto c = s.begin(); c!=s.end(); c++){
+ if(*c ==' '){
+ if(t != ""){
+ ans.push_back(t);
+ t="";
+ }
+ continue;
+ }
+ t+=*c;
+ if(c == s.end()-1){
+ ans.push_back(t);
+ }
+ }
+ reverse(ans.begin(),ans.end());
+ s="";
+ for (auto i = ans.begin();i != ans.end(); i++){
+ if(i == ans.begin()) s=*i;
+ else{
+ s+=" "+*i;
+ }
+ }
+ }
+};
+```
diff --git a/2018.11.28-leetcode151/Ostrichcrab.md b/2018.11.28-leetcode151/Ostrichcrab.md
new file mode 100644
index 000000000..7b897dd54
--- /dev/null
+++ b/2018.11.28-leetcode151/Ostrichcrab.md
@@ -0,0 +1,36 @@
+```
+class Solution {
+public:
+ void reverseWords(string &s) {
+ s.insert(0,1,' ');
+ reverse(s.begin(),s.end());
+ int len = s.size();
+ int now = 0;
+ int pos = 0;
+ int sum = 0;
+ while(now < len){
+
+ if(s[now]!=' '){
+ now++;
+ sum++;
+ }else{
+
+ if(sum != 0){
+ reverse(s.begin()+pos,s.begin()+pos+sum);
+ now++;
+ while(now str;
+ string s1;
+ int i=0;
+ while(i= 0) {
+ while (i >= 0 && chars[i] == ' ') {
+ --i;
+ }
+ if (i >= 0) {
+ int j = i;
+ while (i >= 0 && chars[i] != ' ') {
+ --i;
+ }
+ sb.append(chars, i + 1, j - i).append(' ');
+ --i;
+ }
+ }
+ if (sb.length() > 0) {
+ sb.setLength(sb.length() - 1);
+ }
+ return sb.toString();
+ }
+}
+```
diff --git a/2018.11.28-leetcode151/Tony the Cyclist.md b/2018.11.28-leetcode151/Tony the Cyclist.md
new file mode 100644
index 000000000..e5f497cb8
--- /dev/null
+++ b/2018.11.28-leetcode151/Tony the Cyclist.md
@@ -0,0 +1,26 @@
+```
+public class Solution {
+ public String reverseWords(String s) {
+ s = s.trim();
+ System.out.println(s);
+ if (s.equals("")){
+ return "";
+ }
+ ArrayList ss = new ArrayList(Arrays.asList(s.split(" ")));
+ int len = ss.size();
+ for (int i = 0; i < len; i++) {
+ if (ss.get(i).equals("")) {
+ ss.remove(i);
+ i--;
+ len--;
+ }
+ }
+ Collections.reverse(ss);
+ String result = "";
+ for (String i : ss) {
+ result = result + i + " ";
+ }
+ return result.substring(0, result.length() - 1);
+ }
+}
+```
diff --git a/2018.11.28-leetcode151/V1ncentzzZ b/2018.11.28-leetcode151/V1ncentzzZ
new file mode 100644
index 000000000..eaf5ab1da
--- /dev/null
+++ b/2018.11.28-leetcode151/V1ncentzzZ
@@ -0,0 +1,14 @@
+public class Solution {
+ public String reverseWords(String s) {
+ StringBuilder result = new StringBuilder();
+ if(s == null || s.length() == 0) return "";
+ s = s.trim();
+ String[] words = s.split(" ");
+ for(int i=words.length-1; i>=0; i--){
+ if("".equals(words[i])) continue;
+ result.append(words[i]);
+ if(i > 0) result.append(" ");
+ }
+ return result.toString();
+ }
+}
diff --git a/2018.11.28-leetcode151/WhiteNight.md b/2018.11.28-leetcode151/WhiteNight.md
new file mode 100644
index 000000000..a788c6637
--- /dev/null
+++ b/2018.11.28-leetcode151/WhiteNight.md
@@ -0,0 +1,33 @@
+```java
+/**
+ * 翻转字符串里面的单词
+ *
+ */
+public class S2 {
+ public String reverseWords(String s) {
+ if (s == null || s.length() == 0)
+ return "";
+
+ String[] string = s.split(" ");
+ String res = "";
+
+ for (int i = string.length - 1; i >= 0; i--) {
+ if (!string[i].equals("")){
+ if (res.length() > 0){
+ res += " ";
+ }
+ res += string[i];
+ }
+ }
+
+ return res;
+ }
+
+ public static void main(String[] args) {
+ S2 s = new S2();
+ String string = "the sky is blue";
+ String res = s.reverseWords(string);
+ System.out.println(res);
+ }
+}
+```
\ No newline at end of file
diff --git a/2018.11.28-leetcode151/cuiHlu.md b/2018.11.28-leetcode151/cuiHlu.md
new file mode 100644
index 000000000..d3d5877e4
--- /dev/null
+++ b/2018.11.28-leetcode151/cuiHlu.md
@@ -0,0 +1,26 @@
+ //first reverse the string, second reverse the word
+ void reverseWords(string &s) {
+ if (s.empty())
+ return;
+ reverse(s.begin(), s.end());
+ int length = s.size();
+ int storeIndex = 0;
+ for (int i = 0; i < length; ++i)
+ {
+ if (s[i] != ' ')
+ {
+ if (storeIndex != 0)
+ {
+ s[storeIndex++] = ' ';
+ }
+ int j = i;
+ while (j < length && s[j] != ' ' )
+ {
+ s[storeIndex++] = s[j++];
+ }
+ reverse(s.begin() + storeIndex - j + i, s.begin() + storeIndex);
+ i = j;
+ }
+ }
+ s.erase(s.begin() + storeIndex, s.end());
+ }
diff --git a/2018.11.28-leetcode151/disappo1nted.md b/2018.11.28-leetcode151/disappo1nted.md
new file mode 100644
index 000000000..80b3ca6b5
--- /dev/null
+++ b/2018.11.28-leetcode151/disappo1nted.md
@@ -0,0 +1,18 @@
+public class Solution {
+ public String reverseWords(String s) {
+ if(s==null || s.length()==0){
+ return"";
+ }
+ String[] array=s.split(" ");
+ String str="";
+ for(int i = array.length-1;i>=0;--i){
+ if(!array[i]equals("")){
+ if(str.length()>0){
+ str+=" ";
+ }
+ str+=array[i];
+ }
+ }
+ return str;
+ }
+}
diff --git a/2018.11.28-leetcode151/halfodfwater.md b/2018.11.28-leetcode151/halfodfwater.md
new file mode 100644
index 000000000..83622a87f
--- /dev/null
+++ b/2018.11.28-leetcode151/halfodfwater.md
@@ -0,0 +1,58 @@
+## Leetcode 151
+
+```
+class Solution {
+public:
+ void reverseWords(string &s) {
+
+
+ vector res;
+ int head=0, tail=0;
+
+ # 去掉首尾空格
+ if(!s.empty()){
+ s.erase(0,s.find_first_not_of(" "));
+ s.erase(s.find_last_not_of(" ") + 1);
+ }
+ int len = s.size();
+ int flag = 0;
+ int j=0;
+ for(int i=0;i=0;i--)
+ {
+ s += res[i];
+ s += ' ';
+ }
+ s.erase(s.find_last_not_of(' ')+1);
+ }
+};
+
+```
+
+## Performance:
+
+Beyond the 99.86% of commits.
diff --git a/2018.11.28-leetcode151/ieei.md b/2018.11.28-leetcode151/ieei.md
new file mode 100644
index 000000000..0b3f22190
--- /dev/null
+++ b/2018.11.28-leetcode151/ieei.md
@@ -0,0 +1,50 @@
+public class Solution {
+ public String reverseWords(String s) {
+ int length=s.length();
+ //当字符串为空
+ if(s == null){ return null;}
+ //当字符串为" "时 直接返回null
+ if(s.trim().equals("")){
+ return s.trim();
+ }
+ /**
+ * 先将字符串按照空格分裂为字符串数组
+ * 然后收尾两个指针来交换即可
+ */
+ //0.掐头去尾
+ String allRevStr=s.trim();
+ //1.将字符串按照空格分裂为字符串数组
+ String[] strChar=allRevStr.split(" ");
+
+ //2.使用首尾两个指针来交换
+ int left=0;
+ int right=strChar.length-1;
+ String temStr=null;
+ while(left= 0; i--) {
+ if (!splits[i].equals("")) {
+ //单词不为空
+ result = result + splits[i];
+ }
+ }
+ return result;
+ }
diff --git a/2018.11.28-leetcode151/oven123.md b/2018.11.28-leetcode151/oven123.md
new file mode 100644
index 000000000..d9c045cfc
--- /dev/null
+++ b/2018.11.28-leetcode151/oven123.md
@@ -0,0 +1,39 @@
+###给定一个字符串,逐个翻转字符串中的每个单词。
+先整体利用Java语法,翻转整个字符,再一一翻转单词
+```java
+public class Solution {
+ public String reverseWords(String s) {
+ int index = 0,n = s.length();
+ StringBuilder sb = new StringBuilder(s).reverse();//翻转整个字符串
+ for(int i = 0;i < n;i++){
+ if(sb.charAt(i) != ' '){//如果遍历到的字符不是空格,
+ if(index != 0){//不是第一个单词
+ sb.setCharAt(index, ' ');//加空格
+ index++;//非空字符
+ }
+ int j = i;//从当前遍历到字符开始
+ while(j < n && sb.charAt(j) != ' '){
+ sb.setCharAt(index,sb.charAt(j));//把该单词逐字复制到标记位置
+ index++;
+ j++;
+ }
+ String t = new StringBuilder(sb.substring(index - (j - i),index)).reverse().toString();//将该单词翻转
+ sb.replace(index - (j - i),index,t);//将翻转好的单词复制进去
+ i = j;//将标记移动到该单词结束
+
+ }
+ }
+ sb.setLength(index);//防范空格情况
+ return sb.toString();
+```
+大神解法:
+```java
+public class Solution {
+ public String reverseWords(String s) {
+ String[] words = s.trim().split(" +");
+ Collections.reverse(Arrays.asList(words));
+ return String.join(" ", words);
+ }
+}
+```
+把字符串切割为字符串数组,翻转,在单词间隔加入空格
diff --git a/2018.11.28-leetcode151/sourcema.md b/2018.11.28-leetcode151/sourcema.md
new file mode 100644
index 000000000..ce03ad7e5
--- /dev/null
+++ b/2018.11.28-leetcode151/sourcema.md
@@ -0,0 +1,49 @@
+# LeetCode 151
+ 1. public static String reverseWords(String s) {//first method
+ if (s.length() == 0 || s == null) {
+ return s;
+ }
+ String str = s.trim();
+ String[] split = str.split(" +");
+ String result = "";
+ for (int i = split.length - 1; i >=0; i--) {
+ result += split[i] + " ";
+ }
+ return result.substring(0, result.length() - 1);
+ }
+ 2. public static String reverseWords2(String s) {//two method
+ if (s.length() == 0 || s == null) {
+ return s;
+ }
+ String str = s.trim();//" "此时str为""
+ char[] chars = str.toCharArray();
+ reverse(chars, 0, chars.length - 1);
+ //String target = new StringBuilder(str).reverse().toString();
+ String result = "";
+ int left=0,right=0;
+ //char[] chars = target.toCharArray();
+ while (right < chars.length) {
+ while (right i){
+ char t = c[i];
+ c[i++] = c[j];
+ c[j--] = t;
+ }
+ }
+```
diff --git a/2018.11.28-leetcode151/syuan.md b/2018.11.28-leetcode151/syuan.md
new file mode 100644
index 000000000..77db581f0
--- /dev/null
+++ b/2018.11.28-leetcode151/syuan.md
@@ -0,0 +1,127 @@
+##### 题目
+```
+给定一个字符串,逐个翻转字符串中的每个单词。
+
+示例:
+
+输入: "the sky is blue",
+输出: "blue is sky the".
+
+说明:
+
+ 无空格字符构成一个单词。
+ 输入字符串可以在前面或者后面包含多余的空格,但是反转后的字符不能包括。
+ 如果两个单词间有多余的空格,将反转后单词间的空格减少到只含一个。
+
+进阶: 请选用C语言的用户尝试使用 O(1) 空间复杂度的原地解法。
+```
+##### 思路
+- 先将整个字符串反转
+- 按照空格分成String数组
+- 每个单词反转
+##### 代码
+
+```
+public class Solution {
+ public String reverseWords(String s) {
+ int length=s.length();
+ //当字符串为空
+ if(s == null){ return null;}
+ //当字符串为" "时 直接返回null
+ if(s.trim().equals("")){
+ return s.trim();
+ }
+
+ //1.反转整个字符串
+ String allRevStr=ReverseWord(s);
+ //2.获得每个单词
+ String[] strChar=allRevStr.split(" ");
+
+ //3.反转每个字符串
+ String reverse="";
+ for (int i=0; i
+#include
+#include
+#include
+using namespace std;
+
+//using stack space O(n)
+class Solution {
+public:
+ void reverseWords(string &s) {
+ if (s.empty()) return;
+ stack st;
+ for (int i = 0; i < s.size(); ++i) {
+ string sub;
+ while (s[i] != ' ' && i < s.size()) {
+ sub.push_back(s[i++]);
+ }
+ if (!sub.empty()) st.push(sub);//空字符串因为有‘\0’的存在也会被当做一个元素放到stack中
+ }
+ string res;
+ while (!st.empty()) {
+ res += st.top();
+ res += " ";
+ st.pop();
+ }
+ if (!res.empty()) res.pop_back();
+ s = res;
+ }
+};
+
+class Solution2 {
+public:
+ void reverseWords(string &s) {
+ istringstream is(s);
+ is >> s;
+ cout << s.size();
+ string tmp;
+ while (is >> tmp) s = tmp + " " + s;
+ // if (!s.empty() && s[0] == ' ') s = "";
+ }
+};
+int main() {
+ Solution3 s;
+ // string str{"The sky is blue"};
+ // string str{" "};
+ string str{" The sky is blue"};
+ // string str{"The sky is blue "};
+ // string str{"The sky is blue"};
+ s.reverseWords(str);
+ cout << str << "*";
+}
+```
diff --git "a/2018.11.28-leetcode151/\343\200\202\343\200\202\343\200\202.md" "b/2018.11.28-leetcode151/\343\200\202\343\200\202\343\200\202.md"
new file mode 100644
index 000000000..6b8feff93
--- /dev/null
+++ "b/2018.11.28-leetcode151/\343\200\202\343\200\202\343\200\202.md"
@@ -0,0 +1,29 @@
+```
+public String reverseWords(String s) {
+ int i = s.length()-1,wordRight=-1;
+ StringBuilder builder = new StringBuilder();
+ while (i >= 0){
+ if (s.charAt(i) == ' '){
+ if (wordRight!=-1){
+ if (builder.length()!=0){
+ builder.append(' ');
+ }
+ builder.append(s.substring(i+1,wordRight+1));
+ wordRight=-1;
+ }
+ i--;
+ continue;
+ }
+ if (wordRight==-1)wordRight = i;
+ i--;
+ }
+ //添加最后一个单词
+ if (wordRight!=-1){
+ if (builder.length()!=0){
+ builder.append(' ');
+ }
+ builder.append(s.substring(i+1,wordRight+1));
+ }
+ return builder.toString();
+ }
+ ```
diff --git "a/2018.11.28-leetcode151/\344\270\215\350\203\275\345\220\203\345\244\252\351\245\261.md" "b/2018.11.28-leetcode151/\344\270\215\350\203\275\345\220\203\345\244\252\351\245\261.md"
new file mode 100644
index 000000000..255de0e06
--- /dev/null
+++ "b/2018.11.28-leetcode151/\344\270\215\350\203\275\345\220\203\345\244\252\351\245\261.md"
@@ -0,0 +1,14 @@
+public class Solution {
+ public String reverseWords(String s) {
+ String[] ss=s.split(" ");
+ StringBuilder answer=new StringBuilder();
+ for(int i=ss.length-1;i>=0;i--) {
+ ss[i]=ss[i].trim();
+ if(!ss[i].equals("")&&ss[i]!=null) {
+ System.out.println(ss[i]);
+ answer.append(ss[i]+" ");
+ }
+ }
+ return answer.toString().trim();
+ }
+}
diff --git "a/2018.11.28-leetcode151/\345\225\246\345\225\246\345\225\246.md" "b/2018.11.28-leetcode151/\345\225\246\345\225\246\345\225\246.md"
new file mode 100644
index 000000000..923f4ddf8
--- /dev/null
+++ "b/2018.11.28-leetcode151/\345\225\246\345\225\246\345\225\246.md"
@@ -0,0 +1,26 @@
+```java
+public class Solution {
+ public String reverseWords(String s) {
+ if(s==null||s.length()<=0)return "";
+ String res = "";
+ int l,r;
+ l=s.length()-1;
+ while(l>=0&&s.charAt(l)==' ')l--;
+ if(l<0)return "";
+ boolean flag = false;
+ while(l>=0){
+ while(l>=0&&s.charAt(l)!=' ')l--;
+ for(r=l+1;r=0&&s.charAt(l)==' ')l--;
+ }
+ return res;
+ }
+}
+```
diff --git "a/2018.11.28-leetcode151/\345\244\247\351\255\224\347\216\213\347\210\261\347\251\277\345\255\226\347\203\237\347\255\222.md" "b/2018.11.28-leetcode151/\345\244\247\351\255\224\347\216\213\347\210\261\347\251\277\345\255\226\347\203\237\347\255\222.md"
new file mode 100644
index 000000000..82f8c5168
--- /dev/null
+++ "b/2018.11.28-leetcode151/\345\244\247\351\255\224\347\216\213\347\210\261\347\251\277\345\255\226\347\203\237\347\255\222.md"
@@ -0,0 +1,20 @@
+```
+ public class Solution {
+ public String reverseWords(String s) {
+ if (s == null || s.length() == 0) {
+ return "";
+ }
+ String[] array = s.split(" ");//按照空格划分字符串
+ String str = "";
+ for (int i = array.length - 1; i >= 0; i--) {
+ if (!array[i].equals("")) {
+ if (str.length() > 0) {
+ str += " ";
+ }
+ str += array[i];//如果不是空字符串,就把截断的旧字符串添加到新字符串中。
+ }
+ }
+ return str;
+ }
+}
+```
diff --git "a/2018.11.28-leetcode151/\345\246\256\345\217\257.md" "b/2018.11.28-leetcode151/\345\246\256\345\217\257.md"
new file mode 100644
index 000000000..a86f73238
--- /dev/null
+++ "b/2018.11.28-leetcode151/\345\246\256\345\217\257.md"
@@ -0,0 +1,53 @@
+```java
+package sy181129;
+
+import java.util.Stack;
+
+/**
+ * @author suyuan
+ *
+ *给定一个字符串,逐个翻转字符串中的每个单词。
+
+ 示例:
+
+ 输入: "the sky is blue",
+ 输出: "blue is sky the".
+ 说明:
+
+ 无空格字符构成一个单词。
+ 输入字符串可以在前面或者后面包含多余的空格,但是反转后的字符不能包括。
+ 如果两个单词间有多余的空格,将反转后单词间的空格减少到只含一个。
+ */
+public class leetcode_151反转字符串里的单词
+{
+
+ public static void main(String[] args)
+ {
+ String string=" the sky is blue";
+ System.out.println(reverseWords(string));
+
+ }
+
+ public static String reverseWords(String s) {
+ String str=s.trim();
+ if(str.equals(""))
+ return "";
+ if(str.equals(" "))
+ return "";
+ Stack stack=new Stack<>();
+ StringBuilder sb=new StringBuilder();
+ String[] split = str.split("\\s+");
+ for(String str1:split)
+ {
+ stack.push(str1);
+ }
+ int size=stack.size();
+ for(int i=0;i= 0; )
+ {
+ while (i >= 0 && s[i] == ' ') i--;
+ if (i < 0) break;
+ if (!rw.empty()) rw.push_back(' ');
+ string t;
+ while (i >= 0 && s[i] != ' ') t.push_back(s[i--]); //开始逆向输出
+ reverse(t.begin(), t.end());
+ rw.append(t);
+ }
+ s=rw;
+ }
+};
diff --git "a/2018.11.28-leetcode151/\346\210\221\347\210\261\345\220\203\347\223\234\345\255\220.md" "b/2018.11.28-leetcode151/\346\210\221\347\210\261\345\220\203\347\223\234\345\255\220.md"
new file mode 100644
index 000000000..bee775d9b
--- /dev/null
+++ "b/2018.11.28-leetcode151/\346\210\221\347\210\261\345\220\203\347\223\234\345\255\220.md"
@@ -0,0 +1,32 @@
+#leetcode151
+```
+public class Solution {
+ public String reverseWords(String s) {
+ if(s!=null&&"".equals(s)){
+ return s;
+ }else if(s!=null){
+ String[] ss=s.split(" ");
+ if(ss.length==0){
+ return "";
+ }else{
+ String result="";
+ for(int i=ss.length-1;i>=0;i--){
+ if(i==ss.length-1){
+ if(!ss[i].trim().equals("")){
+ result+=ss[i].trim();
+ }
+
+ }else{
+ if(!ss[i].trim().equals("")){
+ result+=" "+ss[i].trim();
+ }
+ }
+
+ }
+ return result;
+ }
+ }
+ return s;
+ }
+}
+```
\ No newline at end of file
diff --git "a/2018.11.28-leetcode151/\346\231\250\346\233\246\351\233\250\351\234\262.md" "b/2018.11.28-leetcode151/\346\231\250\346\233\246\351\233\250\351\234\262.md"
new file mode 100644
index 000000000..47b9091cd
--- /dev/null
+++ "b/2018.11.28-leetcode151/\346\231\250\346\233\246\351\233\250\351\234\262.md"
@@ -0,0 +1,17 @@
+public static String reverseWords(String str) {
+ str=str.trim();
+ if(str.isEmpty()||str.length()==1||str.indexOf("\\s+")!=-1) {
+ return str;
+ }
+ StringBuffer sb = new StringBuffer();
+ String[] str1=str.split("\\s+");
+ for (int i = 0; i < str1.length; i++) {
+ if(i reverseWord = new Stack<>();
+ StringBuffer sb = new StringBuffer();
+ char[] datas = s.toCharArray();
+ for(int i=0;i=0;i--){
+ if(!array[i].equals("")){
+ if(str.length()>0){
+ str+=" ";
+ }
+ str += array[i];
+ }
+ }
+ return str;
+ }
+
+ public static void main(String[] args) {
+ String s = "hello world!";
+ System.out.println(reverseWords(s));
+ }
+}
diff --git "a/2018.11.28-leetcode151/\346\271\233\346\261\237\347\224\262\351\270\237.md" "b/2018.11.28-leetcode151/\346\271\233\346\261\237\347\224\262\351\270\237.md"
new file mode 100644
index 000000000..9070b2973
--- /dev/null
+++ "b/2018.11.28-leetcode151/\346\271\233\346\261\237\347\224\262\351\270\237.md"
@@ -0,0 +1,17 @@
+```
+public static String reverseWords(String s) {
+ int len = s.length();
+ int j = len;
+ String result = "";
+ for (int i = len - 1; i >= 0; i--) {
+ if (s.charAt(i) == ' '){
+ j = i ;
+ } else if (i == 0 || s.charAt(i - 1) == ' ') {
+ if (result.length() != 0) {
+ result += ' ';
+ }
+ result += s.substring(i, j);
+ }
+ }
+ return result;
+}
diff --git "a/2018.11.28-leetcode151/\347\245\236\347\247\230\347\232\204\347\201\253\346\237\264\344\272\272.md" "b/2018.11.28-leetcode151/\347\245\236\347\247\230\347\232\204\347\201\253\346\237\264\344\272\272.md"
new file mode 100644
index 000000000..c1b1965d5
--- /dev/null
+++ "b/2018.11.28-leetcode151/\347\245\236\347\247\230\347\232\204\347\201\253\346\237\264\344\272\272.md"
@@ -0,0 +1,35 @@
+class Solution {
+public:
+ void reverseWords(string &s) {
+
+ int size = s.length();
+ stack sta;
+
+ int begin = 0;
+ int cur = begin;
+ while(cur < size)
+ {
+ while(cur=1;i--){
+ if (ss[i].equals("")){ //句子中可能会有多余空格
+ continue;
+ }
+ newS = newS+ss[i]+" ";
+ }
+ newS = newS+ss[0];
+ System.out.println(newS);
+ return newS;
+ }
diff --git "a/2018.11.28-leetcode151/\351\223\201\347\224\267\347\245\236sama.md" "b/2018.11.28-leetcode151/\351\223\201\347\224\267\347\245\236sama.md"
new file mode 100644
index 000000000..0e6e6d6d6
--- /dev/null
+++ "b/2018.11.28-leetcode151/\351\223\201\347\224\267\347\245\236sama.md"
@@ -0,0 +1,58 @@
+
+```java
+public class Solution {
+ public String reverseWords(String s) {
+ StringBuilder sb = new StringBuilder();
+ String[] sArray=new StringBuilder(s).reverse().toString().split(" ");
+ for(int i=0;i 0 && chars[i] != chars[i - 1])) {
+ String count = i - end == 1 ? "" : (i - end) + "";
+ chars[length++] = chars[i - 1];
+ for (int j = 0; j < count.length(); j++) {
+ chars[length++] = count.charAt(j);
+ }
+ end = i;
+ }
+ }
+ String count = chars.length - end == 1 ? "" : (chars.length - end) + "";
+ chars[length++] = chars[chars.length - 1];
+ for (int j = 0; j < count.length(); j++) {
+ chars[length++] = count.charAt(j);
+ }
+ return length;
+ }
+}
diff --git a/2018.11.29-leetcode443/Avalon.md b/2018.11.29-leetcode443/Avalon.md
new file mode 100644
index 000000000..7fe154533
--- /dev/null
+++ b/2018.11.29-leetcode443/Avalon.md
@@ -0,0 +1,17 @@
+public static int compress(char[] chars) {
+ Map map = new LinkedHashMap();
+ int len = chars.length;
+ for (int i = 0; i entry : map.entrySet()) {
+ num++;
+ if (!entry.getValue().equals("1")){
+ num += entry.getValue().toCharArray().length ;
+ }
+ }
+ return num;
+ }
diff --git a/2018.11.29-leetcode443/Be a fresh man.md b/2018.11.29-leetcode443/Be a fresh man.md
new file mode 100644
index 000000000..722cd778a
--- /dev/null
+++ b/2018.11.29-leetcode443/Be a fresh man.md
@@ -0,0 +1,104 @@
+## 443_(压缩字符串)String Compression
+## 1 问题描述、输入输出与样例
+### 1.1 问题描述
+给定一组字符,使用原地算法将其压缩。
+压缩后的长度必须始终小于或等于原数组长度。
+数组的每个元素应该是长度为1 的字符(不是 int 整数类型)。
+在完成原地修改输入数组后,返回数组的新长度。
+__注意__:
+所有字符都有一个ASCII值在[35, 126]区间内。
+1 <= len(chars) <= 1000。
+### 1.2 输入与输出
+输入:
+* vector& chars:输入的字符列表
+
+输出:
+* int:原地压缩后的字符串的列表长度
+### 1.3 样例
+#### 1.3.1 样例1
+输入:
+["a","a","b","b","c","c","c"]
+输出:
+返回6,输入数组的前6个字符应该是:["a","2","b","2","c","3"]
+说明:
+"aa"被"a2"替代。"bb"被"b2"替代。"ccc"被"c3"替代。
+#### 1.3.2 样例2
+输入:
+["a"]
+输出:
+返回1,输入数组的前1个字符应该是:["a"]
+说明:
+没有任何字符串被替代。
+#### 1.3.3 样例2
+输入:
+["a","b","b","b","b","b","b","b","b","b","b","b","b"]
+输出:
+返回4,输入数组的前4个字符应该是:["a","b","1","2"]。
+说明:
+由于字符"a"不重复,所以不会被压缩。"bbbbbbbbbbbb"被“b12”替代。
+注意每个数字在数组中都有它自己的位置。
+
+## 2 思路描述与代码
+### 2.1 思路描述(计数方法)
+思路很清晰,这里就不举例了,思路采用计数方法。
+start 记录当前搜索字符的起始下标, search 记录当前搜索字符的遍历下标 , cnt_same_char 记录当前搜索字符的相同长度
+cmpr_len_char 记录当前压缩了的字符串的长度, len 记录输入字符串的长度
+```cpp
+while( search < len ){
+ if(当前字符和前一个字符相同) cnt_same_char++;
+ else{
+ 记录当前单词和数目
+ start = search;
+ cnt_same_char = 1;
+ }
+ search++;
+}
+```
+### 2.2 代码
+```cpp
+int compress(vector& chars) {
+ //强行添加空格方便统一处理
+ chars.push_back(' ');
+ int len = chars.size();
+ int start = 0, search = 1;
+ int cnt_same_char = 1, cmpr_len_char = 0;
+ while( search < len ){
+ if(chars[search] == chars[search - 1]) ++cnt_same_char;
+ else{
+ chars[cmpr_len_char++] = chars[start];
+ //当前char计数值大于1时才压缩
+ if(cnt_same_char > 1){
+ //整形转字符串
+ //从高位往低位转 遇见最高位后flag = 1;
+ int flag = 0;
+ int msb = 1000, cnt2char = cnt_same_char;
+ for( int i = 0; i < 4; i++ ){
+ int weight = cnt2char / msb;
+ if(weight > 0 || flag) flag = 1, chars[cmpr_len_char++] = weight + '0';
+ cnt2char = cnt2char % msb;
+ msb = msb / 10;
+ }
+ }
+ start = search;
+ cnt_same_char = 1;
+ }
+ search++;
+ }
+ //去除空格,恢复原始数据
+ chars.pop_back();
+ return cmpr_len_char;
+}
+```
+## 3 思考与拓展
+### 3.1 思考
+#### 3.1.1 其他方法
+无。
+#### 3.1.2 复杂度分析
+方法|空间复杂度|时间复杂度
+--- | --- | ---
+计数方法|O(1)|O(n)
+#### 3.1.3 难点分析
+1. 原地修改
+2. 整形数据转字符串
+### 3.2 拓展
+如果给你的数链表数据呢?
diff --git a/2018.11.29-leetcode443/Decadence.md b/2018.11.29-leetcode443/Decadence.md
new file mode 100644
index 000000000..edef5f25b
--- /dev/null
+++ b/2018.11.29-leetcode443/Decadence.md
@@ -0,0 +1,67 @@
+题目地址:https://leetcode-cn.com/problems/string-compression/
+
+leetcode 443
+给定一组字符,使用原地算法将其压缩。压缩后的长度必须始终小于或等于原数组长度。数组的每个元素应该是长度为1 的字符
+(不是 int 整数类型)。在完成原地修改输入数组后,返回数组的新长度。
+进阶:
+你能否仅使用O(1) 空间解决问题?
+
+示例 1:
+输入:
+["a","a","b","b","c","c","c"]
+输出:
+返回6,输入数组的前6个字符应该是:["a","2","b","2","c","3"]
+说明:
+"aa"被"a2"替代。"bb"被"b2"替代。"ccc"被"c3"替代。
+
+示例 2:
+输入:
+["a"]
+输出:
+返回1,输入数组的前1个字符应该是:["a"]
+说明:
+没有任何字符串被替代。
+
+示例 3:
+输入:
+["a","b","b","b","b","b","b","b","b","b","b","b","b"]
+输出:
+返回4,输入数组的前4个字符应该是:["a","b","1","2"]。
+说明:
+由于字符"a"不重复,所以不会被压缩。"bbbbbbbbbbbb"被“b12”替代。
+注意每个数字在数组中都有它自己的位置。
+
+注意:
+
+ 所有字符都有一个ASCII值在[35, 126]区间内。
+ 1 <= len(chars) <= 1000。
+
+
+```$java
+class Solution{
+ public int compress(char[] chars){
+ int n = chars.length;
+ int cur = 0;
+ for(int i =0;i 1) {
+ String a = String.valueOf(count);
+ for (int k = 0; k < a.length(); k++) {
+ chars[index++] = a.charAt(k);
+ }
+ }
+ count = 1;
+ } else {
+ count++;
+ }
+ }
+ return index;
+ }
+}
diff --git a/2018.11.29-leetcode443/GatesMa.md b/2018.11.29-leetcode443/GatesMa.md
new file mode 100644
index 000000000..9a007d878
--- /dev/null
+++ b/2018.11.29-leetcode443/GatesMa.md
@@ -0,0 +1,47 @@
+# c++11
+```cpp
+class Solution {
+public:
+ int compress(vector& chars) {
+ vector c;
+ int num = 1;
+ string s;
+ char ch = chars[0];
+ if(chars.size() == 1){
+ return num;
+ }
+ for(vector::iterator it = chars.begin()+1;it != chars.end(); it++){
+ if(ch != *it){
+ c.push_back(ch);
+ if(num != 1){
+ stringstream ss;
+ ss << num;
+ ss >> s;
+ int len = s.length();
+ for(int i =0;i> s;
+ int len = s.length();
+
+ for(int i =0;i chars){
+ int count=0;
+ char c1;
+ char c2;
+ for (int i = 0; i < chars.size()-1; i++) {
+ c1=chars.get(i);
+ count++;
+ c2=chars.get(i+1);
+ if(c1==c2){
+ chars.remove(i);
+ i--;
+ }else{//不相等
+ if(count>1){//添加新元素,如:'1','5'等
+ if(count<10){
+ }else if(count>=10&&count<100){
+ chars.add(i+1,(char) (count/10%10+48));
+ }else if(count>=100&&count<1000){
+ chars.add(i+1,(char) (count/100+48));
+ chars.add(i+1,(char) (count/10%10+48));
+ }else if(count>=1000&&count<10000){
+ chars.add(++i,(char) (count/1000+48));
+ System.out.println(chars.get(i+1));
+ chars.add(++i,(char) (count/100%10+48));
+ chars.add(++i,(char) (count/10%10+48));
+ }
+ chars.add(i+1,(char) (count%10+48));
+ }
+ count=0;
+ }
+ }
+ count++;
+ if(count>1){
+ if(count<10){
+ }else if(count>=10&&count<100){
+ chars.add((char) (count/10%10+48));
+ }else if(count>=100&&count<1000){
+ chars.add((char) (count/100+48));
+ chars.add((char) (count/10%10+48));
+ }else if(count>=1000&&count<10000){
+ chars.add((char) (count/1000+48));
+ chars.add((char) (count/100%10+48));
+ chars.add((char) (count/10%10+48));
+ }
+ chars.add((char) (count%10+48));
+ count=0;
+ }
+ System.out.println(chars);
+ return chars.size();
+ }
+
+ //测试运行
+ public static void main(String[] args) {
+ char[] c = new char[1200];
+ c[0]='a';
+ c[1]='c';
+ c[2]='c';
+ for (int i = 3; i < 1198; i++) {
+ c[i]='g';
+ }
+ c[1198]='c';
+ c[1199]='c';
+ Vector chars= new Vector<>();
+ for (int i = 0; i < c.length; i++) {
+ chars.add(c[i]);
+ }
+ int n= compress(chars);
+ System.out.println("新数组长度:"+n);
+ }
+ }
diff --git a/2018.11.29-leetcode443/Istoryforever.md b/2018.11.29-leetcode443/Istoryforever.md
new file mode 100644
index 000000000..41f3dbf6b
--- /dev/null
+++ b/2018.11.29-leetcode443/Istoryforever.md
@@ -0,0 +1,32 @@
+//Leetcode of 443
+class Solution {
+public:
+ int compress(vector& chars) {
+ stringstream s;
+ int count = 1;
+ // chars.push_back(0);
+ for(int i = 0;i < chars.size();i++){
+
+ if(i == 0){
+ s<1){
+ char[] num = String.valueOf((i-index)).toCharArray();
+ for (int j=0;j& chars) {
+ int len = chars.size();
+ if(len == 1) return chars.size();
+ chars.push_back(' ');//统一一下
+ len++;
+ int cnt = 1;
+ char pre = ' ';
+ pre = chars[0];
+ for(int i = 1; i < len; i++){
+ if(chars[i] == pre){
+ chars.erase(chars.begin()+i);
+ i--;
+ len--;
+ cnt++;
+ } else if(cnt>1){
+ stringstream ss;
+ string s;
+ ss<>s;
+ pre=chars[i];
+ for(int j = 0; j < s.size(); j++){
+ chars.insert(chars.begin()+i,s[j]);
+ i++;
+ len++;
+ }
+ cnt=1;
+ }
+ pre = chars[i];
+ }
+ chars.pop_back();//最后去除
+ return chars.size();
+ }
+};
+```
diff --git a/2018.11.29-leetcode443/Sagittarius.md b/2018.11.29-leetcode443/Sagittarius.md
new file mode 100644
index 000000000..09d701296
--- /dev/null
+++ b/2018.11.29-leetcode443/Sagittarius.md
@@ -0,0 +1,26 @@
+```
+class Solution {
+public:
+ int compress(vector& chars) {
+ int count=0;
+ int index=0;
+ for(int i=0;i 1) {
+ for (char c : Integer.toString(cnt).toCharArray()) {
+ chars[n++] = c;
+ }
+ }
+ }
+ return n;
+ }
+}
+```
diff --git a/2018.11.29-leetcode443/Tony the Cyclist.md b/2018.11.29-leetcode443/Tony the Cyclist.md
new file mode 100644
index 000000000..3d97ffca1
--- /dev/null
+++ b/2018.11.29-leetcode443/Tony the Cyclist.md
@@ -0,0 +1,43 @@
+```
+class Solution {
+ public int compress(char[] chars) {
+ char base = chars[0];
+ int count = 1;
+ int pos = 0;
+ for (int i = 1; i < chars.length; i++){
+ if (base != chars[i]){
+ base = chars[i];
+ if (count == 1){
+ chars[++pos] = base;
+ continue;
+ }
+ // 先计数再写入下一个值
+ for (int j = 0; j < String.valueOf(count).length(); j++){
+ chars[++pos] = String.valueOf(count).charAt(j);
+ }
+ count = 1;
+ chars[++pos] = base;
+ }
+ else {// base == chars[i]
+ count ++;
+ if (i == chars.length-1){
+ if (count == 1){
+ continue;
+ }
+ for (int j = 0; j < String.valueOf(count).length(); j++){
+ chars[++pos] = String.valueOf(count).charAt(j);
+ }
+
+ }
+
+ }
+
+ }
+ pos++;
+ //splitArray(chars, pos);
+ if (pos == 0)
+ return 1;
+ return pos;
+}
+}
+```
diff --git a/2018.11.29-leetcode443/WhiteNight.md b/2018.11.29-leetcode443/WhiteNight.md
new file mode 100644
index 000000000..77f64850c
--- /dev/null
+++ b/2018.11.29-leetcode443/WhiteNight.md
@@ -0,0 +1,41 @@
+```java
+/**
+ * 压缩字符串
+ *
+ */
+public class S3 {
+ public int compress(char[] chars) {
+ int count = 1;
+ int index = 0;
+
+ for (int i = 0; i < chars.length; i++) {
+ if (i + 1 == chars.length || chars[i] != chars[i+1]){
+ chars[index++] = chars[i];
+ if (count > 1){
+ String temp = String.valueOf(count);
+ for (int j = 0; j < temp.length(); j++) {
+ chars[index++] = temp.charAt(j);
+ }
+ }
+ count = 1;
+ }
+ else
+ count++;
+ }
+
+ return index;
+ }
+
+ public static void main(String[] args) {
+ S3 s = new S3();
+ char[] chars = {'a','b','b','b','b','b','b','b','b','b','b','b'};
+ int res = s.compress(chars);
+ System.out.println(res);
+
+ for (int i = 0; i < chars.length; i++) {
+ System.out.print(chars[i] + " ");
+ }
+ }
+}
+```
+
diff --git a/2018.11.29-leetcode443/halfofwater.md b/2018.11.29-leetcode443/halfofwater.md
new file mode 100644
index 000000000..ab5d26b52
--- /dev/null
+++ b/2018.11.29-leetcode443/halfofwater.md
@@ -0,0 +1,59 @@
+## Leetcode 443
+
+```
+class Solution {
+public:
+ int compress(vector& chars) {
+
+ if (chars.size() <= 1) return chars.size();
+
+ vector::iterator it = chars.begin();
+ ++it;
+ int count = 1;
+ char tmp = chars[0];
+
+ char ccc = *(chars.end() - 1);
+ while (it < chars.end())
+ {
+ if (*it == tmp)
+ {
+
+ ++count;
+ if (it == chars.end() - 1) {
+ if (count != 1) {
+
+ string s = to_string(count);
+ for (char c : s) {
+ it = chars.insert(it, c);
+ ++it;
+ }
+ it = chars.erase(it);
+ }
+ //++it;
+ }
+ else {
+ it = chars.erase(it);
+ }
+ }
+ else
+ {
+ if (count != 1)
+ {
+ string s = to_string(count);
+ for (char c : s)
+ {
+ it = chars.insert(it, c);
+ ++it;
+ }
+ }
+
+ tmp = *it;
+ count = 1;
+ ++it;
+ }
+ }
+ return chars.size();
+ }
+};
+
+```
diff --git a/2018.11.29-leetcode443/kiritocly.md b/2018.11.29-leetcode443/kiritocly.md
new file mode 100644
index 000000000..9ed7a4ca1
--- /dev/null
+++ b/2018.11.29-leetcode443/kiritocly.md
@@ -0,0 +1,31 @@
+ private static int solution(char[] charArray) {
+ if (charArray.length == 0) {
+ return 0;
+ }
+ //遍历整个字符数组
+ //压缩后的字符长度
+ int resultCount = 0;
+ //当前重复字符计数
+ int count = 1;
+ for (int i = 0; i < charArray.length; i++) {
+ //如果遇到某个字符与当前字符不相等或者已经遍历到最后一个字符
+ if (i + 1 == charArray.length || charArray[i] != charArray[i + 1]) {
+ //记录一下当前字符,并且resultCount加1,比如a,a,b,b,b,扫面到第二个a时
+ //a!=b,如果a的个数大于1,先将a后面所有的a替换为数字,如a,a替换为a,2
+ charArray[resultCount++] = charArray[i];
+ if (count > 1) {
+ String temp = String.valueOf(count);
+ for (int k = 0; k < temp.length(); k++) {
+ charArray[resultCount++] = temp.charAt(k);
+ }
+ }
+ //重新统计下一个字符
+ count = 1;
+ } else {
+ //统计重复的字符个数
+ count++;
+ }
+
+ }
+ return resultCount;
+ }
diff --git a/2018.11.29-leetcode443/oven123.md b/2018.11.29-leetcode443/oven123.md
new file mode 100644
index 000000000..c3db542ca
--- /dev/null
+++ b/2018.11.29-leetcode443/oven123.md
@@ -0,0 +1,28 @@
+```java
+class Solution {
+ public int compress(char[] chars) {
+ int start = 0;
+ int end = 0;
+ //定义两指示字符的标识符
+ for(int i = 0;i < chars.length;i++){
+ if(i==chars.length-1||chars[i+1] != chars[i]){//如果不同或遍历到最后一个
+ chars[start] = chars[end];//在前一个字符计数后记录字母
+ start++;
+ if(end < i){//当前指示位置与遍历位置不一致
+ int sum = i-end+1;//对重复计数
+ if(sum < 10){
+ chars[start++] =(char)(sum+ '0');
+ }else{
+ chars[start++]=(char)(sum/10+ '0');
+ chars[start] = (char)(sum % 10+ '0');
+ start++;
+ }
+ }
+ end = i + 1;//保证遍历位置与标记位置相同
+ }
+ }
+ return start;
+
+ }
+}
+```
diff --git a/2018.11.29-leetcode443/sourcema.md b/2018.11.29-leetcode443/sourcema.md
new file mode 100644
index 000000000..d52759317
--- /dev/null
+++ b/2018.11.29-leetcode443/sourcema.md
@@ -0,0 +1,29 @@
+# LeetCode 443
+ class Solution {
+ public int compress(char[] chars) {
+ if (chars == null || chars.length == 0) {
+ return 0;
+ }
+ StringBuilder sb = new StringBuilder();
+ int num=1;
+ for (int i = 0,j=0; i =s.length()?0:s.charAt(i);
+ }
+ return sb.toString().length();
+ }
+}
diff --git a/2018.11.29-leetcode443/str818.md b/2018.11.29-leetcode443/str818.md
new file mode 100644
index 000000000..d49d6e855
--- /dev/null
+++ b/2018.11.29-leetcode443/str818.md
@@ -0,0 +1,64 @@
+# 压缩字符串
+
+【 [英文练习](https://leetcode.com/problems/string-compression/description/) | [中文练习](https://leetcode-cn.com/problems/string-compression/description/) 】
+
+**题目描述:** 给定一组字符,使用原地算法将其压缩。压缩后的长度必须始终小于或等于原数组长度,数组的每个元素应该是长度为 1 的字符(不是 int 整数类型),在完成原地修改输入数组后,返回数组的新长度。
+
+**示例 1:**
+```
+输入:
+["a","a","b","b","c","c","c"]
+
+输出:
+返回6,输入数组的前6个字符应该是:["a","2","b","2","c","3"]
+
+说明:
+"aa"被"a2"替代。"bb"被"b2"替代。"ccc"被"c3"替代。
+```
+**示例 2:**
+```
+输入:
+["a"]
+
+输出:
+返回1,输入数组的前1个字符应该是:["a"]
+
+说明:
+没有任何字符串被替代。
+```
+**示例 3:**
+```
+输入:
+["a","b","b","b","b","b","b","b","b","b","b","b","b"]
+
+输出:
+返回4,输入数组的前4个字符应该是:["a","b","1","2"]。
+
+说明:
+由于字符"a"不重复,所以不会被压缩。"bbbbbbbbbbbb"被“b12”替代。
+注意每个数字在数组中都有它自己的位置。
+```
+
+**说明:**
+* 所有字符都有一个ASCII值在[35, 126]区间内。
+* 1 <= len(chars) <= 1000。
+
+**解题思路:** 用双指针的思想,一个指针从前向后读字符,一个指针从前向后写字符,再通过一个指针记录相同字符序列中的第一个字符下标,用来计算相同字符的数量。
+
+```java
+public int compress(char[] chars) {
+ int anchor = 0, write = 0;
+ for (int read = 0; read < chars.length; read++) {
+ if (read + 1 == chars.length || chars[read + 1] != chars[read]) {
+ chars[write++] = chars[anchor];
+ if (read > anchor) {
+ for (char c: ("" + (read - anchor + 1)).toCharArray()) {
+ chars[write++] = c;
+ }
+ }
+ anchor = read + 1;
+ }
+ }
+ return write;
+}
+```
diff --git a/2018.11.29-leetcode443/syuan.md b/2018.11.29-leetcode443/syuan.md
new file mode 100644
index 000000000..a1dc97366
--- /dev/null
+++ b/2018.11.29-leetcode443/syuan.md
@@ -0,0 +1,79 @@
+##### 题目
+```
+给定一组字符,使用原地算法将其压缩。
+
+压缩后的长度必须始终小于或等于原数组长度。
+
+数组的每个元素应该是长度为1 的字符(不是 int 整数类型)。
+
+在完成原地修改输入数组后,返回数组的新长度。
+```
+##### 思路
+设置两个指针i 和 j
+i是赋值指针
+j用来统计每次字符出现的次数
+
+**难点**
+当次数为两位数时的写入
+
+```
+char[] temArray=String.valueOf(count).toCharArray();
+int k=0;
+while (k& chars) {
+ int N = chars.size();
+ int idx = 0, cnt = 0;
+
+ for(int i = 0; i < N; ++i) {
+ cnt++;
+ if (i == N-1 || chars[i] != chars[i+1]) {
+ chars[idx++] = chars[i];
+ if (cnt > 1) {
+ for(auto c : to_string(cnt))
+ chars[idx++] = c;
+ }
+ cnt = 0;
+ }
+ }
+ return idx;
+ }
+};
+```
diff --git "a/2018.11.29-leetcode443/\343\200\201Mr\343\200\202oh\357\274\201.md" "b/2018.11.29-leetcode443/\343\200\201Mr\343\200\202oh\357\274\201.md"
new file mode 100644
index 000000000..80c178869
--- /dev/null
+++ "b/2018.11.29-leetcode443/\343\200\201Mr\343\200\202oh\357\274\201.md"
@@ -0,0 +1,32 @@
+public int compress(char[] chars) {
+ if (chars == null || chars.length == 0) {
+ return 0;
+ }
+ int count = 1;
+ char pre = chars[0];
+ StringBuilder sb = new StringBuilder();
+
+ for (int i = 1; i < chars.length; i++) {
+ if (pre == chars[i]) {
+ count++;
+ }else {
+ if (count > 1) {
+ sb.append(pre);
+ sb.append(count);
+ } else if (count == 1) {
+ sb.append(pre);
+ }
+ pre = chars[i];
+ count = 1;
+ }
+ }
+ sb.append(pre);
+ if (count > 1) {
+ sb.append(count);
+ }
+ int i=0;
+ for (char c : sb.toString().toCharArray()) {
+ chars[i++] = c;
+ }
+ return sb.length();
+ }
diff --git "a/2018.11.29-leetcode443/\343\200\202V1ncentzzZ.md" "b/2018.11.29-leetcode443/\343\200\202V1ncentzzZ.md"
new file mode 100644
index 000000000..78b99e3a8
--- /dev/null
+++ "b/2018.11.29-leetcode443/\343\200\202V1ncentzzZ.md"
@@ -0,0 +1,30 @@
+ // TODO 执行比较慢,有冗余代码,待优化 7ms
+ public int compress(char[] chars) {
+ if(chars.length == 0) return 0;
+ char temp = chars[0];
+ int count = 0;
+ int len = 0;
+ for(int i=0; i 1){
+ char[] step = String.valueOf(count).toCharArray();
+ chars[len++] = step[0];
+ if(count > 9) chars[len++] = step[1];
+ }
+ temp = chars[i];
+ count = 1;
+ }
+ if(i == chars.length - 1) {
+ chars[len++] = temp;
+ if(count > 1){
+ char[] step = String.valueOf(count).toCharArray();
+ chars[len++] = step[0];
+ if(count > 9) chars[len++] = step[1];
+ }
+ continue;
+ }
+ }
+ return len;
+ }
diff --git "a/2018.11.29-leetcode443/\343\200\202\343\200\202\343\200\202.md" "b/2018.11.29-leetcode443/\343\200\202\343\200\202\343\200\202.md"
new file mode 100644
index 000000000..21feabaf2
--- /dev/null
+++ "b/2018.11.29-leetcode443/\343\200\202\343\200\202\343\200\202.md"
@@ -0,0 +1,28 @@
+ ```
+ public int compress(char[] chars) {
+ int cur = 1;//压缩后字符串的长度
+ int repet = 1;
+ for (int i = 1; i < chars.length; i++){
+ if (chars[i-1] == chars[i]) {//出现连续重复的字符串
+ repet++;
+ }else {
+ if (repet!=1){
+ char[] num = String.valueOf(repet).toCharArray();
+ for (int j = 0; j < num.length; j++){
+ chars[cur++] = num[j];
+ }
+ repet=1;
+ }
+ chars[cur++] = chars[i];
+ }
+ }
+ if (repet!=1){
+ char[] num = String.valueOf(repet).toCharArray();
+ for (int j = 0; j < num.length; j++){
+ chars[cur++] = num[j];
+ }
+ }
+ Log.d(new String(chars));
+ return cur;
+ }
+ ```
diff --git "a/2018.11.29-leetcode443/\344\270\200\346\260\247\345\214\226\344\272\214\351\222\222.md" "b/2018.11.29-leetcode443/\344\270\200\346\260\247\345\214\226\344\272\214\351\222\222.md"
new file mode 100644
index 000000000..dc22f2444
--- /dev/null
+++ "b/2018.11.29-leetcode443/\344\270\200\346\260\247\345\214\226\344\272\214\351\222\222.md"
@@ -0,0 +1,27 @@
+
+class Solution(object):
+ def compress(self, chars):
+ """
+ :type chars: List[str]
+ :rtype: int
+ """
+
+ n = len(chars)
+ cnt = 1;
+ i = 0;
+ for j in range(1, len(chars)+1):
+ if j < n and chars[j-1] == chars[j]:
+ cnt += 1;
+ else:
+ chars[i] = chars[j-1];
+ i += 1;
+ if cnt > 1:
+ for m in str(cnt):
+ chars[i] = m;
+ i += 1;
+ cnt = 1;
+ return i;
+
+
+
+
diff --git "a/2018.11.29-leetcode443/\345\244\247\351\255\224\347\216\213\347\210\261\347\251\277\345\255\226\347\203\237\347\255\222.md" "b/2018.11.29-leetcode443/\345\244\247\351\255\224\347\216\213\347\210\261\347\251\277\345\255\226\347\203\237\347\255\222.md"
new file mode 100644
index 000000000..dcc87c6d0
--- /dev/null
+++ "b/2018.11.29-leetcode443/\345\244\247\351\255\224\347\216\213\347\210\261\347\251\277\345\255\226\347\203\237\347\255\222.md"
@@ -0,0 +1,23 @@
+```
+class Solution {
+ public int compress(char[] chars) {//思路有一点,写的时候就缺胳膊少腿,又来模仿群主代码
+ int count = 1;
+ int index = 0;
+ for (int i = 0; i < chars.length; i++) {
+ if (i + 1 == chars.length || chars[i] != chars[i+1]) {
+ chars[index++] = chars[i];//前后不同直接添加
+ if (count > 1) {
+ String temp = String.valueOf(count);//转换成字符串,也可以变成字符数组,然后遍历。
+ for(int k=0;k& chars) {
+ int n = chars.size(), char1 = 0;
+ for (int i = 0, j = 0; i < n; i = j) {
+ while (j < n && chars[j] == chars[i])
+ ++j;
+ chars[char1++] = chars[i];
+ if (j - i == 1) continue;
+ for (char c : to_string(j - i)) //个数
+ chars[char1++] = c;
+ }
+ return char1;
+ }
+};
diff --git "a/2018.11.29-leetcode443/\346\210\221\347\210\261\345\220\203\347\223\234\345\255\220.md" "b/2018.11.29-leetcode443/\346\210\221\347\210\261\345\220\203\347\223\234\345\255\220.md"
new file mode 100644
index 000000000..f478a185b
--- /dev/null
+++ "b/2018.11.29-leetcode443/\346\210\221\347\210\261\345\220\203\347\223\234\345\255\220.md"
@@ -0,0 +1,37 @@
+#leetcode 443
+、、、
+class Solution {
+ public int compress(char[] chars) {
+ int count =1;
+ int index= 0;
+ for(int i=0;i1){
+ //int转为String
+ String temp =String.valueOf(count);
+
+ //将数量赋值到结果数组中
+ for(int z=0;z1){
+ char[] num = String.valueOf((i-index)).toCharArray();
+ for (int j=0;j 1) {
+ char[] chs = String.valueOf(times).toCharArray();
+ for (int j = 0; j < chs.length; j++) {
+ chars[index++] = chs[j];
+ }
+ }
+ }
+ return index;
+}
diff --git "a/2018.11.29-leetcode443/\347\245\236\347\247\230\347\232\204\347\201\253\346\237\264\344\272\272.md" "b/2018.11.29-leetcode443/\347\245\236\347\247\230\347\232\204\347\201\253\346\237\264\344\272\272.md"
new file mode 100644
index 000000000..8c057091f
--- /dev/null
+++ "b/2018.11.29-leetcode443/\347\245\236\347\247\230\347\232\204\347\201\253\346\237\264\344\272\272.md"
@@ -0,0 +1,63 @@
+...
+class Solution {
+public:
+ int compress(vector& chars) {
+ int size = chars.size();
+ int ret = 0;
+
+ int num = 1;
+ int cur = 0;
+ while(cur+1 1)
+ {
+ stack s;
+ while(num != 0)
+ {
+ s.push(num%10+'0');
+ num /= 10;
+ }
+
+ while(!s.empty())
+ {
+ chars[ret++] = s.top();
+ s.pop();
+ }
+
+ }
+ num = 1;
+ }
+
+ cur++;
+ }
+
+ chars[ret++] = chars[cur];
+ if(num > 1)
+ {
+ stack s;
+ while(num != 0)
+ {
+ s.push(num%10+'0');
+ num /= 10;
+ }
+
+ while(!s.empty())
+ {
+ chars[ret++] = s.top();
+ s.pop();
+ }
+
+ }
+
+
+ chars.resize(ret);
+ return ret;
+ }
+};
+...
diff --git a/2018.11.30-leetcode890/-.md b/2018.11.30-leetcode890/-.md
new file mode 100644
index 000000000..ffa55dedd
--- /dev/null
+++ b/2018.11.30-leetcode890/-.md
@@ -0,0 +1,28 @@
+class Solution {
+ public List findAndReplacePattern(String[] words, String pattern) {
+ List result = new ArrayList<>();
+ for (String str : words) {
+ if (str.length() != pattern.length()) {
+ continue;
+ }
+ Map map = new HashMap();
+ for (int i = 0; i < str.length(); i++) {
+ Character c = map.get(str.charAt(i));
+ if (c == null) {
+ if (map.containsValue(pattern.charAt(i))) {
+ break;
+ }
+ map.put(str.charAt(i), pattern.charAt(i));
+ } else if (!c.equals(pattern.charAt(i))) {
+ break;
+ }
+ if (i == str.length() - 1) {
+ result.add(str);
+ }
+ }
+ // System.out.println(map);
+
+ }
+ return result;
+ }
+}
diff --git a/2018.11.30-leetcode890/Avalon.md b/2018.11.30-leetcode890/Avalon.md
new file mode 100644
index 000000000..7813ee0cc
--- /dev/null
+++ b/2018.11.30-leetcode890/Avalon.md
@@ -0,0 +1,31 @@
+class Solution {
+ public List findAndReplacePattern(String[] words, String pattern) {
+ List wlist = new ArrayList<>();
+ int len = words.length;
+ String template = getTemplate(pattern);
+ for (int i=0;i cl = new ArrayList<>();
+ String result="";
+ int len = cs.length;
+ for (int i=0;i
+如果存在字母的排列 p ,使得将模式中的每个字母 x 替换为 p(x) 之后,我们就得到了所需的单词,那么单词与模式是匹配的。
+(回想一下,字母的排列是从字母到字母的双射:每个字母映射到另一个字母,没有两个字母映射到同一个字母。)
+返回 words 中与给定模式匹配的单词列表。
+你可以按任何顺序返回答案。
+__提示__:
+1. 1 <= words.length <= 50
+2. 1 <= pattern.length = words[i].length <= 20
+### 1.2 输入与输出
+输入:
+* vector& words:给定的单词列表
+* string pattern:模式单词
+输出:
+* vector:与给定模式匹配的单词列表
+
+### 1.3 样例
+#### 1.3.1 样例1
+输入:
+words = ["abc","deq","mee","aqq","dkd","ccc"], pattern = "abb"
+
+输出:
+["mee","aqq"]
+
+解释:
+"mee" 与模式匹配,因为存在排列 {a -> m, b -> e, ...}。
+"ccc" 与模式不匹配,因为 {a -> c, b -> c, ...} 不是排列。
+因为 a 和 b 映射到同一个字母。
+## 2 思路描述与代码
+### 2.1 思路描述(双字典方法)
+对每个属于单词列表words的单词word,使用dict1 记录 word 中的字符 word[i] 对 pattern 字符 pattern[i] 的映射
+使用dict2 记录 pattern 中的字符 pattern[i] 对 word 字符 word[i] 的映射
+```cpp
+for(word in words){
+ 初始化字典映射;
+ for(word[i] in word){
+ if(word[i] 未被映射)
+ if(pattern[i] 未被映射) 双方记录映射关系;
+ else 确认 pattern[i] 映射的对象是不是 word[i],如果不是则失败;
+ if(word[i] 已被映射 且 映射对象不是 pattern[i]) 则失败;
+ }
+ 如果成功,记录word;
+}
+```
+
+### 2.2 代码
+```cpp
+vector findAndReplacePattern(vector& words, string pattern) {
+ vector ans;
+ for( auto word : words ){
+ // dict1 记录 word 中的字符对 pattern 字符的映射
+ // dict2 记录 pattern 中的字符对 word 字符的映射
+ vector dict1(127, -1);
+ vector dict2(127, -1);
+ int word_len = word.size();
+ int fail = 0;
+ for( int i = 0; i < word_len; i++ ){
+ // 如果 word[i] 未被映射
+ // (i) 如果 pattern[i] 未被映射,双方记录映射关系
+ // (ii) 如果 pattern[i] 已被映射,确认 pattern[i] 映射的对象是不是 word[i],如果不是则失败
+ if(dict1[word[i]] == -1){
+ if(dict2[pattern[i]] == -1){
+ dict1[word[i]] = pattern[i];
+ dict2[pattern[i]] = word[i];
+ }
+ else if(dict2[pattern[i]] != word[i]){
+ fail = 1;
+ break ;
+ }
+ }
+ // 如果 word[i] 已被映射 且 映射对象不是 pattern[i],则失败
+ else if(dict1[word[i]] != -1 && dict1[word[i]] != pattern[i]){
+ fail = 1;
+ break ;
+ }
+ }
+ //如果成功,记录word
+ if(!fail) ans.push_back(word);
+ }
+ return ans;
+ }
+```
+## 3 思考与拓展
+### 3.1 思考
+#### 3.1.1 其他方法
+无。
+#### 3.1.2 复杂度分析
+方法|空间复杂度|时间复杂度
+--- | --- | ---
+双字典方法|O(1)|O(kn),k为word的长度,n为words的数目
+#### 3.1.3 难点分析
+1. 如何记录二者的映射关系;
+2. 如何分辨映射存在一对多、多对一和多对多情况的出现。
+
+### 3.1 扩展
+本题需要使用两个字典记录映射关系,不然可能导致一对多或者多对一情况。
+
diff --git a/2018.11.30-leetcode890/GatesMa.md b/2018.11.30-leetcode890/GatesMa.md
new file mode 100644
index 000000000..f9107c1cb
--- /dev/null
+++ b/2018.11.30-leetcode890/GatesMa.md
@@ -0,0 +1,25 @@
+# C++
+```
+class Solution {
+public:
+ bool strMatch(string str, string pattern){
+ int len = str.length();
+ for(int i=0;i < len;i++){
+ for(int j=i+1;j < len;j++){
+ if((str[i] == str[j]) && (pattern[i] != pattern[j])) return false;
+ if((str[i] != str[j]) && (pattern[i] == pattern[j])) return false;
+ }
+ }
+ return true;
+ }
+ vector findAndReplacePattern(vector& words, string pattern) {
+ vector set;
+ for(int i=0;i < words.size();i++){
+ if(strMatch(words[i], pattern)){
+ set.push_back(words[i]);
+ }
+ }
+ return set;
+ }
+};
+```
diff --git a/2018.11.30-leetcode890/Istoryforever.md b/2018.11.30-leetcode890/Istoryforever.md
new file mode 100644
index 000000000..4538e31e2
--- /dev/null
+++ b/2018.11.30-leetcode890/Istoryforever.md
@@ -0,0 +1,39 @@
+//Leetcode of 890
+class Solution {
+public:
+ bool match(string str,string p){
+ map m;
+ for(int i=0;i::iterator iter=m.find(str[i]);
+ if(iter==m.end()){
+ m[str[i]]=p[i];
+ continue;
+ }else{
+ if(iter->second!=p[i])
+ return false;
+ }
+ }
+ int seen[27];
+ for(int i=0;i<27;i++)seen[i]=0;
+ for(map::iterator i=m.begin();i!=m.end();i++){
+ if(!seen[i->second-'a']){
+ seen[i->second-'a']=1;
+ }else{
+ return false;
+ }
+ }
+ return true;
+ }
+ vector findAndReplacePattern(vector& words, string pattern) {
+ vector res;
+ for(vector::iterator i=words.begin();i!=words.end();i++){
+
+ if(match(*i,pattern)){
+ res.push_back(*i);
+ }
+
+ }
+ return res;
+
+ }
+};
diff --git a/2018.11.30-leetcode890/Ostrichcrab.md b/2018.11.30-leetcode890/Ostrichcrab.md
new file mode 100644
index 000000000..077e78824
--- /dev/null
+++ b/2018.11.30-leetcode890/Ostrichcrab.md
@@ -0,0 +1,27 @@
+```
+class Solution {
+ public List findAndReplacePattern(String[] words, String pattern) {
+ List ans = new ArrayList();
+ for (String word: words)
+ if (match(word, pattern))
+ ans.add(word);
+ return ans;
+ }
+
+ public boolean match(String word, String pattern) {
+ Map m1 = new HashMap();
+ Map m2 = new HashMap();
+
+ for (int i = 0; i < word.length(); ++i) {
+ char w = word.charAt(i);
+ char p = pattern.charAt(i);
+ if (!m1.containsKey(w)) m1.put(w, p);
+ if (!m2.containsKey(p)) m2.put(p, w);
+ if (m1.get(w) != p || m2.get(p) != w)
+ return false;
+ }
+
+ return true;
+ }
+}
+```
diff --git a/2018.11.30-leetcode890/Sagittarius.md b/2018.11.30-leetcode890/Sagittarius.md
new file mode 100644
index 000000000..f2839f033
--- /dev/null
+++ b/2018.11.30-leetcode890/Sagittarius.md
@@ -0,0 +1,35 @@
+```
+class Solution {
+public:
+ vector findAndReplacePattern(vector& words, string pattern) {
+ vector s;
+ for(int i=0;i cmap;
+ string st="";
+ bool flag=true;
+ if(words[i].size()!=pattern.size())
+ continue;
+ for(int j=0,k=0;k findAndReplacePattern(vector& words, string pattern) {
+ vector s;
+ for(int i=0;i cmap;
+ string st="";
+ bool flag=true;
+ if(words[i].size()!=pattern.size())
+ continue;
+ for(int j=0,k=0;k findAndReplacePattern(String[] words, String pattern) {
+ List result = new ArrayList<>();
+ boolean flag = false;
+ for (String word : words) {
+ if (word.length() != pattern.length()) {
+ continue;
+ }
+ flag = false;
+ char[] wordChars = word.toCharArray();
+ char[] patternChars = pattern.toCharArray();
+ //比较wordChars第i个位置与第j个位置的值,如果相同,那么patternChars第i个位置与第j个位置的值也要相同
+ //如果wordChars第i个位置与第j个位置的值不同,那么patternChars第i个位置与第j个位置的值也要不同
+ for (int i = 0; i < wordChars.length ; i++) {
+ for (int j = i + 1; j < wordChars.length; j++) {
+ if (wordChars[i] == wordChars[j]) {
+ if (patternChars[i] != patternChars[j]) {
+ flag = true;
+ break;
+ }
+ }
+
+ if (wordChars[i] != wordChars[j]) {
+ if (patternChars[i] == patternChars[j]) {
+ flag = true;
+ break;
+ }
+ }
+ }
+ }
+
+ if (!flag) {
+ result.add(word);
+ }
+ }
+ return result;
+ }
+ }
+
+```
diff --git a/2018.11.30-leetcode890/Sunny.md b/2018.11.30-leetcode890/Sunny.md
new file mode 100644
index 000000000..c8588ba44
--- /dev/null
+++ b/2018.11.30-leetcode890/Sunny.md
@@ -0,0 +1,35 @@
+```java
+class Solution {
+ public List findAndReplacePattern(String[] words, String pattern) {
+ List result = new ArrayList<>();
+ for (String word : words) {
+ int l = pattern.length();
+ if (word.length() == l) {
+ boolean valid = true;
+ Map p = new HashMap<>(l);
+ for(int i=0; i findAndReplacePattern(String[] words, String pattern) {
+ List res = new ArrayList<>();
+ for (String word : words) {
+ if (match(word, pattern)) {
+ res.add(word);
+ }
+ }
+ return res;
+ }
+
+ private boolean match(String s, String p) {
+ int[] index1 = new int[26];
+ int[] index2 = new int[26];
+ for (int i = 0; i < s.length(); ++i) {
+ int i1 = s.charAt(i) - 'a';
+ int i2 = p.charAt(i) - 'a';
+ if (index1[i1] != index2[i2]) {
+ return false;
+ }
+ index1[i1] = index2[i2] = i + 1;
+ }
+ return true;
+ }
+}
+```
diff --git a/2018.11.30-leetcode890/Tony the Cyclist.md b/2018.11.30-leetcode890/Tony the Cyclist.md
new file mode 100644
index 000000000..b4557bd3b
--- /dev/null
+++ b/2018.11.30-leetcode890/Tony the Cyclist.md
@@ -0,0 +1,40 @@
+```
+import java.util.*;
+class Solution {
+ public List findAndReplacePattern(String[] words, String pattern) {
+ List result = new ArrayList();
+ String p = transfor(pattern);
+ String w;
+ String ww;
+ for (int i = 0; i < words.length; i++){
+ w = words[i];
+ ww = transfor(w);
+ if (ww.equals(p)){
+ result.add(w);
+ }
+
+ }
+ return result;
+ }
+
+ private String transfor(String s){
+ Map m = new HashMap<>();
+ char j = 0;
+ String ss = "";
+ m.put(s.charAt(0), (char)(j + '0'));
+ for(int i = 1; i < s.length(); i++){
+ if (s.charAt(i-1) != s.charAt(i)){
+ if (m.containsKey(s.charAt(i))){
+ ss += m.get(s.charAt(i));
+ }
+ else {
+ ++j;
+ ss += (char)(j+'0');
+ m.put(s.charAt(i), (char)(j + '0'));
+ }
+ }
+ }
+ return ss;
+ }
+}
+```
diff --git a/2018.11.30-leetcode890/kiritocly.md b/2018.11.30-leetcode890/kiritocly.md
new file mode 100644
index 000000000..a1b915d21
--- /dev/null
+++ b/2018.11.30-leetcode890/kiritocly.md
@@ -0,0 +1,45 @@
+ private static List solution(String[] words, String pattern) {
+ //定义一个list存放结果字符串
+ List result = new ArrayList<>();
+ char[] patternArray = pattern.toCharArray();
+ //遍历字符串
+ for (int i = 0; i < words.length; i++) {
+ //匹配字符串
+ char[] wordArray = words[i].toCharArray();
+ //是否匹配
+ boolean flag = true;
+ //长度相同才能匹配
+ if (wordArray.length == patternArray.length) {
+ //定义两个hashMap存放映射:words中的单词与pattern
+ Map hashMap1 = new HashMap<>();
+ Map hashMap2 = new HashMap<>();
+ //逐个字符匹配
+ for (int j = 0; j < patternArray.length; j++) {
+ if (!hashMap1.containsKey(patternArray[j])) {
+ //如果不存在字符则向hashMap1存放映射关系对
+ hashMap1.put(patternArray[j], wordArray[j]);
+ //判断hashMap2中是否存在反向映射关系对
+ if (!hashMap2.containsKey(wordArray[j])) {
+ hashMap2.put(wordArray[j], patternArray[j]);
+ } else {
+ if (hashMap2.get(wordArray[j]) != patternArray[j]) {
+ //存在反向字符且当前判断的字符不相同
+ flag = false;
+ break;
+ }
+
+ }
+ } else {
+ if (hashMap1.get(patternArray[j]) != wordArray[j]) {
+ flag = false;
+ break;
+ }
+ }
+ }
+ }
+ if (flag) {
+ result.add(words[i]);
+ }
+ }
+ return result;
+ }
diff --git a/2018.11.30-leetcode890/sourcema.md b/2018.11.30-leetcode890/sourcema.md
new file mode 100644
index 000000000..aff17c534
--- /dev/null
+++ b/2018.11.30-leetcode890/sourcema.md
@@ -0,0 +1,34 @@
+# LeetCode 890
+ class Solution {
+ public List findAndReplacePattern(String[] words, String pattern) {
+ List list = new ArrayList<>();
+ if (words.length == 0 || words == null) {
+ return list;
+ }
+ for (int i = 0; i < words.length; i++) {
+ String temp = words[i];
+ if (match(temp, pattern)) {
+ list.add(temp);
+ }
+ }
+ return list;
+ }
+ private static boolean match(String temp, String pattern) {
+ Map map1 = new HashMap<>();
+ Map map2 = new HashMap<>();
+ for (int i = 0; i < temp.length(); i++) {
+ Character t = temp.charAt(i);
+ Character p = pattern.charAt(i);
+ if (!map1.containsKey(t)) {
+ map1.put(t, p);
+ }
+ if (!map2.containsKey(p)) {
+ map2.put(p, t);
+ }
+ if (map1.get(t) != p || map2.get(p) != t) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
diff --git a/2018.11.30-leetcode890/suecurry.md b/2018.11.30-leetcode890/suecurry.md
new file mode 100644
index 000000000..0336110fa
--- /dev/null
+++ b/2018.11.30-leetcode890/suecurry.md
@@ -0,0 +1,54 @@
+import java.util.List;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+public class leetcode890 {
+ public static List findAndReplacePattern(String[] words, String pattern){
+ //定义一个ArrayList动态数组result,只不过里面存的值是String类型的
+ List result = new ArrayList<>();//注意 new List();语法是错的
+ char[] patternArray = pattern.toCharArray();
+ //遍历String[]字符串数组words中的每个字符串
+ for(int i=0; i judge = new HashMap<>();//HashMap 1
+ HashMap judge2 = new HashMap<>();//HashMap 2
+ for(int j=0; j findAndReplacePattern(String[] words, String pattern) {
+ List result=new LinkedList<>();
+ int pHashCode=getHashCode(pattern);
+ for (String word : words) {
+ if (getHashCode(word)==pHashCode) {
+ result.add(word);
+ }
+ }
+ return result;
+ }
+
+ public int getHashCode(String word){
+ int[] arr=new int[26];
+ int hashCode=0,i=1;
+ for (char c : word.toCharArray()) {
+ if (arr[c-'a']==0) {
+ arr[c-'a']=i++;
+ }
+ hashCode=hashCode*11+arr[c-'a'];
+ }
+ return hashCode;
+ }
+}
+```
diff --git a/2018.11.30-leetcode890/zjukk.md b/2018.11.30-leetcode890/zjukk.md
new file mode 100644
index 000000000..9bb653294
--- /dev/null
+++ b/2018.11.30-leetcode890/zjukk.md
@@ -0,0 +1,32 @@
+C++:
+class Solution {
+public:
+ vector findAndReplacePattern(vector& words, string pattern) {
+ vector res;
+ for (int i = 0; i < words.size(); ++i) {
+ map mp;
+ map mp2;
+ string word = words[i];
+ if (pattern.size() != word.size()) continue;
+ int j = 0;
+ for (; j < pattern.size(); ++j) {
+ if (mp.empty() || mp.count(pattern[j]) == 0) {
+ mp.insert({pattern[j], word[j]});
+ } else if (mp[pattern[j]] != word[j]){
+ break;
+ }
+ }
+ if (j != pattern.size()) continue;
+ int k = 0;
+ for (; k < pattern.size(); ++k) {
+ if (mp2.empty() || mp2.count(word[k]) == 0) {
+ mp2.insert({word[k],pattern[k]});
+ } else if (mp2[word[k]] != pattern[k]) {
+ break;
+ }
+ }
+ if (k == pattern.size()) res.push_back(word);
+ }
+ return res;
+ }
+};
diff --git "a/2018.11.30-leetcode890/\343\200\202V1ncentzzZ.md" "b/2018.11.30-leetcode890/\343\200\202V1ncentzzZ.md"
new file mode 100644
index 000000000..f2c68a296
--- /dev/null
+++ "b/2018.11.30-leetcode890/\343\200\202V1ncentzzZ.md"
@@ -0,0 +1,57 @@
+题目描述:
+你有一个单词列表 words 和一个模式 pattern,你想知道 words 中的哪些单词与模式匹配。
+
+如果存在字母的排列 p ,使得将模式中的每个字母 x 替换为 p(x) 之后,我们就得到了所需的单词,那么单词与模式是匹配的。
+
+(回想一下,字母的排列是从字母到字母的双射:每个字母映射到另一个字母,没有两个字母映射到同一个字母。)
+
+返回 words 中与给定模式匹配的单词列表。
+
+你可以按任何顺序返回答案。
+
+
+
+示例:
+
+输入:words = ["abc","deq","mee","aqq","dkd","ccc"], pattern = "abb"
+输出:["mee","aqq"]
+解释:
+"mee" 与模式匹配,因为存在排列 {a -> m, b -> e, ...}。
+"ccc" 与模式不匹配,因为 {a -> c, b -> c, ...} 不是排列。
+因为 a 和 b 映射到同一个字母。
+
+
+提示:
+
+1 <= words.length <= 50
+1 <= pattern.length = words[i].length <= 20
+
+
+
+题解: TODO 8ms 待优化
+class Solution {
+ public List findAndReplacePattern(String[] words, String pattern) {
+
+ List result = new ArrayList<>();
+
+ char[] patternChar = pattern.toCharArray();
+ String regex = "";
+ for(int i=0; i findAndReplacePattern(String[] words, String pattern) {
+ List results = new ArrayList<>();
+ Set characters = new HashSet();
+ Map map = new HashMap<>();//map保存字符映射关系
+ out:
+ for (int i = 0; i < words.length; i++) {//遍历words
+ for (int j = 0; j < pattern.length(); j++) {//初始化map
+ map.put(pattern.charAt(j), -288);
+ }
+ for (int k = 0; k < words[i].length(); k++) {
+ if (map.get(pattern.charAt(k)) == -288 && !characters.contains(words[i].charAt(k))) {
+ map.put(pattern.charAt(k), pattern.charAt(k) - words[i].charAt(k));
+ characters.add(words[i].charAt(k));
+ } else {
+ if (words[i].charAt(k) != -map.get(pattern.charAt(k)) + pattern.charAt(k)) {
+ characters.clear();
+ continue out;
+ }
+ }
+ }
+ results.add(words[i]);
+ characters.clear();
+ }
+ return results;
+ }
diff --git "a/2018.11.30-leetcode890/\345\210\230\346\266\246\346\263\275.md" "b/2018.11.30-leetcode890/\345\210\230\346\266\246\346\263\275.md"
new file mode 100644
index 000000000..a40421b2e
--- /dev/null
+++ "b/2018.11.30-leetcode890/\345\210\230\346\266\246\346\263\275.md"
@@ -0,0 +1,84 @@
+## LeetCode890
+> language:Java
+
+> version:jdk1.7
+
+```java
+/**
+ * 思路一:把pattern弄成一个记忆,然后依次比较
+ * 思路二:把pattern的某个特点记录下来,依次比较,然后再把下一个特点记录下来,依次比较...
+ * 下面代码是思路一的实现
+ */
+ public static List findAndReplacePattern(String[] words, String pattern) {
+
+ List resultList = new ArrayList<>();
+ List> patternRule = getRule(pattern);
+
+ for (int i=0;i> wordRule = getRule(words[i]);
+ if (patternRule.size()!=wordRule.size()) continue;
+ for (int j=0;j patternRuleIntegers = patternRule.get(j);
+ List wordRuleIntegers = wordRule.get(j);
+ for (int m=0;m> getRule(String pattern){
+ //记录pattern的所有特点
+ List> characterList = new ArrayList<>();
+ String currentCharacter = "";
+ List recordList = new ArrayList<>();
+
+ for (int i=0;i tempList=new ArrayList<>();
+ for (int j=i-1;;) {
+ tempIndex = pattern.indexOf(currentCharacter, j);
+ if (tempIndex==-1) break;
+
+ recordList.add(tempIndex);
+ tempList.add(tempIndex);
+ if (tempIndex==pattern.length()-1) break;
+ j=tempIndex+1;
+ }
+ characterList.add(tempList);
+ }
+ return characterList;
+ }
+
+ public static void main(String[] args) {
+ String[] words = new String[]{"abc","deq","meemccccm","aqqa","dkd","ccc"};
+ List list = findAndReplacePattern(words, "abbacccca");
+ for (String s : list){
+ System.out.println(s);
+ }
+ }
+```
diff --git "a/2018.11.30-leetcode890/\345\244\247\351\255\224\347\216\213\347\210\261\347\251\277\345\255\226\347\203\237\347\255\222.md" "b/2018.11.30-leetcode890/\345\244\247\351\255\224\347\216\213\347\210\261\347\251\277\345\255\226\347\203\237\347\255\222.md"
new file mode 100644
index 000000000..3f09b1572
--- /dev/null
+++ "b/2018.11.30-leetcode890/\345\244\247\351\255\224\347\216\213\347\210\261\347\251\277\345\255\226\347\203\237\347\255\222.md"
@@ -0,0 +1,45 @@
+```
+class Solution {
+ public List findAndReplacePattern(String[] words, String pattern) {
+ List list=new ArrayList<>();
+ char [] pat=pattern.toCharArray();
+ for(int i=0;i hash=new HashMap<>();
+ HashMap hash2=new HashMap<>();
+ for(int j=0;j m, b -> e, ...}。
+"ccc" 与模式不匹配,因为 {a -> c, b -> c, ...} 不是排列。
+因为 a 和 b 映射到同一个字母。
+
+
+提示:
+
+1 <= words.length <= 50
+1 <= pattern.length = words[i].length <= 20
+
+ */
+public class leetcode_890查找和替换模式
+{
+
+ public static void main(String[] args)
+ {
+ String[] wordsStrings= {"ddd","abc","deq","mee","aqq","dkd","ccc"};
+ String pattern = "abb";
+ System.out.println(findAndReplacePattern(wordsStrings, pattern));
+
+ }
+
+ public static List findAndReplacePattern(String[] words, String pattern)
+ {
+ List list=new ArrayList();
+ for(int i=0;i findAndReplacePattern(vector& words, string pattern) {
+ vectorres;
+ int n = pattern.size();
+ for (string &word : words) {
+ if (word.size() != n)continue;
+ vectorpletter(256, '#');
+ vectorwletter(256, '#');
+ bool flag = false;
+ //进行映射
+ for (int i = 0; i < n; i++) {
+ if (pletter[pattern[i]] == '#'&&wletter[word[i]]=='#') {
+ pletter[pattern[i]] = word[i];
+ wletter[word[i]] = pattern[i];
+ }
+ else if (pletter[pattern[i]] == word[i]&& wletter[word[i]]==pattern[i]) {
+ continue;
+ }
+ else {
+ flag = true;
+ break;
+ }
+ }
+ if (!flag)res.push_back(word);
+ }
+ return res;
+ }
+};
diff --git "a/2018.11.30-leetcode890/\346\210\221\347\210\261\345\220\203\347\223\234\345\255\220" "b/2018.11.30-leetcode890/\346\210\221\347\210\261\345\220\203\347\223\234\345\255\220"
new file mode 100644
index 000000000..2129c12f8
--- /dev/null
+++ "b/2018.11.30-leetcode890/\346\210\221\347\210\261\345\220\203\347\223\234\345\255\220"
@@ -0,0 +1,49 @@
+#leetcode 890
+```
+//思路是保证对应下标的权重是一样的,只需要比较权重就可以判断是否符合规则
+class Solution {
+ public static List findAndReplacePattern(String[] words, String pattern) {
+ List result = new ArrayList<>();//返回结果
+ char [] patternArray = pattern.toCharArray();//字符串转字符数组
+ for(int i=0;i judge = new HashMap<>();//hashmap1
+ HashMap judge2 = new HashMap<>();//反向比较hashmap2
+ for(int j=0;j 有一个words的列表和一个模式pattern,你想知道列表中哪个word和模式匹配。不考虑顺序,返回符合条件的word列表。
+
+> word和模式匹配:如果存在一种字母间的双射,单词x→都转换为p(x)
+
+**例子**
+>Input: words = ["abc","deq","mee","aqq","dkd","ccc"], pattern = "abb"
+Output: ["mee","aqq"]
+
+>Explanation: "mee" matches the pattern because there is a permutation {a -> m, b -> e, ...}.
+"ccc" does not match the pattern because {a -> c, b -> c, ...} is not a permutation,
+since a and b map to the same letter.
+
+**思想**
+
+(法1)
+考虑将所有字母都映射为0123..这种形式
+
+(法2)
+既然提到双射,我们知道Python中zip(a,b)可以建立列表对应位置元素的元组。
+
+利用长度的Trick。
+
+**解法1**
+映射为dic的长度,即按字母出现顺序映射为0,1,2...
+```python
+class Solution(object):
+ def findAndReplacePattern(self, words, pattern):
+ """
+ :type words: List[str]
+ :type pattern: str
+ :rtype: List[str]
+ """
+ return [word for word in words if self.helper(word) == self.helper(pattern)]
+
+ def helper(self, word):
+ dic = {}
+ for c in word:
+ if c not in dic:
+ dic[c] = len(dic)
+
+ return [dic[c] for c in word]
+```
+用一个dict建立相互之间的映射。
+>注意双射的情况,即若键不存在,值也不能存在于dict.values()中。
+```python
+class Solution(object):
+ def findAndReplacePattern(self, words, pattern):
+ """
+ :type words: List[str]
+ :type pattern: str
+ :rtype: List[str]
+ """
+ return [word for word in words if self.helper(word, pattern)]
+
+ def helper(self, word, pattern):
+ dic = {}
+ for w, p in zip(word, pattern):
+ if w in dic:
+ if dic[w] != p:
+ return False
+ else:
+ if p in dic.values(): # 双射:abc - abb
+ return False
+ dic[w] = p
+ return True
+```
+
+**解法2**
+Trick
+```python
+class Solution(object):
+ def findAndReplacePattern(self, words, pattern):
+ """
+ :type words: List[str]
+ :type pattern: str
+ :rtype: List[str]
+ """
+ return [word for word in words if len(word) == len(pattern)
+ and len(set(word)) == len(set(pattern)) == len(set(zip(word, pattern)))]
+```
diff --git "a/2018.11.30-leetcode890/\347\245\236\347\247\230\347\232\204\347\201\253\346\237\264\344\272\272.md" "b/2018.11.30-leetcode890/\347\245\236\347\247\230\347\232\204\347\201\253\346\237\264\344\272\272.md"
new file mode 100644
index 000000000..6d2cc909b
--- /dev/null
+++ "b/2018.11.30-leetcode890/\347\245\236\347\247\230\347\232\204\347\201\253\346\237\264\344\272\272.md"
@@ -0,0 +1,40 @@
+class Solution {
+public:
+ vector findAndReplacePattern(vector& words, string pattern) {
+ vector ret;
+
+ int size = words.size();
+ int n = pattern.length();
+
+ for(int i=0; i m;
+ map m1;
+ int j = 0;
+ for(j=0; j findAndReplacePattern(String[] words, String pattern) {
+ List list=new ArrayList<>();
+ for(int i=0;i= 0; i--) {
+ if (map[chas1[i]] != map[chas2[i] + 256]) {
+ return false;
+ }
+ map[chas1[i]] = map[chas2[i] + 256] = i;
+ }
+ return true;
+ }
+}
+```
+
diff --git a/2018.12.04-leetcode101/Avalon.md b/2018.12.04-leetcode101/Avalon.md
new file mode 100644
index 000000000..3b7adc570
--- /dev/null
+++ b/2018.12.04-leetcode101/Avalon.md
@@ -0,0 +1,28 @@
+/**
+ * Definition for a binary tree node.
+ * public class TreeNode {
+ * int val;
+ * TreeNode left;
+ * TreeNode right;
+ * TreeNode(int x) { val = x; }
+ * }
+ */
+class Solution {
+ public boolean isSymmetric(TreeNode root) {
+ if (root == null ){
+ return true;
+ }
+
+ return isSymmetric(root.left, root.right);
+ }
+
+ public static boolean isSymmetric(TreeNode nodeA, TreeNode node_A){
+ if (node_A == null && nodeA == null) {
+ return true;
+ }
+ if (node_A != null && nodeA != null) {
+ return node_A.val == nodeA.val && isSymmetric(nodeA.left, node_A.right) && isSymmetric(nodeA.right, node_A.left);
+ }
+ return false;
+ }
+}
diff --git a/2018.12.04-leetcode101/Be a fresh man.md b/2018.12.04-leetcode101/Be a fresh man.md
new file mode 100644
index 000000000..897fc1d09
--- /dev/null
+++ b/2018.12.04-leetcode101/Be a fresh man.md
@@ -0,0 +1,103 @@
+## 101_(对称二叉树)Symmetric Tree
+## 1 问题描述、输入输出与样例
+### 1.1 问题描述
+给定一个二叉树,检查它是否是镜像对称的。
+### 1.2 输入与输出
+输入:
+* TreeNode* root:二叉树的根节点指针
+
+输出:
+* bool:是否是对称二叉树
+
+### 1.3 样例
+#### 1.3.1 样例1
+输入: 给定二叉树: [1,2,2,3,4,4,3] ,
+
+ 1
+ / \
+ 2 2
+ / \ / \
+ 3 4 4 3
+输出: true
+
+#### 1.3.2 样例2
+输入:给定二叉树: [1,2,2,null,3,null,3] ,
+
+ 1
+ / \
+ 2 2
+ \ \
+ 3 3
+输出: false
+## 2 思路描述与代码
+### 2.1 思路描述(队列法)
+利用队列做判断
+```cpp
+根节点左右孩子入队;
+while( 队列非空 ){
+ 取出队列两个元素 tmp1, tmp2;
+ //如果当前节点都是空节点,结束本次循环,即不需要检查后续节点
+ if(tmp1 == null && tmp2 == null) continue;
+ //如果不对称,则返回false
+ if((tmp1 == nullptr && tmp2) || (tmp2 == nullptr && tmp1) || (tmp1->val != tmp2->val))
+ return false;
+ //剩下的可能情况就是左右非空且当前节点的值相等,即对称
+ //然后对这两个节点的左右孩子节点对称入队,保持对称性
+ //对称入队
+ tmp1 左孩子入队;
+ tmp2 右孩子入队;
+ tmp1 右孩子入队;
+ tmp2 左孩子入队;
+}
+return true;
+```
+
+### 2.2 代码
+```cpp
+bool isSymmetric(TreeNode* root) {
+ if(root == nullptr)
+ return true;
+ //使用队列做遍历,这是也可以使用堆栈
+ queue q;
+ //根节点就不用判断了,直接加入左右孩子节点
+ q.push(root->left);
+ q.push(root->right);
+ while( !q.empty() ){
+ //从队列弹出两个节点
+ TreeNode* tmp1 = q.front();
+ q.pop();
+ TreeNode* tmp2 = q.front();
+ q.pop();
+ //如果都是根节点,则结束本次循环
+ if(tmp1 == nullptr && tmp2 == nullptr)
+ continue;
+ //如果不对称,则返回false
+ if((tmp1 == nullptr && tmp2) || (tmp2 == nullptr && tmp1) || (tmp1->val != tmp2->val))
+ return false;
+ //对称入队
+ q.push(tmp1->left);
+ q.push(tmp2->right);
+ q.push(tmp1->right);
+ q.push(tmp2->left);
+ }
+ //都是对称的,返回真
+ return true;
+}
+
+```
+## 3 思考与拓展
+### 3.1 思考
+本题,利用队列和堆栈做遍历都可以解决这个问题。
+#### 3.1.1 其他方法
+#### 3.1.1.1 递归法
+一棵对称的二叉树必然是左右孩子相等且左右孩子也都是一棵对称的二叉树,利用该思路做递归就行了,这里就不继续写代码了。
+#### 3.1.2 复杂度分析
+方法|空间复杂度|时间复杂度
+--- | --- | ---
+队列法|O(2^h),h是树的高度|O(n)
+递归法|O(n)|O(n)
+#### 3.1.3 难点分析
+1. 对称与非对称的判断
+
+### 3.2 拓展
+如果让你判断是不是同构的呢?
diff --git a/2018.12.04-leetcode101/Despacito.md b/2018.12.04-leetcode101/Despacito.md
new file mode 100644
index 000000000..e1e85f4fa
--- /dev/null
+++ b/2018.12.04-leetcode101/Despacito.md
@@ -0,0 +1,52 @@
+# leetcode 101 Symmetric Tree
+## 1. Description
+Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
+
+For example, this binary tree [1,2,2,3,4,4,3] is symmetric:
+
+ 1
+ / \
+ 2 2
+ / \ / \
+ 3 4 4 3
+
+But the following [1,2,2,null,3,null,3] is not:
+
+ 1
+ / \
+ 2 2
+ \ \
+ 3 3
+
+**Note:**
+
+Bonus points if you could solve it both recursively and iteratively.
+
+## 2. Solution
+```python
+# Definition for a binary tree node.
+# class TreeNode:
+# def __init__(self, x):
+# self.val = x
+# self.left = None
+# self.right = None
+
+class Solution:
+ def isSymmetric(self, root):
+ """
+ :type root: TreeNode
+ :rtype: bool
+ """
+ if root == None:
+ return True
+ return self.comroot(root.left, root.right)
+
+ def comroot(self, left, right):
+ if left == None and right == None:
+ return True
+ elif left == None or right == None:
+ return False
+ elif left.val != right.val:
+ return False
+ return self.comroot(left.left, right.right) and self.comroot(left.right, right.left)
+```
\ No newline at end of file
diff --git a/2018.12.04-leetcode101/Istoryforever.md b/2018.12.04-leetcode101/Istoryforever.md
new file mode 100644
index 000000000..97d6054b4
--- /dev/null
+++ b/2018.12.04-leetcode101/Istoryforever.md
@@ -0,0 +1,25 @@
+leetcode of 101
+```
+/**
+ * Definition for a binary tree node.
+ * struct TreeNode {
+ * int val;
+ * TreeNode *left;
+ * TreeNode *right;
+ * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
+ * };
+ */
+class Solution {
+public:
+ bool isSymmetric(TreeNode* p1,TreeNode * p2){
+ if((p1 == nullptr && p2!=nullptr) || (p2 == nullptr && p1!=nullptr)) return false;
+ if(p1 == nullptr && p2 == nullptr) return true;
+ if(p1->val != p2->val) return false;
+ return isSymmetric(p1->left,p2->right) && isSymmetric(p1->right,p2->left);
+
+ }
+ bool isSymmetric(TreeNode* root) {
+ return isSymmetric(root,root);
+ }
+};
+```
diff --git a/2018.12.04-leetcode101/MQQM.cpp b/2018.12.04-leetcode101/MQQM.cpp
new file mode 100644
index 000000000..4ddbc6cff
--- /dev/null
+++ b/2018.12.04-leetcode101/MQQM.cpp
@@ -0,0 +1,43 @@
+/*
+ 题目:
+ 给定一个二叉树,检查它是否是镜像对称的。
+
+ 做法:
+ 给定对应位置上的两个节点,递归判断这两个节点是否一致。
+
+ 参考:
+ https://www.cnblogs.com/xiaozhuyang/p/7376749.html
+*/
+
+/**
+ * Definition for a binary tree node.
+ * struct TreeNode {
+ * int val;
+ * TreeNode *left;
+ * TreeNode *right;
+ * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
+ * };
+ */
+class Solution {
+public:
+ bool isSymmetric(TreeNode* root) {
+ if( root == NULL ){
+ return true;
+ }
+
+ return isEqual(root->left, root->right);
+ }
+ bool isEqual(TreeNode* left, TreeNode* right){//给定的两个节点已经是对应位置上的节点
+ if( left == NULL && right == NULL ){//两个节点都是空
+ return true;
+ }
+ if( left == NULL || right == NULL ){//有一个节点是空
+ return false;
+ }
+ if( left->val != right->val ){//两个节点都存在,但是不相同
+ return false;
+ }
+
+ return isEqual(left->left, right->right) && isEqual(left->right, right->left);
+ }
+};
diff --git a/2018.12.04-leetcode101/Saul.md b/2018.12.04-leetcode101/Saul.md
new file mode 100644
index 000000000..1fff77b94
--- /dev/null
+++ b/2018.12.04-leetcode101/Saul.md
@@ -0,0 +1,24 @@
+```java
+/**
+ * Definition for a binary tree node.
+ * public class TreeNode {
+ * int val;
+ * TreeNode left;
+ * TreeNode right;
+ * TreeNode(int x) { val = x; }
+ * }
+ */
+class Solution {
+ public boolean isSymmetric(TreeNode root) {
+ return isMirror(root, root);
+}
+
+public boolean isMirror(TreeNode t1, TreeNode t2) {
+ if (t1 == null && t2 == null) return true;
+ if (t1 == null || t2 == null) return false;
+ return (t1.val == t2.val)
+ && isMirror(t1.right, t2.left)
+ && isMirror(t1.left, t2.right);
+}
+}
+```
diff --git a/2018.12.04-leetcode101/Tony the Cyclist.md b/2018.12.04-leetcode101/Tony the Cyclist.md
new file mode 100644
index 000000000..a1e44e5c1
--- /dev/null
+++ b/2018.12.04-leetcode101/Tony the Cyclist.md
@@ -0,0 +1,83 @@
+递归
+```java
+class Solution {
+ public boolean isSymmetric(TreeNode root) {
+ if (root == null){
+ return true;
+ }
+ else {
+ if (check(root.left, root.right)){
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+ }
+
+ public static boolean check(TreeNode node1, TreeNode node2){
+ if (node1 == null && node2 == null){
+ return true;
+ }
+ else if (node1 == null || node2 == null){
+ return false;
+ }
+ return node1.val == node2.val && check(node1.right, node2.left) && check(node1.left, node2.right);
+ }
+}
+```
+非递归
+```java
+import java.util.*;
+class Solution {
+ public boolean isSymmetric(TreeNode root) {
+ if ((root == null) || (root.left == null && root.right == null)){
+ return true;
+ }
+ else if (root.left == null || root.right == null){
+ return false;
+ }
+ else {
+ ArrayDeque d = new ArrayDeque();
+ d.addFirst(root.left);
+ d.addLast(root.right);
+ while (d.size() != 0){
+ TreeNode leftnode = d.pollFirst();
+ TreeNode rightnode = d.pollLast();
+ if (leftnode == null && rightnode == null){
+ return true;
+ }
+ else if (leftnode == null || rightnode == null){
+ return false;
+ }
+ else if (leftnode.val != rightnode.val){
+ return false;
+ }
+ else {
+ if (rightnode.right != null && leftnode.left != null){
+ d.addLast(rightnode.right);
+ d.addFirst(leftnode.left);
+ }
+ else if (rightnode.right == null && leftnode.left == null){
+
+ }
+ else {
+ return false;
+ }
+ if (rightnode.left != null && leftnode.right != null){
+ d.addFirst(rightnode.left);
+ d.addLast(leftnode.right);
+ }
+ else if (rightnode.left == null && leftnode.right == null){
+
+ }
+ else {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+ }
+}
+```
diff --git a/2018.12.04-leetcode101/WhiteNight.md b/2018.12.04-leetcode101/WhiteNight.md
new file mode 100644
index 000000000..5b769916c
--- /dev/null
+++ b/2018.12.04-leetcode101/WhiteNight.md
@@ -0,0 +1,58 @@
+>```java
+>/**
+> *给定一个二叉树,检查它是否是镜像对称的。
+> *
+> */
+>public class Tree9
+>{
+> public static class TreeNode
+> {
+> int data;
+> TreeNode left;
+> TreeNode right;
+>
+> TreeNode(int val) {
+> data = val;
+> }
+> }
+>
+> public boolean isSymmetric(TreeNode root)
+> {
+> if (root == null)
+> return true;
+> return checkIsSymmetric(root.left, root.right);
+> }
+>
+> public static boolean checkIsSymmetric(TreeNode leftNode, TreeNode rightNode)
+> {
+> if (leftNode == null && rightNode == null)
+> return true;
+> if ((leftNode == null && rightNode != null) || (leftNode != null && rightNode == null))
+> return false;
+> if (leftNode.data != rightNode.data)
+> return false;
+> return checkIsSymmetric(leftNode.left, rightNode.right) && checkIsSymmetric(leftNode.right, rightNode.left);
+> }
+>
+> public static void main(String[] args)
+> {
+> TreeNode p = new TreeNode(1);
+> p.left = new TreeNode(2);
+> p.right = new TreeNode(2);
+> p.left.left = new TreeNode(3);
+> p.right.right = new TreeNode(3);
+>
+> TreeNode q = new TreeNode(1);
+> q.left = new TreeNode(2);
+> q.right = new TreeNode(2);
+> q.left.right = new TreeNode(3);
+> q.right.right = new TreeNode(3);
+>
+> Tree9 t = new Tree9();
+> System.out.println(t.isSymmetric(p));
+> System.out.println(t.isSymmetric(q));
+>
+> }
+>
+>}
+>```
\ No newline at end of file
diff --git a/2018.12.04-leetcode101/fish.md b/2018.12.04-leetcode101/fish.md
new file mode 100644
index 000000000..609c8569e
--- /dev/null
+++ b/2018.12.04-leetcode101/fish.md
@@ -0,0 +1,58 @@
+```
+class Solution {
+ public boolean isSymmetric(TreeNode treeNode) {
+ if (treeNode == null) {
+ return true;
+ }else {
+ return isSymmetric(treeNode.getLeft(), treeNode.getRight());
+ }
+ }
+
+ public boolean isSymmetric(TreeNode left, TreeNode right) {
+ if (left == null && right == null) {
+ return true;
+ }
+ if (left == null || right == null) {
+ return false;
+ }
+ if (left.getVal() != right.getVal()) {
+ return false;
+ }
+ return isSymmetric(left.getLeft(), right.getRight()) && isSymmetric(left.getRight(), right.getLeft());
+ }
+}
+class TreeNode{
+ private int val;
+ private TreeNode left;
+ private TreeNode right;
+
+ public TreeNode(int val, TreeNode left, TreeNode right) {
+ this.val = val;
+ this.left = left;
+ this.right = right;
+ }
+
+ public int getVal() {
+ return val;
+ }
+
+ public void setVal(int val) {
+ this.val = val;
+ }
+
+ public TreeNode getLeft() {
+ return left;
+ }
+
+ public void setLeft(TreeNode left) {
+ this.left = left;
+ }
+
+ public TreeNode getRight() {
+ return right;
+ }
+
+ public void setRight(TreeNode right) {
+ this.right = right;
+ }
+}
\ No newline at end of file
diff --git a/2018.12.04-leetcode101/kiritocly.md b/2018.12.04-leetcode101/kiritocly.md
new file mode 100644
index 000000000..51cd1718d
--- /dev/null
+++ b/2018.12.04-leetcode101/kiritocly.md
@@ -0,0 +1,33 @@
+ private static boolean solution(TreeNode root) {
+ if (root == null) {
+ return true;
+ } else {
+ //二叉树对称的条件
+ //(1)左子树和右子树对称
+ //(2)左子树的左子树和右子树的右子树对称
+ //(3)左子树的右子树和右子树的左子树对称
+ //递归判断
+ return judge(root.leftNode, root.rightNode);
+ }
+
+ }
+
+ private static boolean judge(TreeNode leftNode, TreeNode rightNode) {
+ if (leftNode == null && rightNode == null) {
+ return true;
+ } else if (leftNode == null || rightNode == null) {
+ return false;
+ }
+ //条件(1)
+ if (leftNode.value != rightNode.value) {
+ return false;
+ }
+ //条件(2)
+ boolean flag1 = judge(leftNode.leftNode, rightNode.rightNode);
+ //条件(3)
+ boolean flag2 = judge(leftNode.rightNode, rightNode.leftNode);
+ if (flag1 && flag2) {
+ return true;
+ }
+ return false;
+ }
diff --git a/2018.12.04-leetcode101/marguerite.md b/2018.12.04-leetcode101/marguerite.md
new file mode 100644
index 000000000..171a682df
--- /dev/null
+++ b/2018.12.04-leetcode101/marguerite.md
@@ -0,0 +1,96 @@
+101_(对称二叉树)Symmetric Tree
+给定一个二叉树,检查它是否是镜像对称的。
+
+输入:
+TreeNode* root:二叉树的根节点指针
+输出:
+bool:是否是对称二叉树
+
+输入: 给定二叉树: [1,2,2,3,4,4,3] ,
+ 1
+ / \
+ 2 2
+ / \ / \
+3 4 4 3
+输出: true
+
+solution1
+
+判断是否是镜像对称,重要的就是判断对应位置的2个结点的值是否相等。用双端队列来实现
+
+public boolean isSymmetric(TreeNode root){
+ if(root == null){
+ return true;
+ }
+ //队列做遍历
+ Deque deque = new LinkedList();
+ //根节点不用判断,直接加入左右孩子结点
+ deque.addFirst(root.left);
+ deque.addLast(root.right);
+
+ TreeNode preNode = null;
+ TreeNode postNode = null;
+
+ while(!deque.isEmpty()){
+ //取出列队两个元素
+ preNode = deque.pollFirst();
+ postNode = deque.pollLast();
+ //如果当前结点是空结点,结束本次循环,即不需要检查后续结点
+ if(preNode == null && postNode == null){
+ continue;
+ }
+ //如果不对称返回false,
+ if(preNode == null || postNode == null){
+ return false;
+ }
+ if(preNode.val != postNode.val){
+ return false;
+ } else{
+ deque.addFirst(preNode.right);//preNode右孩子入队
+ deque.addFirst(preNode.left);//preNode左孩子入队
+
+ deque.addLast(postNode.left);//postNode左孩子入队
+ deque.addLast(postNode.right);//postNode右孩子入队
+ }
+ }
+ return true;//都是对称的返回真
+ }
+
+
+solution2
+ public boolean isSysmmetric2(TreeNode root){
+ if(root == null){
+ return true;
+ }
+ return checkNodes(root.left,root.right);
+ }
+
+ public boolean checkNodes(TreeNode node1,TreeNode node2){
+ if(node1 == null && node2 == null){
+ return true;
+ }
+ if(node1 == null || node2 == null){
+ return false;
+ }
+ if(node1.val != node2.val){
+ return false;
+ } else{
+ return checkNodes(node1.left,node2.right) && checkNodes(node1.right,node2.left);
+ }
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/2018.12.04-leetcode101/sourcema.md b/2018.12.04-leetcode101/sourcema.md
new file mode 100644
index 000000000..bc477d192
--- /dev/null
+++ b/2018.12.04-leetcode101/sourcema.md
@@ -0,0 +1,27 @@
+# LeetCode 101
+ /**
+ * Definition for a binary tree node.
+ * public class TreeNode {
+ * int val;
+ * TreeNode left;
+ * TreeNode right;
+ * TreeNode(int x) { val = x; }
+ * }
+ */
+ class Solution {
+ public boolean isSymmetric(TreeNode root) {
+ if (root == null) {
+ return true;
+ }
+ return symmetric(root.left, root.right);
+ }
+ private boolean symmetric(TreeNode p, TreeNode q) {
+ if (p == null && q == null) {
+ return true;
+ }
+ if ((p == null && q != null) || (p != null && q == null) || p.val != q.val) {
+ return false;
+ }
+ return symmetric(p.left, q.right) && symmetric(p.right, q.left);
+ }
+ }
diff --git a/2018.12.04-leetcode101/syuan.md b/2018.12.04-leetcode101/syuan.md
new file mode 100644
index 000000000..9048177da
--- /dev/null
+++ b/2018.12.04-leetcode101/syuan.md
@@ -0,0 +1,65 @@
+##### 题目
+
+```
+给定一个二叉树,检查它是否是镜像对称的。
+
+例如,二叉树 [1,2,2,3,4,4,3] 是对称的。
+
+ 1
+ / \
+ 2 2
+ / \ / \
+3 4 4 3
+
+但是下面这个 [1,2,2,null,3,null,3] 则不是镜像对称的:
+
+ 1
+ / \
+ 2 2
+ \ \
+ 3 3
+```
+##### 代码
+递归
+```
+public boolean isSymmetric(TreeNode root) {
+ if (root==null) {
+ return true;
+ }else{
+ return isSymmetric(root.left,root.right);
+ }
+ }
+
+ public boolean isSymmetricCore(TreeNode leftNode, TreeNode rightNode){
+ if (leftNode==null && rightNode==null) {
+ return true;
+ }
+ if (leftNode.val!=rightNode.val || leftNode==null || rightNode==null) {
+ return false;
+ }
+ return isSymmetricCore(leftNode.left,rightNode.right) && isSymmetricCore(leftNode.right,rightNode.left);
+ }
+```
+##### 非递归法
+
+```
+class Solution {
+ public boolean isSymmetric(TreeNode root) {
+ if(root == null) return true;
+ Stack stack = new Stack();
+ stack.push(root.left);
+ stack.push(root.right);
+ while(!stack.empty()) {
+ TreeNode right = stack.pop();
+ TreeNode left = stack.pop();
+ if (left == null && right == null) continue;
+ else if (left == null || right == null || right.val != left.val) return false;
+ stack.push(left.left);
+ stack.push(right.right);
+ stack.push(left.right);
+ stack.push(right.left);
+ }
+ return true;
+ }
+}
+```
diff --git "a/2018.12.04-leetcode101/\343\200\202V1ncentzzZ.md" "b/2018.12.04-leetcode101/\343\200\202V1ncentzzZ.md"
new file mode 100644
index 000000000..191025761
--- /dev/null
+++ "b/2018.12.04-leetcode101/\343\200\202V1ncentzzZ.md"
@@ -0,0 +1,43 @@
+101. 对称二叉树
+
+给定一个二叉树,检查它是否是镜像对称的。
+
+例如,二叉树 [1,2,2,3,4,4,3] 是对称的。
+
+ 1
+ / \
+ 2 2
+ / \ / \
+3 4 4 3
+但是下面这个 [1,2,2,null,3,null,3] 则不是镜像对称的:
+
+ 1
+ / \
+ 2 2
+ \ \
+ 3 3
+
+```
+ /**
+ * Definition for a binary tree node.
+ * public class TreeNode {
+ * int val;
+ * TreeNode left;
+ * TreeNode right;
+ * TreeNode(int x) { val = x; }
+ * }
+ */
+class Solution {
+ public boolean isSymmetric(TreeNode root) {
+ if(root == null) return true;
+ return symmetricCheck(root.left,root.right);
+ }
+
+ public boolean symmetricCheck(TreeNode node1,TreeNode node2){
+ if(node1 == null && node2 == null) return true;
+ if(node1 == null || node2 == null) return false;
+ return (node1.val != node2.val) ? false : symmetricCheck(node1.left,node2.right) && symmetricCheck(node1.right,node2.left);
+
+ }
+}
+```
diff --git "a/2018.12.04-leetcode101/\343\200\202\343\200\202\343\200\202.md" "b/2018.12.04-leetcode101/\343\200\202\343\200\202\343\200\202.md"
new file mode 100644
index 000000000..f344327ea
--- /dev/null
+++ "b/2018.12.04-leetcode101/\343\200\202\343\200\202\343\200\202.md"
@@ -0,0 +1,22 @@
+/**
+ * Definition for a binary tree node.
+ * public class TreeNode {
+ * int val;
+ * TreeNode left;
+ * TreeNode right;
+ * TreeNode(int x) { val = x; }
+ * }
+ */
+class Solution {
+ public boolean isSymmetric(TreeNode root) {
+ if(root == null)return true;
+ return isSymmetric2(root.left,root.right);
+ }
+
+ private boolean isSymmetric2(TreeNode left, TreeNode right) {
+ if (left != null && right != null && left.val == right.val){
+ return isSymmetric2(left.left,right.right) && isSymmetric2(left.right,right.left);
+ }
+ return (left==null && right == null);
+ }
+}
diff --git "a/2018.12.04-leetcode101/\345\225\246\345\225\246\345\225\246.md" "b/2018.12.04-leetcode101/\345\225\246\345\225\246\345\225\246.md"
new file mode 100644
index 000000000..87c2b14f3
--- /dev/null
+++ "b/2018.12.04-leetcode101/\345\225\246\345\225\246\345\225\246.md"
@@ -0,0 +1,22 @@
+```java
+/**
+ * Definition for a binary tree node.
+ * public class TreeNode {
+ * int val;
+ * TreeNode left;
+ * TreeNode right;
+ * TreeNode(int x) { val = x; }
+ * }
+ */
+class Solution {
+ public boolean isSymmetric(TreeNode root) {
+ return cal(root,root);
+ }
+
+ boolean cal(TreeNode r1,TreeNode r2){
+ if(r1==null&&r2==null)return true;
+ if(r1==null||r2==null)return false;
+ return r1.val==r2.val&&cal(r1.left,r2.right)&&cal(r1.right,r2.left);
+ }
+}
+```
diff --git "a/2018.12.04-leetcode101/\345\244\247\351\255\224\347\216\213\347\210\261\347\251\277\345\255\226\347\203\237\347\255\222.md" "b/2018.12.04-leetcode101/\345\244\247\351\255\224\347\216\213\347\210\261\347\251\277\345\255\226\347\203\237\347\255\222.md"
new file mode 100644
index 000000000..0ac1a8b14
--- /dev/null
+++ "b/2018.12.04-leetcode101/\345\244\247\351\255\224\347\216\213\347\210\261\347\251\277\345\255\226\347\203\237\347\255\222.md"
@@ -0,0 +1,34 @@
+```
+/**
+ * Definition for a binary tree node.
+ * public class TreeNode {
+ * int val;
+ * TreeNode left;
+ * TreeNode right;
+ * TreeNode(int x) { val = x; }
+ * }
+ */
+class Solution {//递归方式
+ public boolean isSymmetric(TreeNode root) {
+ if(root==null){
+ return true;
+
+ }
+ return isSymmetric(root.left,root.right);
+
+ }
+ public boolean isSymmetric(TreeNode left,TreeNode right){
+ if(left==null&&right==null){//无左右子树,则节点本身是对称的
+ return true;
+ }else if(left==null||right==null){//只含有一个左子树或者右子树,不对称
+ return false;
+ }
+ if(left.val!=right.val){
+ return false;
+ }
+
+
+ return isSymmetric(left.right,right.left)&&isSymmetric(left.left,right.right);//左子树的右子树和右子树的左子树是否对称。
+ }
+}
+```
diff --git "a/2018.12.04-leetcode101/\345\246\256\345\217\257.md" "b/2018.12.04-leetcode101/\345\246\256\345\217\257.md"
new file mode 100644
index 000000000..6a0c165bb
--- /dev/null
+++ "b/2018.12.04-leetcode101/\345\246\256\345\217\257.md"
@@ -0,0 +1,88 @@
+```java
+package sy181204;
+
+/**
+ * @author suyuan
+ *
+给定一个二叉树,检查它是否是镜像对称的。
+
+例如,二叉树 [1,2,2,3,4,4,3] 是对称的。
+
+ 1
+ / \
+ 2 2
+ / \ / \
+3 4 4 3
+但是下面这个 [1,2,2,null,3,null,3] 则不是镜像对称的:
+
+ 1
+ / \
+ 2 2
+ \ \
+ 3 3
+说明:
+
+如果你可以运用递归和迭代两种方法解决这个问题,会很加分。
+ */
+public class leetcode_101对称二叉树
+{
+
+ public static void main(String[] args)
+ {
+ TreeNode node1=new TreeNode(1);
+ TreeNode node2=new TreeNode(2);
+ TreeNode node3=new TreeNode(2);
+ TreeNode node4=new TreeNode(3);
+ TreeNode node5=new TreeNode(3);
+ TreeNode node6=new TreeNode(4);
+ TreeNode node7=new TreeNode(4);
+ node1.left=node2;
+ node1.right=node3;
+
+ node2.left=node4;
+ node2.right=node6;
+
+ node3.left=node7;
+ node3.right=node5;
+
+ node4.left=null;
+ node4.right=null;
+ node5.left=null;
+ node5.right=null;
+ node6.left=null;
+ node6.right=null;
+ node7.left=null;
+ node7.right=null;
+
+ System.out.println(isSymmetric(node1));
+
+ }
+
+ public static boolean isSymmetric(TreeNode root)
+ {
+ if(root==null)
+ return true;
+ return isSy(root.left, root.right);
+ }
+
+ public static boolean isSy(TreeNode left,TreeNode right)
+ {
+ if(left==null && right==null)
+ return true;
+ if((left==null && right!=null) || (right==null && left!=null))
+ return false;
+ if(left.val!=right.val)
+ return false;
+ return isSy(left.left, right.right) && isSy(left.right, right.left);
+ }
+
+}
+
+ class TreeNode {
+ int val;
+ TreeNode left;
+ TreeNode right;
+ TreeNode(int x) { val = x; }
+ }
+
+```
diff --git "a/2018.12.04-leetcode101/\346\235\216\347\242\247\346\266\265.md" "b/2018.12.04-leetcode101/\346\235\216\347\242\247\346\266\265.md"
new file mode 100644
index 000000000..9ed6e6c06
--- /dev/null
+++ "b/2018.12.04-leetcode101/\346\235\216\347\242\247\346\266\265.md"
@@ -0,0 +1,82 @@
+### [101. Symmetric Tree](https://leetcode.com/problems/symmetric-tree/description/)
+**题目描述**
+> 判断是否是镜像二叉树(对称)
+
+**例子**
+略
+
+**思想**
+(递归)
+定义一辅助函数,输入为left和right,判断是否相等。
+(迭代)
+定义两个栈,层次遍历时判断,并分别从左向右和从右向左存储。
+
+**解法1**
+递归
+```python
+# Definition for a binary tree node.
+# class TreeNode(object):
+# def __init__(self, x):
+# self.val = x
+# self.left = None
+# self.right = None
+
+class Solution(object):
+ def isSymmetric(self, root):
+ """
+ :type root: TreeNode
+ :rtype: bool
+ """
+ if not root:
+ return True
+ return self.helper(root.left, root.right)
+
+ def helper(self, left, right):
+ if not left and not right:
+ return True
+ if not left or not right or left.val != right.val:
+ return False
+ return self.helper(left.left, right.right) and self.helper(left.right, right.left)
+```
+**解法2**
+迭代
+```python
+# Definition for a binary tree node.
+# class TreeNode(object):
+# def __init__(self, x):
+# self.val = x
+# self.left = None
+# self.right = None
+
+class Solution(object):
+ def isSymmetric(self, root):
+ """
+ :type root: TreeNode
+ :rtype: bool
+ """
+ if not root or not root.left and not root.right:
+ return True
+ if not root.left or not root.right:
+ return False
+
+ queue1, queue2 = [root.left], [root.right]
+ while queue1 and queue2:
+ node1 = queue1.pop(0)
+ node2 = queue2.pop(0)
+
+ if node1.val != node2.val:
+ return False
+
+ if node1.left and node2.right:
+ queue1.append(node1.left)
+ queue2.append(node2.right)
+ elif node1.left or node2.right:
+ return False
+
+ if node1.right and node2.left:
+ queue1.append(node1.right)
+ queue2.append(node2.left)
+ elif node1.right or node2.left:
+ return False
+ return True
+```
\ No newline at end of file
diff --git "a/2018.12.04-leetcode101/\346\235\250.md" "b/2018.12.04-leetcode101/\346\235\250.md"
new file mode 100644
index 000000000..6afe9301b
--- /dev/null
+++ "b/2018.12.04-leetcode101/\346\235\250.md"
@@ -0,0 +1,25 @@
+```
+ /**
+ * 如果一个树的左子树与右子树镜像对称,那么这个树是对称的。
+ * 如果同时满足下面的条件,两个树互为镜像:
+ * 1.它们的两个根结点具有相同的值。
+ * 2.每个树的右子树都与另一个树的左子树镜像对称。
+ */
+ public boolean isSymmetric(TreeNode root) {
+ if(root == null ){
+ return true;
+ }
+ return isMirrorSymmetry(root.left,root.right);
+ }
+
+ public boolean isMirrorSymmetry(TreeNode left,TreeNode right){
+ if(left==null && right==null){
+ return true;
+ }
+ if(left==null || right==null){
+ return false;
+ }
+ return left.val==right.val && isMirrorSymmetry(left.left,right.right) && isMirrorSymmetry(left.right,right.left);
+ }
+
+```
diff --git "a/2018.12.04-leetcode101/\346\271\233\346\261\237\347\224\262\351\270\237.md" "b/2018.12.04-leetcode101/\346\271\233\346\261\237\347\224\262\351\270\237.md"
new file mode 100644
index 000000000..65dcb627d
--- /dev/null
+++ "b/2018.12.04-leetcode101/\346\271\233\346\261\237\347\224\262\351\270\237.md"
@@ -0,0 +1,45 @@
+#### 递归
+```
+public boolean isSymmetric(TreeNode root) {
+ if (root == null)
+ return true;
+ return dfs(root.left, root.right);
+}
+
+private boolean dfs(TreeNode node1, TreeNode node2) {
+ if ((node1 == null && node2 == null)) {
+ return true;
+ } else if (node1 != null && node2 != null) {
+ if (node1.val != node2.val) {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ return dfs(node1.left, node2.right) && dfs(node1.right, node2.left);
+}
+```
+
+#### 非递归
+```
+public boolean isSymmetric(TreeNode root) {
+ Queue q = new LinkedList<>();
+ q.add(root);
+ q.add(root);
+ while (!q.isEmpty()) {
+ TreeNode t1 = q.poll();
+ TreeNode t2 = q.poll();
+ if (t1 == null && t2 == null) {
+ continue;
+ }
+ if (t1 == null || t2 == null || t1.val != t2.val) {
+ return false;
+ }
+ q.add(t1.left);
+ q.add(t2.right);
+ q.add(t1.right);
+ q.add(t2.left);
+ }
+ return true;
+}
+```
diff --git "a/2018.12.04-leetcode101/\347\245\236\347\247\230\347\232\204\347\201\253\346\237\264\344\272\272.md" "b/2018.12.04-leetcode101/\347\245\236\347\247\230\347\232\204\347\201\253\346\237\264\344\272\272.md"
new file mode 100644
index 000000000..df8f5dbf9
--- /dev/null
+++ "b/2018.12.04-leetcode101/\347\245\236\347\247\230\347\232\204\347\201\253\346\237\264\344\272\272.md"
@@ -0,0 +1,49 @@
+```
+/**
+ * Definition for a binary tree node.
+ * struct TreeNode {
+ * int val;
+ * TreeNode *left;
+ * TreeNode *right;
+ * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
+ * };
+ */
+class Solution {
+public:
+ bool isSymmetric(TreeNode* root) {
+ if(!root) return true;
+
+ queue q1;
+ queue q2;
+ q1.push(root->left);
+ q2.push(root->right);
+
+
+ while(!q1.empty() && !q2.empty())
+ {
+ TreeNode *l = q1.front();
+ TreeNode *r = q2.front();
+
+ q1.pop();
+ q2.pop();
+
+ if( (!l&&r) || (l&&!r) ) return false;
+
+ if(l && r)
+ {
+ if(l->val != r->val)
+ return false;
+
+ q1.push(l->left);
+ q1.push(l->right);
+
+ q2.push(r->right);
+ q2.push(r->left);
+ }
+
+ }
+
+ return true;
+ }
+};
+```
diff --git "a/2018.12.04-leetcode101/\351\223\201\347\224\267\347\245\236sama.md" "b/2018.12.04-leetcode101/\351\223\201\347\224\267\347\245\236sama.md"
new file mode 100644
index 000000000..df7ffe32a
--- /dev/null
+++ "b/2018.12.04-leetcode101/\351\223\201\347\224\267\347\245\236sama.md"
@@ -0,0 +1,68 @@
+
+
+
+
+## 101.对称二叉树
+
+>[https://leetcode-cn.com/problems/symmetric-tree/](https://leetcode-cn.com/problems/symmetric-tree/)
+
+### 一、题目
+
+给定一个二叉树,检查它是否是镜像对称的。
+
+例如,二叉树 `[1,2,2,3,4,4,3]` 是对称的。
+
+```
+ 1
+ / \
+ 2 2
+ / \ / \
+ 3 4 4 3
+```
+
+但是下面这个 `[1,2,2,null,3,null,3]` 则不是镜像对称的:
+
+```
+ 1
+ / \
+ 2 2
+ \ \
+ 3 3
+```
+
+### 二、思路
+
+- 二叉树问题锁定递归
+
+- 如何判定一棵树是否镜像:整棵树镜像=左子树镜像&&右子树镜像
+ - [ ] 条件一:左孩子为空&&右孩子为空(没有孩子的情况)
+ - [ ] 条件二:左孩子值==右孩子值(有两个孩子的情况);(只有一个孩子的肯定不能互为镜像)
+ - [ ] 条件三:左左值==右右值&&左右值==右左值
+
+- 出口:root==null 返回true
+
+### 三、题解
+
+```java
+/**
+ * Definition for a binary tree node.
+ * public class TreeNode { int val; TreeNode
+ * left; TreeNode right; TreeNode(int x) { val = x; } }
+ */
+class Solution {
+ public boolean isSymmetric(TreeNode root) {
+ if (root == null)return true;//出口条件
+ return isMirror(root.left, root.right);
+ }
+
+ public boolean isMirror(TreeNode left,TreeNode right){
+ if(left==null&&right==null)return true;
+ if(left==null||right==null)return false;
+ if(left.val!=right.val)return false;
+ return isMirror(left.left,right.right)&&isMirror(left.right,right.left);
+ }
+}
+```
+
+
+
diff --git "a/2018.12.04-leetcode101/\351\230\263.md" "b/2018.12.04-leetcode101/\351\230\263.md"
new file mode 100644
index 000000000..819d77ef9
--- /dev/null
+++ "b/2018.12.04-leetcode101/\351\230\263.md"
@@ -0,0 +1,32 @@
+/**
+ * Definition for a binary tree node.
+ * public class TreeNode {
+ * int val;
+ * TreeNode left;
+ * TreeNode right;
+ * TreeNode(int x) { val = x; }
+ * }
+ */
+class Solution {
+ public boolean isSymmetric(TreeNode root) {
+ if(root == null) {
+ return true;//根节点为空,返回true
+ }else {
+ return isSymmetric(root.left, root.right);
+ }
+ }
+ public boolean isSymmetric(TreeNode pleft, TreeNode pright) {
+ if(pleft == null && pright == null) {
+ return true;//说明只有一个根节点,返回true
+ }
+ if(pleft == null || pright == null) {
+ return false;//一个子树为空,另一个子树不为空,返回false
+ }
+ //都不为空的情况下判断是否相等
+ if(pleft.val != pright.val) {
+ return false;
+ }
+ //继续判断左子树与右子树是否对称相等
+ return isSymmetric(pleft.left, pright.right)&&isSymmetric(pleft.right, pright.left);
+ }
+}
diff --git a/2018.12.05-leetcode102/-.md b/2018.12.05-leetcode102/-.md
new file mode 100644
index 000000000..65b48bfbe
--- /dev/null
+++ b/2018.12.05-leetcode102/-.md
@@ -0,0 +1,34 @@
+public class Solution_102 {
+ public List> levelOrder(TreeNode root) {
+ List> result = new ArrayList<>();
+
+ List list = new ArrayList<>();
+ if(root==null)
+ return result;
+ list.add(root);
+ while (list.size() != 0) {
+ List temp = new ArrayList<>();
+ List list2 = new ArrayList<>();
+ for (TreeNode node : list) {
+ temp.add(node.val);
+ if(node.left!=null)
+ list2.add(node.left);
+ if (node.right!=null)
+ list2.add(node.right);
+ }
+ result.add(temp);
+ list=list2;
+ }
+
+ return result;
+ }
+}
+class TreeNode {
+ int val;
+ TreeNode left;
+ TreeNode right;
+
+ TreeNode(int x) {
+ val = x;
+ }
+}
diff --git a/2018.12.05-leetcode102/Avalon.md b/2018.12.05-leetcode102/Avalon.md
new file mode 100644
index 000000000..4279df10a
--- /dev/null
+++ b/2018.12.05-leetcode102/Avalon.md
@@ -0,0 +1,35 @@
+/**
+ * Definition for a binary tree node.
+ * public class TreeNode {
+ * int val;
+ * TreeNode left;
+ * TreeNode right;
+ * TreeNode(int x) { val = x; }
+ * }
+ */
+class Solution {
+ public List> levelOrder(TreeNode root) {
+ List> list = new ArrayList>();
+ //List templist=new ArrayList();//这个list 没有实现对应接口
+ LinkedList llist = new LinkedList();//但是这个 linkedlist 实现了 deque 接口
+ //LinkedList templist = new LinkedList();//临时队列-用于存放同一排
+ if (root == null)return list;
+ llist.add(root);
+ TreeNode current;
+ while (!llist.isEmpty() ) {
+ List templist = new ArrayList();
+ int templen = llist.size();
+ for (int i=0;i
+### 1.2 输入与输出
+输入:
+* TreeNode* root:二叉树的根节点指针
+输出:
+* vector>:层次遍历的结果,是一个二维矢量的形式
+### 1.3 样例
+#### 1.3.1 样例1
+输入: 给定二叉树: [3,9,20,null,null,15,7],
+
+ 3
+ / \
+ 9 20
+ / \
+ 15 7
+
+输出:
+
+ [
+ [3],
+ [9,20],
+ [15,7]
+ ]
+
+## 2 思路描述与代码
+### 2.1 思路描述(基于队列的二叉树层次遍历)
+二叉树的层次遍历可以利用队列来做,其思路也很简单。
+这里为了把每层的结果记录下来,对BFS的代码结构稍微改动了下,即里面用了个 for 循环做当前层遍历。
+```cpp
+初始化二叉树层次遍历的二维矢量 res ;
+头结点入队;
+while( 队列不空 ){
+ 初始化当前层的遍历结果 level;
+ 获取当前层的数目数 len;
+ for( int i = 0; i < len; i++ ){
+ 取出当前层的节点tmp并保存至 level;
+ 左右孩子非空则入队;
+ }
+ 将 level 保存至 res ;
+}
+返回 res ;
+```
+比如给定二叉树: [3,9,20,null,null,15,7];
+首先根节点3入队,然后进入 while 循环;
+此时队列不空,有1个元素3,for 循环后有 res = {[3]}, 队列里面有元素[9, 20];
+此时队列不空,有元素[9, 20],for 循环后有 res = {[3],[9,20]}, 队列里面有元素[15, 7];
+此时队列不空,有元素[15, 7],for 循环后有 res = {[3],[9,20], [15,7]}, 队列里面没有元素;
+此时队列空后,返回 res = {[3],[9,20], [15,7]} 。
+
+### 2.2 代码
+```cpp
+vector> levelOrder(TreeNode* root) {
+ vector> res;
+ //如果输入为空
+ if (root == NULL) {
+ return res;
+ }
+ //队列做BFS
+ queue q;
+ q.push(root);
+ while( !q.empty() ){
+ //获取当前层的数目
+ int len = q.size();
+ vector level;
+ TreeNode* tmp;
+ for( int i = 0; i < len; i++ ){
+ //取一节点放入当前层的结果矢量里
+ tmp = q.front();
+ q.pop();
+ level.push_back(tmp->val);
+ //当前层所有的节点如果有孩子节点则压入队列
+ if(tmp->left){
+ q.push(tmp->left);
+ }
+ if(tmp->right){
+ q.push(tmp->right);
+ }
+ }
+ res.push_back(level);
+ }
+ return res;
+}
+```
+## 3 思考与拓展
+### 3.1 思考
+本题,利用队列做二叉树的层次遍历并保存结果。当然你可以利用堆栈做,但是保存结果的方式不一样而已。
+#### 3.1.1 其他方法
+#### 3.1.1.1 基于堆栈的二叉树层次遍历
+思路还是一致的,只是数据结构换了而已。在每层遍历的时候,需要改动的地方有:
+1. 入堆栈要右子树(如果有的话)先入,左子树(如果有的话)后入;
+2. 当前层遍历结果 level 要反序再 push_back 至 res。
+#### 3.1.2 复杂度分析
+方法|空间复杂度|时间复杂度
+--- | --- | ---
+基于队列的二叉树层次遍历|O(2^h),h是树的高度|O(n)
+基于堆栈的二叉树层次遍历|O(2^h),h是树的高度|O(n),由于多了一步反序,所以会比基于队列的慢一点
+#### 3.1.3 难点分析
+1. 采用什么数据结果做层次遍历
+2. 如何保存每层的遍历结果
+### 3.2 拓展
+如果让你[锯齿形层次遍历](https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal/)呢?
diff --git a/2018.12.05-leetcode102/Despacito.md b/2018.12.05-leetcode102/Despacito.md
new file mode 100644
index 000000000..b34b10c89
--- /dev/null
+++ b/2018.12.05-leetcode102/Despacito.md
@@ -0,0 +1,57 @@
+# leetcode 102 Binary Tree Level Order Traversal
+## 1. Description
+Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).
+
+For example:
+Given binary tree [3,9,20,null,null,15,7],
+
+ 3
+ / \
+ 9 20
+ / \
+ 15 7
+
+ return its level order traversal as:
+```python
+[
+ [3],
+ [9, 20],
+ [15, 7]
+]
+```
+
+## 2. Solution
+```python
+# Definition for a binary tree node.
+# class TreeNode:
+# def __init__(self, x):
+# self.val = x
+# self.left = None
+# self.right = None
+
+class Solution:
+ def levelOrder(self, root):
+ """
+ :type root: TreeNode
+ :rtype: List[List[int]]
+ """
+ if not root:
+ return []
+ l = [root, '#']
+ result = []
+ level = []
+ while len(l) > 1:
+ curr = l.pop(0)
+ if curr != '#':
+ level.append(curr.val)
+ if curr.left:
+ l.append(curr.left)
+ if curr.right:
+ l.append(curr.right)
+ else:
+ l.append('#')
+ result.append(level)
+ level = []
+ result.append(level)
+ return result
+```
diff --git a/2018.12.05-leetcode102/FFFro.md b/2018.12.05-leetcode102/FFFro.md
new file mode 100644
index 000000000..3ea1051f8
--- /dev/null
+++ b/2018.12.05-leetcode102/FFFro.md
@@ -0,0 +1,27 @@
+import java.util.ArrayList;
+import java.util.List;
+
+class Solution {
+ public List> levelOrder(TreeNode root) {
+ List> list = new ArrayList<>();
+ if (root == null) {
+ return list;
+ }
+ levelOrder(root,0,list);
+ return list;
+ }
+
+ private void levelOrder(TreeNode root, int i, List> list) {
+ if (root == null)
+ return;
+ if (list.size() == i){
+ List a = new ArrayList<>();
+ a.add(root.val);
+ list.add(a);
+ }else {
+ list.get(i).add(root.val);
+ }
+ levelOrder(root.left,i+1,list);
+ levelOrder(root.right,i+1,list);
+ }
+}
diff --git a/2018.12.05-leetcode102/Felix.md b/2018.12.05-leetcode102/Felix.md
new file mode 100644
index 000000000..84d34ab21
--- /dev/null
+++ b/2018.12.05-leetcode102/Felix.md
@@ -0,0 +1,20 @@
+```javascript
+public static void levelOrder(Node head){
+ if(head == null){
+ return;
+ }
+ Queue queue = new LinkedList<>();
+ queue.offer(head);
+ while(!queue.isEmpty()){
+ head = queue.poll();
+ System.out.print(head.value + " ");
+ if(head.left != null){
+ queue.offer(head.left);
+ }
+ if(head.right != null){
+ queue.offer(head.right);
+ }
+ }
+ }
+
+```
diff --git a/2018.12.05-leetcode102/GatesMa.md b/2018.12.05-leetcode102/GatesMa.md
new file mode 100644
index 000000000..345e13394
--- /dev/null
+++ b/2018.12.05-leetcode102/GatesMa.md
@@ -0,0 +1,21 @@
+# C++
+```cpp
+class Solution {
+public:
+ vector> res;
+ void check(TreeNode* root, int depth){
+ if(root == NULL) return ;
+ if(res.size() == depth)
+ {
+ res.push_back(vector());
+ }
+ res[depth].push_back(root->val);
+ check(root->left, depth + 1);
+ check(root->right, depth + 1);
+ }
+ vector> levelOrder(TreeNode* root) {
+ check(root, 0);
+ return res;
+ }
+};
+```
diff --git a/2018.12.05-leetcode102/Istoryforever.md b/2018.12.05-leetcode102/Istoryforever.md
new file mode 100644
index 000000000..f72c7ad8a
--- /dev/null
+++ b/2018.12.05-leetcode102/Istoryforever.md
@@ -0,0 +1,47 @@
+leetcode of 102
+```
+/**
+ * Definition for a binary tree node.
+ * struct TreeNode {
+ * int val;
+ * TreeNode *left;
+ * TreeNode *right;
+ * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
+ * };
+ */
+struct DataNode{
+ TreeNode * p;
+ int depth;
+};
+class Solution {
+public:
+ vector> levelOrder(TreeNode* root) {
+ vector> ans;
+ if(root == nullptr) return ans;
+ queue q;
+ int depth = 0;
+ q.push(DataNode{root,depth});
+ vectort;
+ while(!q.empty()){
+ DataNode dn = q.front();
+ q.pop();
+ if(depth == dn.depth){
+ t.push_back(dn.p->val);
+ }else{
+ depth = dn.depth;
+ ans.push_back(t);
+ t.clear();
+ t.push_back(dn.p->val);
+ }
+ if(dn.p->left != nullptr)
+ q.push(DataNode{dn.p->left,depth+1});
+ if(dn.p->right != nullptr)
+ q.push(DataNode{dn.p->right,depth+1});
+
+ }
+ ans.push_back(t);
+ return ans;
+
+ }
+};
+```
diff --git a/2018.12.05-leetcode102/MQQM.cpp b/2018.12.05-leetcode102/MQQM.cpp
new file mode 100644
index 000000000..8920a14b2
--- /dev/null
+++ b/2018.12.05-leetcode102/MQQM.cpp
@@ -0,0 +1,48 @@
+/*
+ 题目:
+ 给定一个二叉树,返回其按层次遍历的节点值。 (即逐层地,从左到右访问所有节点)。
+
+ 做法:用队列。
+*/
+
+/**
+ * Definition for a binary tree node.
+ * struct TreeNode {
+ * int val;
+ * TreeNode *left;
+ * TreeNode *right;
+ * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
+ * };
+ */
+class Solution {
+public:
+ vector> levelOrder(TreeNode* root) {
+ vector