From 74c7d61a24a45eda340db25ee664925a57a8f05e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Fri, 28 Sep 2018 15:08:28 +0800 Subject: [PATCH 001/108] commit --- .gitignore | 4 ++ .idea/modules.xml | 1 + .../Main.class" | Bin 715 -> 0 bytes .../Solution.class" | Bin 1320 -> 0 bytes .../Main.class" | Bin 666 -> 0 bytes .../Solution.class" | Bin 1800 -> 0 bytes .../Main.class" | Bin 681 -> 0 bytes .../Solution.class" | Bin 717 -> 0 bytes .../src/Solution.java" | 56 ++++++++++++++++++ 9 files changed, 61 insertions(+) create mode 100644 .gitignore delete mode 100644 "out/production/\343\200\220005\343\200\221\343\200\220LongestValidParentheses\343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220005\343\200\221\343\200\220LongestValidParentheses\343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220013\343\200\221\343\200\2203Sum\343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220013\343\200\221\343\200\2203Sum\343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220152\343\200\221\343\200\220FindMinimumInRotatedSortedArray\343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220152\343\200\221\343\200\220FindMinimumInRotatedSortedArray\343\200\221/Solution.class" create mode 100644 "\343\200\220037\343\200\221\343\200\220Sudoku Solver\343\200\221/src/Solution.java" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bc91813 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +# Created by .ignore support plugin (hsz.mobi) +*.iml +.idea + diff --git a/.idea/modules.xml b/.idea/modules.xml index be74181..8b8b050 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -37,6 +37,7 @@ + diff --git "a/out/production/\343\200\220005\343\200\221\343\200\220LongestValidParentheses\343\200\221/Main.class" "b/out/production/\343\200\220005\343\200\221\343\200\220LongestValidParentheses\343\200\221/Main.class" deleted file mode 100644 index b69cb499ca853a26c6c0d72dd6822d50db6a4b3f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 715 zcmZuu-A>d%7(KIFw%t+%7Z(&!`4MaZsU%)#Fy5G$kW?jEvx)I)c9|?gx~*wvO}zAx z-~tj&d;lNHc&5bw32oBvd_Qx}`KEvV{`?K#1$KP|SaR{uM*~Z3Ji=oS%Qji@v5GYh zPdu!9*l_XGMJUjEtut-j2sFc}FW|h*50$`7qBHejG9IYnlN_Y1bdr21)4nXU%`b|M zInpILlJ`<)dptd66qpacB**fbj8mD7;+`pVHrlJ$WijIX+zo93uguel(K!kHq<4Wy z>i6f7=?Tzj@KY0oVBnj zS2bI5EIT`w=06UO)zDlk^}d%zjVY5)*yz@q>O4N+nug0NIi~A{G|xt=G<})s!vk5U z%p9pwarH%~x$E=OJ=(1uD|3H&;z^h+qd_G4rIfb*;nL0!33~q(JE4Y0H`!&84 pT%@EW_ux}t8q1X3rq7pjYE8`7LW~Q{JnZ5g?$d_ABJ&0w`~y+Hj9~x( diff --git "a/out/production/\343\200\220005\343\200\221\343\200\220LongestValidParentheses\343\200\221/Solution.class" "b/out/production/\343\200\220005\343\200\221\343\200\220LongestValidParentheses\343\200\221/Solution.class" deleted file mode 100644 index 8c0a6656434a32c517eb4c5ae13f6a5f64187d46..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1320 zcmZux-ES0C6#w1b`DmxJP?j!Vby1LyS+-?SVNthK>Qbb-1!GM~eY>5#ZU<&}>+Ebr z9@NCXn5Z$~)fm!{^g&*HX+;v{i3k5AV#ME_ZCM(aa$fC*T#=0mI0{;gN?}GIZl}J*9mSDNxPxqp5ci1e6TG`fkB;~i`Atu z3t|CIq?+v&^^)-03pS4<*v*ecKPhl`kmb3TT#0YNw|Qz4;`c;7!qZBG4syJ^Jp=5+ zesb&*2YJ$2+~Fr@Q+BWT7(>Mkq|7y#>H80nUf6^&o1RRUjda<}nOe7ouZuZz17_LE zS-;T>SR|!L9%+s`I2#yRC|kqcT^w9BQu&;* z1}kSwQtt{}Uq_Zn*Wo@yW}&!=U4O5dV*Tki`TLA*K=<}Zavow|qu7N!`+AiVxafp#D z9L6eMVRVxj?`>hHZ-<$UUnYKH#v|B=q iQ_j({angooqaXxl_bmU!f22LX{xfk5|yXEZrXrsbtj{B=<#bKXH- zF)?W1bsl~sc}f06%?aX`2St*^6@{z8{<~o#BXSx>dQno*ucurt6p%-zO-hPE@Xx(8 z9K087K=MnO#{ypw9``HsLRvxFdVB)$y-xew+jUUlD$jl+z%{JU>!6G4jF{qY)LFD| z&tQ#DU`IdTJdr=Wv2BmW4p)n-ZI6!8I!4s~C`mKLmXXH~s*NzKG5M diff --git "a/out/production/\343\200\220013\343\200\221\343\200\2203Sum\343\200\221/Solution.class" "b/out/production/\343\200\220013\343\200\221\343\200\2203Sum\343\200\221/Solution.class" deleted file mode 100644 index bd9bfe8e88bba17d5a00948ad5f9d776b35e16ac..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1800 zcma)6-%}e^6#njJHyc9ek3cA~AgINL29l~3+J>S)rNxHQHU)}|4hz}BLP+AWsY73U zka6@c@U_$F$fMdBp~?)8ozWNn2%qZs57=pm-`!0L5gyD;_TGEWchCLKch0@P@BX?2 z;2iD*5k^8sG6)5UAkN~QI=qYbbes#qFD-t&A3(1h`{d_*5EpP!M=FR0^apVX1NHa- zAL!p=B)4pxYbFllhE=25t&8?gbyTZDUQwmgnBmkqO~8CYWvrlbB+OtK?Y3y|c#Wmdtt9=g3|l8Ka7E z6>uZ7qUvhFrbm;4vFr9l$*iq9CVR(MC=n3xN@W$2H<*aSbWCG~h4352qM6SMw8p9( zb}(P!dSd%}z!M`?>BvLz0jJ=hWb+;bGNLC_Eg=EDDCy<$WPI3(@?w!FhvR#CRa%mp z?-{w0IewR|U7Jm{X{m;hWwJG~J-Jg|pWqD~=c6Eh3P=!5{6@G+augi3Gg}Zpx$b6u z{jM>D6P$-U09p{`O5in|WDssvzJdy!rm1Zx(_8S3#h;3Fd`EjEM&eJP`Ucv#$UYS3 z+tk@!HNK-}d$ouf(H;u@F|=*?xk-<=B{mTV*KHygkEr|Rnw)QuZ`WO-9J)p6|x*(vwlDy0(_^#NYQo)9eklXF^D*Z`M6)kEUuu4QQYUf{RY?Y z9n$!o*Y^ir-N(3zpLsuj!vy}o9sG%DJi`qB#;16J&rrs!XoMl6xGP$*D9*wXy(owa z_*|r6i(7ES1iojY`|d*_(Ka z?Gq5=IK{mR*@KxVm1u7>n&&%BTa3O_Xn2Vh9bMuj!a}^jx12|xBdUa>N>up=EzgNO NL!?3#1iIZ>&%bobsqFv& diff --git "a/out/production/\343\200\220152\343\200\221\343\200\220FindMinimumInRotatedSortedArray\343\200\221/Main.class" "b/out/production/\343\200\220152\343\200\221\343\200\220FindMinimumInRotatedSortedArray\343\200\221/Main.class" deleted file mode 100644 index 6b254cfae34b0c14421631ecce85292279a7b419..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 681 zcmZvaU2D`p7==%=NhXQWj;&qmx3zv`72F%|DuM{YLTZGSg|t_*+qj*QO(dHY{8@U@ zii$tLA0?j2u9S+o$UE;l=bSu~LFNBXRfomabYz4TE8)kJg#4X$wxFc}a zg7;jPx_M!t6Zb|IoLALhZecCaW&UO{8|U>qH7+<=PpXM3Myl4PUk#n+NY9y(>?vLD z(mi9f(2Wn0WA#z>3sp}0!=~2dbhk}c^_2RJ|7=_E=T)(2bj5%$8Lrk04TsgDp5(8! z!3fNgo|^Co0YbX|Dh0M9+`~?U`*)-K$Z j%jcn9l53yDbCMhO?vfAd*kI?Qz!hwgp8p4X8(04TFQ|m0 diff --git "a/out/production/\343\200\220152\343\200\221\343\200\220FindMinimumInRotatedSortedArray\343\200\221/Solution.class" "b/out/production/\343\200\220152\343\200\221\343\200\220FindMinimumInRotatedSortedArray\343\200\221/Solution.class" deleted file mode 100644 index 1ea61e81d4f7b4b59cd58c4ac1b0690993418f04..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 717 zcmYLGO>fgc6r8o!apERT`3PTiN`qR|)F?qBL`eOJ5CSPu3WuOdsF!XWle#!gbHeY-Pn-tN!8Uq%3GShSGByb0TahItDHiY69J z+!RQy`=K9i3g|24Z2|dc(DelJEkE?04*MN1dagPFD;HY>R|VTD^2h6GQO0}zp@7wD z4}xLr55hG8^Q9klxBO7RSlMZoo74=4eV)>Gh;!{&xv#d=!BipJ@k158ZF?$m_edtC znUIXbSVggbAW8SaE@R(kwAzDVxPt=*~!XKSLgKUr#h= znSn(zOSpigMElBwKh>rZ=D5fA;YkTCV-jH;+z#IeO*X((Po7GL1RBkvnW%#RBeP8TW{4xQ_=| v!$xAYHfjCeYGZ1Zc2K}%kOr<2>HOAljYuYgWFY@Q7p1(xIj+;ch8zC?Lt%D> diff --git "a/\343\200\220037\343\200\221\343\200\220Sudoku Solver\343\200\221/src/Solution.java" "b/\343\200\220037\343\200\221\343\200\220Sudoku Solver\343\200\221/src/Solution.java" new file mode 100644 index 0000000..299431d --- /dev/null +++ "b/\343\200\220037\343\200\221\343\200\220Sudoku Solver\343\200\221/src/Solution.java" @@ -0,0 +1,56 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-09-28 15:06 + **/ +public class Solution { + public void solveSudoku(char[][] board) { + if(board == null || board.length == 0) { + return; + } + solve(board); + } + + public boolean solve(char[][] board){ + for(int i = 0; i < board.length; i++){ + for(int j = 0; j < board[0].length; j++){ + if(board[i][j] == '.'){ + // 尝试1到9的数字 + for(char c = '1'; c <= '9'; c++){ + if(isValid(board, i, j, c)){ + // 将字符放入单元格 + board[i][j] = c; + + // 如果字符可以放入单元格返回true + if(solve(board)){ + return true; + }else { // 如果字符不能放入单元格就是还原成点号 + board[i][j] = '.'; + } + } + } + return false; + } + } + } + return true; + } + + private boolean isValid(char[][] board, int row, int col, char c){ + for(int i = 0; i < 9; i++) { + // 检查行 + if(board[i][col] != '.' && board[i][col] == c) { + return false; + } + // 检查列 + if(board[row][i] != '.' && board[row][i] == c) { + return false; + } + // 检查3*3的单元格 + if(board[3 * (row / 3) + i / 3][ 3 * (col / 3) + i % 3] != '.' + && board[3 * (row / 3) + i / 3][3 * (col / 3) + i % 3] == c) { + return false; + } + } + return true; + } +} From f415e9cfb28e741551caafc084f0a6aeaff32aa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Fri, 28 Sep 2018 15:12:34 +0800 Subject: [PATCH 002/108] commit --- .idea/modules.xml | 1 + .../src/Solution.java" | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 "\343\200\220039\343\200\221\343\200\220Combination Sum\343\200\221/src/Solution.java" diff --git a/.idea/modules.xml b/.idea/modules.xml index 8b8b050..afeb1bf 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -39,6 +39,7 @@ + diff --git "a/\343\200\220039\343\200\221\343\200\220Combination Sum\343\200\221/src/Solution.java" "b/\343\200\220039\343\200\221\343\200\220Combination Sum\343\200\221/src/Solution.java" new file mode 100644 index 0000000..05d51b7 --- /dev/null +++ "b/\343\200\220039\343\200\221\343\200\220Combination Sum\343\200\221/src/Solution.java" @@ -0,0 +1,43 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +/** + * @author: wangjunchao(王俊超) + * @time: 2018-09-28 15:11 + **/ +public class Solution { + public List> combinationSum(int[] nums, int target) { + // 用于保存结果 + List> list = new LinkedList<>(); + Arrays.sort(nums); + backtrack(list, new ArrayList<>(), nums, target, 0); + return list; + } + + // 回溯法 + // list:保存总的结果 + // tempList:保存临时结果 + // nums:输入的数组 + // remain:剩下的值 + // start:可用的值在数组中的起始位置 + private void backtrack(List> list, List tempList, int [] nums, int remain, int start){ + // 不够减 + if(remain < 0) { + return; + } else if(remain == 0) { // 刚好够减 + list.add(new LinkedList<>(tempList)); + } else { + // 从剩下的数中一个一个尝试 + for(int i = start; i < nums.length; i++){ + // 假设这个值是临时结果中的一个值 + tempList.add(nums[i]); + // 处理下一步 + backtrack(list, tempList, nums, remain - nums[i], i); + // 现场还原 + tempList.remove(tempList.size() - 1); + } + } + } +} From 5916c6237ea4578690d9fefa6fb41309b6ecd34b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Fri, 28 Sep 2018 15:15:42 +0800 Subject: [PATCH 003/108] commit --- .idea/modules.xml | 1 + .../src/Solution.java" | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 "\343\200\220040\343\200\221\343\200\220Combination Sum II\343\200\221/src/Solution.java" diff --git a/.idea/modules.xml b/.idea/modules.xml index afeb1bf..4bd98ee 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -40,6 +40,7 @@ + diff --git "a/\343\200\220040\343\200\221\343\200\220Combination Sum II\343\200\221/src/Solution.java" "b/\343\200\220040\343\200\221\343\200\220Combination Sum II\343\200\221/src/Solution.java" new file mode 100644 index 0000000..e809d3a --- /dev/null +++ "b/\343\200\220040\343\200\221\343\200\220Combination Sum II\343\200\221/src/Solution.java" @@ -0,0 +1,42 @@ +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +/** + * @author: wangjunchao(王俊超) + * @time: 2018-09-28 15:15 + **/ +public class Solution { + public List> combinationSum2(int[] nums, int target) { + List> list = new LinkedList<>(); + Arrays.sort(nums); + backtrack(list, new LinkedList<>(), nums, target, 0); + return list; + + } + + /** + * @param list 结果集 + * @param tempList 临时结果集 + * @param nums 可选值数组 + * @param remain 剩余值 + * @param start 可选值的起始下标 + */ + private void backtrack(List> list, List tempList, int[] nums, int remain, int start) { + if (remain < 0) { + return; + } else if (remain == 0) { + list.add(new LinkedList<>(tempList)); + } else { + for (int i = start; i < nums.length; i++) { + if (i > start && nums[i] == nums[i - 1]) { + continue; + } + tempList.add(nums[i]); + // 数值不可以被重用 + backtrack(list, tempList, nums, remain - nums[i], i + 1); + tempList.remove(tempList.size() - 1); + } + } + } +} From 1f5d201de5b3797fb89014f08c422c5a3820eed3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Fri, 28 Sep 2018 15:19:06 +0800 Subject: [PATCH 004/108] commit --- .idea/modules.xml | 1 + .../src/Solution.java" | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 "\343\200\220041\343\200\221\343\200\220First Missing Positive\343\200\221/src/Solution.java" diff --git a/.idea/modules.xml b/.idea/modules.xml index 4bd98ee..10c4596 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -41,6 +41,7 @@ + diff --git "a/\343\200\220041\343\200\221\343\200\220First Missing Positive\343\200\221/src/Solution.java" "b/\343\200\220041\343\200\221\343\200\220First Missing Positive\343\200\221/src/Solution.java" new file mode 100644 index 0000000..7fb1d3c --- /dev/null +++ "b/\343\200\220041\343\200\221\343\200\220First Missing Positive\343\200\221/src/Solution.java" @@ -0,0 +1,27 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-09-28 15:18 + **/ +public class Solution { + public int firstMissingPositive(int[] nums) { + int n = nums.length; + for (int i = 0; i < n; i++) { + while (nums[i] > 0 && nums[i] <= n && nums[i] != nums[nums[i] - 1]) { + swap(nums, i, nums[i] - 1); + } + } + for (int i = 0; i < n; i++) { + if (nums[i] != i + 1) { + return i + 1; + } + } + + return n + 1; + } + + private void swap(int[] nums, int i, int j) { + int temp = nums[i]; + nums[i] = nums[j]; + nums[j] = temp; + } +} From 98248e69758c8281f4434210b31104d5b561e1de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Fri, 28 Sep 2018 15:21:08 +0800 Subject: [PATCH 005/108] commit --- .idea/modules.xml | 1 + .../src/Solution.java" | 105 ++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 "\343\200\220042\343\200\221\343\200\220Trapping Rain Water\343\200\221/src/Solution.java" diff --git a/.idea/modules.xml b/.idea/modules.xml index 10c4596..7b4a90e 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -42,6 +42,7 @@ + diff --git "a/\343\200\220042\343\200\221\343\200\220Trapping Rain Water\343\200\221/src/Solution.java" "b/\343\200\220042\343\200\221\343\200\220Trapping Rain Water\343\200\221/src/Solution.java" new file mode 100644 index 0000000..f057b8f --- /dev/null +++ "b/\343\200\220042\343\200\221\343\200\220Trapping Rain Water\343\200\221/src/Solution.java" @@ -0,0 +1,105 @@ +import java.util.Deque; +import java.util.LinkedList; + +/** + * @author: wangjunchao(王俊超) + * @time: 2018-09-28 15:20 + **/ +class Solution { + + public int trap(int[] height) { + return trap4(height); + } + + public int trap1(int[] height) { + int ans = 0; + int size = height.length; + for (int i = 1; i < size - 1; i++) { + int maxLeft = 0; + int maxRight = 0; + for (int j = i; j >= 0; j--) { //Search the left part for max bar size + maxLeft = Math.max(maxLeft, height[j]); + } + for (int j = i; j < size; j++) { //Search the right part for max bar size + maxRight = Math.max(maxRight, height[j]); + } + + // TODO 原理是什么? + ans += Math.min(maxLeft, maxRight) - height[i]; + } + return ans; + } + + int trap2(int[] height) { + if (height == null || height.length == 0) { + return 0; + } + int ans = 0; + int size = height.length; + int[] leftMax = new int[size]; + int[] rightMax = new int[size]; + + leftMax[0] = height[0]; + for (int i = 1; i < size; i++) { + leftMax[i] = Math.max(height[i], leftMax[i - 1]); + } + + rightMax[size - 1] = height[size - 1]; + for (int i = size - 2; i >= 0; i--) { + rightMax[i] = Math.max(height[i], rightMax[i + 1]); + } + + for (int i = 1; i < size - 1; i++) { + ans += Math.min(leftMax[i], rightMax[i]) - height[i]; + } + return ans; + } + + int trap3(int[] height) { + int ans = 0, current = 0; + Deque st = new LinkedList<>(); + while (current < height.length) { + while (!st.isEmpty() && height[current] > height[st.getFirst()]) { + int top = st.peek(); + st.pop(); + if (st.isEmpty()) { + break; + } + int distance = current - st.peek() - 1; + int boundedHeight = Math.min(height[current], height[st.peek()]) - height[top]; + ans += distance * boundedHeight; + } + st.push(current++); + } + return ans; + } + + int trap4(int[] height) { + int left = 0; + int right = height.length - 1; + int ans = 0; + int leftMax = 0; + int rightMax = 0; + + while (left < right) { + if (height[left] < height[right]) { + if (height[left] >= leftMax) { + leftMax = height[left]; + } else { + ans += leftMax - height[left]; + } + + ++left; + } else { + if (height[right] >= rightMax) { + rightMax = height[right]; + } else { + ans += rightMax - height[right]; + } + + --right; + } + } + return ans; + } +} From c3e974f7d5b7fa44c565c436fd534d095d2c98c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Fri, 28 Sep 2018 15:23:41 +0800 Subject: [PATCH 006/108] commit --- .idea/modules.xml | 1 + .../src/Solution.java" | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 "\343\200\220043\343\200\221\343\200\220Multiply Strings\343\200\221/src/Solution.java" diff --git a/.idea/modules.xml b/.idea/modules.xml index 7b4a90e..1e281e8 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -43,6 +43,7 @@ + diff --git "a/\343\200\220043\343\200\221\343\200\220Multiply Strings\343\200\221/src/Solution.java" "b/\343\200\220043\343\200\221\343\200\220Multiply Strings\343\200\221/src/Solution.java" new file mode 100644 index 0000000..1570a3f --- /dev/null +++ "b/\343\200\220043\343\200\221\343\200\220Multiply Strings\343\200\221/src/Solution.java" @@ -0,0 +1,42 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-09-28 15:23 + **/ +public class Solution { + public String multiply(String num1, String num2) { + int m = num1.length(), n = num2.length(); + int[] pos = new int[m + n]; + + int mul; + int index; + int temp; + for (int i = m - 1; i >= 0; i--) { + for (int j = n - 1; j >= 0; j--) { + // 求积 + mul = (num1.charAt(i) - '0') * (num2.charAt(j) - '0'); + // 积的最低位所在的位置 + index = i + j + 1; + + // 最低低求和 + pos[index] += mul; + + // 做进位处理 + while (pos[index] > 9) { + temp = pos[index]; + pos[index] = temp % 10; + --index; + pos[index] += temp / 10; + } + + } + } + + StringBuilder sb = new StringBuilder(); + for (int p : pos) { + if (!(sb.length() == 0 && p == 0)) { + sb.append(p); + } + } + return sb.length() == 0 ? "0" : sb.toString(); + } +} From 40579a3879ca75f3ef50bdb67150e5652cc85724 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Fri, 28 Sep 2018 15:25:40 +0800 Subject: [PATCH 007/108] commit --- .gitignore | 1 - .idea/modules.xml | 1 + .../src/Solution.java" | 54 +++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 "\343\200\220044\343\200\221\343\200\220Wildcard Matching\343\200\221/src/Solution.java" diff --git a/.gitignore b/.gitignore index bc91813..cd09efa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ # Created by .ignore support plugin (hsz.mobi) *.iml .idea - diff --git a/.idea/modules.xml b/.idea/modules.xml index 1e281e8..44111e0 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -44,6 +44,7 @@ + diff --git "a/\343\200\220044\343\200\221\343\200\220Wildcard Matching\343\200\221/src/Solution.java" "b/\343\200\220044\343\200\221\343\200\220Wildcard Matching\343\200\221/src/Solution.java" new file mode 100644 index 0000000..2f5d7e2 --- /dev/null +++ "b/\343\200\220044\343\200\221\343\200\220Wildcard Matching\343\200\221/src/Solution.java" @@ -0,0 +1,54 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-09-28 15:25 + **/ +public class Solution { + public boolean isMatch(String str, String pattern) { + // 匹配串的索引 + int s = 0; + // 模式串的索引 + int p = 0; + // 记录匹配的匹配位置 + int match = 0; + // 星号的起始索引 + int starIdx = -1; + while (s < str.length()) { + // 两个指针都往前推进 + if (p < pattern.length() && (pattern.charAt(p) == '?' || str.charAt(s) == pattern.charAt(p))) { + s++; + p++; + } + // 发现一个*,只前进模式串索引 + else if (p < pattern.length() && pattern.charAt(p) == '*') { + // 记录最后一次发现*的位置 + starIdx = p; + // 记录在匹配串中匹配*时的位置 + match = s; + // 模式串索引向前推进 + p++; + } + // last pattern pointer was *, advancing string pointer + // 最后的模式串索引是*,匹配串索引向前推进。这个条件隐含p >= pattern.length(),再加上starIdx != -1 + // 说明存在*号匹配,在星号匹配的 + else if (starIdx != -1) { + // 记录模式串最后处理的*号的下一个位置 + p = starIdx + 1; + // 记录在匹配串中匹配*时的位置 + match++; + // 匹配串索引向前推进 + s = match; + } + // 当前的模式索引指向的不是*号,最后一个模式索引指向的也不是*号,说明不匹配 + else { + return false; + } + } + + // 检查余下的模式串,模式串必须全都是*号才行 + while (p < pattern.length() && pattern.charAt(p) == '*') { + p++; + } + + return p == pattern.length(); + } +} From 2d7be6b9dd6ec579c691b9cba2f3b67bdec5e002 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Fri, 28 Sep 2018 15:28:00 +0800 Subject: [PATCH 008/108] commit --- .idea/modules.xml | 1 + .../src/Solution.java" | 49 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 "\343\200\220045\343\200\221\343\200\220Jump Game II\343\200\221/src/Solution.java" diff --git a/.idea/modules.xml b/.idea/modules.xml index 44111e0..a2c7623 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -45,6 +45,7 @@ + diff --git "a/\343\200\220045\343\200\221\343\200\220Jump Game II\343\200\221/src/Solution.java" "b/\343\200\220045\343\200\221\343\200\220Jump Game II\343\200\221/src/Solution.java" new file mode 100644 index 0000000..3f11ba2 --- /dev/null +++ "b/\343\200\220045\343\200\221\343\200\220Jump Game II\343\200\221/src/Solution.java" @@ -0,0 +1,49 @@ +/** + * 使用贪心算法,每次都移动最远的距离 + * + * @author: wangjunchao(王俊超) + * @time: 2018-09-28 15:27 + **/ +public class Solution { + + public int jump(int[] nums) { + + if (nums == null || nums.length < 2) { + return 0; + } + + // 记录跳跃次数 + int jump = 0; + // 记录当前可以到达的最远的位置 + int currentMax = 0; + // 下一次可以到达的最远的位置 + int nextMax = 0; + // 记录处理的位置 + int i = 0; + + // 还没有到最未位置,还可以移动 + while (currentMax - i + 1 > 0) { + // 跳数增加 + jump++; + // 找下一次最远可以移动的位置 + for (; i <= currentMax; i++) { + nextMax = Math.max(nextMax, nums[i] + i); + // 如果下一次可以移动到最末的位置,则返回跳数 + if (nextMax >= nums.length - 1) { + return jump; + } + } + + // 本次处理不能使移动位增加,并且不能到达最末位置,说明永远到不了最后的位置 + if (currentMax == nextMax) { + return Integer.MAX_VALUE; + } + + // 更新当前可以移动的最远位置 + currentMax = nextMax; + } + + return 0; + } + +} From 8004fe7fb726ec3abb46e34b30af8061ceb3e510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Fri, 28 Sep 2018 15:29:45 +0800 Subject: [PATCH 009/108] commit --- .idea/modules.xml | 1 + .../src/Solution.java" | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 "\343\200\220047\343\200\221\343\200\220Permutations II\343\200\221/src/Solution.java" diff --git a/.idea/modules.xml b/.idea/modules.xml index a2c7623..017d796 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -47,6 +47,7 @@ + diff --git "a/\343\200\220047\343\200\221\343\200\220Permutations II\343\200\221/src/Solution.java" "b/\343\200\220047\343\200\221\343\200\220Permutations II\343\200\221/src/Solution.java" new file mode 100644 index 0000000..ff6c4b5 --- /dev/null +++ "b/\343\200\220047\343\200\221\343\200\220Permutations II\343\200\221/src/Solution.java" @@ -0,0 +1,55 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * @author: wangjunchao(王俊超) + * @time: 2018-09-28 15:29 + **/ +public class Solution { + + public List> permuteUnique(int[] nums) { + List> res = new ArrayList<>(); + + if (nums == null || nums.length == 0){ + return res; + } + + boolean[] used = new boolean[nums.length]; + List list = new ArrayList<>(); + + Arrays.sort(nums); + + permuteUnique(nums, used, list, res); + return res; + } + + private void permuteUnique(int[] nums, boolean[] used, List list, List> res) { + if (list.size() == nums.length) { + res.add(new ArrayList<>(list)); + return; + } + + for (int i = 0; i < nums.length; i++) { + // 第i个数值已经被使用过 + if (used[i]) { + continue; + } + + // 第不个字符与前一个字符相等,并且第i-1个字符没有使用,说明此次不应该交换 + if (i > 0 && nums[i - 1] == nums[i] && !used[i - 1]) { + continue; + } + + // 标记第i个字符已经被使用 + used[i] = true; + // 添加到临时结果中 + list.add(nums[i]); + // 下一次处理 + permuteUnique(nums, used, list, res); + // 现场还原 + used[i] = false; + list.remove(list.size() - 1); + } + } +} From 71a30d770aae65070124b76f0fba6564f6ef0454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Fri, 28 Sep 2018 15:31:25 +0800 Subject: [PATCH 010/108] commit --- .idea/modules.xml | 1 + .../src/Solution.java" | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 "\343\200\220048\343\200\221\343\200\220Rotate Image\343\200\221/src/Solution.java" diff --git a/.idea/modules.xml b/.idea/modules.xml index 017d796..aedca48 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -48,6 +48,7 @@ + diff --git "a/\343\200\220048\343\200\221\343\200\220Rotate Image\343\200\221/src/Solution.java" "b/\343\200\220048\343\200\221\343\200\220Rotate Image\343\200\221/src/Solution.java" new file mode 100644 index 0000000..8a32e23 --- /dev/null +++ "b/\343\200\220048\343\200\221\343\200\220Rotate Image\343\200\221/src/Solution.java" @@ -0,0 +1,28 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-09-28 15:31 + **/ +public class Solution { + public void rotate(int[][] matrix) { + int temp; + + // 先做y=x对称转换 + for (int i = 0; i < matrix.length; i++) { + for (int j = i; j < matrix.length; j++) { + temp = matrix[i][j]; + matrix[i][j] = matrix[j][i]; + matrix[j][i] = temp; + } + } + + // 再对行进行水平转换 + int half = matrix.length / 2; + for (int i = 0; i < matrix.length; i++) { + for (int j = 0; j < half; j++) { + temp = matrix[i][j]; + matrix[i][j] = matrix[i][matrix.length - 1 - j]; + matrix[i][matrix.length - 1 - j] = temp; + } + } + } +} From 84f446904b54b33f3bd45a7e9258d6781628f6dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Fri, 28 Sep 2018 15:34:50 +0800 Subject: [PATCH 011/108] commit --- .idea/modules.xml | 1 + .../src/Solution.java" | 80 +++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 "\343\200\220049\343\200\221\343\200\220Group Anagrams\343\200\221/src/Solution.java" diff --git a/.idea/modules.xml b/.idea/modules.xml index aedca48..0292255 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -49,6 +49,7 @@ + diff --git "a/\343\200\220049\343\200\221\343\200\220Group Anagrams\343\200\221/src/Solution.java" "b/\343\200\220049\343\200\221\343\200\220Group Anagrams\343\200\221/src/Solution.java" new file mode 100644 index 0000000..3ff45ad --- /dev/null +++ "b/\343\200\220049\343\200\221\343\200\220Group Anagrams\343\200\221/src/Solution.java" @@ -0,0 +1,80 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author: wangjunchao(王俊超) + * @time: 2018-09-28 15:33 + **/ +public class Solution { + + public List> groupAnagrams(String[] strs) { + return groupAnagrams2(strs); + } + + /** + * 算法原理:对字符串进行排序,相同类型的字符串排序后的字符串都是一样的 + * + * @param strs + * @return + */ + public List> groupAnagrams1(String[] strs) { + if (strs.length == 0) { + return new ArrayList(); + } + Map ans = new HashMap<>(); + // 处理每一个字符串 + for (String s : strs) { + char[] ca = s.toCharArray(); + // 对象字符串对应的字符数组进行排序,再转成排序后的字符串 + Arrays.sort(ca); + String key = String.valueOf(ca); + // 如果map中不包含已经排序后的字符串,那么就创建一个新容器要放入结果 + if (!ans.containsKey(key)) { + ans.put(key, new ArrayList()); + } + + // 结果放入对应的集合中 + ans.get(key).add(s); + } + return new ArrayList(ans.values()); + } + + /** + * 算法原理:统计每个字符出现的次数,然后使用#字符将每个字符出现的次数拼成一个字符串, + * 相同类型的字符串通过上面的方式拼出来的字符串都是一样的 + * + * @param strs + * @return + */ + public List> groupAnagrams2(String[] strs) { + if (strs.length == 0) { + return new ArrayList(); + } + Map ans = new HashMap<>(); + int[] count = new int[26]; + + for (String s : strs) { + // 清零操作 + Arrays.fill(count, 0); + for (char c : s.toCharArray()) { + count[c - 'a']++; + } + + // 字符串拼接 + StringBuilder sb = new StringBuilder(""); + for (int i = 0; i < 26; i++) { + sb.append('#'); + sb.append(count[i]); + } + String key = sb.toString(); + if (!ans.containsKey(key)) { + ans.put(key, new ArrayList()); + } + ans.get(key).add(s); + } + return new ArrayList(ans.values()); + } +} From 11bd9907704589dcc48926beca079bd9a51083a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Fri, 28 Sep 2018 15:36:38 +0800 Subject: [PATCH 012/108] commit --- .idea/modules.xml | 1 + .../src/Solution.java" | 69 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 "\343\200\220051\343\200\221\343\200\220N-Queens\343\200\221/src/Solution.java" diff --git a/.idea/modules.xml b/.idea/modules.xml index 0292255..4c1f263 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -51,6 +51,7 @@ + diff --git "a/\343\200\220051\343\200\221\343\200\220N-Queens\343\200\221/src/Solution.java" "b/\343\200\220051\343\200\221\343\200\220N-Queens\343\200\221/src/Solution.java" new file mode 100644 index 0000000..7d31661 --- /dev/null +++ "b/\343\200\220051\343\200\221\343\200\220N-Queens\343\200\221/src/Solution.java" @@ -0,0 +1,69 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * @author: wangjunchao(王俊超) + * @time: 2018-09-28 15:36 + **/ +public class Solution { + public List> solveNQueens(int n) { + List> result = new ArrayList<>(); + + if (n < 1) { + return result; + } + + char[][] board = new char[n][]; + for (int i = 0; i < n; i++) { + board[i] = new char[n]; + Arrays.fill(board[i], '.'); + } + + solveNQueens(board, 0, result); + return result; + } + + private void solveNQueens(char[][] board, int row, List> result) { + if (board.length == row) { + List list = new ArrayList<>(); + for (char[] chs : board) { + list.add(new String(chs)); + } + result.add(list); + } + + for (int col = 0; col < board.length; col++) { + if (canPlace(board, row, col)) { + board[row][col] = 'Q'; + solveNQueens(board, row + 1, result); + board[row][col] = '.'; + } + } + } + + private boolean canPlace(char[][] board, int row, int col) { + // 检测之前的列上是否已经放过皇后 + for (int i = 0; i < row; ++i) { + if (board[i][col] == 'Q') { + return false; + } + } + + // 45度角(左下角)上是否已经存在过皇后 + for (int i = row - 1, j = col - 1; i >= 0 && j >= 0; --i, --j) { + if (board[i][j] == 'Q') { + return false; + } + } + + // 135度角上(左上角)是否已经存在过皇后 + for (int i = row - 1, j = col + 1; i >= 0 && j < board.length; --i, ++j) { + if (board[i][j] == 'Q') { + return false; + } + } + + return true; + } +} From 6046579743fdd7a41f71fa11ff6309574ce59d4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Fri, 28 Sep 2018 15:39:07 +0800 Subject: [PATCH 013/108] commit --- .idea/modules.xml | 2 +- .../src/Solution.java" | 63 +++++++++++++++++++ ...21\343\200\220N-QueensII \343\200\221.iml" | 11 ---- 3 files changed, 64 insertions(+), 12 deletions(-) create mode 100644 "\343\200\220052\343\200\221\343\200\220N-Queens II\343\200\221/src/Solution.java" delete mode 100644 "\343\200\220052\346\234\252\343\200\221\343\200\220N-QueensII \343\200\221/\343\200\220052\343\200\221\343\200\220N-QueensII \343\200\221.iml" diff --git a/.idea/modules.xml b/.idea/modules.xml index 4c1f263..503f331 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -52,7 +52,7 @@ - + diff --git "a/\343\200\220052\343\200\221\343\200\220N-Queens II\343\200\221/src/Solution.java" "b/\343\200\220052\343\200\221\343\200\220N-Queens II\343\200\221/src/Solution.java" new file mode 100644 index 0000000..5638da5 --- /dev/null +++ "b/\343\200\220052\343\200\221\343\200\220N-Queens II\343\200\221/src/Solution.java" @@ -0,0 +1,63 @@ +import java.util.Arrays; + +/** + * @author: wangjunchao(王俊超) + * @time: 2018-09-28 15:38 + **/ +public class Solution { + public int totalNQueens(int n) { + int[] result = {0}; + + if (n < 1) { + return result[0]; + } + + char[][] board = new char[n][]; + for (int i = 0; i < n; i++) { + board[i] = new char[n]; + Arrays.fill(board[i], '.'); + } + + solveNQueens(board, 0, result); + return result[0]; + } + + private void solveNQueens(char[][] board, int row, int[] result) { + if (board.length == row) { + result[0]++; + } + + for (int col = 0; col < board.length; col++) { + if (canPlace(board, row, col)) { + board[row][col] = 'Q'; + solveNQueens(board, row + 1, result); + board[row][col] = '.'; + } + } + } + + private boolean canPlace(char[][] board, int row, int col) { + // 检测之前的列上是否已经放过皇后 + for (int i = 0; i < row; ++i) { + if (board[i][col] == 'Q') { + return false; + } + } + + // 45度角(左下角)上是否已经存在过皇后 + for (int i = row - 1, j = col - 1; i >= 0 && j >= 0; --i, --j) { + if (board[i][j] == 'Q') { + return false; + } + } + + // 135度角上(左上角)是否已经存在过皇后 + for (int i = row - 1, j = col + 1; i >= 0 && j < board.length; --i, ++j) { + if (board[i][j] == 'Q') { + return false; + } + } + + return true; + } +} \ No newline at end of file diff --git "a/\343\200\220052\346\234\252\343\200\221\343\200\220N-QueensII \343\200\221/\343\200\220052\343\200\221\343\200\220N-QueensII \343\200\221.iml" "b/\343\200\220052\346\234\252\343\200\221\343\200\220N-QueensII \343\200\221/\343\200\220052\343\200\221\343\200\220N-QueensII \343\200\221.iml" deleted file mode 100644 index c90834f..0000000 --- "a/\343\200\220052\346\234\252\343\200\221\343\200\220N-QueensII \343\200\221/\343\200\220052\343\200\221\343\200\220N-QueensII \343\200\221.iml" +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file From b60d78945d883a5f8cd5d640dfae779e2d620cf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Fri, 28 Sep 2018 15:42:44 +0800 Subject: [PATCH 014/108] commit --- .idea/modules.xml | 2 +- .../src/Solution.java" | 65 +++++++++++++++++++ .../src/Solution.java" | 33 ---------- ...0\221\343\200\220JumpGame\343\200\221.iml" | 11 ---- 4 files changed, 66 insertions(+), 45 deletions(-) create mode 100644 "\343\200\220055\343\200\221\343\200\220Jump Game\343\200\221/src/Solution.java" delete mode 100644 "\343\200\220055\346\234\252\343\200\221\343\200\220JumpGame\343\200\221/src/Solution.java" delete mode 100644 "\343\200\220055\346\234\252\343\200\221\343\200\220JumpGame\343\200\221/\343\200\220055\343\200\221\343\200\220JumpGame\343\200\221.iml" diff --git a/.idea/modules.xml b/.idea/modules.xml index 503f331..fab6a17 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -55,7 +55,7 @@ - + diff --git "a/\343\200\220055\343\200\221\343\200\220Jump Game\343\200\221/src/Solution.java" "b/\343\200\220055\343\200\221\343\200\220Jump Game\343\200\221/src/Solution.java" new file mode 100644 index 0000000..2fabd87 --- /dev/null +++ "b/\343\200\220055\343\200\221\343\200\220Jump Game\343\200\221/src/Solution.java" @@ -0,0 +1,65 @@ +/** + * Author: 王俊超 + * Date: 2015-06-19 + * Time: 19:29 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Given an array of non-negative integers, you are initially positioned at the
+     * first index of the array.
+     *
+     * Each element in the array represents your maximum jump length at that position.
+     *
+     * Determine if you are able to reach the last index.
+     *
+     * For example:
+     * A = [2,3,1,1,4], return true.
+     * A = [3,2,1,0,4], return false.
+     *
+     * 题目大意:
+     * 给定的非负整数的数组,则最初定位在数组的第一个位置。数组中的每个元素都代表你的最大跳跃长度在那个位置。
+     * 决定你是否能到达最后一个索引。
+     *
+     * 
+ * + * @param nums + * @return + */ + public boolean canJump(int[] nums) { + return canJump2(nums); + } + public boolean canJump1(int[] nums) { + if (nums == null || nums.length < 2) { + return true; + } + + // 最后可以移动的位置 + int lastPos = 0; + + // 处理每一个位置 + for (int i = 0; i < nums.length; i++) { + // i不能比lastPos大,否则说明不能走到i,走不到i也就不能走到最后 + // 如果在i位置可以移动的距离比已经记录到的最大距离还要大,那么更新最大的移动距离 + if (i <= lastPos && i + nums[i] > lastPos ) { + lastPos = i + nums[i]; + } else if (i > lastPos) { + return false; + } + } + + // 最后的位置必然可以达到最后 + return lastPos >= nums.length - 1; + } + + public boolean canJump2(int[] nums) { + int lastPos = nums.length - 1; + for (int i = nums.length - 1; i >= 0; i--) { + if (i + nums[i] >= lastPos) { + lastPos = i; + } + } + return lastPos == 0; + } +} diff --git "a/\343\200\220055\346\234\252\343\200\221\343\200\220JumpGame\343\200\221/src/Solution.java" "b/\343\200\220055\346\234\252\343\200\221\343\200\220JumpGame\343\200\221/src/Solution.java" deleted file mode 100644 index d3e5313..0000000 --- "a/\343\200\220055\346\234\252\343\200\221\343\200\220JumpGame\343\200\221/src/Solution.java" +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Author: - * Date: 2015-06-19 - * Time: 19:29 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Given an array of non-negative integers, you are initially positioned at the
-     * first index of the array.
-     *
-     * Each element in the array represents your maximum jump length at that position.
-     *
-     * Determine if you are able to reach the last index.
-     *
-     * For example:
-     * A = [2,3,1,1,4], return true.
-     * A = [3,2,1,0,4], return false.
-     *
-     * Ŀ⣺
-     * ķǸ飬λĵһλáеÿԪضԾǸλá
-     * Ƿܵһ
-     *
-     * 
- * - * @param nums - * @return - */ - public boolean canJump(int[] nums) { - return false; - } -} diff --git "a/\343\200\220055\346\234\252\343\200\221\343\200\220JumpGame\343\200\221/\343\200\220055\343\200\221\343\200\220JumpGame\343\200\221.iml" "b/\343\200\220055\346\234\252\343\200\221\343\200\220JumpGame\343\200\221/\343\200\220055\343\200\221\343\200\220JumpGame\343\200\221.iml" deleted file mode 100644 index c90834f..0000000 --- "a/\343\200\220055\346\234\252\343\200\221\343\200\220JumpGame\343\200\221/\343\200\220055\343\200\221\343\200\220JumpGame\343\200\221.iml" +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file From 2cff2ea23dfc0d8165b57a176d44805a5bc68d9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Fri, 28 Sep 2018 15:46:14 +0800 Subject: [PATCH 015/108] commit --- .idea/modules.xml | 1 + .../src/Solution.java" | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 "\343\200\220060\343\200\221\343\200\220Permutation Sequence\343\200\221/src/Solution.java" diff --git a/.idea/modules.xml b/.idea/modules.xml index fab6a17..5213db8 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -60,6 +60,7 @@ + diff --git "a/\343\200\220060\343\200\221\343\200\220Permutation Sequence\343\200\221/src/Solution.java" "b/\343\200\220060\343\200\221\343\200\220Permutation Sequence\343\200\221/src/Solution.java" new file mode 100644 index 0000000..1234e44 --- /dev/null +++ "b/\343\200\220060\343\200\221\343\200\220Permutation Sequence\343\200\221/src/Solution.java" @@ -0,0 +1,34 @@ +import java.util.ArrayList; +import java.util.List; + +/** + * @author: wangjunchao(王俊超) + * @time: 2018-09-28 15:45 + **/ +public class Solution { + public String getPermutation(int n, int k) { + + StringBuilder sb = new StringBuilder(); + List num = new ArrayList<>(); + // 用于计录最大的阶乘数 + int fact = 1; + for (int i = 1; i <= n; i++) { + fact *= i; + num.add(i); + } + + // l = k - 1;为了方便从0开始计数 + int index; + for (int i = 0, l = k - 1; i < n; i++) { + // 从最大的阶乘数开始减少 + fact /= (n - i); + // 计算剩下的数据中的索引 + index = (l / fact); + // 将索引值添加到结果中 + sb.append(num.remove(index)); + // 余下要处理的数 + l -= index * fact; + } + return sb.toString(); + } +} From 4c9d64af73520bb8cb35848a6bfe0c90f658ae19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Fri, 28 Sep 2018 15:51:13 +0800 Subject: [PATCH 016/108] commit --- .idea/modules.xml | 1 + .../src/Solution.java" | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 "\343\200\220071\343\200\221\343\200\220Simplify Path\343\200\221/src/Solution.java" diff --git a/.idea/modules.xml b/.idea/modules.xml index 5213db8..9e0b721 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -68,6 +68,7 @@ + diff --git "a/\343\200\220071\343\200\221\343\200\220Simplify Path\343\200\221/src/Solution.java" "b/\343\200\220071\343\200\221\343\200\220Simplify Path\343\200\221/src/Solution.java" new file mode 100644 index 0000000..c17fc59 --- /dev/null +++ "b/\343\200\220071\343\200\221\343\200\220Simplify Path\343\200\221/src/Solution.java" @@ -0,0 +1,32 @@ +import java.util.LinkedList; +import java.util.List; + +/** + * @author: wangjunchao(王俊超) + * @time: 2018-09-28 15:50 + **/ +public class Solution { + public String simplifyPath(String path) { + String[] ss = path.split("/"); + List result = new LinkedList<>(); + + for (String part : ss) { + if (".".equals(part)) { + continue; + } else if ("..".equals(part)) { + if (result.size() > 0) { + result.remove(result.size() - 1); + } + } else if (!"".equals(part.trim())) { + result.add(part); + } + } + + StringBuilder builder = new StringBuilder(); + for (String part : result) { + builder.append("/").append(part); + } + + return builder.length() == 0 ? "/" : builder.toString(); + } +} From d83949a5183a0aa8babd4ed96734106457d87c1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Fri, 28 Sep 2018 15:58:07 +0800 Subject: [PATCH 017/108] commit --- .gitignore | 3 +-- ...200\221\343\200\220Sudoku Solver\343\200\221.iml" | 11 +++++++++++ ...0\221\343\200\220Combination Sum\343\200\221.iml" | 11 +++++++++++ ...21\343\200\220Combination Sum II\343\200\221.iml" | 11 +++++++++++ ...43\200\220First Missing Positive\343\200\221.iml" | 11 +++++++++++ ...1\343\200\220Trapping Rain Water\343\200\221.iml" | 11 +++++++++++ ...\221\343\200\220Multiply Strings\343\200\221.iml" | 11 +++++++++++ ...221\343\200\220Wildcard Matching\343\200\221.iml" | 11 +++++++++++ ...\200\221\343\200\220Jump Game II\343\200\221.iml" | 11 +++++++++++ ...0\221\343\200\220Permutations II\343\200\221.iml" | 11 +++++++++++ ...\200\221\343\200\220Rotate Image\343\200\221.iml" | 11 +++++++++++ ...00\221\343\200\220Group Anagrams\343\200\221.iml" | 11 +++++++++++ ...\343\200\221\343\200\220N-Queens\343\200\221.iml" | 11 +++++++++++ ...3\200\221\343\200\220N-Queens II\343\200\221.iml" | 12 ++++++++++++ ...343\200\221\343\200\220Jump Game\343\200\221.iml" | 11 +++++++++++ ...\343\200\220Permutation Sequence\343\200\221.iml" | 11 +++++++++++ ...200\221\343\200\220Simplify Path\343\200\221.iml" | 11 +++++++++++ 17 files changed, 178 insertions(+), 2 deletions(-) create mode 100644 "\343\200\220037\343\200\221\343\200\220Sudoku Solver\343\200\221/\343\200\220037\343\200\221\343\200\220Sudoku Solver\343\200\221.iml" create mode 100644 "\343\200\220039\343\200\221\343\200\220Combination Sum\343\200\221/\343\200\220039\343\200\221\343\200\220Combination Sum\343\200\221.iml" create mode 100644 "\343\200\220040\343\200\221\343\200\220Combination Sum II\343\200\221/\343\200\220040\343\200\221\343\200\220Combination Sum II\343\200\221.iml" create mode 100644 "\343\200\220041\343\200\221\343\200\220First Missing Positive\343\200\221/\343\200\220041\343\200\221\343\200\220First Missing Positive\343\200\221.iml" create mode 100644 "\343\200\220042\343\200\221\343\200\220Trapping Rain Water\343\200\221/\343\200\220042\343\200\221\343\200\220Trapping Rain Water\343\200\221.iml" create mode 100644 "\343\200\220043\343\200\221\343\200\220Multiply Strings\343\200\221/\343\200\220043\343\200\221\343\200\220Multiply Strings\343\200\221.iml" create mode 100644 "\343\200\220044\343\200\221\343\200\220Wildcard Matching\343\200\221/\343\200\220044\343\200\221\343\200\220Wildcard Matching\343\200\221.iml" create mode 100644 "\343\200\220045\343\200\221\343\200\220Jump Game II\343\200\221/\343\200\220045\343\200\221\343\200\220Jump Game II\343\200\221.iml" create mode 100644 "\343\200\220047\343\200\221\343\200\220Permutations II\343\200\221/\343\200\220047\343\200\221\343\200\220Permutations II\343\200\221.iml" create mode 100644 "\343\200\220048\343\200\221\343\200\220Rotate Image\343\200\221/\343\200\220048\343\200\221\343\200\220Rotate Image\343\200\221.iml" create mode 100644 "\343\200\220049\343\200\221\343\200\220Group Anagrams\343\200\221/\343\200\220049\343\200\221\343\200\220Group Anagrams\343\200\221.iml" create mode 100644 "\343\200\220051\343\200\221\343\200\220N-Queens\343\200\221/\343\200\220051\343\200\221\343\200\220N-Queens\343\200\221.iml" create mode 100644 "\343\200\220052\343\200\221\343\200\220N-Queens II\343\200\221/\343\200\220052\343\200\221\343\200\220N-Queens II\343\200\221.iml" create mode 100644 "\343\200\220055\343\200\221\343\200\220Jump Game\343\200\221/\343\200\220055\343\200\221\343\200\220Jump Game\343\200\221.iml" create mode 100644 "\343\200\220060\343\200\221\343\200\220Permutation Sequence\343\200\221/\343\200\220060\343\200\221\343\200\220Permutation Sequence\343\200\221.iml" create mode 100644 "\343\200\220071\343\200\221\343\200\220Simplify Path\343\200\221/\343\200\220071\343\200\221\343\200\220Simplify Path\343\200\221.iml" diff --git a/.gitignore b/.gitignore index cd09efa..886a8cf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ # Created by .ignore support plugin (hsz.mobi) -*.iml -.idea +out diff --git "a/\343\200\220037\343\200\221\343\200\220Sudoku Solver\343\200\221/\343\200\220037\343\200\221\343\200\220Sudoku Solver\343\200\221.iml" "b/\343\200\220037\343\200\221\343\200\220Sudoku Solver\343\200\221/\343\200\220037\343\200\221\343\200\220Sudoku Solver\343\200\221.iml" new file mode 100644 index 0000000..c90834f --- /dev/null +++ "b/\343\200\220037\343\200\221\343\200\220Sudoku Solver\343\200\221/\343\200\220037\343\200\221\343\200\220Sudoku Solver\343\200\221.iml" @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git "a/\343\200\220039\343\200\221\343\200\220Combination Sum\343\200\221/\343\200\220039\343\200\221\343\200\220Combination Sum\343\200\221.iml" "b/\343\200\220039\343\200\221\343\200\220Combination Sum\343\200\221/\343\200\220039\343\200\221\343\200\220Combination Sum\343\200\221.iml" new file mode 100644 index 0000000..c90834f --- /dev/null +++ "b/\343\200\220039\343\200\221\343\200\220Combination Sum\343\200\221/\343\200\220039\343\200\221\343\200\220Combination Sum\343\200\221.iml" @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git "a/\343\200\220040\343\200\221\343\200\220Combination Sum II\343\200\221/\343\200\220040\343\200\221\343\200\220Combination Sum II\343\200\221.iml" "b/\343\200\220040\343\200\221\343\200\220Combination Sum II\343\200\221/\343\200\220040\343\200\221\343\200\220Combination Sum II\343\200\221.iml" new file mode 100644 index 0000000..c90834f --- /dev/null +++ "b/\343\200\220040\343\200\221\343\200\220Combination Sum II\343\200\221/\343\200\220040\343\200\221\343\200\220Combination Sum II\343\200\221.iml" @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git "a/\343\200\220041\343\200\221\343\200\220First Missing Positive\343\200\221/\343\200\220041\343\200\221\343\200\220First Missing Positive\343\200\221.iml" "b/\343\200\220041\343\200\221\343\200\220First Missing Positive\343\200\221/\343\200\220041\343\200\221\343\200\220First Missing Positive\343\200\221.iml" new file mode 100644 index 0000000..c90834f --- /dev/null +++ "b/\343\200\220041\343\200\221\343\200\220First Missing Positive\343\200\221/\343\200\220041\343\200\221\343\200\220First Missing Positive\343\200\221.iml" @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git "a/\343\200\220042\343\200\221\343\200\220Trapping Rain Water\343\200\221/\343\200\220042\343\200\221\343\200\220Trapping Rain Water\343\200\221.iml" "b/\343\200\220042\343\200\221\343\200\220Trapping Rain Water\343\200\221/\343\200\220042\343\200\221\343\200\220Trapping Rain Water\343\200\221.iml" new file mode 100644 index 0000000..c90834f --- /dev/null +++ "b/\343\200\220042\343\200\221\343\200\220Trapping Rain Water\343\200\221/\343\200\220042\343\200\221\343\200\220Trapping Rain Water\343\200\221.iml" @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git "a/\343\200\220043\343\200\221\343\200\220Multiply Strings\343\200\221/\343\200\220043\343\200\221\343\200\220Multiply Strings\343\200\221.iml" "b/\343\200\220043\343\200\221\343\200\220Multiply Strings\343\200\221/\343\200\220043\343\200\221\343\200\220Multiply Strings\343\200\221.iml" new file mode 100644 index 0000000..c90834f --- /dev/null +++ "b/\343\200\220043\343\200\221\343\200\220Multiply Strings\343\200\221/\343\200\220043\343\200\221\343\200\220Multiply Strings\343\200\221.iml" @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git "a/\343\200\220044\343\200\221\343\200\220Wildcard Matching\343\200\221/\343\200\220044\343\200\221\343\200\220Wildcard Matching\343\200\221.iml" "b/\343\200\220044\343\200\221\343\200\220Wildcard Matching\343\200\221/\343\200\220044\343\200\221\343\200\220Wildcard Matching\343\200\221.iml" new file mode 100644 index 0000000..c90834f --- /dev/null +++ "b/\343\200\220044\343\200\221\343\200\220Wildcard Matching\343\200\221/\343\200\220044\343\200\221\343\200\220Wildcard Matching\343\200\221.iml" @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git "a/\343\200\220045\343\200\221\343\200\220Jump Game II\343\200\221/\343\200\220045\343\200\221\343\200\220Jump Game II\343\200\221.iml" "b/\343\200\220045\343\200\221\343\200\220Jump Game II\343\200\221/\343\200\220045\343\200\221\343\200\220Jump Game II\343\200\221.iml" new file mode 100644 index 0000000..c90834f --- /dev/null +++ "b/\343\200\220045\343\200\221\343\200\220Jump Game II\343\200\221/\343\200\220045\343\200\221\343\200\220Jump Game II\343\200\221.iml" @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git "a/\343\200\220047\343\200\221\343\200\220Permutations II\343\200\221/\343\200\220047\343\200\221\343\200\220Permutations II\343\200\221.iml" "b/\343\200\220047\343\200\221\343\200\220Permutations II\343\200\221/\343\200\220047\343\200\221\343\200\220Permutations II\343\200\221.iml" new file mode 100644 index 0000000..c90834f --- /dev/null +++ "b/\343\200\220047\343\200\221\343\200\220Permutations II\343\200\221/\343\200\220047\343\200\221\343\200\220Permutations II\343\200\221.iml" @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git "a/\343\200\220048\343\200\221\343\200\220Rotate Image\343\200\221/\343\200\220048\343\200\221\343\200\220Rotate Image\343\200\221.iml" "b/\343\200\220048\343\200\221\343\200\220Rotate Image\343\200\221/\343\200\220048\343\200\221\343\200\220Rotate Image\343\200\221.iml" new file mode 100644 index 0000000..c90834f --- /dev/null +++ "b/\343\200\220048\343\200\221\343\200\220Rotate Image\343\200\221/\343\200\220048\343\200\221\343\200\220Rotate Image\343\200\221.iml" @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git "a/\343\200\220049\343\200\221\343\200\220Group Anagrams\343\200\221/\343\200\220049\343\200\221\343\200\220Group Anagrams\343\200\221.iml" "b/\343\200\220049\343\200\221\343\200\220Group Anagrams\343\200\221/\343\200\220049\343\200\221\343\200\220Group Anagrams\343\200\221.iml" new file mode 100644 index 0000000..c90834f --- /dev/null +++ "b/\343\200\220049\343\200\221\343\200\220Group Anagrams\343\200\221/\343\200\220049\343\200\221\343\200\220Group Anagrams\343\200\221.iml" @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git "a/\343\200\220051\343\200\221\343\200\220N-Queens\343\200\221/\343\200\220051\343\200\221\343\200\220N-Queens\343\200\221.iml" "b/\343\200\220051\343\200\221\343\200\220N-Queens\343\200\221/\343\200\220051\343\200\221\343\200\220N-Queens\343\200\221.iml" new file mode 100644 index 0000000..c90834f --- /dev/null +++ "b/\343\200\220051\343\200\221\343\200\220N-Queens\343\200\221/\343\200\220051\343\200\221\343\200\220N-Queens\343\200\221.iml" @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git "a/\343\200\220052\343\200\221\343\200\220N-Queens II\343\200\221/\343\200\220052\343\200\221\343\200\220N-Queens II\343\200\221.iml" "b/\343\200\220052\343\200\221\343\200\220N-Queens II\343\200\221/\343\200\220052\343\200\221\343\200\220N-Queens II\343\200\221.iml" new file mode 100644 index 0000000..47071ea --- /dev/null +++ "b/\343\200\220052\343\200\221\343\200\220N-Queens II\343\200\221/\343\200\220052\343\200\221\343\200\220N-Queens II\343\200\221.iml" @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git "a/\343\200\220055\343\200\221\343\200\220Jump Game\343\200\221/\343\200\220055\343\200\221\343\200\220Jump Game\343\200\221.iml" "b/\343\200\220055\343\200\221\343\200\220Jump Game\343\200\221/\343\200\220055\343\200\221\343\200\220Jump Game\343\200\221.iml" new file mode 100644 index 0000000..c90834f --- /dev/null +++ "b/\343\200\220055\343\200\221\343\200\220Jump Game\343\200\221/\343\200\220055\343\200\221\343\200\220Jump Game\343\200\221.iml" @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git "a/\343\200\220060\343\200\221\343\200\220Permutation Sequence\343\200\221/\343\200\220060\343\200\221\343\200\220Permutation Sequence\343\200\221.iml" "b/\343\200\220060\343\200\221\343\200\220Permutation Sequence\343\200\221/\343\200\220060\343\200\221\343\200\220Permutation Sequence\343\200\221.iml" new file mode 100644 index 0000000..c90834f --- /dev/null +++ "b/\343\200\220060\343\200\221\343\200\220Permutation Sequence\343\200\221/\343\200\220060\343\200\221\343\200\220Permutation Sequence\343\200\221.iml" @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git "a/\343\200\220071\343\200\221\343\200\220Simplify Path\343\200\221/\343\200\220071\343\200\221\343\200\220Simplify Path\343\200\221.iml" "b/\343\200\220071\343\200\221\343\200\220Simplify Path\343\200\221/\343\200\220071\343\200\221\343\200\220Simplify Path\343\200\221.iml" new file mode 100644 index 0000000..c90834f --- /dev/null +++ "b/\343\200\220071\343\200\221\343\200\220Simplify Path\343\200\221/\343\200\220071\343\200\221\343\200\220Simplify Path\343\200\221.iml" @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file From 7279a827614b5420e3f0d099ea0802c9c6571d7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Fri, 28 Sep 2018 16:53:48 +0800 Subject: [PATCH 018/108] commit --- .idea/modules.xml | 1 + .../src/Main.java" | 2 +- .../src/Solution.java" | 18 +++--- .../src/Solution.java" | 60 +++++++++---------- .../src/Solution.java" | 58 ++++++++++++++++++ ...I - Input array is sorted\343\200\221.iml" | 11 ++++ 6 files changed, 110 insertions(+), 40 deletions(-) create mode 100644 "\343\200\220167\343\200\221\343\200\220Two Sum II - Input array is sorted\343\200\221/src/Solution.java" create mode 100644 "\343\200\220167\343\200\221\343\200\220Two Sum II - Input array is sorted\343\200\221/\343\200\220167\343\200\221\343\200\220Two Sum II - Input array is sorted\343\200\221.iml" diff --git a/.idea/modules.xml b/.idea/modules.xml index 9e0b721..6b72936 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -129,6 +129,7 @@ + diff --git "a/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221/src/Main.java" "b/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221/src/Main.java" index 6c41f33..d83cdd8 100644 --- "a/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221/src/Main.java" +++ "b/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221/src/Main.java" @@ -1,5 +1,5 @@ /** - * Author: + * Author: 王俊超 * Date: 2015-06-18 * Time: 09:17 * Declaration: All Rights Reserved !!! diff --git "a/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221/src/Solution.java" "b/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221/src/Solution.java" index 5fc48cd..2794018 100644 --- "a/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221/src/Solution.java" +++ "b/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221/src/Solution.java" @@ -1,7 +1,7 @@ import java.util.Arrays; /** - * Author: + * Author: 王俊超 * Date: 2015-06-17 * Time: 20:27 * Declaration: All Rights Reserved !!! @@ -40,15 +40,15 @@ public int compareTo(Node o) { * Input: numbers={2, 7, 11, 15}, target=9 * Output: index1=1, index2=2 * - * Ŀ - * һ飬ҳӵָĿ֡ - * ҪtwoSumҪܹӵĿֵindex1ҪСindex2 - * עһ㣬㷵صĽindex1index2ǻ0ʼġԼÿһ϶ֻһ + * 题目大意 + * 给定一个整数数组,找出其中两个数满足相加等于你指定的目标数字。 + * 要求:这个函数twoSum必须要返回能够相加等于目标数字的两个数的索引,且index1必须要小于index2。 + * 请注意一点,你返回的结果(包括index1和index2)都不是基于0开始的。你可以假设每一个输入肯定只有一个结果。 * - * ˼· - * һ飬Ըʹָ룬ʼʱֱָˣ±ӦֵǷ - * ĿֵھʹӸҳ¼±꣬÷ؽءھұߵ±ƣ - * һƥ䣬Сھߵ±ƶһƥ䣬ֱеݶ + * 解题思路 + * 创建一个辅助类数组,对辅助类进行排序,使用两个指针,开始时分别指向数组的两端,看这两个下标对应的值是否 + * 等于目标值,如果等于就从辅助类中找出记录的下标,构造好返回结果,返回。如果大于就让右边的下标向左移, + * 进入下一次匹配,如果小于就让左边的下标向右移动,进入下一次匹配,直到所有的数据都处理完 * * * @param nums diff --git "a/\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221/src/Solution.java" "b/\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221/src/Solution.java" index e8921ba..4f3e4eb 100644 --- "a/\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221/src/Solution.java" +++ "b/\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221/src/Solution.java" @@ -1,5 +1,5 @@ /** - * Author: + * Author: 王俊超 * Date: 2015-06-21 * Time: 14:48 * Declaration: All Rights Reserved !!! @@ -14,15 +14,15 @@ public class Solution { * * You may assume no duplicate exists in the array. * - * Ŀ⣺ - * һһδ֪ĵת0 1 2 4 5 6 7ܳΪ4 5 6 7 0 1 2 - * һĿֵѰھͷӦ±꣬򷵻-1 - * вظֵ + * 题目大意: + * 假设一个排序的数组以一个未知的的枢轴旋转。(即,0 1 2 4 5 6 7可能成为4 5 6 7 0 1 2)。 + * 给定一个目标值,在数组中搜寻。如果存在就返回其对应的下标,否则返回-1。 + * 假设数组中不存在重复值。 * - * ˼· - * תСֵλminIndexLeetCode153 minIndexΪ˵ڷָ - * 飬ǰһеĵһԪضںһÿһԪأжtargetһ - * ʹö㷨ңminIndex=0˵ȫ򣬶жңزҽ + * 解题思路: + * 找旋转数组最小值的位置minIndex(见LeetCode第153题 ),如果minIndex不为,说明其在分隔成 + * 两个有序数组,并且前一个中的第一个元素都大于后一个数组的每一个元素,判断target中哪一个数组区 + * 间中使用二叉搜索算法查找,如果minIndex=0,说明全局有序,对整个数组进行二叉查找,返回查找结果 * * * @param nums @@ -33,24 +33,24 @@ public int search(int[] nums, int target) { if (nums != null && nums.length > 0) { - // СԪضӦ± + // 找最小元素对应的下标 int minIndex = searchMinIndex(nums, 0, nums.length - 1); - // ȫ + // 整个数组全局有序 if (minIndex == 0) { return binarySearch(nums, 0, nums.length - 1, target); } - // ֲ, 4 5 6 7 8 9 0 1 2 3 + // 有两个局部有序区间, 如 4 5 6 7 8 9 0 1 2 3 else { - // úͺһһԪȣضӦ± + // 恬好和后一个有序区间的最后一个元素相等,返回对应的下标 if (nums[nums.length - 1] == target) { return nums.length - 1; } - // targetںһ + // target可能在后一个有序区间中 else if (nums[nums.length - 1] > target) { return binarySearch(nums, minIndex, nums.length - 1, target); } - // targetǰһ + // target可能是前一个有序区间中 else { return binarySearch(nums, 0, minIndex - 1, target); } @@ -61,13 +61,13 @@ else if (nums[nums.length - 1] > target) { } /** - * + * 二分搜索 * - * @param nums - * @param start ʼλ - * @param end λ - * @param target Ŀ - * @return ƥԪص± + * @param nums 数组 + * @param start 起始位置 + * @param end 结束位置 + * @param target 搜索目标 + * @return 匹配元素的下标 */ public int binarySearch(int[] nums, int start, int end, int target) { @@ -88,33 +88,33 @@ public int binarySearch(int[] nums, int start, int end, int target) { } /** - * СԪص± + * 找最小元素的下标 * - * @param nums - * @param start ʼλ - * @param end λ - * @return СԪص± + * @param nums 数组 + * @param start 起始位置 + * @param end 结束位置 + * @return 最小元素的下标 */ public int searchMinIndex(int[] nums, int start, int end) { int mid; while (start < end) { mid = start + ((end - start) >> 1); - // һǰСҵ + // 后一个数比前个数小就找到了 if (nums[mid] > nums[mid + 1]) { return mid + 1; } - // ˵мֵڵһ + // 说明中间值在第一个有序的数组中 else if (nums[mid] > nums[start]) { start = mid; } - // ˵мֵڵڶ + // 说明中间值在第二个有序的数组中 else { end = mid; } } - // ˵ + // 说明整个数组是有序的 return 0; } } diff --git "a/\343\200\220167\343\200\221\343\200\220Two Sum II - Input array is sorted\343\200\221/src/Solution.java" "b/\343\200\220167\343\200\221\343\200\220Two Sum II - Input array is sorted\343\200\221/src/Solution.java" new file mode 100644 index 0000000..74f81cc --- /dev/null +++ "b/\343\200\220167\343\200\221\343\200\220Two Sum II - Input array is sorted\343\200\221/src/Solution.java" @@ -0,0 +1,58 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-09-28 16:17 + **/ +public class Solution { + /** + * 如果数组很大,target很小,可以考虑先用二分查找法找到不大于target元素的下标,再作处理 + * @param numbers + * @param target + * @return + */ + public int[] twoSum(int[] numbers, int target) { +// int idx = search(numbers, target); + int idx = numbers.length - 1; + return twoSum(numbers, target, idx); + } + + public int[] twoSum(int[] numbers, int target, int end) { + int[] result = {0, 0}; + + int lo = 0; + int hi = end; + + while (lo < hi) { + if (numbers[lo] + numbers[hi] == target) { + result[0] = lo; + result[1] = hi; + break; + } else if (numbers[lo] + numbers[hi] > target) { + hi--; + } else { + lo++; + } + } + + return result; + } + + public int search(int[] numbers, int target) { + + int lo = 0; + int hi = numbers.length - 1; + int mid; + + while (lo <= hi) { + mid = lo + (hi - lo) / 2; + if (numbers[mid] == target) { + return mid; + } else if (numbers[mid] > target) { + hi = mid - 1; + } else { + lo = mid + 1; + } + + } + return hi; + } +} diff --git "a/\343\200\220167\343\200\221\343\200\220Two Sum II - Input array is sorted\343\200\221/\343\200\220167\343\200\221\343\200\220Two Sum II - Input array is sorted\343\200\221.iml" "b/\343\200\220167\343\200\221\343\200\220Two Sum II - Input array is sorted\343\200\221/\343\200\220167\343\200\221\343\200\220Two Sum II - Input array is sorted\343\200\221.iml" new file mode 100644 index 0000000..c90834f --- /dev/null +++ "b/\343\200\220167\343\200\221\343\200\220Two Sum II - Input array is sorted\343\200\221/\343\200\220167\343\200\221\343\200\220Two Sum II - Input array is sorted\343\200\221.iml" @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file From 66543d54a84cbae4c15baa15103d1ca8e2fcb741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Tue, 9 Oct 2018 09:17:53 +0800 Subject: [PATCH 019/108] commit --- .../src/Solution.java" | 37 +++++++++++++++++++ .../src/Test.java" | 18 +++++++++ 2 files changed, 55 insertions(+) create mode 100644 "\343\200\220122\343\200\221\343\200\220Best Time to Buy and Sell Stock II\343\200\221/src/Solution.java" create mode 100644 "\343\200\220122\343\200\221\343\200\220Best Time to Buy and Sell Stock II\343\200\221/src/Test.java" diff --git "a/\343\200\220122\343\200\221\343\200\220Best Time to Buy and Sell Stock II\343\200\221/src/Solution.java" "b/\343\200\220122\343\200\221\343\200\220Best Time to Buy and Sell Stock II\343\200\221/src/Solution.java" new file mode 100644 index 0000000..bef6708 --- /dev/null +++ "b/\343\200\220122\343\200\221\343\200\220Best Time to Buy and Sell Stock II\343\200\221/src/Solution.java" @@ -0,0 +1,37 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-09 08:46 + **/ +public class Solution { + public int maxProfit(int[] prices) { + + if (prices == null || prices.length < 2) { + return 0; + } + + int buy = 0; + int sell = 1; + + int sum = 0; + while (sell < prices.length) { + // 从buy的位置开始找降序子序列中最小的值 + while (buy + 1 < prices.length && prices[buy] >= prices[buy + 1]) { + buy++; + } + // 从buy的位置开始找升序子序列中最大的值 + sell = buy + 1; + while (sell + 1 < prices.length && prices[sell] <= prices[sell + 1]) { + sell++; + } + + if (sell < prices.length) { + sum += prices[sell] - prices[buy]; + } + + buy = sell + 1; + + } + + return sum; + } +} diff --git "a/\343\200\220122\343\200\221\343\200\220Best Time to Buy and Sell Stock II\343\200\221/src/Test.java" "b/\343\200\220122\343\200\221\343\200\220Best Time to Buy and Sell Stock II\343\200\221/src/Test.java" new file mode 100644 index 0000000..2b9341e --- /dev/null +++ "b/\343\200\220122\343\200\221\343\200\220Best Time to Buy and Sell Stock II\343\200\221/src/Test.java" @@ -0,0 +1,18 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-09 09:13 + **/ +public class Test { + public static void main(String[] args) { + Solution solution = new Solution(); + + int[] prices = {7, 1, 5, 3, 6, 4}; + System.out.println(solution.maxProfit(prices) == 7); + + int[] prices2 = {1, 2, 3, 4, 5}; + System.out.println(solution.maxProfit(prices2) == 4); + + int[] prices3 = {7, 6, 4, 3, 1}; + System.out.println(solution.maxProfit(prices3) == 0); + } +} From dc62e8d68a39fa4c9d9b1006df164142f0336b6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Tue, 9 Oct 2018 09:19:25 +0800 Subject: [PATCH 020/108] commit --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 886a8cf..bdafa63 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ # Created by .ignore support plugin (hsz.mobi) out +.idea +*.iml From f852a8bf23ae2ec8c1f2b5fb182e0f024612a25f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Tue, 9 Oct 2018 09:21:18 +0800 Subject: [PATCH 021/108] commit --- .idea/modules.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/.idea/modules.xml b/.idea/modules.xml index 6b72936..7a897f2 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -106,6 +106,7 @@ + From 74251ca76cb462e5d03a5ca8e6b5701c709671f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Tue, 9 Oct 2018 13:06:54 +0800 Subject: [PATCH 022/108] commit --- .idea/misc.xml | 15 +---- .idea/modules.xml | 4 ++ .../src/Solution.java" | 28 +++++++++ .../src/Test.java" | 16 +++++ .../src/MyQueue.java" | 56 ++++++++++++++++++ .../src/Test.java" | 15 +++++ .../src/ListNode.java" | 12 ++++ .../src/Solution.java" | 58 +++++++++++++++++++ .../src/Solution2.java" | 38 ++++++++++++ .../src/Test.java" | 42 ++++++++++++++ .../src/Solution.java" | 56 ++++++++++++++++++ .../src/TreeNode.java" | 13 +++++ 12 files changed, 339 insertions(+), 14 deletions(-) create mode 100644 "\343\200\220231\343\200\221\343\200\220Power of Two\343\200\221/src/Solution.java" create mode 100644 "\343\200\220231\343\200\221\343\200\220Power of Two\343\200\221/src/Test.java" create mode 100644 "\343\200\220232\343\200\221\343\200\220Implement Queue using Stacks\343\200\221/src/MyQueue.java" create mode 100644 "\343\200\220232\343\200\221\343\200\220Implement Queue using Stacks\343\200\221/src/Test.java" create mode 100644 "\343\200\220234\343\200\221\343\200\220Palindrome Linked List\343\200\221/src/ListNode.java" create mode 100644 "\343\200\220234\343\200\221\343\200\220Palindrome Linked List\343\200\221/src/Solution.java" create mode 100644 "\343\200\220234\343\200\221\343\200\220Palindrome Linked List\343\200\221/src/Solution2.java" create mode 100644 "\343\200\220234\343\200\221\343\200\220Palindrome Linked List\343\200\221/src/Test.java" create mode 100644 "\343\200\220235\343\200\221\343\200\220Lowest Common Ancestor of a Binary Search Tree\343\200\221/src/Solution.java" create mode 100644 "\343\200\220235\343\200\221\343\200\220Lowest Common Ancestor of a Binary Search Tree\343\200\221/src/TreeNode.java" diff --git a/.idea/misc.xml b/.idea/misc.xml index 02642ab..d5d79e0 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,19 +1,6 @@ - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index 7a897f2..6e5bbb4 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -148,6 +148,10 @@ + + + + \ No newline at end of file diff --git "a/\343\200\220231\343\200\221\343\200\220Power of Two\343\200\221/src/Solution.java" "b/\343\200\220231\343\200\221\343\200\220Power of Two\343\200\221/src/Solution.java" new file mode 100644 index 0000000..dee3309 --- /dev/null +++ "b/\343\200\220231\343\200\221\343\200\220Power of Two\343\200\221/src/Solution.java" @@ -0,0 +1,28 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-09 09:24 + **/ +public class Solution { + public boolean isPowerOfTwo(int n) { + if (n < 1) { + return false; + } + + int remainder; + boolean result = false; + while (n > 0) { + // 求余数 + remainder = n % 2; + n >>>= 1; + + if (n == 0 && remainder == 1) { + result = true; + break; + } else if (n > 0 && remainder == 1) { + break; + } + } + + return result; + } +} diff --git "a/\343\200\220231\343\200\221\343\200\220Power of Two\343\200\221/src/Test.java" "b/\343\200\220231\343\200\221\343\200\220Power of Two\343\200\221/src/Test.java" new file mode 100644 index 0000000..0b8841a --- /dev/null +++ "b/\343\200\220231\343\200\221\343\200\220Power of Two\343\200\221/src/Test.java" @@ -0,0 +1,16 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-09 09:28 + **/ +public class Test { + public static void main(String[] args) { + Solution solution = new Solution(); + + System.out.println(solution.isPowerOfTwo(-1)); + System.out.println(solution.isPowerOfTwo(0)); + System.out.println(solution.isPowerOfTwo(1)); + System.out.println(solution.isPowerOfTwo(2)); + System.out.println(solution.isPowerOfTwo(16)); + System.out.println(solution.isPowerOfTwo(218)); + } +} diff --git "a/\343\200\220232\343\200\221\343\200\220Implement Queue using Stacks\343\200\221/src/MyQueue.java" "b/\343\200\220232\343\200\221\343\200\220Implement Queue using Stacks\343\200\221/src/MyQueue.java" new file mode 100644 index 0000000..a4cdc0c --- /dev/null +++ "b/\343\200\220232\343\200\221\343\200\220Implement Queue using Stacks\343\200\221/src/MyQueue.java" @@ -0,0 +1,56 @@ +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; + +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-09 09:37 + **/ +class MyQueue { + + private List list; + + /** + * Initialize your data structure here. + */ + public MyQueue() { + list = new LinkedList<>(); + } + + /** + * Push element x to the back of queue. + */ + public void push(int x) { + list.add(x); + } + + /** + * Removes the element from in front of queue and returns that element. + */ + public int pop() { + return list.remove(0); + } + + /** + * Get the front element. + */ + public int peek() { + return list.get(0); + } + + /** + * Returns whether the queue is empty. + */ + public boolean empty() { + return list.isEmpty(); + } +} + +/** + * Your MyQueue object will be instantiated and called as such: + * MyQueue obj = new MyQueue(); + * obj.push(x); + * int param_2 = obj.pop(); + * int param_3 = obj.peek(); + * boolean param_4 = obj.empty(); + */ diff --git "a/\343\200\220232\343\200\221\343\200\220Implement Queue using Stacks\343\200\221/src/Test.java" "b/\343\200\220232\343\200\221\343\200\220Implement Queue using Stacks\343\200\221/src/Test.java" new file mode 100644 index 0000000..4adabf6 --- /dev/null +++ "b/\343\200\220232\343\200\221\343\200\220Implement Queue using Stacks\343\200\221/src/Test.java" @@ -0,0 +1,15 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-09 10:58 + **/ +public class Test { + public static void main(String[] args) { + MyQueue queue = new MyQueue(); + queue.push(1); + queue.push(2); + + System.out.println(queue.peek()); + System.out.println(queue.pop()); + System.out.println(queue.empty()); + } +} diff --git "a/\343\200\220234\343\200\221\343\200\220Palindrome Linked List\343\200\221/src/ListNode.java" "b/\343\200\220234\343\200\221\343\200\220Palindrome Linked List\343\200\221/src/ListNode.java" new file mode 100644 index 0000000..0304f36 --- /dev/null +++ "b/\343\200\220234\343\200\221\343\200\220Palindrome Linked List\343\200\221/src/ListNode.java" @@ -0,0 +1,12 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-09 11:03 + **/ +public class ListNode { + int val; + ListNode next; + + ListNode(int x) { + val = x; + } +} diff --git "a/\343\200\220234\343\200\221\343\200\220Palindrome Linked List\343\200\221/src/Solution.java" "b/\343\200\220234\343\200\221\343\200\220Palindrome Linked List\343\200\221/src/Solution.java" new file mode 100644 index 0000000..9ace1e4 --- /dev/null +++ "b/\343\200\220234\343\200\221\343\200\220Palindrome Linked List\343\200\221/src/Solution.java" @@ -0,0 +1,58 @@ +/** + * O(n) time and O(1) space + *
+ * 1->2->2->1
+ * 1->2->3->2->1
+ * 先找到第二个2的位置,将2及后面的链逆转,形成新的链A,再按A与原来的链,从头开开始比较
+ * 
+ * + * @author: wangjunchao(王俊超) + * @time: 2018-10-09 11:02 + **/ +public class Solution { + public boolean isPalindrome(ListNode head) { + + // 没有节点或者只有一个结点 + if (head == null || head.next == null) { + return true; + } + + int count = 0; + ListNode node = head; + while (node != null) { + count++; + node = node.next; + } + + // 找反向链的起始位置 + count = (count + 1) / 2; + node = head; + while (count >0) { + count--; + node = node.next; + } + + + ListNode reverseHead = new ListNode(0); + ListNode temp; + while (node != null) { + temp = node.next; + node.next = reverseHead.next; + reverseHead.next = node; + node = temp; + } + + reverseHead = reverseHead.next; + + while (reverseHead != null) { + if (head.val != reverseHead.val) { + return false; + } + + reverseHead = reverseHead.next; + head = head.next; + } + + return true; + } +} diff --git "a/\343\200\220234\343\200\221\343\200\220Palindrome Linked List\343\200\221/src/Solution2.java" "b/\343\200\220234\343\200\221\343\200\220Palindrome Linked List\343\200\221/src/Solution2.java" new file mode 100644 index 0000000..f6138f7 --- /dev/null +++ "b/\343\200\220234\343\200\221\343\200\220Palindrome Linked List\343\200\221/src/Solution2.java" @@ -0,0 +1,38 @@ +/** + * O(n) time and O(n) space + * + * @author: wangjunchao(王俊超) + * @time: 2018-10-09 11:02 + **/ +public class Solution2 { + public boolean isPalindrome(ListNode head) { + + if (head == null) { + return true; + } + + // 反向链的头 + ListNode reverseHead = new ListNode(-1); + + ListNode temp = head; + ListNode node; + // 头插法构建反向链 + while (temp != null) { + node = new ListNode(temp.val); + node.next = reverseHead.next; + reverseHead.next = node; + temp = temp.next; + } + + reverseHead = reverseHead.next; + while (head != null) { + if (head.val != reverseHead.val) { + return false; + } + + head = head.next; + reverseHead = reverseHead.next; + } + return true; + } +} diff --git "a/\343\200\220234\343\200\221\343\200\220Palindrome Linked List\343\200\221/src/Test.java" "b/\343\200\220234\343\200\221\343\200\220Palindrome Linked List\343\200\221/src/Test.java" new file mode 100644 index 0000000..97b7f35 --- /dev/null +++ "b/\343\200\220234\343\200\221\343\200\220Palindrome Linked List\343\200\221/src/Test.java" @@ -0,0 +1,42 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-09 11:10 + **/ +public class Test { + public static void main(String[] args) { + test1(); + test2(); + test3(); + } + + public static void test1() { + Solution solution = new Solution(); + ListNode head = new ListNode(1); + head.next = new ListNode(2); + System.out.println(solution.isPalindrome(head)); + } + + public static void test2() { + Solution solution = new Solution(); + + ListNode head = new ListNode(1); + head.next = new ListNode(2); + head.next.next= new ListNode(2); + head.next.next.next= new ListNode(1); + head.next.next.next.next= new ListNode(2); + head.next.next.next.next.next= new ListNode(2); + head.next.next.next.next.next.next= new ListNode(1); + System.out.println(solution.isPalindrome(head)); + } + + public static void test3() { + Solution solution = new Solution(); + + ListNode head = new ListNode(1); + head.next = new ListNode(2); + head.next.next= new ListNode(2); + head.next.next.next= new ListNode(1); + + System.out.println(solution.isPalindrome(head)); + } +} diff --git "a/\343\200\220235\343\200\221\343\200\220Lowest Common Ancestor of a Binary Search Tree\343\200\221/src/Solution.java" "b/\343\200\220235\343\200\221\343\200\220Lowest Common Ancestor of a Binary Search Tree\343\200\221/src/Solution.java" new file mode 100644 index 0000000..632cf2f --- /dev/null +++ "b/\343\200\220235\343\200\221\343\200\220Lowest Common Ancestor of a Binary Search Tree\343\200\221/src/Solution.java" @@ -0,0 +1,56 @@ +import java.util.ArrayList; +import java.util.List; + +/** + * Definition for a binary tree node. + *
+ * public class TreeNode {
+ *      int val;
+ *      TreeNode left;
+ *      TreeNode right;
+ *      TreeNode(int x) { val = x; }
+ * }
+ * 
+ * + * @author: wangjunchao(王俊超) + * @time: 2018-10-09 11:32 + */ +class Solution { + public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { + + List pPath = new ArrayList<>(); + List qPath = new ArrayList<>(); + + search(pPath, root, p); + search(qPath, root, q); + + TreeNode ancestor = pPath.get(0); + + int idx = 1; + while (idx < pPath.size() && idx < qPath.size()) { + p = pPath.get(idx); + q = qPath.get(idx); + if (p != null && q != null && p.val == q.val) { + ancestor = pPath.get(idx); + idx++; + } else { + break; + } + } + + return ancestor; + } + + public void search(List path, TreeNode root, TreeNode node) { + path.add(root); + + if (root != null) { + if (root.val > node.val) { + search(path, root.left, node); + } + if (root.val < node.val) { + search(path, root.right, node); + } + } + } +} diff --git "a/\343\200\220235\343\200\221\343\200\220Lowest Common Ancestor of a Binary Search Tree\343\200\221/src/TreeNode.java" "b/\343\200\220235\343\200\221\343\200\220Lowest Common Ancestor of a Binary Search Tree\343\200\221/src/TreeNode.java" new file mode 100644 index 0000000..cb9448f --- /dev/null +++ "b/\343\200\220235\343\200\221\343\200\220Lowest Common Ancestor of a Binary Search Tree\343\200\221/src/TreeNode.java" @@ -0,0 +1,13 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-09 11:33 + **/ +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} From 66b3a79d810fc281ad7817a69ae39e37ebcd5a3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Wed, 10 Oct 2018 10:27:53 +0800 Subject: [PATCH 023/108] commit --- .idea/modules.xml | 1 + .../src/ListNode.java" | 12 +++++++ .../src/Solution.java" | 31 ++++++++++++++++++ .../src/Test.java" | 32 +++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 "\343\200\220237\343\200\221\343\200\220Delete Node in a Linked List\343\200\221/src/ListNode.java" create mode 100644 "\343\200\220237\343\200\221\343\200\220Delete Node in a Linked List\343\200\221/src/Solution.java" create mode 100644 "\343\200\220237\343\200\221\343\200\220Delete Node in a Linked List\343\200\221/src/Test.java" diff --git a/.idea/modules.xml b/.idea/modules.xml index 6e5bbb4..5817e41 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -152,6 +152,7 @@ + \ No newline at end of file diff --git "a/\343\200\220237\343\200\221\343\200\220Delete Node in a Linked List\343\200\221/src/ListNode.java" "b/\343\200\220237\343\200\221\343\200\220Delete Node in a Linked List\343\200\221/src/ListNode.java" new file mode 100644 index 0000000..50f6a11 --- /dev/null +++ "b/\343\200\220237\343\200\221\343\200\220Delete Node in a Linked List\343\200\221/src/ListNode.java" @@ -0,0 +1,12 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 09:58 + **/ +public class ListNode { + int val; + ListNode next; + + ListNode(int x) { + val = x; + } +} diff --git "a/\343\200\220237\343\200\221\343\200\220Delete Node in a Linked List\343\200\221/src/Solution.java" "b/\343\200\220237\343\200\221\343\200\220Delete Node in a Linked List\343\200\221/src/Solution.java" new file mode 100644 index 0000000..b440a61 --- /dev/null +++ "b/\343\200\220237\343\200\221\343\200\220Delete Node in a Linked List\343\200\221/src/Solution.java" @@ -0,0 +1,31 @@ +/** + *
+ * Definition for singly-linked list.
+ * public class ListNode {
+ *     int val;
+ *     ListNode next;
+ *     ListNode(int x) { val = x; }
+ * }
+ * 
+ * @author: wangjunchao(王俊超) + * @time: 2018-10-10 09:57 + **/ +class Solution { + public void deleteNode(ListNode node) { + + if (node == null || node.next == null) { + return; + } + + ListNode prev = node; + while (node.next != null) { + node.val = node.next.val; + prev = node; + node = node.next; + + + } + + prev.next = null; + } +} \ No newline at end of file diff --git "a/\343\200\220237\343\200\221\343\200\220Delete Node in a Linked List\343\200\221/src/Test.java" "b/\343\200\220237\343\200\221\343\200\220Delete Node in a Linked List\343\200\221/src/Test.java" new file mode 100644 index 0000000..8863287 --- /dev/null +++ "b/\343\200\220237\343\200\221\343\200\220Delete Node in a Linked List\343\200\221/src/Test.java" @@ -0,0 +1,32 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 10:01 + **/ +public class Test { + public static void main(String[] args) { + ListNode node = new ListNode(4); + node.next = new ListNode(5); + node.next.next = new ListNode(1); + node.next.next.next = new ListNode(9); + + Solution solution = new Solution(); + solution.deleteNode(node.next); + + print(node); + } + + private static void print(ListNode node) { + do { + if (node == null) { + System.out.println("null"); + } else if (node.next != null){ + System.out.print(node.val + "->"); + node = node.next; + } else { + System.out.println(node.val + "->null"); + node = node.next; + } + + }while (node != null); + } +} From eb56524bcb217a02f03660fed805566749fb1fbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Wed, 10 Oct 2018 10:38:12 +0800 Subject: [PATCH 024/108] commit --- .idea/modules.xml | 1 + .../src/Solution.java" | 48 +++++++++++++++++++ .../src/Test.java" | 12 +++++ 3 files changed, 61 insertions(+) create mode 100644 "\343\200\220242\343\200\221\343\200\220Valid Anagram\343\200\221/src/Solution.java" create mode 100644 "\343\200\220242\343\200\221\343\200\220Valid Anagram\343\200\221/src/Test.java" diff --git a/.idea/modules.xml b/.idea/modules.xml index 5817e41..58dc29a 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -153,6 +153,7 @@ + \ No newline at end of file diff --git "a/\343\200\220242\343\200\221\343\200\220Valid Anagram\343\200\221/src/Solution.java" "b/\343\200\220242\343\200\221\343\200\220Valid Anagram\343\200\221/src/Solution.java" new file mode 100644 index 0000000..ace39c8 --- /dev/null +++ "b/\343\200\220242\343\200\221\343\200\220Valid Anagram\343\200\221/src/Solution.java" @@ -0,0 +1,48 @@ +import java.util.HashMap; +import java.util.Map; + +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 10:28 + **/ +public class Solution { + public boolean isAnagram(String s, String t) { + + if (s == null && t == null) { + return true; + } else if (s == null || t == null) { + return false; + } + + Map map = new HashMap<>(); + + for (int i = 0; i < s.length(); i++) { + Character c = s.charAt(i); + if (map.containsKey(c)) { + map.put(c, map.get(c) + 1); + } else { + map.put(c, 1); + } + } + + for (int i = 0; i < t.length(); i++) { + Character c = t.charAt(i); + Integer count = map.get(c); + // t有s中不包含的字符串 + if (count == null) { + return false; + } else { + map.put(c, count - 1); + } + } + + // map中的值有非0的说明不合法 + for (Integer i : map.values()) { + if (i != 0) { + return false; + } + } + + return true; + } +} diff --git "a/\343\200\220242\343\200\221\343\200\220Valid Anagram\343\200\221/src/Test.java" "b/\343\200\220242\343\200\221\343\200\220Valid Anagram\343\200\221/src/Test.java" new file mode 100644 index 0000000..5282683 --- /dev/null +++ "b/\343\200\220242\343\200\221\343\200\220Valid Anagram\343\200\221/src/Test.java" @@ -0,0 +1,12 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 10:35 + **/ +public class Test { + public static void main(String[] args) { + Solution solution = new Solution(); + + System.out.println(solution.isAnagram("anagram", "nagaram")); + System.out.println(solution.isAnagram("rat", "car")); + } +} From 6cecaffcd50686c0b5e963ad28510652bf193f14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Wed, 10 Oct 2018 13:32:28 +0800 Subject: [PATCH 025/108] commit --- .gitignore | 2 +- .idea/modules.xml | 2 + .../src/Solution.java" | 56 +++++++++++++++++++ .../src/Test.java" | 16 ++++++ .../src/TreeNode.java" | 15 +++++ .../src/Solution.java" | 26 +++++++++ 6 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 "\343\200\220257\343\200\221\343\200\220Binary Tree Paths\343\200\221/src/Solution.java" create mode 100644 "\343\200\220257\343\200\221\343\200\220Binary Tree Paths\343\200\221/src/Test.java" create mode 100644 "\343\200\220257\343\200\221\343\200\220Binary Tree Paths\343\200\221/src/TreeNode.java" create mode 100644 "\343\200\220258\343\200\221\343\200\220Add Digits\343\200\221/src/Solution.java" diff --git a/.gitignore b/.gitignore index bdafa63..ded3800 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ # Created by .ignore support plugin (hsz.mobi) -out + out .idea *.iml diff --git a/.idea/modules.xml b/.idea/modules.xml index 58dc29a..6b6acf6 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -154,6 +154,8 @@ + + \ No newline at end of file diff --git "a/\343\200\220257\343\200\221\343\200\220Binary Tree Paths\343\200\221/src/Solution.java" "b/\343\200\220257\343\200\221\343\200\220Binary Tree Paths\343\200\221/src/Solution.java" new file mode 100644 index 0000000..6480a96 --- /dev/null +++ "b/\343\200\220257\343\200\221\343\200\220Binary Tree Paths\343\200\221/src/Solution.java" @@ -0,0 +1,56 @@ +import java.util.LinkedList; +import java.util.List; + +/** + *
+ * Definition for a binary tree node.
+ * public class TreeNode {
+ *     int val;
+ *     TreeNode left;
+ *     TreeNode right;
+ *     TreeNode(int x) { val = x; }
+ * }
+ * 
+ * + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 11:16 + **/ +public class Solution { + public List binaryTreePaths(TreeNode root) { + List result = new LinkedList<>(); + binaryTreePaths(root, new LinkedList<>(), result); + + return result; + } + + private void binaryTreePaths(TreeNode root, LinkedList path, List result) { + + if (root == null) { + return; + } + + path.add(root); + + if (root.left == null && root.right == null) { + addResult(path, result); + } else { + binaryTreePaths(root.left, path, result); + binaryTreePaths(root.right, path, result); + } + + path.remove(path.size() - 1); + } + + private void addResult(LinkedList path, List result) { + StringBuilder builder = new StringBuilder(); + if (path != null) { + for (TreeNode node : path) { + builder.append("->").append(node.val); + } + } + + if (builder.length() > 0) { + result.add(builder.substring(2)); + } + } +} diff --git "a/\343\200\220257\343\200\221\343\200\220Binary Tree Paths\343\200\221/src/Test.java" "b/\343\200\220257\343\200\221\343\200\220Binary Tree Paths\343\200\221/src/Test.java" new file mode 100644 index 0000000..318a15c --- /dev/null +++ "b/\343\200\220257\343\200\221\343\200\220Binary Tree Paths\343\200\221/src/Test.java" @@ -0,0 +1,16 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 11:25 + **/ +public class Test { + public static void main(String[] args) { + Solution solution = new Solution(); + + TreeNode root = new TreeNode(1); + root.left = new TreeNode(2); + root.right = new TreeNode(3); + root.left.right = new TreeNode(5); + + System.out.println(solution.binaryTreePaths(root)); + } +} diff --git "a/\343\200\220257\343\200\221\343\200\220Binary Tree Paths\343\200\221/src/TreeNode.java" "b/\343\200\220257\343\200\221\343\200\220Binary Tree Paths\343\200\221/src/TreeNode.java" new file mode 100644 index 0000000..2e248fe --- /dev/null +++ "b/\343\200\220257\343\200\221\343\200\220Binary Tree Paths\343\200\221/src/TreeNode.java" @@ -0,0 +1,15 @@ +/** + * Author: 王俊超 + * Date: 2015-06-18 + * Time: 10:02 + * Declaration: All Rights Reserved !!! + */ +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} diff --git "a/\343\200\220258\343\200\221\343\200\220Add Digits\343\200\221/src/Solution.java" "b/\343\200\220258\343\200\221\343\200\220Add Digits\343\200\221/src/Solution.java" new file mode 100644 index 0000000..4be177f --- /dev/null +++ "b/\343\200\220258\343\200\221\343\200\220Add Digits\343\200\221/src/Solution.java" @@ -0,0 +1,26 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 13:28 + **/ +public class Solution { + public int addDigits(int num) { + + if (num < 0) { + throw new IllegalArgumentException("input num :" + num + ", must not be negative"); + } + + int result = 0; + + while (num != 0) { + result += num % 10; + num /= 10; + + if (num == 0 && result > 9) { + num = result; + result = 0; + } + } + + return result; + } +} From 9ad71d796dcb249ae76c3285f9cb7ef4a6692e87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Wed, 10 Oct 2018 13:49:55 +0800 Subject: [PATCH 026/108] commit --- .idea/modules.xml | 1 + .../src/Solution.java" | 3 +- .../src/Test.java" | 13 +++++++++ .../src/Solution.java" | 29 +++++++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 "\343\200\220258\343\200\221\343\200\220Add Digits\343\200\221/src/Test.java" create mode 100644 "\343\200\220263\343\200\221\343\200\220Ugly Number\343\200\221/src/Solution.java" diff --git a/.idea/modules.xml b/.idea/modules.xml index 6b6acf6..1838c0a 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -156,6 +156,7 @@ + \ No newline at end of file diff --git "a/\343\200\220258\343\200\221\343\200\220Add Digits\343\200\221/src/Solution.java" "b/\343\200\220258\343\200\221\343\200\220Add Digits\343\200\221/src/Solution.java" index 4be177f..ff595f5 100644 --- "a/\343\200\220258\343\200\221\343\200\220Add Digits\343\200\221/src/Solution.java" +++ "b/\343\200\220258\343\200\221\343\200\220Add Digits\343\200\221/src/Solution.java" @@ -11,10 +11,11 @@ public int addDigits(int num) { int result = 0; - while (num != 0) { + while (num > 0) { result += num % 10; num /= 10; + // 需要重新进行位相加 if (num == 0 && result > 9) { num = result; result = 0; diff --git "a/\343\200\220258\343\200\221\343\200\220Add Digits\343\200\221/src/Test.java" "b/\343\200\220258\343\200\221\343\200\220Add Digits\343\200\221/src/Test.java" new file mode 100644 index 0000000..d3afaa3 --- /dev/null +++ "b/\343\200\220258\343\200\221\343\200\220Add Digits\343\200\221/src/Test.java" @@ -0,0 +1,13 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 13:35 + **/ +public class Test { + public static void main(String[] args) { + Solution solution = new Solution(); + + System.out.println(solution.addDigits(38)); + System.out.println(solution.addDigits(999999999)); + System.out.println(solution.addDigits(100000000)); + } +} diff --git "a/\343\200\220263\343\200\221\343\200\220Ugly Number\343\200\221/src/Solution.java" "b/\343\200\220263\343\200\221\343\200\220Ugly Number\343\200\221/src/Solution.java" new file mode 100644 index 0000000..3e7a0f4 --- /dev/null +++ "b/\343\200\220263\343\200\221\343\200\220Ugly Number\343\200\221/src/Solution.java" @@ -0,0 +1,29 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 13:45 + **/ +public class Solution { + public boolean isUgly(int num) { + + if (num < 1) { + return false; + } else if (num == 1) { + return true; + } + + int remainder; + while ((num % 2) == 0) { + num /= 2; + } + + while ((num % 3) == 0) { + num /= 3; + } + + while ((num % 5) == 0) { + num /= 5; + } + + return num == 1; + } +} From 535e983f5209b3f42c9772036ff91d03bdeb8134 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Wed, 10 Oct 2018 13:52:27 +0800 Subject: [PATCH 027/108] commit --- .../src/Solution.java" | 1 - .../src/Test.java" | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 "\343\200\220263\343\200\221\343\200\220Ugly Number\343\200\221/src/Test.java" diff --git "a/\343\200\220263\343\200\221\343\200\220Ugly Number\343\200\221/src/Solution.java" "b/\343\200\220263\343\200\221\343\200\220Ugly Number\343\200\221/src/Solution.java" index 3e7a0f4..a05b03c 100644 --- "a/\343\200\220263\343\200\221\343\200\220Ugly Number\343\200\221/src/Solution.java" +++ "b/\343\200\220263\343\200\221\343\200\220Ugly Number\343\200\221/src/Solution.java" @@ -11,7 +11,6 @@ public boolean isUgly(int num) { return true; } - int remainder; while ((num % 2) == 0) { num /= 2; } diff --git "a/\343\200\220263\343\200\221\343\200\220Ugly Number\343\200\221/src/Test.java" "b/\343\200\220263\343\200\221\343\200\220Ugly Number\343\200\221/src/Test.java" new file mode 100644 index 0000000..dccb247 --- /dev/null +++ "b/\343\200\220263\343\200\221\343\200\220Ugly Number\343\200\221/src/Test.java" @@ -0,0 +1,16 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 13:50 + **/ +public class Test { + public static void main(String[] args) { + Solution solution = new Solution(); + + System.out.println(solution.isUgly(-1)); + System.out.println(solution.isUgly(0)); + System.out.println(solution.isUgly(1)); + System.out.println(solution.isUgly(6)); + System.out.println(solution.isUgly(8)); + System.out.println(solution.isUgly(14)); + } +} From ecb33a67afff5e8a165921eb2c67ff868fc975a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Wed, 10 Oct 2018 14:25:08 +0800 Subject: [PATCH 028/108] commit --- .idea/modules.xml | 1 + .../src/Solution.java" | 39 +++++++++++++++++++ .../src/Test.java" | 21 ++++++++++ 3 files changed, 61 insertions(+) create mode 100644 "\343\200\220268\343\200\221\343\200\220Missing Number\343\200\221/src/Solution.java" create mode 100644 "\343\200\220268\343\200\221\343\200\220Missing Number\343\200\221/src/Test.java" diff --git a/.idea/modules.xml b/.idea/modules.xml index 1838c0a..0d85b7f 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -157,6 +157,7 @@ + \ No newline at end of file diff --git "a/\343\200\220268\343\200\221\343\200\220Missing Number\343\200\221/src/Solution.java" "b/\343\200\220268\343\200\221\343\200\220Missing Number\343\200\221/src/Solution.java" new file mode 100644 index 0000000..0ad6903 --- /dev/null +++ "b/\343\200\220268\343\200\221\343\200\220Missing Number\343\200\221/src/Solution.java" @@ -0,0 +1,39 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 14:02 + **/ +public class Solution { + public int missingNumber(int[] nums) { + + if (nums == null || nums.length < 1) { + throw new IllegalArgumentException("array should contain at least one element"); + } + + for (int i = 0; i < nums.length; i++) { + // 只会存在一个大于nums.length的数,将其放在数组最后一个位置 + if (nums[i] > nums.length) { + swap(nums, i, nums.length - 1); + } + + // 交换位置,直到nums[i] = i + while (nums[i] != i && nums[i] < nums.length) { + swap(nums, i, nums[i]); + } + } + + // 找出丢失的元素 + for (int i = 0; i < nums.length; i++) { + if (nums[i] != i) { + return i; + } + } + + return nums.length; + } + + private void swap(int[] nums, int x, int y) { + int temp = nums[x]; + nums[x] = nums[y]; + nums[y] = temp; + } +} diff --git "a/\343\200\220268\343\200\221\343\200\220Missing Number\343\200\221/src/Test.java" "b/\343\200\220268\343\200\221\343\200\220Missing Number\343\200\221/src/Test.java" new file mode 100644 index 0000000..a4452e8 --- /dev/null +++ "b/\343\200\220268\343\200\221\343\200\220Missing Number\343\200\221/src/Test.java" @@ -0,0 +1,21 @@ +import java.util.Arrays; + +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 14:14 + **/ +public class Test { + public static void main(String[] args) { + Solution solution = new Solution(); + + missingNumber(solution, new int[]{0}); + missingNumber(solution, new int[]{3, 0, 1}); + missingNumber(solution, new int[]{9, 6, 4, 2, 3, 5, 7, 0, 1}); + missingNumber(solution, new int[]{8, 6, 4, 2, 3, 5, 7, 0, 1}); + } + + private static void missingNumber(Solution solution, int[] array) { + System.out.println(solution.missingNumber(array)); + System.out.println(Arrays.toString(array)); + } +} From a4f39925a06310da54c1662926ce128f89d6ff75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Wed, 10 Oct 2018 17:04:05 +0800 Subject: [PATCH 029/108] commit --- .idea/modules.xml | 1 + .../src/Solution.java" | 39 +++++++++++++++++++ .../src/Test.java" | 12 ++++++ .../src/VersionControl.java" | 20 ++++++++++ 4 files changed, 72 insertions(+) create mode 100644 "\343\200\220278\343\200\221\343\200\220First Bad Version\343\200\221/src/Solution.java" create mode 100644 "\343\200\220278\343\200\221\343\200\220First Bad Version\343\200\221/src/Test.java" create mode 100644 "\343\200\220278\343\200\221\343\200\220First Bad Version\343\200\221/src/VersionControl.java" diff --git a/.idea/modules.xml b/.idea/modules.xml index 0d85b7f..663325e 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -158,6 +158,7 @@ + \ No newline at end of file diff --git "a/\343\200\220278\343\200\221\343\200\220First Bad Version\343\200\221/src/Solution.java" "b/\343\200\220278\343\200\221\343\200\220First Bad Version\343\200\221/src/Solution.java" new file mode 100644 index 0000000..2f344d1 --- /dev/null +++ "b/\343\200\220278\343\200\221\343\200\220First Bad Version\343\200\221/src/Solution.java" @@ -0,0 +1,39 @@ +/** + *
+ * The isBadVersion API is defined in the parent class VersionControl.
+ *       boolean isBadVersion(int version);
+ * 
+ * + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 14:26 + **/ +public class Solution extends VersionControl { + public int firstBadVersion(int n) { + + if (!isBadVersion(n)) { + return 0; + } + + int hi = n; + int lo = 1; + int mid; + + while (hi >= lo) { + mid = lo + (hi - lo) / 2; + if (isBadVersion(mid)) { + // 当前是1号版本,或者前一个是合法版本,那么当前版本就是第一个非法的版本 + if (mid == 1 || (mid > 1 && !isBadVersion(mid - 1))) { + return mid; + } else { + // 非法的版本在[lo, mid-1]间 + hi = mid - 1; + } + } else { + // 非法版本在[mid + 1, hi]间 + lo = mid + 1; + } + } + + return 0; + } +} diff --git "a/\343\200\220278\343\200\221\343\200\220First Bad Version\343\200\221/src/Test.java" "b/\343\200\220278\343\200\221\343\200\220First Bad Version\343\200\221/src/Test.java" new file mode 100644 index 0000000..3a57cd6 --- /dev/null +++ "b/\343\200\220278\343\200\221\343\200\220First Bad Version\343\200\221/src/Test.java" @@ -0,0 +1,12 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 16:55 + **/ +public class Test { + public static void main(String[] args) { + Solution solution = new Solution(); + + solution.setBadVersion(new boolean[]{false, false, false, true, true}); + System.out.println(solution.firstBadVersion(5)); + } +} diff --git "a/\343\200\220278\343\200\221\343\200\220First Bad Version\343\200\221/src/VersionControl.java" "b/\343\200\220278\343\200\221\343\200\220First Bad Version\343\200\221/src/VersionControl.java" new file mode 100644 index 0000000..d124b97 --- /dev/null +++ "b/\343\200\220278\343\200\221\343\200\220First Bad Version\343\200\221/src/VersionControl.java" @@ -0,0 +1,20 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 14:27 + **/ +public class VersionControl { + + private boolean[] badVersion; + + public boolean isBadVersion(int version){ + return badVersion[version - 1]; + } + + public boolean[] getBadVersion() { + return badVersion; + } + + public void setBadVersion(boolean[] badVersion) { + this.badVersion = badVersion; + } +} From 0879ca861640194412b9425c0f99033547fa91ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Wed, 10 Oct 2018 17:20:45 +0800 Subject: [PATCH 030/108] commit --- .idea/modules.xml | 1 + .../src/Solution.java" | 44 +++++++++++++++++++ .../src/Test.java" | 20 +++++++++ 3 files changed, 65 insertions(+) create mode 100644 "\343\200\220283\343\200\221\343\200\220Move Zeroes\343\200\221/src/Solution.java" create mode 100644 "\343\200\220283\343\200\221\343\200\220Move Zeroes\343\200\221/src/Test.java" diff --git a/.idea/modules.xml b/.idea/modules.xml index 663325e..c3501c9 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -159,6 +159,7 @@ + \ No newline at end of file diff --git "a/\343\200\220283\343\200\221\343\200\220Move Zeroes\343\200\221/src/Solution.java" "b/\343\200\220283\343\200\221\343\200\220Move Zeroes\343\200\221/src/Solution.java" new file mode 100644 index 0000000..4afeb4a --- /dev/null +++ "b/\343\200\220283\343\200\221\343\200\220Move Zeroes\343\200\221/src/Solution.java" @@ -0,0 +1,44 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 17:04 + **/ +public class Solution { + public void moveZeroes(int[] nums) { + + if (nums == null || nums.length < 1) { + return; + } + + int idx = 0; + // 找第一个0的位置 + while (idx < nums.length && nums[idx] != 0) { + idx++; + } + + // 数组的值都非0 + if (idx >= nums.length) { + return; + } + + int temp = idx + 1; + + while (temp < nums.length) { + // 找temp开始第一个非0的位置 + while (temp < nums.length && nums[temp] == 0) { + temp++; + } + + // 找到非0值,移动到idx位置 + if (temp < nums.length) { + nums[idx] = nums[temp]; + idx++; + temp++; + } + } + + // 从[idx, nums.length-1]的长度都设置为0 + for (int i = idx; i < nums.length; i++) { + nums[i] = 0; + } + } +} diff --git "a/\343\200\220283\343\200\221\343\200\220Move Zeroes\343\200\221/src/Test.java" "b/\343\200\220283\343\200\221\343\200\220Move Zeroes\343\200\221/src/Test.java" new file mode 100644 index 0000000..1c5d20c --- /dev/null +++ "b/\343\200\220283\343\200\221\343\200\220Move Zeroes\343\200\221/src/Test.java" @@ -0,0 +1,20 @@ +import java.util.Arrays; + +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 17:11 + **/ +public class Test { + public static void main(String[] args) { + moveZeros(new int[]{0, 1, 0, 3, 12}); + moveZeros(new int[]{2, 1, 6, 3, 12}); + moveZeros(new int[]{2}); + moveZeros(new int[]{0}); + } + + private static void moveZeros(int[] a1) { + Solution solution = new Solution(); + solution.moveZeroes(a1); + System.out.println(Arrays.toString(a1)); + } +} From f68ebb69d3914603c345fbeb8f32b1ebbb5b8ffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Wed, 10 Oct 2018 18:11:47 +0800 Subject: [PATCH 031/108] commit --- .idea/modules.xml | 1 + .../src/Solution.java" | 48 +++++++++++++++++++ .../src/Test.java" | 14 ++++++ 3 files changed, 63 insertions(+) create mode 100644 "\343\200\220290\343\200\221\343\200\220Word Pattern\343\200\221/src/Solution.java" create mode 100644 "\343\200\220290\343\200\221\343\200\220Word Pattern\343\200\221/src/Test.java" diff --git a/.idea/modules.xml b/.idea/modules.xml index c3501c9..cf62bdf 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -160,6 +160,7 @@ + \ No newline at end of file diff --git "a/\343\200\220290\343\200\221\343\200\220Word Pattern\343\200\221/src/Solution.java" "b/\343\200\220290\343\200\221\343\200\220Word Pattern\343\200\221/src/Solution.java" new file mode 100644 index 0000000..580d1c2 --- /dev/null +++ "b/\343\200\220290\343\200\221\343\200\220Word Pattern\343\200\221/src/Solution.java" @@ -0,0 +1,48 @@ +import java.util.HashMap; +import java.util.Map; + +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 17:24 + **/ +public class Solution { + public boolean wordPattern(String pattern, String str) { + + if (pattern == null && str == null) { + return true; + } else if (pattern == null || str == null) { + return false; + } + + String[] parts = str.split("\\s+"); + + if (pattern.length() != parts.length) { + return false; + } + + Map map = new HashMap<>(); + Map rmap = new HashMap<>(); + + Character c; + for (int i = 0; i < pattern.length(); i++) { + c = pattern.charAt(i); + if (!map.containsKey(c)) { + map.put(c, parts[i]); + } else { + if (!parts[i].equals(map.get(c))) { + return false; + } + } + // 双射,两边都要验证 + if (!rmap.containsKey(parts[i])) { + rmap.put(parts[i], c); + } else { + if (!c.equals(rmap.get(parts[i]))) { + return false; + } + } + } + + return true; + } +} diff --git "a/\343\200\220290\343\200\221\343\200\220Word Pattern\343\200\221/src/Test.java" "b/\343\200\220290\343\200\221\343\200\220Word Pattern\343\200\221/src/Test.java" new file mode 100644 index 0000000..6c75500 --- /dev/null +++ "b/\343\200\220290\343\200\221\343\200\220Word Pattern\343\200\221/src/Test.java" @@ -0,0 +1,14 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 17:29 + **/ +public class Test { + public static void main(String[] args) { + Solution solution = new Solution(); + + System.out.println(solution.wordPattern("abba", "dog cat cat dog")); + System.out.println(solution.wordPattern("abba", "dog cat cat fish")); + System.out.println(solution.wordPattern("aaaa", "dog cat cat dog")); + System.out.println(solution.wordPattern("abba", "dog dog dog dog")); + } +} From 7df64b1a42c790d9a1cb95091472eade4ce5b9b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Fri, 12 Oct 2018 14:19:55 +0800 Subject: [PATCH 032/108] commit --- .idea/modules.xml | 1 + .../src/NumArray.java" | 34 +++++++++++++++++++ .../src/Test.java" | 12 +++++++ 3 files changed, 47 insertions(+) create mode 100644 "\343\200\220303\343\200\221\343\200\220Range Sum Query - Immutable\343\200\221/src/NumArray.java" create mode 100644 "\343\200\220303\343\200\221\343\200\220Range Sum Query - Immutable\343\200\221/src/Test.java" diff --git a/.idea/modules.xml b/.idea/modules.xml index cf62bdf..53e639d 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -161,6 +161,7 @@ + \ No newline at end of file diff --git "a/\343\200\220303\343\200\221\343\200\220Range Sum Query - Immutable\343\200\221/src/NumArray.java" "b/\343\200\220303\343\200\221\343\200\220Range Sum Query - Immutable\343\200\221/src/NumArray.java" new file mode 100644 index 0000000..fb70aae --- /dev/null +++ "b/\343\200\220303\343\200\221\343\200\220Range Sum Query - Immutable\343\200\221/src/NumArray.java" @@ -0,0 +1,34 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-12 13:53 + **/ +public class NumArray { + private int[] nums; + + public NumArray(int[] nums) { + this.nums = nums; + } + + public int sumRange(int i, int j) { + + if (i > j) { + throw new IllegalArgumentException("i = " + i + ", j = " + j +", i must not greater than j"); + } + + if (j < 0) { + throw new IllegalArgumentException("i = " + i + ", j = " + j +", i must not less than 0"); + } + + i = i < 0 ? 0 : i; + j = j >= nums.length ? nums.length - 1 : j; + + int sum = 0; + + + for (int k = i; k <= j; k++) { + sum += nums[k]; + } + + return sum; + } +} diff --git "a/\343\200\220303\343\200\221\343\200\220Range Sum Query - Immutable\343\200\221/src/Test.java" "b/\343\200\220303\343\200\221\343\200\220Range Sum Query - Immutable\343\200\221/src/Test.java" new file mode 100644 index 0000000..470204f --- /dev/null +++ "b/\343\200\220303\343\200\221\343\200\220Range Sum Query - Immutable\343\200\221/src/Test.java" @@ -0,0 +1,12 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-12 14:17 + **/ +public class Test { + public static void main(String[] args) { + NumArray array = new NumArray(new int[]{-2, 0, 3, -5, 2, -1}); + System.out.println(array.sumRange(0, 2)); + System.out.println(array.sumRange(2, 5)); + System.out.println(array.sumRange(0, 5)); + } +} From dbe34409549db78d84b9e4b91df8548a8f262144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Fri, 16 Nov 2018 15:39:01 +0800 Subject: [PATCH 033/108] commit --- .idea/modules.xml | 1 + .../src/Solution.java" | 25 +++++++++++++++++++ .../src/Test.java" | 13 ++++++++++ 3 files changed, 39 insertions(+) create mode 100644 "\343\200\220326\343\200\221\343\200\220Power of Three\343\200\221/src/Solution.java" create mode 100644 "\343\200\220326\343\200\221\343\200\220Power of Three\343\200\221/src/Test.java" diff --git a/.idea/modules.xml b/.idea/modules.xml index 53e639d..7190bcb 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -162,6 +162,7 @@ + \ No newline at end of file diff --git "a/\343\200\220326\343\200\221\343\200\220Power of Three\343\200\221/src/Solution.java" "b/\343\200\220326\343\200\221\343\200\220Power of Three\343\200\221/src/Solution.java" new file mode 100644 index 0000000..8ab7b8d --- /dev/null +++ "b/\343\200\220326\343\200\221\343\200\220Power of Three\343\200\221/src/Solution.java" @@ -0,0 +1,25 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-11-16 15:21 + **/ +public class Solution { + + public boolean isPowerOfThree(int n) { + double rst = (Math.log10(n) / Math.log10(3)); + return n > 0 &&Double.doubleToLongBits((int)rst) == Double.doubleToLongBits(rst); + } + + public boolean isPowerOfThree2(int n) { + return (n > 0 && 1162261467 % n == 0); + } + + public boolean isPowerOfThree1(int n) { + while (n > 1 && n % 3 == 0) { + n /= 3; + } + + return n == 1; + } + + +} diff --git "a/\343\200\220326\343\200\221\343\200\220Power of Three\343\200\221/src/Test.java" "b/\343\200\220326\343\200\221\343\200\220Power of Three\343\200\221/src/Test.java" new file mode 100644 index 0000000..c99e19b --- /dev/null +++ "b/\343\200\220326\343\200\221\343\200\220Power of Three\343\200\221/src/Test.java" @@ -0,0 +1,13 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-11-16 15:31 + **/ +public class Test { + public static void main(String[] args) { + System.out.println(Double.doubleToLongBits((int)1.00000000001) + == Double.doubleToLongBits(1.00000000001)); + + System.out.println(Double.doubleToLongBits((int)1.00000000000) + == Double.doubleToLongBits(1.00000000000)); + } +} From 29e5144c10891c04b472436e1f54faec5bea1042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Fri, 16 Nov 2018 16:01:32 +0800 Subject: [PATCH 034/108] commit --- .idea/modules.xml | 1 + .../src/Solution.java" | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 "\343\200\220342\343\200\221\343\200\220Power of Four\343\200\221/src/Solution.java" diff --git a/.idea/modules.xml b/.idea/modules.xml index 7190bcb..31ebd57 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -163,6 +163,7 @@ + \ No newline at end of file diff --git "a/\343\200\220342\343\200\221\343\200\220Power of Four\343\200\221/src/Solution.java" "b/\343\200\220342\343\200\221\343\200\220Power of Four\343\200\221/src/Solution.java" new file mode 100644 index 0000000..1466de8 --- /dev/null +++ "b/\343\200\220342\343\200\221\343\200\220Power of Four\343\200\221/src/Solution.java" @@ -0,0 +1,29 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-11-16 15:43 + **/ +public class Solution { + + public boolean isPowerOfFour(int num) { + return num > 0 && (num & (num - 1)) == 0 && (num - 1) % 3 == 0; + } + + + public boolean isPowerOfFour3(int num) { + int n = 0b1010101_01010101_01010101_01010101; +// int n = 0x55555555; + return num > 0 && (num & (num - 1)) == 0 && (num & n) == num; + } + + public boolean isPowerOfFour2(int num) { + double rst = (Math.log10(num) / Math.log10(4)); + return num > 0 && Double.doubleToLongBits((int) rst) == Double.doubleToLongBits(rst); + } + + public boolean isPowerOfFour1(int num) { + while (num > 1 && (num % 4 == 0)) { + num /= 4; + } + return num == 1; + } +} From 0fe86d5cfddf73398fef5662699d744ffe031480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E8=B6=85?= Date: Fri, 16 Nov 2018 16:08:51 +0800 Subject: [PATCH 035/108] commit --- .idea/modules.xml | 1 + .../src/Solution.java" | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 "\343\200\220344\343\200\221\343\200\220Reverse String\343\200\221/src/Solution.java" diff --git a/.idea/modules.xml b/.idea/modules.xml index 31ebd57..9e0dcd8 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -164,6 +164,7 @@ + \ No newline at end of file diff --git "a/\343\200\220344\343\200\221\343\200\220Reverse String\343\200\221/src/Solution.java" "b/\343\200\220344\343\200\221\343\200\220Reverse String\343\200\221/src/Solution.java" new file mode 100644 index 0000000..955ed6b --- /dev/null +++ "b/\343\200\220344\343\200\221\343\200\220Reverse String\343\200\221/src/Solution.java" @@ -0,0 +1,25 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-11-16 16:04 + **/ +public class Solution { + public String reverseString(String s) { + if (s == null || s.length() < 1) { + return s; + } + + char[] chars = s.toCharArray(); + + for (int i = 0, j = chars.length - 1; i Date: Thu, 13 Jun 2019 06:14:38 +0800 Subject: [PATCH 036/108] commit --- .idea/modules.xml | 1 + ...200\221\343\200\220TwoSum\343\200\221.iml" | 2 + ...\343\200\220AddTwoNumbers\343\200\221.iml" | 2 + ...ithoutRepeatingCharacters\343\200\221.iml" | 2 + ...20MedianofTwoSortedArrays\343\200\221.iml" | 2 + ...alindromicSubstringTotal \343\200\221.iml" | 2 + ...3\200\220ZigZagConversion\343\200\221.iml" | 2 + ...343\200\220ReverseInteger\343\200\221.iml" | 2 + ...220StringToInteger (atoi)\343\200\221.iml" | 2 + ...3\200\220PalindromeNumber\343\200\221.iml" | 2 + ...RegularExpressionMatching\343\200\221.iml" | 2 + ...20ContainerWithMost Water\343\200\221.iml" | 2 + ...343\200\220IntegerToRoman\343\200\221.iml" | 2 + ...343\200\220RomarToInteger\343\200\221.iml" | 2 + ...00\220LongestCommonPrefix\343\200\221.iml" | 2 + ...3\200\221\343\200\2203Sum\343\200\221.iml" | 2 + ...21\343\200\2203SumClosest\343\200\221.iml" | 2 + ...ombinationsOfAPhonNumber \343\200\221.iml" | 2 + ...3\200\221\343\200\2204Sum\343\200\221.iml" | 2 + ...emoveNthNodeFromEndOfList\343\200\221.iml" | 2 + ...3\200\220ValidParentheses\343\200\221.iml" | 2 + ...00\220MergeTwoSortedLists\343\200\221.iml" | 2 + ...00\220GenerateParentheses\343\200\221.iml" | 2 + ...\200\220MergeKSortedLists\343\200\221.iml" | 2 + ...3\200\220SwapNodesInPairs\343\200\221.iml" | 2 + ...\220ReverseNodesInK-Group\343\200\221.iml" | 2 + .../src/Solution.java" | 27 ++++---- .../src/Solution2.java" | 57 ++++++++++++++++ ...DuplicatesfromSortedArray\343\200\221.iml" | 2 + ...\343\200\220RemoveElement\343\200\221.iml" | 2 + ...200\220Implement-strStr()\343\200\221.iml" | 2 + ...\200\220DivideTwoIntegers\343\200\221.iml" | 2 + ...thConcatenationOfAllWords\343\200\221.iml" | 2 + ...20LongestValidParentheses\343\200\221.iml" | 2 + .../src/Main.java" | 14 ++++ .../src/Solution2.java" | 65 +++++++++++++++++++ ...earchInRotatedSortedArray\343\200\221.iml" | 2 + ...43\200\220SearchForARange\343\200\221.iml" | 2 + ...0\220SearchInsertPosition\343\200\221.iml" | 2 + ...1\343\200\220Valid Sudoku\343\200\221.iml" | 2 + ...\343\200\220Sudoku Solver\343\200\221.iml" | 2 + ...21\343\200\220CountAndSay\343\200\221.iml" | 2 + ...43\200\220Combination Sum\343\200\221.iml" | 2 + ...200\220Combination Sum II\343\200\221.iml" | 2 + ...220First Missing Positive\343\200\221.iml" | 2 + ...00\220Trapping Rain Water\343\200\221.iml" | 2 + ...3\200\220Multiply Strings\343\200\221.iml" | 2 + ...\200\220Wildcard Matching\343\200\221.iml" | 2 + ...1\343\200\220Jump Game II\343\200\221.iml" | 2 + ...1\343\200\220Permutations\343\200\221.iml" | 2 + ...43\200\220Permutations II\343\200\221.iml" | 2 + ...1\343\200\220Rotate Image\343\200\221.iml" | 2 + ...343\200\220Group Anagrams\343\200\221.iml" | 2 + ...0\221\343\200\220Pow(x,n)\343\200\221.iml" | 2 + ...0\221\343\200\220N-Queens\343\200\221.iml" | 2 + ...21\343\200\220N-Queens II\343\200\221.iml" | 2 + ...43\200\220MaximumSubarray\343\200\221.iml" | 2 + ...1\343\200\220SpiralMatrix\343\200\221.iml" | 2 + ...\221\343\200\220Jump Game\343\200\221.iml" | 2 + ...343\200\220MergeIntervals\343\200\221.iml" | 2 + ...343\200\220InsertInterval\343\200\221.iml" | 2 + ...3\200\220LengthOfLastWord\343\200\221.iml" | 2 + ...343\200\220SpiralMatrixII\343\200\221.iml" | 2 + ...0\220Permutation Sequence\343\200\221.iml" | 2 + ...221\343\200\220RotateList\343\200\221.iml" | 2 + ...21\343\200\220UniquePaths\343\200\221.iml" | 2 + ...\343\200\220UniquePathsII\343\200\221.iml" | 2 + ...343\200\220MinimumPathSum\343\200\221.iml" | 2 + ...00\221\343\200\220PlusOne\343\200\221.iml" | 2 + ...\221\343\200\220AddBinary\343\200\221.iml" | 2 + ...343\200\220ClimbingStairs\343\200\221.iml" | 2 + ...\343\200\220Simplify Path\343\200\221.iml" | 2 + ...43\200\220SetMatrixZeroes\343\200\221.iml" | 2 + ...43\200\220SearchA2DMatrix\343\200\221.iml" | 2 + ...221\343\200\220SortColors\343\200\221.iml" | 2 + ...1\343\200\220Combinations\343\200\221.iml" | 2 + ...00\221\343\200\220Subsets\343\200\221.iml" | 2 + ...221\343\200\220WordSearch\343\200\221.iml" | 2 + .../src/Main.java" | 15 +++++ .../src/Solution.java" | 24 +++++++ .../src/Solution2.java" | 24 +++++++ ...archInRotatedSortedArraII\343\200\221.iml" | 2 + ...uplicatesFromSortedListII\343\200\221.iml" | 2 + ...eDuplicatesFromSortedList\343\200\221.iml" | 2 + ...\343\200\220PartitionList\343\200\221.iml" | 2 + ...3\200\220MergeSortedArray\343\200\221.iml" | 2 + ...0\221\343\200\220GrayCode\343\200\221.iml" | 2 + ...00\220ReverseLinkedListII\343\200\221.iml" | 2 + ...naryTree InorderTraversal\343\200\221.iml" | 2 + ...20UniqueBinarySearchTrees\343\200\221.iml" | 2 + ...0ValidateBinarySearchTree\343\200\221.iml" | 2 + ...0\221\343\200\220SameTree\343\200\221.iml" | 2 + ...\343\200\220SymmetricTree\343\200\221.iml" | 2 + ...ryTreeLevelOrderTraversal\343\200\221.iml" | 2 + ...ZigzagLevelOrderTraversal\343\200\221.iml" | 2 + ...0MaximumDepthOfBinaryTree\343\200\221.iml" | 2 + ...eorderAndInorderTraversal\343\200\221.iml" | 2 + ...rderAndPostorderTraversal\343\200\221.iml" | 2 + ...TreeLevelOrderTraversalII\343\200\221.iml" | 2 + ...edArrayToBinarySearchTree\343\200\221.iml" | 2 + ...tedListToBinarySearchTree\343\200\221.iml" | 2 + ...200\220BalancedBinaryTree\343\200\221.iml" | 2 + ...0MinimumDepthOfBinaryTree\343\200\221.iml" | 2 + ...00\221\343\200\220PathSum\343\200\221.iml" | 2 + ...\221\343\200\220PathSumII\343\200\221.iml" | 2 + ...tenBinaryTreeToLinkedList\343\200\221.iml" | 2 + ...tRightPointersinEachNode \343\200\221.iml" | 2 + ...RightPointersInEachNodeII\343\200\221.iml" | 2 + ...3\200\220Pascal'sTriangle\343\200\221.iml" | 2 + ...200\220Pascal'sTriangleII\343\200\221.iml" | 2 + ...0\221\343\200\220Triangle\343\200\221.iml" | 2 + ...BestTimeToBuyAndSellStock\343\200\221.iml" | 2 + ...0BinaryTreeMaximumPathSum\343\200\221.iml" | 2 + ...43\200\220ValidPalindrome\343\200\221.iml" | 2 + ...221\343\200\220WordLadder\343\200\221.iml" | 2 + ...0\220SumRootToLeafNumbers\343\200\221.iml" | 2 + ...\200\220SurroundedRegions\343\200\221.iml" | 2 + ...221\343\200\220GasStation\343\200\221.iml" | 2 + ...1\343\200\220SingleNumber\343\200\221.iml" | 2 + ...343\200\220SingleNumberII\343\200\221.iml" | 2 + ...CopyListWithRandomPointer\343\200\221.iml" | 2 + ...\221\343\200\220WordBreak\343\200\221.iml" | 2 + ...43\200\220LinkedListCycle\343\200\221.iml" | 2 + ...\200\220LinkedListCycleII\343\200\221.iml" | 2 + ...CopyListWithRandomPointer\343\200\221.iml" | 2 + ...naryTreePreorderTraversal\343\200\221.iml" | 2 + ...aryTreePostorderTraversal\343\200\221.iml" | 2 + ...\200\220InsertionSortList\343\200\221.iml" | 2 + ...uateReversePolishNotation\343\200\221.iml" | 2 + ...\220ReverseWordsInAString\343\200\221.iml" | 2 + ...220MaximumProductSubarray\343\200\221.iml" | 2 + ...nimumInRotatedSortedArray\343\200\221.iml" | 2 + ...mumInRotatedSortedArrayII\343\200\221.iml" | 2 + ...0\221\343\200\220MinStack\343\200\221.iml" | 2 + ...43\200\220FindPeakElement\343\200\221.iml" | 2 + ...I - Input array is sorted\343\200\221.iml" | 2 + ...\343\200\220NumberOf1Bits\343\200\221.iml" | 2 + ...21\343\200\220HouseRobber\343\200\221.iml" | 2 + ...20BinaryTreeRightSideView\343\200\221.iml" | 2 + ...43\200\220NumberOfIslands\343\200\221.iml" | 2 + ...0BitwiseANDOfNumbersRange\343\200\221.iml" | 2 + ...1\343\200\220HappyNumber \343\200\221.iml" | 2 + ...RemoveLinkedList Elements\343\200\221.iml" | 2 + ...21\343\200\220CountPrimes\343\200\221.iml" | 2 + ...\200\220IsomorphicStrings\343\200\221.iml" | 2 + ...\200\220ReverseLinkedList\343\200\221.iml" | 2 + ...thLargestElementInAnArray\343\200\221.iml" | 2 + ...\200\220CombinationSumIII\343\200\221.iml" | 2 + ...200\220ContainsDuplicate \343\200\221.iml" | 2 + ...00\220ContainsDuplicateII\343\200\221.iml" | 2 + ...\343\200\220RectangleArea\343\200\221.iml" | 2 + ...ImplementStackUsingQueues\343\200\221.iml" | 2 + ...\200\220InvertBinaryTree \343\200\221.iml" | 2 + 153 files changed, 502 insertions(+), 15 deletions(-) create mode 100644 "\343\200\220026\343\200\221\343\200\220RemoveDuplicatesfromSortedArray\343\200\221/src/Solution2.java" create mode 100644 "\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221/src/Main.java" create mode 100644 "\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221/src/Solution2.java" create mode 100644 "\343\200\220080\343\200\221\343\200\220Remove Duplicates from Sorted Array II\343\200\221/src/Main.java" create mode 100644 "\343\200\220080\343\200\221\343\200\220Remove Duplicates from Sorted Array II\343\200\221/src/Solution.java" create mode 100644 "\343\200\220080\343\200\221\343\200\220Remove Duplicates from Sorted Array II\343\200\221/src/Solution2.java" diff --git a/.idea/modules.xml b/.idea/modules.xml index 9e0dcd8..2b4658f 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -75,6 +75,7 @@ + diff --git "a/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221.iml" "b/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221.iml" +++ "b/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221.iml" @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git "a/\343\200\220002\343\200\221\343\200\220AddTwoNumbers\343\200\221/\343\200\220002\343\200\221\343\200\220AddTwoNumbers\343\200\221.iml" "b/\343\200\220002\343\200\221\343\200\220AddTwoNumbers\343\200\221/\343\200\220002\343\200\221\343\200\220AddTwoNumbers\343\200\221.iml" index b769534..bdc5d75 100644 --- "a/\343\200\220002\343\200\221\343\200\220AddTwoNumbers\343\200\221/\343\200\220002\343\200\221\343\200\220AddTwoNumbers\343\200\221.iml" +++ "b/\343\200\220002\343\200\221\343\200\220AddTwoNumbers\343\200\221/\343\200\220002\343\200\221\343\200\220AddTwoNumbers\343\200\221.iml" @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git "a/\343\200\220003\343\200\221\343\200\220LongestSubstringWithoutRepeatingCharacters\343\200\221/\343\200\220003\343\200\221\343\200\220LongestSubstringWithoutRepeatingCharacters\343\200\221.iml" "b/\343\200\220003\343\200\221\343\200\220LongestSubstringWithoutRepeatingCharacters\343\200\221/\343\200\220003\343\200\221\343\200\220LongestSubstringWithoutRepeatingCharacters\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220003\343\200\221\343\200\220LongestSubstringWithoutRepeatingCharacters\343\200\221/\343\200\220003\343\200\221\343\200\220LongestSubstringWithoutRepeatingCharacters\343\200\221.iml" +++ "b/\343\200\220003\343\200\221\343\200\220LongestSubstringWithoutRepeatingCharacters\343\200\221/\343\200\220003\343\200\221\343\200\220LongestSubstringWithoutRepeatingCharacters\343\200\221.iml" @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git "a/\343\200\220004\343\200\221\343\200\220MedianofTwoSortedArrays\343\200\221/\343\200\220004\343\200\221\343\200\220MedianofTwoSortedArrays\343\200\221.iml" "b/\343\200\220004\343\200\221\343\200\220MedianofTwoSortedArrays\343\200\221/\343\200\220004\343\200\221\343\200\220MedianofTwoSortedArrays\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220004\343\200\221\343\200\220MedianofTwoSortedArrays\343\200\221/\343\200\220004\343\200\221\343\200\220MedianofTwoSortedArrays\343\200\221.iml" +++ "b/\343\200\220004\343\200\221\343\200\220MedianofTwoSortedArrays\343\200\221/\343\200\220004\343\200\221\343\200\220MedianofTwoSortedArrays\343\200\221.iml" @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git "a/\343\200\220005\343\200\221\343\200\220LongestPalindromicSubstringTotal \343\200\221/\343\200\220005\343\200\221\343\200\220LongestPalindromicSubstringTotal \343\200\221.iml" "b/\343\200\220005\343\200\221\343\200\220LongestPalindromicSubstringTotal \343\200\221/\343\200\220005\343\200\221\343\200\220LongestPalindromicSubstringTotal \343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220005\343\200\221\343\200\220LongestPalindromicSubstringTotal \343\200\221/\343\200\220005\343\200\221\343\200\220LongestPalindromicSubstringTotal \343\200\221.iml" +++ "b/\343\200\220005\343\200\221\343\200\220LongestPalindromicSubstringTotal \343\200\221/\343\200\220005\343\200\221\343\200\220LongestPalindromicSubstringTotal \343\200\221.iml" @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git "a/\343\200\220006\343\200\221\343\200\220ZigZagConversion\343\200\221/\343\200\220006\343\200\221\343\200\220ZigZagConversion\343\200\221.iml" "b/\343\200\220006\343\200\221\343\200\220ZigZagConversion\343\200\221/\343\200\220006\343\200\221\343\200\220ZigZagConversion\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220006\343\200\221\343\200\220ZigZagConversion\343\200\221/\343\200\220006\343\200\221\343\200\220ZigZagConversion\343\200\221.iml" +++ "b/\343\200\220006\343\200\221\343\200\220ZigZagConversion\343\200\221/\343\200\220006\343\200\221\343\200\220ZigZagConversion\343\200\221.iml" @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git "a/\343\200\220007\343\200\221\343\200\220ReverseInteger\343\200\221/\343\200\220007\343\200\221\343\200\220ReverseInteger\343\200\221.iml" "b/\343\200\220007\343\200\221\343\200\220ReverseInteger\343\200\221/\343\200\220007\343\200\221\343\200\220ReverseInteger\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220007\343\200\221\343\200\220ReverseInteger\343\200\221/\343\200\220007\343\200\221\343\200\220ReverseInteger\343\200\221.iml" +++ "b/\343\200\220007\343\200\221\343\200\220ReverseInteger\343\200\221/\343\200\220007\343\200\221\343\200\220ReverseInteger\343\200\221.iml" @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git "a/\343\200\220008\343\200\221\343\200\220StringToInteger (atoi)\343\200\221/\343\200\220008\343\200\221\343\200\220StringToInteger (atoi)\343\200\221.iml" "b/\343\200\220008\343\200\221\343\200\220StringToInteger (atoi)\343\200\221/\343\200\220008\343\200\221\343\200\220StringToInteger (atoi)\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220008\343\200\221\343\200\220StringToInteger (atoi)\343\200\221/\343\200\220008\343\200\221\343\200\220StringToInteger (atoi)\343\200\221.iml" +++ "b/\343\200\220008\343\200\221\343\200\220StringToInteger (atoi)\343\200\221/\343\200\220008\343\200\221\343\200\220StringToInteger (atoi)\343\200\221.iml" @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git "a/\343\200\220009\343\200\221\343\200\220PalindromeNumber\343\200\221/\343\200\220009\343\200\221\343\200\220PalindromeNumber\343\200\221.iml" "b/\343\200\220009\343\200\221\343\200\220PalindromeNumber\343\200\221/\343\200\220009\343\200\221\343\200\220PalindromeNumber\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220009\343\200\221\343\200\220PalindromeNumber\343\200\221/\343\200\220009\343\200\221\343\200\220PalindromeNumber\343\200\221.iml" +++ "b/\343\200\220009\343\200\221\343\200\220PalindromeNumber\343\200\221/\343\200\220009\343\200\221\343\200\220PalindromeNumber\343\200\221.iml" @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git "a/\343\200\220010\343\200\221\343\200\220RegularExpressionMatching\343\200\221/\343\200\220010\343\200\221\343\200\220RegularExpressionMatching\343\200\221.iml" "b/\343\200\220010\343\200\221\343\200\220RegularExpressionMatching\343\200\221/\343\200\220010\343\200\221\343\200\220RegularExpressionMatching\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220010\343\200\221\343\200\220RegularExpressionMatching\343\200\221/\343\200\220010\343\200\221\343\200\220RegularExpressionMatching\343\200\221.iml" +++ "b/\343\200\220010\343\200\221\343\200\220RegularExpressionMatching\343\200\221/\343\200\220010\343\200\221\343\200\220RegularExpressionMatching\343\200\221.iml" @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git "a/\343\200\220011\343\200\221\343\200\220ContainerWithMost Water\343\200\221/\343\200\220011\343\200\221\343\200\220ContainerWithMost Water\343\200\221.iml" "b/\343\200\220011\343\200\221\343\200\220ContainerWithMost Water\343\200\221/\343\200\220011\343\200\221\343\200\220ContainerWithMost Water\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220011\343\200\221\343\200\220ContainerWithMost Water\343\200\221/\343\200\220011\343\200\221\343\200\220ContainerWithMost Water\343\200\221.iml" +++ "b/\343\200\220011\343\200\221\343\200\220ContainerWithMost Water\343\200\221/\343\200\220011\343\200\221\343\200\220ContainerWithMost Water\343\200\221.iml" @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git "a/\343\200\220012\343\200\221\343\200\220IntegerToRoman\343\200\221/\343\200\220012\343\200\221\343\200\220IntegerToRoman\343\200\221.iml" "b/\343\200\220012\343\200\221\343\200\220IntegerToRoman\343\200\221/\343\200\220012\343\200\221\343\200\220IntegerToRoman\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220012\343\200\221\343\200\220IntegerToRoman\343\200\221/\343\200\220012\343\200\221\343\200\220IntegerToRoman\343\200\221.iml" +++ "b/\343\200\220012\343\200\221\343\200\220IntegerToRoman\343\200\221/\343\200\220012\343\200\221\343\200\220IntegerToRoman\343\200\221.iml" @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git "a/\343\200\220013\343\200\221\343\200\220RomarToInteger\343\200\221/\343\200\220013\343\200\221\343\200\220RomarToInteger\343\200\221.iml" "b/\343\200\220013\343\200\221\343\200\220RomarToInteger\343\200\221/\343\200\220013\343\200\221\343\200\220RomarToInteger\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220013\343\200\221\343\200\220RomarToInteger\343\200\221/\343\200\220013\343\200\221\343\200\220RomarToInteger\343\200\221.iml" +++ "b/\343\200\220013\343\200\221\343\200\220RomarToInteger\343\200\221/\343\200\220013\343\200\221\343\200\220RomarToInteger\343\200\221.iml" @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git "a/\343\200\220014\343\200\221\343\200\220LongestCommonPrefix\343\200\221/\343\200\220014\343\200\221\343\200\220LongestCommonPrefix\343\200\221.iml" "b/\343\200\220014\343\200\221\343\200\220LongestCommonPrefix\343\200\221/\343\200\220014\343\200\221\343\200\220LongestCommonPrefix\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220014\343\200\221\343\200\220LongestCommonPrefix\343\200\221/\343\200\220014\343\200\221\343\200\220LongestCommonPrefix\343\200\221.iml" +++ "b/\343\200\220014\343\200\221\343\200\220LongestCommonPrefix\343\200\221/\343\200\220014\343\200\221\343\200\220LongestCommonPrefix\343\200\221.iml" @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git "a/\343\200\220015\343\200\221\343\200\2203Sum\343\200\221/\343\200\220015\343\200\221\343\200\2203Sum\343\200\221.iml" "b/\343\200\220015\343\200\221\343\200\2203Sum\343\200\221/\343\200\220015\343\200\221\343\200\2203Sum\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220015\343\200\221\343\200\2203Sum\343\200\221/\343\200\220015\343\200\221\343\200\2203Sum\343\200\221.iml" +++ "b/\343\200\220015\343\200\221\343\200\2203Sum\343\200\221/\343\200\220015\343\200\221\343\200\2203Sum\343\200\221.iml" @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git "a/\343\200\220016\343\200\221\343\200\2203SumClosest\343\200\221/\343\200\220016\343\200\221\343\200\2203SumClosest\343\200\221.iml" "b/\343\200\220016\343\200\221\343\200\2203SumClosest\343\200\221/\343\200\220016\343\200\221\343\200\2203SumClosest\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220016\343\200\221\343\200\2203SumClosest\343\200\221/\343\200\220016\343\200\221\343\200\2203SumClosest\343\200\221.iml" +++ "b/\343\200\220016\343\200\221\343\200\2203SumClosest\343\200\221/\343\200\220016\343\200\221\343\200\2203SumClosest\343\200\221.iml" @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git "a/\343\200\220017\343\200\221\343\200\220LetterCombinationsOfAPhonNumber \343\200\221/\343\200\220017\343\200\221\343\200\220LetterCombinationsOfAPhonNumber \343\200\221.iml" "b/\343\200\220017\343\200\221\343\200\220LetterCombinationsOfAPhonNumber \343\200\221/\343\200\220017\343\200\221\343\200\220LetterCombinationsOfAPhonNumber \343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220017\343\200\221\343\200\220LetterCombinationsOfAPhonNumber \343\200\221/\343\200\220017\343\200\221\343\200\220LetterCombinationsOfAPhonNumber \343\200\221.iml" +++ "b/\343\200\220017\343\200\221\343\200\220LetterCombinationsOfAPhonNumber \343\200\221/\343\200\220017\343\200\221\343\200\220LetterCombinationsOfAPhonNumber \343\200\221.iml" @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git "a/\343\200\220018\343\200\221\343\200\2204Sum\343\200\221/\343\200\220018\343\200\221\343\200\2204Sum\343\200\221.iml" "b/\343\200\220018\343\200\221\343\200\2204Sum\343\200\221/\343\200\220018\343\200\221\343\200\2204Sum\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220018\343\200\221\343\200\2204Sum\343\200\221/\343\200\220018\343\200\221\343\200\2204Sum\343\200\221.iml" +++ "b/\343\200\220018\343\200\221\343\200\2204Sum\343\200\221/\343\200\220018\343\200\221\343\200\2204Sum\343\200\221.iml" @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git "a/\343\200\220019\343\200\221\343\200\220RemoveNthNodeFromEndOfList\343\200\221/\343\200\220019\343\200\221\343\200\220RemoveNthNodeFromEndOfList\343\200\221.iml" "b/\343\200\220019\343\200\221\343\200\220RemoveNthNodeFromEndOfList\343\200\221/\343\200\220019\343\200\221\343\200\220RemoveNthNodeFromEndOfList\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220019\343\200\221\343\200\220RemoveNthNodeFromEndOfList\343\200\221/\343\200\220019\343\200\221\343\200\220RemoveNthNodeFromEndOfList\343\200\221.iml" +++ "b/\343\200\220019\343\200\221\343\200\220RemoveNthNodeFromEndOfList\343\200\221/\343\200\220019\343\200\221\343\200\220RemoveNthNodeFromEndOfList\343\200\221.iml" @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git "a/\343\200\220020\343\200\221\343\200\220ValidParentheses\343\200\221/\343\200\220020\343\200\221\343\200\220ValidParentheses\343\200\221.iml" "b/\343\200\220020\343\200\221\343\200\220ValidParentheses\343\200\221/\343\200\220020\343\200\221\343\200\220ValidParentheses\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220020\343\200\221\343\200\220ValidParentheses\343\200\221/\343\200\220020\343\200\221\343\200\220ValidParentheses\343\200\221.iml" +++ "b/\343\200\220020\343\200\221\343\200\220ValidParentheses\343\200\221/\343\200\220020\343\200\221\343\200\220ValidParentheses\343\200\221.iml" @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git "a/\343\200\220021\343\200\221\343\200\220MergeTwoSortedLists\343\200\221/\343\200\220021\343\200\221\343\200\220MergeTwoSortedLists\343\200\221.iml" "b/\343\200\220021\343\200\221\343\200\220MergeTwoSortedLists\343\200\221/\343\200\220021\343\200\221\343\200\220MergeTwoSortedLists\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220021\343\200\221\343\200\220MergeTwoSortedLists\343\200\221/\343\200\220021\343\200\221\343\200\220MergeTwoSortedLists\343\200\221.iml" +++ "b/\343\200\220021\343\200\221\343\200\220MergeTwoSortedLists\343\200\221/\343\200\220021\343\200\221\343\200\220MergeTwoSortedLists\343\200\221.iml" @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git "a/\343\200\220022\343\200\221\343\200\220GenerateParentheses\343\200\221/\343\200\220022\343\200\221\343\200\220GenerateParentheses\343\200\221.iml" "b/\343\200\220022\343\200\221\343\200\220GenerateParentheses\343\200\221/\343\200\220022\343\200\221\343\200\220GenerateParentheses\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220022\343\200\221\343\200\220GenerateParentheses\343\200\221/\343\200\220022\343\200\221\343\200\220GenerateParentheses\343\200\221.iml" +++ "b/\343\200\220022\343\200\221\343\200\220GenerateParentheses\343\200\221/\343\200\220022\343\200\221\343\200\220GenerateParentheses\343\200\221.iml" @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git "a/\343\200\220023\343\200\221\343\200\220MergeKSortedLists\343\200\221/\343\200\220023\343\200\221\343\200\220MergeKSortedLists\343\200\221.iml" "b/\343\200\220023\343\200\221\343\200\220MergeKSortedLists\343\200\221/\343\200\220023\343\200\221\343\200\220MergeKSortedLists\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220023\343\200\221\343\200\220MergeKSortedLists\343\200\221/\343\200\220023\343\200\221\343\200\220MergeKSortedLists\343\200\221.iml" +++ "b/\343\200\220023\343\200\221\343\200\220MergeKSortedLists\343\200\221/\343\200\220023\343\200\221\343\200\220MergeKSortedLists\343\200\221.iml" @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git "a/\343\200\220024\343\200\221\343\200\220SwapNodesInPairs\343\200\221/\343\200\220024\343\200\221\343\200\220SwapNodesInPairs\343\200\221.iml" "b/\343\200\220024\343\200\221\343\200\220SwapNodesInPairs\343\200\221/\343\200\220024\343\200\221\343\200\220SwapNodesInPairs\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220024\343\200\221\343\200\220SwapNodesInPairs\343\200\221/\343\200\220024\343\200\221\343\200\220SwapNodesInPairs\343\200\221.iml" +++ "b/\343\200\220024\343\200\221\343\200\220SwapNodesInPairs\343\200\221/\343\200\220024\343\200\221\343\200\220SwapNodesInPairs\343\200\221.iml" @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git "a/\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221/\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221.iml" "b/\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221/\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221/\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221.iml" +++ "b/\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221/\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221.iml" @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git "a/\343\200\220026\343\200\221\343\200\220RemoveDuplicatesfromSortedArray\343\200\221/src/Solution.java" "b/\343\200\220026\343\200\221\343\200\220RemoveDuplicatesfromSortedArray\343\200\221/src/Solution.java" index d2a1fa2..9131cb0 100644 --- "a/\343\200\220026\343\200\221\343\200\220RemoveDuplicatesfromSortedArray\343\200\221/src/Solution.java" +++ "b/\343\200\220026\343\200\221\343\200\220RemoveDuplicatesfromSortedArray\343\200\221/src/Solution.java" @@ -31,27 +31,24 @@ public class Solution { */ public int removeDuplicates(int[] A) { - if (A.length == 0) { + if (A == null) { return 0; } - int index = 0;//[0,index]ֻ¼гֵİСΨһһѾź - int next = 1; - - // 㷨˼룺index֮ıA[index]ҵƶA[index+1] - // indexƶһλãnextƶһλãұA[index] - - while (next < A.length) { - while (next < A.length && A[index] == A[next]) { // Ҳ - next++; - } + if (A.length < 2) { + return A.length; + } - if (next < A.length) { + // ָһλ + int index = 1; + for (int i = 1; i < A.length; i++) { + // index - 1ʾǰһźõλ + if (A[index - 1] < A[i]) { + A[index] = A[i]; index++; - A[index] = A[next]; - next++; } } - return index + 1; + + return index; } } diff --git "a/\343\200\220026\343\200\221\343\200\220RemoveDuplicatesfromSortedArray\343\200\221/src/Solution2.java" "b/\343\200\220026\343\200\221\343\200\220RemoveDuplicatesfromSortedArray\343\200\221/src/Solution2.java" new file mode 100644 index 0000000..fc801b2 --- /dev/null +++ "b/\343\200\220026\343\200\221\343\200\220RemoveDuplicatesfromSortedArray\343\200\221/src/Solution2.java" @@ -0,0 +1,57 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 16:40 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + /** + *
+     * ԭ
+     * Given a sorted array, remove the duplicates in place such that each element
+     * appear only once and return the new length.
+     * Do not allocate extra space for another array, you must do this in place
+     * with constant memory.
+     * For example,
+     * Given input array nums = [1,1,2],
+     * Your function should return length = 2, with the first two elements of nums
+     * being 1 and 2 respectively. It doesnt matter what you leave beyond the new length.
+     *
+     * Ŀ
+     * һ飬еظԪȥֻͬһҷµԪظ
+     * Ҫһµڳʱڽ
+     *
+     * ˼·
+     * ӵڶԪؿʼΪǰԪأǰԪǰһԪͬɾԪأ
+     * ͬͽƶȷλãԪ˸
+     * 
+ * + * @param A + * @return + */ + public int removeDuplicates(int[] A) { + + if (A.length == 0) { + return 0; + } + + int index = 0;//[0,index]ֻ¼гֵİСΨһһѾź + int next = 1; + + // 㷨˼룺index֮ıA[index]ҵƶA[index+1] + // indexƶһλãnextƶһλãұA[index] + + while (next < A.length) { + while (next < A.length && A[index] == A[next]) { // Ҳ + next++; + } + + if (next < A.length) { + index++; + A[index] = A[next]; + next++; + } + } + return index + 1; + } +} diff --git "a/\343\200\220026\343\200\221\343\200\220RemoveDuplicatesfromSortedArray\343\200\221/\343\200\220026\343\200\221\343\200\220RemoveDuplicatesfromSortedArray\343\200\221.iml" "b/\343\200\220026\343\200\221\343\200\220RemoveDuplicatesfromSortedArray\343\200\221/\343\200\220026\343\200\221\343\200\220RemoveDuplicatesfromSortedArray\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220026\343\200\221\343\200\220RemoveDuplicatesfromSortedArray\343\200\221/\343\200\220026\343\200\221\343\200\220RemoveDuplicatesfromSortedArray\343\200\221.iml" +++ "b/\343\200\220026\343\200\221\343\200\220RemoveDuplicatesfromSortedArray\343\200\221/\343\200\220026\343\200\221\343\200\220RemoveDuplicatesfromSortedArray\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220027\343\200\221\343\200\220RemoveElement\343\200\221/\343\200\220027\343\200\221\343\200\220RemoveElement\343\200\221.iml" "b/\343\200\220027\343\200\221\343\200\220RemoveElement\343\200\221/\343\200\220027\343\200\221\343\200\220RemoveElement\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220027\343\200\221\343\200\220RemoveElement\343\200\221/\343\200\220027\343\200\221\343\200\220RemoveElement\343\200\221.iml" +++ "b/\343\200\220027\343\200\221\343\200\220RemoveElement\343\200\221/\343\200\220027\343\200\221\343\200\220RemoveElement\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220028\343\200\221\343\200\220Implement-strStr()\343\200\221/\343\200\220028\343\200\221\343\200\220Implement-strStr()\343\200\221.iml" "b/\343\200\220028\343\200\221\343\200\220Implement-strStr()\343\200\221/\343\200\220028\343\200\221\343\200\220Implement-strStr()\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220028\343\200\221\343\200\220Implement-strStr()\343\200\221/\343\200\220028\343\200\221\343\200\220Implement-strStr()\343\200\221.iml" +++ "b/\343\200\220028\343\200\221\343\200\220Implement-strStr()\343\200\221/\343\200\220028\343\200\221\343\200\220Implement-strStr()\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220029\343\200\221\343\200\220DivideTwoIntegers\343\200\221/\343\200\220029\343\200\221\343\200\220DivideTwoIntegers\343\200\221.iml" "b/\343\200\220029\343\200\221\343\200\220DivideTwoIntegers\343\200\221/\343\200\220029\343\200\221\343\200\220DivideTwoIntegers\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220029\343\200\221\343\200\220DivideTwoIntegers\343\200\221/\343\200\220029\343\200\221\343\200\220DivideTwoIntegers\343\200\221.iml" +++ "b/\343\200\220029\343\200\221\343\200\220DivideTwoIntegers\343\200\221/\343\200\220029\343\200\221\343\200\220DivideTwoIntegers\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220030\343\200\221\343\200\220SubstringWithConcatenationOfAllWords\343\200\221/\343\200\220030\343\200\221\343\200\220SubstringWithConcatenationOfAllWords\343\200\221.iml" "b/\343\200\220030\343\200\221\343\200\220SubstringWithConcatenationOfAllWords\343\200\221/\343\200\220030\343\200\221\343\200\220SubstringWithConcatenationOfAllWords\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220030\343\200\221\343\200\220SubstringWithConcatenationOfAllWords\343\200\221/\343\200\220030\343\200\221\343\200\220SubstringWithConcatenationOfAllWords\343\200\221.iml" +++ "b/\343\200\220030\343\200\221\343\200\220SubstringWithConcatenationOfAllWords\343\200\221/\343\200\220030\343\200\221\343\200\220SubstringWithConcatenationOfAllWords\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220032\343\200\221\343\200\220LongestValidParentheses\343\200\221/\343\200\220032\343\200\221\343\200\220LongestValidParentheses\343\200\221.iml" "b/\343\200\220032\343\200\221\343\200\220LongestValidParentheses\343\200\221/\343\200\220032\343\200\221\343\200\220LongestValidParentheses\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220032\343\200\221\343\200\220LongestValidParentheses\343\200\221/\343\200\220032\343\200\221\343\200\220LongestValidParentheses\343\200\221.iml" +++ "b/\343\200\220032\343\200\221\343\200\220LongestValidParentheses\343\200\221/\343\200\220032\343\200\221\343\200\220LongestValidParentheses\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221/src/Main.java" "b/\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221/src/Main.java" new file mode 100644 index 0000000..7665c43 --- /dev/null +++ "b/\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221/src/Main.java" @@ -0,0 +1,14 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-12 23:22 + **/ +public class Main { + public static void main(String[] args) { + int[] nums = {4,5,6,7,0,1,2} + ; + Solution2 solution = new Solution2(); + + System.out.println(solution.search(nums, 4)); + System.out.println(solution.search(nums, 3)); + } +} diff --git "a/\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221/src/Solution2.java" "b/\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221/src/Solution2.java" new file mode 100644 index 0000000..59a71a5 --- /dev/null +++ "b/\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221/src/Solution2.java" @@ -0,0 +1,65 @@ +/** + * Author: 王俊超 + * Date: 2015-06-21 + * Time: 14:48 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + /** + *
+     * Suppose a sorted array is rotated at some pivot unknown to you beforehand.
+     * (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).
+     * You are given a target value to search. If found in the array return its
+     * index, otherwise return -1.
+     *
+     * You may assume no duplicate exists in the array.
+     *
+     * 题目大意:
+     * 假设一个排序的数组以一个未知的的枢轴旋转。(即,0 1 2 4 5 6 7可能成为4 5 6 7 0 1 2)。
+     * 给定一个目标值,在数组中搜寻。如果存在就返回其对应的下标,否则返回-1。
+     * 假设数组中不存在重复值。
+     *
+     * 解题思路:
+     * 找旋转数组最小值的位置minIndex(见LeetCode第153题 ),如果minIndex不为,说明其在分隔成
+     * 两个有序数组,并且前一个中的第一个元素都大于后一个数组的每一个元素,判断target中哪一个数组区
+     * 间中使用二叉搜索算法查找,如果minIndex=0,说明全局有序,对整个数组进行二叉查找,返回查找结果
+     * 
+ * + * @param nums + * @param target + * @return + */ + public int search(int[] nums, int target) { + if (nums == null || nums.length == 0) { + return -1; + } + + int left = 0; + int right = nums.length - 1; + int mid; + while (left <= right) { + mid = left + (right - left) / 2; + if (nums[mid] == target) { + return mid; + } + + // 说明first,mid都在同一个递增子序列中 + if (nums[left] <= nums[mid]) { + if (nums[left] <= target && target < nums[mid]) { + right = mid - 1; + } else { + left = mid + 1; + } + } else { + if (nums[mid] < target && target <= nums[right]) { + left = mid + 1; + } else { + right = mid - 1; + } + } + } + + return -1; + } + +} diff --git "a/\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221/\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221.iml" "b/\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221/\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221/\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221.iml" +++ "b/\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221/\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220034\343\200\221\343\200\220SearchForARange\343\200\221/\343\200\220034\343\200\221\343\200\220SearchForARange\343\200\221.iml" "b/\343\200\220034\343\200\221\343\200\220SearchForARange\343\200\221/\343\200\220034\343\200\221\343\200\220SearchForARange\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220034\343\200\221\343\200\220SearchForARange\343\200\221/\343\200\220034\343\200\221\343\200\220SearchForARange\343\200\221.iml" +++ "b/\343\200\220034\343\200\221\343\200\220SearchForARange\343\200\221/\343\200\220034\343\200\221\343\200\220SearchForARange\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220035\343\200\221\343\200\220SearchInsertPosition\343\200\221/\343\200\220035\343\200\221\343\200\220SearchInsertPosition\343\200\221.iml" "b/\343\200\220035\343\200\221\343\200\220SearchInsertPosition\343\200\221/\343\200\220035\343\200\221\343\200\220SearchInsertPosition\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220035\343\200\221\343\200\220SearchInsertPosition\343\200\221/\343\200\220035\343\200\221\343\200\220SearchInsertPosition\343\200\221.iml" +++ "b/\343\200\220035\343\200\221\343\200\220SearchInsertPosition\343\200\221/\343\200\220035\343\200\221\343\200\220SearchInsertPosition\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220036\343\200\221\343\200\220Valid Sudoku\343\200\221/\343\200\220036\343\200\221\343\200\220Valid Sudoku\343\200\221.iml" "b/\343\200\220036\343\200\221\343\200\220Valid Sudoku\343\200\221/\343\200\220036\343\200\221\343\200\220Valid Sudoku\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220036\343\200\221\343\200\220Valid Sudoku\343\200\221/\343\200\220036\343\200\221\343\200\220Valid Sudoku\343\200\221.iml" +++ "b/\343\200\220036\343\200\221\343\200\220Valid Sudoku\343\200\221/\343\200\220036\343\200\221\343\200\220Valid Sudoku\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220037\343\200\221\343\200\220Sudoku Solver\343\200\221/\343\200\220037\343\200\221\343\200\220Sudoku Solver\343\200\221.iml" "b/\343\200\220037\343\200\221\343\200\220Sudoku Solver\343\200\221/\343\200\220037\343\200\221\343\200\220Sudoku Solver\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220037\343\200\221\343\200\220Sudoku Solver\343\200\221/\343\200\220037\343\200\221\343\200\220Sudoku Solver\343\200\221.iml" +++ "b/\343\200\220037\343\200\221\343\200\220Sudoku Solver\343\200\221/\343\200\220037\343\200\221\343\200\220Sudoku Solver\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220038\343\200\221\343\200\220CountAndSay\343\200\221/\343\200\220038\343\200\221\343\200\220CountAndSay\343\200\221.iml" "b/\343\200\220038\343\200\221\343\200\220CountAndSay\343\200\221/\343\200\220038\343\200\221\343\200\220CountAndSay\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220038\343\200\221\343\200\220CountAndSay\343\200\221/\343\200\220038\343\200\221\343\200\220CountAndSay\343\200\221.iml" +++ "b/\343\200\220038\343\200\221\343\200\220CountAndSay\343\200\221/\343\200\220038\343\200\221\343\200\220CountAndSay\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220039\343\200\221\343\200\220Combination Sum\343\200\221/\343\200\220039\343\200\221\343\200\220Combination Sum\343\200\221.iml" "b/\343\200\220039\343\200\221\343\200\220Combination Sum\343\200\221/\343\200\220039\343\200\221\343\200\220Combination Sum\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220039\343\200\221\343\200\220Combination Sum\343\200\221/\343\200\220039\343\200\221\343\200\220Combination Sum\343\200\221.iml" +++ "b/\343\200\220039\343\200\221\343\200\220Combination Sum\343\200\221/\343\200\220039\343\200\221\343\200\220Combination Sum\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220040\343\200\221\343\200\220Combination Sum II\343\200\221/\343\200\220040\343\200\221\343\200\220Combination Sum II\343\200\221.iml" "b/\343\200\220040\343\200\221\343\200\220Combination Sum II\343\200\221/\343\200\220040\343\200\221\343\200\220Combination Sum II\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220040\343\200\221\343\200\220Combination Sum II\343\200\221/\343\200\220040\343\200\221\343\200\220Combination Sum II\343\200\221.iml" +++ "b/\343\200\220040\343\200\221\343\200\220Combination Sum II\343\200\221/\343\200\220040\343\200\221\343\200\220Combination Sum II\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220041\343\200\221\343\200\220First Missing Positive\343\200\221/\343\200\220041\343\200\221\343\200\220First Missing Positive\343\200\221.iml" "b/\343\200\220041\343\200\221\343\200\220First Missing Positive\343\200\221/\343\200\220041\343\200\221\343\200\220First Missing Positive\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220041\343\200\221\343\200\220First Missing Positive\343\200\221/\343\200\220041\343\200\221\343\200\220First Missing Positive\343\200\221.iml" +++ "b/\343\200\220041\343\200\221\343\200\220First Missing Positive\343\200\221/\343\200\220041\343\200\221\343\200\220First Missing Positive\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220042\343\200\221\343\200\220Trapping Rain Water\343\200\221/\343\200\220042\343\200\221\343\200\220Trapping Rain Water\343\200\221.iml" "b/\343\200\220042\343\200\221\343\200\220Trapping Rain Water\343\200\221/\343\200\220042\343\200\221\343\200\220Trapping Rain Water\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220042\343\200\221\343\200\220Trapping Rain Water\343\200\221/\343\200\220042\343\200\221\343\200\220Trapping Rain Water\343\200\221.iml" +++ "b/\343\200\220042\343\200\221\343\200\220Trapping Rain Water\343\200\221/\343\200\220042\343\200\221\343\200\220Trapping Rain Water\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220043\343\200\221\343\200\220Multiply Strings\343\200\221/\343\200\220043\343\200\221\343\200\220Multiply Strings\343\200\221.iml" "b/\343\200\220043\343\200\221\343\200\220Multiply Strings\343\200\221/\343\200\220043\343\200\221\343\200\220Multiply Strings\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220043\343\200\221\343\200\220Multiply Strings\343\200\221/\343\200\220043\343\200\221\343\200\220Multiply Strings\343\200\221.iml" +++ "b/\343\200\220043\343\200\221\343\200\220Multiply Strings\343\200\221/\343\200\220043\343\200\221\343\200\220Multiply Strings\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220044\343\200\221\343\200\220Wildcard Matching\343\200\221/\343\200\220044\343\200\221\343\200\220Wildcard Matching\343\200\221.iml" "b/\343\200\220044\343\200\221\343\200\220Wildcard Matching\343\200\221/\343\200\220044\343\200\221\343\200\220Wildcard Matching\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220044\343\200\221\343\200\220Wildcard Matching\343\200\221/\343\200\220044\343\200\221\343\200\220Wildcard Matching\343\200\221.iml" +++ "b/\343\200\220044\343\200\221\343\200\220Wildcard Matching\343\200\221/\343\200\220044\343\200\221\343\200\220Wildcard Matching\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220045\343\200\221\343\200\220Jump Game II\343\200\221/\343\200\220045\343\200\221\343\200\220Jump Game II\343\200\221.iml" "b/\343\200\220045\343\200\221\343\200\220Jump Game II\343\200\221/\343\200\220045\343\200\221\343\200\220Jump Game II\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220045\343\200\221\343\200\220Jump Game II\343\200\221/\343\200\220045\343\200\221\343\200\220Jump Game II\343\200\221.iml" +++ "b/\343\200\220045\343\200\221\343\200\220Jump Game II\343\200\221/\343\200\220045\343\200\221\343\200\220Jump Game II\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220046\343\200\221\343\200\220Permutations\343\200\221/\343\200\220046\343\200\221\343\200\220Permutations\343\200\221.iml" "b/\343\200\220046\343\200\221\343\200\220Permutations\343\200\221/\343\200\220046\343\200\221\343\200\220Permutations\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220046\343\200\221\343\200\220Permutations\343\200\221/\343\200\220046\343\200\221\343\200\220Permutations\343\200\221.iml" +++ "b/\343\200\220046\343\200\221\343\200\220Permutations\343\200\221/\343\200\220046\343\200\221\343\200\220Permutations\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220047\343\200\221\343\200\220Permutations II\343\200\221/\343\200\220047\343\200\221\343\200\220Permutations II\343\200\221.iml" "b/\343\200\220047\343\200\221\343\200\220Permutations II\343\200\221/\343\200\220047\343\200\221\343\200\220Permutations II\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220047\343\200\221\343\200\220Permutations II\343\200\221/\343\200\220047\343\200\221\343\200\220Permutations II\343\200\221.iml" +++ "b/\343\200\220047\343\200\221\343\200\220Permutations II\343\200\221/\343\200\220047\343\200\221\343\200\220Permutations II\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220048\343\200\221\343\200\220Rotate Image\343\200\221/\343\200\220048\343\200\221\343\200\220Rotate Image\343\200\221.iml" "b/\343\200\220048\343\200\221\343\200\220Rotate Image\343\200\221/\343\200\220048\343\200\221\343\200\220Rotate Image\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220048\343\200\221\343\200\220Rotate Image\343\200\221/\343\200\220048\343\200\221\343\200\220Rotate Image\343\200\221.iml" +++ "b/\343\200\220048\343\200\221\343\200\220Rotate Image\343\200\221/\343\200\220048\343\200\221\343\200\220Rotate Image\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220049\343\200\221\343\200\220Group Anagrams\343\200\221/\343\200\220049\343\200\221\343\200\220Group Anagrams\343\200\221.iml" "b/\343\200\220049\343\200\221\343\200\220Group Anagrams\343\200\221/\343\200\220049\343\200\221\343\200\220Group Anagrams\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220049\343\200\221\343\200\220Group Anagrams\343\200\221/\343\200\220049\343\200\221\343\200\220Group Anagrams\343\200\221.iml" +++ "b/\343\200\220049\343\200\221\343\200\220Group Anagrams\343\200\221/\343\200\220049\343\200\221\343\200\220Group Anagrams\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220050\343\200\221\343\200\220Pow(x,n)\343\200\221/\343\200\220050\343\200\221\343\200\220Pow(x,n)\343\200\221.iml" "b/\343\200\220050\343\200\221\343\200\220Pow(x,n)\343\200\221/\343\200\220050\343\200\221\343\200\220Pow(x,n)\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220050\343\200\221\343\200\220Pow(x,n)\343\200\221/\343\200\220050\343\200\221\343\200\220Pow(x,n)\343\200\221.iml" +++ "b/\343\200\220050\343\200\221\343\200\220Pow(x,n)\343\200\221/\343\200\220050\343\200\221\343\200\220Pow(x,n)\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220051\343\200\221\343\200\220N-Queens\343\200\221/\343\200\220051\343\200\221\343\200\220N-Queens\343\200\221.iml" "b/\343\200\220051\343\200\221\343\200\220N-Queens\343\200\221/\343\200\220051\343\200\221\343\200\220N-Queens\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220051\343\200\221\343\200\220N-Queens\343\200\221/\343\200\220051\343\200\221\343\200\220N-Queens\343\200\221.iml" +++ "b/\343\200\220051\343\200\221\343\200\220N-Queens\343\200\221/\343\200\220051\343\200\221\343\200\220N-Queens\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220052\343\200\221\343\200\220N-Queens II\343\200\221/\343\200\220052\343\200\221\343\200\220N-Queens II\343\200\221.iml" "b/\343\200\220052\343\200\221\343\200\220N-Queens II\343\200\221/\343\200\220052\343\200\221\343\200\220N-Queens II\343\200\221.iml" index 47071ea..788d4d1 100644 --- "a/\343\200\220052\343\200\221\343\200\220N-Queens II\343\200\221/\343\200\220052\343\200\221\343\200\220N-Queens II\343\200\221.iml" +++ "b/\343\200\220052\343\200\221\343\200\220N-Queens II\343\200\221/\343\200\220052\343\200\221\343\200\220N-Queens II\343\200\221.iml" @@ -8,5 +8,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220053\343\200\221\343\200\220MaximumSubarray\343\200\221/\343\200\220053\343\200\221\343\200\220MaximumSubarray\343\200\221.iml" "b/\343\200\220053\343\200\221\343\200\220MaximumSubarray\343\200\221/\343\200\220053\343\200\221\343\200\220MaximumSubarray\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220053\343\200\221\343\200\220MaximumSubarray\343\200\221/\343\200\220053\343\200\221\343\200\220MaximumSubarray\343\200\221.iml" +++ "b/\343\200\220053\343\200\221\343\200\220MaximumSubarray\343\200\221/\343\200\220053\343\200\221\343\200\220MaximumSubarray\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220054\343\200\221\343\200\220SpiralMatrix\343\200\221/\343\200\220054\343\200\221\343\200\220SpiralMatrix\343\200\221.iml" "b/\343\200\220054\343\200\221\343\200\220SpiralMatrix\343\200\221/\343\200\220054\343\200\221\343\200\220SpiralMatrix\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220054\343\200\221\343\200\220SpiralMatrix\343\200\221/\343\200\220054\343\200\221\343\200\220SpiralMatrix\343\200\221.iml" +++ "b/\343\200\220054\343\200\221\343\200\220SpiralMatrix\343\200\221/\343\200\220054\343\200\221\343\200\220SpiralMatrix\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220055\343\200\221\343\200\220Jump Game\343\200\221/\343\200\220055\343\200\221\343\200\220Jump Game\343\200\221.iml" "b/\343\200\220055\343\200\221\343\200\220Jump Game\343\200\221/\343\200\220055\343\200\221\343\200\220Jump Game\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220055\343\200\221\343\200\220Jump Game\343\200\221/\343\200\220055\343\200\221\343\200\220Jump Game\343\200\221.iml" +++ "b/\343\200\220055\343\200\221\343\200\220Jump Game\343\200\221/\343\200\220055\343\200\221\343\200\220Jump Game\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220056\343\200\221\343\200\220MergeIntervals\343\200\221/\343\200\220056\343\200\221\343\200\220MergeIntervals\343\200\221.iml" "b/\343\200\220056\343\200\221\343\200\220MergeIntervals\343\200\221/\343\200\220056\343\200\221\343\200\220MergeIntervals\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220056\343\200\221\343\200\220MergeIntervals\343\200\221/\343\200\220056\343\200\221\343\200\220MergeIntervals\343\200\221.iml" +++ "b/\343\200\220056\343\200\221\343\200\220MergeIntervals\343\200\221/\343\200\220056\343\200\221\343\200\220MergeIntervals\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220057\343\200\221\343\200\220InsertInterval\343\200\221/\343\200\220057\343\200\221\343\200\220InsertInterval\343\200\221.iml" "b/\343\200\220057\343\200\221\343\200\220InsertInterval\343\200\221/\343\200\220057\343\200\221\343\200\220InsertInterval\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220057\343\200\221\343\200\220InsertInterval\343\200\221/\343\200\220057\343\200\221\343\200\220InsertInterval\343\200\221.iml" +++ "b/\343\200\220057\343\200\221\343\200\220InsertInterval\343\200\221/\343\200\220057\343\200\221\343\200\220InsertInterval\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220058\343\200\221\343\200\220LengthOfLastWord\343\200\221/\343\200\220058\343\200\221\343\200\220LengthOfLastWord\343\200\221.iml" "b/\343\200\220058\343\200\221\343\200\220LengthOfLastWord\343\200\221/\343\200\220058\343\200\221\343\200\220LengthOfLastWord\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220058\343\200\221\343\200\220LengthOfLastWord\343\200\221/\343\200\220058\343\200\221\343\200\220LengthOfLastWord\343\200\221.iml" +++ "b/\343\200\220058\343\200\221\343\200\220LengthOfLastWord\343\200\221/\343\200\220058\343\200\221\343\200\220LengthOfLastWord\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220059\343\200\221\343\200\220SpiralMatrixII\343\200\221/\343\200\220059\343\200\221\343\200\220SpiralMatrixII\343\200\221.iml" "b/\343\200\220059\343\200\221\343\200\220SpiralMatrixII\343\200\221/\343\200\220059\343\200\221\343\200\220SpiralMatrixII\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220059\343\200\221\343\200\220SpiralMatrixII\343\200\221/\343\200\220059\343\200\221\343\200\220SpiralMatrixII\343\200\221.iml" +++ "b/\343\200\220059\343\200\221\343\200\220SpiralMatrixII\343\200\221/\343\200\220059\343\200\221\343\200\220SpiralMatrixII\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220060\343\200\221\343\200\220Permutation Sequence\343\200\221/\343\200\220060\343\200\221\343\200\220Permutation Sequence\343\200\221.iml" "b/\343\200\220060\343\200\221\343\200\220Permutation Sequence\343\200\221/\343\200\220060\343\200\221\343\200\220Permutation Sequence\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220060\343\200\221\343\200\220Permutation Sequence\343\200\221/\343\200\220060\343\200\221\343\200\220Permutation Sequence\343\200\221.iml" +++ "b/\343\200\220060\343\200\221\343\200\220Permutation Sequence\343\200\221/\343\200\220060\343\200\221\343\200\220Permutation Sequence\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220061\343\200\221\343\200\220RotateList\343\200\221/\343\200\220061\343\200\221\343\200\220RotateList\343\200\221.iml" "b/\343\200\220061\343\200\221\343\200\220RotateList\343\200\221/\343\200\220061\343\200\221\343\200\220RotateList\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220061\343\200\221\343\200\220RotateList\343\200\221/\343\200\220061\343\200\221\343\200\220RotateList\343\200\221.iml" +++ "b/\343\200\220061\343\200\221\343\200\220RotateList\343\200\221/\343\200\220061\343\200\221\343\200\220RotateList\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220062\343\200\221\343\200\220UniquePaths\343\200\221/\343\200\220062\343\200\221\343\200\220UniquePaths\343\200\221.iml" "b/\343\200\220062\343\200\221\343\200\220UniquePaths\343\200\221/\343\200\220062\343\200\221\343\200\220UniquePaths\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220062\343\200\221\343\200\220UniquePaths\343\200\221/\343\200\220062\343\200\221\343\200\220UniquePaths\343\200\221.iml" +++ "b/\343\200\220062\343\200\221\343\200\220UniquePaths\343\200\221/\343\200\220062\343\200\221\343\200\220UniquePaths\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220063\343\200\221\343\200\220UniquePathsII\343\200\221/\343\200\220063\343\200\221\343\200\220UniquePathsII\343\200\221.iml" "b/\343\200\220063\343\200\221\343\200\220UniquePathsII\343\200\221/\343\200\220063\343\200\221\343\200\220UniquePathsII\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220063\343\200\221\343\200\220UniquePathsII\343\200\221/\343\200\220063\343\200\221\343\200\220UniquePathsII\343\200\221.iml" +++ "b/\343\200\220063\343\200\221\343\200\220UniquePathsII\343\200\221/\343\200\220063\343\200\221\343\200\220UniquePathsII\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220064\343\200\221\343\200\220MinimumPathSum\343\200\221/\343\200\220064\343\200\221\343\200\220MinimumPathSum\343\200\221.iml" "b/\343\200\220064\343\200\221\343\200\220MinimumPathSum\343\200\221/\343\200\220064\343\200\221\343\200\220MinimumPathSum\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220064\343\200\221\343\200\220MinimumPathSum\343\200\221/\343\200\220064\343\200\221\343\200\220MinimumPathSum\343\200\221.iml" +++ "b/\343\200\220064\343\200\221\343\200\220MinimumPathSum\343\200\221/\343\200\220064\343\200\221\343\200\220MinimumPathSum\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220066\343\200\221\343\200\220PlusOne\343\200\221/\343\200\220066\343\200\221\343\200\220PlusOne\343\200\221.iml" "b/\343\200\220066\343\200\221\343\200\220PlusOne\343\200\221/\343\200\220066\343\200\221\343\200\220PlusOne\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220066\343\200\221\343\200\220PlusOne\343\200\221/\343\200\220066\343\200\221\343\200\220PlusOne\343\200\221.iml" +++ "b/\343\200\220066\343\200\221\343\200\220PlusOne\343\200\221/\343\200\220066\343\200\221\343\200\220PlusOne\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220067\343\200\221\343\200\220AddBinary\343\200\221/\343\200\220067\343\200\221\343\200\220AddBinary\343\200\221.iml" "b/\343\200\220067\343\200\221\343\200\220AddBinary\343\200\221/\343\200\220067\343\200\221\343\200\220AddBinary\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220067\343\200\221\343\200\220AddBinary\343\200\221/\343\200\220067\343\200\221\343\200\220AddBinary\343\200\221.iml" +++ "b/\343\200\220067\343\200\221\343\200\220AddBinary\343\200\221/\343\200\220067\343\200\221\343\200\220AddBinary\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220070\343\200\221\343\200\220ClimbingStairs\343\200\221/\343\200\220070\343\200\221\343\200\220ClimbingStairs\343\200\221.iml" "b/\343\200\220070\343\200\221\343\200\220ClimbingStairs\343\200\221/\343\200\220070\343\200\221\343\200\220ClimbingStairs\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220070\343\200\221\343\200\220ClimbingStairs\343\200\221/\343\200\220070\343\200\221\343\200\220ClimbingStairs\343\200\221.iml" +++ "b/\343\200\220070\343\200\221\343\200\220ClimbingStairs\343\200\221/\343\200\220070\343\200\221\343\200\220ClimbingStairs\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220071\343\200\221\343\200\220Simplify Path\343\200\221/\343\200\220071\343\200\221\343\200\220Simplify Path\343\200\221.iml" "b/\343\200\220071\343\200\221\343\200\220Simplify Path\343\200\221/\343\200\220071\343\200\221\343\200\220Simplify Path\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220071\343\200\221\343\200\220Simplify Path\343\200\221/\343\200\220071\343\200\221\343\200\220Simplify Path\343\200\221.iml" +++ "b/\343\200\220071\343\200\221\343\200\220Simplify Path\343\200\221/\343\200\220071\343\200\221\343\200\220Simplify Path\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220073\343\200\221\343\200\220SetMatrixZeroes\343\200\221/\343\200\220073\343\200\221\343\200\220SetMatrixZeroes\343\200\221.iml" "b/\343\200\220073\343\200\221\343\200\220SetMatrixZeroes\343\200\221/\343\200\220073\343\200\221\343\200\220SetMatrixZeroes\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220073\343\200\221\343\200\220SetMatrixZeroes\343\200\221/\343\200\220073\343\200\221\343\200\220SetMatrixZeroes\343\200\221.iml" +++ "b/\343\200\220073\343\200\221\343\200\220SetMatrixZeroes\343\200\221/\343\200\220073\343\200\221\343\200\220SetMatrixZeroes\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220074\343\200\221\343\200\220SearchA2DMatrix\343\200\221/\343\200\220074\343\200\221\343\200\220SearchA2DMatrix\343\200\221.iml" "b/\343\200\220074\343\200\221\343\200\220SearchA2DMatrix\343\200\221/\343\200\220074\343\200\221\343\200\220SearchA2DMatrix\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220074\343\200\221\343\200\220SearchA2DMatrix\343\200\221/\343\200\220074\343\200\221\343\200\220SearchA2DMatrix\343\200\221.iml" +++ "b/\343\200\220074\343\200\221\343\200\220SearchA2DMatrix\343\200\221/\343\200\220074\343\200\221\343\200\220SearchA2DMatrix\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220075\343\200\221\343\200\220SortColors\343\200\221/\343\200\220075\343\200\221\343\200\220SortColors\343\200\221.iml" "b/\343\200\220075\343\200\221\343\200\220SortColors\343\200\221/\343\200\220075\343\200\221\343\200\220SortColors\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220075\343\200\221\343\200\220SortColors\343\200\221/\343\200\220075\343\200\221\343\200\220SortColors\343\200\221.iml" +++ "b/\343\200\220075\343\200\221\343\200\220SortColors\343\200\221/\343\200\220075\343\200\221\343\200\220SortColors\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220077\343\200\221\343\200\220Combinations\343\200\221/\343\200\220077\343\200\221\343\200\220Combinations\343\200\221.iml" "b/\343\200\220077\343\200\221\343\200\220Combinations\343\200\221/\343\200\220077\343\200\221\343\200\220Combinations\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220077\343\200\221\343\200\220Combinations\343\200\221/\343\200\220077\343\200\221\343\200\220Combinations\343\200\221.iml" +++ "b/\343\200\220077\343\200\221\343\200\220Combinations\343\200\221/\343\200\220077\343\200\221\343\200\220Combinations\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220078\343\200\221\343\200\220Subsets\343\200\221/\343\200\220078\343\200\221\343\200\220Subsets\343\200\221.iml" "b/\343\200\220078\343\200\221\343\200\220Subsets\343\200\221/\343\200\220078\343\200\221\343\200\220Subsets\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220078\343\200\221\343\200\220Subsets\343\200\221/\343\200\220078\343\200\221\343\200\220Subsets\343\200\221.iml" +++ "b/\343\200\220078\343\200\221\343\200\220Subsets\343\200\221/\343\200\220078\343\200\221\343\200\220Subsets\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220079\343\200\221\343\200\220WordSearch\343\200\221/\343\200\220079\343\200\221\343\200\220WordSearch\343\200\221.iml" "b/\343\200\220079\343\200\221\343\200\220WordSearch\343\200\221/\343\200\220079\343\200\221\343\200\220WordSearch\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220079\343\200\221\343\200\220WordSearch\343\200\221/\343\200\220079\343\200\221\343\200\220WordSearch\343\200\221.iml" +++ "b/\343\200\220079\343\200\221\343\200\220WordSearch\343\200\221/\343\200\220079\343\200\221\343\200\220WordSearch\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220080\343\200\221\343\200\220Remove Duplicates from Sorted Array II\343\200\221/src/Main.java" "b/\343\200\220080\343\200\221\343\200\220Remove Duplicates from Sorted Array II\343\200\221/src/Main.java" new file mode 100644 index 0000000..83f9e74 --- /dev/null +++ "b/\343\200\220080\343\200\221\343\200\220Remove Duplicates from Sorted Array II\343\200\221/src/Main.java" @@ -0,0 +1,15 @@ +import java.util.Arrays; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-12 22:29 + **/ +public class Main { + public static void main(String[] args) { + Solution solution = new Solution(); + int[] nums = {1, 1, 1, 2, 2, 3}; + int i = solution.removeDuplicates(nums); + System.out.println(i + ": "+ Arrays.toString(nums)); + + } +} diff --git "a/\343\200\220080\343\200\221\343\200\220Remove Duplicates from Sorted Array II\343\200\221/src/Solution.java" "b/\343\200\220080\343\200\221\343\200\220Remove Duplicates from Sorted Array II\343\200\221/src/Solution.java" new file mode 100644 index 0000000..9109816 --- /dev/null +++ "b/\343\200\220080\343\200\221\343\200\220Remove Duplicates from Sorted Array II\343\200\221/src/Solution.java" @@ -0,0 +1,24 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-12 22:29 + **/ +public class Solution { + public int removeDuplicates(int[] nums) { + if (nums == null) { + return 0; + } + if (nums.length < 3) { + return nums.length; + } + + int index = 2; + for (int i = 2; i < nums.length; i++) { + if (nums[index - 2] < nums[i] ) { + nums[index] = nums[i]; + index++; + } + } + + return index; + } +} diff --git "a/\343\200\220080\343\200\221\343\200\220Remove Duplicates from Sorted Array II\343\200\221/src/Solution2.java" "b/\343\200\220080\343\200\221\343\200\220Remove Duplicates from Sorted Array II\343\200\221/src/Solution2.java" new file mode 100644 index 0000000..c3e4f83 --- /dev/null +++ "b/\343\200\220080\343\200\221\343\200\220Remove Duplicates from Sorted Array II\343\200\221/src/Solution2.java" @@ -0,0 +1,24 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-12 22:53 + **/ +/** + * 删除重复出现的数字,使之最多出现两次 + */ +public class Solution2 { + public int removeDuplicates(int[] nums) { + int i = 0; + + // 处理每一个数字 + for (int n : nums) { + // i < 2 处理前两个数字 + // n > nums[i - 2]说明n不与nums[i - 2]重复,并且因为数组有序,那么必然n > nums[i - 2] + if (i < 2 || n > nums[i - 2]) { + nums[i++] = n; + } + } + + return i; + } +} + diff --git "a/\343\200\220081\343\200\221\343\200\220SearchInRotatedSortedArraII\343\200\221/\343\200\220081\343\200\221\343\200\220SearchInRotatedSortedArraII\343\200\221.iml" "b/\343\200\220081\343\200\221\343\200\220SearchInRotatedSortedArraII\343\200\221/\343\200\220081\343\200\221\343\200\220SearchInRotatedSortedArraII\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220081\343\200\221\343\200\220SearchInRotatedSortedArraII\343\200\221/\343\200\220081\343\200\221\343\200\220SearchInRotatedSortedArraII\343\200\221.iml" +++ "b/\343\200\220081\343\200\221\343\200\220SearchInRotatedSortedArraII\343\200\221/\343\200\220081\343\200\221\343\200\220SearchInRotatedSortedArraII\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220082\343\200\221\343\200\220RemoveDuplicatesFromSortedListII\343\200\221/\343\200\220082\343\200\221\343\200\220RemoveDuplicatesFromSortedListII\343\200\221.iml" "b/\343\200\220082\343\200\221\343\200\220RemoveDuplicatesFromSortedListII\343\200\221/\343\200\220082\343\200\221\343\200\220RemoveDuplicatesFromSortedListII\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220082\343\200\221\343\200\220RemoveDuplicatesFromSortedListII\343\200\221/\343\200\220082\343\200\221\343\200\220RemoveDuplicatesFromSortedListII\343\200\221.iml" +++ "b/\343\200\220082\343\200\221\343\200\220RemoveDuplicatesFromSortedListII\343\200\221/\343\200\220082\343\200\221\343\200\220RemoveDuplicatesFromSortedListII\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220083\343\200\221\343\200\220RemoveDuplicatesFromSortedList\343\200\221/\343\200\220083\343\200\221\343\200\220RemoveDuplicatesFromSortedList\343\200\221.iml" "b/\343\200\220083\343\200\221\343\200\220RemoveDuplicatesFromSortedList\343\200\221/\343\200\220083\343\200\221\343\200\220RemoveDuplicatesFromSortedList\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220083\343\200\221\343\200\220RemoveDuplicatesFromSortedList\343\200\221/\343\200\220083\343\200\221\343\200\220RemoveDuplicatesFromSortedList\343\200\221.iml" +++ "b/\343\200\220083\343\200\221\343\200\220RemoveDuplicatesFromSortedList\343\200\221/\343\200\220083\343\200\221\343\200\220RemoveDuplicatesFromSortedList\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220086\343\200\221\343\200\220PartitionList\343\200\221/\343\200\220086\343\200\221\343\200\220PartitionList\343\200\221.iml" "b/\343\200\220086\343\200\221\343\200\220PartitionList\343\200\221/\343\200\220086\343\200\221\343\200\220PartitionList\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220086\343\200\221\343\200\220PartitionList\343\200\221/\343\200\220086\343\200\221\343\200\220PartitionList\343\200\221.iml" +++ "b/\343\200\220086\343\200\221\343\200\220PartitionList\343\200\221/\343\200\220086\343\200\221\343\200\220PartitionList\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220088\343\200\221\343\200\220MergeSortedArray\343\200\221/\343\200\220088\343\200\221\343\200\220MergeSortedArray\343\200\221.iml" "b/\343\200\220088\343\200\221\343\200\220MergeSortedArray\343\200\221/\343\200\220088\343\200\221\343\200\220MergeSortedArray\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220088\343\200\221\343\200\220MergeSortedArray\343\200\221/\343\200\220088\343\200\221\343\200\220MergeSortedArray\343\200\221.iml" +++ "b/\343\200\220088\343\200\221\343\200\220MergeSortedArray\343\200\221/\343\200\220088\343\200\221\343\200\220MergeSortedArray\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220089\343\200\221\343\200\220GrayCode\343\200\221/\343\200\220089\343\200\221\343\200\220GrayCode\343\200\221.iml" "b/\343\200\220089\343\200\221\343\200\220GrayCode\343\200\221/\343\200\220089\343\200\221\343\200\220GrayCode\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220089\343\200\221\343\200\220GrayCode\343\200\221/\343\200\220089\343\200\221\343\200\220GrayCode\343\200\221.iml" +++ "b/\343\200\220089\343\200\221\343\200\220GrayCode\343\200\221/\343\200\220089\343\200\221\343\200\220GrayCode\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220092\343\200\221\343\200\220ReverseLinkedListII\343\200\221/\343\200\220092\343\200\221\343\200\220ReverseLinkedListII\343\200\221.iml" "b/\343\200\220092\343\200\221\343\200\220ReverseLinkedListII\343\200\221/\343\200\220092\343\200\221\343\200\220ReverseLinkedListII\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220092\343\200\221\343\200\220ReverseLinkedListII\343\200\221/\343\200\220092\343\200\221\343\200\220ReverseLinkedListII\343\200\221.iml" +++ "b/\343\200\220092\343\200\221\343\200\220ReverseLinkedListII\343\200\221/\343\200\220092\343\200\221\343\200\220ReverseLinkedListII\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221/\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221.iml" "b/\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221/\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221/\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221.iml" +++ "b/\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221/\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220096\343\200\221\343\200\220UniqueBinarySearchTrees\343\200\221/\343\200\220096\343\200\221\343\200\220UniqueBinarySearchTrees\343\200\221.iml" "b/\343\200\220096\343\200\221\343\200\220UniqueBinarySearchTrees\343\200\221/\343\200\220096\343\200\221\343\200\220UniqueBinarySearchTrees\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220096\343\200\221\343\200\220UniqueBinarySearchTrees\343\200\221/\343\200\220096\343\200\221\343\200\220UniqueBinarySearchTrees\343\200\221.iml" +++ "b/\343\200\220096\343\200\221\343\200\220UniqueBinarySearchTrees\343\200\221/\343\200\220096\343\200\221\343\200\220UniqueBinarySearchTrees\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220098\343\200\221\343\200\220ValidateBinarySearchTree\343\200\221/\343\200\220098\343\200\221\343\200\220ValidateBinarySearchTree\343\200\221.iml" "b/\343\200\220098\343\200\221\343\200\220ValidateBinarySearchTree\343\200\221/\343\200\220098\343\200\221\343\200\220ValidateBinarySearchTree\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220098\343\200\221\343\200\220ValidateBinarySearchTree\343\200\221/\343\200\220098\343\200\221\343\200\220ValidateBinarySearchTree\343\200\221.iml" +++ "b/\343\200\220098\343\200\221\343\200\220ValidateBinarySearchTree\343\200\221/\343\200\220098\343\200\221\343\200\220ValidateBinarySearchTree\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220100\343\200\221\343\200\220SameTree\343\200\221/\343\200\220100\343\200\221\343\200\220SameTree\343\200\221.iml" "b/\343\200\220100\343\200\221\343\200\220SameTree\343\200\221/\343\200\220100\343\200\221\343\200\220SameTree\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220100\343\200\221\343\200\220SameTree\343\200\221/\343\200\220100\343\200\221\343\200\220SameTree\343\200\221.iml" +++ "b/\343\200\220100\343\200\221\343\200\220SameTree\343\200\221/\343\200\220100\343\200\221\343\200\220SameTree\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220101\343\200\221\343\200\220SymmetricTree\343\200\221/\343\200\220101\343\200\221\343\200\220SymmetricTree\343\200\221.iml" "b/\343\200\220101\343\200\221\343\200\220SymmetricTree\343\200\221/\343\200\220101\343\200\221\343\200\220SymmetricTree\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220101\343\200\221\343\200\220SymmetricTree\343\200\221/\343\200\220101\343\200\221\343\200\220SymmetricTree\343\200\221.iml" +++ "b/\343\200\220101\343\200\221\343\200\220SymmetricTree\343\200\221/\343\200\220101\343\200\221\343\200\220SymmetricTree\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220102\343\200\221\343\200\220BinaryTreeLevelOrderTraversal\343\200\221/\343\200\220102\343\200\221\343\200\220BinaryTreeLevelOrderTraversal\343\200\221.iml" "b/\343\200\220102\343\200\221\343\200\220BinaryTreeLevelOrderTraversal\343\200\221/\343\200\220102\343\200\221\343\200\220BinaryTreeLevelOrderTraversal\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220102\343\200\221\343\200\220BinaryTreeLevelOrderTraversal\343\200\221/\343\200\220102\343\200\221\343\200\220BinaryTreeLevelOrderTraversal\343\200\221.iml" +++ "b/\343\200\220102\343\200\221\343\200\220BinaryTreeLevelOrderTraversal\343\200\221/\343\200\220102\343\200\221\343\200\220BinaryTreeLevelOrderTraversal\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221/\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221.iml" "b/\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221/\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221/\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221.iml" +++ "b/\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221/\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220104\343\200\221\343\200\220MaximumDepthOfBinaryTree\343\200\221/\343\200\220104\343\200\221\343\200\220MaximumDepthOfBinaryTree\343\200\221.iml" "b/\343\200\220104\343\200\221\343\200\220MaximumDepthOfBinaryTree\343\200\221/\343\200\220104\343\200\221\343\200\220MaximumDepthOfBinaryTree\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220104\343\200\221\343\200\220MaximumDepthOfBinaryTree\343\200\221/\343\200\220104\343\200\221\343\200\220MaximumDepthOfBinaryTree\343\200\221.iml" +++ "b/\343\200\220104\343\200\221\343\200\220MaximumDepthOfBinaryTree\343\200\221/\343\200\220104\343\200\221\343\200\220MaximumDepthOfBinaryTree\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220105\343\200\221\343\200\220ConstructBinaryTreeFromPreorderAndInorderTraversal\343\200\221/\343\200\220105\343\200\221\343\200\220ConstructBinaryTreeFromPreorderAndInorderTraversal\343\200\221.iml" "b/\343\200\220105\343\200\221\343\200\220ConstructBinaryTreeFromPreorderAndInorderTraversal\343\200\221/\343\200\220105\343\200\221\343\200\220ConstructBinaryTreeFromPreorderAndInorderTraversal\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220105\343\200\221\343\200\220ConstructBinaryTreeFromPreorderAndInorderTraversal\343\200\221/\343\200\220105\343\200\221\343\200\220ConstructBinaryTreeFromPreorderAndInorderTraversal\343\200\221.iml" +++ "b/\343\200\220105\343\200\221\343\200\220ConstructBinaryTreeFromPreorderAndInorderTraversal\343\200\221/\343\200\220105\343\200\221\343\200\220ConstructBinaryTreeFromPreorderAndInorderTraversal\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220106\343\200\221\343\200\220ConstructBinaryTreeFromInorderAndPostorderTraversal\343\200\221/\343\200\220106\343\200\221\343\200\220ConstructBinaryTreeFromInorderAndPostorderTraversal\343\200\221.iml" "b/\343\200\220106\343\200\221\343\200\220ConstructBinaryTreeFromInorderAndPostorderTraversal\343\200\221/\343\200\220106\343\200\221\343\200\220ConstructBinaryTreeFromInorderAndPostorderTraversal\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220106\343\200\221\343\200\220ConstructBinaryTreeFromInorderAndPostorderTraversal\343\200\221/\343\200\220106\343\200\221\343\200\220ConstructBinaryTreeFromInorderAndPostorderTraversal\343\200\221.iml" +++ "b/\343\200\220106\343\200\221\343\200\220ConstructBinaryTreeFromInorderAndPostorderTraversal\343\200\221/\343\200\220106\343\200\221\343\200\220ConstructBinaryTreeFromInorderAndPostorderTraversal\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220107\343\200\221\343\200\220BinaryTreeLevelOrderTraversalII\343\200\221/\343\200\220107\343\200\221\343\200\220BinaryTreeLevelOrderTraversalII\343\200\221.iml" "b/\343\200\220107\343\200\221\343\200\220BinaryTreeLevelOrderTraversalII\343\200\221/\343\200\220107\343\200\221\343\200\220BinaryTreeLevelOrderTraversalII\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220107\343\200\221\343\200\220BinaryTreeLevelOrderTraversalII\343\200\221/\343\200\220107\343\200\221\343\200\220BinaryTreeLevelOrderTraversalII\343\200\221.iml" +++ "b/\343\200\220107\343\200\221\343\200\220BinaryTreeLevelOrderTraversalII\343\200\221/\343\200\220107\343\200\221\343\200\220BinaryTreeLevelOrderTraversalII\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220108\343\200\221\343\200\220ConvertSortedArrayToBinarySearchTree\343\200\221/\343\200\220108\343\200\221\343\200\220ConvertSortedArrayToBinarySearchTree\343\200\221.iml" "b/\343\200\220108\343\200\221\343\200\220ConvertSortedArrayToBinarySearchTree\343\200\221/\343\200\220108\343\200\221\343\200\220ConvertSortedArrayToBinarySearchTree\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220108\343\200\221\343\200\220ConvertSortedArrayToBinarySearchTree\343\200\221/\343\200\220108\343\200\221\343\200\220ConvertSortedArrayToBinarySearchTree\343\200\221.iml" +++ "b/\343\200\220108\343\200\221\343\200\220ConvertSortedArrayToBinarySearchTree\343\200\221/\343\200\220108\343\200\221\343\200\220ConvertSortedArrayToBinarySearchTree\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221.iml" "b/\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221.iml" +++ "b/\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220110\343\200\221\343\200\220BalancedBinaryTree\343\200\221/\343\200\220110\343\200\221\343\200\220BalancedBinaryTree\343\200\221.iml" "b/\343\200\220110\343\200\221\343\200\220BalancedBinaryTree\343\200\221/\343\200\220110\343\200\221\343\200\220BalancedBinaryTree\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220110\343\200\221\343\200\220BalancedBinaryTree\343\200\221/\343\200\220110\343\200\221\343\200\220BalancedBinaryTree\343\200\221.iml" +++ "b/\343\200\220110\343\200\221\343\200\220BalancedBinaryTree\343\200\221/\343\200\220110\343\200\221\343\200\220BalancedBinaryTree\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220111\343\200\221\343\200\220MinimumDepthOfBinaryTree\343\200\221/\343\200\220111\343\200\221\343\200\220MinimumDepthOfBinaryTree\343\200\221.iml" "b/\343\200\220111\343\200\221\343\200\220MinimumDepthOfBinaryTree\343\200\221/\343\200\220111\343\200\221\343\200\220MinimumDepthOfBinaryTree\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220111\343\200\221\343\200\220MinimumDepthOfBinaryTree\343\200\221/\343\200\220111\343\200\221\343\200\220MinimumDepthOfBinaryTree\343\200\221.iml" +++ "b/\343\200\220111\343\200\221\343\200\220MinimumDepthOfBinaryTree\343\200\221/\343\200\220111\343\200\221\343\200\220MinimumDepthOfBinaryTree\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220112\343\200\221\343\200\220PathSum\343\200\221/\343\200\220112\343\200\221\343\200\220PathSum\343\200\221.iml" "b/\343\200\220112\343\200\221\343\200\220PathSum\343\200\221/\343\200\220112\343\200\221\343\200\220PathSum\343\200\221.iml" index 5c38831..86622ab 100644 --- "a/\343\200\220112\343\200\221\343\200\220PathSum\343\200\221/\343\200\220112\343\200\221\343\200\220PathSum\343\200\221.iml" +++ "b/\343\200\220112\343\200\221\343\200\220PathSum\343\200\221/\343\200\220112\343\200\221\343\200\220PathSum\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220113\343\200\221\343\200\220PathSumII\343\200\221/\343\200\220113\343\200\221\343\200\220PathSumII\343\200\221.iml" "b/\343\200\220113\343\200\221\343\200\220PathSumII\343\200\221/\343\200\220113\343\200\221\343\200\220PathSumII\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220113\343\200\221\343\200\220PathSumII\343\200\221/\343\200\220113\343\200\221\343\200\220PathSumII\343\200\221.iml" +++ "b/\343\200\220113\343\200\221\343\200\220PathSumII\343\200\221/\343\200\220113\343\200\221\343\200\220PathSumII\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220114\343\200\221\343\200\220FlattenBinaryTreeToLinkedList\343\200\221/\343\200\220114\343\200\221\343\200\220FlattenBinaryTreeToLinkedList\343\200\221.iml" "b/\343\200\220114\343\200\221\343\200\220FlattenBinaryTreeToLinkedList\343\200\221/\343\200\220114\343\200\221\343\200\220FlattenBinaryTreeToLinkedList\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220114\343\200\221\343\200\220FlattenBinaryTreeToLinkedList\343\200\221/\343\200\220114\343\200\221\343\200\220FlattenBinaryTreeToLinkedList\343\200\221.iml" +++ "b/\343\200\220114\343\200\221\343\200\220FlattenBinaryTreeToLinkedList\343\200\221/\343\200\220114\343\200\221\343\200\220FlattenBinaryTreeToLinkedList\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220116\343\200\221\343\200\220PopulatingNextRightPointersinEachNode \343\200\221/\343\200\220116\343\200\221\343\200\220PopulatingNextRightPointersinEachNode \343\200\221.iml" "b/\343\200\220116\343\200\221\343\200\220PopulatingNextRightPointersinEachNode \343\200\221/\343\200\220116\343\200\221\343\200\220PopulatingNextRightPointersinEachNode \343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220116\343\200\221\343\200\220PopulatingNextRightPointersinEachNode \343\200\221/\343\200\220116\343\200\221\343\200\220PopulatingNextRightPointersinEachNode \343\200\221.iml" +++ "b/\343\200\220116\343\200\221\343\200\220PopulatingNextRightPointersinEachNode \343\200\221/\343\200\220116\343\200\221\343\200\220PopulatingNextRightPointersinEachNode \343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221/\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221.iml" "b/\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221/\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221/\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221.iml" +++ "b/\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221/\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220118\343\200\221\343\200\220Pascal'sTriangle\343\200\221/\343\200\220118\343\200\221\343\200\220Pascal'sTriangle\343\200\221.iml" "b/\343\200\220118\343\200\221\343\200\220Pascal'sTriangle\343\200\221/\343\200\220118\343\200\221\343\200\220Pascal'sTriangle\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220118\343\200\221\343\200\220Pascal'sTriangle\343\200\221/\343\200\220118\343\200\221\343\200\220Pascal'sTriangle\343\200\221.iml" +++ "b/\343\200\220118\343\200\221\343\200\220Pascal'sTriangle\343\200\221/\343\200\220118\343\200\221\343\200\220Pascal'sTriangle\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220119\343\200\221\343\200\220Pascal'sTriangleII\343\200\221/\343\200\220119\343\200\221\343\200\220Pascal'sTriangleII\343\200\221.iml" "b/\343\200\220119\343\200\221\343\200\220Pascal'sTriangleII\343\200\221/\343\200\220119\343\200\221\343\200\220Pascal'sTriangleII\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220119\343\200\221\343\200\220Pascal'sTriangleII\343\200\221/\343\200\220119\343\200\221\343\200\220Pascal'sTriangleII\343\200\221.iml" +++ "b/\343\200\220119\343\200\221\343\200\220Pascal'sTriangleII\343\200\221/\343\200\220119\343\200\221\343\200\220Pascal'sTriangleII\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220120\343\200\221\343\200\220Triangle\343\200\221/\343\200\220120\343\200\221\343\200\220Triangle\343\200\221.iml" "b/\343\200\220120\343\200\221\343\200\220Triangle\343\200\221/\343\200\220120\343\200\221\343\200\220Triangle\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220120\343\200\221\343\200\220Triangle\343\200\221/\343\200\220120\343\200\221\343\200\220Triangle\343\200\221.iml" +++ "b/\343\200\220120\343\200\221\343\200\220Triangle\343\200\221/\343\200\220120\343\200\221\343\200\220Triangle\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220121\343\200\221\343\200\220BestTimeToBuyAndSellStock\343\200\221/\343\200\220121\343\200\221\343\200\220BestTimeToBuyAndSellStock\343\200\221.iml" "b/\343\200\220121\343\200\221\343\200\220BestTimeToBuyAndSellStock\343\200\221/\343\200\220121\343\200\221\343\200\220BestTimeToBuyAndSellStock\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220121\343\200\221\343\200\220BestTimeToBuyAndSellStock\343\200\221/\343\200\220121\343\200\221\343\200\220BestTimeToBuyAndSellStock\343\200\221.iml" +++ "b/\343\200\220121\343\200\221\343\200\220BestTimeToBuyAndSellStock\343\200\221/\343\200\220121\343\200\221\343\200\220BestTimeToBuyAndSellStock\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220124\346\234\252\343\200\221\343\200\220BinaryTreeMaximumPathSum\343\200\221/\343\200\220124\343\200\221\343\200\220BinaryTreeMaximumPathSum\343\200\221.iml" "b/\343\200\220124\346\234\252\343\200\221\343\200\220BinaryTreeMaximumPathSum\343\200\221/\343\200\220124\343\200\221\343\200\220BinaryTreeMaximumPathSum\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220124\346\234\252\343\200\221\343\200\220BinaryTreeMaximumPathSum\343\200\221/\343\200\220124\343\200\221\343\200\220BinaryTreeMaximumPathSum\343\200\221.iml" +++ "b/\343\200\220124\346\234\252\343\200\221\343\200\220BinaryTreeMaximumPathSum\343\200\221/\343\200\220124\343\200\221\343\200\220BinaryTreeMaximumPathSum\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220125\343\200\221\343\200\220ValidPalindrome\343\200\221/\343\200\220125\343\200\221\343\200\220ValidPalindrome\343\200\221.iml" "b/\343\200\220125\343\200\221\343\200\220ValidPalindrome\343\200\221/\343\200\220125\343\200\221\343\200\220ValidPalindrome\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220125\343\200\221\343\200\220ValidPalindrome\343\200\221/\343\200\220125\343\200\221\343\200\220ValidPalindrome\343\200\221.iml" +++ "b/\343\200\220125\343\200\221\343\200\220ValidPalindrome\343\200\221/\343\200\220125\343\200\221\343\200\220ValidPalindrome\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220127\346\234\252\343\200\221\343\200\220WordLadder\343\200\221/\343\200\220127\343\200\221\343\200\220WordLadder\343\200\221.iml" "b/\343\200\220127\346\234\252\343\200\221\343\200\220WordLadder\343\200\221/\343\200\220127\343\200\221\343\200\220WordLadder\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220127\346\234\252\343\200\221\343\200\220WordLadder\343\200\221/\343\200\220127\343\200\221\343\200\220WordLadder\343\200\221.iml" +++ "b/\343\200\220127\346\234\252\343\200\221\343\200\220WordLadder\343\200\221/\343\200\220127\343\200\221\343\200\220WordLadder\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220129\343\200\221\343\200\220SumRootToLeafNumbers\343\200\221/\343\200\220129\343\200\221\343\200\220SumRootToLeafNumbers\343\200\221.iml" "b/\343\200\220129\343\200\221\343\200\220SumRootToLeafNumbers\343\200\221/\343\200\220129\343\200\221\343\200\220SumRootToLeafNumbers\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220129\343\200\221\343\200\220SumRootToLeafNumbers\343\200\221/\343\200\220129\343\200\221\343\200\220SumRootToLeafNumbers\343\200\221.iml" +++ "b/\343\200\220129\343\200\221\343\200\220SumRootToLeafNumbers\343\200\221/\343\200\220129\343\200\221\343\200\220SumRootToLeafNumbers\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220130\343\200\221\343\200\220SurroundedRegions\343\200\221/\343\200\220130\343\200\221\343\200\220SurroundedRegions\343\200\221.iml" "b/\343\200\220130\343\200\221\343\200\220SurroundedRegions\343\200\221/\343\200\220130\343\200\221\343\200\220SurroundedRegions\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220130\343\200\221\343\200\220SurroundedRegions\343\200\221/\343\200\220130\343\200\221\343\200\220SurroundedRegions\343\200\221.iml" +++ "b/\343\200\220130\343\200\221\343\200\220SurroundedRegions\343\200\221/\343\200\220130\343\200\221\343\200\220SurroundedRegions\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220134\343\200\221\343\200\220GasStation\343\200\221/\343\200\220134\343\200\221\343\200\220GasStation\343\200\221.iml" "b/\343\200\220134\343\200\221\343\200\220GasStation\343\200\221/\343\200\220134\343\200\221\343\200\220GasStation\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220134\343\200\221\343\200\220GasStation\343\200\221/\343\200\220134\343\200\221\343\200\220GasStation\343\200\221.iml" +++ "b/\343\200\220134\343\200\221\343\200\220GasStation\343\200\221/\343\200\220134\343\200\221\343\200\220GasStation\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220136\343\200\221\343\200\220SingleNumber\343\200\221/\343\200\220136\343\200\221\343\200\220SingleNumber\343\200\221.iml" "b/\343\200\220136\343\200\221\343\200\220SingleNumber\343\200\221/\343\200\220136\343\200\221\343\200\220SingleNumber\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220136\343\200\221\343\200\220SingleNumber\343\200\221/\343\200\220136\343\200\221\343\200\220SingleNumber\343\200\221.iml" +++ "b/\343\200\220136\343\200\221\343\200\220SingleNumber\343\200\221/\343\200\220136\343\200\221\343\200\220SingleNumber\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220137\343\200\221\343\200\220SingleNumberII\343\200\221/\343\200\220137\343\200\221\343\200\220SingleNumberII\343\200\221.iml" "b/\343\200\220137\343\200\221\343\200\220SingleNumberII\343\200\221/\343\200\220137\343\200\221\343\200\220SingleNumberII\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220137\343\200\221\343\200\220SingleNumberII\343\200\221/\343\200\220137\343\200\221\343\200\220SingleNumberII\343\200\221.iml" +++ "b/\343\200\220137\343\200\221\343\200\220SingleNumberII\343\200\221/\343\200\220137\343\200\221\343\200\220SingleNumberII\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221.iml" "b/\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221.iml" +++ "b/\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220139\343\200\221\343\200\220WordBreak\343\200\221/\343\200\220139\343\200\221\343\200\220WordBreak\343\200\221.iml" "b/\343\200\220139\343\200\221\343\200\220WordBreak\343\200\221/\343\200\220139\343\200\221\343\200\220WordBreak\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220139\343\200\221\343\200\220WordBreak\343\200\221/\343\200\220139\343\200\221\343\200\220WordBreak\343\200\221.iml" +++ "b/\343\200\220139\343\200\221\343\200\220WordBreak\343\200\221/\343\200\220139\343\200\221\343\200\220WordBreak\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220141\343\200\221\343\200\220LinkedListCycle\343\200\221/\343\200\220141\343\200\221\343\200\220LinkedListCycle\343\200\221.iml" "b/\343\200\220141\343\200\221\343\200\220LinkedListCycle\343\200\221/\343\200\220141\343\200\221\343\200\220LinkedListCycle\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220141\343\200\221\343\200\220LinkedListCycle\343\200\221/\343\200\220141\343\200\221\343\200\220LinkedListCycle\343\200\221.iml" +++ "b/\343\200\220141\343\200\221\343\200\220LinkedListCycle\343\200\221/\343\200\220141\343\200\221\343\200\220LinkedListCycle\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220142\343\200\221\343\200\220LinkedListCycleII\343\200\221/\343\200\220142\343\200\221\343\200\220LinkedListCycleII\343\200\221.iml" "b/\343\200\220142\343\200\221\343\200\220LinkedListCycleII\343\200\221/\343\200\220142\343\200\221\343\200\220LinkedListCycleII\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220142\343\200\221\343\200\220LinkedListCycleII\343\200\221/\343\200\220142\343\200\221\343\200\220LinkedListCycleII\343\200\221.iml" +++ "b/\343\200\220142\343\200\221\343\200\220LinkedListCycleII\343\200\221/\343\200\220142\343\200\221\343\200\220LinkedListCycleII\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220143\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/\343\200\220143\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221.iml" "b/\343\200\220143\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/\343\200\220143\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220143\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/\343\200\220143\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221.iml" +++ "b/\343\200\220143\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/\343\200\220143\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220144\343\200\221\343\200\220BinaryTreePreorderTraversal\343\200\221/\343\200\220144\343\200\221\343\200\220BinaryTreePreorderTraversal\343\200\221.iml" "b/\343\200\220144\343\200\221\343\200\220BinaryTreePreorderTraversal\343\200\221/\343\200\220144\343\200\221\343\200\220BinaryTreePreorderTraversal\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220144\343\200\221\343\200\220BinaryTreePreorderTraversal\343\200\221/\343\200\220144\343\200\221\343\200\220BinaryTreePreorderTraversal\343\200\221.iml" +++ "b/\343\200\220144\343\200\221\343\200\220BinaryTreePreorderTraversal\343\200\221/\343\200\220144\343\200\221\343\200\220BinaryTreePreorderTraversal\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220145\343\200\221\343\200\220BinaryTreePostorderTraversal\343\200\221/\343\200\220145\343\200\221\343\200\220BinaryTreePostorderTraversal\343\200\221.iml" "b/\343\200\220145\343\200\221\343\200\220BinaryTreePostorderTraversal\343\200\221/\343\200\220145\343\200\221\343\200\220BinaryTreePostorderTraversal\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220145\343\200\221\343\200\220BinaryTreePostorderTraversal\343\200\221/\343\200\220145\343\200\221\343\200\220BinaryTreePostorderTraversal\343\200\221.iml" +++ "b/\343\200\220145\343\200\221\343\200\220BinaryTreePostorderTraversal\343\200\221/\343\200\220145\343\200\221\343\200\220BinaryTreePostorderTraversal\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220147\343\200\221\343\200\220InsertionSortList\343\200\221/\343\200\220147\343\200\221\343\200\220InsertionSortList\343\200\221.iml" "b/\343\200\220147\343\200\221\343\200\220InsertionSortList\343\200\221/\343\200\220147\343\200\221\343\200\220InsertionSortList\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220147\343\200\221\343\200\220InsertionSortList\343\200\221/\343\200\220147\343\200\221\343\200\220InsertionSortList\343\200\221.iml" +++ "b/\343\200\220147\343\200\221\343\200\220InsertionSortList\343\200\221/\343\200\220147\343\200\221\343\200\220InsertionSortList\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220150\343\200\221\343\200\220EvaluateReversePolishNotation\343\200\221/\343\200\220150\343\200\221\343\200\220EvaluateReversePolishNotation\343\200\221.iml" "b/\343\200\220150\343\200\221\343\200\220EvaluateReversePolishNotation\343\200\221/\343\200\220150\343\200\221\343\200\220EvaluateReversePolishNotation\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220150\343\200\221\343\200\220EvaluateReversePolishNotation\343\200\221/\343\200\220150\343\200\221\343\200\220EvaluateReversePolishNotation\343\200\221.iml" +++ "b/\343\200\220150\343\200\221\343\200\220EvaluateReversePolishNotation\343\200\221/\343\200\220150\343\200\221\343\200\220EvaluateReversePolishNotation\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220151\343\200\221\343\200\220ReverseWordsInAString\343\200\221/\343\200\220151\343\200\221\343\200\220ReverseWordsInAString\343\200\221.iml" "b/\343\200\220151\343\200\221\343\200\220ReverseWordsInAString\343\200\221/\343\200\220151\343\200\221\343\200\220ReverseWordsInAString\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220151\343\200\221\343\200\220ReverseWordsInAString\343\200\221/\343\200\220151\343\200\221\343\200\220ReverseWordsInAString\343\200\221.iml" +++ "b/\343\200\220151\343\200\221\343\200\220ReverseWordsInAString\343\200\221/\343\200\220151\343\200\221\343\200\220ReverseWordsInAString\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220152\343\200\221\343\200\220MaximumProductSubarray\343\200\221/\343\200\220152\343\200\221\343\200\220MaximumProductSubarray\343\200\221.iml" "b/\343\200\220152\343\200\221\343\200\220MaximumProductSubarray\343\200\221/\343\200\220152\343\200\221\343\200\220MaximumProductSubarray\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220152\343\200\221\343\200\220MaximumProductSubarray\343\200\221/\343\200\220152\343\200\221\343\200\220MaximumProductSubarray\343\200\221.iml" +++ "b/\343\200\220152\343\200\221\343\200\220MaximumProductSubarray\343\200\221/\343\200\220152\343\200\221\343\200\220MaximumProductSubarray\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220153\343\200\221\343\200\220FindMinimumInRotatedSortedArray\343\200\221/\343\200\220153\343\200\221\343\200\220FindMinimumInRotatedSortedArray\343\200\221.iml" "b/\343\200\220153\343\200\221\343\200\220FindMinimumInRotatedSortedArray\343\200\221/\343\200\220153\343\200\221\343\200\220FindMinimumInRotatedSortedArray\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220153\343\200\221\343\200\220FindMinimumInRotatedSortedArray\343\200\221/\343\200\220153\343\200\221\343\200\220FindMinimumInRotatedSortedArray\343\200\221.iml" +++ "b/\343\200\220153\343\200\221\343\200\220FindMinimumInRotatedSortedArray\343\200\221/\343\200\220153\343\200\221\343\200\220FindMinimumInRotatedSortedArray\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220154\343\200\221\343\200\220FindMinimumInRotatedSortedArrayII\343\200\221/\343\200\220154\343\200\221\343\200\220FindMinimumInRotatedSortedArrayII\343\200\221.iml" "b/\343\200\220154\343\200\221\343\200\220FindMinimumInRotatedSortedArrayII\343\200\221/\343\200\220154\343\200\221\343\200\220FindMinimumInRotatedSortedArrayII\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220154\343\200\221\343\200\220FindMinimumInRotatedSortedArrayII\343\200\221/\343\200\220154\343\200\221\343\200\220FindMinimumInRotatedSortedArrayII\343\200\221.iml" +++ "b/\343\200\220154\343\200\221\343\200\220FindMinimumInRotatedSortedArrayII\343\200\221/\343\200\220154\343\200\221\343\200\220FindMinimumInRotatedSortedArrayII\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220155\343\200\221\343\200\220MinStack\343\200\221/\343\200\220155\343\200\221\343\200\220MinStack\343\200\221.iml" "b/\343\200\220155\343\200\221\343\200\220MinStack\343\200\221/\343\200\220155\343\200\221\343\200\220MinStack\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220155\343\200\221\343\200\220MinStack\343\200\221/\343\200\220155\343\200\221\343\200\220MinStack\343\200\221.iml" +++ "b/\343\200\220155\343\200\221\343\200\220MinStack\343\200\221/\343\200\220155\343\200\221\343\200\220MinStack\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220162\346\234\252\343\200\221\343\200\220FindPeakElement\343\200\221/\343\200\220162\343\200\221\343\200\220FindPeakElement\343\200\221.iml" "b/\343\200\220162\346\234\252\343\200\221\343\200\220FindPeakElement\343\200\221/\343\200\220162\343\200\221\343\200\220FindPeakElement\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220162\346\234\252\343\200\221\343\200\220FindPeakElement\343\200\221/\343\200\220162\343\200\221\343\200\220FindPeakElement\343\200\221.iml" +++ "b/\343\200\220162\346\234\252\343\200\221\343\200\220FindPeakElement\343\200\221/\343\200\220162\343\200\221\343\200\220FindPeakElement\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220167\343\200\221\343\200\220Two Sum II - Input array is sorted\343\200\221/\343\200\220167\343\200\221\343\200\220Two Sum II - Input array is sorted\343\200\221.iml" "b/\343\200\220167\343\200\221\343\200\220Two Sum II - Input array is sorted\343\200\221/\343\200\220167\343\200\221\343\200\220Two Sum II - Input array is sorted\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220167\343\200\221\343\200\220Two Sum II - Input array is sorted\343\200\221/\343\200\220167\343\200\221\343\200\220Two Sum II - Input array is sorted\343\200\221.iml" +++ "b/\343\200\220167\343\200\221\343\200\220Two Sum II - Input array is sorted\343\200\221/\343\200\220167\343\200\221\343\200\220Two Sum II - Input array is sorted\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220191\343\200\221\343\200\220NumberOf1Bits\343\200\221/\343\200\220191\343\200\221\343\200\220NumberOf1Bits\343\200\221.iml" "b/\343\200\220191\343\200\221\343\200\220NumberOf1Bits\343\200\221/\343\200\220191\343\200\221\343\200\220NumberOf1Bits\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220191\343\200\221\343\200\220NumberOf1Bits\343\200\221/\343\200\220191\343\200\221\343\200\220NumberOf1Bits\343\200\221.iml" +++ "b/\343\200\220191\343\200\221\343\200\220NumberOf1Bits\343\200\221/\343\200\220191\343\200\221\343\200\220NumberOf1Bits\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220198\343\200\221\343\200\220HouseRobber\343\200\221/\343\200\220198\343\200\221\343\200\220HouseRobber\343\200\221.iml" "b/\343\200\220198\343\200\221\343\200\220HouseRobber\343\200\221/\343\200\220198\343\200\221\343\200\220HouseRobber\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220198\343\200\221\343\200\220HouseRobber\343\200\221/\343\200\220198\343\200\221\343\200\220HouseRobber\343\200\221.iml" +++ "b/\343\200\220198\343\200\221\343\200\220HouseRobber\343\200\221/\343\200\220198\343\200\221\343\200\220HouseRobber\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220199\343\200\221\343\200\220BinaryTreeRightSideView\343\200\221/\343\200\220199\343\200\221\343\200\220BinaryTreeRightSideView\343\200\221.iml" "b/\343\200\220199\343\200\221\343\200\220BinaryTreeRightSideView\343\200\221/\343\200\220199\343\200\221\343\200\220BinaryTreeRightSideView\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220199\343\200\221\343\200\220BinaryTreeRightSideView\343\200\221/\343\200\220199\343\200\221\343\200\220BinaryTreeRightSideView\343\200\221.iml" +++ "b/\343\200\220199\343\200\221\343\200\220BinaryTreeRightSideView\343\200\221/\343\200\220199\343\200\221\343\200\220BinaryTreeRightSideView\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220200\343\200\221\343\200\220NumberOfIslands\343\200\221/\343\200\220200\343\200\221\343\200\220NumberOfIslands\343\200\221.iml" "b/\343\200\220200\343\200\221\343\200\220NumberOfIslands\343\200\221/\343\200\220200\343\200\221\343\200\220NumberOfIslands\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220200\343\200\221\343\200\220NumberOfIslands\343\200\221/\343\200\220200\343\200\221\343\200\220NumberOfIslands\343\200\221.iml" +++ "b/\343\200\220200\343\200\221\343\200\220NumberOfIslands\343\200\221/\343\200\220200\343\200\221\343\200\220NumberOfIslands\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220201\343\200\221\343\200\220BitwiseANDOfNumbersRange\343\200\221/\343\200\220201\343\200\221\343\200\220BitwiseANDOfNumbersRange\343\200\221.iml" "b/\343\200\220201\343\200\221\343\200\220BitwiseANDOfNumbersRange\343\200\221/\343\200\220201\343\200\221\343\200\220BitwiseANDOfNumbersRange\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220201\343\200\221\343\200\220BitwiseANDOfNumbersRange\343\200\221/\343\200\220201\343\200\221\343\200\220BitwiseANDOfNumbersRange\343\200\221.iml" +++ "b/\343\200\220201\343\200\221\343\200\220BitwiseANDOfNumbersRange\343\200\221/\343\200\220201\343\200\221\343\200\220BitwiseANDOfNumbersRange\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220202\343\200\221\343\200\220HappyNumber \343\200\221/\343\200\220202\343\200\221\343\200\220HappyNumber \343\200\221.iml" "b/\343\200\220202\343\200\221\343\200\220HappyNumber \343\200\221/\343\200\220202\343\200\221\343\200\220HappyNumber \343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220202\343\200\221\343\200\220HappyNumber \343\200\221/\343\200\220202\343\200\221\343\200\220HappyNumber \343\200\221.iml" +++ "b/\343\200\220202\343\200\221\343\200\220HappyNumber \343\200\221/\343\200\220202\343\200\221\343\200\220HappyNumber \343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220203\343\200\221\343\200\220RemoveLinkedList Elements\343\200\221/\343\200\220203\343\200\221\343\200\220RemoveLinkedList Elements\343\200\221.iml" "b/\343\200\220203\343\200\221\343\200\220RemoveLinkedList Elements\343\200\221/\343\200\220203\343\200\221\343\200\220RemoveLinkedList Elements\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220203\343\200\221\343\200\220RemoveLinkedList Elements\343\200\221/\343\200\220203\343\200\221\343\200\220RemoveLinkedList Elements\343\200\221.iml" +++ "b/\343\200\220203\343\200\221\343\200\220RemoveLinkedList Elements\343\200\221/\343\200\220203\343\200\221\343\200\220RemoveLinkedList Elements\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220204\343\200\221\343\200\220CountPrimes\343\200\221/\343\200\220204\343\200\221\343\200\220CountPrimes\343\200\221.iml" "b/\343\200\220204\343\200\221\343\200\220CountPrimes\343\200\221/\343\200\220204\343\200\221\343\200\220CountPrimes\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220204\343\200\221\343\200\220CountPrimes\343\200\221/\343\200\220204\343\200\221\343\200\220CountPrimes\343\200\221.iml" +++ "b/\343\200\220204\343\200\221\343\200\220CountPrimes\343\200\221/\343\200\220204\343\200\221\343\200\220CountPrimes\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220205\343\200\221\343\200\220IsomorphicStrings\343\200\221/\343\200\220205\343\200\221\343\200\220IsomorphicStrings\343\200\221.iml" "b/\343\200\220205\343\200\221\343\200\220IsomorphicStrings\343\200\221/\343\200\220205\343\200\221\343\200\220IsomorphicStrings\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220205\343\200\221\343\200\220IsomorphicStrings\343\200\221/\343\200\220205\343\200\221\343\200\220IsomorphicStrings\343\200\221.iml" +++ "b/\343\200\220205\343\200\221\343\200\220IsomorphicStrings\343\200\221/\343\200\220205\343\200\221\343\200\220IsomorphicStrings\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220206\343\200\221\343\200\220ReverseLinkedList\343\200\221/\343\200\220206\343\200\221\343\200\220ReverseLinkedList\343\200\221.iml" "b/\343\200\220206\343\200\221\343\200\220ReverseLinkedList\343\200\221/\343\200\220206\343\200\221\343\200\220ReverseLinkedList\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220206\343\200\221\343\200\220ReverseLinkedList\343\200\221/\343\200\220206\343\200\221\343\200\220ReverseLinkedList\343\200\221.iml" +++ "b/\343\200\220206\343\200\221\343\200\220ReverseLinkedList\343\200\221/\343\200\220206\343\200\221\343\200\220ReverseLinkedList\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220215\343\200\221\343\200\220KthLargestElementInAnArray\343\200\221/\343\200\220215\343\200\221\343\200\220KthLargestElementInAnArray\343\200\221.iml" "b/\343\200\220215\343\200\221\343\200\220KthLargestElementInAnArray\343\200\221/\343\200\220215\343\200\221\343\200\220KthLargestElementInAnArray\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220215\343\200\221\343\200\220KthLargestElementInAnArray\343\200\221/\343\200\220215\343\200\221\343\200\220KthLargestElementInAnArray\343\200\221.iml" +++ "b/\343\200\220215\343\200\221\343\200\220KthLargestElementInAnArray\343\200\221/\343\200\220215\343\200\221\343\200\220KthLargestElementInAnArray\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220216\343\200\221\343\200\220CombinationSumIII\343\200\221/\343\200\220216\343\200\221\343\200\220CombinationSumIII\343\200\221.iml" "b/\343\200\220216\343\200\221\343\200\220CombinationSumIII\343\200\221/\343\200\220216\343\200\221\343\200\220CombinationSumIII\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220216\343\200\221\343\200\220CombinationSumIII\343\200\221/\343\200\220216\343\200\221\343\200\220CombinationSumIII\343\200\221.iml" +++ "b/\343\200\220216\343\200\221\343\200\220CombinationSumIII\343\200\221/\343\200\220216\343\200\221\343\200\220CombinationSumIII\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220217\343\200\221\343\200\220ContainsDuplicate \343\200\221/\343\200\220217\343\200\221\343\200\220ContainsDuplicate \343\200\221.iml" "b/\343\200\220217\343\200\221\343\200\220ContainsDuplicate \343\200\221/\343\200\220217\343\200\221\343\200\220ContainsDuplicate \343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220217\343\200\221\343\200\220ContainsDuplicate \343\200\221/\343\200\220217\343\200\221\343\200\220ContainsDuplicate \343\200\221.iml" +++ "b/\343\200\220217\343\200\221\343\200\220ContainsDuplicate \343\200\221/\343\200\220217\343\200\221\343\200\220ContainsDuplicate \343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220219\343\200\221\343\200\220ContainsDuplicateII\343\200\221/\343\200\220219\343\200\221\343\200\220ContainsDuplicateII\343\200\221.iml" "b/\343\200\220219\343\200\221\343\200\220ContainsDuplicateII\343\200\221/\343\200\220219\343\200\221\343\200\220ContainsDuplicateII\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220219\343\200\221\343\200\220ContainsDuplicateII\343\200\221/\343\200\220219\343\200\221\343\200\220ContainsDuplicateII\343\200\221.iml" +++ "b/\343\200\220219\343\200\221\343\200\220ContainsDuplicateII\343\200\221/\343\200\220219\343\200\221\343\200\220ContainsDuplicateII\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220223\343\200\221\343\200\220RectangleArea\343\200\221/\343\200\220223\343\200\221\343\200\220RectangleArea\343\200\221.iml" "b/\343\200\220223\343\200\221\343\200\220RectangleArea\343\200\221/\343\200\220223\343\200\221\343\200\220RectangleArea\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220223\343\200\221\343\200\220RectangleArea\343\200\221/\343\200\220223\343\200\221\343\200\220RectangleArea\343\200\221.iml" +++ "b/\343\200\220223\343\200\221\343\200\220RectangleArea\343\200\221/\343\200\220223\343\200\221\343\200\220RectangleArea\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220225\343\200\221\343\200\220ImplementStackUsingQueues\343\200\221/\343\200\220225\343\200\221\343\200\220ImplementStackUsingQueues\343\200\221.iml" "b/\343\200\220225\343\200\221\343\200\220ImplementStackUsingQueues\343\200\221/\343\200\220225\343\200\221\343\200\220ImplementStackUsingQueues\343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220225\343\200\221\343\200\220ImplementStackUsingQueues\343\200\221/\343\200\220225\343\200\221\343\200\220ImplementStackUsingQueues\343\200\221.iml" +++ "b/\343\200\220225\343\200\221\343\200\220ImplementStackUsingQueues\343\200\221/\343\200\220225\343\200\221\343\200\220ImplementStackUsingQueues\343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file diff --git "a/\343\200\220226\343\200\221\343\200\220InvertBinaryTree \343\200\221/\343\200\220226\343\200\221\343\200\220InvertBinaryTree \343\200\221.iml" "b/\343\200\220226\343\200\221\343\200\220InvertBinaryTree \343\200\221/\343\200\220226\343\200\221\343\200\220InvertBinaryTree \343\200\221.iml" index c90834f..f080bef 100644 --- "a/\343\200\220226\343\200\221\343\200\220InvertBinaryTree \343\200\221/\343\200\220226\343\200\221\343\200\220InvertBinaryTree \343\200\221.iml" +++ "b/\343\200\220226\343\200\221\343\200\220InvertBinaryTree \343\200\221/\343\200\220226\343\200\221\343\200\220InvertBinaryTree \343\200\221.iml" @@ -7,5 +7,7 @@ + +
\ No newline at end of file From 3095511ac32ecf8add8f9efffc5e52ad083848d7 Mon Sep 17 00:00:00 2001 From: Wang-Jun-Chao Date: Fri, 14 Jun 2019 10:51:20 +0800 Subject: [PATCH 037/108] commit --- .gitignore | 27 +- .idea/compiler.xml | 22 +- .idea/misc.xml | 10 + .idea/modules.xml | 330 +++++++++--------- [000][utils]/src/FileRename.java | 30 ++ .../src/Main.java | 0 .../src/Solution.java | 0 .../src/ListNode.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution2.java | 79 +++++ .../src/Main.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../Main.java" => [015][3 Sum]/src/Main.java | 0 .../src/Solution.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/phone-number.png | Bin .../src/Solution.java | 0 .../src/ListNode.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/ListNode.java | 0 .../src/Solution.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/ListNode.java | 0 .../src/Solution.java | 0 .../src/ListNode.java | 0 .../src/Solution.java | 0 .../src/ListNode.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution2.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/Solution2.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/sodoku.png | Bin .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Interval.java | 0 .../src/Solution.java | 0 .../src/Interval.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/ListNode.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/Solution2.java | 0 .../src/Main.java | 6 +- .../src/Solution.java | 0 .../src/Solution2.java | 56 +++ .../src/ListNode.java | 0 .../src/Solution.java | 0 .../src/ListNode.java | 0 .../src/Solution.java | 0 .../src/ListNode.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/ListNode.java | 0 .../src/Solution.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/TreeNode.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/TreeNode.java | 0 .../src/Solution.java | 0 .../src/TreeNode.java | 0 .../src/Solution.java | 0 .../src/TreeNode.java | 0 .../src/Solution.java | 0 .../src/TreeNode.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/TreeNode.java | 0 .../src/Solution.java | 0 .../src/TreeNode.java | 0 .../src/Solution.java | 0 .../src/TreeNode.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/TreeNode.java | 0 .../src/Solution.java | 0 .../src/TreeNode.java | 0 .../src/Solution.java | 0 .../src/TreeNode.java | 0 .../src/ListNode.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/TreeNode.java | 0 .../src/Solution.java | 0 .../src/TreeNode.java | 0 .../src/Solution.java | 0 .../src/TreeNode.java | 0 .../src/Solution.java | 0 .../src/TreeNode.java | 0 .../src/Solution.java | 0 .../src/TreeNode.java | 0 .../src/Solution.java | 0 .../src/TreeNode.java | 0 .../src/Solution.java | 0 .../src/TreeLinkNode.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/TreeLinkNode.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Test.java | 0 .../src/Solution.java | 0 .../src/TreeNode.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/TreeNode.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Main.java | 0 .../src/RandomListNode.java | 0 .../src/Solution.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/ListNode.java | 0 .../src/Solution.java | 0 .../src/ListNode.java | 0 .../src/Solution.java | 0 .../src/RandomListNode.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/TreeNode.java | 0 .../src/Solution.java | 0 .../src/TreeNode.java | 0 .../src/ListNode.java | 0 .../src/Solution.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/MinStack.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/TreeNode.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/ListNode.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/ListNode.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../src/Main.java | 0 .../src/Solution.java | 0 .../src/MyStack.java | 0 .../src/Solution.java | 0 .../src/TreeNode.java | 0 .../src/Solution.java | 0 .../src/Test.java | 0 .../src/MyQueue.java | 0 .../src/Test.java | 0 .../src/ListNode.java | 0 .../src/Solution.java | 0 .../src/Solution2.java | 0 .../src/Test.java | 0 .../src/Solution.java | 0 .../src/TreeNode.java | 0 .../src/ListNode.java | 0 .../src/Solution.java | 0 .../src/Test.java | 0 .../src/Solution.java | 0 .../src/Test.java | 0 .../src/Solution.java | 0 .../src/Test.java | 0 .../src/TreeNode.java | 0 .../src/Solution.java | 0 .../src/Test.java | 0 .../src/Solution.java | 0 .../src/Test.java | 0 .../src/Solution.java | 0 .../src/Test.java | 0 .../src/Solution.java | 0 .../src/Test.java | 0 .../src/VersionControl.java | 0 .../src/Solution.java | 0 .../src/Test.java | 0 .../src/Solution.java | 0 .../src/Test.java | 0 .../src/NumArray.java | 0 .../src/Test.java | 0 .../src/Solution.java | 0 .../src/Test.java | 0 .../src/Solution.java | 0 .../src/Solution.java | 0 .../Main.class" | Bin 847 -> 0 bytes .../Solution$Node.class" | Bin 837 -> 0 bytes .../Solution.class" | Bin 979 -> 0 bytes .../Main.class" | Bin 649 -> 0 bytes .../Solution.class" | Bin 1708 -> 0 bytes .../Main.class" | Bin 630 -> 0 bytes .../Solution.class" | Bin 992 -> 0 bytes .../Main.class" | Bin 601 -> 0 bytes .../Solution.class" | Bin 927 -> 0 bytes .../Main.class" | Bin 695 -> 0 bytes .../Solution.class" | Bin 1157 -> 0 bytes .../ListNode.class" | Bin 326 -> 0 bytes .../Main.class" | Bin 1429 -> 0 bytes .../Solution.class" | Bin 874 -> 0 bytes .../Main.class" | Bin 589 -> 0 bytes .../Solution.class" | Bin 1168 -> 0 bytes .../Main.class" | Bin 4731 -> 0 bytes .../Solution.class" | Bin 878 -> 0 bytes .../Main.class" | Bin 732 -> 0 bytes .../Solution.class" | Bin 1350 -> 0 bytes .../Main.class" | Bin 596 -> 0 bytes .../Solution.class" | Bin 1522 -> 0 bytes .../Main.class" | Bin 1179 -> 0 bytes .../Solution.class" | Bin 1003 -> 0 bytes .../Main.class" | Bin 938 -> 0 bytes .../Solution.class" | Bin 1334 -> 0 bytes .../TreeNode.class" | Bin 342 -> 0 bytes .../Main.class" | Bin 637 -> 0 bytes .../Solution.class" | Bin 581 -> 0 bytes .../Main.class" | Bin 834 -> 0 bytes .../Solution.class" | Bin 2157 -> 0 bytes .../TreeNode.class" | Bin 342 -> 0 bytes .../Main.class" | Bin 1168 -> 0 bytes .../Solution.class" | Bin 1077 -> 0 bytes .../TreeNode.class" | Bin 342 -> 0 bytes .../ListNode.class" | Bin 326 -> 0 bytes .../Main.class" | Bin 1972 -> 0 bytes .../Solution.class" | Bin 807 -> 0 bytes .../TreeNode.class" | Bin 342 -> 0 bytes .../Main.class" | Bin 1248 -> 0 bytes .../Solution.class" | Bin 1542 -> 0 bytes .../TreeLinkNode.class" | Bin 369 -> 0 bytes .../Main.class" | Bin 1319 -> 0 bytes .../Solution.class" | Bin 1387 -> 0 bytes .../Main.class" | Bin 1745 -> 0 bytes .../Solution$Coordinate.class" | Bin 976 -> 0 bytes .../Solution.class" | Bin 3808 -> 0 bytes .../Main.class" | Bin 1298 -> 0 bytes .../RandomListNode.class" | Bin 363 -> 0 bytes .../Solution.class" | Bin 1208 -> 0 bytes .../Main.class" | Bin 1631 -> 0 bytes .../Solution.class" | Bin 2561 -> 0 bytes .../Main.class" | Bin 655 -> 0 bytes .../Solution.class" | Bin 1436 -> 0 bytes .../Main.class" | Bin 722 -> 0 bytes .../Solution.class" | Bin 1745 -> 0 bytes .../Main.class" | Bin 594 -> 0 bytes .../Solution.class" | Bin 769 -> 0 bytes .../Main.class" | Bin 591 -> 0 bytes .../Solution.class" | Bin 886 -> 0 bytes .../Main.class" | Bin 588 -> 0 bytes .../Solution.class" | Bin 429 -> 0 bytes .../Main.class" | Bin 631 -> 0 bytes .../Solution.class" | Bin 584 -> 0 bytes .../Solution.class" | Bin 1267 -> 0 bytes .../Main.class" | Bin 596 -> 0 bytes .../Solution.class" | Bin 1498 -> 0 bytes .../Main.class" | Bin 620 -> 0 bytes .../Solution.class" | Bin 1819 -> 0 bytes .../Main.class" | Bin 674 -> 0 bytes .../Solution.class" | Bin 854 -> 0 bytes .../Main.class" | Bin 618 -> 0 bytes .../Solution.class" | Bin 1055 -> 0 bytes pom.xml | 12 + ...200\221\343\200\220TwoSum\343\200\221.iml" | 13 - ...\343\200\220AddTwoNumbers\343\200\221.iml" | 13 - ...ithoutRepeatingCharacters\343\200\221.iml" | 13 - ...20MedianofTwoSortedArrays\343\200\221.iml" | 13 - ...alindromicSubstringTotal \343\200\221.iml" | 13 - ...3\200\220ZigZagConversion\343\200\221.iml" | 13 - ...343\200\220ReverseInteger\343\200\221.iml" | 13 - ...220StringToInteger (atoi)\343\200\221.iml" | 13 - ...3\200\220PalindromeNumber\343\200\221.iml" | 13 - ...RegularExpressionMatching\343\200\221.iml" | 13 - ...20ContainerWithMost Water\343\200\221.iml" | 13 - ...343\200\220IntegerToRoman\343\200\221.iml" | 13 - ...343\200\220RomarToInteger\343\200\221.iml" | 13 - ...00\220LongestCommonPrefix\343\200\221.iml" | 13 - ...3\200\221\343\200\2203Sum\343\200\221.iml" | 13 - ...21\343\200\2203SumClosest\343\200\221.iml" | 13 - ...ombinationsOfAPhonNumber \343\200\221.iml" | 13 - ...3\200\221\343\200\2204Sum\343\200\221.iml" | 13 - ...emoveNthNodeFromEndOfList\343\200\221.iml" | 13 - ...3\200\220ValidParentheses\343\200\221.iml" | 13 - ...00\220MergeTwoSortedLists\343\200\221.iml" | 13 - ...00\220GenerateParentheses\343\200\221.iml" | 13 - ...\200\220MergeKSortedLists\343\200\221.iml" | 13 - ...3\200\220SwapNodesInPairs\343\200\221.iml" | 13 - ...\220ReverseNodesInK-Group\343\200\221.iml" | 13 - ...DuplicatesfromSortedArray\343\200\221.iml" | 13 - ...\343\200\220RemoveElement\343\200\221.iml" | 13 - ...200\220Implement-strStr()\343\200\221.iml" | 13 - ...\200\220DivideTwoIntegers\343\200\221.iml" | 13 - ...thConcatenationOfAllWords\343\200\221.iml" | 13 - ...20LongestValidParentheses\343\200\221.iml" | 13 - ...earchInRotatedSortedArray\343\200\221.iml" | 13 - ...43\200\220SearchForARange\343\200\221.iml" | 13 - ...0\220SearchInsertPosition\343\200\221.iml" | 13 - ...1\343\200\220Valid Sudoku\343\200\221.iml" | 13 - ...\343\200\220Sudoku Solver\343\200\221.iml" | 13 - ...21\343\200\220CountAndSay\343\200\221.iml" | 13 - ...43\200\220Combination Sum\343\200\221.iml" | 13 - ...200\220Combination Sum II\343\200\221.iml" | 13 - ...220First Missing Positive\343\200\221.iml" | 13 - ...00\220Trapping Rain Water\343\200\221.iml" | 13 - ...3\200\220Multiply Strings\343\200\221.iml" | 13 - ...\200\220Wildcard Matching\343\200\221.iml" | 13 - ...1\343\200\220Jump Game II\343\200\221.iml" | 13 - ...1\343\200\220Permutations\343\200\221.iml" | 13 - ...43\200\220Permutations II\343\200\221.iml" | 13 - ...1\343\200\220Rotate Image\343\200\221.iml" | 13 - ...343\200\220Group Anagrams\343\200\221.iml" | 13 - ...0\221\343\200\220Pow(x,n)\343\200\221.iml" | 13 - ...0\221\343\200\220N-Queens\343\200\221.iml" | 13 - ...21\343\200\220N-Queens II\343\200\221.iml" | 14 - ...43\200\220MaximumSubarray\343\200\221.iml" | 13 - ...1\343\200\220SpiralMatrix\343\200\221.iml" | 13 - ...\221\343\200\220Jump Game\343\200\221.iml" | 13 - ...343\200\220MergeIntervals\343\200\221.iml" | 13 - ...343\200\220InsertInterval\343\200\221.iml" | 13 - ...3\200\220LengthOfLastWord\343\200\221.iml" | 13 - ...343\200\220SpiralMatrixII\343\200\221.iml" | 13 - ...0\220Permutation Sequence\343\200\221.iml" | 13 - ...221\343\200\220RotateList\343\200\221.iml" | 13 - ...21\343\200\220UniquePaths\343\200\221.iml" | 13 - ...\343\200\220UniquePathsII\343\200\221.iml" | 13 - ...343\200\220MinimumPathSum\343\200\221.iml" | 13 - ...00\221\343\200\220PlusOne\343\200\221.iml" | 13 - ...\221\343\200\220AddBinary\343\200\221.iml" | 13 - ...343\200\220ClimbingStairs\343\200\221.iml" | 13 - ...\343\200\220Simplify Path\343\200\221.iml" | 13 - ...43\200\220SetMatrixZeroes\343\200\221.iml" | 13 - ...43\200\220SearchA2DMatrix\343\200\221.iml" | 13 - ...221\343\200\220SortColors\343\200\221.iml" | 13 - ...1\343\200\220Combinations\343\200\221.iml" | 13 - ...00\221\343\200\220Subsets\343\200\221.iml" | 13 - ...221\343\200\220WordSearch\343\200\221.iml" | 13 - ...archInRotatedSortedArraII\343\200\221.iml" | 13 - ...uplicatesFromSortedListII\343\200\221.iml" | 13 - ...eDuplicatesFromSortedList\343\200\221.iml" | 13 - ...\343\200\220PartitionList\343\200\221.iml" | 13 - ...3\200\220MergeSortedArray\343\200\221.iml" | 13 - ...0\221\343\200\220GrayCode\343\200\221.iml" | 13 - ...00\220ReverseLinkedListII\343\200\221.iml" | 13 - ...naryTree InorderTraversal\343\200\221.iml" | 13 - ...20UniqueBinarySearchTrees\343\200\221.iml" | 13 - ...0ValidateBinarySearchTree\343\200\221.iml" | 13 - ...0\221\343\200\220SameTree\343\200\221.iml" | 13 - ...\343\200\220SymmetricTree\343\200\221.iml" | 13 - ...ryTreeLevelOrderTraversal\343\200\221.iml" | 13 - ...ZigzagLevelOrderTraversal\343\200\221.iml" | 13 - ...0MaximumDepthOfBinaryTree\343\200\221.iml" | 13 - ...eorderAndInorderTraversal\343\200\221.iml" | 13 - ...rderAndPostorderTraversal\343\200\221.iml" | 13 - ...TreeLevelOrderTraversalII\343\200\221.iml" | 13 - ...edArrayToBinarySearchTree\343\200\221.iml" | 13 - ...tedListToBinarySearchTree\343\200\221.iml" | 13 - ...200\220BalancedBinaryTree\343\200\221.iml" | 13 - ...0MinimumDepthOfBinaryTree\343\200\221.iml" | 13 - ...00\221\343\200\220PathSum\343\200\221.iml" | 13 - ...\221\343\200\220PathSumII\343\200\221.iml" | 13 - ...tenBinaryTreeToLinkedList\343\200\221.iml" | 13 - ...tRightPointersinEachNode \343\200\221.iml" | 13 - ...RightPointersInEachNodeII\343\200\221.iml" | 13 - ...3\200\220Pascal'sTriangle\343\200\221.iml" | 13 - ...200\220Pascal'sTriangleII\343\200\221.iml" | 13 - ...0\221\343\200\220Triangle\343\200\221.iml" | 13 - ...BestTimeToBuyAndSellStock\343\200\221.iml" | 13 - ...0BinaryTreeMaximumPathSum\343\200\221.iml" | 13 - ...43\200\220ValidPalindrome\343\200\221.iml" | 13 - ...221\343\200\220WordLadder\343\200\221.iml" | 13 - ...0\220SumRootToLeafNumbers\343\200\221.iml" | 13 - ...\200\220SurroundedRegions\343\200\221.iml" | 13 - ...221\343\200\220GasStation\343\200\221.iml" | 13 - ...1\343\200\220SingleNumber\343\200\221.iml" | 13 - ...343\200\220SingleNumberII\343\200\221.iml" | 13 - ...CopyListWithRandomPointer\343\200\221.iml" | 13 - ...\221\343\200\220WordBreak\343\200\221.iml" | 13 - ...43\200\220LinkedListCycle\343\200\221.iml" | 13 - ...\200\220LinkedListCycleII\343\200\221.iml" | 13 - ...CopyListWithRandomPointer\343\200\221.iml" | 13 - ...naryTreePreorderTraversal\343\200\221.iml" | 13 - ...aryTreePostorderTraversal\343\200\221.iml" | 13 - ...\200\220InsertionSortList\343\200\221.iml" | 13 - ...uateReversePolishNotation\343\200\221.iml" | 13 - ...\220ReverseWordsInAString\343\200\221.iml" | 13 - ...220MaximumProductSubarray\343\200\221.iml" | 13 - ...nimumInRotatedSortedArray\343\200\221.iml" | 13 - ...mumInRotatedSortedArrayII\343\200\221.iml" | 13 - ...0\221\343\200\220MinStack\343\200\221.iml" | 13 - ...43\200\220FindPeakElement\343\200\221.iml" | 13 - ...I - Input array is sorted\343\200\221.iml" | 13 - ...\343\200\220NumberOf1Bits\343\200\221.iml" | 13 - ...21\343\200\220HouseRobber\343\200\221.iml" | 13 - ...20BinaryTreeRightSideView\343\200\221.iml" | 13 - ...43\200\220NumberOfIslands\343\200\221.iml" | 13 - ...0BitwiseANDOfNumbersRange\343\200\221.iml" | 13 - ...1\343\200\220HappyNumber \343\200\221.iml" | 13 - ...RemoveLinkedList Elements\343\200\221.iml" | 13 - ...21\343\200\220CountPrimes\343\200\221.iml" | 13 - ...\200\220IsomorphicStrings\343\200\221.iml" | 13 - ...\200\220ReverseLinkedList\343\200\221.iml" | 13 - ...thLargestElementInAnArray\343\200\221.iml" | 13 - ...\200\220CombinationSumIII\343\200\221.iml" | 13 - ...200\220ContainsDuplicate \343\200\221.iml" | 13 - ...00\220ContainsDuplicateII\343\200\221.iml" | 13 - ...\343\200\220RectangleArea\343\200\221.iml" | 13 - ...ImplementStackUsingQueues\343\200\221.iml" | 13 - ...\200\220InvertBinaryTree \343\200\221.iml" | 13 - 501 files changed, 390 insertions(+), 2068 deletions(-) create mode 100644 [000][utils]/src/FileRename.java rename "\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221/src/Main.java" => [001][Two Sum]/src/Main.java (100%) rename "\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221/src/Solution.java" => [001][Two Sum]/src/Solution.java (100%) rename "\343\200\220002\343\200\221\343\200\220AddTwoNumbers\343\200\221/src/ListNode.java" => [002][Add Two Numbers]/src/ListNode.java (100%) rename "\343\200\220002\343\200\221\343\200\220AddTwoNumbers\343\200\221/src/Solution.java" => [002][Add Two Numbers]/src/Solution.java (100%) rename "\343\200\220003\343\200\221\343\200\220LongestSubstringWithoutRepeatingCharacters\343\200\221/src/Solution.java" => [003][Longest Substring Without Repeating Characters]/src/Solution.java (100%) rename "\343\200\220004\343\200\221\343\200\220MedianofTwoSortedArrays\343\200\221/src/Solution.java" => [004][Median of Two Sorted Arrays]/src/Solution.java (100%) create mode 100644 [004][Median of Two Sorted Arrays]/src/Solution2.java rename "\343\200\220005\343\200\221\343\200\220LongestPalindromicSubstringTotal \343\200\221/src/Main.java" => [005][Longest Palindromic Substring Total]/src/Main.java (100%) rename "\343\200\220005\343\200\221\343\200\220LongestPalindromicSubstringTotal \343\200\221/src/Solution.java" => [005][Longest Palindromic Substring Total]/src/Solution.java (100%) rename "\343\200\220006\343\200\221\343\200\220ZigZagConversion\343\200\221/src/Solution.java" => [006][Zig Zag Conversion]/src/Solution.java (100%) rename "\343\200\220007\343\200\221\343\200\220ReverseInteger\343\200\221/src/Solution.java" => [007][Reverse Integer]/src/Solution.java (100%) rename "\343\200\220008\343\200\221\343\200\220StringToInteger (atoi)\343\200\221/src/Solution.java" => [008][String To Integer (atoi)]/src/Solution.java (100%) rename "\343\200\220009\343\200\221\343\200\220PalindromeNumber\343\200\221/src/Solution.java" => [009][Palindrome Number]/src/Solution.java (100%) rename "\343\200\220010\343\200\221\343\200\220RegularExpressionMatching\343\200\221/src/Main.java" => [010][Regular Expression Matching]/src/Main.java (100%) rename "\343\200\220010\343\200\221\343\200\220RegularExpressionMatching\343\200\221/src/Solution.java" => [010][Regular Expression Matching]/src/Solution.java (100%) rename "\343\200\220011\343\200\221\343\200\220ContainerWithMost Water\343\200\221/src/Solution.java" => [011][Container With Most Water]/src/Solution.java (100%) rename "\343\200\220012\343\200\221\343\200\220IntegerToRoman\343\200\221/src/Solution.java" => [012][Integer To Roman]/src/Solution.java (100%) rename "\343\200\220013\343\200\221\343\200\220RomarToInteger\343\200\221/src/Main.java" => [013][Romar To Integer]/src/Main.java (100%) rename "\343\200\220013\343\200\221\343\200\220RomarToInteger\343\200\221/src/Solution.java" => [013][Romar To Integer]/src/Solution.java (100%) rename "\343\200\220014\343\200\221\343\200\220LongestCommonPrefix\343\200\221/src/Solution.java" => [014][Longest Common Prefix]/src/Solution.java (100%) rename "\343\200\220015\343\200\221\343\200\2203Sum\343\200\221/src/Main.java" => [015][3 Sum]/src/Main.java (100%) rename "\343\200\220015\343\200\221\343\200\2203Sum\343\200\221/src/Solution.java" => [015][3 Sum]/src/Solution.java (100%) rename "\343\200\220016\343\200\221\343\200\2203SumClosest\343\200\221/src/Main.java" => [016][3 Sum Closest/src/Main.java (100%) rename "\343\200\220016\343\200\221\343\200\2203SumClosest\343\200\221/src/Solution.java" => [016][3 Sum Closest/src/Solution.java (100%) rename "\343\200\220017\343\200\221\343\200\220LetterCombinationsOfAPhonNumber \343\200\221/src/Solution.java" => [017][Letter Combinations Of A Phon Number/src/Solution.java (100%) rename "\343\200\220017\343\200\221\343\200\220LetterCombinationsOfAPhonNumber \343\200\221/src/phone-number.png" => [017][Letter Combinations Of A Phon Number/src/phone-number.png (100%) rename "\343\200\220018\343\200\221\343\200\2204Sum\343\200\221/src/Solution.java" => [018][4 Sum]/src/Solution.java (100%) rename "\343\200\220019\343\200\221\343\200\220RemoveNthNodeFromEndOfList\343\200\221/src/ListNode.java" => [019][Remove Nth Node From End Of List]/src/ListNode.java (100%) rename "\343\200\220019\343\200\221\343\200\220RemoveNthNodeFromEndOfList\343\200\221/src/Solution.java" => [019][Remove Nth Node From End Of List]/src/Solution.java (100%) rename "\343\200\220020\343\200\221\343\200\220ValidParentheses\343\200\221/src/Solution.java" => [020][Valid Parentheses]/src/Solution.java (100%) rename "\343\200\220021\343\200\221\343\200\220MergeTwoSortedLists\343\200\221/src/ListNode.java" => [021][Merge Two Sorted Lists]/src/ListNode.java (100%) rename "\343\200\220021\343\200\221\343\200\220MergeTwoSortedLists\343\200\221/src/Solution.java" => [021][Merge Two Sorted Lists]/src/Solution.java (100%) rename "\343\200\220022\343\200\221\343\200\220GenerateParentheses\343\200\221/src/Main.java" => [022][Generate Parentheses]/src/Main.java (100%) rename "\343\200\220022\343\200\221\343\200\220GenerateParentheses\343\200\221/src/Solution.java" => [022][Generate Parentheses]/src/Solution.java (100%) rename "\343\200\220023\343\200\221\343\200\220MergeKSortedLists\343\200\221/src/ListNode.java" => [023][Merge K Sorted Lists]/src/ListNode.java (100%) rename "\343\200\220023\343\200\221\343\200\220MergeKSortedLists\343\200\221/src/Solution.java" => [023][Merge K Sorted Lists]/src/Solution.java (100%) rename "\343\200\220024\343\200\221\343\200\220SwapNodesInPairs\343\200\221/src/ListNode.java" => [024][Swap Nodes In Pairs]/src/ListNode.java (100%) rename "\343\200\220024\343\200\221\343\200\220SwapNodesInPairs\343\200\221/src/Solution.java" => [024][Swap Nodes In Pairs]/src/Solution.java (100%) rename "\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221/src/ListNode.java" => [025][Reverse Nodes In K-Group]/src/ListNode.java (100%) rename "\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221/src/Main.java" => [025][Reverse Nodes In K-Group]/src/Main.java (100%) rename "\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221/src/Solution.java" => [025][Reverse Nodes In K-Group]/src/Solution.java (100%) rename "\343\200\220026\343\200\221\343\200\220RemoveDuplicatesfromSortedArray\343\200\221/src/Solution.java" => [026][Remove Duplicates from Sorted Array]/src/Solution.java (100%) rename "\343\200\220026\343\200\221\343\200\220RemoveDuplicatesfromSortedArray\343\200\221/src/Solution2.java" => [026][Remove Duplicates from Sorted Array]/src/Solution2.java (100%) rename "\343\200\220027\343\200\221\343\200\220RemoveElement\343\200\221/src/Solution.java" => [027][Remove Element]/src/Solution.java (100%) rename "\343\200\220028\343\200\221\343\200\220Implement-strStr()\343\200\221/src/Solution.java" => [028][Implement-strStr()]/src/Solution.java (100%) rename "\343\200\220029\343\200\221\343\200\220DivideTwoIntegers\343\200\221/src/Main.java" => [029][Divide Two Integers]/src/Main.java (100%) rename "\343\200\220029\343\200\221\343\200\220DivideTwoIntegers\343\200\221/src/Solution.java" => [029][Divide Two Integers]/src/Solution.java (100%) rename "\343\200\220030\343\200\221\343\200\220SubstringWithConcatenationOfAllWords\343\200\221/src/Solution.java" => [030][Substring With Concatenation Of All Words]/src/Solution.java (100%) rename "\343\200\220032\343\200\221\343\200\220LongestValidParentheses\343\200\221/src/Main.java" => [032][Longest Valid Parentheses]/src/Main.java (100%) rename "\343\200\220032\343\200\221\343\200\220LongestValidParentheses\343\200\221/src/Solution.java" => [032][Longest Valid Parentheses]/src/Solution.java (100%) rename "\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221/src/Main.java" => [033][Search In Rotated Sorted Array]/src/Main.java (100%) rename "\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221/src/Solution.java" => [033][Search In Rotated Sorted Array]/src/Solution.java (100%) rename "\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221/src/Solution2.java" => [033][Search In Rotated Sorted Array]/src/Solution2.java (100%) rename "\343\200\220034\343\200\221\343\200\220SearchForARange\343\200\221/src/Solution.java" => [034][Search For A Range]/src/Solution.java (100%) rename "\343\200\220035\343\200\221\343\200\220SearchInsertPosition\343\200\221/src/Solution.java" => [035][Search Insert Position]/src/Solution.java (100%) rename "\343\200\220036\343\200\221\343\200\220Valid Sudoku\343\200\221/src/Solution.java" => [036][Valid Sudoku]/src/Solution.java (100%) rename "\343\200\220036\343\200\221\343\200\220Valid Sudoku\343\200\221/src/sodoku.png" => [036][Valid Sudoku]/src/sodoku.png (100%) rename "\343\200\220037\343\200\221\343\200\220Sudoku Solver\343\200\221/src/Solution.java" => [037][Sudoku Solver]/src/Solution.java (100%) rename "\343\200\220038\343\200\221\343\200\220CountAndSay\343\200\221/src/Solution.java" => [038][Count And Say]/src/Solution.java (100%) rename "\343\200\220039\343\200\221\343\200\220Combination Sum\343\200\221/src/Solution.java" => [039][Combination Sum]/src/Solution.java (100%) rename "\343\200\220040\343\200\221\343\200\220Combination Sum II\343\200\221/src/Solution.java" => [040][Combination Sum II]/src/Solution.java (100%) rename "\343\200\220041\343\200\221\343\200\220First Missing Positive\343\200\221/src/Solution.java" => [041][First Missing Positive]/src/Solution.java (100%) rename "\343\200\220042\343\200\221\343\200\220Trapping Rain Water\343\200\221/src/Solution.java" => [042][Trapping Rain Water]/src/Solution.java (100%) rename "\343\200\220043\343\200\221\343\200\220Multiply Strings\343\200\221/src/Solution.java" => [043][Multiply Strings]/src/Solution.java (100%) rename "\343\200\220044\343\200\221\343\200\220Wildcard Matching\343\200\221/src/Solution.java" => [044][Wildcard Matching]/src/Solution.java (100%) rename "\343\200\220045\343\200\221\343\200\220Jump Game II\343\200\221/src/Solution.java" => [045][Jump Game II]/src/Solution.java (100%) rename "\343\200\220046\343\200\221\343\200\220Permutations\343\200\221/src/Solution.java" => [046][Permutations]/src/Solution.java (100%) rename "\343\200\220047\343\200\221\343\200\220Permutations II\343\200\221/src/Solution.java" => [047][Permutations II]/src/Solution.java (100%) rename "\343\200\220048\343\200\221\343\200\220Rotate Image\343\200\221/src/Solution.java" => [048][Rotate Image]/src/Solution.java (100%) rename "\343\200\220049\343\200\221\343\200\220Group Anagrams\343\200\221/src/Solution.java" => [049][Group Anagrams]/src/Solution.java (100%) rename "\343\200\220050\343\200\221\343\200\220Pow(x,n)\343\200\221/src/Solution.java" => [050][Pow(x,n)]/src/Solution.java (100%) rename "\343\200\220051\343\200\221\343\200\220N-Queens\343\200\221/src/Solution.java" => [051][N-Queens]/src/Solution.java (100%) rename "\343\200\220052\343\200\221\343\200\220N-Queens II\343\200\221/src/Solution.java" => [052][N-Queens II]/src/Solution.java (100%) rename "\343\200\220053\343\200\221\343\200\220MaximumSubarray\343\200\221/src/Solution.java" => [053][Maximum Subarray]/src/Solution.java (100%) rename "\343\200\220054\343\200\221\343\200\220SpiralMatrix\343\200\221/src/Solution.java" => [054][Spiral Matrix]/src/Solution.java (100%) rename "\343\200\220055\343\200\221\343\200\220Jump Game\343\200\221/src/Solution.java" => [055][Jump Game]/src/Solution.java (100%) rename "\343\200\220056\343\200\221\343\200\220MergeIntervals\343\200\221/src/Interval.java" => [056][Merge Intervals]/src/Interval.java (100%) rename "\343\200\220056\343\200\221\343\200\220MergeIntervals\343\200\221/src/Solution.java" => [056][Merge Intervals]/src/Solution.java (100%) rename "\343\200\220057\343\200\221\343\200\220InsertInterval\343\200\221/src/Interval.java" => [057][Insert Interval]/src/Interval.java (100%) rename "\343\200\220057\343\200\221\343\200\220InsertInterval\343\200\221/src/Solution.java" => [057][Insert Interval]/src/Solution.java (100%) rename "\343\200\220058\343\200\221\343\200\220LengthOfLastWord\343\200\221/src/Solution.java" => [058][Length Of Last Word]/src/Solution.java (100%) rename "\343\200\220059\343\200\221\343\200\220SpiralMatrixII\343\200\221/src/Solution.java" => [059][Spiral Matrix II]/src/Solution.java (100%) rename "\343\200\220060\343\200\221\343\200\220Permutation Sequence\343\200\221/src/Solution.java" => [060][Permutation Sequence]/src/Solution.java (100%) rename "\343\200\220061\343\200\221\343\200\220RotateList\343\200\221/src/ListNode.java" => [061][Rotate List]/src/ListNode.java (100%) rename "\343\200\220061\343\200\221\343\200\220RotateList\343\200\221/src/Solution.java" => [061][Rotate List]/src/Solution.java (100%) rename "\343\200\220062\343\200\221\343\200\220UniquePaths\343\200\221/src/Solution.java" => [062][Unique Paths]/src/Solution.java (100%) rename "\343\200\220063\343\200\221\343\200\220UniquePathsII\343\200\221/src/Solution.java" => [063][Unique Paths II]/src/Solution.java (100%) rename "\343\200\220064\343\200\221\343\200\220MinimumPathSum\343\200\221/src/Main.java" => [064][Minimum Path Sum]/src/Main.java (100%) rename "\343\200\220064\343\200\221\343\200\220MinimumPathSum\343\200\221/src/Solution.java" => [064][Minimum Path Sum]/src/Solution.java (100%) rename "\343\200\220066\343\200\221\343\200\220PlusOne\343\200\221/src/Solution.java" => [066][Plus One]/src/Solution.java (100%) rename "\343\200\220067\343\200\221\343\200\220AddBinary\343\200\221/src/Solution.java" => [067][Add Binary]/src/Solution.java (100%) rename "\343\200\220070\343\200\221\343\200\220ClimbingStairs\343\200\221/src/Solution.java" => [070][Climbing Stairs]/src/Solution.java (100%) rename "\343\200\220071\343\200\221\343\200\220Simplify Path\343\200\221/src/Solution.java" => [071][Simplify Path]/src/Solution.java (100%) rename "\343\200\220073\343\200\221\343\200\220SetMatrixZeroes\343\200\221/src/Solution.java" => [073][Set Matrix Zeroes]/src/Solution.java (100%) rename "\343\200\220074\343\200\221\343\200\220SearchA2DMatrix\343\200\221/src/Solution.java" => [074][Search A 2D Matrix]/src/Solution.java (100%) rename "\343\200\220075\343\200\221\343\200\220SortColors\343\200\221/src/Solution.java" => [075][Sort Colors]/src/Solution.java (100%) rename "\343\200\220077\343\200\221\343\200\220Combinations\343\200\221/src/Solution.java" => [077][Combinations]/src/Solution.java (100%) rename "\343\200\220078\343\200\221\343\200\220Subsets\343\200\221/src/Solution.java" => [078][Subsets]/src/Solution.java (100%) rename "\343\200\220079\343\200\221\343\200\220WordSearch\343\200\221/src/Main.java" => [079][Word Search]/src/Main.java (100%) rename "\343\200\220079\343\200\221\343\200\220WordSearch\343\200\221/src/Solution.java" => [079][Word Search]/src/Solution.java (100%) rename "\343\200\220080\343\200\221\343\200\220Remove Duplicates from Sorted Array II\343\200\221/src/Main.java" => [080][Remove Duplicates from Sorted Array II]/src/Main.java (100%) rename "\343\200\220080\343\200\221\343\200\220Remove Duplicates from Sorted Array II\343\200\221/src/Solution.java" => [080][Remove Duplicates from Sorted Array II]/src/Solution.java (100%) rename "\343\200\220080\343\200\221\343\200\220Remove Duplicates from Sorted Array II\343\200\221/src/Solution2.java" => [080][Remove Duplicates from Sorted Array II]/src/Solution2.java (100%) rename "\343\200\220081\343\200\221\343\200\220SearchInRotatedSortedArraII\343\200\221/src/Main.java" => [081][Search In Rotated Sorted Array II]/src/Main.java (62%) rename "\343\200\220081\343\200\221\343\200\220SearchInRotatedSortedArraII\343\200\221/src/Solution.java" => [081][Search In Rotated Sorted Array II]/src/Solution.java (100%) create mode 100644 [081][Search In Rotated Sorted Array II]/src/Solution2.java rename "\343\200\220082\343\200\221\343\200\220RemoveDuplicatesFromSortedListII\343\200\221/src/ListNode.java" => [082][Remove Duplicates From Sorted List II]/src/ListNode.java (100%) rename "\343\200\220082\343\200\221\343\200\220RemoveDuplicatesFromSortedListII\343\200\221/src/Solution.java" => [082][Remove Duplicates From Sorted List II]/src/Solution.java (100%) rename "\343\200\220083\343\200\221\343\200\220RemoveDuplicatesFromSortedList\343\200\221/src/ListNode.java" => [083][Remove Duplicates From Sorted List]/src/ListNode.java (100%) rename "\343\200\220083\343\200\221\343\200\220RemoveDuplicatesFromSortedList\343\200\221/src/Solution.java" => [083][Remove Duplicates From Sorted List]/src/Solution.java (100%) rename "\343\200\220086\343\200\221\343\200\220PartitionList\343\200\221/src/ListNode.java" => [086][Partition List]/src/ListNode.java (100%) rename "\343\200\220086\343\200\221\343\200\220PartitionList\343\200\221/src/Solution.java" => [086][Partition List]/src/Solution.java (100%) rename "\343\200\220088\343\200\221\343\200\220MergeSortedArray\343\200\221/src/Solution.java" => [088][Merge Sorted Array]/src/Solution.java (100%) rename "\343\200\220089\343\200\221\343\200\220GrayCode\343\200\221/src/Main.java" => [089][Gray Code]/src/Main.java (100%) rename "\343\200\220089\343\200\221\343\200\220GrayCode\343\200\221/src/Solution.java" => [089][Gray Code]/src/Solution.java (100%) rename "\343\200\220092\343\200\221\343\200\220ReverseLinkedListII\343\200\221/src/ListNode.java" => [092][Reverse Linked List II]/src/ListNode.java (100%) rename "\343\200\220092\343\200\221\343\200\220ReverseLinkedListII\343\200\221/src/Solution.java" => [092][Reverse Linked List II]/src/Solution.java (100%) rename "\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221/src/Main.java" => [094][Binary Tree Inorder Traversal]/src/Main.java (100%) rename "\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221/src/Solution.java" => [094][Binary Tree Inorder Traversal]/src/Solution.java (100%) rename "\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221/src/TreeNode.java" => [094][Binary Tree Inorder Traversal]/src/TreeNode.java (100%) rename "\343\200\220096\343\200\221\343\200\220UniqueBinarySearchTrees\343\200\221/src/Main.java" => [096][Unique Binary Search Trees]/src/Main.java (100%) rename "\343\200\220096\343\200\221\343\200\220UniqueBinarySearchTrees\343\200\221/src/Solution.java" => [096][Unique Binary Search Trees]/src/Solution.java (100%) rename "\343\200\220098\343\200\221\343\200\220ValidateBinarySearchTree\343\200\221/src/Solution.java" => [098][Validate Binary Search Tree]/src/Solution.java (100%) rename "\343\200\220098\343\200\221\343\200\220ValidateBinarySearchTree\343\200\221/src/TreeNode.java" => [098][Validate Binary Search Tree]/src/TreeNode.java (100%) rename "\343\200\220100\343\200\221\343\200\220SameTree\343\200\221/src/Solution.java" => [100][Same Tree]/src/Solution.java (100%) rename "\343\200\220100\343\200\221\343\200\220SameTree\343\200\221/src/TreeNode.java" => [100][Same Tree]/src/TreeNode.java (100%) rename "\343\200\220101\343\200\221\343\200\220SymmetricTree\343\200\221/src/Solution.java" => [101][Symmetric Tree]/src/Solution.java (100%) rename "\343\200\220101\343\200\221\343\200\220SymmetricTree\343\200\221/src/TreeNode.java" => [101][Symmetric Tree]/src/TreeNode.java (100%) rename "\343\200\220102\343\200\221\343\200\220BinaryTreeLevelOrderTraversal\343\200\221/src/Solution.java" => [102][Binary Tree Level Order Traversal]/src/Solution.java (100%) rename "\343\200\220102\343\200\221\343\200\220BinaryTreeLevelOrderTraversal\343\200\221/src/TreeNode.java" => [102][Binary Tree Level Order Traversal]/src/TreeNode.java (100%) rename "\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221/src/Main.java" => [103][Binary Tree Zigzag LevelOrder Traversal]/src/Main.java (100%) rename "\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221/src/Solution.java" => [103][Binary Tree Zigzag LevelOrder Traversal]/src/Solution.java (100%) rename "\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221/src/TreeNode.java" => [103][Binary Tree Zigzag LevelOrder Traversal]/src/TreeNode.java (100%) rename "\343\200\220104\343\200\221\343\200\220MaximumDepthOfBinaryTree\343\200\221/src/Solution.java" => [104][Maximum Depth Of Binary Tree]/src/Solution.java (100%) rename "\343\200\220104\343\200\221\343\200\220MaximumDepthOfBinaryTree\343\200\221/src/TreeNode.java" => [104][Maximum Depth Of Binary Tree]/src/TreeNode.java (100%) rename "\343\200\220105\343\200\221\343\200\220ConstructBinaryTreeFromPreorderAndInorderTraversal\343\200\221/src/Solution.java" => [105][Construct Binary Tree From Preorder And Inorder Traversal]/src/Solution.java (100%) rename "\343\200\220105\343\200\221\343\200\220ConstructBinaryTreeFromPreorderAndInorderTraversal\343\200\221/src/TreeNode.java" => [105][Construct Binary Tree From Preorder And Inorder Traversal]/src/TreeNode.java (100%) rename "\343\200\220106\343\200\221\343\200\220ConstructBinaryTreeFromInorderAndPostorderTraversal\343\200\221/src/Main.java" => [106][Construct Binary Tree From Inorder And Postorder Traversal]/src/Main.java (100%) rename "\343\200\220106\343\200\221\343\200\220ConstructBinaryTreeFromInorderAndPostorderTraversal\343\200\221/src/Solution.java" => [106][Construct Binary Tree From Inorder And Postorder Traversal]/src/Solution.java (100%) rename "\343\200\220106\343\200\221\343\200\220ConstructBinaryTreeFromInorderAndPostorderTraversal\343\200\221/src/TreeNode.java" => [106][Construct Binary Tree From Inorder And Postorder Traversal]/src/TreeNode.java (100%) rename "\343\200\220107\343\200\221\343\200\220BinaryTreeLevelOrderTraversalII\343\200\221/src/Solution.java" => [107][Binary Tree Level Order Traversa lII]/src/Solution.java (100%) rename "\343\200\220107\343\200\221\343\200\220BinaryTreeLevelOrderTraversalII\343\200\221/src/TreeNode.java" => [107][Binary Tree Level Order Traversa lII]/src/TreeNode.java (100%) rename "\343\200\220108\343\200\221\343\200\220ConvertSortedArrayToBinarySearchTree\343\200\221/src/Solution.java" => [108][Convert Sorted Array To Binary Search Tree]/src/Solution.java (100%) rename "\343\200\220108\343\200\221\343\200\220ConvertSortedArrayToBinarySearchTree\343\200\221/src/TreeNode.java" => [108][Convert Sorted Array To Binary Search Tree]/src/TreeNode.java (100%) rename "\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/src/ListNode.java" => [109][Convert Sorted List To Binary Search Tree]/src/ListNode.java (100%) rename "\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/src/Main.java" => [109][Convert Sorted List To Binary Search Tree]/src/Main.java (100%) rename "\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/src/Solution.java" => [109][Convert Sorted List To Binary Search Tree]/src/Solution.java (100%) rename "\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/src/TreeNode.java" => [109][Convert Sorted List To Binary Search Tree]/src/TreeNode.java (100%) rename "\343\200\220110\343\200\221\343\200\220BalancedBinaryTree\343\200\221/src/Solution.java" => [110][Balanced Binary Tree]/src/Solution.java (100%) rename "\343\200\220110\343\200\221\343\200\220BalancedBinaryTree\343\200\221/src/TreeNode.java" => [110][Balanced Binary Tree]/src/TreeNode.java (100%) rename "\343\200\220111\343\200\221\343\200\220MinimumDepthOfBinaryTree\343\200\221/src/Solution.java" => [111][Minimum Depth Of Binary Tree]/src/Solution.java (100%) rename "\343\200\220111\343\200\221\343\200\220MinimumDepthOfBinaryTree\343\200\221/src/TreeNode.java" => [111][Minimum Depth Of Binary Tree]/src/TreeNode.java (100%) rename "\343\200\220112\343\200\221\343\200\220PathSum\343\200\221/src/Solution.java" => [112][Path Sum]/src/Solution.java (100%) rename "\343\200\220112\343\200\221\343\200\220PathSum\343\200\221/src/TreeNode.java" => [112][Path Sum]/src/TreeNode.java (100%) rename "\343\200\220113\343\200\221\343\200\220PathSumII\343\200\221/src/Solution.java" => [113][Path Sum II]/src/Solution.java (100%) rename "\343\200\220113\343\200\221\343\200\220PathSumII\343\200\221/src/TreeNode.java" => [113][Path Sum II]/src/TreeNode.java (100%) rename "\343\200\220114\343\200\221\343\200\220FlattenBinaryTreeToLinkedList\343\200\221/src/Solution.java" => [114][Flatten Binary Tree To Linked List]/src/Solution.java (100%) rename "\343\200\220114\343\200\221\343\200\220FlattenBinaryTreeToLinkedList\343\200\221/src/TreeNode.java" => [114][Flatten Binary Tree To Linked List]/src/TreeNode.java (100%) rename "\343\200\220116\343\200\221\343\200\220PopulatingNextRightPointersinEachNode \343\200\221/src/Solution.java" => [116][Populating Next Right Pointersin Each Node]/src/Solution.java (100%) rename "\343\200\220116\343\200\221\343\200\220PopulatingNextRightPointersinEachNode \343\200\221/src/TreeLinkNode.java" => [116][Populating Next Right Pointersin Each Node]/src/TreeLinkNode.java (100%) rename "\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221/src/Main.java" => [117][Populating Next Right Pointers In Each Node II]/src/Main.java (100%) rename "\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221/src/Solution.java" => [117][Populating Next Right Pointers In Each Node II]/src/Solution.java (100%) rename "\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221/src/TreeLinkNode.java" => [117][Populating Next Right Pointers In Each Node II]/src/TreeLinkNode.java (100%) rename "\343\200\220118\343\200\221\343\200\220Pascal'sTriangle\343\200\221/src/Solution.java" => [118][Pascal's Triangle]/src/Solution.java (100%) rename "\343\200\220119\343\200\221\343\200\220Pascal'sTriangleII\343\200\221/src/Solution.java" => [119][Pascal's Triangle II]/src/Solution.java (100%) rename "\343\200\220120\343\200\221\343\200\220Triangle\343\200\221/src/Main.java" => [120][Triangle]/src/Main.java (100%) rename "\343\200\220120\343\200\221\343\200\220Triangle\343\200\221/src/Solution.java" => [120][Triangle]/src/Solution.java (100%) rename "\343\200\220121\343\200\221\343\200\220BestTimeToBuyAndSellStock\343\200\221/src/Solution.java" => [121][Best Time To Buy And Sell Stock]/src/Solution.java (100%) rename "\343\200\220122\343\200\221\343\200\220Best Time to Buy and Sell Stock II\343\200\221/src/Solution.java" => [122][Best Time to Buy and Sell Stock II]/src/Solution.java (100%) rename "\343\200\220122\343\200\221\343\200\220Best Time to Buy and Sell Stock II\343\200\221/src/Test.java" => [122][Best Time to Buy and Sell Stock II]/src/Test.java (100%) rename "\343\200\220124\346\234\252\343\200\221\343\200\220BinaryTreeMaximumPathSum\343\200\221/src/Solution.java" => [124][Binary Tree Maximum Path Sum]/src/Solution.java (100%) rename "\343\200\220124\346\234\252\343\200\221\343\200\220BinaryTreeMaximumPathSum\343\200\221/src/TreeNode.java" => [124][Binary Tree Maximum Path Sum]/src/TreeNode.java (100%) rename "\343\200\220125\343\200\221\343\200\220ValidPalindrome\343\200\221/src/Solution.java" => [125][Valid Palindrome]/src/Solution.java (100%) rename "\343\200\220127\346\234\252\343\200\221\343\200\220WordLadder\343\200\221/src/Solution.java" => [127][Word Ladder]/src/Solution.java (100%) rename "\343\200\220129\343\200\221\343\200\220SumRootToLeafNumbers\343\200\221/src/Solution.java" => [129][Sum Root To Leaf Numbers]/src/Solution.java (100%) rename "\343\200\220129\343\200\221\343\200\220SumRootToLeafNumbers\343\200\221/src/TreeNode.java" => [129][Sum Root To Leaf Numbers]/src/TreeNode.java (100%) rename "\343\200\220130\343\200\221\343\200\220SurroundedRegions\343\200\221/src/Main.java" => [130][Surrounded Regions]/src/Main.java (100%) rename "\343\200\220130\343\200\221\343\200\220SurroundedRegions\343\200\221/src/Solution.java" => [130][Surrounded Regions]/src/Solution.java (100%) rename "\343\200\220134\343\200\221\343\200\220GasStation\343\200\221/src/Solution.java" => [134][Gas Station]/src/Solution.java (100%) rename "\343\200\220136\343\200\221\343\200\220SingleNumber\343\200\221/src/Solution.java" => [136][Single Number]/src/Solution.java (100%) rename "\343\200\220137\343\200\221\343\200\220SingleNumberII\343\200\221/src/Solution.java" => [137][Single Number II]/src/Solution.java (100%) rename "\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/src/Main.java" => [138][Copy List With Random Pointer]/src/Main.java (100%) rename "\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/src/RandomListNode.java" => [138][Copy List With Random Pointer]/src/RandomListNode.java (100%) rename "\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/src/Solution.java" => [138][Copy List With Random Pointer]/src/Solution.java (100%) rename "\343\200\220139\343\200\221\343\200\220WordBreak\343\200\221/src/Main.java" => [139][Word Break]/src/Main.java (100%) rename "\343\200\220139\343\200\221\343\200\220WordBreak\343\200\221/src/Solution.java" => [139][Word Break]/src/Solution.java (100%) rename "\343\200\220141\343\200\221\343\200\220LinkedListCycle\343\200\221/src/ListNode.java" => [141][Linked List Cycle]/src/ListNode.java (100%) rename "\343\200\220141\343\200\221\343\200\220LinkedListCycle\343\200\221/src/Solution.java" => [141][Linked List Cycle]/src/Solution.java (100%) rename "\343\200\220142\343\200\221\343\200\220LinkedListCycleII\343\200\221/src/ListNode.java" => [142][Linked List Cycle II]/src/ListNode.java (100%) rename "\343\200\220142\343\200\221\343\200\220LinkedListCycleII\343\200\221/src/Solution.java" => [142][Linked List Cycle II]/src/Solution.java (100%) rename "\343\200\220143\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/src/RandomListNode.java" => [143][Copy List With Random Pointer]/src/RandomListNode.java (100%) rename "\343\200\220143\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/src/Solution.java" => [143][Copy List With Random Pointer]/src/Solution.java (100%) rename "\343\200\220144\343\200\221\343\200\220BinaryTreePreorderTraversal\343\200\221/src/Solution.java" => [144][Binary Tree Preorder Traversal]/src/Solution.java (100%) rename "\343\200\220144\343\200\221\343\200\220BinaryTreePreorderTraversal\343\200\221/src/TreeNode.java" => [144][Binary Tree Preorder Traversal]/src/TreeNode.java (100%) rename "\343\200\220145\343\200\221\343\200\220BinaryTreePostorderTraversal\343\200\221/src/Solution.java" => [145][Binary Tree Postorder Traversal]/src/Solution.java (100%) rename "\343\200\220145\343\200\221\343\200\220BinaryTreePostorderTraversal\343\200\221/src/TreeNode.java" => [145][Binary Tree Postorder Traversal]/src/TreeNode.java (100%) rename "\343\200\220147\343\200\221\343\200\220InsertionSortList\343\200\221/src/ListNode.java" => [147][Insertion Sort List]/src/ListNode.java (100%) rename "\343\200\220147\343\200\221\343\200\220InsertionSortList\343\200\221/src/Solution.java" => [147][Insertion Sort List]/src/Solution.java (100%) rename "\343\200\220150\343\200\221\343\200\220EvaluateReversePolishNotation\343\200\221/src/Main.java" => [150][Evaluate Reverse Polish Notation]/src/Main.java (100%) rename "\343\200\220150\343\200\221\343\200\220EvaluateReversePolishNotation\343\200\221/src/Solution.java" => [150][Evaluate Reverse Polish Notation]/src/Solution.java (100%) rename "\343\200\220151\343\200\221\343\200\220ReverseWordsInAString\343\200\221/src/Main.java" => [151][Reverse Words In A String]/src/Main.java (100%) rename "\343\200\220151\343\200\221\343\200\220ReverseWordsInAString\343\200\221/src/Solution.java" => [151][Reverse Words In A String]/src/Solution.java (100%) rename "\343\200\220152\343\200\221\343\200\220MaximumProductSubarray\343\200\221/src/Main.java" => [152][Maximum Product Subarray]/src/Main.java (100%) rename "\343\200\220152\343\200\221\343\200\220MaximumProductSubarray\343\200\221/src/Solution.java" => [152][Maximum Product Subarray]/src/Solution.java (100%) rename "\343\200\220153\343\200\221\343\200\220FindMinimumInRotatedSortedArray\343\200\221/src/Main.java" => [153][Find Minimum In Rotated Sorted Array]/src/Main.java (100%) rename "\343\200\220153\343\200\221\343\200\220FindMinimumInRotatedSortedArray\343\200\221/src/Solution.java" => [153][Find Minimum In Rotated Sorted Array]/src/Solution.java (100%) rename "\343\200\220154\343\200\221\343\200\220FindMinimumInRotatedSortedArrayII\343\200\221/src/Main.java" => [154][Find Minimum In Rotated Sorted Array II]/src/Main.java (100%) rename "\343\200\220154\343\200\221\343\200\220FindMinimumInRotatedSortedArrayII\343\200\221/src/Solution.java" => [154][Find Minimum In Rotated Sorted Array II]/src/Solution.java (100%) rename "\343\200\220155\343\200\221\343\200\220MinStack\343\200\221/src/MinStack.java" => [155][Min Stack]/src/MinStack.java (100%) rename "\343\200\220162\346\234\252\343\200\221\343\200\220FindPeakElement\343\200\221/src/Solution.java" => [162][Find Peak Element]/src/Solution.java (100%) rename "\343\200\220167\343\200\221\343\200\220Two Sum II - Input array is sorted\343\200\221/src/Solution.java" => [167][Two Sum II - Input array is sorted]/src/Solution.java (100%) rename "\343\200\220191\343\200\221\343\200\220NumberOf1Bits\343\200\221/src/Main.java" => [191][Number Of 1 Bits]/src/Main.java (100%) rename "\343\200\220191\343\200\221\343\200\220NumberOf1Bits\343\200\221/src/Solution.java" => [191][Number Of 1 Bits]/src/Solution.java (100%) rename "\343\200\220198\343\200\221\343\200\220HouseRobber\343\200\221/src/Main.java" => [198][House Robber]/src/Main.java (100%) rename "\343\200\220198\343\200\221\343\200\220HouseRobber\343\200\221/src/Solution.java" => [198][House Robber]/src/Solution.java (100%) rename "\343\200\220199\343\200\221\343\200\220BinaryTreeRightSideView\343\200\221/src/Solution.java" => [199][Binary Tree Right Side View]/src/Solution.java (100%) rename "\343\200\220199\343\200\221\343\200\220BinaryTreeRightSideView\343\200\221/src/TreeNode.java" => [199][Binary Tree Right Side View]/src/TreeNode.java (100%) rename "\343\200\220200\343\200\221\343\200\220NumberOfIslands\343\200\221/src/Solution.java" => [200][Number Of Islands]/src/Solution.java (100%) rename "\343\200\220201\343\200\221\343\200\220BitwiseANDOfNumbersRange\343\200\221/src/Solution.java" => [201][Bitwise AND Of Numbers Range]/src/Solution.java (100%) rename "\343\200\220202\343\200\221\343\200\220HappyNumber \343\200\221/src/Main.java" => [202][Happy Number ]/src/Main.java (100%) rename "\343\200\220202\343\200\221\343\200\220HappyNumber \343\200\221/src/Solution.java" => [202][Happy Number ]/src/Solution.java (100%) rename "\343\200\220203\343\200\221\343\200\220RemoveLinkedList Elements\343\200\221/src/ListNode.java" => [203][Remove Linked List Elements]/src/ListNode.java (100%) rename "\343\200\220203\343\200\221\343\200\220RemoveLinkedList Elements\343\200\221/src/Solution.java" => [203][Remove Linked List Elements]/src/Solution.java (100%) rename "\343\200\220204\343\200\221\343\200\220CountPrimes\343\200\221/src/Solution.java" => [204][Count Primes]/src/Solution.java (100%) rename "\343\200\220205\343\200\221\343\200\220IsomorphicStrings\343\200\221/src/Solution.java" => [205][Isomorphic Strings]/src/Solution.java (100%) rename "\343\200\220206\343\200\221\343\200\220ReverseLinkedList\343\200\221/src/ListNode.java" => [206][Reverse Linked List]/src/ListNode.java (100%) rename "\343\200\220206\343\200\221\343\200\220ReverseLinkedList\343\200\221/src/Main.java" => [206][Reverse Linked List]/src/Main.java (100%) rename "\343\200\220206\343\200\221\343\200\220ReverseLinkedList\343\200\221/src/Solution.java" => [206][Reverse Linked List]/src/Solution.java (100%) rename "\343\200\220215\343\200\221\343\200\220KthLargestElementInAnArray\343\200\221/src/Main.java" => [215][Kth Largest Element In An Array]/src/Main.java (100%) rename "\343\200\220215\343\200\221\343\200\220KthLargestElementInAnArray\343\200\221/src/Solution.java" => [215][Kth Largest Element In An Array]/src/Solution.java (100%) rename "\343\200\220216\343\200\221\343\200\220CombinationSumIII\343\200\221/src/Main.java" => [216][Combination Sum III]/src/Main.java (100%) rename "\343\200\220216\343\200\221\343\200\220CombinationSumIII\343\200\221/src/Solution.java" => [216][Combination Sum III]/src/Solution.java (100%) rename "\343\200\220217\343\200\221\343\200\220ContainsDuplicate \343\200\221/src/Main.java" => [217][Contains Duplicate ]/src/Main.java (100%) rename "\343\200\220217\343\200\221\343\200\220ContainsDuplicate \343\200\221/src/Solution.java" => [217][Contains Duplicate ]/src/Solution.java (100%) rename "\343\200\220219\343\200\221\343\200\220ContainsDuplicateII\343\200\221/src/Solution.java" => [219][Contains Duplicate II]/src/Solution.java (100%) rename "\343\200\220223\343\200\221\343\200\220RectangleArea\343\200\221/src/Main.java" => [223][Rectangle Area]/src/Main.java (100%) rename "\343\200\220223\343\200\221\343\200\220RectangleArea\343\200\221/src/Solution.java" => [223][Rectangle Area]/src/Solution.java (100%) rename "\343\200\220225\343\200\221\343\200\220ImplementStackUsingQueues\343\200\221/src/MyStack.java" => [225][Implement Stack Using Queues]/src/MyStack.java (100%) rename "\343\200\220226\343\200\221\343\200\220InvertBinaryTree \343\200\221/src/Solution.java" => [226][Invert Binary Tree]/src/Solution.java (100%) rename "\343\200\220226\343\200\221\343\200\220InvertBinaryTree \343\200\221/src/TreeNode.java" => [226][Invert Binary Tree]/src/TreeNode.java (100%) rename "\343\200\220231\343\200\221\343\200\220Power of Two\343\200\221/src/Solution.java" => [231][Power of Two]/src/Solution.java (100%) rename "\343\200\220231\343\200\221\343\200\220Power of Two\343\200\221/src/Test.java" => [231][Power of Two]/src/Test.java (100%) rename "\343\200\220232\343\200\221\343\200\220Implement Queue using Stacks\343\200\221/src/MyQueue.java" => [232][Implement Queue using Stacks]/src/MyQueue.java (100%) rename "\343\200\220232\343\200\221\343\200\220Implement Queue using Stacks\343\200\221/src/Test.java" => [232][Implement Queue using Stacks]/src/Test.java (100%) rename "\343\200\220234\343\200\221\343\200\220Palindrome Linked List\343\200\221/src/ListNode.java" => [234][Palindrome Linked List]/src/ListNode.java (100%) rename "\343\200\220234\343\200\221\343\200\220Palindrome Linked List\343\200\221/src/Solution.java" => [234][Palindrome Linked List]/src/Solution.java (100%) rename "\343\200\220234\343\200\221\343\200\220Palindrome Linked List\343\200\221/src/Solution2.java" => [234][Palindrome Linked List]/src/Solution2.java (100%) rename "\343\200\220234\343\200\221\343\200\220Palindrome Linked List\343\200\221/src/Test.java" => [234][Palindrome Linked List]/src/Test.java (100%) rename "\343\200\220235\343\200\221\343\200\220Lowest Common Ancestor of a Binary Search Tree\343\200\221/src/Solution.java" => [235][Lowest Common Ancestor of a Binary Search Tree]/src/Solution.java (100%) rename "\343\200\220235\343\200\221\343\200\220Lowest Common Ancestor of a Binary Search Tree\343\200\221/src/TreeNode.java" => [235][Lowest Common Ancestor of a Binary Search Tree]/src/TreeNode.java (100%) rename "\343\200\220237\343\200\221\343\200\220Delete Node in a Linked List\343\200\221/src/ListNode.java" => [237][Delete Node in a Linked List]/src/ListNode.java (100%) rename "\343\200\220237\343\200\221\343\200\220Delete Node in a Linked List\343\200\221/src/Solution.java" => [237][Delete Node in a Linked List]/src/Solution.java (100%) rename "\343\200\220237\343\200\221\343\200\220Delete Node in a Linked List\343\200\221/src/Test.java" => [237][Delete Node in a Linked List]/src/Test.java (100%) rename "\343\200\220242\343\200\221\343\200\220Valid Anagram\343\200\221/src/Solution.java" => [242][Valid Anagram]/src/Solution.java (100%) rename "\343\200\220242\343\200\221\343\200\220Valid Anagram\343\200\221/src/Test.java" => [242][Valid Anagram]/src/Test.java (100%) rename "\343\200\220257\343\200\221\343\200\220Binary Tree Paths\343\200\221/src/Solution.java" => [257][Binary Tree Paths]/src/Solution.java (100%) rename "\343\200\220257\343\200\221\343\200\220Binary Tree Paths\343\200\221/src/Test.java" => [257][Binary Tree Paths]/src/Test.java (100%) rename "\343\200\220257\343\200\221\343\200\220Binary Tree Paths\343\200\221/src/TreeNode.java" => [257][Binary Tree Paths]/src/TreeNode.java (100%) rename "\343\200\220258\343\200\221\343\200\220Add Digits\343\200\221/src/Solution.java" => [258][Add Digits]/src/Solution.java (100%) rename "\343\200\220258\343\200\221\343\200\220Add Digits\343\200\221/src/Test.java" => [258][Add Digits]/src/Test.java (100%) rename "\343\200\220263\343\200\221\343\200\220Ugly Number\343\200\221/src/Solution.java" => [263][Ugly Number]/src/Solution.java (100%) rename "\343\200\220263\343\200\221\343\200\220Ugly Number\343\200\221/src/Test.java" => [263][Ugly Number]/src/Test.java (100%) rename "\343\200\220268\343\200\221\343\200\220Missing Number\343\200\221/src/Solution.java" => [268][Missing Number]/src/Solution.java (100%) rename "\343\200\220268\343\200\221\343\200\220Missing Number\343\200\221/src/Test.java" => [268][Missing Number]/src/Test.java (100%) rename "\343\200\220278\343\200\221\343\200\220First Bad Version\343\200\221/src/Solution.java" => [278][First Bad Version]/src/Solution.java (100%) rename "\343\200\220278\343\200\221\343\200\220First Bad Version\343\200\221/src/Test.java" => [278][First Bad Version]/src/Test.java (100%) rename "\343\200\220278\343\200\221\343\200\220First Bad Version\343\200\221/src/VersionControl.java" => [278][First Bad Version]/src/VersionControl.java (100%) rename "\343\200\220283\343\200\221\343\200\220Move Zeroes\343\200\221/src/Solution.java" => [283][Move Zeroes]/src/Solution.java (100%) rename "\343\200\220283\343\200\221\343\200\220Move Zeroes\343\200\221/src/Test.java" => [283][Move Zeroes]/src/Test.java (100%) rename "\343\200\220290\343\200\221\343\200\220Word Pattern\343\200\221/src/Solution.java" => [290][Word Pattern]/src/Solution.java (100%) rename "\343\200\220290\343\200\221\343\200\220Word Pattern\343\200\221/src/Test.java" => [290][Word Pattern]/src/Test.java (100%) rename "\343\200\220303\343\200\221\343\200\220Range Sum Query - Immutable\343\200\221/src/NumArray.java" => [303][Range Sum Query - Immutable]/src/NumArray.java (100%) rename "\343\200\220303\343\200\221\343\200\220Range Sum Query - Immutable\343\200\221/src/Test.java" => [303][Range Sum Query - Immutable]/src/Test.java (100%) rename "\343\200\220326\343\200\221\343\200\220Power of Three\343\200\221/src/Solution.java" => [326][Power of Three]/src/Solution.java (100%) rename "\343\200\220326\343\200\221\343\200\220Power of Three\343\200\221/src/Test.java" => [326][Power of Three]/src/Test.java (100%) rename "\343\200\220342\343\200\221\343\200\220Power of Four\343\200\221/src/Solution.java" => [342][Power of Four]/src/Solution.java (100%) rename "\343\200\220344\343\200\221\343\200\220Reverse String\343\200\221/src/Solution.java" => [344][Reverse String]/src/Solution.java (100%) delete mode 100644 "out/production/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221/Solution$Node.class" delete mode 100644 "out/production/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220005\343\200\221\343\200\220LongestPalindromicSubstringTotal \343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220005\343\200\221\343\200\220LongestPalindromicSubstringTotal \343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220010\343\200\221\343\200\220RegularExpressionMatching\343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220010\343\200\221\343\200\220RegularExpressionMatching\343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220016\343\200\221\343\200\2203SumClosest\343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220016\343\200\221\343\200\2203SumClosest\343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220022\343\200\221\343\200\220GenerateParentheses\343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220022\343\200\221\343\200\220GenerateParentheses\343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221/ListNode.class" delete mode 100644 "out/production/\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220029\343\200\221\343\200\220DivideTwoIntegers\343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220029\343\200\221\343\200\220DivideTwoIntegers\343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220064\343\200\221\343\200\220MinimumPathSum\343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220064\343\200\221\343\200\220MinimumPathSum\343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220079\343\200\221\343\200\220WordSearch\343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220079\343\200\221\343\200\220WordSearch\343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220081\343\200\221\343\200\220SearchInRotatedSortedArraII\343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220081\343\200\221\343\200\220SearchInRotatedSortedArraII\343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220089\343\200\221\343\200\220GrayCode\343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220089\343\200\221\343\200\220GrayCode\343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221/TreeNode.class" delete mode 100644 "out/production/\343\200\220096\343\200\221\343\200\220UniqueBinarySearchTrees\343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220096\343\200\221\343\200\220UniqueBinarySearchTrees\343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221/TreeNode.class" delete mode 100644 "out/production/\343\200\220106\343\200\221\343\200\220ConstructBinaryTreeFromInorderAndPostorderTraversal\343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220106\343\200\221\343\200\220ConstructBinaryTreeFromInorderAndPostorderTraversal\343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220106\343\200\221\343\200\220ConstructBinaryTreeFromInorderAndPostorderTraversal\343\200\221/TreeNode.class" delete mode 100644 "out/production/\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/ListNode.class" delete mode 100644 "out/production/\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/TreeNode.class" delete mode 100644 "out/production/\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221/TreeLinkNode.class" delete mode 100644 "out/production/\343\200\220120\343\200\221\343\200\220Triangle\343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220120\343\200\221\343\200\220Triangle\343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220130\343\200\221\343\200\220SurroundedRegions\343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220130\343\200\221\343\200\220SurroundedRegions\343\200\221/Solution$Coordinate.class" delete mode 100644 "out/production/\343\200\220130\343\200\221\343\200\220SurroundedRegions\343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/RandomListNode.class" delete mode 100644 "out/production/\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220139\343\200\221\343\200\220WordBreak\343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220139\343\200\221\343\200\220WordBreak\343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220150\343\200\221\343\200\220EvaluateReversePolishNotation\343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220150\343\200\221\343\200\220EvaluateReversePolishNotation\343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220151\343\200\221\343\200\220ReverseWordsInAString\343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220151\343\200\221\343\200\220ReverseWordsInAString\343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220152\343\200\221\343\200\220MaximumProductSubarray\343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220152\343\200\221\343\200\220MaximumProductSubarray\343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220154\343\200\221\343\200\220FindMinimumInRotatedSortedArrayII\343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220154\343\200\221\343\200\220FindMinimumInRotatedSortedArrayII\343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220191\343\200\221\343\200\220NumberOf1Bits\343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220191\343\200\221\343\200\220NumberOf1Bits\343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220198\343\200\221\343\200\220HouseRobber\343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220198\343\200\221\343\200\220HouseRobber\343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220202\343\200\221\343\200\220HappyNumber \343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220215\343\200\221\343\200\220KthLargestElementInAnArray\343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220215\343\200\221\343\200\220KthLargestElementInAnArray\343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220216\343\200\221\343\200\220CombinationSumIII\343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220216\343\200\221\343\200\220CombinationSumIII\343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220217\343\200\221\343\200\220ContainsDuplicate \343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220217\343\200\221\343\200\220ContainsDuplicate \343\200\221/Solution.class" delete mode 100644 "out/production/\343\200\220223\343\200\221\343\200\220RectangleArea\343\200\221/Main.class" delete mode 100644 "out/production/\343\200\220223\343\200\221\343\200\220RectangleArea\343\200\221/Solution.class" create mode 100644 pom.xml delete mode 100644 "\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221.iml" delete mode 100644 "\343\200\220002\343\200\221\343\200\220AddTwoNumbers\343\200\221/\343\200\220002\343\200\221\343\200\220AddTwoNumbers\343\200\221.iml" delete mode 100644 "\343\200\220003\343\200\221\343\200\220LongestSubstringWithoutRepeatingCharacters\343\200\221/\343\200\220003\343\200\221\343\200\220LongestSubstringWithoutRepeatingCharacters\343\200\221.iml" delete mode 100644 "\343\200\220004\343\200\221\343\200\220MedianofTwoSortedArrays\343\200\221/\343\200\220004\343\200\221\343\200\220MedianofTwoSortedArrays\343\200\221.iml" delete mode 100644 "\343\200\220005\343\200\221\343\200\220LongestPalindromicSubstringTotal \343\200\221/\343\200\220005\343\200\221\343\200\220LongestPalindromicSubstringTotal \343\200\221.iml" delete mode 100644 "\343\200\220006\343\200\221\343\200\220ZigZagConversion\343\200\221/\343\200\220006\343\200\221\343\200\220ZigZagConversion\343\200\221.iml" delete mode 100644 "\343\200\220007\343\200\221\343\200\220ReverseInteger\343\200\221/\343\200\220007\343\200\221\343\200\220ReverseInteger\343\200\221.iml" delete mode 100644 "\343\200\220008\343\200\221\343\200\220StringToInteger (atoi)\343\200\221/\343\200\220008\343\200\221\343\200\220StringToInteger (atoi)\343\200\221.iml" delete mode 100644 "\343\200\220009\343\200\221\343\200\220PalindromeNumber\343\200\221/\343\200\220009\343\200\221\343\200\220PalindromeNumber\343\200\221.iml" delete mode 100644 "\343\200\220010\343\200\221\343\200\220RegularExpressionMatching\343\200\221/\343\200\220010\343\200\221\343\200\220RegularExpressionMatching\343\200\221.iml" delete mode 100644 "\343\200\220011\343\200\221\343\200\220ContainerWithMost Water\343\200\221/\343\200\220011\343\200\221\343\200\220ContainerWithMost Water\343\200\221.iml" delete mode 100644 "\343\200\220012\343\200\221\343\200\220IntegerToRoman\343\200\221/\343\200\220012\343\200\221\343\200\220IntegerToRoman\343\200\221.iml" delete mode 100644 "\343\200\220013\343\200\221\343\200\220RomarToInteger\343\200\221/\343\200\220013\343\200\221\343\200\220RomarToInteger\343\200\221.iml" delete mode 100644 "\343\200\220014\343\200\221\343\200\220LongestCommonPrefix\343\200\221/\343\200\220014\343\200\221\343\200\220LongestCommonPrefix\343\200\221.iml" delete mode 100644 "\343\200\220015\343\200\221\343\200\2203Sum\343\200\221/\343\200\220015\343\200\221\343\200\2203Sum\343\200\221.iml" delete mode 100644 "\343\200\220016\343\200\221\343\200\2203SumClosest\343\200\221/\343\200\220016\343\200\221\343\200\2203SumClosest\343\200\221.iml" delete mode 100644 "\343\200\220017\343\200\221\343\200\220LetterCombinationsOfAPhonNumber \343\200\221/\343\200\220017\343\200\221\343\200\220LetterCombinationsOfAPhonNumber \343\200\221.iml" delete mode 100644 "\343\200\220018\343\200\221\343\200\2204Sum\343\200\221/\343\200\220018\343\200\221\343\200\2204Sum\343\200\221.iml" delete mode 100644 "\343\200\220019\343\200\221\343\200\220RemoveNthNodeFromEndOfList\343\200\221/\343\200\220019\343\200\221\343\200\220RemoveNthNodeFromEndOfList\343\200\221.iml" delete mode 100644 "\343\200\220020\343\200\221\343\200\220ValidParentheses\343\200\221/\343\200\220020\343\200\221\343\200\220ValidParentheses\343\200\221.iml" delete mode 100644 "\343\200\220021\343\200\221\343\200\220MergeTwoSortedLists\343\200\221/\343\200\220021\343\200\221\343\200\220MergeTwoSortedLists\343\200\221.iml" delete mode 100644 "\343\200\220022\343\200\221\343\200\220GenerateParentheses\343\200\221/\343\200\220022\343\200\221\343\200\220GenerateParentheses\343\200\221.iml" delete mode 100644 "\343\200\220023\343\200\221\343\200\220MergeKSortedLists\343\200\221/\343\200\220023\343\200\221\343\200\220MergeKSortedLists\343\200\221.iml" delete mode 100644 "\343\200\220024\343\200\221\343\200\220SwapNodesInPairs\343\200\221/\343\200\220024\343\200\221\343\200\220SwapNodesInPairs\343\200\221.iml" delete mode 100644 "\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221/\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221.iml" delete mode 100644 "\343\200\220026\343\200\221\343\200\220RemoveDuplicatesfromSortedArray\343\200\221/\343\200\220026\343\200\221\343\200\220RemoveDuplicatesfromSortedArray\343\200\221.iml" delete mode 100644 "\343\200\220027\343\200\221\343\200\220RemoveElement\343\200\221/\343\200\220027\343\200\221\343\200\220RemoveElement\343\200\221.iml" delete mode 100644 "\343\200\220028\343\200\221\343\200\220Implement-strStr()\343\200\221/\343\200\220028\343\200\221\343\200\220Implement-strStr()\343\200\221.iml" delete mode 100644 "\343\200\220029\343\200\221\343\200\220DivideTwoIntegers\343\200\221/\343\200\220029\343\200\221\343\200\220DivideTwoIntegers\343\200\221.iml" delete mode 100644 "\343\200\220030\343\200\221\343\200\220SubstringWithConcatenationOfAllWords\343\200\221/\343\200\220030\343\200\221\343\200\220SubstringWithConcatenationOfAllWords\343\200\221.iml" delete mode 100644 "\343\200\220032\343\200\221\343\200\220LongestValidParentheses\343\200\221/\343\200\220032\343\200\221\343\200\220LongestValidParentheses\343\200\221.iml" delete mode 100644 "\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221/\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221.iml" delete mode 100644 "\343\200\220034\343\200\221\343\200\220SearchForARange\343\200\221/\343\200\220034\343\200\221\343\200\220SearchForARange\343\200\221.iml" delete mode 100644 "\343\200\220035\343\200\221\343\200\220SearchInsertPosition\343\200\221/\343\200\220035\343\200\221\343\200\220SearchInsertPosition\343\200\221.iml" delete mode 100644 "\343\200\220036\343\200\221\343\200\220Valid Sudoku\343\200\221/\343\200\220036\343\200\221\343\200\220Valid Sudoku\343\200\221.iml" delete mode 100644 "\343\200\220037\343\200\221\343\200\220Sudoku Solver\343\200\221/\343\200\220037\343\200\221\343\200\220Sudoku Solver\343\200\221.iml" delete mode 100644 "\343\200\220038\343\200\221\343\200\220CountAndSay\343\200\221/\343\200\220038\343\200\221\343\200\220CountAndSay\343\200\221.iml" delete mode 100644 "\343\200\220039\343\200\221\343\200\220Combination Sum\343\200\221/\343\200\220039\343\200\221\343\200\220Combination Sum\343\200\221.iml" delete mode 100644 "\343\200\220040\343\200\221\343\200\220Combination Sum II\343\200\221/\343\200\220040\343\200\221\343\200\220Combination Sum II\343\200\221.iml" delete mode 100644 "\343\200\220041\343\200\221\343\200\220First Missing Positive\343\200\221/\343\200\220041\343\200\221\343\200\220First Missing Positive\343\200\221.iml" delete mode 100644 "\343\200\220042\343\200\221\343\200\220Trapping Rain Water\343\200\221/\343\200\220042\343\200\221\343\200\220Trapping Rain Water\343\200\221.iml" delete mode 100644 "\343\200\220043\343\200\221\343\200\220Multiply Strings\343\200\221/\343\200\220043\343\200\221\343\200\220Multiply Strings\343\200\221.iml" delete mode 100644 "\343\200\220044\343\200\221\343\200\220Wildcard Matching\343\200\221/\343\200\220044\343\200\221\343\200\220Wildcard Matching\343\200\221.iml" delete mode 100644 "\343\200\220045\343\200\221\343\200\220Jump Game II\343\200\221/\343\200\220045\343\200\221\343\200\220Jump Game II\343\200\221.iml" delete mode 100644 "\343\200\220046\343\200\221\343\200\220Permutations\343\200\221/\343\200\220046\343\200\221\343\200\220Permutations\343\200\221.iml" delete mode 100644 "\343\200\220047\343\200\221\343\200\220Permutations II\343\200\221/\343\200\220047\343\200\221\343\200\220Permutations II\343\200\221.iml" delete mode 100644 "\343\200\220048\343\200\221\343\200\220Rotate Image\343\200\221/\343\200\220048\343\200\221\343\200\220Rotate Image\343\200\221.iml" delete mode 100644 "\343\200\220049\343\200\221\343\200\220Group Anagrams\343\200\221/\343\200\220049\343\200\221\343\200\220Group Anagrams\343\200\221.iml" delete mode 100644 "\343\200\220050\343\200\221\343\200\220Pow(x,n)\343\200\221/\343\200\220050\343\200\221\343\200\220Pow(x,n)\343\200\221.iml" delete mode 100644 "\343\200\220051\343\200\221\343\200\220N-Queens\343\200\221/\343\200\220051\343\200\221\343\200\220N-Queens\343\200\221.iml" delete mode 100644 "\343\200\220052\343\200\221\343\200\220N-Queens II\343\200\221/\343\200\220052\343\200\221\343\200\220N-Queens II\343\200\221.iml" delete mode 100644 "\343\200\220053\343\200\221\343\200\220MaximumSubarray\343\200\221/\343\200\220053\343\200\221\343\200\220MaximumSubarray\343\200\221.iml" delete mode 100644 "\343\200\220054\343\200\221\343\200\220SpiralMatrix\343\200\221/\343\200\220054\343\200\221\343\200\220SpiralMatrix\343\200\221.iml" delete mode 100644 "\343\200\220055\343\200\221\343\200\220Jump Game\343\200\221/\343\200\220055\343\200\221\343\200\220Jump Game\343\200\221.iml" delete mode 100644 "\343\200\220056\343\200\221\343\200\220MergeIntervals\343\200\221/\343\200\220056\343\200\221\343\200\220MergeIntervals\343\200\221.iml" delete mode 100644 "\343\200\220057\343\200\221\343\200\220InsertInterval\343\200\221/\343\200\220057\343\200\221\343\200\220InsertInterval\343\200\221.iml" delete mode 100644 "\343\200\220058\343\200\221\343\200\220LengthOfLastWord\343\200\221/\343\200\220058\343\200\221\343\200\220LengthOfLastWord\343\200\221.iml" delete mode 100644 "\343\200\220059\343\200\221\343\200\220SpiralMatrixII\343\200\221/\343\200\220059\343\200\221\343\200\220SpiralMatrixII\343\200\221.iml" delete mode 100644 "\343\200\220060\343\200\221\343\200\220Permutation Sequence\343\200\221/\343\200\220060\343\200\221\343\200\220Permutation Sequence\343\200\221.iml" delete mode 100644 "\343\200\220061\343\200\221\343\200\220RotateList\343\200\221/\343\200\220061\343\200\221\343\200\220RotateList\343\200\221.iml" delete mode 100644 "\343\200\220062\343\200\221\343\200\220UniquePaths\343\200\221/\343\200\220062\343\200\221\343\200\220UniquePaths\343\200\221.iml" delete mode 100644 "\343\200\220063\343\200\221\343\200\220UniquePathsII\343\200\221/\343\200\220063\343\200\221\343\200\220UniquePathsII\343\200\221.iml" delete mode 100644 "\343\200\220064\343\200\221\343\200\220MinimumPathSum\343\200\221/\343\200\220064\343\200\221\343\200\220MinimumPathSum\343\200\221.iml" delete mode 100644 "\343\200\220066\343\200\221\343\200\220PlusOne\343\200\221/\343\200\220066\343\200\221\343\200\220PlusOne\343\200\221.iml" delete mode 100644 "\343\200\220067\343\200\221\343\200\220AddBinary\343\200\221/\343\200\220067\343\200\221\343\200\220AddBinary\343\200\221.iml" delete mode 100644 "\343\200\220070\343\200\221\343\200\220ClimbingStairs\343\200\221/\343\200\220070\343\200\221\343\200\220ClimbingStairs\343\200\221.iml" delete mode 100644 "\343\200\220071\343\200\221\343\200\220Simplify Path\343\200\221/\343\200\220071\343\200\221\343\200\220Simplify Path\343\200\221.iml" delete mode 100644 "\343\200\220073\343\200\221\343\200\220SetMatrixZeroes\343\200\221/\343\200\220073\343\200\221\343\200\220SetMatrixZeroes\343\200\221.iml" delete mode 100644 "\343\200\220074\343\200\221\343\200\220SearchA2DMatrix\343\200\221/\343\200\220074\343\200\221\343\200\220SearchA2DMatrix\343\200\221.iml" delete mode 100644 "\343\200\220075\343\200\221\343\200\220SortColors\343\200\221/\343\200\220075\343\200\221\343\200\220SortColors\343\200\221.iml" delete mode 100644 "\343\200\220077\343\200\221\343\200\220Combinations\343\200\221/\343\200\220077\343\200\221\343\200\220Combinations\343\200\221.iml" delete mode 100644 "\343\200\220078\343\200\221\343\200\220Subsets\343\200\221/\343\200\220078\343\200\221\343\200\220Subsets\343\200\221.iml" delete mode 100644 "\343\200\220079\343\200\221\343\200\220WordSearch\343\200\221/\343\200\220079\343\200\221\343\200\220WordSearch\343\200\221.iml" delete mode 100644 "\343\200\220081\343\200\221\343\200\220SearchInRotatedSortedArraII\343\200\221/\343\200\220081\343\200\221\343\200\220SearchInRotatedSortedArraII\343\200\221.iml" delete mode 100644 "\343\200\220082\343\200\221\343\200\220RemoveDuplicatesFromSortedListII\343\200\221/\343\200\220082\343\200\221\343\200\220RemoveDuplicatesFromSortedListII\343\200\221.iml" delete mode 100644 "\343\200\220083\343\200\221\343\200\220RemoveDuplicatesFromSortedList\343\200\221/\343\200\220083\343\200\221\343\200\220RemoveDuplicatesFromSortedList\343\200\221.iml" delete mode 100644 "\343\200\220086\343\200\221\343\200\220PartitionList\343\200\221/\343\200\220086\343\200\221\343\200\220PartitionList\343\200\221.iml" delete mode 100644 "\343\200\220088\343\200\221\343\200\220MergeSortedArray\343\200\221/\343\200\220088\343\200\221\343\200\220MergeSortedArray\343\200\221.iml" delete mode 100644 "\343\200\220089\343\200\221\343\200\220GrayCode\343\200\221/\343\200\220089\343\200\221\343\200\220GrayCode\343\200\221.iml" delete mode 100644 "\343\200\220092\343\200\221\343\200\220ReverseLinkedListII\343\200\221/\343\200\220092\343\200\221\343\200\220ReverseLinkedListII\343\200\221.iml" delete mode 100644 "\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221/\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221.iml" delete mode 100644 "\343\200\220096\343\200\221\343\200\220UniqueBinarySearchTrees\343\200\221/\343\200\220096\343\200\221\343\200\220UniqueBinarySearchTrees\343\200\221.iml" delete mode 100644 "\343\200\220098\343\200\221\343\200\220ValidateBinarySearchTree\343\200\221/\343\200\220098\343\200\221\343\200\220ValidateBinarySearchTree\343\200\221.iml" delete mode 100644 "\343\200\220100\343\200\221\343\200\220SameTree\343\200\221/\343\200\220100\343\200\221\343\200\220SameTree\343\200\221.iml" delete mode 100644 "\343\200\220101\343\200\221\343\200\220SymmetricTree\343\200\221/\343\200\220101\343\200\221\343\200\220SymmetricTree\343\200\221.iml" delete mode 100644 "\343\200\220102\343\200\221\343\200\220BinaryTreeLevelOrderTraversal\343\200\221/\343\200\220102\343\200\221\343\200\220BinaryTreeLevelOrderTraversal\343\200\221.iml" delete mode 100644 "\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221/\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221.iml" delete mode 100644 "\343\200\220104\343\200\221\343\200\220MaximumDepthOfBinaryTree\343\200\221/\343\200\220104\343\200\221\343\200\220MaximumDepthOfBinaryTree\343\200\221.iml" delete mode 100644 "\343\200\220105\343\200\221\343\200\220ConstructBinaryTreeFromPreorderAndInorderTraversal\343\200\221/\343\200\220105\343\200\221\343\200\220ConstructBinaryTreeFromPreorderAndInorderTraversal\343\200\221.iml" delete mode 100644 "\343\200\220106\343\200\221\343\200\220ConstructBinaryTreeFromInorderAndPostorderTraversal\343\200\221/\343\200\220106\343\200\221\343\200\220ConstructBinaryTreeFromInorderAndPostorderTraversal\343\200\221.iml" delete mode 100644 "\343\200\220107\343\200\221\343\200\220BinaryTreeLevelOrderTraversalII\343\200\221/\343\200\220107\343\200\221\343\200\220BinaryTreeLevelOrderTraversalII\343\200\221.iml" delete mode 100644 "\343\200\220108\343\200\221\343\200\220ConvertSortedArrayToBinarySearchTree\343\200\221/\343\200\220108\343\200\221\343\200\220ConvertSortedArrayToBinarySearchTree\343\200\221.iml" delete mode 100644 "\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221.iml" delete mode 100644 "\343\200\220110\343\200\221\343\200\220BalancedBinaryTree\343\200\221/\343\200\220110\343\200\221\343\200\220BalancedBinaryTree\343\200\221.iml" delete mode 100644 "\343\200\220111\343\200\221\343\200\220MinimumDepthOfBinaryTree\343\200\221/\343\200\220111\343\200\221\343\200\220MinimumDepthOfBinaryTree\343\200\221.iml" delete mode 100644 "\343\200\220112\343\200\221\343\200\220PathSum\343\200\221/\343\200\220112\343\200\221\343\200\220PathSum\343\200\221.iml" delete mode 100644 "\343\200\220113\343\200\221\343\200\220PathSumII\343\200\221/\343\200\220113\343\200\221\343\200\220PathSumII\343\200\221.iml" delete mode 100644 "\343\200\220114\343\200\221\343\200\220FlattenBinaryTreeToLinkedList\343\200\221/\343\200\220114\343\200\221\343\200\220FlattenBinaryTreeToLinkedList\343\200\221.iml" delete mode 100644 "\343\200\220116\343\200\221\343\200\220PopulatingNextRightPointersinEachNode \343\200\221/\343\200\220116\343\200\221\343\200\220PopulatingNextRightPointersinEachNode \343\200\221.iml" delete mode 100644 "\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221/\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221.iml" delete mode 100644 "\343\200\220118\343\200\221\343\200\220Pascal'sTriangle\343\200\221/\343\200\220118\343\200\221\343\200\220Pascal'sTriangle\343\200\221.iml" delete mode 100644 "\343\200\220119\343\200\221\343\200\220Pascal'sTriangleII\343\200\221/\343\200\220119\343\200\221\343\200\220Pascal'sTriangleII\343\200\221.iml" delete mode 100644 "\343\200\220120\343\200\221\343\200\220Triangle\343\200\221/\343\200\220120\343\200\221\343\200\220Triangle\343\200\221.iml" delete mode 100644 "\343\200\220121\343\200\221\343\200\220BestTimeToBuyAndSellStock\343\200\221/\343\200\220121\343\200\221\343\200\220BestTimeToBuyAndSellStock\343\200\221.iml" delete mode 100644 "\343\200\220124\346\234\252\343\200\221\343\200\220BinaryTreeMaximumPathSum\343\200\221/\343\200\220124\343\200\221\343\200\220BinaryTreeMaximumPathSum\343\200\221.iml" delete mode 100644 "\343\200\220125\343\200\221\343\200\220ValidPalindrome\343\200\221/\343\200\220125\343\200\221\343\200\220ValidPalindrome\343\200\221.iml" delete mode 100644 "\343\200\220127\346\234\252\343\200\221\343\200\220WordLadder\343\200\221/\343\200\220127\343\200\221\343\200\220WordLadder\343\200\221.iml" delete mode 100644 "\343\200\220129\343\200\221\343\200\220SumRootToLeafNumbers\343\200\221/\343\200\220129\343\200\221\343\200\220SumRootToLeafNumbers\343\200\221.iml" delete mode 100644 "\343\200\220130\343\200\221\343\200\220SurroundedRegions\343\200\221/\343\200\220130\343\200\221\343\200\220SurroundedRegions\343\200\221.iml" delete mode 100644 "\343\200\220134\343\200\221\343\200\220GasStation\343\200\221/\343\200\220134\343\200\221\343\200\220GasStation\343\200\221.iml" delete mode 100644 "\343\200\220136\343\200\221\343\200\220SingleNumber\343\200\221/\343\200\220136\343\200\221\343\200\220SingleNumber\343\200\221.iml" delete mode 100644 "\343\200\220137\343\200\221\343\200\220SingleNumberII\343\200\221/\343\200\220137\343\200\221\343\200\220SingleNumberII\343\200\221.iml" delete mode 100644 "\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221.iml" delete mode 100644 "\343\200\220139\343\200\221\343\200\220WordBreak\343\200\221/\343\200\220139\343\200\221\343\200\220WordBreak\343\200\221.iml" delete mode 100644 "\343\200\220141\343\200\221\343\200\220LinkedListCycle\343\200\221/\343\200\220141\343\200\221\343\200\220LinkedListCycle\343\200\221.iml" delete mode 100644 "\343\200\220142\343\200\221\343\200\220LinkedListCycleII\343\200\221/\343\200\220142\343\200\221\343\200\220LinkedListCycleII\343\200\221.iml" delete mode 100644 "\343\200\220143\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/\343\200\220143\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221.iml" delete mode 100644 "\343\200\220144\343\200\221\343\200\220BinaryTreePreorderTraversal\343\200\221/\343\200\220144\343\200\221\343\200\220BinaryTreePreorderTraversal\343\200\221.iml" delete mode 100644 "\343\200\220145\343\200\221\343\200\220BinaryTreePostorderTraversal\343\200\221/\343\200\220145\343\200\221\343\200\220BinaryTreePostorderTraversal\343\200\221.iml" delete mode 100644 "\343\200\220147\343\200\221\343\200\220InsertionSortList\343\200\221/\343\200\220147\343\200\221\343\200\220InsertionSortList\343\200\221.iml" delete mode 100644 "\343\200\220150\343\200\221\343\200\220EvaluateReversePolishNotation\343\200\221/\343\200\220150\343\200\221\343\200\220EvaluateReversePolishNotation\343\200\221.iml" delete mode 100644 "\343\200\220151\343\200\221\343\200\220ReverseWordsInAString\343\200\221/\343\200\220151\343\200\221\343\200\220ReverseWordsInAString\343\200\221.iml" delete mode 100644 "\343\200\220152\343\200\221\343\200\220MaximumProductSubarray\343\200\221/\343\200\220152\343\200\221\343\200\220MaximumProductSubarray\343\200\221.iml" delete mode 100644 "\343\200\220153\343\200\221\343\200\220FindMinimumInRotatedSortedArray\343\200\221/\343\200\220153\343\200\221\343\200\220FindMinimumInRotatedSortedArray\343\200\221.iml" delete mode 100644 "\343\200\220154\343\200\221\343\200\220FindMinimumInRotatedSortedArrayII\343\200\221/\343\200\220154\343\200\221\343\200\220FindMinimumInRotatedSortedArrayII\343\200\221.iml" delete mode 100644 "\343\200\220155\343\200\221\343\200\220MinStack\343\200\221/\343\200\220155\343\200\221\343\200\220MinStack\343\200\221.iml" delete mode 100644 "\343\200\220162\346\234\252\343\200\221\343\200\220FindPeakElement\343\200\221/\343\200\220162\343\200\221\343\200\220FindPeakElement\343\200\221.iml" delete mode 100644 "\343\200\220167\343\200\221\343\200\220Two Sum II - Input array is sorted\343\200\221/\343\200\220167\343\200\221\343\200\220Two Sum II - Input array is sorted\343\200\221.iml" delete mode 100644 "\343\200\220191\343\200\221\343\200\220NumberOf1Bits\343\200\221/\343\200\220191\343\200\221\343\200\220NumberOf1Bits\343\200\221.iml" delete mode 100644 "\343\200\220198\343\200\221\343\200\220HouseRobber\343\200\221/\343\200\220198\343\200\221\343\200\220HouseRobber\343\200\221.iml" delete mode 100644 "\343\200\220199\343\200\221\343\200\220BinaryTreeRightSideView\343\200\221/\343\200\220199\343\200\221\343\200\220BinaryTreeRightSideView\343\200\221.iml" delete mode 100644 "\343\200\220200\343\200\221\343\200\220NumberOfIslands\343\200\221/\343\200\220200\343\200\221\343\200\220NumberOfIslands\343\200\221.iml" delete mode 100644 "\343\200\220201\343\200\221\343\200\220BitwiseANDOfNumbersRange\343\200\221/\343\200\220201\343\200\221\343\200\220BitwiseANDOfNumbersRange\343\200\221.iml" delete mode 100644 "\343\200\220202\343\200\221\343\200\220HappyNumber \343\200\221/\343\200\220202\343\200\221\343\200\220HappyNumber \343\200\221.iml" delete mode 100644 "\343\200\220203\343\200\221\343\200\220RemoveLinkedList Elements\343\200\221/\343\200\220203\343\200\221\343\200\220RemoveLinkedList Elements\343\200\221.iml" delete mode 100644 "\343\200\220204\343\200\221\343\200\220CountPrimes\343\200\221/\343\200\220204\343\200\221\343\200\220CountPrimes\343\200\221.iml" delete mode 100644 "\343\200\220205\343\200\221\343\200\220IsomorphicStrings\343\200\221/\343\200\220205\343\200\221\343\200\220IsomorphicStrings\343\200\221.iml" delete mode 100644 "\343\200\220206\343\200\221\343\200\220ReverseLinkedList\343\200\221/\343\200\220206\343\200\221\343\200\220ReverseLinkedList\343\200\221.iml" delete mode 100644 "\343\200\220215\343\200\221\343\200\220KthLargestElementInAnArray\343\200\221/\343\200\220215\343\200\221\343\200\220KthLargestElementInAnArray\343\200\221.iml" delete mode 100644 "\343\200\220216\343\200\221\343\200\220CombinationSumIII\343\200\221/\343\200\220216\343\200\221\343\200\220CombinationSumIII\343\200\221.iml" delete mode 100644 "\343\200\220217\343\200\221\343\200\220ContainsDuplicate \343\200\221/\343\200\220217\343\200\221\343\200\220ContainsDuplicate \343\200\221.iml" delete mode 100644 "\343\200\220219\343\200\221\343\200\220ContainsDuplicateII\343\200\221/\343\200\220219\343\200\221\343\200\220ContainsDuplicateII\343\200\221.iml" delete mode 100644 "\343\200\220223\343\200\221\343\200\220RectangleArea\343\200\221/\343\200\220223\343\200\221\343\200\220RectangleArea\343\200\221.iml" delete mode 100644 "\343\200\220225\343\200\221\343\200\220ImplementStackUsingQueues\343\200\221/\343\200\220225\343\200\221\343\200\220ImplementStackUsingQueues\343\200\221.iml" delete mode 100644 "\343\200\220226\343\200\221\343\200\220InvertBinaryTree \343\200\221/\343\200\220226\343\200\221\343\200\220InvertBinaryTree \343\200\221.iml" diff --git a/.gitignore b/.gitignore index ded3800..2ea5840 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,29 @@ # Created by .ignore support plugin (hsz.mobi) - out +out .idea *.iml +### Java template +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 96cc43e..ab52643 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,22 +1,16 @@ - - - - - - - - - - - - - - + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index d5d79e0..a46b26f 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,15 @@ + + + + + diff --git a/.idea/modules.xml b/.idea/modules.xml index 2b4658f..425286a 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,170 +2,172 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/[000][utils]/src/FileRename.java b/[000][utils]/src/FileRename.java new file mode 100644 index 0000000..e0b062d --- /dev/null +++ b/[000][utils]/src/FileRename.java @@ -0,0 +1,30 @@ +import java.io.File; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-14 10:00 + **/ +public class FileRename { + public static void main(String[] args) { + String pathName = "/Users/wangjunchao/Project/leetcode"; + File path = new File("/Users/wangjunchao/Project/leetcode"); + + File[] files = path.listFiles(); + renameFile(files); + } + + public static void renameFile(File[] files) { + for (File f : files) { + if (f.isDirectory()) { + renameFile(f.listFiles()); + } + } + + for (File f : files) { + String name = f.getName(); + name = name.replaceAll("【", "["); + name = name.replaceAll("】", "]"); + f.renameTo(new File(f.getParent() + "/" + name)); + } + } +} diff --git "a/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221/src/Main.java" b/[001][Two Sum]/src/Main.java similarity index 100% rename from "\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221/src/Main.java" rename to [001][Two Sum]/src/Main.java diff --git "a/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221/src/Solution.java" b/[001][Two Sum]/src/Solution.java similarity index 100% rename from "\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221/src/Solution.java" rename to [001][Two Sum]/src/Solution.java diff --git "a/\343\200\220002\343\200\221\343\200\220AddTwoNumbers\343\200\221/src/ListNode.java" b/[002][Add Two Numbers]/src/ListNode.java similarity index 100% rename from "\343\200\220002\343\200\221\343\200\220AddTwoNumbers\343\200\221/src/ListNode.java" rename to [002][Add Two Numbers]/src/ListNode.java diff --git "a/\343\200\220002\343\200\221\343\200\220AddTwoNumbers\343\200\221/src/Solution.java" b/[002][Add Two Numbers]/src/Solution.java similarity index 100% rename from "\343\200\220002\343\200\221\343\200\220AddTwoNumbers\343\200\221/src/Solution.java" rename to [002][Add Two Numbers]/src/Solution.java diff --git "a/\343\200\220003\343\200\221\343\200\220LongestSubstringWithoutRepeatingCharacters\343\200\221/src/Solution.java" b/[003][Longest Substring Without Repeating Characters]/src/Solution.java similarity index 100% rename from "\343\200\220003\343\200\221\343\200\220LongestSubstringWithoutRepeatingCharacters\343\200\221/src/Solution.java" rename to [003][Longest Substring Without Repeating Characters]/src/Solution.java diff --git "a/\343\200\220004\343\200\221\343\200\220MedianofTwoSortedArrays\343\200\221/src/Solution.java" b/[004][Median of Two Sorted Arrays]/src/Solution.java similarity index 100% rename from "\343\200\220004\343\200\221\343\200\220MedianofTwoSortedArrays\343\200\221/src/Solution.java" rename to [004][Median of Two Sorted Arrays]/src/Solution.java diff --git a/[004][Median of Two Sorted Arrays]/src/Solution2.java b/[004][Median of Two Sorted Arrays]/src/Solution2.java new file mode 100644 index 0000000..601e821 --- /dev/null +++ b/[004][Median of Two Sorted Arrays]/src/Solution2.java @@ -0,0 +1,79 @@ +/** + * Author: + * Date: 2015-06-17 + * Time: 20:54 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + /** + *
+     * There are two sorted arrays nums1 and nums2 of size m and n respectively.
+     * Find the median of the two sorted arrays. The overall run time complexity
+     * should be O(log (m+n)).
+     *
+     * Ŀ⣺
+     * 飬λʱ临ӶΪO(log(m+n))
+     *
+     * ˼·
+     * ݹ
+     * 
+ * + * @param nums1 + * @param nums2 + * @return + */ + public double findMedianSortedArrays(int[] nums1, int[] nums2) { + + if (nums1 == null) { + nums1 = new int[0]; + } + + if (nums2 == null) { + nums2 = new int[0]; + } + + int len1 = nums1.length; + int len2 = nums2.length; + + if (len1 < len2) { + // ȷһȵڶ鳤ȴ + return findMedianSortedArrays(nums2, nums1); + } + + // С鳤Ϊ0ͷǰһλ + if (len2 == 0) { + return (nums1[(len1 - 1) / 2] + nums1[len1 / 2]) / 2.0; + } + + + int lo = 0; + int hi = len2 * 2; + int mid1; + int mid2; + double l1; + double l2; + double r1; + double r2; + + while (lo <= hi) { + mid2 = (lo + hi) / 2; + mid1 = len1 + len2 - mid2; + + l1 = (mid1 == 0) ? Integer.MIN_VALUE : nums1[(mid1 - 1) / 2]; + l2 = (mid2 == 0) ? Integer.MIN_VALUE : nums2[(mid2 - 1) / 2]; + + r1 = (mid1 == len1 * 2) ? Integer.MAX_VALUE : nums1[mid1 / 2]; + r2 = (mid2 == len2 * 2) ? Integer.MAX_VALUE : nums2[mid2 / 2]; + + if (l1 > r2) { + lo = mid2 + 1; + } else if (l2 > r1) { + hi = mid2 - 1; + } else { + return (Math.max(l1, l2) + Math.min(r1, r2)) / 2; + } + } + + return -1; + } +} diff --git "a/\343\200\220005\343\200\221\343\200\220LongestPalindromicSubstringTotal \343\200\221/src/Main.java" b/[005][Longest Palindromic Substring Total]/src/Main.java similarity index 100% rename from "\343\200\220005\343\200\221\343\200\220LongestPalindromicSubstringTotal \343\200\221/src/Main.java" rename to [005][Longest Palindromic Substring Total]/src/Main.java diff --git "a/\343\200\220005\343\200\221\343\200\220LongestPalindromicSubstringTotal \343\200\221/src/Solution.java" b/[005][Longest Palindromic Substring Total]/src/Solution.java similarity index 100% rename from "\343\200\220005\343\200\221\343\200\220LongestPalindromicSubstringTotal \343\200\221/src/Solution.java" rename to [005][Longest Palindromic Substring Total]/src/Solution.java diff --git "a/\343\200\220006\343\200\221\343\200\220ZigZagConversion\343\200\221/src/Solution.java" b/[006][Zig Zag Conversion]/src/Solution.java similarity index 100% rename from "\343\200\220006\343\200\221\343\200\220ZigZagConversion\343\200\221/src/Solution.java" rename to [006][Zig Zag Conversion]/src/Solution.java diff --git "a/\343\200\220007\343\200\221\343\200\220ReverseInteger\343\200\221/src/Solution.java" b/[007][Reverse Integer]/src/Solution.java similarity index 100% rename from "\343\200\220007\343\200\221\343\200\220ReverseInteger\343\200\221/src/Solution.java" rename to [007][Reverse Integer]/src/Solution.java diff --git "a/\343\200\220008\343\200\221\343\200\220StringToInteger (atoi)\343\200\221/src/Solution.java" b/[008][String To Integer (atoi)]/src/Solution.java similarity index 100% rename from "\343\200\220008\343\200\221\343\200\220StringToInteger (atoi)\343\200\221/src/Solution.java" rename to [008][String To Integer (atoi)]/src/Solution.java diff --git "a/\343\200\220009\343\200\221\343\200\220PalindromeNumber\343\200\221/src/Solution.java" b/[009][Palindrome Number]/src/Solution.java similarity index 100% rename from "\343\200\220009\343\200\221\343\200\220PalindromeNumber\343\200\221/src/Solution.java" rename to [009][Palindrome Number]/src/Solution.java diff --git "a/\343\200\220010\343\200\221\343\200\220RegularExpressionMatching\343\200\221/src/Main.java" b/[010][Regular Expression Matching]/src/Main.java similarity index 100% rename from "\343\200\220010\343\200\221\343\200\220RegularExpressionMatching\343\200\221/src/Main.java" rename to [010][Regular Expression Matching]/src/Main.java diff --git "a/\343\200\220010\343\200\221\343\200\220RegularExpressionMatching\343\200\221/src/Solution.java" b/[010][Regular Expression Matching]/src/Solution.java similarity index 100% rename from "\343\200\220010\343\200\221\343\200\220RegularExpressionMatching\343\200\221/src/Solution.java" rename to [010][Regular Expression Matching]/src/Solution.java diff --git "a/\343\200\220011\343\200\221\343\200\220ContainerWithMost Water\343\200\221/src/Solution.java" b/[011][Container With Most Water]/src/Solution.java similarity index 100% rename from "\343\200\220011\343\200\221\343\200\220ContainerWithMost Water\343\200\221/src/Solution.java" rename to [011][Container With Most Water]/src/Solution.java diff --git "a/\343\200\220012\343\200\221\343\200\220IntegerToRoman\343\200\221/src/Solution.java" b/[012][Integer To Roman]/src/Solution.java similarity index 100% rename from "\343\200\220012\343\200\221\343\200\220IntegerToRoman\343\200\221/src/Solution.java" rename to [012][Integer To Roman]/src/Solution.java diff --git "a/\343\200\220013\343\200\221\343\200\220RomarToInteger\343\200\221/src/Main.java" b/[013][Romar To Integer]/src/Main.java similarity index 100% rename from "\343\200\220013\343\200\221\343\200\220RomarToInteger\343\200\221/src/Main.java" rename to [013][Romar To Integer]/src/Main.java diff --git "a/\343\200\220013\343\200\221\343\200\220RomarToInteger\343\200\221/src/Solution.java" b/[013][Romar To Integer]/src/Solution.java similarity index 100% rename from "\343\200\220013\343\200\221\343\200\220RomarToInteger\343\200\221/src/Solution.java" rename to [013][Romar To Integer]/src/Solution.java diff --git "a/\343\200\220014\343\200\221\343\200\220LongestCommonPrefix\343\200\221/src/Solution.java" b/[014][Longest Common Prefix]/src/Solution.java similarity index 100% rename from "\343\200\220014\343\200\221\343\200\220LongestCommonPrefix\343\200\221/src/Solution.java" rename to [014][Longest Common Prefix]/src/Solution.java diff --git "a/\343\200\220015\343\200\221\343\200\2203Sum\343\200\221/src/Main.java" b/[015][3 Sum]/src/Main.java similarity index 100% rename from "\343\200\220015\343\200\221\343\200\2203Sum\343\200\221/src/Main.java" rename to [015][3 Sum]/src/Main.java diff --git "a/\343\200\220015\343\200\221\343\200\2203Sum\343\200\221/src/Solution.java" b/[015][3 Sum]/src/Solution.java similarity index 100% rename from "\343\200\220015\343\200\221\343\200\2203Sum\343\200\221/src/Solution.java" rename to [015][3 Sum]/src/Solution.java diff --git "a/\343\200\220016\343\200\221\343\200\2203SumClosest\343\200\221/src/Main.java" b/[016][3 Sum Closest/src/Main.java similarity index 100% rename from "\343\200\220016\343\200\221\343\200\2203SumClosest\343\200\221/src/Main.java" rename to [016][3 Sum Closest/src/Main.java diff --git "a/\343\200\220016\343\200\221\343\200\2203SumClosest\343\200\221/src/Solution.java" b/[016][3 Sum Closest/src/Solution.java similarity index 100% rename from "\343\200\220016\343\200\221\343\200\2203SumClosest\343\200\221/src/Solution.java" rename to [016][3 Sum Closest/src/Solution.java diff --git "a/\343\200\220017\343\200\221\343\200\220LetterCombinationsOfAPhonNumber \343\200\221/src/Solution.java" b/[017][Letter Combinations Of A Phon Number/src/Solution.java similarity index 100% rename from "\343\200\220017\343\200\221\343\200\220LetterCombinationsOfAPhonNumber \343\200\221/src/Solution.java" rename to [017][Letter Combinations Of A Phon Number/src/Solution.java diff --git "a/\343\200\220017\343\200\221\343\200\220LetterCombinationsOfAPhonNumber \343\200\221/src/phone-number.png" b/[017][Letter Combinations Of A Phon Number/src/phone-number.png similarity index 100% rename from "\343\200\220017\343\200\221\343\200\220LetterCombinationsOfAPhonNumber \343\200\221/src/phone-number.png" rename to [017][Letter Combinations Of A Phon Number/src/phone-number.png diff --git "a/\343\200\220018\343\200\221\343\200\2204Sum\343\200\221/src/Solution.java" b/[018][4 Sum]/src/Solution.java similarity index 100% rename from "\343\200\220018\343\200\221\343\200\2204Sum\343\200\221/src/Solution.java" rename to [018][4 Sum]/src/Solution.java diff --git "a/\343\200\220019\343\200\221\343\200\220RemoveNthNodeFromEndOfList\343\200\221/src/ListNode.java" b/[019][Remove Nth Node From End Of List]/src/ListNode.java similarity index 100% rename from "\343\200\220019\343\200\221\343\200\220RemoveNthNodeFromEndOfList\343\200\221/src/ListNode.java" rename to [019][Remove Nth Node From End Of List]/src/ListNode.java diff --git "a/\343\200\220019\343\200\221\343\200\220RemoveNthNodeFromEndOfList\343\200\221/src/Solution.java" b/[019][Remove Nth Node From End Of List]/src/Solution.java similarity index 100% rename from "\343\200\220019\343\200\221\343\200\220RemoveNthNodeFromEndOfList\343\200\221/src/Solution.java" rename to [019][Remove Nth Node From End Of List]/src/Solution.java diff --git "a/\343\200\220020\343\200\221\343\200\220ValidParentheses\343\200\221/src/Solution.java" b/[020][Valid Parentheses]/src/Solution.java similarity index 100% rename from "\343\200\220020\343\200\221\343\200\220ValidParentheses\343\200\221/src/Solution.java" rename to [020][Valid Parentheses]/src/Solution.java diff --git "a/\343\200\220021\343\200\221\343\200\220MergeTwoSortedLists\343\200\221/src/ListNode.java" b/[021][Merge Two Sorted Lists]/src/ListNode.java similarity index 100% rename from "\343\200\220021\343\200\221\343\200\220MergeTwoSortedLists\343\200\221/src/ListNode.java" rename to [021][Merge Two Sorted Lists]/src/ListNode.java diff --git "a/\343\200\220021\343\200\221\343\200\220MergeTwoSortedLists\343\200\221/src/Solution.java" b/[021][Merge Two Sorted Lists]/src/Solution.java similarity index 100% rename from "\343\200\220021\343\200\221\343\200\220MergeTwoSortedLists\343\200\221/src/Solution.java" rename to [021][Merge Two Sorted Lists]/src/Solution.java diff --git "a/\343\200\220022\343\200\221\343\200\220GenerateParentheses\343\200\221/src/Main.java" b/[022][Generate Parentheses]/src/Main.java similarity index 100% rename from "\343\200\220022\343\200\221\343\200\220GenerateParentheses\343\200\221/src/Main.java" rename to [022][Generate Parentheses]/src/Main.java diff --git "a/\343\200\220022\343\200\221\343\200\220GenerateParentheses\343\200\221/src/Solution.java" b/[022][Generate Parentheses]/src/Solution.java similarity index 100% rename from "\343\200\220022\343\200\221\343\200\220GenerateParentheses\343\200\221/src/Solution.java" rename to [022][Generate Parentheses]/src/Solution.java diff --git "a/\343\200\220023\343\200\221\343\200\220MergeKSortedLists\343\200\221/src/ListNode.java" b/[023][Merge K Sorted Lists]/src/ListNode.java similarity index 100% rename from "\343\200\220023\343\200\221\343\200\220MergeKSortedLists\343\200\221/src/ListNode.java" rename to [023][Merge K Sorted Lists]/src/ListNode.java diff --git "a/\343\200\220023\343\200\221\343\200\220MergeKSortedLists\343\200\221/src/Solution.java" b/[023][Merge K Sorted Lists]/src/Solution.java similarity index 100% rename from "\343\200\220023\343\200\221\343\200\220MergeKSortedLists\343\200\221/src/Solution.java" rename to [023][Merge K Sorted Lists]/src/Solution.java diff --git "a/\343\200\220024\343\200\221\343\200\220SwapNodesInPairs\343\200\221/src/ListNode.java" b/[024][Swap Nodes In Pairs]/src/ListNode.java similarity index 100% rename from "\343\200\220024\343\200\221\343\200\220SwapNodesInPairs\343\200\221/src/ListNode.java" rename to [024][Swap Nodes In Pairs]/src/ListNode.java diff --git "a/\343\200\220024\343\200\221\343\200\220SwapNodesInPairs\343\200\221/src/Solution.java" b/[024][Swap Nodes In Pairs]/src/Solution.java similarity index 100% rename from "\343\200\220024\343\200\221\343\200\220SwapNodesInPairs\343\200\221/src/Solution.java" rename to [024][Swap Nodes In Pairs]/src/Solution.java diff --git "a/\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221/src/ListNode.java" b/[025][Reverse Nodes In K-Group]/src/ListNode.java similarity index 100% rename from "\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221/src/ListNode.java" rename to [025][Reverse Nodes In K-Group]/src/ListNode.java diff --git "a/\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221/src/Main.java" b/[025][Reverse Nodes In K-Group]/src/Main.java similarity index 100% rename from "\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221/src/Main.java" rename to [025][Reverse Nodes In K-Group]/src/Main.java diff --git "a/\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221/src/Solution.java" b/[025][Reverse Nodes In K-Group]/src/Solution.java similarity index 100% rename from "\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221/src/Solution.java" rename to [025][Reverse Nodes In K-Group]/src/Solution.java diff --git "a/\343\200\220026\343\200\221\343\200\220RemoveDuplicatesfromSortedArray\343\200\221/src/Solution.java" b/[026][Remove Duplicates from Sorted Array]/src/Solution.java similarity index 100% rename from "\343\200\220026\343\200\221\343\200\220RemoveDuplicatesfromSortedArray\343\200\221/src/Solution.java" rename to [026][Remove Duplicates from Sorted Array]/src/Solution.java diff --git "a/\343\200\220026\343\200\221\343\200\220RemoveDuplicatesfromSortedArray\343\200\221/src/Solution2.java" b/[026][Remove Duplicates from Sorted Array]/src/Solution2.java similarity index 100% rename from "\343\200\220026\343\200\221\343\200\220RemoveDuplicatesfromSortedArray\343\200\221/src/Solution2.java" rename to [026][Remove Duplicates from Sorted Array]/src/Solution2.java diff --git "a/\343\200\220027\343\200\221\343\200\220RemoveElement\343\200\221/src/Solution.java" b/[027][Remove Element]/src/Solution.java similarity index 100% rename from "\343\200\220027\343\200\221\343\200\220RemoveElement\343\200\221/src/Solution.java" rename to [027][Remove Element]/src/Solution.java diff --git "a/\343\200\220028\343\200\221\343\200\220Implement-strStr()\343\200\221/src/Solution.java" b/[028][Implement-strStr()]/src/Solution.java similarity index 100% rename from "\343\200\220028\343\200\221\343\200\220Implement-strStr()\343\200\221/src/Solution.java" rename to [028][Implement-strStr()]/src/Solution.java diff --git "a/\343\200\220029\343\200\221\343\200\220DivideTwoIntegers\343\200\221/src/Main.java" b/[029][Divide Two Integers]/src/Main.java similarity index 100% rename from "\343\200\220029\343\200\221\343\200\220DivideTwoIntegers\343\200\221/src/Main.java" rename to [029][Divide Two Integers]/src/Main.java diff --git "a/\343\200\220029\343\200\221\343\200\220DivideTwoIntegers\343\200\221/src/Solution.java" b/[029][Divide Two Integers]/src/Solution.java similarity index 100% rename from "\343\200\220029\343\200\221\343\200\220DivideTwoIntegers\343\200\221/src/Solution.java" rename to [029][Divide Two Integers]/src/Solution.java diff --git "a/\343\200\220030\343\200\221\343\200\220SubstringWithConcatenationOfAllWords\343\200\221/src/Solution.java" b/[030][Substring With Concatenation Of All Words]/src/Solution.java similarity index 100% rename from "\343\200\220030\343\200\221\343\200\220SubstringWithConcatenationOfAllWords\343\200\221/src/Solution.java" rename to [030][Substring With Concatenation Of All Words]/src/Solution.java diff --git "a/\343\200\220032\343\200\221\343\200\220LongestValidParentheses\343\200\221/src/Main.java" b/[032][Longest Valid Parentheses]/src/Main.java similarity index 100% rename from "\343\200\220032\343\200\221\343\200\220LongestValidParentheses\343\200\221/src/Main.java" rename to [032][Longest Valid Parentheses]/src/Main.java diff --git "a/\343\200\220032\343\200\221\343\200\220LongestValidParentheses\343\200\221/src/Solution.java" b/[032][Longest Valid Parentheses]/src/Solution.java similarity index 100% rename from "\343\200\220032\343\200\221\343\200\220LongestValidParentheses\343\200\221/src/Solution.java" rename to [032][Longest Valid Parentheses]/src/Solution.java diff --git "a/\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221/src/Main.java" b/[033][Search In Rotated Sorted Array]/src/Main.java similarity index 100% rename from "\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221/src/Main.java" rename to [033][Search In Rotated Sorted Array]/src/Main.java diff --git "a/\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221/src/Solution.java" b/[033][Search In Rotated Sorted Array]/src/Solution.java similarity index 100% rename from "\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221/src/Solution.java" rename to [033][Search In Rotated Sorted Array]/src/Solution.java diff --git "a/\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221/src/Solution2.java" b/[033][Search In Rotated Sorted Array]/src/Solution2.java similarity index 100% rename from "\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221/src/Solution2.java" rename to [033][Search In Rotated Sorted Array]/src/Solution2.java diff --git "a/\343\200\220034\343\200\221\343\200\220SearchForARange\343\200\221/src/Solution.java" b/[034][Search For A Range]/src/Solution.java similarity index 100% rename from "\343\200\220034\343\200\221\343\200\220SearchForARange\343\200\221/src/Solution.java" rename to [034][Search For A Range]/src/Solution.java diff --git "a/\343\200\220035\343\200\221\343\200\220SearchInsertPosition\343\200\221/src/Solution.java" b/[035][Search Insert Position]/src/Solution.java similarity index 100% rename from "\343\200\220035\343\200\221\343\200\220SearchInsertPosition\343\200\221/src/Solution.java" rename to [035][Search Insert Position]/src/Solution.java diff --git "a/\343\200\220036\343\200\221\343\200\220Valid Sudoku\343\200\221/src/Solution.java" b/[036][Valid Sudoku]/src/Solution.java similarity index 100% rename from "\343\200\220036\343\200\221\343\200\220Valid Sudoku\343\200\221/src/Solution.java" rename to [036][Valid Sudoku]/src/Solution.java diff --git "a/\343\200\220036\343\200\221\343\200\220Valid Sudoku\343\200\221/src/sodoku.png" b/[036][Valid Sudoku]/src/sodoku.png similarity index 100% rename from "\343\200\220036\343\200\221\343\200\220Valid Sudoku\343\200\221/src/sodoku.png" rename to [036][Valid Sudoku]/src/sodoku.png diff --git "a/\343\200\220037\343\200\221\343\200\220Sudoku Solver\343\200\221/src/Solution.java" b/[037][Sudoku Solver]/src/Solution.java similarity index 100% rename from "\343\200\220037\343\200\221\343\200\220Sudoku Solver\343\200\221/src/Solution.java" rename to [037][Sudoku Solver]/src/Solution.java diff --git "a/\343\200\220038\343\200\221\343\200\220CountAndSay\343\200\221/src/Solution.java" b/[038][Count And Say]/src/Solution.java similarity index 100% rename from "\343\200\220038\343\200\221\343\200\220CountAndSay\343\200\221/src/Solution.java" rename to [038][Count And Say]/src/Solution.java diff --git "a/\343\200\220039\343\200\221\343\200\220Combination Sum\343\200\221/src/Solution.java" b/[039][Combination Sum]/src/Solution.java similarity index 100% rename from "\343\200\220039\343\200\221\343\200\220Combination Sum\343\200\221/src/Solution.java" rename to [039][Combination Sum]/src/Solution.java diff --git "a/\343\200\220040\343\200\221\343\200\220Combination Sum II\343\200\221/src/Solution.java" b/[040][Combination Sum II]/src/Solution.java similarity index 100% rename from "\343\200\220040\343\200\221\343\200\220Combination Sum II\343\200\221/src/Solution.java" rename to [040][Combination Sum II]/src/Solution.java diff --git "a/\343\200\220041\343\200\221\343\200\220First Missing Positive\343\200\221/src/Solution.java" b/[041][First Missing Positive]/src/Solution.java similarity index 100% rename from "\343\200\220041\343\200\221\343\200\220First Missing Positive\343\200\221/src/Solution.java" rename to [041][First Missing Positive]/src/Solution.java diff --git "a/\343\200\220042\343\200\221\343\200\220Trapping Rain Water\343\200\221/src/Solution.java" b/[042][Trapping Rain Water]/src/Solution.java similarity index 100% rename from "\343\200\220042\343\200\221\343\200\220Trapping Rain Water\343\200\221/src/Solution.java" rename to [042][Trapping Rain Water]/src/Solution.java diff --git "a/\343\200\220043\343\200\221\343\200\220Multiply Strings\343\200\221/src/Solution.java" b/[043][Multiply Strings]/src/Solution.java similarity index 100% rename from "\343\200\220043\343\200\221\343\200\220Multiply Strings\343\200\221/src/Solution.java" rename to [043][Multiply Strings]/src/Solution.java diff --git "a/\343\200\220044\343\200\221\343\200\220Wildcard Matching\343\200\221/src/Solution.java" b/[044][Wildcard Matching]/src/Solution.java similarity index 100% rename from "\343\200\220044\343\200\221\343\200\220Wildcard Matching\343\200\221/src/Solution.java" rename to [044][Wildcard Matching]/src/Solution.java diff --git "a/\343\200\220045\343\200\221\343\200\220Jump Game II\343\200\221/src/Solution.java" b/[045][Jump Game II]/src/Solution.java similarity index 100% rename from "\343\200\220045\343\200\221\343\200\220Jump Game II\343\200\221/src/Solution.java" rename to [045][Jump Game II]/src/Solution.java diff --git "a/\343\200\220046\343\200\221\343\200\220Permutations\343\200\221/src/Solution.java" b/[046][Permutations]/src/Solution.java similarity index 100% rename from "\343\200\220046\343\200\221\343\200\220Permutations\343\200\221/src/Solution.java" rename to [046][Permutations]/src/Solution.java diff --git "a/\343\200\220047\343\200\221\343\200\220Permutations II\343\200\221/src/Solution.java" b/[047][Permutations II]/src/Solution.java similarity index 100% rename from "\343\200\220047\343\200\221\343\200\220Permutations II\343\200\221/src/Solution.java" rename to [047][Permutations II]/src/Solution.java diff --git "a/\343\200\220048\343\200\221\343\200\220Rotate Image\343\200\221/src/Solution.java" b/[048][Rotate Image]/src/Solution.java similarity index 100% rename from "\343\200\220048\343\200\221\343\200\220Rotate Image\343\200\221/src/Solution.java" rename to [048][Rotate Image]/src/Solution.java diff --git "a/\343\200\220049\343\200\221\343\200\220Group Anagrams\343\200\221/src/Solution.java" b/[049][Group Anagrams]/src/Solution.java similarity index 100% rename from "\343\200\220049\343\200\221\343\200\220Group Anagrams\343\200\221/src/Solution.java" rename to [049][Group Anagrams]/src/Solution.java diff --git "a/\343\200\220050\343\200\221\343\200\220Pow(x,n)\343\200\221/src/Solution.java" b/[050][Pow(x,n)]/src/Solution.java similarity index 100% rename from "\343\200\220050\343\200\221\343\200\220Pow(x,n)\343\200\221/src/Solution.java" rename to [050][Pow(x,n)]/src/Solution.java diff --git "a/\343\200\220051\343\200\221\343\200\220N-Queens\343\200\221/src/Solution.java" b/[051][N-Queens]/src/Solution.java similarity index 100% rename from "\343\200\220051\343\200\221\343\200\220N-Queens\343\200\221/src/Solution.java" rename to [051][N-Queens]/src/Solution.java diff --git "a/\343\200\220052\343\200\221\343\200\220N-Queens II\343\200\221/src/Solution.java" b/[052][N-Queens II]/src/Solution.java similarity index 100% rename from "\343\200\220052\343\200\221\343\200\220N-Queens II\343\200\221/src/Solution.java" rename to [052][N-Queens II]/src/Solution.java diff --git "a/\343\200\220053\343\200\221\343\200\220MaximumSubarray\343\200\221/src/Solution.java" b/[053][Maximum Subarray]/src/Solution.java similarity index 100% rename from "\343\200\220053\343\200\221\343\200\220MaximumSubarray\343\200\221/src/Solution.java" rename to [053][Maximum Subarray]/src/Solution.java diff --git "a/\343\200\220054\343\200\221\343\200\220SpiralMatrix\343\200\221/src/Solution.java" b/[054][Spiral Matrix]/src/Solution.java similarity index 100% rename from "\343\200\220054\343\200\221\343\200\220SpiralMatrix\343\200\221/src/Solution.java" rename to [054][Spiral Matrix]/src/Solution.java diff --git "a/\343\200\220055\343\200\221\343\200\220Jump Game\343\200\221/src/Solution.java" b/[055][Jump Game]/src/Solution.java similarity index 100% rename from "\343\200\220055\343\200\221\343\200\220Jump Game\343\200\221/src/Solution.java" rename to [055][Jump Game]/src/Solution.java diff --git "a/\343\200\220056\343\200\221\343\200\220MergeIntervals\343\200\221/src/Interval.java" b/[056][Merge Intervals]/src/Interval.java similarity index 100% rename from "\343\200\220056\343\200\221\343\200\220MergeIntervals\343\200\221/src/Interval.java" rename to [056][Merge Intervals]/src/Interval.java diff --git "a/\343\200\220056\343\200\221\343\200\220MergeIntervals\343\200\221/src/Solution.java" b/[056][Merge Intervals]/src/Solution.java similarity index 100% rename from "\343\200\220056\343\200\221\343\200\220MergeIntervals\343\200\221/src/Solution.java" rename to [056][Merge Intervals]/src/Solution.java diff --git "a/\343\200\220057\343\200\221\343\200\220InsertInterval\343\200\221/src/Interval.java" b/[057][Insert Interval]/src/Interval.java similarity index 100% rename from "\343\200\220057\343\200\221\343\200\220InsertInterval\343\200\221/src/Interval.java" rename to [057][Insert Interval]/src/Interval.java diff --git "a/\343\200\220057\343\200\221\343\200\220InsertInterval\343\200\221/src/Solution.java" b/[057][Insert Interval]/src/Solution.java similarity index 100% rename from "\343\200\220057\343\200\221\343\200\220InsertInterval\343\200\221/src/Solution.java" rename to [057][Insert Interval]/src/Solution.java diff --git "a/\343\200\220058\343\200\221\343\200\220LengthOfLastWord\343\200\221/src/Solution.java" b/[058][Length Of Last Word]/src/Solution.java similarity index 100% rename from "\343\200\220058\343\200\221\343\200\220LengthOfLastWord\343\200\221/src/Solution.java" rename to [058][Length Of Last Word]/src/Solution.java diff --git "a/\343\200\220059\343\200\221\343\200\220SpiralMatrixII\343\200\221/src/Solution.java" b/[059][Spiral Matrix II]/src/Solution.java similarity index 100% rename from "\343\200\220059\343\200\221\343\200\220SpiralMatrixII\343\200\221/src/Solution.java" rename to [059][Spiral Matrix II]/src/Solution.java diff --git "a/\343\200\220060\343\200\221\343\200\220Permutation Sequence\343\200\221/src/Solution.java" b/[060][Permutation Sequence]/src/Solution.java similarity index 100% rename from "\343\200\220060\343\200\221\343\200\220Permutation Sequence\343\200\221/src/Solution.java" rename to [060][Permutation Sequence]/src/Solution.java diff --git "a/\343\200\220061\343\200\221\343\200\220RotateList\343\200\221/src/ListNode.java" b/[061][Rotate List]/src/ListNode.java similarity index 100% rename from "\343\200\220061\343\200\221\343\200\220RotateList\343\200\221/src/ListNode.java" rename to [061][Rotate List]/src/ListNode.java diff --git "a/\343\200\220061\343\200\221\343\200\220RotateList\343\200\221/src/Solution.java" b/[061][Rotate List]/src/Solution.java similarity index 100% rename from "\343\200\220061\343\200\221\343\200\220RotateList\343\200\221/src/Solution.java" rename to [061][Rotate List]/src/Solution.java diff --git "a/\343\200\220062\343\200\221\343\200\220UniquePaths\343\200\221/src/Solution.java" b/[062][Unique Paths]/src/Solution.java similarity index 100% rename from "\343\200\220062\343\200\221\343\200\220UniquePaths\343\200\221/src/Solution.java" rename to [062][Unique Paths]/src/Solution.java diff --git "a/\343\200\220063\343\200\221\343\200\220UniquePathsII\343\200\221/src/Solution.java" b/[063][Unique Paths II]/src/Solution.java similarity index 100% rename from "\343\200\220063\343\200\221\343\200\220UniquePathsII\343\200\221/src/Solution.java" rename to [063][Unique Paths II]/src/Solution.java diff --git "a/\343\200\220064\343\200\221\343\200\220MinimumPathSum\343\200\221/src/Main.java" b/[064][Minimum Path Sum]/src/Main.java similarity index 100% rename from "\343\200\220064\343\200\221\343\200\220MinimumPathSum\343\200\221/src/Main.java" rename to [064][Minimum Path Sum]/src/Main.java diff --git "a/\343\200\220064\343\200\221\343\200\220MinimumPathSum\343\200\221/src/Solution.java" b/[064][Minimum Path Sum]/src/Solution.java similarity index 100% rename from "\343\200\220064\343\200\221\343\200\220MinimumPathSum\343\200\221/src/Solution.java" rename to [064][Minimum Path Sum]/src/Solution.java diff --git "a/\343\200\220066\343\200\221\343\200\220PlusOne\343\200\221/src/Solution.java" b/[066][Plus One]/src/Solution.java similarity index 100% rename from "\343\200\220066\343\200\221\343\200\220PlusOne\343\200\221/src/Solution.java" rename to [066][Plus One]/src/Solution.java diff --git "a/\343\200\220067\343\200\221\343\200\220AddBinary\343\200\221/src/Solution.java" b/[067][Add Binary]/src/Solution.java similarity index 100% rename from "\343\200\220067\343\200\221\343\200\220AddBinary\343\200\221/src/Solution.java" rename to [067][Add Binary]/src/Solution.java diff --git "a/\343\200\220070\343\200\221\343\200\220ClimbingStairs\343\200\221/src/Solution.java" b/[070][Climbing Stairs]/src/Solution.java similarity index 100% rename from "\343\200\220070\343\200\221\343\200\220ClimbingStairs\343\200\221/src/Solution.java" rename to [070][Climbing Stairs]/src/Solution.java diff --git "a/\343\200\220071\343\200\221\343\200\220Simplify Path\343\200\221/src/Solution.java" b/[071][Simplify Path]/src/Solution.java similarity index 100% rename from "\343\200\220071\343\200\221\343\200\220Simplify Path\343\200\221/src/Solution.java" rename to [071][Simplify Path]/src/Solution.java diff --git "a/\343\200\220073\343\200\221\343\200\220SetMatrixZeroes\343\200\221/src/Solution.java" b/[073][Set Matrix Zeroes]/src/Solution.java similarity index 100% rename from "\343\200\220073\343\200\221\343\200\220SetMatrixZeroes\343\200\221/src/Solution.java" rename to [073][Set Matrix Zeroes]/src/Solution.java diff --git "a/\343\200\220074\343\200\221\343\200\220SearchA2DMatrix\343\200\221/src/Solution.java" b/[074][Search A 2D Matrix]/src/Solution.java similarity index 100% rename from "\343\200\220074\343\200\221\343\200\220SearchA2DMatrix\343\200\221/src/Solution.java" rename to [074][Search A 2D Matrix]/src/Solution.java diff --git "a/\343\200\220075\343\200\221\343\200\220SortColors\343\200\221/src/Solution.java" b/[075][Sort Colors]/src/Solution.java similarity index 100% rename from "\343\200\220075\343\200\221\343\200\220SortColors\343\200\221/src/Solution.java" rename to [075][Sort Colors]/src/Solution.java diff --git "a/\343\200\220077\343\200\221\343\200\220Combinations\343\200\221/src/Solution.java" b/[077][Combinations]/src/Solution.java similarity index 100% rename from "\343\200\220077\343\200\221\343\200\220Combinations\343\200\221/src/Solution.java" rename to [077][Combinations]/src/Solution.java diff --git "a/\343\200\220078\343\200\221\343\200\220Subsets\343\200\221/src/Solution.java" b/[078][Subsets]/src/Solution.java similarity index 100% rename from "\343\200\220078\343\200\221\343\200\220Subsets\343\200\221/src/Solution.java" rename to [078][Subsets]/src/Solution.java diff --git "a/\343\200\220079\343\200\221\343\200\220WordSearch\343\200\221/src/Main.java" b/[079][Word Search]/src/Main.java similarity index 100% rename from "\343\200\220079\343\200\221\343\200\220WordSearch\343\200\221/src/Main.java" rename to [079][Word Search]/src/Main.java diff --git "a/\343\200\220079\343\200\221\343\200\220WordSearch\343\200\221/src/Solution.java" b/[079][Word Search]/src/Solution.java similarity index 100% rename from "\343\200\220079\343\200\221\343\200\220WordSearch\343\200\221/src/Solution.java" rename to [079][Word Search]/src/Solution.java diff --git "a/\343\200\220080\343\200\221\343\200\220Remove Duplicates from Sorted Array II\343\200\221/src/Main.java" b/[080][Remove Duplicates from Sorted Array II]/src/Main.java similarity index 100% rename from "\343\200\220080\343\200\221\343\200\220Remove Duplicates from Sorted Array II\343\200\221/src/Main.java" rename to [080][Remove Duplicates from Sorted Array II]/src/Main.java diff --git "a/\343\200\220080\343\200\221\343\200\220Remove Duplicates from Sorted Array II\343\200\221/src/Solution.java" b/[080][Remove Duplicates from Sorted Array II]/src/Solution.java similarity index 100% rename from "\343\200\220080\343\200\221\343\200\220Remove Duplicates from Sorted Array II\343\200\221/src/Solution.java" rename to [080][Remove Duplicates from Sorted Array II]/src/Solution.java diff --git "a/\343\200\220080\343\200\221\343\200\220Remove Duplicates from Sorted Array II\343\200\221/src/Solution2.java" b/[080][Remove Duplicates from Sorted Array II]/src/Solution2.java similarity index 100% rename from "\343\200\220080\343\200\221\343\200\220Remove Duplicates from Sorted Array II\343\200\221/src/Solution2.java" rename to [080][Remove Duplicates from Sorted Array II]/src/Solution2.java diff --git "a/\343\200\220081\343\200\221\343\200\220SearchInRotatedSortedArraII\343\200\221/src/Main.java" b/[081][Search In Rotated Sorted Array II]/src/Main.java similarity index 62% rename from "\343\200\220081\343\200\221\343\200\220SearchInRotatedSortedArraII\343\200\221/src/Main.java" rename to [081][Search In Rotated Sorted Array II]/src/Main.java index e6ee29f..be94e08 100644 --- "a/\343\200\220081\343\200\221\343\200\220SearchInRotatedSortedArraII\343\200\221/src/Main.java" +++ b/[081][Search In Rotated Sorted Array II]/src/Main.java @@ -1,13 +1,13 @@ /** - * Author: + * Author: 王俊超 * Date: 2015-06-21 * Time: 16:38 * Declaration: All Rights Reserved !!! */ public class Main { public static void main(String[] args) { - Solution solution = new Solution(); + Solution2 solution = new Solution2(); System.out.println(solution.search(new int[]{1, 1, 3, 1}, 3)); -// System.out.println(solution.findMinIndex(new int[]{1, 1, 3, 1})); + System.out.println(solution.search(new int[]{5, 1, 3}, 3)); } } diff --git "a/\343\200\220081\343\200\221\343\200\220SearchInRotatedSortedArraII\343\200\221/src/Solution.java" b/[081][Search In Rotated Sorted Array II]/src/Solution.java similarity index 100% rename from "\343\200\220081\343\200\221\343\200\220SearchInRotatedSortedArraII\343\200\221/src/Solution.java" rename to [081][Search In Rotated Sorted Array II]/src/Solution.java diff --git a/[081][Search In Rotated Sorted Array II]/src/Solution2.java b/[081][Search In Rotated Sorted Array II]/src/Solution2.java new file mode 100644 index 0000000..9e48b6c --- /dev/null +++ b/[081][Search In Rotated Sorted Array II]/src/Solution2.java @@ -0,0 +1,56 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-13 06:19 + **/ +public class Solution2 { + /** + * 分析 + * 允许重复元素,则上一题中如果A[mid]>=A[left], 那么[left,mid] 为递增序列的假设就不能成立了,比 + * 如[1,3,1,1,1]。 + * 如果A[mid]>=A[left] 不能确定递增,那就把它拆分成两个条件: + * • 若A[mid]>A[left],则区间[left,mid] 一定递增 + * • 若A[mid]==A[left] 确定不了,那就l++,往下看一步即可。 + * + * @param nums + * @param target + * @return + */ + public boolean search(int[] nums, int target) { + if (nums == null || nums.length < 1) { + return false; + } + + int left = 0; + int right = nums.length - 1; + int mid; + while (left <= right) { + mid = left + (right - left) / 2; + if (nums[mid] == target) { + return true; + } + + // [left, mid]区间递增 + if (nums[left] < nums[mid]) { + // target在[nums[left], nums[mid]]之间 + if (nums[left] <= target && target < nums[mid]) { + right = mid - 1; + } else { + left = mid + 1; + } + } else if (nums[left] > nums[mid]) { // [mid, right]区间递增 + // target在[nums[mid], nums[right]]之间 + if (nums[mid] < target && target <= nums[right]) { + left = mid + 1; + } else { + right = mid - 1; + } + } else { + // 无法区分递增区间,向右移动一个位置 + left++; + } + } + + + return false; + } +} diff --git "a/\343\200\220082\343\200\221\343\200\220RemoveDuplicatesFromSortedListII\343\200\221/src/ListNode.java" b/[082][Remove Duplicates From Sorted List II]/src/ListNode.java similarity index 100% rename from "\343\200\220082\343\200\221\343\200\220RemoveDuplicatesFromSortedListII\343\200\221/src/ListNode.java" rename to [082][Remove Duplicates From Sorted List II]/src/ListNode.java diff --git "a/\343\200\220082\343\200\221\343\200\220RemoveDuplicatesFromSortedListII\343\200\221/src/Solution.java" b/[082][Remove Duplicates From Sorted List II]/src/Solution.java similarity index 100% rename from "\343\200\220082\343\200\221\343\200\220RemoveDuplicatesFromSortedListII\343\200\221/src/Solution.java" rename to [082][Remove Duplicates From Sorted List II]/src/Solution.java diff --git "a/\343\200\220083\343\200\221\343\200\220RemoveDuplicatesFromSortedList\343\200\221/src/ListNode.java" b/[083][Remove Duplicates From Sorted List]/src/ListNode.java similarity index 100% rename from "\343\200\220083\343\200\221\343\200\220RemoveDuplicatesFromSortedList\343\200\221/src/ListNode.java" rename to [083][Remove Duplicates From Sorted List]/src/ListNode.java diff --git "a/\343\200\220083\343\200\221\343\200\220RemoveDuplicatesFromSortedList\343\200\221/src/Solution.java" b/[083][Remove Duplicates From Sorted List]/src/Solution.java similarity index 100% rename from "\343\200\220083\343\200\221\343\200\220RemoveDuplicatesFromSortedList\343\200\221/src/Solution.java" rename to [083][Remove Duplicates From Sorted List]/src/Solution.java diff --git "a/\343\200\220086\343\200\221\343\200\220PartitionList\343\200\221/src/ListNode.java" b/[086][Partition List]/src/ListNode.java similarity index 100% rename from "\343\200\220086\343\200\221\343\200\220PartitionList\343\200\221/src/ListNode.java" rename to [086][Partition List]/src/ListNode.java diff --git "a/\343\200\220086\343\200\221\343\200\220PartitionList\343\200\221/src/Solution.java" b/[086][Partition List]/src/Solution.java similarity index 100% rename from "\343\200\220086\343\200\221\343\200\220PartitionList\343\200\221/src/Solution.java" rename to [086][Partition List]/src/Solution.java diff --git "a/\343\200\220088\343\200\221\343\200\220MergeSortedArray\343\200\221/src/Solution.java" b/[088][Merge Sorted Array]/src/Solution.java similarity index 100% rename from "\343\200\220088\343\200\221\343\200\220MergeSortedArray\343\200\221/src/Solution.java" rename to [088][Merge Sorted Array]/src/Solution.java diff --git "a/\343\200\220089\343\200\221\343\200\220GrayCode\343\200\221/src/Main.java" b/[089][Gray Code]/src/Main.java similarity index 100% rename from "\343\200\220089\343\200\221\343\200\220GrayCode\343\200\221/src/Main.java" rename to [089][Gray Code]/src/Main.java diff --git "a/\343\200\220089\343\200\221\343\200\220GrayCode\343\200\221/src/Solution.java" b/[089][Gray Code]/src/Solution.java similarity index 100% rename from "\343\200\220089\343\200\221\343\200\220GrayCode\343\200\221/src/Solution.java" rename to [089][Gray Code]/src/Solution.java diff --git "a/\343\200\220092\343\200\221\343\200\220ReverseLinkedListII\343\200\221/src/ListNode.java" b/[092][Reverse Linked List II]/src/ListNode.java similarity index 100% rename from "\343\200\220092\343\200\221\343\200\220ReverseLinkedListII\343\200\221/src/ListNode.java" rename to [092][Reverse Linked List II]/src/ListNode.java diff --git "a/\343\200\220092\343\200\221\343\200\220ReverseLinkedListII\343\200\221/src/Solution.java" b/[092][Reverse Linked List II]/src/Solution.java similarity index 100% rename from "\343\200\220092\343\200\221\343\200\220ReverseLinkedListII\343\200\221/src/Solution.java" rename to [092][Reverse Linked List II]/src/Solution.java diff --git "a/\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221/src/Main.java" b/[094][Binary Tree Inorder Traversal]/src/Main.java similarity index 100% rename from "\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221/src/Main.java" rename to [094][Binary Tree Inorder Traversal]/src/Main.java diff --git "a/\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221/src/Solution.java" b/[094][Binary Tree Inorder Traversal]/src/Solution.java similarity index 100% rename from "\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221/src/Solution.java" rename to [094][Binary Tree Inorder Traversal]/src/Solution.java diff --git "a/\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221/src/TreeNode.java" b/[094][Binary Tree Inorder Traversal]/src/TreeNode.java similarity index 100% rename from "\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221/src/TreeNode.java" rename to [094][Binary Tree Inorder Traversal]/src/TreeNode.java diff --git "a/\343\200\220096\343\200\221\343\200\220UniqueBinarySearchTrees\343\200\221/src/Main.java" b/[096][Unique Binary Search Trees]/src/Main.java similarity index 100% rename from "\343\200\220096\343\200\221\343\200\220UniqueBinarySearchTrees\343\200\221/src/Main.java" rename to [096][Unique Binary Search Trees]/src/Main.java diff --git "a/\343\200\220096\343\200\221\343\200\220UniqueBinarySearchTrees\343\200\221/src/Solution.java" b/[096][Unique Binary Search Trees]/src/Solution.java similarity index 100% rename from "\343\200\220096\343\200\221\343\200\220UniqueBinarySearchTrees\343\200\221/src/Solution.java" rename to [096][Unique Binary Search Trees]/src/Solution.java diff --git "a/\343\200\220098\343\200\221\343\200\220ValidateBinarySearchTree\343\200\221/src/Solution.java" b/[098][Validate Binary Search Tree]/src/Solution.java similarity index 100% rename from "\343\200\220098\343\200\221\343\200\220ValidateBinarySearchTree\343\200\221/src/Solution.java" rename to [098][Validate Binary Search Tree]/src/Solution.java diff --git "a/\343\200\220098\343\200\221\343\200\220ValidateBinarySearchTree\343\200\221/src/TreeNode.java" b/[098][Validate Binary Search Tree]/src/TreeNode.java similarity index 100% rename from "\343\200\220098\343\200\221\343\200\220ValidateBinarySearchTree\343\200\221/src/TreeNode.java" rename to [098][Validate Binary Search Tree]/src/TreeNode.java diff --git "a/\343\200\220100\343\200\221\343\200\220SameTree\343\200\221/src/Solution.java" b/[100][Same Tree]/src/Solution.java similarity index 100% rename from "\343\200\220100\343\200\221\343\200\220SameTree\343\200\221/src/Solution.java" rename to [100][Same Tree]/src/Solution.java diff --git "a/\343\200\220100\343\200\221\343\200\220SameTree\343\200\221/src/TreeNode.java" b/[100][Same Tree]/src/TreeNode.java similarity index 100% rename from "\343\200\220100\343\200\221\343\200\220SameTree\343\200\221/src/TreeNode.java" rename to [100][Same Tree]/src/TreeNode.java diff --git "a/\343\200\220101\343\200\221\343\200\220SymmetricTree\343\200\221/src/Solution.java" b/[101][Symmetric Tree]/src/Solution.java similarity index 100% rename from "\343\200\220101\343\200\221\343\200\220SymmetricTree\343\200\221/src/Solution.java" rename to [101][Symmetric Tree]/src/Solution.java diff --git "a/\343\200\220101\343\200\221\343\200\220SymmetricTree\343\200\221/src/TreeNode.java" b/[101][Symmetric Tree]/src/TreeNode.java similarity index 100% rename from "\343\200\220101\343\200\221\343\200\220SymmetricTree\343\200\221/src/TreeNode.java" rename to [101][Symmetric Tree]/src/TreeNode.java diff --git "a/\343\200\220102\343\200\221\343\200\220BinaryTreeLevelOrderTraversal\343\200\221/src/Solution.java" b/[102][Binary Tree Level Order Traversal]/src/Solution.java similarity index 100% rename from "\343\200\220102\343\200\221\343\200\220BinaryTreeLevelOrderTraversal\343\200\221/src/Solution.java" rename to [102][Binary Tree Level Order Traversal]/src/Solution.java diff --git "a/\343\200\220102\343\200\221\343\200\220BinaryTreeLevelOrderTraversal\343\200\221/src/TreeNode.java" b/[102][Binary Tree Level Order Traversal]/src/TreeNode.java similarity index 100% rename from "\343\200\220102\343\200\221\343\200\220BinaryTreeLevelOrderTraversal\343\200\221/src/TreeNode.java" rename to [102][Binary Tree Level Order Traversal]/src/TreeNode.java diff --git "a/\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221/src/Main.java" b/[103][Binary Tree Zigzag LevelOrder Traversal]/src/Main.java similarity index 100% rename from "\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221/src/Main.java" rename to [103][Binary Tree Zigzag LevelOrder Traversal]/src/Main.java diff --git "a/\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221/src/Solution.java" b/[103][Binary Tree Zigzag LevelOrder Traversal]/src/Solution.java similarity index 100% rename from "\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221/src/Solution.java" rename to [103][Binary Tree Zigzag LevelOrder Traversal]/src/Solution.java diff --git "a/\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221/src/TreeNode.java" b/[103][Binary Tree Zigzag LevelOrder Traversal]/src/TreeNode.java similarity index 100% rename from "\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221/src/TreeNode.java" rename to [103][Binary Tree Zigzag LevelOrder Traversal]/src/TreeNode.java diff --git "a/\343\200\220104\343\200\221\343\200\220MaximumDepthOfBinaryTree\343\200\221/src/Solution.java" b/[104][Maximum Depth Of Binary Tree]/src/Solution.java similarity index 100% rename from "\343\200\220104\343\200\221\343\200\220MaximumDepthOfBinaryTree\343\200\221/src/Solution.java" rename to [104][Maximum Depth Of Binary Tree]/src/Solution.java diff --git "a/\343\200\220104\343\200\221\343\200\220MaximumDepthOfBinaryTree\343\200\221/src/TreeNode.java" b/[104][Maximum Depth Of Binary Tree]/src/TreeNode.java similarity index 100% rename from "\343\200\220104\343\200\221\343\200\220MaximumDepthOfBinaryTree\343\200\221/src/TreeNode.java" rename to [104][Maximum Depth Of Binary Tree]/src/TreeNode.java diff --git "a/\343\200\220105\343\200\221\343\200\220ConstructBinaryTreeFromPreorderAndInorderTraversal\343\200\221/src/Solution.java" b/[105][Construct Binary Tree From Preorder And Inorder Traversal]/src/Solution.java similarity index 100% rename from "\343\200\220105\343\200\221\343\200\220ConstructBinaryTreeFromPreorderAndInorderTraversal\343\200\221/src/Solution.java" rename to [105][Construct Binary Tree From Preorder And Inorder Traversal]/src/Solution.java diff --git "a/\343\200\220105\343\200\221\343\200\220ConstructBinaryTreeFromPreorderAndInorderTraversal\343\200\221/src/TreeNode.java" b/[105][Construct Binary Tree From Preorder And Inorder Traversal]/src/TreeNode.java similarity index 100% rename from "\343\200\220105\343\200\221\343\200\220ConstructBinaryTreeFromPreorderAndInorderTraversal\343\200\221/src/TreeNode.java" rename to [105][Construct Binary Tree From Preorder And Inorder Traversal]/src/TreeNode.java diff --git "a/\343\200\220106\343\200\221\343\200\220ConstructBinaryTreeFromInorderAndPostorderTraversal\343\200\221/src/Main.java" b/[106][Construct Binary Tree From Inorder And Postorder Traversal]/src/Main.java similarity index 100% rename from "\343\200\220106\343\200\221\343\200\220ConstructBinaryTreeFromInorderAndPostorderTraversal\343\200\221/src/Main.java" rename to [106][Construct Binary Tree From Inorder And Postorder Traversal]/src/Main.java diff --git "a/\343\200\220106\343\200\221\343\200\220ConstructBinaryTreeFromInorderAndPostorderTraversal\343\200\221/src/Solution.java" b/[106][Construct Binary Tree From Inorder And Postorder Traversal]/src/Solution.java similarity index 100% rename from "\343\200\220106\343\200\221\343\200\220ConstructBinaryTreeFromInorderAndPostorderTraversal\343\200\221/src/Solution.java" rename to [106][Construct Binary Tree From Inorder And Postorder Traversal]/src/Solution.java diff --git "a/\343\200\220106\343\200\221\343\200\220ConstructBinaryTreeFromInorderAndPostorderTraversal\343\200\221/src/TreeNode.java" b/[106][Construct Binary Tree From Inorder And Postorder Traversal]/src/TreeNode.java similarity index 100% rename from "\343\200\220106\343\200\221\343\200\220ConstructBinaryTreeFromInorderAndPostorderTraversal\343\200\221/src/TreeNode.java" rename to [106][Construct Binary Tree From Inorder And Postorder Traversal]/src/TreeNode.java diff --git "a/\343\200\220107\343\200\221\343\200\220BinaryTreeLevelOrderTraversalII\343\200\221/src/Solution.java" b/[107][Binary Tree Level Order Traversa lII]/src/Solution.java similarity index 100% rename from "\343\200\220107\343\200\221\343\200\220BinaryTreeLevelOrderTraversalII\343\200\221/src/Solution.java" rename to [107][Binary Tree Level Order Traversa lII]/src/Solution.java diff --git "a/\343\200\220107\343\200\221\343\200\220BinaryTreeLevelOrderTraversalII\343\200\221/src/TreeNode.java" b/[107][Binary Tree Level Order Traversa lII]/src/TreeNode.java similarity index 100% rename from "\343\200\220107\343\200\221\343\200\220BinaryTreeLevelOrderTraversalII\343\200\221/src/TreeNode.java" rename to [107][Binary Tree Level Order Traversa lII]/src/TreeNode.java diff --git "a/\343\200\220108\343\200\221\343\200\220ConvertSortedArrayToBinarySearchTree\343\200\221/src/Solution.java" b/[108][Convert Sorted Array To Binary Search Tree]/src/Solution.java similarity index 100% rename from "\343\200\220108\343\200\221\343\200\220ConvertSortedArrayToBinarySearchTree\343\200\221/src/Solution.java" rename to [108][Convert Sorted Array To Binary Search Tree]/src/Solution.java diff --git "a/\343\200\220108\343\200\221\343\200\220ConvertSortedArrayToBinarySearchTree\343\200\221/src/TreeNode.java" b/[108][Convert Sorted Array To Binary Search Tree]/src/TreeNode.java similarity index 100% rename from "\343\200\220108\343\200\221\343\200\220ConvertSortedArrayToBinarySearchTree\343\200\221/src/TreeNode.java" rename to [108][Convert Sorted Array To Binary Search Tree]/src/TreeNode.java diff --git "a/\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/src/ListNode.java" b/[109][Convert Sorted List To Binary Search Tree]/src/ListNode.java similarity index 100% rename from "\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/src/ListNode.java" rename to [109][Convert Sorted List To Binary Search Tree]/src/ListNode.java diff --git "a/\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/src/Main.java" b/[109][Convert Sorted List To Binary Search Tree]/src/Main.java similarity index 100% rename from "\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/src/Main.java" rename to [109][Convert Sorted List To Binary Search Tree]/src/Main.java diff --git "a/\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/src/Solution.java" b/[109][Convert Sorted List To Binary Search Tree]/src/Solution.java similarity index 100% rename from "\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/src/Solution.java" rename to [109][Convert Sorted List To Binary Search Tree]/src/Solution.java diff --git "a/\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/src/TreeNode.java" b/[109][Convert Sorted List To Binary Search Tree]/src/TreeNode.java similarity index 100% rename from "\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/src/TreeNode.java" rename to [109][Convert Sorted List To Binary Search Tree]/src/TreeNode.java diff --git "a/\343\200\220110\343\200\221\343\200\220BalancedBinaryTree\343\200\221/src/Solution.java" b/[110][Balanced Binary Tree]/src/Solution.java similarity index 100% rename from "\343\200\220110\343\200\221\343\200\220BalancedBinaryTree\343\200\221/src/Solution.java" rename to [110][Balanced Binary Tree]/src/Solution.java diff --git "a/\343\200\220110\343\200\221\343\200\220BalancedBinaryTree\343\200\221/src/TreeNode.java" b/[110][Balanced Binary Tree]/src/TreeNode.java similarity index 100% rename from "\343\200\220110\343\200\221\343\200\220BalancedBinaryTree\343\200\221/src/TreeNode.java" rename to [110][Balanced Binary Tree]/src/TreeNode.java diff --git "a/\343\200\220111\343\200\221\343\200\220MinimumDepthOfBinaryTree\343\200\221/src/Solution.java" b/[111][Minimum Depth Of Binary Tree]/src/Solution.java similarity index 100% rename from "\343\200\220111\343\200\221\343\200\220MinimumDepthOfBinaryTree\343\200\221/src/Solution.java" rename to [111][Minimum Depth Of Binary Tree]/src/Solution.java diff --git "a/\343\200\220111\343\200\221\343\200\220MinimumDepthOfBinaryTree\343\200\221/src/TreeNode.java" b/[111][Minimum Depth Of Binary Tree]/src/TreeNode.java similarity index 100% rename from "\343\200\220111\343\200\221\343\200\220MinimumDepthOfBinaryTree\343\200\221/src/TreeNode.java" rename to [111][Minimum Depth Of Binary Tree]/src/TreeNode.java diff --git "a/\343\200\220112\343\200\221\343\200\220PathSum\343\200\221/src/Solution.java" b/[112][Path Sum]/src/Solution.java similarity index 100% rename from "\343\200\220112\343\200\221\343\200\220PathSum\343\200\221/src/Solution.java" rename to [112][Path Sum]/src/Solution.java diff --git "a/\343\200\220112\343\200\221\343\200\220PathSum\343\200\221/src/TreeNode.java" b/[112][Path Sum]/src/TreeNode.java similarity index 100% rename from "\343\200\220112\343\200\221\343\200\220PathSum\343\200\221/src/TreeNode.java" rename to [112][Path Sum]/src/TreeNode.java diff --git "a/\343\200\220113\343\200\221\343\200\220PathSumII\343\200\221/src/Solution.java" b/[113][Path Sum II]/src/Solution.java similarity index 100% rename from "\343\200\220113\343\200\221\343\200\220PathSumII\343\200\221/src/Solution.java" rename to [113][Path Sum II]/src/Solution.java diff --git "a/\343\200\220113\343\200\221\343\200\220PathSumII\343\200\221/src/TreeNode.java" b/[113][Path Sum II]/src/TreeNode.java similarity index 100% rename from "\343\200\220113\343\200\221\343\200\220PathSumII\343\200\221/src/TreeNode.java" rename to [113][Path Sum II]/src/TreeNode.java diff --git "a/\343\200\220114\343\200\221\343\200\220FlattenBinaryTreeToLinkedList\343\200\221/src/Solution.java" b/[114][Flatten Binary Tree To Linked List]/src/Solution.java similarity index 100% rename from "\343\200\220114\343\200\221\343\200\220FlattenBinaryTreeToLinkedList\343\200\221/src/Solution.java" rename to [114][Flatten Binary Tree To Linked List]/src/Solution.java diff --git "a/\343\200\220114\343\200\221\343\200\220FlattenBinaryTreeToLinkedList\343\200\221/src/TreeNode.java" b/[114][Flatten Binary Tree To Linked List]/src/TreeNode.java similarity index 100% rename from "\343\200\220114\343\200\221\343\200\220FlattenBinaryTreeToLinkedList\343\200\221/src/TreeNode.java" rename to [114][Flatten Binary Tree To Linked List]/src/TreeNode.java diff --git "a/\343\200\220116\343\200\221\343\200\220PopulatingNextRightPointersinEachNode \343\200\221/src/Solution.java" b/[116][Populating Next Right Pointersin Each Node]/src/Solution.java similarity index 100% rename from "\343\200\220116\343\200\221\343\200\220PopulatingNextRightPointersinEachNode \343\200\221/src/Solution.java" rename to [116][Populating Next Right Pointersin Each Node]/src/Solution.java diff --git "a/\343\200\220116\343\200\221\343\200\220PopulatingNextRightPointersinEachNode \343\200\221/src/TreeLinkNode.java" b/[116][Populating Next Right Pointersin Each Node]/src/TreeLinkNode.java similarity index 100% rename from "\343\200\220116\343\200\221\343\200\220PopulatingNextRightPointersinEachNode \343\200\221/src/TreeLinkNode.java" rename to [116][Populating Next Right Pointersin Each Node]/src/TreeLinkNode.java diff --git "a/\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221/src/Main.java" b/[117][Populating Next Right Pointers In Each Node II]/src/Main.java similarity index 100% rename from "\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221/src/Main.java" rename to [117][Populating Next Right Pointers In Each Node II]/src/Main.java diff --git "a/\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221/src/Solution.java" b/[117][Populating Next Right Pointers In Each Node II]/src/Solution.java similarity index 100% rename from "\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221/src/Solution.java" rename to [117][Populating Next Right Pointers In Each Node II]/src/Solution.java diff --git "a/\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221/src/TreeLinkNode.java" b/[117][Populating Next Right Pointers In Each Node II]/src/TreeLinkNode.java similarity index 100% rename from "\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221/src/TreeLinkNode.java" rename to [117][Populating Next Right Pointers In Each Node II]/src/TreeLinkNode.java diff --git "a/\343\200\220118\343\200\221\343\200\220Pascal'sTriangle\343\200\221/src/Solution.java" b/[118][Pascal's Triangle]/src/Solution.java similarity index 100% rename from "\343\200\220118\343\200\221\343\200\220Pascal'sTriangle\343\200\221/src/Solution.java" rename to [118][Pascal's Triangle]/src/Solution.java diff --git "a/\343\200\220119\343\200\221\343\200\220Pascal'sTriangleII\343\200\221/src/Solution.java" b/[119][Pascal's Triangle II]/src/Solution.java similarity index 100% rename from "\343\200\220119\343\200\221\343\200\220Pascal'sTriangleII\343\200\221/src/Solution.java" rename to [119][Pascal's Triangle II]/src/Solution.java diff --git "a/\343\200\220120\343\200\221\343\200\220Triangle\343\200\221/src/Main.java" b/[120][Triangle]/src/Main.java similarity index 100% rename from "\343\200\220120\343\200\221\343\200\220Triangle\343\200\221/src/Main.java" rename to [120][Triangle]/src/Main.java diff --git "a/\343\200\220120\343\200\221\343\200\220Triangle\343\200\221/src/Solution.java" b/[120][Triangle]/src/Solution.java similarity index 100% rename from "\343\200\220120\343\200\221\343\200\220Triangle\343\200\221/src/Solution.java" rename to [120][Triangle]/src/Solution.java diff --git "a/\343\200\220121\343\200\221\343\200\220BestTimeToBuyAndSellStock\343\200\221/src/Solution.java" b/[121][Best Time To Buy And Sell Stock]/src/Solution.java similarity index 100% rename from "\343\200\220121\343\200\221\343\200\220BestTimeToBuyAndSellStock\343\200\221/src/Solution.java" rename to [121][Best Time To Buy And Sell Stock]/src/Solution.java diff --git "a/\343\200\220122\343\200\221\343\200\220Best Time to Buy and Sell Stock II\343\200\221/src/Solution.java" b/[122][Best Time to Buy and Sell Stock II]/src/Solution.java similarity index 100% rename from "\343\200\220122\343\200\221\343\200\220Best Time to Buy and Sell Stock II\343\200\221/src/Solution.java" rename to [122][Best Time to Buy and Sell Stock II]/src/Solution.java diff --git "a/\343\200\220122\343\200\221\343\200\220Best Time to Buy and Sell Stock II\343\200\221/src/Test.java" b/[122][Best Time to Buy and Sell Stock II]/src/Test.java similarity index 100% rename from "\343\200\220122\343\200\221\343\200\220Best Time to Buy and Sell Stock II\343\200\221/src/Test.java" rename to [122][Best Time to Buy and Sell Stock II]/src/Test.java diff --git "a/\343\200\220124\346\234\252\343\200\221\343\200\220BinaryTreeMaximumPathSum\343\200\221/src/Solution.java" b/[124][Binary Tree Maximum Path Sum]/src/Solution.java similarity index 100% rename from "\343\200\220124\346\234\252\343\200\221\343\200\220BinaryTreeMaximumPathSum\343\200\221/src/Solution.java" rename to [124][Binary Tree Maximum Path Sum]/src/Solution.java diff --git "a/\343\200\220124\346\234\252\343\200\221\343\200\220BinaryTreeMaximumPathSum\343\200\221/src/TreeNode.java" b/[124][Binary Tree Maximum Path Sum]/src/TreeNode.java similarity index 100% rename from "\343\200\220124\346\234\252\343\200\221\343\200\220BinaryTreeMaximumPathSum\343\200\221/src/TreeNode.java" rename to [124][Binary Tree Maximum Path Sum]/src/TreeNode.java diff --git "a/\343\200\220125\343\200\221\343\200\220ValidPalindrome\343\200\221/src/Solution.java" b/[125][Valid Palindrome]/src/Solution.java similarity index 100% rename from "\343\200\220125\343\200\221\343\200\220ValidPalindrome\343\200\221/src/Solution.java" rename to [125][Valid Palindrome]/src/Solution.java diff --git "a/\343\200\220127\346\234\252\343\200\221\343\200\220WordLadder\343\200\221/src/Solution.java" b/[127][Word Ladder]/src/Solution.java similarity index 100% rename from "\343\200\220127\346\234\252\343\200\221\343\200\220WordLadder\343\200\221/src/Solution.java" rename to [127][Word Ladder]/src/Solution.java diff --git "a/\343\200\220129\343\200\221\343\200\220SumRootToLeafNumbers\343\200\221/src/Solution.java" b/[129][Sum Root To Leaf Numbers]/src/Solution.java similarity index 100% rename from "\343\200\220129\343\200\221\343\200\220SumRootToLeafNumbers\343\200\221/src/Solution.java" rename to [129][Sum Root To Leaf Numbers]/src/Solution.java diff --git "a/\343\200\220129\343\200\221\343\200\220SumRootToLeafNumbers\343\200\221/src/TreeNode.java" b/[129][Sum Root To Leaf Numbers]/src/TreeNode.java similarity index 100% rename from "\343\200\220129\343\200\221\343\200\220SumRootToLeafNumbers\343\200\221/src/TreeNode.java" rename to [129][Sum Root To Leaf Numbers]/src/TreeNode.java diff --git "a/\343\200\220130\343\200\221\343\200\220SurroundedRegions\343\200\221/src/Main.java" b/[130][Surrounded Regions]/src/Main.java similarity index 100% rename from "\343\200\220130\343\200\221\343\200\220SurroundedRegions\343\200\221/src/Main.java" rename to [130][Surrounded Regions]/src/Main.java diff --git "a/\343\200\220130\343\200\221\343\200\220SurroundedRegions\343\200\221/src/Solution.java" b/[130][Surrounded Regions]/src/Solution.java similarity index 100% rename from "\343\200\220130\343\200\221\343\200\220SurroundedRegions\343\200\221/src/Solution.java" rename to [130][Surrounded Regions]/src/Solution.java diff --git "a/\343\200\220134\343\200\221\343\200\220GasStation\343\200\221/src/Solution.java" b/[134][Gas Station]/src/Solution.java similarity index 100% rename from "\343\200\220134\343\200\221\343\200\220GasStation\343\200\221/src/Solution.java" rename to [134][Gas Station]/src/Solution.java diff --git "a/\343\200\220136\343\200\221\343\200\220SingleNumber\343\200\221/src/Solution.java" b/[136][Single Number]/src/Solution.java similarity index 100% rename from "\343\200\220136\343\200\221\343\200\220SingleNumber\343\200\221/src/Solution.java" rename to [136][Single Number]/src/Solution.java diff --git "a/\343\200\220137\343\200\221\343\200\220SingleNumberII\343\200\221/src/Solution.java" b/[137][Single Number II]/src/Solution.java similarity index 100% rename from "\343\200\220137\343\200\221\343\200\220SingleNumberII\343\200\221/src/Solution.java" rename to [137][Single Number II]/src/Solution.java diff --git "a/\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/src/Main.java" b/[138][Copy List With Random Pointer]/src/Main.java similarity index 100% rename from "\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/src/Main.java" rename to [138][Copy List With Random Pointer]/src/Main.java diff --git "a/\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/src/RandomListNode.java" b/[138][Copy List With Random Pointer]/src/RandomListNode.java similarity index 100% rename from "\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/src/RandomListNode.java" rename to [138][Copy List With Random Pointer]/src/RandomListNode.java diff --git "a/\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/src/Solution.java" b/[138][Copy List With Random Pointer]/src/Solution.java similarity index 100% rename from "\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/src/Solution.java" rename to [138][Copy List With Random Pointer]/src/Solution.java diff --git "a/\343\200\220139\343\200\221\343\200\220WordBreak\343\200\221/src/Main.java" b/[139][Word Break]/src/Main.java similarity index 100% rename from "\343\200\220139\343\200\221\343\200\220WordBreak\343\200\221/src/Main.java" rename to [139][Word Break]/src/Main.java diff --git "a/\343\200\220139\343\200\221\343\200\220WordBreak\343\200\221/src/Solution.java" b/[139][Word Break]/src/Solution.java similarity index 100% rename from "\343\200\220139\343\200\221\343\200\220WordBreak\343\200\221/src/Solution.java" rename to [139][Word Break]/src/Solution.java diff --git "a/\343\200\220141\343\200\221\343\200\220LinkedListCycle\343\200\221/src/ListNode.java" b/[141][Linked List Cycle]/src/ListNode.java similarity index 100% rename from "\343\200\220141\343\200\221\343\200\220LinkedListCycle\343\200\221/src/ListNode.java" rename to [141][Linked List Cycle]/src/ListNode.java diff --git "a/\343\200\220141\343\200\221\343\200\220LinkedListCycle\343\200\221/src/Solution.java" b/[141][Linked List Cycle]/src/Solution.java similarity index 100% rename from "\343\200\220141\343\200\221\343\200\220LinkedListCycle\343\200\221/src/Solution.java" rename to [141][Linked List Cycle]/src/Solution.java diff --git "a/\343\200\220142\343\200\221\343\200\220LinkedListCycleII\343\200\221/src/ListNode.java" b/[142][Linked List Cycle II]/src/ListNode.java similarity index 100% rename from "\343\200\220142\343\200\221\343\200\220LinkedListCycleII\343\200\221/src/ListNode.java" rename to [142][Linked List Cycle II]/src/ListNode.java diff --git "a/\343\200\220142\343\200\221\343\200\220LinkedListCycleII\343\200\221/src/Solution.java" b/[142][Linked List Cycle II]/src/Solution.java similarity index 100% rename from "\343\200\220142\343\200\221\343\200\220LinkedListCycleII\343\200\221/src/Solution.java" rename to [142][Linked List Cycle II]/src/Solution.java diff --git "a/\343\200\220143\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/src/RandomListNode.java" b/[143][Copy List With Random Pointer]/src/RandomListNode.java similarity index 100% rename from "\343\200\220143\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/src/RandomListNode.java" rename to [143][Copy List With Random Pointer]/src/RandomListNode.java diff --git "a/\343\200\220143\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/src/Solution.java" b/[143][Copy List With Random Pointer]/src/Solution.java similarity index 100% rename from "\343\200\220143\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/src/Solution.java" rename to [143][Copy List With Random Pointer]/src/Solution.java diff --git "a/\343\200\220144\343\200\221\343\200\220BinaryTreePreorderTraversal\343\200\221/src/Solution.java" b/[144][Binary Tree Preorder Traversal]/src/Solution.java similarity index 100% rename from "\343\200\220144\343\200\221\343\200\220BinaryTreePreorderTraversal\343\200\221/src/Solution.java" rename to [144][Binary Tree Preorder Traversal]/src/Solution.java diff --git "a/\343\200\220144\343\200\221\343\200\220BinaryTreePreorderTraversal\343\200\221/src/TreeNode.java" b/[144][Binary Tree Preorder Traversal]/src/TreeNode.java similarity index 100% rename from "\343\200\220144\343\200\221\343\200\220BinaryTreePreorderTraversal\343\200\221/src/TreeNode.java" rename to [144][Binary Tree Preorder Traversal]/src/TreeNode.java diff --git "a/\343\200\220145\343\200\221\343\200\220BinaryTreePostorderTraversal\343\200\221/src/Solution.java" b/[145][Binary Tree Postorder Traversal]/src/Solution.java similarity index 100% rename from "\343\200\220145\343\200\221\343\200\220BinaryTreePostorderTraversal\343\200\221/src/Solution.java" rename to [145][Binary Tree Postorder Traversal]/src/Solution.java diff --git "a/\343\200\220145\343\200\221\343\200\220BinaryTreePostorderTraversal\343\200\221/src/TreeNode.java" b/[145][Binary Tree Postorder Traversal]/src/TreeNode.java similarity index 100% rename from "\343\200\220145\343\200\221\343\200\220BinaryTreePostorderTraversal\343\200\221/src/TreeNode.java" rename to [145][Binary Tree Postorder Traversal]/src/TreeNode.java diff --git "a/\343\200\220147\343\200\221\343\200\220InsertionSortList\343\200\221/src/ListNode.java" b/[147][Insertion Sort List]/src/ListNode.java similarity index 100% rename from "\343\200\220147\343\200\221\343\200\220InsertionSortList\343\200\221/src/ListNode.java" rename to [147][Insertion Sort List]/src/ListNode.java diff --git "a/\343\200\220147\343\200\221\343\200\220InsertionSortList\343\200\221/src/Solution.java" b/[147][Insertion Sort List]/src/Solution.java similarity index 100% rename from "\343\200\220147\343\200\221\343\200\220InsertionSortList\343\200\221/src/Solution.java" rename to [147][Insertion Sort List]/src/Solution.java diff --git "a/\343\200\220150\343\200\221\343\200\220EvaluateReversePolishNotation\343\200\221/src/Main.java" b/[150][Evaluate Reverse Polish Notation]/src/Main.java similarity index 100% rename from "\343\200\220150\343\200\221\343\200\220EvaluateReversePolishNotation\343\200\221/src/Main.java" rename to [150][Evaluate Reverse Polish Notation]/src/Main.java diff --git "a/\343\200\220150\343\200\221\343\200\220EvaluateReversePolishNotation\343\200\221/src/Solution.java" b/[150][Evaluate Reverse Polish Notation]/src/Solution.java similarity index 100% rename from "\343\200\220150\343\200\221\343\200\220EvaluateReversePolishNotation\343\200\221/src/Solution.java" rename to [150][Evaluate Reverse Polish Notation]/src/Solution.java diff --git "a/\343\200\220151\343\200\221\343\200\220ReverseWordsInAString\343\200\221/src/Main.java" b/[151][Reverse Words In A String]/src/Main.java similarity index 100% rename from "\343\200\220151\343\200\221\343\200\220ReverseWordsInAString\343\200\221/src/Main.java" rename to [151][Reverse Words In A String]/src/Main.java diff --git "a/\343\200\220151\343\200\221\343\200\220ReverseWordsInAString\343\200\221/src/Solution.java" b/[151][Reverse Words In A String]/src/Solution.java similarity index 100% rename from "\343\200\220151\343\200\221\343\200\220ReverseWordsInAString\343\200\221/src/Solution.java" rename to [151][Reverse Words In A String]/src/Solution.java diff --git "a/\343\200\220152\343\200\221\343\200\220MaximumProductSubarray\343\200\221/src/Main.java" b/[152][Maximum Product Subarray]/src/Main.java similarity index 100% rename from "\343\200\220152\343\200\221\343\200\220MaximumProductSubarray\343\200\221/src/Main.java" rename to [152][Maximum Product Subarray]/src/Main.java diff --git "a/\343\200\220152\343\200\221\343\200\220MaximumProductSubarray\343\200\221/src/Solution.java" b/[152][Maximum Product Subarray]/src/Solution.java similarity index 100% rename from "\343\200\220152\343\200\221\343\200\220MaximumProductSubarray\343\200\221/src/Solution.java" rename to [152][Maximum Product Subarray]/src/Solution.java diff --git "a/\343\200\220153\343\200\221\343\200\220FindMinimumInRotatedSortedArray\343\200\221/src/Main.java" b/[153][Find Minimum In Rotated Sorted Array]/src/Main.java similarity index 100% rename from "\343\200\220153\343\200\221\343\200\220FindMinimumInRotatedSortedArray\343\200\221/src/Main.java" rename to [153][Find Minimum In Rotated Sorted Array]/src/Main.java diff --git "a/\343\200\220153\343\200\221\343\200\220FindMinimumInRotatedSortedArray\343\200\221/src/Solution.java" b/[153][Find Minimum In Rotated Sorted Array]/src/Solution.java similarity index 100% rename from "\343\200\220153\343\200\221\343\200\220FindMinimumInRotatedSortedArray\343\200\221/src/Solution.java" rename to [153][Find Minimum In Rotated Sorted Array]/src/Solution.java diff --git "a/\343\200\220154\343\200\221\343\200\220FindMinimumInRotatedSortedArrayII\343\200\221/src/Main.java" b/[154][Find Minimum In Rotated Sorted Array II]/src/Main.java similarity index 100% rename from "\343\200\220154\343\200\221\343\200\220FindMinimumInRotatedSortedArrayII\343\200\221/src/Main.java" rename to [154][Find Minimum In Rotated Sorted Array II]/src/Main.java diff --git "a/\343\200\220154\343\200\221\343\200\220FindMinimumInRotatedSortedArrayII\343\200\221/src/Solution.java" b/[154][Find Minimum In Rotated Sorted Array II]/src/Solution.java similarity index 100% rename from "\343\200\220154\343\200\221\343\200\220FindMinimumInRotatedSortedArrayII\343\200\221/src/Solution.java" rename to [154][Find Minimum In Rotated Sorted Array II]/src/Solution.java diff --git "a/\343\200\220155\343\200\221\343\200\220MinStack\343\200\221/src/MinStack.java" b/[155][Min Stack]/src/MinStack.java similarity index 100% rename from "\343\200\220155\343\200\221\343\200\220MinStack\343\200\221/src/MinStack.java" rename to [155][Min Stack]/src/MinStack.java diff --git "a/\343\200\220162\346\234\252\343\200\221\343\200\220FindPeakElement\343\200\221/src/Solution.java" b/[162][Find Peak Element]/src/Solution.java similarity index 100% rename from "\343\200\220162\346\234\252\343\200\221\343\200\220FindPeakElement\343\200\221/src/Solution.java" rename to [162][Find Peak Element]/src/Solution.java diff --git "a/\343\200\220167\343\200\221\343\200\220Two Sum II - Input array is sorted\343\200\221/src/Solution.java" b/[167][Two Sum II - Input array is sorted]/src/Solution.java similarity index 100% rename from "\343\200\220167\343\200\221\343\200\220Two Sum II - Input array is sorted\343\200\221/src/Solution.java" rename to [167][Two Sum II - Input array is sorted]/src/Solution.java diff --git "a/\343\200\220191\343\200\221\343\200\220NumberOf1Bits\343\200\221/src/Main.java" b/[191][Number Of 1 Bits]/src/Main.java similarity index 100% rename from "\343\200\220191\343\200\221\343\200\220NumberOf1Bits\343\200\221/src/Main.java" rename to [191][Number Of 1 Bits]/src/Main.java diff --git "a/\343\200\220191\343\200\221\343\200\220NumberOf1Bits\343\200\221/src/Solution.java" b/[191][Number Of 1 Bits]/src/Solution.java similarity index 100% rename from "\343\200\220191\343\200\221\343\200\220NumberOf1Bits\343\200\221/src/Solution.java" rename to [191][Number Of 1 Bits]/src/Solution.java diff --git "a/\343\200\220198\343\200\221\343\200\220HouseRobber\343\200\221/src/Main.java" b/[198][House Robber]/src/Main.java similarity index 100% rename from "\343\200\220198\343\200\221\343\200\220HouseRobber\343\200\221/src/Main.java" rename to [198][House Robber]/src/Main.java diff --git "a/\343\200\220198\343\200\221\343\200\220HouseRobber\343\200\221/src/Solution.java" b/[198][House Robber]/src/Solution.java similarity index 100% rename from "\343\200\220198\343\200\221\343\200\220HouseRobber\343\200\221/src/Solution.java" rename to [198][House Robber]/src/Solution.java diff --git "a/\343\200\220199\343\200\221\343\200\220BinaryTreeRightSideView\343\200\221/src/Solution.java" b/[199][Binary Tree Right Side View]/src/Solution.java similarity index 100% rename from "\343\200\220199\343\200\221\343\200\220BinaryTreeRightSideView\343\200\221/src/Solution.java" rename to [199][Binary Tree Right Side View]/src/Solution.java diff --git "a/\343\200\220199\343\200\221\343\200\220BinaryTreeRightSideView\343\200\221/src/TreeNode.java" b/[199][Binary Tree Right Side View]/src/TreeNode.java similarity index 100% rename from "\343\200\220199\343\200\221\343\200\220BinaryTreeRightSideView\343\200\221/src/TreeNode.java" rename to [199][Binary Tree Right Side View]/src/TreeNode.java diff --git "a/\343\200\220200\343\200\221\343\200\220NumberOfIslands\343\200\221/src/Solution.java" b/[200][Number Of Islands]/src/Solution.java similarity index 100% rename from "\343\200\220200\343\200\221\343\200\220NumberOfIslands\343\200\221/src/Solution.java" rename to [200][Number Of Islands]/src/Solution.java diff --git "a/\343\200\220201\343\200\221\343\200\220BitwiseANDOfNumbersRange\343\200\221/src/Solution.java" b/[201][Bitwise AND Of Numbers Range]/src/Solution.java similarity index 100% rename from "\343\200\220201\343\200\221\343\200\220BitwiseANDOfNumbersRange\343\200\221/src/Solution.java" rename to [201][Bitwise AND Of Numbers Range]/src/Solution.java diff --git "a/\343\200\220202\343\200\221\343\200\220HappyNumber \343\200\221/src/Main.java" b/[202][Happy Number ]/src/Main.java similarity index 100% rename from "\343\200\220202\343\200\221\343\200\220HappyNumber \343\200\221/src/Main.java" rename to [202][Happy Number ]/src/Main.java diff --git "a/\343\200\220202\343\200\221\343\200\220HappyNumber \343\200\221/src/Solution.java" b/[202][Happy Number ]/src/Solution.java similarity index 100% rename from "\343\200\220202\343\200\221\343\200\220HappyNumber \343\200\221/src/Solution.java" rename to [202][Happy Number ]/src/Solution.java diff --git "a/\343\200\220203\343\200\221\343\200\220RemoveLinkedList Elements\343\200\221/src/ListNode.java" b/[203][Remove Linked List Elements]/src/ListNode.java similarity index 100% rename from "\343\200\220203\343\200\221\343\200\220RemoveLinkedList Elements\343\200\221/src/ListNode.java" rename to [203][Remove Linked List Elements]/src/ListNode.java diff --git "a/\343\200\220203\343\200\221\343\200\220RemoveLinkedList Elements\343\200\221/src/Solution.java" b/[203][Remove Linked List Elements]/src/Solution.java similarity index 100% rename from "\343\200\220203\343\200\221\343\200\220RemoveLinkedList Elements\343\200\221/src/Solution.java" rename to [203][Remove Linked List Elements]/src/Solution.java diff --git "a/\343\200\220204\343\200\221\343\200\220CountPrimes\343\200\221/src/Solution.java" b/[204][Count Primes]/src/Solution.java similarity index 100% rename from "\343\200\220204\343\200\221\343\200\220CountPrimes\343\200\221/src/Solution.java" rename to [204][Count Primes]/src/Solution.java diff --git "a/\343\200\220205\343\200\221\343\200\220IsomorphicStrings\343\200\221/src/Solution.java" b/[205][Isomorphic Strings]/src/Solution.java similarity index 100% rename from "\343\200\220205\343\200\221\343\200\220IsomorphicStrings\343\200\221/src/Solution.java" rename to [205][Isomorphic Strings]/src/Solution.java diff --git "a/\343\200\220206\343\200\221\343\200\220ReverseLinkedList\343\200\221/src/ListNode.java" b/[206][Reverse Linked List]/src/ListNode.java similarity index 100% rename from "\343\200\220206\343\200\221\343\200\220ReverseLinkedList\343\200\221/src/ListNode.java" rename to [206][Reverse Linked List]/src/ListNode.java diff --git "a/\343\200\220206\343\200\221\343\200\220ReverseLinkedList\343\200\221/src/Main.java" b/[206][Reverse Linked List]/src/Main.java similarity index 100% rename from "\343\200\220206\343\200\221\343\200\220ReverseLinkedList\343\200\221/src/Main.java" rename to [206][Reverse Linked List]/src/Main.java diff --git "a/\343\200\220206\343\200\221\343\200\220ReverseLinkedList\343\200\221/src/Solution.java" b/[206][Reverse Linked List]/src/Solution.java similarity index 100% rename from "\343\200\220206\343\200\221\343\200\220ReverseLinkedList\343\200\221/src/Solution.java" rename to [206][Reverse Linked List]/src/Solution.java diff --git "a/\343\200\220215\343\200\221\343\200\220KthLargestElementInAnArray\343\200\221/src/Main.java" b/[215][Kth Largest Element In An Array]/src/Main.java similarity index 100% rename from "\343\200\220215\343\200\221\343\200\220KthLargestElementInAnArray\343\200\221/src/Main.java" rename to [215][Kth Largest Element In An Array]/src/Main.java diff --git "a/\343\200\220215\343\200\221\343\200\220KthLargestElementInAnArray\343\200\221/src/Solution.java" b/[215][Kth Largest Element In An Array]/src/Solution.java similarity index 100% rename from "\343\200\220215\343\200\221\343\200\220KthLargestElementInAnArray\343\200\221/src/Solution.java" rename to [215][Kth Largest Element In An Array]/src/Solution.java diff --git "a/\343\200\220216\343\200\221\343\200\220CombinationSumIII\343\200\221/src/Main.java" b/[216][Combination Sum III]/src/Main.java similarity index 100% rename from "\343\200\220216\343\200\221\343\200\220CombinationSumIII\343\200\221/src/Main.java" rename to [216][Combination Sum III]/src/Main.java diff --git "a/\343\200\220216\343\200\221\343\200\220CombinationSumIII\343\200\221/src/Solution.java" b/[216][Combination Sum III]/src/Solution.java similarity index 100% rename from "\343\200\220216\343\200\221\343\200\220CombinationSumIII\343\200\221/src/Solution.java" rename to [216][Combination Sum III]/src/Solution.java diff --git "a/\343\200\220217\343\200\221\343\200\220ContainsDuplicate \343\200\221/src/Main.java" b/[217][Contains Duplicate ]/src/Main.java similarity index 100% rename from "\343\200\220217\343\200\221\343\200\220ContainsDuplicate \343\200\221/src/Main.java" rename to [217][Contains Duplicate ]/src/Main.java diff --git "a/\343\200\220217\343\200\221\343\200\220ContainsDuplicate \343\200\221/src/Solution.java" b/[217][Contains Duplicate ]/src/Solution.java similarity index 100% rename from "\343\200\220217\343\200\221\343\200\220ContainsDuplicate \343\200\221/src/Solution.java" rename to [217][Contains Duplicate ]/src/Solution.java diff --git "a/\343\200\220219\343\200\221\343\200\220ContainsDuplicateII\343\200\221/src/Solution.java" b/[219][Contains Duplicate II]/src/Solution.java similarity index 100% rename from "\343\200\220219\343\200\221\343\200\220ContainsDuplicateII\343\200\221/src/Solution.java" rename to [219][Contains Duplicate II]/src/Solution.java diff --git "a/\343\200\220223\343\200\221\343\200\220RectangleArea\343\200\221/src/Main.java" b/[223][Rectangle Area]/src/Main.java similarity index 100% rename from "\343\200\220223\343\200\221\343\200\220RectangleArea\343\200\221/src/Main.java" rename to [223][Rectangle Area]/src/Main.java diff --git "a/\343\200\220223\343\200\221\343\200\220RectangleArea\343\200\221/src/Solution.java" b/[223][Rectangle Area]/src/Solution.java similarity index 100% rename from "\343\200\220223\343\200\221\343\200\220RectangleArea\343\200\221/src/Solution.java" rename to [223][Rectangle Area]/src/Solution.java diff --git "a/\343\200\220225\343\200\221\343\200\220ImplementStackUsingQueues\343\200\221/src/MyStack.java" b/[225][Implement Stack Using Queues]/src/MyStack.java similarity index 100% rename from "\343\200\220225\343\200\221\343\200\220ImplementStackUsingQueues\343\200\221/src/MyStack.java" rename to [225][Implement Stack Using Queues]/src/MyStack.java diff --git "a/\343\200\220226\343\200\221\343\200\220InvertBinaryTree \343\200\221/src/Solution.java" b/[226][Invert Binary Tree]/src/Solution.java similarity index 100% rename from "\343\200\220226\343\200\221\343\200\220InvertBinaryTree \343\200\221/src/Solution.java" rename to [226][Invert Binary Tree]/src/Solution.java diff --git "a/\343\200\220226\343\200\221\343\200\220InvertBinaryTree \343\200\221/src/TreeNode.java" b/[226][Invert Binary Tree]/src/TreeNode.java similarity index 100% rename from "\343\200\220226\343\200\221\343\200\220InvertBinaryTree \343\200\221/src/TreeNode.java" rename to [226][Invert Binary Tree]/src/TreeNode.java diff --git "a/\343\200\220231\343\200\221\343\200\220Power of Two\343\200\221/src/Solution.java" b/[231][Power of Two]/src/Solution.java similarity index 100% rename from "\343\200\220231\343\200\221\343\200\220Power of Two\343\200\221/src/Solution.java" rename to [231][Power of Two]/src/Solution.java diff --git "a/\343\200\220231\343\200\221\343\200\220Power of Two\343\200\221/src/Test.java" b/[231][Power of Two]/src/Test.java similarity index 100% rename from "\343\200\220231\343\200\221\343\200\220Power of Two\343\200\221/src/Test.java" rename to [231][Power of Two]/src/Test.java diff --git "a/\343\200\220232\343\200\221\343\200\220Implement Queue using Stacks\343\200\221/src/MyQueue.java" b/[232][Implement Queue using Stacks]/src/MyQueue.java similarity index 100% rename from "\343\200\220232\343\200\221\343\200\220Implement Queue using Stacks\343\200\221/src/MyQueue.java" rename to [232][Implement Queue using Stacks]/src/MyQueue.java diff --git "a/\343\200\220232\343\200\221\343\200\220Implement Queue using Stacks\343\200\221/src/Test.java" b/[232][Implement Queue using Stacks]/src/Test.java similarity index 100% rename from "\343\200\220232\343\200\221\343\200\220Implement Queue using Stacks\343\200\221/src/Test.java" rename to [232][Implement Queue using Stacks]/src/Test.java diff --git "a/\343\200\220234\343\200\221\343\200\220Palindrome Linked List\343\200\221/src/ListNode.java" b/[234][Palindrome Linked List]/src/ListNode.java similarity index 100% rename from "\343\200\220234\343\200\221\343\200\220Palindrome Linked List\343\200\221/src/ListNode.java" rename to [234][Palindrome Linked List]/src/ListNode.java diff --git "a/\343\200\220234\343\200\221\343\200\220Palindrome Linked List\343\200\221/src/Solution.java" b/[234][Palindrome Linked List]/src/Solution.java similarity index 100% rename from "\343\200\220234\343\200\221\343\200\220Palindrome Linked List\343\200\221/src/Solution.java" rename to [234][Palindrome Linked List]/src/Solution.java diff --git "a/\343\200\220234\343\200\221\343\200\220Palindrome Linked List\343\200\221/src/Solution2.java" b/[234][Palindrome Linked List]/src/Solution2.java similarity index 100% rename from "\343\200\220234\343\200\221\343\200\220Palindrome Linked List\343\200\221/src/Solution2.java" rename to [234][Palindrome Linked List]/src/Solution2.java diff --git "a/\343\200\220234\343\200\221\343\200\220Palindrome Linked List\343\200\221/src/Test.java" b/[234][Palindrome Linked List]/src/Test.java similarity index 100% rename from "\343\200\220234\343\200\221\343\200\220Palindrome Linked List\343\200\221/src/Test.java" rename to [234][Palindrome Linked List]/src/Test.java diff --git "a/\343\200\220235\343\200\221\343\200\220Lowest Common Ancestor of a Binary Search Tree\343\200\221/src/Solution.java" b/[235][Lowest Common Ancestor of a Binary Search Tree]/src/Solution.java similarity index 100% rename from "\343\200\220235\343\200\221\343\200\220Lowest Common Ancestor of a Binary Search Tree\343\200\221/src/Solution.java" rename to [235][Lowest Common Ancestor of a Binary Search Tree]/src/Solution.java diff --git "a/\343\200\220235\343\200\221\343\200\220Lowest Common Ancestor of a Binary Search Tree\343\200\221/src/TreeNode.java" b/[235][Lowest Common Ancestor of a Binary Search Tree]/src/TreeNode.java similarity index 100% rename from "\343\200\220235\343\200\221\343\200\220Lowest Common Ancestor of a Binary Search Tree\343\200\221/src/TreeNode.java" rename to [235][Lowest Common Ancestor of a Binary Search Tree]/src/TreeNode.java diff --git "a/\343\200\220237\343\200\221\343\200\220Delete Node in a Linked List\343\200\221/src/ListNode.java" b/[237][Delete Node in a Linked List]/src/ListNode.java similarity index 100% rename from "\343\200\220237\343\200\221\343\200\220Delete Node in a Linked List\343\200\221/src/ListNode.java" rename to [237][Delete Node in a Linked List]/src/ListNode.java diff --git "a/\343\200\220237\343\200\221\343\200\220Delete Node in a Linked List\343\200\221/src/Solution.java" b/[237][Delete Node in a Linked List]/src/Solution.java similarity index 100% rename from "\343\200\220237\343\200\221\343\200\220Delete Node in a Linked List\343\200\221/src/Solution.java" rename to [237][Delete Node in a Linked List]/src/Solution.java diff --git "a/\343\200\220237\343\200\221\343\200\220Delete Node in a Linked List\343\200\221/src/Test.java" b/[237][Delete Node in a Linked List]/src/Test.java similarity index 100% rename from "\343\200\220237\343\200\221\343\200\220Delete Node in a Linked List\343\200\221/src/Test.java" rename to [237][Delete Node in a Linked List]/src/Test.java diff --git "a/\343\200\220242\343\200\221\343\200\220Valid Anagram\343\200\221/src/Solution.java" b/[242][Valid Anagram]/src/Solution.java similarity index 100% rename from "\343\200\220242\343\200\221\343\200\220Valid Anagram\343\200\221/src/Solution.java" rename to [242][Valid Anagram]/src/Solution.java diff --git "a/\343\200\220242\343\200\221\343\200\220Valid Anagram\343\200\221/src/Test.java" b/[242][Valid Anagram]/src/Test.java similarity index 100% rename from "\343\200\220242\343\200\221\343\200\220Valid Anagram\343\200\221/src/Test.java" rename to [242][Valid Anagram]/src/Test.java diff --git "a/\343\200\220257\343\200\221\343\200\220Binary Tree Paths\343\200\221/src/Solution.java" b/[257][Binary Tree Paths]/src/Solution.java similarity index 100% rename from "\343\200\220257\343\200\221\343\200\220Binary Tree Paths\343\200\221/src/Solution.java" rename to [257][Binary Tree Paths]/src/Solution.java diff --git "a/\343\200\220257\343\200\221\343\200\220Binary Tree Paths\343\200\221/src/Test.java" b/[257][Binary Tree Paths]/src/Test.java similarity index 100% rename from "\343\200\220257\343\200\221\343\200\220Binary Tree Paths\343\200\221/src/Test.java" rename to [257][Binary Tree Paths]/src/Test.java diff --git "a/\343\200\220257\343\200\221\343\200\220Binary Tree Paths\343\200\221/src/TreeNode.java" b/[257][Binary Tree Paths]/src/TreeNode.java similarity index 100% rename from "\343\200\220257\343\200\221\343\200\220Binary Tree Paths\343\200\221/src/TreeNode.java" rename to [257][Binary Tree Paths]/src/TreeNode.java diff --git "a/\343\200\220258\343\200\221\343\200\220Add Digits\343\200\221/src/Solution.java" b/[258][Add Digits]/src/Solution.java similarity index 100% rename from "\343\200\220258\343\200\221\343\200\220Add Digits\343\200\221/src/Solution.java" rename to [258][Add Digits]/src/Solution.java diff --git "a/\343\200\220258\343\200\221\343\200\220Add Digits\343\200\221/src/Test.java" b/[258][Add Digits]/src/Test.java similarity index 100% rename from "\343\200\220258\343\200\221\343\200\220Add Digits\343\200\221/src/Test.java" rename to [258][Add Digits]/src/Test.java diff --git "a/\343\200\220263\343\200\221\343\200\220Ugly Number\343\200\221/src/Solution.java" b/[263][Ugly Number]/src/Solution.java similarity index 100% rename from "\343\200\220263\343\200\221\343\200\220Ugly Number\343\200\221/src/Solution.java" rename to [263][Ugly Number]/src/Solution.java diff --git "a/\343\200\220263\343\200\221\343\200\220Ugly Number\343\200\221/src/Test.java" b/[263][Ugly Number]/src/Test.java similarity index 100% rename from "\343\200\220263\343\200\221\343\200\220Ugly Number\343\200\221/src/Test.java" rename to [263][Ugly Number]/src/Test.java diff --git "a/\343\200\220268\343\200\221\343\200\220Missing Number\343\200\221/src/Solution.java" b/[268][Missing Number]/src/Solution.java similarity index 100% rename from "\343\200\220268\343\200\221\343\200\220Missing Number\343\200\221/src/Solution.java" rename to [268][Missing Number]/src/Solution.java diff --git "a/\343\200\220268\343\200\221\343\200\220Missing Number\343\200\221/src/Test.java" b/[268][Missing Number]/src/Test.java similarity index 100% rename from "\343\200\220268\343\200\221\343\200\220Missing Number\343\200\221/src/Test.java" rename to [268][Missing Number]/src/Test.java diff --git "a/\343\200\220278\343\200\221\343\200\220First Bad Version\343\200\221/src/Solution.java" b/[278][First Bad Version]/src/Solution.java similarity index 100% rename from "\343\200\220278\343\200\221\343\200\220First Bad Version\343\200\221/src/Solution.java" rename to [278][First Bad Version]/src/Solution.java diff --git "a/\343\200\220278\343\200\221\343\200\220First Bad Version\343\200\221/src/Test.java" b/[278][First Bad Version]/src/Test.java similarity index 100% rename from "\343\200\220278\343\200\221\343\200\220First Bad Version\343\200\221/src/Test.java" rename to [278][First Bad Version]/src/Test.java diff --git "a/\343\200\220278\343\200\221\343\200\220First Bad Version\343\200\221/src/VersionControl.java" b/[278][First Bad Version]/src/VersionControl.java similarity index 100% rename from "\343\200\220278\343\200\221\343\200\220First Bad Version\343\200\221/src/VersionControl.java" rename to [278][First Bad Version]/src/VersionControl.java diff --git "a/\343\200\220283\343\200\221\343\200\220Move Zeroes\343\200\221/src/Solution.java" b/[283][Move Zeroes]/src/Solution.java similarity index 100% rename from "\343\200\220283\343\200\221\343\200\220Move Zeroes\343\200\221/src/Solution.java" rename to [283][Move Zeroes]/src/Solution.java diff --git "a/\343\200\220283\343\200\221\343\200\220Move Zeroes\343\200\221/src/Test.java" b/[283][Move Zeroes]/src/Test.java similarity index 100% rename from "\343\200\220283\343\200\221\343\200\220Move Zeroes\343\200\221/src/Test.java" rename to [283][Move Zeroes]/src/Test.java diff --git "a/\343\200\220290\343\200\221\343\200\220Word Pattern\343\200\221/src/Solution.java" b/[290][Word Pattern]/src/Solution.java similarity index 100% rename from "\343\200\220290\343\200\221\343\200\220Word Pattern\343\200\221/src/Solution.java" rename to [290][Word Pattern]/src/Solution.java diff --git "a/\343\200\220290\343\200\221\343\200\220Word Pattern\343\200\221/src/Test.java" b/[290][Word Pattern]/src/Test.java similarity index 100% rename from "\343\200\220290\343\200\221\343\200\220Word Pattern\343\200\221/src/Test.java" rename to [290][Word Pattern]/src/Test.java diff --git "a/\343\200\220303\343\200\221\343\200\220Range Sum Query - Immutable\343\200\221/src/NumArray.java" b/[303][Range Sum Query - Immutable]/src/NumArray.java similarity index 100% rename from "\343\200\220303\343\200\221\343\200\220Range Sum Query - Immutable\343\200\221/src/NumArray.java" rename to [303][Range Sum Query - Immutable]/src/NumArray.java diff --git "a/\343\200\220303\343\200\221\343\200\220Range Sum Query - Immutable\343\200\221/src/Test.java" b/[303][Range Sum Query - Immutable]/src/Test.java similarity index 100% rename from "\343\200\220303\343\200\221\343\200\220Range Sum Query - Immutable\343\200\221/src/Test.java" rename to [303][Range Sum Query - Immutable]/src/Test.java diff --git "a/\343\200\220326\343\200\221\343\200\220Power of Three\343\200\221/src/Solution.java" b/[326][Power of Three]/src/Solution.java similarity index 100% rename from "\343\200\220326\343\200\221\343\200\220Power of Three\343\200\221/src/Solution.java" rename to [326][Power of Three]/src/Solution.java diff --git "a/\343\200\220326\343\200\221\343\200\220Power of Three\343\200\221/src/Test.java" b/[326][Power of Three]/src/Test.java similarity index 100% rename from "\343\200\220326\343\200\221\343\200\220Power of Three\343\200\221/src/Test.java" rename to [326][Power of Three]/src/Test.java diff --git "a/\343\200\220342\343\200\221\343\200\220Power of Four\343\200\221/src/Solution.java" b/[342][Power of Four]/src/Solution.java similarity index 100% rename from "\343\200\220342\343\200\221\343\200\220Power of Four\343\200\221/src/Solution.java" rename to [342][Power of Four]/src/Solution.java diff --git "a/\343\200\220344\343\200\221\343\200\220Reverse String\343\200\221/src/Solution.java" b/[344][Reverse String]/src/Solution.java similarity index 100% rename from "\343\200\220344\343\200\221\343\200\220Reverse String\343\200\221/src/Solution.java" rename to [344][Reverse String]/src/Solution.java diff --git "a/out/production/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221/Main.class" "b/out/production/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221/Main.class" deleted file mode 100644 index 7297ec1a56e6d1d6caf4d34bcd733a4f8693915d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 847 zcmaJ4%w^pq-f1kPzaB0u8=PX-R1{{sMoG ze&`Zs`~m(b<9W-HsUtS&xu54e=j8qQ>)Q_iyLhT&8C8yT9T`-m*vR7=u5;Ybp`xnc zrqs8jFg4UPY)W%W$2N92>KqLQbx-&rdd8rbwGKn}c`$StmMr1Buj6sw4c|I_k0J#t z7&ud=lG+B9fiUlHB)pa98rC7PMT0c zcN%*UL#Eea(Cr`&2kr|Yhvy}JT|yc-j{<{c2VNYBz&CIkcR21ExQAVa)qltC$HE)B zAp`3fxQ_=?JS1kk=r%sIz76FMPIjcaDB_MfyC1+xn? zte9sD380uR^fw_|Wg_W$v~X!2p$^uuMDI&}88CTvl11_wq#5bl<`LMJG`&JnO@kaI zvW-~*%2*{Yj|;d+5!w71If4UT9V62{g2KP+T}5ekv%KBSsqL<+w3P%|>nn1{P^p3! zv;_GrrJg`9EJ!n(ng*E(&LvnprLYJk9aq5uUJ?mOr92ylOSnv4g`WNzt`Hf9tK?@; F`3?T-w8#Je diff --git "a/out/production/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221/Solution$Node.class" "b/out/production/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221/Solution$Node.class" deleted file mode 100644 index 5a6d57e13c432fc9283d8649832fc4e799ab2c24..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 837 zcmZXS(QDIC6vn@sw9OLJCU)K2?9{4LyB6HTe36ZT6of*Z51j)aZ__X{vt*>{@Q>Py z;1qli-v;}m#P8l_c2q*n%{@8i`+eso*MENg0`Lki98~boMhTBpXjypTaD8fF)50?W z^IXOPqR*#j{6(O$7bQ`?&ux3_NTAe9$Dx2Xh?4MNdO8ZTLph3>sSnaX#z!)X)V@fT z@=wu(O$WNk?I%f?^n|14#T~dVmSDSZU|V>8t3nUwVg;)L{-Q&H#ymCW3oP9L(Bjvr zK)`~*4@d?h6o#?HJkg9*?sm8euI0`Th_8GwP-Ap-V~xcgFX(a>!N)RpN}y2)d}O7` zoTmgj%}W@ajZ2twsX9e~yNq@6mnq-SlC4==AxQ!4Q+e^UQ-c5=K!N!{jGD#oUZHGU zbiTpp@*ZC>XKKqet+z(bI%jWc#_Fu+AH&BzIuKaXU83T@A!5Bi>=X#Q)BTOoca)X( i>^Rg}szaF{gA1`Q{*8JMJ?1)1jPtK#QLh#)=)!2x{#qvU~oD^rc;y^8{*2u z#I*}UNE)LHO-wL~O^gc@6T_eIS7-#!9a}?e()0Yzch6(K?S7~NIFG>~8gNoYPY?o5 z1#uc@0%S$G=vC3DBE}$PoOy#Gl(KEZOp1~r;brF!!z24>Qq zv}Biy1Q&Qr@pN~=@W^nDQrRLy^oq+2P5FOhJ-lIJ6fB3tB9Vl1o?duxM_=~eSJAAZ zjh@drWw&75FnOQhdMo`)`idUH0fhDieM%lYt0EpkKN2AfKnvjU~wGtDqtFO{TQps@%5sBv0|JRN35^+VhNSgDH&<&Mt#eV`A z?~Y`cydlzzwA{A^_SR1yB*_m71R#;sNEU|^2u(Odn$ChFB#D5%fL&;zk~l1Da;&<6wiZc~KSG#^X>z|NZ$Zqh%dE2ZqeXfT4vST#`C&zqHDv>j zIe73LWYP-Pv+XZ%w-!`tL1hzNak1`5v)Q;*N03v&grDRzN^DV;%SAti-?L&6FQQPAakT!zQC}nBLB1-dVYKq0vA`ZNHP8%Roh~ScmkrQ5~@He~7#H4E)s;uwy-Acz5~@7{&;*0!C3LV#pUrQx2%SA$9eFwEKk2 oPC5IG+%v3Su_3k@VxDuyIoXI#^obZF0#-_>5HnsTnWr%I1s;@%bpQYW diff --git "a/out/production/\343\200\220005\343\200\221\343\200\220LongestPalindromicSubstringTotal \343\200\221/Solution.class" "b/out/production/\343\200\220005\343\200\221\343\200\220LongestPalindromicSubstringTotal \343\200\221/Solution.class" deleted file mode 100644 index 9ec8c08437c87fe80398b69e4dd138312438de2f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1708 zcma)6OHUhD7(LgXnL9QnA%@ALAp{6XObp?bm=GYm5)u+aNNgpg*)ZUd8DeZ|#%-gj ztD^2IRjs;6S1l}9Hf<$GYNe{1R#m&`KdAZ(x-W`K&mEiQ0a9ygzWd$ty&p5b{Qd3s z04^XMMm^4l(S>e_v+C?oq&I{E@l8(#nEUOxp`NBGF`F(aznoi>|s?LCsro*95}J zR3TUL+(Ld(;83oR&pK<~tetc7nPOpu#%E&5W&16=D`)4kT`8~V=CgzCdm#bg@|ohZ z%!G1Io*ey0_frk6*zY8reAZhMkkyzhhekf6dzHL{4<5WBP@D4X#fQ`Os-L)D`?$me zQ%@C2#YJb*RW;V`mT_KX8$kmsiSYn@x;3jSf9C@{-@sgX%IK>E( zm=*|hG%Icv7un6wpF5#YLl5WaUxT`Qrz}yWiQ1{&F?S*A$(R&H1^iH7O*K!M8 zv+Siu)Uj9m5wdrowbH_x-(!Kpv8kzj8*MBu*~KwB*J4xc?86ITQ;*g>M|mrhD7PxT ze>oJ#Y}l)-PCg^hNC$i7Q|$!xI{(+`pX-}mVYkSJ*j~rkD_?ws)bK%xqvRtM1sua`ya^mfBPor84bTxH^eFxl zYT{)C^bP3oC&6JcqizY!;{Qhk1DEw+!mtcW+rY_Vx@GiQhL(;KFtqtHv>9!9-4I(l ze^j-!%m#WXF4J2@MgJVfcMa#Orn+ycS4@93Dgid}WiTNvX&LicW-eh`nwHtbr(eVP z4sz}(OiPv#iiXRmu}pGhM9Qd*E0nQ_Fw*P)q0K~OuVt!3n1&{_TRSjSF&bfbPU8S#s6#s^9_Ii%(8?)ypc@y_gHiNioc9|@AdP-FxP(;< z;9Y(P-y`-uM(`oEzQ7oMpyqFwz@NA(0=OpXF)5mGU9{n*=)|b#!-yEbteC(ZG0oT6 z;rS40@g}jiao=B_b<{GWQ#gSpF4ZkYt8gD-)8`~U!(*JJ)Wiq)2F*%OOwvYSQVe0R zYQZ(DuAt&tSQXz?;nH^#cRDJvtiF}qI4W#fH$g+IxQ{b9%O#DmH(At2#18jXO0-Ly z6O|{(?cYZ0GXzA>Hgt79Lx|5O!u$*R3(%ZIe1}2JSM2!(qlDhJVQ!;_8XXK5K<7Us CT34+A diff --git "a/out/production/\343\200\220010\343\200\221\343\200\220RegularExpressionMatching\343\200\221/Main.class" "b/out/production/\343\200\220010\343\200\221\343\200\220RegularExpressionMatching\343\200\221/Main.class" deleted file mode 100644 index 6e32f137ccbe7f403e9a9c6d39aad90a6209b76f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 630 zcmZuuNlwE+5Ug=b?3l0x2>ZS{Y`Jg)aY5o_7Re|Q;WPI0qkJQfrCj4Qw|JF7BGz&8?!d%bUp820gD!vEG!G;_f(|P zeSw@?sR@_|@ns+|;HfA$?zS62awZ!gk&+iTWmuDm()AZ;rdO&%4ev;*XqW6Zvq0Is z@UG>ptcEgbRsA$kQEN9-mr0BL!~a|h*qu1+rYfd@(l!cu(zX^a zq8CN7zB?_f6tRjm0Yge1){AgavB126O`6kGfx#bVCync%nf`+OyG|Ok`8VP&FGfGt zP;vE?JEYtskZoGBROd*h%`1U5_wS~EkxHFQXLEl`QRzkthxBE-^-7H|Q{dC-&w$Vy zGWM~mG7ILO^(Tn??7E*ZpMe$zc-F0Kz#xX03n*cjh$j0mDF=+bz&L+G&U=8lQR*q> mA7MSh{*miPE~DD?Q08ma$ zEK?m!y}CCDm$xd~j(r3p(ZXnkJ}z7O7zKU#2Qu1msp_(HhHuE4y0-rF`&viD=tY7;GQ+|b10-R#)9zCJ+=@o&dR~H4^ z#+hh$wdxNj!73$Kv)Ac-eLpqv560OiqF`>F`nZ$UTRU7y2_l2+Bp@q ngE*!rDs|KHs;}6=1!7VQ9f36wyJs7#0wc)?rM}39051In=Nz)A diff --git "a/out/production/\343\200\220016\343\200\221\343\200\2203SumClosest\343\200\221/Main.class" "b/out/production/\343\200\220016\343\200\221\343\200\2203SumClosest\343\200\221/Main.class" deleted file mode 100644 index 9ed186c9fc42d049656b45c47c08f7a4d4e3bdbe..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 601 zcmZuuTWi!n7(J6@lie7*z1xeowpOzW?u%~~UkZhV)De&A{DkYBaL^lJ2OeLN5()*6VAC%Vr$#bepD!hs=XH01N1{>R=H|>=^PXaTep=4_M=C*wJ@5Z`_~$ y*tUmb#~F@Wt)Y8`))m}4=>^!0Oq(8dDPvZw&tC;ned8^Kzr7$I&<|(-tiage3?i`)+^ZMMca47 z^BJfFYi>;-md$zPdfJ@tH zd>IfMd|f6~>lM~(Stb?@Y`^4?E-P+zvPq2kPOV-hWaI+7urX`DZ|Z1{(nA?JukII| zDL2$>oJ&ft+ncry4KabX(9e|ZYAKWTswIh(j(ZrENbAVpzCi0aOW@MK-1+>vQ()Uu zh=Z0hFMQwLqEw~k`HZL>FbqqB!8aLyq6Sa5%$BZj0 zqk8H@DUKSZZW;&3rc6DZGL7^~%8aLjmEAF|ch}OKV?@WKCAIxeke0T0WXZn$&xl#_ zrNz1yllH$r+c6r4jUPL@IBa~|iPL_x)V(7Lh)^Ujhfdl7iW=m!X-a&EZvGXoV-)>( zgdse}IDb=khFLtv8%$z}r)9jtJItem*Qj6tHS)IbwmJMNH#J3O2Wv}mN6PE9>9aouA54Ul>n=F5#S|WNvs7}M@S^sATU?+d>bC#IJHW;Mgvc5_hSCssQ&e%gDnV?la?> zPtc?t@c9Cby)!i9-)OyVo?_+{Z6{l`Wa=i{uBEJHr;;_oYRT(y^wH&Z%LM5YXpTN8bM?k(7#tl5U0w7?Hx&QzG diff --git "a/out/production/\343\200\220022\343\200\221\343\200\220GenerateParentheses\343\200\221/Solution.class" "b/out/production/\343\200\220022\343\200\221\343\200\220GenerateParentheses\343\200\221/Solution.class" deleted file mode 100644 index 902bade194535eb51ea0ef5a82c13e3639861c90..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1157 zcmZ`%O-~b16g|_lIfJl|8NC~ z3pZ?aBT)=Lz(3<3Fvjzyt$e!ZynD|(_ug|)-_JkaPXWwfE{G0H_>l<0gNYylNcxcq zLcwGRQ%L(U?MFs}Z^5t(XHkMTkt|A(bG5QAp*wF_`fB6dwr;O$+a{6Te66IJMa?!u z-U4N(YSbkJ^M#t(aEzLjmC#qwE#1}}eND4<%c<&hLFr2@C-Xbno|Ylc%;b%_LvCod z&C$v6Y~>_K7JtjsW$X2Z=}3rNEsI{%vcKEbGkS@;(9BKEs$>d|ZCI7;BFA#iyUrSmp4=d@m2=n9%4G@tiF5uoYqH7L80KT^;3EXQpnQb* z4KvH|lz1wsV@O{Zc+knO&jmy1VjOM~(2WQ)2|ef~OB8?L%awV?PvF@+hId8%h#p0) z{!ms^s+ykq3VG@??`5}Vlx$##LWWs=mt95>!(G4tRy8Fag)^cQFQh!@pEtj7gfqo|I~R$Hodq_+$m2$BZ;GxD c@;@I0Yk*G5t`7>lkyx^2!YG@JvDkz0zn?tdQ~&?~ diff --git "a/out/production/\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221/ListNode.class" "b/out/production/\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221/ListNode.class" deleted file mode 100644 index 8fb9287925ce65666693aa46dfc025970fc72f3f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 326 zcmXv}!A`kTiJE^uDbdT~gbm6vA(LFeV=S06)s` zHcB=#vv1y;x3fRLU*7l1zoIS0 sDx4-7e?rDrAMoCZJjBc=^Z-?gC`5+`82qWpIWNwkOLuOM9+8LBJ-3K9AOHXW diff --git "a/out/production/\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221/Main.class" "b/out/production/\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221/Main.class" deleted file mode 100644 index 78a7b958a5ceadac890d90bae7f42c3307770671..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1429 zcmaJ=X;afs6g_FPH3q@5XmMXDOD$+!0L2AGkpOBHVO(YcWH1_%PMR|Mi~Ovk#gQ35 z`oX{8e^JjZb*kbxnRnmG&3*Ttdv4y>@1H&cC}GJ$4@wrgan8Vb3u#=)&|EYyYC)GT zI>zMlcm|hn*}#N_T_{P+6+u@`T$BB}m`MvaaMQ$;?6(ZuHZZL~zvPF0GNB-y?_W@$ zPDZPqf_BFby}8=@vKK#amjimTPPF0%3vTSod(){V&;2TMIJ2%Fj`Q?7cLhE9$Ic6P z!z~7GxK=DDu^+CDH?q6&8sj_v@tIi?ubK>xFiU<~f|ZwCWS9!+vmD2-CUYdmGO6&4 zn6qL^V$LZrt5Hx({D|c(r`*Is>AB~wD$ptcREt-< zDPMZdNL#0+6B~Q6&&DwvXQf|E#ChDt9rV%ptE7z?I5vtHHZW^r4)Y53{w>D!njfrs zv5mVpY2zO5vx&llpt6kzcxYfjQamF4uoeV178_XTDClTqn_qt6t*|RK^j=AGvA5yH zRd4229MvkU`&+Zq{jJ9T$WeY>O}ur^KdLcB_x9lYsCZWdet2dkm_7mIN0XTqze9Pbv4$~utpKzDMz3NA#G%lUX z;4-;7x|rCuB%T`-P+S+ml2USyNLXIn@wshdz8 z0UE)q0G(h?fI%>(3Ni(0gF_#n4Hak#Ih8i2<}_|w(3du0jOjUju(u9#%*c^;rp5L= znE_dL+ezC+cHKBh0gIHbMDa$+`3jYqqAK&$Ws#aZC2!H|{x(yb;0e*|Ax@!>ePrPv zPn2TRB>IWcj2OiLk;=?P3=(O~*N!0+IDJYMUCe~^^t)u=z9li3%l5i zJ@6iFb?nZz*U?eOo;tGhXftnqd}B=u^*ewWOvIt#ijJW;A{dTQ zjOZBEF(#nha6Pv%FAz;nRs@v0{+c7uS#Uk4*nGa~1Z8`*#z;@WuiCYW9k|jz4JwTd zcUvG{DEYN!!}Yy6fkfc!IKj5_a535e-QWQpyLY(?{PBS&1Ga zTFh9=w53j4T6ESh)f3Dmjd##Z)zbD2VXB{@SoBPV#uq52VyaTUfM@W?rF;*LZ?AM97^z zW9J$6F+5i9m diff --git "a/out/production/\343\200\220029\343\200\221\343\200\220DivideTwoIntegers\343\200\221/Main.class" "b/out/production/\343\200\220029\343\200\221\343\200\220DivideTwoIntegers\343\200\221/Main.class" deleted file mode 100644 index 9552b18c35fe339735654e388c6413a73291d56e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 589 zcmZutO>5gg6r8nW%U0Alv1=!FKN7cTD?1Qha&zgWP%x-TLB&vdT06qoAWKD-4ZZbm zSpRP8L_|mpRz!45{J`N#T2kT zfAOZM?Z?w(7<^RPMoCXP(Bcl(;E?sN)50qUdwA{O4c=OC9kkGW9Q wB@FKu%>7EfQkcVoLr}%maRWf@fbB`MPhYqQCMJ`c@9th0&`|_y#N3J diff --git "a/out/production/\343\200\220029\343\200\221\343\200\220DivideTwoIntegers\343\200\221/Solution.class" "b/out/production/\343\200\220029\343\200\221\343\200\220DivideTwoIntegers\343\200\221/Solution.class" deleted file mode 100644 index a65cee56226f1924ab866c3808ac0343b47288dc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1168 zcmaJ=OHUI~6#j1KGBa(5SGDy)ReTo&ssgP~5F{E1K9U*|6EzNWtb^@L(@rrgjK)Oc z#<(#iL>BJYxX}d~OO`e^cm=n!N5T!225ntd02@fF&xF9fguCK0{SV}bAu59Ez>h2AkX?m zN1%P$^_+{1%B)knV$YUoNlg25c6r9Gxk~?Kl)-JcE)bh8_~l06`rb(J>%F&XU zoa~uo;-FF$5K}~zMp?jI3-F3G(rqZU?$=nm?v^}86&L8DWM;kQ)EnhMptTU#b9XM- z)vz+jvueR_)aIOXuAS0( zaGTB8vus9Yrg}Jq-!2pu>w#0D-*50*ayq={`q|4Q5|EB#SJXu9YSmHWN;AP)OxV*O zd>PlD`OA6ofAMDEucZ*!ocTMD88`id5MQjS=#}|Y$$wRx!EUs1G1V6V`$Z>Zf?AfR z;Mvmq4&qJd-bAT~MgyCPt+fCok)p=u!B$FM7SGUvR@#=+OK9s#Xs-}YM_xfs$k$!V zFysoPmR<)BmtaI_kt1D?-lHWi)8V0OIrA;_k1(#jgPD@6h$dpIh^KU-RamQNP05u0 z{3UWJJs*wb<5Z(^k%oji^U+kCGQQIMsvJ&UCe25wxcww&t~5U<&DZ3oLG^TwO@o7I z#~!jjfC2uO!|3HI^>dRB;|Bl1Tl|IRkwXQ?a2LmMj~n?IBY282yx^WKVIrK#HAETL zhi%wSRAHtrqPUvHuQ@4{#*T1y%h*X2VMPzSh&0wMp_?}(tKTH2?VR{1u9MjgnApoa tgRt5o#u;&5G^uF@_6e@O5HvMO)(8zkN19;;{c;O8s#5t#Gy|WRPwzsFJ`_!pZ)z$6&{okK{GqYQ^Rat3o0|KQ+q=`Vlni?AmoJ5HbF(7?7-ww#L&IzI*siH(yxq2fZGk%`}+X5dGRGSYs`oN?WrF7{TIp zV!5Se%|Ace%J_w?ZnwiO~a;5c1GjGaj`PN6ydfolH*h0(`IaP!4-S~XhKy)?Xy=CYS5Nw zhiV&5ZdU=GIygusT$^HQh7WlbnnfSloG^vfmV~X;?PFDd(}L3$0}vREGl#~jgvh|j zxGcv&L6A&S`Pdf3FWIZu>&tR2BLnq^n%iikMLQbj3v_^`bUDLEIs|h;qaW`!jOg-i$7PpGSWJvkppb{LaV9IfGk`ZT31Bjx>AK}6X=q{11FCG zk0BrDBWRWTNQ8i;HW{|-2rW0k-$O?gNv8QJGF7wF>0)NB=sk|ruC9q>$+fqWZs zR>Od`cm{q~8c7eoGE8#miR9$Dq$`ZbdP4G*3nLSbF7R?ep084TnBO@GD@&9^@R4=` zUBHz_UWQ+A7kcIB3Mv4lJ2Z84iW_^0-fM4_jG1pz8muMJd@J!?!=}YBgz0zC$sNWO zRrH-Y*?0vI`IQDQPI)kVYEkU+j$Twgaz_4J#yumGz96Zz*&< zmdvAbCkW)_MmChQH8BUwALJ!#qY&{v!N;orVYNxMz{{=#@G7G`sWjjPOscaPf+;Z0 z5xG9)MAdPwD@eo<*;8FFWyb3kQEDYOwHIFIcvzf3$@7fEdoSL^@fyg*rFeP5F*pt; zckzZ*PwdFW9R@}14@OCzWoo1Bk%gy$M*HFyIn4f0iCZiv0#|9vIliCC!YdtFEFCa% zyiXe)pS2UhX}n4#B5YAL9wUAhYH6G*7>qEJ(!BPwAC*~<;W-_rFMgbm<-&6^St<-< z992!a#z830dHBJdg`6S^2yIzJ#lz!j5;=lRJ-UY!p9c)0@(}@aM8qY|4MvE*6Dcq; z1frx7DaippuSq!$KI+1A4?HVJrJk^-B!WqYq-{@00kY}td_sG8gcpVCJjW>|K05Om z^v+d9dE#DkX+>n;F?@_VC3>~f!vy!4D&irBGjY<(WBTS*Rd{UTpp+>`1mL}P&8x)) zRtv21h*Ll>7r^(ONC@9N#P(Vtn#!-G+O7apErH26h)KrJVH%5@o2>PP7`ecgL;C1PB_G{F z<`yvEI}IHrFtf{@V16v$f|PB9@Y7P(&cg{4e8nRTHdtfxjtK~^bRjpd4|Fz;26pEK zf~(_5W;YH_a`F3wjPmG#5$0sEhy~`KU!Lg&gB(?jUB9qMoG>7&Ar$pQ-JQppk_jIO zi)_Msuj^DvMM-d-GDo6uLnopaIric@N+Jy>@pxt|cqN6*vO&~@q*697T^h+P3Lk~> zd!2OXbKP7ijj%k!j@rDAmUcwZuizs!d_vB?57IHy8mm)kcXW9DB^Iv z;|OBpY5}BEZRLnoN6fiA&Q*!xM>XXc(r8@X7e=Zuf*Go6)Cv<-HH7QeNMUKackUaK zB-|i)Y(LFyrQ;g^bwYiSBXbiJ3Lh_=%nc7YIl4~lxlY|+khA;1p2O=tSvx!!EOsAN z0!;UR5Ju5YXRpk(9NU|KzV|rTbREzMHRy;0GunLg09NA0#C4uf6ry{R50MzC`IVLa zHJm3yzB7hlf<=nHb+Q(g!ViK(6(QyBJ%!IvYKiQ-kA_?*Wo+X%n6R`QyAO{_C{Fg9 zpOm7l?yW@zI43rrl;U6~5^Xqvwb~M3qDW&}cpx>HT=P)SR@@ET6*JZ^4zlLmM?xXxP~7M`13$v{dCis@_}7y{?KQMJLJ7PE9g0om6n+ z(jQJ7k73_OC|Q*3;iZVNSS4czK&_u=!Tk&RwK9Z za?5=+=x!bcts_dORg+R_hd(u<41?DKf_-EoXi=~lbi;8mkEFD7vg+#@%Q1V#iV z6<%q%oxPP(C-U~ZFpaCYCNOeQEif^xsnid=Mud6V6sLWFgiwumULspz6pUv6JH%Il z7?M2WI+;LMN!#Gd%_yg+<#)AC|llGbM2`O6^&Ws*Rd20MjK9?C;+0sB( zw)3`>x0k=cSeDKyUrDVrt;d=}h9gd40TyoYT!aH#tLOU)19fU)0+ZCYaD{I!bKV8c zHAN(u0jpyfwGu7qPbu0x77H0<#iR^HB8#%|Wgn%tPg*tG^^_@G%)j`w{ia6{k@ zcUr{^zw#yABf5_btf7W=)KNs6>^z brT(*H?VhPU8-cMp_6M6OI(CD1G35RM!U>RU diff --git "a/out/production/\343\200\220079\343\200\221\343\200\220WordSearch\343\200\221/Main.class" "b/out/production/\343\200\220079\343\200\221\343\200\220WordSearch\343\200\221/Main.class" deleted file mode 100644 index 0d76e638c0877a40287944e94159dac7cdfe6150..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 732 zcmZuv*>2N76g}hE8OJd+xHOclP*%Hzx@AX2NGMXD%pw^@O7k>Hrs-6UjT{@%&w__k z0>KCHQHVQEQK?iv+&gzW=iC|p{`378fG2qA;5=41Za6To(!foua@?|U+rb^&wQ%Ziq2>o&2D6imB*Q|aQu(f&3}pUM3=+zCQ8pAwSL8~^ z$4Rr;S5v}>-U^j&)AWQqL)-612ja5`6OoR?xX4vH-mcI^KBoS~Gs+D1G)u}tWdz_v z@$s2Joj5D=q1;hgMnf}gXmA$`XwlTaPL2&1AvPI|euvf(gCWP3i${2@BRSG`Z_L1{ zGLm~^m#*z8$1@kt@q)B#WQNv>@b`lQIV?`4;=^enCxn!hR9KpCsj~0`tys{aQcOtk ze;D)S8Jb1b*%$enJQs(=uE+oh|jLV6NAH!s^w$`V2honVwyF%WG)wIWsh8a8HQZuqsd+4iPlzzjLrjS~YQd4vuA9 SrpQKsE4WJ34A&?&aQ!cTDw4PW diff --git "a/out/production/\343\200\220079\343\200\221\343\200\220WordSearch\343\200\221/Solution.class" "b/out/production/\343\200\220079\343\200\221\343\200\220WordSearch\343\200\221/Solution.class" deleted file mode 100644 index 08433ae9f9413127e7e9c1aac6ce93d634db8add..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1350 zcmaJ=&u0;P>`EweKfo+zNXF>FQF{-iX7fGb>;Q55rz8aB`wvpRcZY_r2-1*IAuj zio0QFbvA!TK&4_%&gGg;g-#sT_-w%6X93)s)8D5G#e|^#Wq2G+v z3%su15*Sm=_4=Jk<=ry%ifX{sRC z8u(T!@s7i42c1>bABV+$Ex+Y;uM#RJD*1Vw;c$mIc|bxaVy=g|o90vSX->X`_=Q0V z8LpO2+8Ab>NdOqZ5$?#1_qnRWf3S?j=YqTE8pXX|kxE@RO45<;-g6XZsqXiX0r*3KnpJ=oG8YB8yYx`hdt|F#pDgjg)wU zLt^YNnEVpOu_P+RBD+!6ZDuW_kTrK9pQ+xBl0E58_o%V&ZN= zuGADjHWLUnZ{zdih+I*JbmqLqth|MB`j}=PvjtnefFz$|Z(~$b7=4On&9M)B`+}-L zcQW{z(KXKL8+?Q+U+F~@QNs;>8u%75ZsJEQ<0pKFC-@#e4p zxq#F3*wE2f-|bE9tf_P3oR&rA$2d!FTYG#M=ExhY3*(A#XeuvxVl8%9$mX$f?kQ$+ z>edt-`4oBHpyb|Yv6r@S!d1r3WKGA~h4rlO$bs@SCkC|PBGO8(C1nRn$^#|kfs*n- eNg4Y}$^#{3j8mPZ`{#YQd_}z{=SY&m`TqdxK-<3n diff --git "a/out/production/\343\200\220081\343\200\221\343\200\220SearchInRotatedSortedArraII\343\200\221/Main.class" "b/out/production/\343\200\220081\343\200\221\343\200\220SearchInRotatedSortedArraII\343\200\221/Main.class" deleted file mode 100644 index 2142fe456f48090d2c295430507a2532e118cc89..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 596 zcmZuuT}$IY6g`usnKowq{@xFD)tV~Umwj{bMG%Cz6}l9vPt$CuQ_@7zRPbl%gM!Nb zfc;U+o=FuEc3|e-d+xpGo|*ac_whG?Z>YPdU|C|tg@xrRR`JnzpIml}2AbphwQ zPIP`KQ1a_-0sAQZ6$wlQI*ERa2Hhz8sk$+d*&q#7+*X-3@e63@mwHH!;8f}4fZYRH zfkpo!=&Nhhh*i>SwDL?Ry@P^XWj)r<{U+mFKh9n`uR=Fxy}kdByG7>n0w zW|cbLY!fwvhb3Qe{phBKj%dX*7t=1^2)TuoND{$^)@yj`4MJW;0@sNoM6BbNK)O diff --git "a/out/production/\343\200\220081\343\200\221\343\200\220SearchInRotatedSortedArraII\343\200\221/Solution.class" "b/out/production/\343\200\220081\343\200\221\343\200\220SearchInRotatedSortedArraII\343\200\221/Solution.class" deleted file mode 100644 index b1ec3da82988265d2081f1de9486afe0b1a88fe5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1522 zcmZux&u<$=7=4o+d;KeMpxv}IyKPC*5__o~iV2{$kqT|7rGz5f1WFNPV{e@;_B!>C z(&kty@fUF6fYLTnI7CQrNUI{kjRQ9>Nc;i(6H(OgX1#WLK$d2{nR)Zgd++1bb>nX*9JyE$^&K)O(BvL7yz)2l%rs(rqI;K;28}FoW45I>L3YD)pel=gL)!eF6 zyV$ID>aO3ue7EebDtA&C#{~W8B^DSyxO8>-mRqKx7q&|GT5Y#Zk&O-yjJW{pHS!-d zJ-=OQH(jSr!w>z>wt&8>KsBF!PZl$ac$FQHV1ob=2&IMNAXjW;L07D$3 z!KRKhV+B>$hVc?-wgL`uRG0teuH?L6|ACL~ogXltwYM=a^9wX<8`An7>8!2UJF;SK zBeG?yC}*xCB75`Jw)7))c-U@Jl_Awko4t8Lmt$0HfW|2&A!Hl`h<1*l;p2d_~)$X z7yQ%ulD)Y^W6C%O7gymCRfhu~Rov#UiLY@dFs;y4)wgObwCXT!(#mdy9a^nA!DMb_ zZr7?I=n4Hf;z9^xBAupB{6fRRe;2wnZca->T8}Uq=rN>R%55N~=B)=(Z0`SS9>^LA zsN83(enS!u*hTkA;oCk@vGx+pDki Gwf_Lqq5`r2 diff --git "a/out/production/\343\200\220089\343\200\221\343\200\220GrayCode\343\200\221/Main.class" "b/out/production/\343\200\220089\343\200\221\343\200\220GrayCode\343\200\221/Main.class" deleted file mode 100644 index b92e07d0235d9782d498999614ab92d880aaacdc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1179 zcmZux*-{fh6g?dhCd(KIfhg{%Xu=j36eSU5)#wnciiL$fHE|4s$qY4_Smsmw0-yB( zL`%zOp8Xmh(9>BUP$X5o+&=g8Ik#`JxBvYYfJv-`5kX4BNEkk()G!*s7{()*Kw1qq zHQWl}Htqy5so`!ILEKZrR2cX1K*O{^ch<5kZ$_XinOYU_&pU5TfgZ!M&3vu0Zn`h! zdYO?v!zs%0s&p;2Zw39{hE*kpu`De+!|V!Yfkg6+u_-^ubXnS^bis2iyOdGv!V-vg z9OZ1!ESav#lx~Sk@e>jSf>ozn^DKwdVWZGmGpXA(tF^Kx(A(rBrkpmcs>id$QN8u8 zw&vku*z5^p<@|& z7EN6)5N%)&%=4`d13AxhrRTU5R&r&%`MU9BE_JL5G#s=Ju!&^nd7Fb6Z9`V`=0}#C z?edxm?8c_Qjc+`7Q!vpTCJObcXI7Zz)R;WbyxnrrFW4I%JH(Wgh6LMNmE{@>Oa2_K zdCr_=OSj%^B4!>)@9Zr$PQ&t1LN>^jqJJllO?JF;t06mEttGkT`Y25XL+IfTO?`Zz zE5tbVahK*SI0r^{Aigw?;~cvi!4Uen)|&tfAi-S-r*Vc6mApq>fb-%H_||sNWsC;4 z`J!XH2ngiIchN2I2`Mf#f!_#D`@bU87xw=|WUXt^zYYBxdvqJoSD*j=QJ4FnE28r}@zld`<&pF6;y?~1p7sV7V;WE7rF|G_WBUc!? b%18{peGF*0reRpa^}qa|5xBtvACmt8zvB$< diff --git "a/out/production/\343\200\220089\343\200\221\343\200\220GrayCode\343\200\221/Solution.class" "b/out/production/\343\200\220089\343\200\221\343\200\220GrayCode\343\200\221/Solution.class" deleted file mode 100644 index 53d6fb982848b09d2a45e7fa9e3b8e74ee76d2e4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1003 zcmZ`&T~E_s7(MUWQZ_n1wg=c;={h1_8vcce z7v6BIHzJxCFTC^)?R0Q2P z(}S}}%PAwL2_5GoZ0b0#V^W}N&heZeC!nM=%L3|rt!xYQH!l(m1BX! z;RrZ9s_^Z4!{wp>aDL)o<@MFQ>f`_9&b7|2TU0(L!LARu-+*rfMBo zfpEd8cvjHx=`4L%<^Px>g<8We**6{8k?5Z3Nomo5fv7;N)2_E-m!)X~7cj-T1}@@~ z!E2f}FoP=s1I_GC!3M5knoZo}W=H(}BT1B1%!cI6`!o5>Hdw6vf@*dWYif6MM|46rZC&6XS>@0SzO#PCP-r zVcft`?i4A%ZB6cmiLr0wIEEx`jxa78&_YIu948Wkx`PoNCxrNoKJg2wp9te5BO!KL JP?6k?{Q+U7&#(Xh diff --git "a/out/production/\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221/Main.class" "b/out/production/\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221/Main.class" deleted file mode 100644 index 637d7b4d636846026daa61e03ec026f2f20c674d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 938 zcmZuwZBNrs6n<{kuC!LcA?OreP=BV6`RWZR`zjdKABcI4#KTHM2vWCnFYrg8Gj7?r=e0+Gxx^yFVeTeKv zl**1w)*1wGTX8?xm7kQJ-_avh^;8~i;|?iZ64myShh-E!tf0uqB|(p8d1GVM!&|(w z@!mrn#5FY(DPOJVbNfK@sO|9gqG%E`yFe{5Eu+EX+IfGp{i)Q5%BX#QsoT7CKSGUbUx1A+C$kbue0$Dy{ zn`exaXjR#MmCYM$uW2>1)|kY7S`K3mP$aPe|1%G%8LXb+w@BS)AR^Dr_aEPf1wn>&j0`b diff --git "a/out/production/\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221/Solution.class" "b/out/production/\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221/Solution.class" deleted file mode 100644 index 2ba8bdb0eaa04343e036e5f81760c4b9b1ed5a54..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1334 zcmaJ>+fEZv6kSuM3=C7C+_V<&w*tj_K~#!YKt&6vLok|XGPH*}I-MaiQxbl~AMjO; z0WXR1NfUp;fAAC3b*3$}G1`Z7&fa_Nz1LpnOuzs7_!+HF zVzF9T75=id>d@0y@QRkRV)?eT>rOR%W(NxNg6TQc(DvNCf?nJ8{1WqgYeV>f%AFw_!qUx-qp zpc@S_)Jl1Cy+QkUOJWdC*KEgf%ei?s6lLM(uaMZ07F?sj^e#^cN|=((g0&uLqTwp9 zh3YHlH0`o$g;k&Go%xRf|LU%rUezy(o3@lc(NOr5l+QpCeF_GerEJhMa1GZD+`x>1 zS)>ij;iiI)hPDQ7;kJf(19xzjYz-8!U|igo@l$uh%K_B0O`V!Yu>R0rS zr_?RPQ|ddkPpPkd|BPb4e{j>jpkqqS%24Nf=pWD(!$WBq68PaQ64@Su!=T4^MCaB_iZB6E(*5X~>=NG^gsoQw(E2 zC+fut@dweyY9KJ25sK3y!;kbqq8cuc%WRRgdh7pz?jZR~K E0M(@}?*IS* diff --git "a/out/production/\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221/TreeNode.class" "b/out/production/\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221/TreeNode.class" deleted file mode 100644 index 7c3216cdbd88cf7553b0974d05cb7da8be7d4703..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 342 zcmXv}O;5r=5Pj1YN^1*3v&QSW;%EybJ3qf)-vDlK;lsg+2OFm@&Rp~b_Eu#AnF^dtzmx($nipEn@@IW3XcT6# zB-p$&Yg68{X)qne3=iZ5oye^9Z1bAvVy=>mNH5A$mBp$sRlNtDa%tYUWJmR^7#p=UvC!P)qL9)S3I$U5}x6?MK4@zp&_v? z@lv4h-b5z-Adqjh2LjIL_)H6|`6klevT&%A6EzIj+3@3$3I-}Mw!UjR>A9Iu!~d#G z)Z=u>U7*(b?q8@MsuQSa-07!@iN?LTx=P06SN?M>P@Kd;mYSFXuHV1I6m|P?mW=cl zV`G%8(_1UYSIZ1WMe-LLp zs4l{rxO2?pDf4R;GDtDX!jnX6-oR-cwhwucx#~lrfV{M00bMO^fF>j#!hSjM25`AP zV%6a;xUU?{Ag<@f9@oOWDX~iIEeLpwHC82*vCfVizCxaIz^5DJPG`vbzu>&dPq8vZ z!9r&V*}Cr*mQXI>(zn5w)}zRP6?!!2-e!s}-9OUb=BX__u|WpNe1}a`nTT)BI)^9! E0I64dQvd(} diff --git "a/out/production/\343\200\220096\343\200\221\343\200\220UniqueBinarySearchTrees\343\200\221/Solution.class" "b/out/production/\343\200\220096\343\200\221\343\200\220UniqueBinarySearchTrees\343\200\221/Solution.class" deleted file mode 100644 index 8c40ac83a7a1aeee7e719b212b49031c9a86c8f7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 581 zcmXv~%Wl&^6g@W{+a)xlO)&*rBOX#oka0E@6%TcT1S(1~QmQNpi#n;*I=D7+ZN8wt zfrQirn{HSkA;bstGx&`1JY(9C=047uIrnk$=j(R>E4bc-fkhivZCn#rPm(Mt*91nl zHxj6)`A#fo50Wf?S?!PGVlx`2L^^|f5~ZW4NOXP%s&X$m5HttFJgv$k&mIeAvTA>` zh-2cayWU$D$dp(6gg0Z!B0i|nQqXu!v^6ZF$=i+SU9D-OL%m^M6_fZ`q6@dqwS#H& zKAMGs$s*^VU{1sRG|G1S;dmNPO58$&6YA3dn}A7cG3(O{y?O5oOuqgy=xgTH}$FBMaQ_*dIYi{_45&BAn=9=doVb%9c-%~rmUZ@@@ zM=?CYlJC6s9P{XKRSV=D ZSeEr0Z5x;67v|*@H&5&RIV2mn@(-lRU`YS~ diff --git "a/out/production/\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221/Main.class" "b/out/production/\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221/Main.class" deleted file mode 100644 index 5ec4a23142868763078d8bc6c58f7f3024e313de..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 834 zcmZuuT~E_s7(MO!wK-t}0jv0dPTgQ1qNv0fFI+-m(v6D|2+_oJqm(XPmvkK$^H+I+ zOC<3J_@j*HDUjXRq~|%$$NRkJw158o`VC+QFLTJ@iHWBdHhfwuzhINBXe;=Z>Ri0rH=tBaUCZXwTGZZ?zNtd!PP9#zL&C~ndx!hpD`Aufj@P9$2<4J{rJR-6|9%%vMX1g zgbu@o6O5B4Hjw3yl1GIi>WH_QH5e5}eRBroN7`N>8fnqQBDsum00k5ovsl71D?F@h zBf}i{ehKw>hKzFw?O2;ZZwt{$IzkMR_nI(Mm@do`W(X^!Z8N25->TLwU{r1G0%pzD z$!*OxnAo~)N@my=v#sh+SVwcopD0k|S@cv#lX8pd^mFxHHha6~Of)pAV3L>!YiuHl4^IL6}8@Uo&_iD628UscOV z9T`mPn89o_PT`2sI<4%_C@QO@a~fXLa8{sc)N-uKxIj47$8BVyn3Dpn8OxC~)xx}V z=gfJVoc2s{!L-ksuBG-hW~8!Yl?C)nwrE!?R?!&|XuD?RubKIbT#@#yo0G17W_>!*nBQtC$g!u+y$5S_8_YN% z9gBm2XWdgc~#eN&gXbfDyMFX$n4FhlDl0Yoz zx`xXJ-hwI6?b&+8$W~m-$sem)HiyK(Jo*hRASVzS*sUmOU=eu@O9m_~Yq(;-MuF)Y zaL{X@h?0S;igFdISOAq1u^nV~epxQC@h$b3%Ve}}GrX>HHq0D@ccuKUco2Q-k-m!p znpHktC{;K;JSg1jt}GN+WX4p^I#ac=uD5EykzFlw%4uAzQoqZOVHF2Yu?8GLSDFP* zM0mxtIoW2ZBpqVem71#e+fXoS@2iLE3xnhJ?*dalRw?>g_XDok3UqiyX@te&Qc@uA zD@_oOcgD``a@Pi&-bSoO#)v-OE=vD zRpWH2C!0P;^BRoy9cyS=L+cvalA6c-0z22yP8U7bF|0Tp8)#3)J!&1DA-oqAYSXoW z37_2+uy0_fCaD>0N&d@^kMiTqY%-qKld*I>si$K^xrRifCpSKj)O;*Kg4&JE)WA)a zD*{!{57EoDA2AHDocqv%18BoRbnx*?;4lmOB2pN^5XO+^qce%4e1s-YzzMvAlX#cU z&-<9h2YjDC!fAYhGx!u)+`@U>;T5uhi};Qg$Pc)LpK%$#Acx<072HK0e_#oJVj1_q zvxKsUqbl05BD%2ZwYS6;-o?{+3VWb4>Nli&IRI>Ht>ub(hCChz(TZn@G=w&xp^q7b z(IFz(ODckd5X`S1QRed(vrO^jOyPIzr{@@R`<2tShi~lx)?%1ie$*jG_5B{CU*Gb% zEz6-T%OP40(=rF`9$GX!zsaz=hC><-b0-*_9}O??AJ}9y8ic-9AWkL{oAlP8QE$$E NsFRXr&LbW*`VSx3=+XcH diff --git "a/out/production/\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221/TreeNode.class" "b/out/production/\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221/TreeNode.class" deleted file mode 100644 index 7c3216cdbd88cf7553b0974d05cb7da8be7d4703..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 342 zcmXv}O;5r=5Pj1YN^1*3v&QSW;%EybJ3qf)-vDlK;lsg+2OFm@&Rp~b_Eu#AnF^dtzmx($nipEn@@IW3XcT6# zB-p$&Yg68{X)qne3=iZ5oye^9Z1bAvVy=>mNH5A$mBp$sRlNtDa%tYUWJmRHb4*+6txVt`GSfJQ9;q^UQ9+vmVN3*9mQ>3N=M@V@egRs zFk<}Z2Y;0D+-_tl#xM6iJh6s`Zxg(;L2=0pgo>=Z{Sj7X8TT_r#ur49IZntf3LqgD4+?612IeV6bvAo^3 zirrSta(B#HlSnM@)XnCu>DuCZ0LtFJeMpXc!L-|1o^ElMFlkit2j-EPX`1aurtG

)8$ow0wCGlT@+Wj=N{M5(3qn1hwNFdILaq9mf;pJFaCF z>73=E4&?|&jUg(uqh-&mzb%-Zfp@L!bltkOZHw+y(Lh>w))7a7W=;+0c!&)h*Kl3I zBOQ;ipx}v)O>9Y+`n$=^uHB?l9Z&I0$2Oizkmf}2LPriS6}%Emc^w5Ta9ToC!uXJ- zR6DTh^sd$fk!Xr(qnfMc7KhEy+-bYyXj*T0;5Ux)yF<@v@jjg{6BGT5u$|0nF&5s1 zWwtn_;E~y+InFa|b~;vjPr|H0m7$mZwGBGriIj0Bnf+gV#B=%-5)#JQLNdmEu|KWR z@xOFR|5?m+vmEkUN4<(NweP9s4B-gMHDwtxd_X}_y)BI8~ zg9}8&;rEac;=XZ$K;;<0yz*761m#ji4wWjQaH$ejN(CQd>|+Wsxl~+QPW2$K$9TqW04 zEYP7U{=$J{*KeO~C%+?={Dd&|KSDV{g#J|mS`Q;Jy@zNIqdklf86Q{-`h%JDEyPG0 cr@;hna1d#l8xAVt%Yqqy)@dpm30)ev@2b#T~Z2)Pd?}$ z@Qsjw0aIV=gOX^{M;`nu{sk4!UJAi%?%bKVGiPSb?9ad78vt(Lx(OXI6B^!l*?8fHAP@PYfjm%6zqzCFPmoc zvb$1kI$CF{x%`Uc^sZ4QX{ztF=xhIt>o=V#~ZlyXr{rX+*&RO17;AX(Ji1K74)1# zL0m;Rh-(P*;uNKq{ECo%-m&C9LaBYUCmS0ulZ{kk8>*-$ zlKx~vDWv=<%5U)18S0ntZ8EJ7UFhemaapG45UN>*py)(MmX0wl#KtV@tUbcHnAIt?qbVQH?d)6rk)djy}4kk$>aFbJw;4DTt?>JJpO=|*UxPxij#bczA#eK{pgEx4Hw|Ip2 zn87yYu!AS~glCewWil{=BF-SpJ&(aA;yErSi+hMrGnmX_r&F~>EW=c`Y? zUZCc!wI+F2q}D^9Dz#o}0lAAfwAde58u~={Z}bcA91ug(a8aW!r0{+jflJKw;qpIb CPPJ_S diff --git "a/out/production/\343\200\220106\343\200\221\343\200\220ConstructBinaryTreeFromInorderAndPostorderTraversal\343\200\221/TreeNode.class" "b/out/production/\343\200\220106\343\200\221\343\200\220ConstructBinaryTreeFromInorderAndPostorderTraversal\343\200\221/TreeNode.class" deleted file mode 100644 index 7c3216cdbd88cf7553b0974d05cb7da8be7d4703..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 342 zcmXv}O;5r=5Pj1YN^1*3v&QSW;%EybJ3qf)-vDlK;lsg+2OFm@&Rp~b_Eu#AnF^dtzmx($nipEn@@IW3XcT6# zB-p$&Yg68{X)qne3=iZ5oye^9Z1bAvVy=>mNH5A$mBp$sRlNtDa%tYUWJmRkTiJE^uDbdT~gbm6vA(LFeV=S06)s` zHcB=#vv1y;x3fRLU*7l1zoIS0 sDx4-7e?rDrAMoCZJjBc=^Z-?gC`5+`82qWpIWNwkOLuOM9+8LBJ-3K9AOHXW diff --git "a/out/production/\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/Main.class" "b/out/production/\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/Main.class" deleted file mode 100644 index 25c7044079f3069645073d818cb53ae4d27c354d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1972 zcmaJ?-%}e^6#h25$tGbbzd{fSinO+YB%~CqmLMvXwrHTWK`L#nF3A=al5E^0D9$+J zjD4uS`qoEZeAdxWWXAES5B>}OFUId|f+?lr%f08GdwzW9J7@3y_0R8r0GPoSVT@ow z$CWUAvcDIGhQ$z5$%5p1=ELP?2 zBOPmD^kbm|xACzo>$2R@aaU~a>G(v)eFcFzyJT1A6{xZCH3ixgCvPd}%Gf1qrB>Xq z+*Na0RWmAR4=y**160RKYB5rm|JnE^Vg0 z=%%|#`@R=kD+pGcLak~$3=qy_TQYifA*p=!E!FigCqMnvzhFM+5sfx*}YgsK5 zf0;?C?2NUwf}k^7HFG=5X1P^Cz_VjGt-$ySx|_g>qmYt}QdG&KM9bA&SAnu58tY5i zMvqgnS3aU;__-i+Z4C2iHbBRxgqwA0ZqB-D3%em9a8fuk@G@Q@8Ak+AJgQu-J~NO; z!hnel1FvJ+Kn_y|E@E0o-hhP%3I?9%exYU;@|J606SD@kV3WASs7Tuec2Lk!ln^BY z4#;)H^KVg5+OhHifS3)G@wovP6$4e&i0p`P1G@rRlPbtzJO7Q1Z7WBrPCXk^c-CS| z(vGf*<5rsqR-J|Hs?1Ki)8lR4=uxm9(D9kz*}Y2DDspn28ZY{rq}xvFrnH_@XPHH| zPu(>O98t4ewn}*g!%Tc)I9mkKIvG20nf^cfVAW~PH))HVG-Sj+uk_=vi1tN!NQmFH zH@8@gYUT;{m{pU@^!ObGx?Nc;maBW-SIcw2wTjLz=cxa9buAYdebo%`}3eCzvA zGl$UDef#iJp{=VFRz%P!%xWU}Me-+-zafwu)VL06gMM!DL>>BUU@-6m!8V9VbTGJq zAUe^5Q+(XI2%#I3JWZn)m(hoJ_|#oP6d4S7V6Qg;;XGpW4Pp`Fm>}F9%pr~h%NwF^ zl9I|;0J%pBP$xs5aUl6DL4Y6MBlCxa`eH z4>g5{NJ|;{PdW0q@gpPEak}42_EX~rDNXZAyM+klF`mw_S7&)T$9|m0AUiNdhLhy~ z0=dsn%ChMDWZERRTdc0aa(D3tzQUXMhW-2&v-l44UMFW*v4O8~iTC_IagR1r>|c~# zmuaUmLz$1_EHjgt7JYM+Wni10Z&4CLQ_vbT_v@I~@ir9pvcXoj&eVz~(%?)fJkUYm JV9B@e?!P@jkcLFo2uZydJ$%~o4r(XwUKp+^n1-Um-k0wo2EOSY|%{ z`6(MDH|<$hb82ZCDqj#kfi8n}ttw8SFjbDoL^Y>H@iEVjL2BNlLSPvxR;X%~3fGW> z#nnrUDyX4~hqMhmK$Ab}8$3o2PvBt#V?4uqJdgHmOn182m)qeA7PxT%udzs^aM~`e m62&;Dh9#b&a?%p=3v&QSW;%EybJ3qf)-vDlK;lsg+2OFm@&Rp~b_Eu#AnF^dtzmx($nipEn@@IW3XcT6# zB-p$&Yg68{X)qne3=iZ5oye^9Z1bAvVy=>mNH5A$mBp$sRlNtDa%tYUWJmR0=sqJp59DJ+T@#Ka8kSO&@z+hU@>#Fbmu zE|egNapl6_;vaC~$9Yo-pptOkdH2pe_niCs?boNz0LHNtMiYiLjD(?JG{i6_!?=ct zFaj8sVN%0X7$FQd;0A8Wkda|p!;FSo0)ZLFb!xK$zQn+qfI43;*aA(a?rQxuyr6u)FHKrZ4__mKcjRTiZ$a@5i``2!F2f&j%_)l(B`kG*7|P zpFDtgPoSWcG2kV`Xd~9^AD|r_yoGQ97nxzR=pk8%xfe%J*3|>}ObPr1SqTCJ%Mxe= z8C9a7M1F~yWi=Dj%&>!B{Z$5y4ZTvz{xR zG8!o-jK`38AkFe zl1B*9Q#flR57D6Dv2h4p;4Pwt?+}d&zCbbG{r)b!s@|h?astSyl21oJwGU8V5-ALN rK03&*Q(Zq2M4ZBUoM)2%@)7H`6l;c;QGT*b!{84-tiTX+3etZ78f58j diff --git "a/out/production/\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221/Solution.class" "b/out/production/\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221/Solution.class" deleted file mode 100644 index 5c03eb97d5b98219d63bc72ed54d8fbcd4b97d37..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1542 zcmZuxU2_vv7=BK&$!U{qpdqP75vUYRXlSTn3;hB`z(N{6Qp<;quu0Z-%XYVJHXU)i zWX2o+fH1=y!#FzQ)Ujeg8LznTANXG!!*e!Go1nRP&pFTgzR&x)`Rm^&&j1|5Cov>3 zD)CMXA&kcHE{-Yjo)TjcnklfWXgOx7u~IR;d81+zNfzCzVJ{e-rQTbh<}X=wfmpHZ+6~`w zok;;%bsfj7`U3sg;=E^?q`F-q>!jlEv3%2OF{X;k#+p%}pIw+$sPB68*KDg!=iMFJ zA`zuo^~^PaL^msOC&*c=Hat&2%qqnEk{p`nx;zHDQ@^v?PJgH)MmvM4ZuS|*Jx1W1XI!mbj+lI&LV{ zAZO6dfn5$F+lI4PxL8>Zrk3bTMol8Q1GJk&TBBAINM~EE=^&WQ-C*PE)>kZ+E5%_% zJ#)of<1?L|&HdM&*0%XM<3v1bafxSZMYs%{Tz1RhwS&m=!J=0j>sP_c5cEeohRb^y5FBMEL%UR@FV-WrPFx4*v zk|0Hy=BvO{@QfUO46z=l2PmTf7{@ET>n#JkiVR-@uiml}R_&I)miqQ4P z2+xU<0q*C+n}~++C**{7H`2^#rHu9qdY&Vh4=ye9yHTND zy=}O68%{^=H8;o>6PS=0xrw;IcQ~$Yx=^&GZSdgF=u0Mk#jYLYgmxsOZD2RUK5G7* zjs`gj-YcqV4XWxjyg`}gYlKxFMS_25{TO4jPGB#lxSKN=#VMlaG0u%XiOaaajV^JK zxyq>E8cckOWqbw?H}N%Y;TsstvVw=G;s?~QPVEM4{00Y4@CE*WA9VQ&JL&Oj+RGdy zqpxEh_OrhU{DcD>Uzm}<#hbio%;`rQ#1JCP?0aT4#CdTFTN6^Zw`eEuHqilcw0N`I zyg6crsXK#clL4i~utZ+s2qgs9p~+xfC>07H_y>a$Be^Ex2(`ROBe+Fsua3R|v8PKT diff --git "a/out/production/\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221/TreeLinkNode.class" "b/out/production/\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221/TreeLinkNode.class" deleted file mode 100644 index 2a3ad57155053348503c282d98341ea8e398a814..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 369 zcmYjMO;5r=5Pj1wR7&MbMU5wKzyU7aG+sOlafhaq?)c z1*Oz3mK0QMwuJJHjcs;I-WheLgge>cq~pclezr1m{>trir?})|ii_r# zb&PY+{pq|6!-oMe}*Q0oYz)9OiS8(?|Jv0d+&LVZ@)in0XUBd6ZMEn#7qQ~JtJ|} zgpR0*ew?dg#)Vo8V9>-xTv9ogl^2&7lDHyZ47pj?9~KC9N2Ua{8@YK$V1L5RI`@j1 zStozrp7n?{CUSGOH)ZEt6<0vbf9w{>k(jXEY@F2@T7j1CnZ%;KV#ho?yAVtHc{jTd zSL|Yu-*M)7q!$R4vx>g!#S(78CxdW#YUdZo+Ej%^pr(-XSde2IGm)zJs?g^OGczO) zvL9#IJMZf9znM?`*K}ytsN-4RS#a|4VG<5j&)XihdY!7=m-6kor3rhvq>@BCFGu2- z1XVUuxnh3Kx#cQNYn5zKrIdyJ2ywZ83kd|&D$OMoD=o82&b(4d;;MxaTqB=_>$o8? zYT+hsN!+$DhH(pba94Q=N~tl8GImfa} z^0-OWMtoUThR--t%-qlUwnv)EJlnSwk5EpHOH82?`}iNDJ^}EhBgEeZMlo7JtDoM0 zcwahh%jpdZ1je; zexhxyy7IzC^aJEa)CBP0sUhC}`QF#6S3-^9*EQ7kt;3}0p{-kor8d=|HXWcaYR4Md zN$&WNTh4OFC2siy2l0&d1={eE_$##I4UXbHI!elnar-QeF{_n|Eg_0S%+xW1Q5+_w zDQ$3sRUrR6R(4RiN%D8HD!^XT=wd|>$C=SWq|9-G9Obi3OQ&+3>;@uN&y|q0@|R1UrIEz0nDKQP62G2(m2_wtB5=oyZFXBl-H4 z_n}wjby%(kJJCX+CXj$Xy>BsP$XtSqYK;gIv?Gvmd8u zYbXI2!Z3FZBt}TW;FJf8NJzQ(6LQ6SNU`c&DC16I--oeeR2_GJ7sIaOm}@^|8n+DD z`}=p-s2D}#9?TSeB>vDye+z5bOag8foulh{)0k7Xa-9l^KDE_Xn51oto5$l^$K0$K zrM2ZfyzkiRYg{14R^z6vj$^ix}oRbF_`3n;~jaqnKiusv8p&mdz U#Hffkv{;9p*z=6N5L*}j0a?N!6aWAK diff --git "a/out/production/\343\200\220130\343\200\221\343\200\220SurroundedRegions\343\200\221/Main.class" "b/out/production/\343\200\220130\343\200\221\343\200\220SurroundedRegions\343\200\221/Main.class" deleted file mode 100644 index 8f33c4d577c2117cb4f49c4069d20233deb3c291..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1745 zcmbW1%Tg0t6o&s!y3a0vvALNJO!ywEXL1r-V>4Yt^tq^+j0%K3Q` zCytK;ICU(YTIJLSu*#=!r2e}vh>{T$)ob6@+Uxt*%Kr5I{|^ABa8E}D<2nvwLPbGG z65}e)XqeQ|g((deH54^m5*wF0FpU`%C9yTD;|j_eu4=fZVNSz!6%`fp5>m5H%kj$+ zlG&jL66A{e*p|?3IxYL|R&&kvmaMe~R}9l#w;B&D&k^%zQTCrYn~Y&rEvHqYcav7a zk?gAZ%zA0%8&+#0U-vzywNVP9TiyoG_qEw(6yM(T$0r!2!OJBiRx1*;O}DY-J1(Q@ zW<477CS}dFyvNLXRh;Uo`_}sNs`Vnsi^{0D5C<&8gUNU>#aMNB%Uib>9D&v$vL6!( zr*Q=RX^f(uH^;Xzp=JK1aRUotT&pbyOQETWotwC&;&vK$uqdJDPjnI0R8dXiE^2hG zEyu2$C2IU6YvL=5Jbv@9tv$2XeF>euTX|}EbDn3t;<@aQfL18YOQxU7QUjsx-iu#t z`gW6n-7UIj!fH5f{vJ!=vmmzB6e4Cr$G#xr-?t^GFT~*nGsq5CAUXu7_>1FocmRLn7-tO`ig95fmMu-z@`jcSTi@gjn3if z$cJ*WC}-rs*El|skqa}*TcqEiYh^&$!J%z*|07FpetZ>qB?G20baLDa4F-D9NBqOg zD1$8J80Coq2^YwCpLUguBKMQ@T|hTZ;|vsfF5xWBaeb7+oyP^zXF2Of;s<7+s2Ea_ z5)(v<-~!s_<}+3U;JIdA|yaZB-cARpDc#f*Grzgd!LLv}^?S zz>w$Jp1>p_r&!{PEOC+TI!)vfN3(ntN?0UjT-xFusQCzLa6eS8Efim#=y&irf?A59 zqRRF~P@z?fz#bSb$94kd2zQ-u6~fK4#cr^Mw~*s=Rwi1Nw$5)1Sl$C@Mu6w`0~Xo< LN^Ao09OQojOA#Z{ diff --git "a/out/production/\343\200\220130\343\200\221\343\200\220SurroundedRegions\343\200\221/Solution$Coordinate.class" "b/out/production/\343\200\220130\343\200\221\343\200\220SurroundedRegions\343\200\221/Solution$Coordinate.class" deleted file mode 100644 index 672f58af1b14923cf7c65f086e828a8bf48af0dc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 976 zcma)4U279j5Ir{^&1T)0n6|dssHvv9iEWeGz9~K!5CTELNTH9LWT{)$-Llz8{ZBq9 z*c24}0sb2w6hA;cvzw667Ll+sbLY;SGiP!?|Nig^zz%k@FmOvuMMn;68Qj*9!kUIV z;!QDC4K)pSC0x&7GlRNc*z8~}*&k9*+v^>uanyxh%*t}b8cYJpkI=)w#R^3-f zo2`}*YN6i=1IOD}STL*Y1M8JlcP($f9%ospTfLq=7*raKhQhLWE?$*t5=XqB6mLnf z-tmV)&wlKPfZSw`P2n(5K;FPbF_%zOSUS!8Xy~|oJK&Z~0}X76xkr}uGE-FpD=1~K ztuQ~qozbUIn8H2n9@xE*o3;)QZLhDeVV;$FR{5Bp3n-bbe_d;n0kF!KkmJip@JD4) zM49wyD3M7!&(k)&l5Fh+$#+rN0k4WvEAYGgr zAya#g#0Xk38^=mwo$&}4-V!GPkupaF;LnTZC3x$%*j?Gikn!b*U4;P153#M1=^gelK=n! diff --git "a/out/production/\343\200\220130\343\200\221\343\200\220SurroundedRegions\343\200\221/Solution.class" "b/out/production/\343\200\220130\343\200\221\343\200\220SurroundedRegions\343\200\221/Solution.class" deleted file mode 100644 index 712759b1cddbca1c5b8da867df6f8c3a74c423e8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3808 zcma)8ZETxY6@IS$+Hc}GYnt>8^Op2u&D35Jbt;e_RN4koHAqM+g$@{$Apw(s{eXe^0e_G{{NPX9#XRS}cI>n+ zLbC6B?z#7#d+s^UbMAd_>DnTItw?)dVV{XM6JZaW*jIz6@U)2m58T)EszMaJP<*_KQhpG@VpXVM>|wSxOW9Cpd9D9m&L~zx05DnhjWqW zsr`}D`XDBrryJwPc@&>`Jvw^qE=zrK5EWIhDwO|Mj_(VL)@IO%QR+ftTk|LaoXCk?Dh9He5;}Q9`^6&!nNQ{uR zTJ0c~8SInLkYOYNGd!6Vf>^ELwtFWsW|3$#p3Sy&cXum1*jf>AVyHN;N9I+LI|Zj2 zTMK42XNt}e^ybM(b})X9hoL8ek(BPNDb6qV7aLeWEY>H$1l@p-?L+Ks;aBnNYM+O? zO2L7L*?Rbu*1*5fM9FJULNnH~r?3v|+0uaHZ>(Exs-^=!$LheM@g39zoWVt77RJ@U zqKNOp;n;s2&ZF}%2Av_pGDJIzz7A*5GPb;i4)!f$Yu(Vdv7vJTE``qPa36JA#yrdg zR5@_CJgjkKh)jEkTP*VJ&J=WfMK-= z;FyZB{H9po&QgAfx|cDoF?5`GY9nJe;1PN`No%%rjk=9mw}fYGNsY4K!oN!$pwEx$ zQDUrsKau>{LCP^4~4*8zY(#dWI3xi+r{yOkla@Qy~9 zA;Br;ijtix(b>5YX=Sc#O)*z)2KqLBPn=3UdW^vj73+=qGxzaOfAjyVH-);>YuGd* zp}y=4xh=O%sEZwzD`>e%sB}O}nx#=4Qp;tzmqRJ_$7jspfskpLGuY}g7O+a8x5`(w zfI5X4Y!GR+(io@?_^JtlptQB*=#~5*ZQ{!^mbYm)IeS4fH&u%EAejnWAZIU9`V2Yy z3M2PfGWT=XhR>6EU%)87$b7ttb7bpF_zGUfSMeskhVSE>_yN7R&Ux=}{x671soT#n zcduiW&Pp{`_2c9C1h0VYv@QH{bL8uqUjpcx%Q?GQbofjic(%31h~;VzXoWPjbEv-%Dr(3gTh}myE_)U4 z5v?N{nr%{vt-{1IB$O-~V{<62w^tiuE7xn2Wuz>4L`L4T|5(NS?TMB5kIDW^|5|Zs z-aAVlmi)K(FC+NUjbhn)Xc^Tr@LH}Jn8per+GY$Yb*-a3C|yMe8SzCA~%1Q7V)QN`+EE$u1Q#&xW0omITHw)Uf>T)G(H!FHn?O?Y!`uTG~d*hGHYC zKH_wB2NzB3+O_Kz_BQV(4DAxLnk?se7D~eKEP%;AeG(tz N*F%Tgd^t9v`oADc0#N_} diff --git "a/out/production/\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/Main.class" "b/out/production/\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/Main.class" deleted file mode 100644 index 7957a8cc384b1a95944599d2d803a3e3cc35afd8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1298 zcmaJ=+fvg|6kVrHnl^-j1&Vk@yif|IR`6C7FDQzHixin*d`jC41kJut`q8X0LO>yv(C;wYp=b}KHqhW2nq?BYZ|6>sK`q* zt)m~;6S#q!8gA*(k(V*IB`U@-BiB39+|@CQdvV;C>jMoBHOvXb?l_(k%nC#^V;cg> zoL{vCdQ8W&mz%Y+-B`EEE$}as z@tH?AOKmK3SN!^00kzI-0dr)IGKB)RZL2EKT?(wqt0k-6u0t>R%|^wZcVwjrSminU*qIL7N_oewutp`b5EkXxZ@5d!26Utfj2v&l(ViTl zExp|h>>4M*Z<21{;0hf-zbZS*TePhj`>eWF*>(lQ0x#aG*KLmtJwqkOuDo3?&*U=4 ze$M>(Ngm0(GFVg$<)Xaq%N zeBu+7i5yLCNTJ<_y19o~Q5{mpThNNJq1b1{I~pd@73NFu38#opQ^{p?Ba0+u_ux8C z@I9wEfBl@Rbg1>|fgYU4aCml(g^y5e3PoHbijbv%OGHs}jq)3TLY5@1aHo*Vzo41{AX2F!}+Bedtu)mHh~#h3-_cg`O6ATR1_FviR=zPsXHDE%eD^qG3bR jBnOc~nZp#3VH2-XW~adgj59GX!B3&kQ6|q3M=<#ZF&GOg diff --git "a/out/production/\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/RandomListNode.class" "b/out/production/\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/RandomListNode.class" deleted file mode 100644 index 6618a10c0a66bfef4186ff03f44835e52dd94d8e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 363 zcmY*UO;5r=5Pj1YYD)zKMH5fnfP-ATX}p+_kTjU6>3v%^x}>y8DTKe}!I*gP2l%6m zuayhg?7W#bZ@zwhzrF$7;KGN4z6TqpF3wyG1dUY1Iu*!F;ADDN3cBHw$`<)5H0yGn zFZ8XTS=0=jJCm96p4#DT6cHXM5OhM5>G@_A>*7VlDVbiFCn}9pVXAmfI^~;LbJkAa zKj)hw(Nj~2`-cOsmujm5_&5*HKvU2@%yY#`F-cYSI(dwjI^ov#a1`N+r#U>;=4T}> z;Nqx8uSTKoqXj`gZwiZ#%=i;BzWjjo&d9zZ#u=Paj=Q;YB#9 G>w16h&p^Ha diff --git "a/out/production/\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/Solution.class" "b/out/production/\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/Solution.class" deleted file mode 100644 index 374f06f403fe6ea01c71985f2f39f245e09dad91..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1208 zcmZXUT~8BH5Qg8=ZrOGzA4RBqC?7@WHwDCyh!Ud-fuvLegs6$pZP~y=*^*L>{sjMo zx7=c)l4#$_xL8LGhj4LRFG>_MACq-g#zbvtNII_yk}E(*{}*Ghkp;%r!A% zI>ti?Aa2kkWR( z%Q80^LrYROu#rR27=swTG0=VlmTw1v@&zA&zcxr%O9`)_GsWHBK(b74#( z8paf&OmHT|0!1oUHl5Af{o=M&Vt)cjh6*s%{%G!a25b!rU6m*Z23H+2m4h6^7$Xj@#Tj!v$_-UUR^#T{FQZdwU0@wSi8X!;8R>L`_d51$yn z810BBepfBZq(DD33{ZKHAVX9han+-qLPMQe=;2@CvKy@gg#BtHd`$_B2kG>3rjGbW z1RiDHqNUS#b_~6c36Bgqlh6Wq0E;d#RT(AasX3^VH$B6%PdeZ>!{@oW!%^L3-xe^AMVD{blRfWP{G4j+FDe6mkE+)o5MQ(g)@SO< zG-lJ1I9f@Usp00EaN-wp8a>q`7{#x!v&pg3jjhcOqY+fuGE# KFiaI6M*aYa48p4b diff --git "a/out/production/\343\200\220139\343\200\221\343\200\220WordBreak\343\200\221/Main.class" "b/out/production/\343\200\220139\343\200\221\343\200\220WordBreak\343\200\221/Main.class" deleted file mode 100644 index fc8c37f55a94a0a78203226002cfa31ba45a5dfb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1631 zcmd5+ZBi3K5PeGmJ6QsR06`EG0W}aM1n`RhDk!3a4-JCiuT9v3#gL?ujmQZ`^mM;|J(FL5e*6S5gB=b1h-v7i44XlO=E z;7%*<;-0{LA0A*L2uIM$hg?lUBjZ?#J!udSRdbUH{l-6w4@DlQ9LNn9GzbGsj3;B3Z_a z?kO6Uq-KYvLnfLuEZRf$)K2m)y^(s?xkge8JnrP3a=|pSCUd1i+E_Ma;XYa0gv{y3 zWeoT+fdO)Kc`4|u@>$V~2joN{GKOKPNcgdabuQCXRmFxMn|R5?a#x!Cc!i{jEk9m^ z;w!p>CY^&vm!p>>r)D{EZn0+q)d57Jj0k-$B-SdJi_g`?|AbPkPb#Y*P`xS}sY4@8 z`P!{fHg+9p?&r zi(I@{Fj^b5d{yhOjh&;*W>g=Eoyg0$85ZFU?~ZNb8sBL@-!1q)6?t1Y4ssRctVrwl z8I&&sO}N6b#WrfVO6+$WFvK8$55pLtMIN5wCl7nSp{aUSV+^3355A-3yceUmPP>L1 zmE@n`wS6bg;dy%o@9H_4IkzMtLG?RC6Lum&p98)^8xOWdPT@aAo6P00dG?bj5QIP% z0_bLuJ>(Z+S-p1d5aSDkag!hDF@!OUlXHYCS(jtEMWo?&g;&1J>&iu5HjDNK7D4)h z@(KzYV3a}rq;gL7P$heNLw0F#vh(edg;e!-Is3zN^$K>6c{0pB#NrV6Z diff --git "a/out/production/\343\200\220139\343\200\221\343\200\220WordBreak\343\200\221/Solution.class" "b/out/production/\343\200\220139\343\200\221\343\200\220WordBreak\343\200\221/Solution.class" deleted file mode 100644 index e1ff981711f866b3d561d6ee31fc06612a219e98..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2561 zcmb7_-%}G;6vw|e`wNz(A{ulpSi~O<2|p|1|Co+bwcoo5NdTu#XR^EZo_p^3@j2(-ym zp^1GMHqnGjP1uFYa&$$GJ~c36LPt_gK5N2NjLO$F17lKW+{AT!-h?lZGB9D_OA{>^ zmh(xuVah}szLJVJ3``riDWISAa-N?MP$J!v0_t!+;|lB=^>Xf5>E4W6m~dvYl(dfK z(@u8MDR^>T5vu;YR}?TuQ~7Mk_wu>8K;y%FA#<_dI(G$*L`D~!2Tp(1$<6hr{DPO8 zinbb-~X4Q7#bb94T@fOgOE)BJ{R z(r(+`zjQj9b17~;oOE8n>l<%bPUUL?MYz;)2T*{lvIew`?B4^&2+*|F+gv~0W z0fH~O%t@6Z0YiT1a%++lFrH*x)Rfd)AD(v#PTF@1+wj)wRQM<2iMWAV2EJy`ut@}t zz9o@uzJfC81-DqrGFHJ96fg6LxMjGk*zI?ls1N0Th8rMDvXO1y{Coozf3=8b30j}1cHXk_I zk~=;tusrLj+Hq{`q_F+$@G@%%H3kdk#Ccj*$8UyL+Caxn~0kfv!MP)}%bqq2Bpb9a3#oQ76>!#s?q*0)2HeM7`+3TaqZb1>gA=&Of2x}pgoD$_aK1qKB0dR{8({)*>K{TElRl2~ zILwhIld2>vM@MipfKb9Qe8}VvVS*mIpzwW-o}-K;#yw?JQmcnry_D>OaX`Gr9$}zQ z`~y=&UP9xKE+y;ZH2YDN=X8bV(tq)M2K`2v?^76K95o0?vKwd=1a@7HOo89gG^F*~ znz9b-XEbl%y%1%)hICv169=E6<;GL&9@1+Xw!VQ@1yipuP|1DDDA3i&0O`BjWy6t~F1!8qAo$M;C#2NL=blL6xd$=;&o0NLr(POt_?1I9~L z#!FSkOBKdZUV0~Sii{=MPJYWadT0ZXT9R>DYmlpwwhiroc!jWm(+1AGLejv;28RA- zVQRd2*Kwol-(%$6z-_bbvPqvnQ`dT9?c0D6?Q>j~R3&Il!U;eR$WaBf9IJTcaPePdbte4) diff --git "a/out/production/\343\200\220150\343\200\221\343\200\220EvaluateReversePolishNotation\343\200\221/Main.class" "b/out/production/\343\200\220150\343\200\221\343\200\220EvaluateReversePolishNotation\343\200\221/Main.class" deleted file mode 100644 index def9594693794c5b117afdaff6af128e1cb4e05e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 655 zcmZ`%+iuf95IyTSS;uvo;?lIx8|6}x7V4t%R>TWZrAqEaHHsARv@2hYlVY z^s$R4*phfE(GsY=(y1<93shR|j)46pdmjrlLY>AZ<6$q(->P0h#1FH+N;)dn#=imW z;)5QMBRp0*Jz({aR-oB>7hb4K6(lMh1W}RebZ}6zt9-!xg@1$voKcpH3!Ra`4WpYg zN!=(L=l%Fln=$I9)2<=+FpD`>{mGPQd)UT~!2Ipr0%DJApDXb249_KYJp>?V8@{QM z)80kgFQ%aA)2N7t{6*QAfyIe7odstUR#0B7hMZHzmnu0wJNcjfBML7ko33QxN5hkF z47+vI?qCx$yhQU^5Jn~U2EBk*&{nsvAwHMkdG56ml(@sQH%Wkx1$uSd#Uc??++&_a zyY&rL_ZpS(3+$cRcT~F-zZP|EUq;=k??hLqU%~y$K8H%l;wfQY2{uwSq)K%TT9|KSte#HCfnhV!C1U z-G4%#7{-~-sKcl;29%lV6A$|8lYanz1LHW>?`{$spqaUQ&wl5g^PTgZyZQa!U$y|u z;HrTGC`i0wAfomu0~!iCrVYG`86Br}%<4F!(AOl+8Zc2*u9C9m6g;o2vcx%w^8)cX z*LQ=mKs1|M70?!&*Bya}9M2qQ zfuWNu2X@KE*p0xh-4qz@#j*;IRD@W{*poGX-Wt?B{`BFwA?Au7ICZC8Dl zg$;+A9jE3J3+#HO*=g6Di>{I~kn*uTT>g@urDOsF-*QmrYc0#l#Yp1@u8x z0{eI3me+1LwcrV;Hyn!XeA=-+ik-?1Dbfol<=*4yTFsWg!EEkXH|bnIShc+l_26yd zc;mH(-CiJ-maXL2jpWtnILn`?yHOcVG0>bRTb+%D!1!+byK=Vd_J+gwr)vKHy5T62 z{AAQG0+x;xpJRM0a2MQT6Zar~2;GPHjEA6s=V+U~1F-Ns-vkaL%_oB+g2_gRJ<31C zNPbJZgFO!rdG{WozdnG*Jyz86#h4Y_nvF+iWlE;vcksOxOUdb?o{U?17xF6{P3nE? zP;#ViC6Y#HeTj8T>tfGuFuO>UhwOPvk9M*58`9$(*92FAYldr_OJS$_dnujyczzS9 zbmls@z3EJYn@nfCc}q**$G$H1zq5%^OSAO*80`aJNU^!SJjD1NvuRN3EQL}Yff34j zl8WTWo5u%aY+w=rrf{2oH(wLo#4NtW8QjHL{D>lc!W@3ac|7Dz{*!Tkp%SWGrse^z zA%hpFY6BnQMOsm2xQ!#^(aHO$KLceQ!|`wyf8ZsYU|p(bHL1f;$VnnuA|JstVWg=oV;6kG|oqh#MrX%s~nYLR_t#C2Zx`;5e0dEVyVT zkoo|9D8#=`QHh8p@6P-)`_0Vm~I|8j|CNt%8fqHLuAkcV`54FHbWHSAFI*xVmPQ@vePLwAq9jL-s|4M9>pUs4f z=#?_rF;9=V3k1E7(TO@$VXCrG*e?r{jgBk2Dn`s-TM!m-CwV$8O-_Ip^{;F~y?#C| z68+NHHrlq*k%jy4vBXnp-y8k!viB8HnssC+K>M`#upEA&$4Qul7EhjBGuU2C=?ic!07Zd$HFNU0Y zr?=oz{+HN)ReK&M;C!+0l)ZHqfd+h9`|$RwfyJ@Jb(vnsU2t#iokM)D!Yf=`mFQrV zwm(b2O?2qBv4(Xj_V8EKi31LQq4wb%_2>s0`<><)T4!)7+x^FG&+O|W0h$%iC2$>G cNCY^*?W$-n15*u{<6;}P7_q(HpZZU6uP diff --git "a/out/production/\343\200\220151\343\200\221\343\200\220ReverseWordsInAString\343\200\221/Solution.class" "b/out/production/\343\200\220151\343\200\221\343\200\220ReverseWordsInAString\343\200\221/Solution.class" deleted file mode 100644 index 9e3985a8216ed6bed4042dfe4965a8e59d00c640..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1745 zcma)6&vz456#iZ_lS$I4ZPKP_No*0pBvYths9+&NE0tY8nM_eU zZt!&D#$O8-ZcsMeaE|CAJ;$EYrJmy-;!^h%*V6 z0pu|kLm!UBpyOx^y?9A3c>~9!W;}|QaooU(7$P_l!7K7VA(xXeoI*kRzG~pKfinW( zlWxro3Id@_c0oX!@+yu%Z_%web8D+hj(^!+s#23EdS$!1VEeAzx0PD3;x+_g#gbQD z3tX=@Az=E>4aaXdS3JK$+rdonx_!eQtJ<~Yu~Oi>wdINIe^tbHY83%7!;i-jySeD) z72Bt=YjKL8zGGL5PHj0@5zrff?FRxqrNAzKFl*OUf(C{esqC%ReW%g5vf>6#scx59 zjhkZxH6ubDWDX@NaY+9%iCYQ^yh_lb$uan8gH-Z1c{ zi6UlAjLM*qN5GH8KfiR{DU*usz?&jnXMEq51!S_4w14Muvk^F}EZy2Gt zivl*vu~*s6uwAdK#vJ-zeQc-AgOR{%bz5K{vunfqRn3nhlKZ;Euhy8-Zioxm$La0k z9RMd?NV2*1b2rAnklNfP#19m@Fu*melm?QN&6WcOv4=Z>r|}F|9u~t47N)Ll{Q_Ow zx0>jh&5bq@D&$5(X|2+P78=)*TKX=|sx>j1)bf2J-y*uMiH)7#lbZJ4xSrJMK$A|> z9h!7$%F#8cs~AarT-(^$+Jb(SVK))JPt1_Yv%s=|6f~rn$q2gf9E&@EAr4TQ{oaqm zILacAb1m=zn8h)aa01sb0f)C*)>q)k0;g^Wdsz>wX;&(x6r*q`==&^&$xR&Z5@j#Z z(~Pr^l14-@juC!{K?D1R&b^sG19@c}QpP(-SSd>L>s?}9di|D?=Ob3CZ=|F9KBc1n2xAM8 ztDA@>Voh{Q{;W_+tB^r%m97c1i5}|iF|!t>mlUz*5ar$JCSg68V|f=y(EIZ7UuNuLWJUn5X7=U9C&F5{r0k34i}zOBgRlYr0g z0z#bS99m;7CD~$m7Y312SxCuJ*~%7c>S_r2h_o~CsFMQ|w^I3Wt<@GQ yoz&+4xkoMV&*}CB$^4R6@GAwLZyoG_$2;Kh4tTr`t~2dJoMVl!V}$F%i+=+?G?}ZKBrRP1@>4p?UGm(ifo+*fv5+AP9v?vc!?S$YxjCpVdAn zSn&t+M-|U(EFyFs=DVKrow@w^dvya~9~~DpY)U+JVPUh5XLxSB7cO4nmBed_Edl3) zPIUfJpyGFi0`_4#4Fy&LorGVCcpPS5)i`3N5u_6p4OOO1e3!KI6FnzK@LB2PfasW3 zV8cHSPSv^UMk<+g2YIHG*+I#!vKjlE|0xU9=4n*qIwgS{4DNiAx`VXHCgCS-WYo>1 z_lDd<9WGJ-Iwe{j+IZvPE#66Nd)R?bNd_RWdatKHJ`E@NgVf;1JP%{uL0Yh|z7Vg| z?h%#e)E}zY2#MAAqb!{k23_@!dz~K7QW8Jx6_95J8F8@f_c}wgAo&(%S>Peya$jQ9 zr4_W*-Ajm{W!dBIlu3z4^u0v`ma)R9j#WHn#(=-E&!TPrhBdlGCHMt<&$)I-6{kP4 tt^TMg`xmHQz`18$Mx|t_Q9_F>X2QmT1r0PA)%Z`=u+ABLNX8bP+yavdbZ`Iw diff --git "a/out/production/\343\200\220152\343\200\221\343\200\220MaximumProductSubarray\343\200\221/Solution.class" "b/out/production/\343\200\220152\343\200\221\343\200\220MaximumProductSubarray\343\200\221/Solution.class" deleted file mode 100644 index 35187e61055e12ddca1efdf538e9b1f0b4b6b85b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 769 zcmY*XOHUJF6g}TO>Chrp>jMh{qO?@opk{p0CdNQ$(t=41#;}@}u^pVwG{X$^2lzt_ z8#ioRVKAvX7yctR;+X+LoaDRrp8GuaW`6%Y83A~Tq5&N9tHf?8cVhWM6*$0@bMsUuB0eU^X>CWv@@Oj5E~EJIG39+Z9|RT?RW z82qnU>y7Vrc`n3T^bpJNj*;IP6c zicn2fT<01lR&bToDjuSaYqT_WJ~&@Hwyq<`#b@yzHyD-JxrLjwWcJ_S%q$e#X3Z2- aLrc0~vK>s&u?en%Rw-kRxbH6`!+v zOe?VO^@5T7F6)tuhxK-rs(5&wv&(cy{LTYqfzl+2rkP4e-~{cZPg19yOw&PlskDr; zp7dUmyC}n9*MFpqnu{YGyEwsX8*f~^g-1!cL7=+Q)9R1HLAI7^|CnUqn0Js&S=d{M zS4sU7m1oo+$}xr5UsZhF)NDns*YF!WNY1(rB<`DTi-(=QO%vRU5 sTHT`6nxQy@wPLQIkh7F1p+*)xVSmAbZR{{A@ssRgk2Cm+j14@#2R3YT3;+NC diff --git "a/out/production/\343\200\220154\343\200\221\343\200\220FindMinimumInRotatedSortedArrayII\343\200\221/Solution.class" "b/out/production/\343\200\220154\343\200\221\343\200\220FindMinimumInRotatedSortedArrayII\343\200\221/Solution.class" deleted file mode 100644 index d45b962a85abbaee5f9443884f496a85b26f7494..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 886 zcmYLG%}x_h7(KUh+o8ix5gZilAQY9Kn${?i7^Ddr2~9v21q@-sFdf^$=@iOTjdAHq zxC1n)3u59%j3&5q;cNI7#!$~pi)`*a=id9B@0{=cI{kJ6U<#ueVi;0!O+y4j8lo6h zF`^HFJu6O8pu6Ck*7GHE zr>)wvXYbZ+&$0`)S+mNNq)$vF))~D^%+>%bs@vlig=NGTY`0vkNLZ z1X2Ocx~5mk=3Un=neJSzRIk{c|M-<ak4CT!96;84Dp#D0*z}dJXFz1+|_!(y_-y+2MMk$7AZ)|0&mhk5l^4ULv(&e zWc?V*4`r6Tm{X=@I+;lunFFjE$)emx+?bXPEF=T=dXv|>%<#!R^bi?Dos;RL@dfgz zeRqJkE@vCfuk9D_o1b)5*Fe!dcYhHNQp4V7%TI$j`gb^mvrQFPXfJQ=a^j3;S^EYR59&I4B zv%;aTvdJ0@tT5#If2#_HX(+G&hHiaSfLf*lbR{$$psS(jz^Vr2FBCEOhw6ecg3mYp E0WpA-8vpiX^ z6D0(kLwCP=RrRWSKEK{R0PJAXLKc<0Y3oBT)u!eO58x~3^Gm;hvjP&!I*6*A~Gyqi}+mYk(4T26EgTk9eD|^&nfoxYt^jqcyFDC8YUF^cMr~gdwgLs|t6) zJ-PV`@ziZ+xu&|HfnlDl9sxOwu*zT*c_LbTjyUar!aHKuuZY{vNNnYkFG#(>=$j3b driE$F9p_|iI?)qij0o7tqCiY%nPeTq)DNrtbFcsa diff --git "a/out/production/\343\200\220191\343\200\221\343\200\220NumberOf1Bits\343\200\221/Solution.class" "b/out/production/\343\200\220191\343\200\221\343\200\220NumberOf1Bits\343\200\221/Solution.class" deleted file mode 100644 index 8a3606a93ffacf89c5162355587b74f50613a37f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 429 zcmXw!J5Iwu5QhI*+i@^44#9*+Qb3nbkcN&xgM<_*KoJz`jbkMXju!=+l8Q@k0vZ}B zBnl3|b!ZVVHqJ^rkAG&q+5P-^{{V1+x&s4iHhdfFgi=?_YIbvLnDdVX-Z7)?rWVt-UwUYhJe5mU7WXnd8cT1D4=$Mp(|3Y*-gi-#BVK!Fv?c zFvpFD?(^?g^M&gMGFF|J0UO-A$=ogGY@>!|&fdu%^7A-KciNTABIHpDjs Kd0bfKl#74ub4SVm diff --git "a/out/production/\343\200\220198\343\200\221\343\200\220HouseRobber\343\200\221/Main.class" "b/out/production/\343\200\220198\343\200\221\343\200\220HouseRobber\343\200\221/Main.class" deleted file mode 100644 index 35cfcfc70e748d6458e3e3d4ebd42d7d30ebe32a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 631 zcmZvZ+iKK69LB%d9448@c5H2}XX`Pm;NEyw@kS^tq>Zq$5PFqe!#X9KNH#0@3cihA zw4mYx_)y|E*-9yxi}|0w|8FwC|9t-i;3fJB0d^&BDDpjN%lV{e-sO{$na!l0=H)nVjE&EeZu`M3sF57zrrPK9 zoK|2bK2A>ZPx+wCtJz@GHl~{Gcj|dFWB=BF$^yZnE|;yTDWH_vEhhY=p(vBZ-IPZ1Nz4hZNAo^*0jOxsJT(dR{5%=r)MB@5dt zcvBDFlDs8AurJ>UTzYQAMHrVjcz>bkFf{IN3dTHq=(|U#%Mq* zXuW4=5MR4;#MAGR5?AO)s|KuNgHZ^LtIXKpFYN2l9{oTsJA;#agZo^s{ZyIbrkU%d zndhgOFVjp0X%=V(+V4)O75zZ7q(jZ3Rys^i;hn<2pjd~~Z49{WkQ|m~XSETV*kTmm P0N1ch9=c*%m_fX_g{xos*edFIZUGiT2H`17pkI^(Zy<1aykM^gs}_yZK;Tqj$du+*AtbXn~z6v@;EhnYNt|-ef>sl&jO{>f-F$Lc#Os(cUEK2oLo5utKlG?d-g?RfVh zRenIEA_9@yXYl%sudsGI?=1QB_m?W2L-^#H$wSomQjQ@UsmL*O&X|g8Y#3{|xgJ=c zwM81bju|Xr9;=9;a1Cp?#k_%aJirY+V)c|0&vEDYl!X(!lT&CMbxiS?2v0CgB@46E T4&hg&{u?4!tEM|g%);4!cFkpg diff --git "a/out/production/\343\200\220202\343\200\221\343\200\220HappyNumber \343\200\221/Solution.class" "b/out/production/\343\200\220202\343\200\221\343\200\220HappyNumber \343\200\221/Solution.class" deleted file mode 100644 index 0c65e79119fca32b23e615dd6ee9288467d487c7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1267 zcmZ`(O;giQ6g`h71VVsfEq+7={A>}asMHT?0a2tg6?N*sfEz=J5KPlfo9ggaT&UxQ zjT>EnBQx&Y_(%K=E)dU4i-b`(FZZ2$-+AYr``YinzI+964LKcM7}9V_M+=5Eq;x14 z(s3Ch61gImtL-ct)sWVq%bbquI&R>mhFb!y8OL+{tUx4@oD)!{%FDJuci!>r*?MWo zu0FArTq1|^<)Y=zSye~wo1o&aIyC`3UnskE-zj@z0-95su_~2yawT%fMH2g^ih#%w z@a$K!3_XH1+ZTxC*Q}RTibvhlj8$7L*ghE)*QqfX4JGqLnCU$zV!g5_BoV4@5@i~Y zYk4cFoafssc6BUEj&q?>N&COL&Vp|hUp%lXL9cXJgVa{C9Ln!aJPpwo{Ho)vj0OH# z)fGAt`$w8S70UH$(Vljsp`Cl44NDIUbR#Oz^Oqkokr6n&pWtX-*vnG7hT8_R7&kD1 zNdtEv7NY%Ih&PgiGh}{7 z>n60<7-@!W^O3Y_zJX~*^-5ad>Sp3d+1UMND(|2v8&D!2c#9G! zOQVx<7gRQ(QC|;L9fOG^PT&eoVic!v6MYy*KW9FG$2g05TnIYJQtdd;9pwpym3=tQ zNR=HlyOWVgO!oJfj3?>GG33bE$6otc*-NC68~Bqu&Dn7@O$aAAtOe0xq)Uq0kUwNU%{kgh8$?xcD0x Cyai4G diff --git "a/out/production/\343\200\220215\343\200\221\343\200\220KthLargestElementInAnArray\343\200\221/Main.class" "b/out/production/\343\200\220215\343\200\221\343\200\220KthLargestElementInAnArray\343\200\221/Main.class" deleted file mode 100644 index 48501d5761076661ae8bac176931152688089dcf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 596 zcmZuuT}#_g7=BKYHfff%PHpSHtnNcoh4p549lIF}%CdFPQ7FAStyw*iCX%LtKT9tZ zocII$QL^Wx9a300ocHs2-sjD^f4I2=@DWWH4z_GOcVS?wgco?Jy;m+?W7|f<#*RSo zlZsXLS-|w0eF5uBaufDN%8u2H9Km;~;x^G! zT7jBB3{K>kY(+Ajw0c>p;z>Jam+6H48~-T_II|?0XDT6q8}ybwN!?yDPsia`rDc@# zqz{_hLkTWX|2l2#dU%7k9^T=-jXe+h@F__H1lAt)bVn!QI9o~e&SzOTexh;1NfAT4b=Yvb*puA diff --git "a/out/production/\343\200\220215\343\200\221\343\200\220KthLargestElementInAnArray\343\200\221/Solution.class" "b/out/production/\343\200\220215\343\200\221\343\200\220KthLargestElementInAnArray\343\200\221/Solution.class" deleted file mode 100644 index e66f2f920e4c82888682c49c0a88013c744f1a1d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1498 zcmZuxO>Y}j6g|%#&)8$$(BFBA3&(#ycvfiG?x6{{XF-)d*{7hpZvH9 z;1rg1Xvk{F=?EdKBZ-$|m_zBRtve{`^U5^zqtEJLRiP&zh$>`83WpRst?n712tle5R+XKX? z3=YDDEfDE?W``JI%dJyu+Z!!vA*aPUCOPa9LAWyw3G{u z={5=_$FUlwbD`7dH7(b>_-V~*OVSBEhbawb6F7%ANb~sY9E*+aCRWyNS~X9@`2;Rt zQNvOKZ{lJCmt=v7-MFgPvE9aE&vxooCxN%{Hqp-VC*@KC@8GgbDhot+sP3y%{jBR* zO`f*Z<0*}@k8HOJ?-JG{xMeok;6u9wORi@%td4-TVLCmlazkJ|Q<@19gEI#aOgnr4 z8i&)C*vwnV?8yoaGQYaV6!c(zfc+FH&Bt+EBAV^CKdsb$Ci|L0KC=fD+{^s`@lmf8 zm;}Z$PX`jwI0$hCQ@kV^FAop~+ki2y2DJir!99|F2=N_-5XQNxzA=Ug%84KV&)`{V zg5SyWTxD_>5yAmSQ_39-<$ggdx0$+&_#=d_Jw*7YY%ZMJRO+cdlm`q8`_RKd3Px~@ z@Gto#CI_~l1Obsk+An()FW?ACO)_6WXhib~Oa%nQW1cBS&sHv#FGf;DHC@yU)zI!@ zG1!thL(3bHJBZ!Zw(oEMl`~Xnsr=_v>Agplg>VLu8$Dsi4%s}$53*(kC8q``#3~2BT`8lYF)W*C|`lv zgB|T_jArRquBQz}HYl4*QL7tD5K!OOv=zVKv+Q>seC7Cho#a60FwNI6gCb7gG|uA; z@6`g{qx2!~=*QeY!4f{_J^g~7FHyobynf$e8GT&A&v@T&{zq)#RknPZjgHD@4kj(7 zoiS|DFUKHl$0*6EZ~3E9$mtIpr!B(l-|-?PmHd9=Xpe9_lZ+gP{seI$1V>}&{~#p( P#`N3-hnS%^gqeQ;v`7h_2ngr>EoP?}wc*#_TW0@+Q-xq7yrCN~Ty_YH; zQ5`V~^qkM$Tz->oDC3#yXQ_&3qk=Be8Rt9yX$v$KNtkCUA;9wd`#qtSpXBK@I91w) zsZV;R;WkWIRQ;VaFtG6)dp2I+rGZyAUc;d!Ef8og{hUwc!8BVb`QH~=5b+L@oQ-a2 zUM22FI?w1okP(fvrb#qWvD6;@JUS5Abk5F(1EzPt@MF&G!Bk)~--r;+m)y(guM&f;6^QO0j_svj*Xt=n~8)W?sS89RhiO AY5)KL diff --git "a/out/production/\343\200\220216\343\200\221\343\200\220CombinationSumIII\343\200\221/Solution.class" "b/out/production/\343\200\220216\343\200\221\343\200\220CombinationSumIII\343\200\221/Solution.class" deleted file mode 100644 index 12ad096b265f6bcadfba99fc2e8c744003c258fb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1819 zcma)6TT>fl7=FHFlTDU|21>AN5=*P42^LZ;ww55aw$P>xL`{cIJ&awFE#0!&WpZFV z+&caNue@;_tHYh6Gfoi|$8p9Re}%t;vDW9?92zJWOtRm;=hO3k`}cpp{0?9mZ)q67 zl!{k01TdwcALle^nC`=?I4_S2eRvHQa8lOBLmsQlPdednL#GbWN9NG(v>@DEq^-d8N z_PNX+%sZyLn$5cnYt^dd=J*phbtp@L{!+s%uPvJEe%mT82}DcwDtm0!IGWr6{T;rD zP~CGj809phBL&ON8Y`?>RnvAW7HM_8W^F8+j*80y z<%1Hn>)jJ?Zh!W}HYJPHN?x;8wiax;JpG;hn3P+f;|OA0i{6cJ*Q|=%3mvC0rsGXq z;h1$?#k`IMTw~!nt|PDG25t%r`mVjj>L_4Q#}bMHkxn+Q(^JFZ$^)y+JsRjuD;I0% zsUY95YG%We6WcJIrd7Phy-RnNw>KZRCumkG0`YVY60ID$%)2bY?#3EP_ileD2P3HW z&H9q{5o_S(qmSbH%y7rvPuPx0ZQcGvqMOd}((uAmJ-IgVz2&v7ae`lh0e&HXAb2Mc z<2gt!%eUY=G` ziLWr6h(#Y_U_7BDgN8Ek2+G6{v{n50Bfj4mL@>!nXOX}Z#`qbM`KDVj+xZwB$6)w1 zr13nd0KG=(kz^}_tR+QC!3*>p>FSPmb)(dspso+%F~(G!gN0M7mo{_uuW diff --git "a/out/production/\343\200\220217\343\200\221\343\200\220ContainsDuplicate \343\200\221/Main.class" "b/out/production/\343\200\220217\343\200\221\343\200\220ContainsDuplicate \343\200\221/Main.class" deleted file mode 100644 index 9dfa3edd33fe79717622cec072e614be47459ace..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 674 zcmZvaUu)Dr6vfZ%CYdBgn{I8b|E+(s3hs+<6@5?yAsS(2A?<_A#<)(&CMBB)ej=as zp#>E`fFDXcldaZ*fy|wI=bkga$>is+uRj1hz|e<_O^Ne9df4=E0T<2el8?){B5_sX znt=0Am%4c*(2s@_0qaTiHWyflb(z0x=hM7?t)>MlgSg66F;TTP`BBko-s=TD;ulJn z+f>gP1vaAHcu##$qe7Ll(YUE~Ios~sRXt<>+JBY>+(lKijjm|m$K#_pP5p7z)>-~c z8w}6vbl;c<@ZeMRr&D4pz;)aRa1*yAZU?x7h)6~t5FYa+)4e=vPL#$U7fn9rH>g@J ztS{kpHF`zzhWxpj6J#~3%7$)>r|o{BGu4pCj&`39cX*`E|D;4f?i+)G`&-e@aDpvJ zUWs{n;91~vJjHCpC>ZU#hY+8;<$$Bp6(vq{9xNMh1}n@wgji+8h(EEf$2j|jUV4ar z`~}v%(EIMEeJe>VJ4x-(O;X26QYn+v3iH3=Y$#oszisPq;NE zZrHfON7AJW*ZvaM#(M6Q21uA>zI(s#p6@&7+?ikhzV`tW@=F4fjg}us*Y7^*wLP~X12&thaHT>QI=V?2{OrIxw*B+5BpKn_mrk?b73uQlWcAZXXowH)KKsMfP%66zVv^!%V zO|`XFuhVcgTxBaZQl3{@qPPT`7EX0NlifXPQwJFf*(h?zb4nBitVVGUs{&)A5dv4j z#!$*uecx%&WbAYn=g?xZtnPV8aaOc|btt`_v-O7F3A(@*xki^OkVu|E4B1NRj&<2= zVi6X z(>Ffh=?`eHGW}!do0)2^Uo`ZhnJ^Q^M`UsdGhd8k6OpelzQNS+0j6;@$|D+HzBk3^ z!EgPD6AiKgOQGaBik(Ls3rMr_kbmtXtYCwA1=&zxn)ozkF@>vC9w#P_1dUSJiE6c* w#td~|V^ujCqOKElgOw!o0p<{~aMQx9g*isSd-=;{K)>4XfJlK`j2hsY0q0$pxgKNQl)WSYePa$gwN&B)mcQ z?E)l_`T$*(7XtoqQX!;zanAhb%=zZ`%%A(4-vG9-X~V&Sg+&_`EYz`tW#h-?-v@>} z7)Pgm8HDbx*jU9I3vVsF6R7T}MCG3a46o4^Fn80FP+%fZNw` z%S>rKESmYL>XQ+ClPcNfbj&O;;~fWQ^1JjSne_Zto~fj_UD9RN82KKa@2 zoQ2)|S*dl=&%>B^kQQuA56r97KcMrR{zDnl$Y?i>&x<_#LQUm0hhL+~Un=>}M+B^M z4TyNY=`|Z|-uoz@Nq-dx?VoXi%4ZhLBWu?XKg;$cW3?<=c)_(Z*Z>z(RCT<>G%I@e z82VL#8pRnUFN<@v&CA!e~nE`@%ma4`$hj|_# J@QS*E*N^r;d#eBd diff --git "a/out/production/\343\200\220223\343\200\221\343\200\220RectangleArea\343\200\221/Solution.class" "b/out/production/\343\200\220223\343\200\221\343\200\220RectangleArea\343\200\221/Solution.class" deleted file mode 100644 index 1cdde861e5f5d7225ca7e1e67eaca9158cfa920a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1055 zcmaJ<*>2NN5Ir}G?Kn<%hovb{%90e?u#^_M(w#(Mk%B7m=q6TktHche!`A0Wd<-w} zkX9h^0elqVT&Ji=t#C9mXXehGImgbg-`{@%m_flrKe8rrm{jhLa(5G$!nBUO2~C}8 zxM$$LiVqAtRB^_{Bh2cU)A3k9Ta=y*mIb2O+>StO-LJX={UzzSFWQY=xAofDt+O&z z@+(e#$7xBGpA=(3O&$oCrLtdd2h#Tz1deQ_iM;p!ul@*IQ3i{`M`Qt(0HrU{|ImIr8W2B#d zMQQ;Fx=w>HQ*)Y4*Q*L-vc+7l=d1$uO=Zsjkl5E#jxZREt^a|j9OO+~Lx zf%bVDcQB4V{wLKF0rg^#eu!C~Q830Qk08E=$HVkmSWIAq*y=UFMw%Hv7%tNDvY23> z8hSW3TJ6}eOtm9z-HsC*w#LMnON`n2F(RE&JARC4$4wj~HkY(xwxOySTRW|$z9Iet z+M6Tj>0}qiP@)Snol=OYnNFrtl1Ud<7pZh2%-zplxIO|!IgL2|3NB-fsy6xC## + + 4.0.0 + + wjc.leetcode + leetcode + 1.0-SNAPSHOT + + + \ No newline at end of file diff --git "a/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221.iml" "b/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221/\343\200\220001\343\200\221\343\200\220TwoSum\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220002\343\200\221\343\200\220AddTwoNumbers\343\200\221/\343\200\220002\343\200\221\343\200\220AddTwoNumbers\343\200\221.iml" "b/\343\200\220002\343\200\221\343\200\220AddTwoNumbers\343\200\221/\343\200\220002\343\200\221\343\200\220AddTwoNumbers\343\200\221.iml" deleted file mode 100644 index bdc5d75..0000000 --- "a/\343\200\220002\343\200\221\343\200\220AddTwoNumbers\343\200\221/\343\200\220002\343\200\221\343\200\220AddTwoNumbers\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220003\343\200\221\343\200\220LongestSubstringWithoutRepeatingCharacters\343\200\221/\343\200\220003\343\200\221\343\200\220LongestSubstringWithoutRepeatingCharacters\343\200\221.iml" "b/\343\200\220003\343\200\221\343\200\220LongestSubstringWithoutRepeatingCharacters\343\200\221/\343\200\220003\343\200\221\343\200\220LongestSubstringWithoutRepeatingCharacters\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220003\343\200\221\343\200\220LongestSubstringWithoutRepeatingCharacters\343\200\221/\343\200\220003\343\200\221\343\200\220LongestSubstringWithoutRepeatingCharacters\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220004\343\200\221\343\200\220MedianofTwoSortedArrays\343\200\221/\343\200\220004\343\200\221\343\200\220MedianofTwoSortedArrays\343\200\221.iml" "b/\343\200\220004\343\200\221\343\200\220MedianofTwoSortedArrays\343\200\221/\343\200\220004\343\200\221\343\200\220MedianofTwoSortedArrays\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220004\343\200\221\343\200\220MedianofTwoSortedArrays\343\200\221/\343\200\220004\343\200\221\343\200\220MedianofTwoSortedArrays\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220005\343\200\221\343\200\220LongestPalindromicSubstringTotal \343\200\221/\343\200\220005\343\200\221\343\200\220LongestPalindromicSubstringTotal \343\200\221.iml" "b/\343\200\220005\343\200\221\343\200\220LongestPalindromicSubstringTotal \343\200\221/\343\200\220005\343\200\221\343\200\220LongestPalindromicSubstringTotal \343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220005\343\200\221\343\200\220LongestPalindromicSubstringTotal \343\200\221/\343\200\220005\343\200\221\343\200\220LongestPalindromicSubstringTotal \343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220006\343\200\221\343\200\220ZigZagConversion\343\200\221/\343\200\220006\343\200\221\343\200\220ZigZagConversion\343\200\221.iml" "b/\343\200\220006\343\200\221\343\200\220ZigZagConversion\343\200\221/\343\200\220006\343\200\221\343\200\220ZigZagConversion\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220006\343\200\221\343\200\220ZigZagConversion\343\200\221/\343\200\220006\343\200\221\343\200\220ZigZagConversion\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220007\343\200\221\343\200\220ReverseInteger\343\200\221/\343\200\220007\343\200\221\343\200\220ReverseInteger\343\200\221.iml" "b/\343\200\220007\343\200\221\343\200\220ReverseInteger\343\200\221/\343\200\220007\343\200\221\343\200\220ReverseInteger\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220007\343\200\221\343\200\220ReverseInteger\343\200\221/\343\200\220007\343\200\221\343\200\220ReverseInteger\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220008\343\200\221\343\200\220StringToInteger (atoi)\343\200\221/\343\200\220008\343\200\221\343\200\220StringToInteger (atoi)\343\200\221.iml" "b/\343\200\220008\343\200\221\343\200\220StringToInteger (atoi)\343\200\221/\343\200\220008\343\200\221\343\200\220StringToInteger (atoi)\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220008\343\200\221\343\200\220StringToInteger (atoi)\343\200\221/\343\200\220008\343\200\221\343\200\220StringToInteger (atoi)\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220009\343\200\221\343\200\220PalindromeNumber\343\200\221/\343\200\220009\343\200\221\343\200\220PalindromeNumber\343\200\221.iml" "b/\343\200\220009\343\200\221\343\200\220PalindromeNumber\343\200\221/\343\200\220009\343\200\221\343\200\220PalindromeNumber\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220009\343\200\221\343\200\220PalindromeNumber\343\200\221/\343\200\220009\343\200\221\343\200\220PalindromeNumber\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220010\343\200\221\343\200\220RegularExpressionMatching\343\200\221/\343\200\220010\343\200\221\343\200\220RegularExpressionMatching\343\200\221.iml" "b/\343\200\220010\343\200\221\343\200\220RegularExpressionMatching\343\200\221/\343\200\220010\343\200\221\343\200\220RegularExpressionMatching\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220010\343\200\221\343\200\220RegularExpressionMatching\343\200\221/\343\200\220010\343\200\221\343\200\220RegularExpressionMatching\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220011\343\200\221\343\200\220ContainerWithMost Water\343\200\221/\343\200\220011\343\200\221\343\200\220ContainerWithMost Water\343\200\221.iml" "b/\343\200\220011\343\200\221\343\200\220ContainerWithMost Water\343\200\221/\343\200\220011\343\200\221\343\200\220ContainerWithMost Water\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220011\343\200\221\343\200\220ContainerWithMost Water\343\200\221/\343\200\220011\343\200\221\343\200\220ContainerWithMost Water\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220012\343\200\221\343\200\220IntegerToRoman\343\200\221/\343\200\220012\343\200\221\343\200\220IntegerToRoman\343\200\221.iml" "b/\343\200\220012\343\200\221\343\200\220IntegerToRoman\343\200\221/\343\200\220012\343\200\221\343\200\220IntegerToRoman\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220012\343\200\221\343\200\220IntegerToRoman\343\200\221/\343\200\220012\343\200\221\343\200\220IntegerToRoman\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220013\343\200\221\343\200\220RomarToInteger\343\200\221/\343\200\220013\343\200\221\343\200\220RomarToInteger\343\200\221.iml" "b/\343\200\220013\343\200\221\343\200\220RomarToInteger\343\200\221/\343\200\220013\343\200\221\343\200\220RomarToInteger\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220013\343\200\221\343\200\220RomarToInteger\343\200\221/\343\200\220013\343\200\221\343\200\220RomarToInteger\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220014\343\200\221\343\200\220LongestCommonPrefix\343\200\221/\343\200\220014\343\200\221\343\200\220LongestCommonPrefix\343\200\221.iml" "b/\343\200\220014\343\200\221\343\200\220LongestCommonPrefix\343\200\221/\343\200\220014\343\200\221\343\200\220LongestCommonPrefix\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220014\343\200\221\343\200\220LongestCommonPrefix\343\200\221/\343\200\220014\343\200\221\343\200\220LongestCommonPrefix\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220015\343\200\221\343\200\2203Sum\343\200\221/\343\200\220015\343\200\221\343\200\2203Sum\343\200\221.iml" "b/\343\200\220015\343\200\221\343\200\2203Sum\343\200\221/\343\200\220015\343\200\221\343\200\2203Sum\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220015\343\200\221\343\200\2203Sum\343\200\221/\343\200\220015\343\200\221\343\200\2203Sum\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220016\343\200\221\343\200\2203SumClosest\343\200\221/\343\200\220016\343\200\221\343\200\2203SumClosest\343\200\221.iml" "b/\343\200\220016\343\200\221\343\200\2203SumClosest\343\200\221/\343\200\220016\343\200\221\343\200\2203SumClosest\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220016\343\200\221\343\200\2203SumClosest\343\200\221/\343\200\220016\343\200\221\343\200\2203SumClosest\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220017\343\200\221\343\200\220LetterCombinationsOfAPhonNumber \343\200\221/\343\200\220017\343\200\221\343\200\220LetterCombinationsOfAPhonNumber \343\200\221.iml" "b/\343\200\220017\343\200\221\343\200\220LetterCombinationsOfAPhonNumber \343\200\221/\343\200\220017\343\200\221\343\200\220LetterCombinationsOfAPhonNumber \343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220017\343\200\221\343\200\220LetterCombinationsOfAPhonNumber \343\200\221/\343\200\220017\343\200\221\343\200\220LetterCombinationsOfAPhonNumber \343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220018\343\200\221\343\200\2204Sum\343\200\221/\343\200\220018\343\200\221\343\200\2204Sum\343\200\221.iml" "b/\343\200\220018\343\200\221\343\200\2204Sum\343\200\221/\343\200\220018\343\200\221\343\200\2204Sum\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220018\343\200\221\343\200\2204Sum\343\200\221/\343\200\220018\343\200\221\343\200\2204Sum\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220019\343\200\221\343\200\220RemoveNthNodeFromEndOfList\343\200\221/\343\200\220019\343\200\221\343\200\220RemoveNthNodeFromEndOfList\343\200\221.iml" "b/\343\200\220019\343\200\221\343\200\220RemoveNthNodeFromEndOfList\343\200\221/\343\200\220019\343\200\221\343\200\220RemoveNthNodeFromEndOfList\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220019\343\200\221\343\200\220RemoveNthNodeFromEndOfList\343\200\221/\343\200\220019\343\200\221\343\200\220RemoveNthNodeFromEndOfList\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220020\343\200\221\343\200\220ValidParentheses\343\200\221/\343\200\220020\343\200\221\343\200\220ValidParentheses\343\200\221.iml" "b/\343\200\220020\343\200\221\343\200\220ValidParentheses\343\200\221/\343\200\220020\343\200\221\343\200\220ValidParentheses\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220020\343\200\221\343\200\220ValidParentheses\343\200\221/\343\200\220020\343\200\221\343\200\220ValidParentheses\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220021\343\200\221\343\200\220MergeTwoSortedLists\343\200\221/\343\200\220021\343\200\221\343\200\220MergeTwoSortedLists\343\200\221.iml" "b/\343\200\220021\343\200\221\343\200\220MergeTwoSortedLists\343\200\221/\343\200\220021\343\200\221\343\200\220MergeTwoSortedLists\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220021\343\200\221\343\200\220MergeTwoSortedLists\343\200\221/\343\200\220021\343\200\221\343\200\220MergeTwoSortedLists\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220022\343\200\221\343\200\220GenerateParentheses\343\200\221/\343\200\220022\343\200\221\343\200\220GenerateParentheses\343\200\221.iml" "b/\343\200\220022\343\200\221\343\200\220GenerateParentheses\343\200\221/\343\200\220022\343\200\221\343\200\220GenerateParentheses\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220022\343\200\221\343\200\220GenerateParentheses\343\200\221/\343\200\220022\343\200\221\343\200\220GenerateParentheses\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220023\343\200\221\343\200\220MergeKSortedLists\343\200\221/\343\200\220023\343\200\221\343\200\220MergeKSortedLists\343\200\221.iml" "b/\343\200\220023\343\200\221\343\200\220MergeKSortedLists\343\200\221/\343\200\220023\343\200\221\343\200\220MergeKSortedLists\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220023\343\200\221\343\200\220MergeKSortedLists\343\200\221/\343\200\220023\343\200\221\343\200\220MergeKSortedLists\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220024\343\200\221\343\200\220SwapNodesInPairs\343\200\221/\343\200\220024\343\200\221\343\200\220SwapNodesInPairs\343\200\221.iml" "b/\343\200\220024\343\200\221\343\200\220SwapNodesInPairs\343\200\221/\343\200\220024\343\200\221\343\200\220SwapNodesInPairs\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220024\343\200\221\343\200\220SwapNodesInPairs\343\200\221/\343\200\220024\343\200\221\343\200\220SwapNodesInPairs\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221/\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221.iml" "b/\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221/\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221/\343\200\220025\343\200\221\343\200\220ReverseNodesInK-Group\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220026\343\200\221\343\200\220RemoveDuplicatesfromSortedArray\343\200\221/\343\200\220026\343\200\221\343\200\220RemoveDuplicatesfromSortedArray\343\200\221.iml" "b/\343\200\220026\343\200\221\343\200\220RemoveDuplicatesfromSortedArray\343\200\221/\343\200\220026\343\200\221\343\200\220RemoveDuplicatesfromSortedArray\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220026\343\200\221\343\200\220RemoveDuplicatesfromSortedArray\343\200\221/\343\200\220026\343\200\221\343\200\220RemoveDuplicatesfromSortedArray\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220027\343\200\221\343\200\220RemoveElement\343\200\221/\343\200\220027\343\200\221\343\200\220RemoveElement\343\200\221.iml" "b/\343\200\220027\343\200\221\343\200\220RemoveElement\343\200\221/\343\200\220027\343\200\221\343\200\220RemoveElement\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220027\343\200\221\343\200\220RemoveElement\343\200\221/\343\200\220027\343\200\221\343\200\220RemoveElement\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220028\343\200\221\343\200\220Implement-strStr()\343\200\221/\343\200\220028\343\200\221\343\200\220Implement-strStr()\343\200\221.iml" "b/\343\200\220028\343\200\221\343\200\220Implement-strStr()\343\200\221/\343\200\220028\343\200\221\343\200\220Implement-strStr()\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220028\343\200\221\343\200\220Implement-strStr()\343\200\221/\343\200\220028\343\200\221\343\200\220Implement-strStr()\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220029\343\200\221\343\200\220DivideTwoIntegers\343\200\221/\343\200\220029\343\200\221\343\200\220DivideTwoIntegers\343\200\221.iml" "b/\343\200\220029\343\200\221\343\200\220DivideTwoIntegers\343\200\221/\343\200\220029\343\200\221\343\200\220DivideTwoIntegers\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220029\343\200\221\343\200\220DivideTwoIntegers\343\200\221/\343\200\220029\343\200\221\343\200\220DivideTwoIntegers\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220030\343\200\221\343\200\220SubstringWithConcatenationOfAllWords\343\200\221/\343\200\220030\343\200\221\343\200\220SubstringWithConcatenationOfAllWords\343\200\221.iml" "b/\343\200\220030\343\200\221\343\200\220SubstringWithConcatenationOfAllWords\343\200\221/\343\200\220030\343\200\221\343\200\220SubstringWithConcatenationOfAllWords\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220030\343\200\221\343\200\220SubstringWithConcatenationOfAllWords\343\200\221/\343\200\220030\343\200\221\343\200\220SubstringWithConcatenationOfAllWords\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220032\343\200\221\343\200\220LongestValidParentheses\343\200\221/\343\200\220032\343\200\221\343\200\220LongestValidParentheses\343\200\221.iml" "b/\343\200\220032\343\200\221\343\200\220LongestValidParentheses\343\200\221/\343\200\220032\343\200\221\343\200\220LongestValidParentheses\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220032\343\200\221\343\200\220LongestValidParentheses\343\200\221/\343\200\220032\343\200\221\343\200\220LongestValidParentheses\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221/\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221.iml" "b/\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221/\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221/\343\200\220033\343\200\221\343\200\220SearchInRotatedSortedArray\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220034\343\200\221\343\200\220SearchForARange\343\200\221/\343\200\220034\343\200\221\343\200\220SearchForARange\343\200\221.iml" "b/\343\200\220034\343\200\221\343\200\220SearchForARange\343\200\221/\343\200\220034\343\200\221\343\200\220SearchForARange\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220034\343\200\221\343\200\220SearchForARange\343\200\221/\343\200\220034\343\200\221\343\200\220SearchForARange\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220035\343\200\221\343\200\220SearchInsertPosition\343\200\221/\343\200\220035\343\200\221\343\200\220SearchInsertPosition\343\200\221.iml" "b/\343\200\220035\343\200\221\343\200\220SearchInsertPosition\343\200\221/\343\200\220035\343\200\221\343\200\220SearchInsertPosition\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220035\343\200\221\343\200\220SearchInsertPosition\343\200\221/\343\200\220035\343\200\221\343\200\220SearchInsertPosition\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220036\343\200\221\343\200\220Valid Sudoku\343\200\221/\343\200\220036\343\200\221\343\200\220Valid Sudoku\343\200\221.iml" "b/\343\200\220036\343\200\221\343\200\220Valid Sudoku\343\200\221/\343\200\220036\343\200\221\343\200\220Valid Sudoku\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220036\343\200\221\343\200\220Valid Sudoku\343\200\221/\343\200\220036\343\200\221\343\200\220Valid Sudoku\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220037\343\200\221\343\200\220Sudoku Solver\343\200\221/\343\200\220037\343\200\221\343\200\220Sudoku Solver\343\200\221.iml" "b/\343\200\220037\343\200\221\343\200\220Sudoku Solver\343\200\221/\343\200\220037\343\200\221\343\200\220Sudoku Solver\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220037\343\200\221\343\200\220Sudoku Solver\343\200\221/\343\200\220037\343\200\221\343\200\220Sudoku Solver\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220038\343\200\221\343\200\220CountAndSay\343\200\221/\343\200\220038\343\200\221\343\200\220CountAndSay\343\200\221.iml" "b/\343\200\220038\343\200\221\343\200\220CountAndSay\343\200\221/\343\200\220038\343\200\221\343\200\220CountAndSay\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220038\343\200\221\343\200\220CountAndSay\343\200\221/\343\200\220038\343\200\221\343\200\220CountAndSay\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220039\343\200\221\343\200\220Combination Sum\343\200\221/\343\200\220039\343\200\221\343\200\220Combination Sum\343\200\221.iml" "b/\343\200\220039\343\200\221\343\200\220Combination Sum\343\200\221/\343\200\220039\343\200\221\343\200\220Combination Sum\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220039\343\200\221\343\200\220Combination Sum\343\200\221/\343\200\220039\343\200\221\343\200\220Combination Sum\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220040\343\200\221\343\200\220Combination Sum II\343\200\221/\343\200\220040\343\200\221\343\200\220Combination Sum II\343\200\221.iml" "b/\343\200\220040\343\200\221\343\200\220Combination Sum II\343\200\221/\343\200\220040\343\200\221\343\200\220Combination Sum II\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220040\343\200\221\343\200\220Combination Sum II\343\200\221/\343\200\220040\343\200\221\343\200\220Combination Sum II\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220041\343\200\221\343\200\220First Missing Positive\343\200\221/\343\200\220041\343\200\221\343\200\220First Missing Positive\343\200\221.iml" "b/\343\200\220041\343\200\221\343\200\220First Missing Positive\343\200\221/\343\200\220041\343\200\221\343\200\220First Missing Positive\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220041\343\200\221\343\200\220First Missing Positive\343\200\221/\343\200\220041\343\200\221\343\200\220First Missing Positive\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220042\343\200\221\343\200\220Trapping Rain Water\343\200\221/\343\200\220042\343\200\221\343\200\220Trapping Rain Water\343\200\221.iml" "b/\343\200\220042\343\200\221\343\200\220Trapping Rain Water\343\200\221/\343\200\220042\343\200\221\343\200\220Trapping Rain Water\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220042\343\200\221\343\200\220Trapping Rain Water\343\200\221/\343\200\220042\343\200\221\343\200\220Trapping Rain Water\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220043\343\200\221\343\200\220Multiply Strings\343\200\221/\343\200\220043\343\200\221\343\200\220Multiply Strings\343\200\221.iml" "b/\343\200\220043\343\200\221\343\200\220Multiply Strings\343\200\221/\343\200\220043\343\200\221\343\200\220Multiply Strings\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220043\343\200\221\343\200\220Multiply Strings\343\200\221/\343\200\220043\343\200\221\343\200\220Multiply Strings\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220044\343\200\221\343\200\220Wildcard Matching\343\200\221/\343\200\220044\343\200\221\343\200\220Wildcard Matching\343\200\221.iml" "b/\343\200\220044\343\200\221\343\200\220Wildcard Matching\343\200\221/\343\200\220044\343\200\221\343\200\220Wildcard Matching\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220044\343\200\221\343\200\220Wildcard Matching\343\200\221/\343\200\220044\343\200\221\343\200\220Wildcard Matching\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220045\343\200\221\343\200\220Jump Game II\343\200\221/\343\200\220045\343\200\221\343\200\220Jump Game II\343\200\221.iml" "b/\343\200\220045\343\200\221\343\200\220Jump Game II\343\200\221/\343\200\220045\343\200\221\343\200\220Jump Game II\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220045\343\200\221\343\200\220Jump Game II\343\200\221/\343\200\220045\343\200\221\343\200\220Jump Game II\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220046\343\200\221\343\200\220Permutations\343\200\221/\343\200\220046\343\200\221\343\200\220Permutations\343\200\221.iml" "b/\343\200\220046\343\200\221\343\200\220Permutations\343\200\221/\343\200\220046\343\200\221\343\200\220Permutations\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220046\343\200\221\343\200\220Permutations\343\200\221/\343\200\220046\343\200\221\343\200\220Permutations\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220047\343\200\221\343\200\220Permutations II\343\200\221/\343\200\220047\343\200\221\343\200\220Permutations II\343\200\221.iml" "b/\343\200\220047\343\200\221\343\200\220Permutations II\343\200\221/\343\200\220047\343\200\221\343\200\220Permutations II\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220047\343\200\221\343\200\220Permutations II\343\200\221/\343\200\220047\343\200\221\343\200\220Permutations II\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220048\343\200\221\343\200\220Rotate Image\343\200\221/\343\200\220048\343\200\221\343\200\220Rotate Image\343\200\221.iml" "b/\343\200\220048\343\200\221\343\200\220Rotate Image\343\200\221/\343\200\220048\343\200\221\343\200\220Rotate Image\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220048\343\200\221\343\200\220Rotate Image\343\200\221/\343\200\220048\343\200\221\343\200\220Rotate Image\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220049\343\200\221\343\200\220Group Anagrams\343\200\221/\343\200\220049\343\200\221\343\200\220Group Anagrams\343\200\221.iml" "b/\343\200\220049\343\200\221\343\200\220Group Anagrams\343\200\221/\343\200\220049\343\200\221\343\200\220Group Anagrams\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220049\343\200\221\343\200\220Group Anagrams\343\200\221/\343\200\220049\343\200\221\343\200\220Group Anagrams\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220050\343\200\221\343\200\220Pow(x,n)\343\200\221/\343\200\220050\343\200\221\343\200\220Pow(x,n)\343\200\221.iml" "b/\343\200\220050\343\200\221\343\200\220Pow(x,n)\343\200\221/\343\200\220050\343\200\221\343\200\220Pow(x,n)\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220050\343\200\221\343\200\220Pow(x,n)\343\200\221/\343\200\220050\343\200\221\343\200\220Pow(x,n)\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220051\343\200\221\343\200\220N-Queens\343\200\221/\343\200\220051\343\200\221\343\200\220N-Queens\343\200\221.iml" "b/\343\200\220051\343\200\221\343\200\220N-Queens\343\200\221/\343\200\220051\343\200\221\343\200\220N-Queens\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220051\343\200\221\343\200\220N-Queens\343\200\221/\343\200\220051\343\200\221\343\200\220N-Queens\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220052\343\200\221\343\200\220N-Queens II\343\200\221/\343\200\220052\343\200\221\343\200\220N-Queens II\343\200\221.iml" "b/\343\200\220052\343\200\221\343\200\220N-Queens II\343\200\221/\343\200\220052\343\200\221\343\200\220N-Queens II\343\200\221.iml" deleted file mode 100644 index 788d4d1..0000000 --- "a/\343\200\220052\343\200\221\343\200\220N-Queens II\343\200\221/\343\200\220052\343\200\221\343\200\220N-Queens II\343\200\221.iml" +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220053\343\200\221\343\200\220MaximumSubarray\343\200\221/\343\200\220053\343\200\221\343\200\220MaximumSubarray\343\200\221.iml" "b/\343\200\220053\343\200\221\343\200\220MaximumSubarray\343\200\221/\343\200\220053\343\200\221\343\200\220MaximumSubarray\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220053\343\200\221\343\200\220MaximumSubarray\343\200\221/\343\200\220053\343\200\221\343\200\220MaximumSubarray\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220054\343\200\221\343\200\220SpiralMatrix\343\200\221/\343\200\220054\343\200\221\343\200\220SpiralMatrix\343\200\221.iml" "b/\343\200\220054\343\200\221\343\200\220SpiralMatrix\343\200\221/\343\200\220054\343\200\221\343\200\220SpiralMatrix\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220054\343\200\221\343\200\220SpiralMatrix\343\200\221/\343\200\220054\343\200\221\343\200\220SpiralMatrix\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220055\343\200\221\343\200\220Jump Game\343\200\221/\343\200\220055\343\200\221\343\200\220Jump Game\343\200\221.iml" "b/\343\200\220055\343\200\221\343\200\220Jump Game\343\200\221/\343\200\220055\343\200\221\343\200\220Jump Game\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220055\343\200\221\343\200\220Jump Game\343\200\221/\343\200\220055\343\200\221\343\200\220Jump Game\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220056\343\200\221\343\200\220MergeIntervals\343\200\221/\343\200\220056\343\200\221\343\200\220MergeIntervals\343\200\221.iml" "b/\343\200\220056\343\200\221\343\200\220MergeIntervals\343\200\221/\343\200\220056\343\200\221\343\200\220MergeIntervals\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220056\343\200\221\343\200\220MergeIntervals\343\200\221/\343\200\220056\343\200\221\343\200\220MergeIntervals\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220057\343\200\221\343\200\220InsertInterval\343\200\221/\343\200\220057\343\200\221\343\200\220InsertInterval\343\200\221.iml" "b/\343\200\220057\343\200\221\343\200\220InsertInterval\343\200\221/\343\200\220057\343\200\221\343\200\220InsertInterval\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220057\343\200\221\343\200\220InsertInterval\343\200\221/\343\200\220057\343\200\221\343\200\220InsertInterval\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220058\343\200\221\343\200\220LengthOfLastWord\343\200\221/\343\200\220058\343\200\221\343\200\220LengthOfLastWord\343\200\221.iml" "b/\343\200\220058\343\200\221\343\200\220LengthOfLastWord\343\200\221/\343\200\220058\343\200\221\343\200\220LengthOfLastWord\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220058\343\200\221\343\200\220LengthOfLastWord\343\200\221/\343\200\220058\343\200\221\343\200\220LengthOfLastWord\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220059\343\200\221\343\200\220SpiralMatrixII\343\200\221/\343\200\220059\343\200\221\343\200\220SpiralMatrixII\343\200\221.iml" "b/\343\200\220059\343\200\221\343\200\220SpiralMatrixII\343\200\221/\343\200\220059\343\200\221\343\200\220SpiralMatrixII\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220059\343\200\221\343\200\220SpiralMatrixII\343\200\221/\343\200\220059\343\200\221\343\200\220SpiralMatrixII\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220060\343\200\221\343\200\220Permutation Sequence\343\200\221/\343\200\220060\343\200\221\343\200\220Permutation Sequence\343\200\221.iml" "b/\343\200\220060\343\200\221\343\200\220Permutation Sequence\343\200\221/\343\200\220060\343\200\221\343\200\220Permutation Sequence\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220060\343\200\221\343\200\220Permutation Sequence\343\200\221/\343\200\220060\343\200\221\343\200\220Permutation Sequence\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220061\343\200\221\343\200\220RotateList\343\200\221/\343\200\220061\343\200\221\343\200\220RotateList\343\200\221.iml" "b/\343\200\220061\343\200\221\343\200\220RotateList\343\200\221/\343\200\220061\343\200\221\343\200\220RotateList\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220061\343\200\221\343\200\220RotateList\343\200\221/\343\200\220061\343\200\221\343\200\220RotateList\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220062\343\200\221\343\200\220UniquePaths\343\200\221/\343\200\220062\343\200\221\343\200\220UniquePaths\343\200\221.iml" "b/\343\200\220062\343\200\221\343\200\220UniquePaths\343\200\221/\343\200\220062\343\200\221\343\200\220UniquePaths\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220062\343\200\221\343\200\220UniquePaths\343\200\221/\343\200\220062\343\200\221\343\200\220UniquePaths\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220063\343\200\221\343\200\220UniquePathsII\343\200\221/\343\200\220063\343\200\221\343\200\220UniquePathsII\343\200\221.iml" "b/\343\200\220063\343\200\221\343\200\220UniquePathsII\343\200\221/\343\200\220063\343\200\221\343\200\220UniquePathsII\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220063\343\200\221\343\200\220UniquePathsII\343\200\221/\343\200\220063\343\200\221\343\200\220UniquePathsII\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220064\343\200\221\343\200\220MinimumPathSum\343\200\221/\343\200\220064\343\200\221\343\200\220MinimumPathSum\343\200\221.iml" "b/\343\200\220064\343\200\221\343\200\220MinimumPathSum\343\200\221/\343\200\220064\343\200\221\343\200\220MinimumPathSum\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220064\343\200\221\343\200\220MinimumPathSum\343\200\221/\343\200\220064\343\200\221\343\200\220MinimumPathSum\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220066\343\200\221\343\200\220PlusOne\343\200\221/\343\200\220066\343\200\221\343\200\220PlusOne\343\200\221.iml" "b/\343\200\220066\343\200\221\343\200\220PlusOne\343\200\221/\343\200\220066\343\200\221\343\200\220PlusOne\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220066\343\200\221\343\200\220PlusOne\343\200\221/\343\200\220066\343\200\221\343\200\220PlusOne\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220067\343\200\221\343\200\220AddBinary\343\200\221/\343\200\220067\343\200\221\343\200\220AddBinary\343\200\221.iml" "b/\343\200\220067\343\200\221\343\200\220AddBinary\343\200\221/\343\200\220067\343\200\221\343\200\220AddBinary\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220067\343\200\221\343\200\220AddBinary\343\200\221/\343\200\220067\343\200\221\343\200\220AddBinary\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220070\343\200\221\343\200\220ClimbingStairs\343\200\221/\343\200\220070\343\200\221\343\200\220ClimbingStairs\343\200\221.iml" "b/\343\200\220070\343\200\221\343\200\220ClimbingStairs\343\200\221/\343\200\220070\343\200\221\343\200\220ClimbingStairs\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220070\343\200\221\343\200\220ClimbingStairs\343\200\221/\343\200\220070\343\200\221\343\200\220ClimbingStairs\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220071\343\200\221\343\200\220Simplify Path\343\200\221/\343\200\220071\343\200\221\343\200\220Simplify Path\343\200\221.iml" "b/\343\200\220071\343\200\221\343\200\220Simplify Path\343\200\221/\343\200\220071\343\200\221\343\200\220Simplify Path\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220071\343\200\221\343\200\220Simplify Path\343\200\221/\343\200\220071\343\200\221\343\200\220Simplify Path\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220073\343\200\221\343\200\220SetMatrixZeroes\343\200\221/\343\200\220073\343\200\221\343\200\220SetMatrixZeroes\343\200\221.iml" "b/\343\200\220073\343\200\221\343\200\220SetMatrixZeroes\343\200\221/\343\200\220073\343\200\221\343\200\220SetMatrixZeroes\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220073\343\200\221\343\200\220SetMatrixZeroes\343\200\221/\343\200\220073\343\200\221\343\200\220SetMatrixZeroes\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220074\343\200\221\343\200\220SearchA2DMatrix\343\200\221/\343\200\220074\343\200\221\343\200\220SearchA2DMatrix\343\200\221.iml" "b/\343\200\220074\343\200\221\343\200\220SearchA2DMatrix\343\200\221/\343\200\220074\343\200\221\343\200\220SearchA2DMatrix\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220074\343\200\221\343\200\220SearchA2DMatrix\343\200\221/\343\200\220074\343\200\221\343\200\220SearchA2DMatrix\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220075\343\200\221\343\200\220SortColors\343\200\221/\343\200\220075\343\200\221\343\200\220SortColors\343\200\221.iml" "b/\343\200\220075\343\200\221\343\200\220SortColors\343\200\221/\343\200\220075\343\200\221\343\200\220SortColors\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220075\343\200\221\343\200\220SortColors\343\200\221/\343\200\220075\343\200\221\343\200\220SortColors\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220077\343\200\221\343\200\220Combinations\343\200\221/\343\200\220077\343\200\221\343\200\220Combinations\343\200\221.iml" "b/\343\200\220077\343\200\221\343\200\220Combinations\343\200\221/\343\200\220077\343\200\221\343\200\220Combinations\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220077\343\200\221\343\200\220Combinations\343\200\221/\343\200\220077\343\200\221\343\200\220Combinations\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220078\343\200\221\343\200\220Subsets\343\200\221/\343\200\220078\343\200\221\343\200\220Subsets\343\200\221.iml" "b/\343\200\220078\343\200\221\343\200\220Subsets\343\200\221/\343\200\220078\343\200\221\343\200\220Subsets\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220078\343\200\221\343\200\220Subsets\343\200\221/\343\200\220078\343\200\221\343\200\220Subsets\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220079\343\200\221\343\200\220WordSearch\343\200\221/\343\200\220079\343\200\221\343\200\220WordSearch\343\200\221.iml" "b/\343\200\220079\343\200\221\343\200\220WordSearch\343\200\221/\343\200\220079\343\200\221\343\200\220WordSearch\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220079\343\200\221\343\200\220WordSearch\343\200\221/\343\200\220079\343\200\221\343\200\220WordSearch\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220081\343\200\221\343\200\220SearchInRotatedSortedArraII\343\200\221/\343\200\220081\343\200\221\343\200\220SearchInRotatedSortedArraII\343\200\221.iml" "b/\343\200\220081\343\200\221\343\200\220SearchInRotatedSortedArraII\343\200\221/\343\200\220081\343\200\221\343\200\220SearchInRotatedSortedArraII\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220081\343\200\221\343\200\220SearchInRotatedSortedArraII\343\200\221/\343\200\220081\343\200\221\343\200\220SearchInRotatedSortedArraII\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220082\343\200\221\343\200\220RemoveDuplicatesFromSortedListII\343\200\221/\343\200\220082\343\200\221\343\200\220RemoveDuplicatesFromSortedListII\343\200\221.iml" "b/\343\200\220082\343\200\221\343\200\220RemoveDuplicatesFromSortedListII\343\200\221/\343\200\220082\343\200\221\343\200\220RemoveDuplicatesFromSortedListII\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220082\343\200\221\343\200\220RemoveDuplicatesFromSortedListII\343\200\221/\343\200\220082\343\200\221\343\200\220RemoveDuplicatesFromSortedListII\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220083\343\200\221\343\200\220RemoveDuplicatesFromSortedList\343\200\221/\343\200\220083\343\200\221\343\200\220RemoveDuplicatesFromSortedList\343\200\221.iml" "b/\343\200\220083\343\200\221\343\200\220RemoveDuplicatesFromSortedList\343\200\221/\343\200\220083\343\200\221\343\200\220RemoveDuplicatesFromSortedList\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220083\343\200\221\343\200\220RemoveDuplicatesFromSortedList\343\200\221/\343\200\220083\343\200\221\343\200\220RemoveDuplicatesFromSortedList\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220086\343\200\221\343\200\220PartitionList\343\200\221/\343\200\220086\343\200\221\343\200\220PartitionList\343\200\221.iml" "b/\343\200\220086\343\200\221\343\200\220PartitionList\343\200\221/\343\200\220086\343\200\221\343\200\220PartitionList\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220086\343\200\221\343\200\220PartitionList\343\200\221/\343\200\220086\343\200\221\343\200\220PartitionList\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220088\343\200\221\343\200\220MergeSortedArray\343\200\221/\343\200\220088\343\200\221\343\200\220MergeSortedArray\343\200\221.iml" "b/\343\200\220088\343\200\221\343\200\220MergeSortedArray\343\200\221/\343\200\220088\343\200\221\343\200\220MergeSortedArray\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220088\343\200\221\343\200\220MergeSortedArray\343\200\221/\343\200\220088\343\200\221\343\200\220MergeSortedArray\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220089\343\200\221\343\200\220GrayCode\343\200\221/\343\200\220089\343\200\221\343\200\220GrayCode\343\200\221.iml" "b/\343\200\220089\343\200\221\343\200\220GrayCode\343\200\221/\343\200\220089\343\200\221\343\200\220GrayCode\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220089\343\200\221\343\200\220GrayCode\343\200\221/\343\200\220089\343\200\221\343\200\220GrayCode\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220092\343\200\221\343\200\220ReverseLinkedListII\343\200\221/\343\200\220092\343\200\221\343\200\220ReverseLinkedListII\343\200\221.iml" "b/\343\200\220092\343\200\221\343\200\220ReverseLinkedListII\343\200\221/\343\200\220092\343\200\221\343\200\220ReverseLinkedListII\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220092\343\200\221\343\200\220ReverseLinkedListII\343\200\221/\343\200\220092\343\200\221\343\200\220ReverseLinkedListII\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221/\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221.iml" "b/\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221/\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221/\343\200\220094\343\200\221\343\200\220BinaryTree InorderTraversal\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220096\343\200\221\343\200\220UniqueBinarySearchTrees\343\200\221/\343\200\220096\343\200\221\343\200\220UniqueBinarySearchTrees\343\200\221.iml" "b/\343\200\220096\343\200\221\343\200\220UniqueBinarySearchTrees\343\200\221/\343\200\220096\343\200\221\343\200\220UniqueBinarySearchTrees\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220096\343\200\221\343\200\220UniqueBinarySearchTrees\343\200\221/\343\200\220096\343\200\221\343\200\220UniqueBinarySearchTrees\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220098\343\200\221\343\200\220ValidateBinarySearchTree\343\200\221/\343\200\220098\343\200\221\343\200\220ValidateBinarySearchTree\343\200\221.iml" "b/\343\200\220098\343\200\221\343\200\220ValidateBinarySearchTree\343\200\221/\343\200\220098\343\200\221\343\200\220ValidateBinarySearchTree\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220098\343\200\221\343\200\220ValidateBinarySearchTree\343\200\221/\343\200\220098\343\200\221\343\200\220ValidateBinarySearchTree\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220100\343\200\221\343\200\220SameTree\343\200\221/\343\200\220100\343\200\221\343\200\220SameTree\343\200\221.iml" "b/\343\200\220100\343\200\221\343\200\220SameTree\343\200\221/\343\200\220100\343\200\221\343\200\220SameTree\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220100\343\200\221\343\200\220SameTree\343\200\221/\343\200\220100\343\200\221\343\200\220SameTree\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220101\343\200\221\343\200\220SymmetricTree\343\200\221/\343\200\220101\343\200\221\343\200\220SymmetricTree\343\200\221.iml" "b/\343\200\220101\343\200\221\343\200\220SymmetricTree\343\200\221/\343\200\220101\343\200\221\343\200\220SymmetricTree\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220101\343\200\221\343\200\220SymmetricTree\343\200\221/\343\200\220101\343\200\221\343\200\220SymmetricTree\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220102\343\200\221\343\200\220BinaryTreeLevelOrderTraversal\343\200\221/\343\200\220102\343\200\221\343\200\220BinaryTreeLevelOrderTraversal\343\200\221.iml" "b/\343\200\220102\343\200\221\343\200\220BinaryTreeLevelOrderTraversal\343\200\221/\343\200\220102\343\200\221\343\200\220BinaryTreeLevelOrderTraversal\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220102\343\200\221\343\200\220BinaryTreeLevelOrderTraversal\343\200\221/\343\200\220102\343\200\221\343\200\220BinaryTreeLevelOrderTraversal\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221/\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221.iml" "b/\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221/\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221/\343\200\220103\343\200\221\343\200\220BinaryTreeZigzagLevelOrderTraversal\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220104\343\200\221\343\200\220MaximumDepthOfBinaryTree\343\200\221/\343\200\220104\343\200\221\343\200\220MaximumDepthOfBinaryTree\343\200\221.iml" "b/\343\200\220104\343\200\221\343\200\220MaximumDepthOfBinaryTree\343\200\221/\343\200\220104\343\200\221\343\200\220MaximumDepthOfBinaryTree\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220104\343\200\221\343\200\220MaximumDepthOfBinaryTree\343\200\221/\343\200\220104\343\200\221\343\200\220MaximumDepthOfBinaryTree\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220105\343\200\221\343\200\220ConstructBinaryTreeFromPreorderAndInorderTraversal\343\200\221/\343\200\220105\343\200\221\343\200\220ConstructBinaryTreeFromPreorderAndInorderTraversal\343\200\221.iml" "b/\343\200\220105\343\200\221\343\200\220ConstructBinaryTreeFromPreorderAndInorderTraversal\343\200\221/\343\200\220105\343\200\221\343\200\220ConstructBinaryTreeFromPreorderAndInorderTraversal\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220105\343\200\221\343\200\220ConstructBinaryTreeFromPreorderAndInorderTraversal\343\200\221/\343\200\220105\343\200\221\343\200\220ConstructBinaryTreeFromPreorderAndInorderTraversal\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220106\343\200\221\343\200\220ConstructBinaryTreeFromInorderAndPostorderTraversal\343\200\221/\343\200\220106\343\200\221\343\200\220ConstructBinaryTreeFromInorderAndPostorderTraversal\343\200\221.iml" "b/\343\200\220106\343\200\221\343\200\220ConstructBinaryTreeFromInorderAndPostorderTraversal\343\200\221/\343\200\220106\343\200\221\343\200\220ConstructBinaryTreeFromInorderAndPostorderTraversal\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220106\343\200\221\343\200\220ConstructBinaryTreeFromInorderAndPostorderTraversal\343\200\221/\343\200\220106\343\200\221\343\200\220ConstructBinaryTreeFromInorderAndPostorderTraversal\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220107\343\200\221\343\200\220BinaryTreeLevelOrderTraversalII\343\200\221/\343\200\220107\343\200\221\343\200\220BinaryTreeLevelOrderTraversalII\343\200\221.iml" "b/\343\200\220107\343\200\221\343\200\220BinaryTreeLevelOrderTraversalII\343\200\221/\343\200\220107\343\200\221\343\200\220BinaryTreeLevelOrderTraversalII\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220107\343\200\221\343\200\220BinaryTreeLevelOrderTraversalII\343\200\221/\343\200\220107\343\200\221\343\200\220BinaryTreeLevelOrderTraversalII\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220108\343\200\221\343\200\220ConvertSortedArrayToBinarySearchTree\343\200\221/\343\200\220108\343\200\221\343\200\220ConvertSortedArrayToBinarySearchTree\343\200\221.iml" "b/\343\200\220108\343\200\221\343\200\220ConvertSortedArrayToBinarySearchTree\343\200\221/\343\200\220108\343\200\221\343\200\220ConvertSortedArrayToBinarySearchTree\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220108\343\200\221\343\200\220ConvertSortedArrayToBinarySearchTree\343\200\221/\343\200\220108\343\200\221\343\200\220ConvertSortedArrayToBinarySearchTree\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221.iml" "b/\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221/\343\200\220109\343\200\221\343\200\220ConvertSortedListToBinarySearchTree\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220110\343\200\221\343\200\220BalancedBinaryTree\343\200\221/\343\200\220110\343\200\221\343\200\220BalancedBinaryTree\343\200\221.iml" "b/\343\200\220110\343\200\221\343\200\220BalancedBinaryTree\343\200\221/\343\200\220110\343\200\221\343\200\220BalancedBinaryTree\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220110\343\200\221\343\200\220BalancedBinaryTree\343\200\221/\343\200\220110\343\200\221\343\200\220BalancedBinaryTree\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220111\343\200\221\343\200\220MinimumDepthOfBinaryTree\343\200\221/\343\200\220111\343\200\221\343\200\220MinimumDepthOfBinaryTree\343\200\221.iml" "b/\343\200\220111\343\200\221\343\200\220MinimumDepthOfBinaryTree\343\200\221/\343\200\220111\343\200\221\343\200\220MinimumDepthOfBinaryTree\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220111\343\200\221\343\200\220MinimumDepthOfBinaryTree\343\200\221/\343\200\220111\343\200\221\343\200\220MinimumDepthOfBinaryTree\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220112\343\200\221\343\200\220PathSum\343\200\221/\343\200\220112\343\200\221\343\200\220PathSum\343\200\221.iml" "b/\343\200\220112\343\200\221\343\200\220PathSum\343\200\221/\343\200\220112\343\200\221\343\200\220PathSum\343\200\221.iml" deleted file mode 100644 index 86622ab..0000000 --- "a/\343\200\220112\343\200\221\343\200\220PathSum\343\200\221/\343\200\220112\343\200\221\343\200\220PathSum\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220113\343\200\221\343\200\220PathSumII\343\200\221/\343\200\220113\343\200\221\343\200\220PathSumII\343\200\221.iml" "b/\343\200\220113\343\200\221\343\200\220PathSumII\343\200\221/\343\200\220113\343\200\221\343\200\220PathSumII\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220113\343\200\221\343\200\220PathSumII\343\200\221/\343\200\220113\343\200\221\343\200\220PathSumII\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220114\343\200\221\343\200\220FlattenBinaryTreeToLinkedList\343\200\221/\343\200\220114\343\200\221\343\200\220FlattenBinaryTreeToLinkedList\343\200\221.iml" "b/\343\200\220114\343\200\221\343\200\220FlattenBinaryTreeToLinkedList\343\200\221/\343\200\220114\343\200\221\343\200\220FlattenBinaryTreeToLinkedList\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220114\343\200\221\343\200\220FlattenBinaryTreeToLinkedList\343\200\221/\343\200\220114\343\200\221\343\200\220FlattenBinaryTreeToLinkedList\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220116\343\200\221\343\200\220PopulatingNextRightPointersinEachNode \343\200\221/\343\200\220116\343\200\221\343\200\220PopulatingNextRightPointersinEachNode \343\200\221.iml" "b/\343\200\220116\343\200\221\343\200\220PopulatingNextRightPointersinEachNode \343\200\221/\343\200\220116\343\200\221\343\200\220PopulatingNextRightPointersinEachNode \343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220116\343\200\221\343\200\220PopulatingNextRightPointersinEachNode \343\200\221/\343\200\220116\343\200\221\343\200\220PopulatingNextRightPointersinEachNode \343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221/\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221.iml" "b/\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221/\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221/\343\200\220117\343\200\221\343\200\220PopulatingNextRightPointersInEachNodeII\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220118\343\200\221\343\200\220Pascal'sTriangle\343\200\221/\343\200\220118\343\200\221\343\200\220Pascal'sTriangle\343\200\221.iml" "b/\343\200\220118\343\200\221\343\200\220Pascal'sTriangle\343\200\221/\343\200\220118\343\200\221\343\200\220Pascal'sTriangle\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220118\343\200\221\343\200\220Pascal'sTriangle\343\200\221/\343\200\220118\343\200\221\343\200\220Pascal'sTriangle\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220119\343\200\221\343\200\220Pascal'sTriangleII\343\200\221/\343\200\220119\343\200\221\343\200\220Pascal'sTriangleII\343\200\221.iml" "b/\343\200\220119\343\200\221\343\200\220Pascal'sTriangleII\343\200\221/\343\200\220119\343\200\221\343\200\220Pascal'sTriangleII\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220119\343\200\221\343\200\220Pascal'sTriangleII\343\200\221/\343\200\220119\343\200\221\343\200\220Pascal'sTriangleII\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220120\343\200\221\343\200\220Triangle\343\200\221/\343\200\220120\343\200\221\343\200\220Triangle\343\200\221.iml" "b/\343\200\220120\343\200\221\343\200\220Triangle\343\200\221/\343\200\220120\343\200\221\343\200\220Triangle\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220120\343\200\221\343\200\220Triangle\343\200\221/\343\200\220120\343\200\221\343\200\220Triangle\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220121\343\200\221\343\200\220BestTimeToBuyAndSellStock\343\200\221/\343\200\220121\343\200\221\343\200\220BestTimeToBuyAndSellStock\343\200\221.iml" "b/\343\200\220121\343\200\221\343\200\220BestTimeToBuyAndSellStock\343\200\221/\343\200\220121\343\200\221\343\200\220BestTimeToBuyAndSellStock\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220121\343\200\221\343\200\220BestTimeToBuyAndSellStock\343\200\221/\343\200\220121\343\200\221\343\200\220BestTimeToBuyAndSellStock\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220124\346\234\252\343\200\221\343\200\220BinaryTreeMaximumPathSum\343\200\221/\343\200\220124\343\200\221\343\200\220BinaryTreeMaximumPathSum\343\200\221.iml" "b/\343\200\220124\346\234\252\343\200\221\343\200\220BinaryTreeMaximumPathSum\343\200\221/\343\200\220124\343\200\221\343\200\220BinaryTreeMaximumPathSum\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220124\346\234\252\343\200\221\343\200\220BinaryTreeMaximumPathSum\343\200\221/\343\200\220124\343\200\221\343\200\220BinaryTreeMaximumPathSum\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220125\343\200\221\343\200\220ValidPalindrome\343\200\221/\343\200\220125\343\200\221\343\200\220ValidPalindrome\343\200\221.iml" "b/\343\200\220125\343\200\221\343\200\220ValidPalindrome\343\200\221/\343\200\220125\343\200\221\343\200\220ValidPalindrome\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220125\343\200\221\343\200\220ValidPalindrome\343\200\221/\343\200\220125\343\200\221\343\200\220ValidPalindrome\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220127\346\234\252\343\200\221\343\200\220WordLadder\343\200\221/\343\200\220127\343\200\221\343\200\220WordLadder\343\200\221.iml" "b/\343\200\220127\346\234\252\343\200\221\343\200\220WordLadder\343\200\221/\343\200\220127\343\200\221\343\200\220WordLadder\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220127\346\234\252\343\200\221\343\200\220WordLadder\343\200\221/\343\200\220127\343\200\221\343\200\220WordLadder\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220129\343\200\221\343\200\220SumRootToLeafNumbers\343\200\221/\343\200\220129\343\200\221\343\200\220SumRootToLeafNumbers\343\200\221.iml" "b/\343\200\220129\343\200\221\343\200\220SumRootToLeafNumbers\343\200\221/\343\200\220129\343\200\221\343\200\220SumRootToLeafNumbers\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220129\343\200\221\343\200\220SumRootToLeafNumbers\343\200\221/\343\200\220129\343\200\221\343\200\220SumRootToLeafNumbers\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220130\343\200\221\343\200\220SurroundedRegions\343\200\221/\343\200\220130\343\200\221\343\200\220SurroundedRegions\343\200\221.iml" "b/\343\200\220130\343\200\221\343\200\220SurroundedRegions\343\200\221/\343\200\220130\343\200\221\343\200\220SurroundedRegions\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220130\343\200\221\343\200\220SurroundedRegions\343\200\221/\343\200\220130\343\200\221\343\200\220SurroundedRegions\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220134\343\200\221\343\200\220GasStation\343\200\221/\343\200\220134\343\200\221\343\200\220GasStation\343\200\221.iml" "b/\343\200\220134\343\200\221\343\200\220GasStation\343\200\221/\343\200\220134\343\200\221\343\200\220GasStation\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220134\343\200\221\343\200\220GasStation\343\200\221/\343\200\220134\343\200\221\343\200\220GasStation\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220136\343\200\221\343\200\220SingleNumber\343\200\221/\343\200\220136\343\200\221\343\200\220SingleNumber\343\200\221.iml" "b/\343\200\220136\343\200\221\343\200\220SingleNumber\343\200\221/\343\200\220136\343\200\221\343\200\220SingleNumber\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220136\343\200\221\343\200\220SingleNumber\343\200\221/\343\200\220136\343\200\221\343\200\220SingleNumber\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220137\343\200\221\343\200\220SingleNumberII\343\200\221/\343\200\220137\343\200\221\343\200\220SingleNumberII\343\200\221.iml" "b/\343\200\220137\343\200\221\343\200\220SingleNumberII\343\200\221/\343\200\220137\343\200\221\343\200\220SingleNumberII\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220137\343\200\221\343\200\220SingleNumberII\343\200\221/\343\200\220137\343\200\221\343\200\220SingleNumberII\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221.iml" "b/\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/\343\200\220138\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220139\343\200\221\343\200\220WordBreak\343\200\221/\343\200\220139\343\200\221\343\200\220WordBreak\343\200\221.iml" "b/\343\200\220139\343\200\221\343\200\220WordBreak\343\200\221/\343\200\220139\343\200\221\343\200\220WordBreak\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220139\343\200\221\343\200\220WordBreak\343\200\221/\343\200\220139\343\200\221\343\200\220WordBreak\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220141\343\200\221\343\200\220LinkedListCycle\343\200\221/\343\200\220141\343\200\221\343\200\220LinkedListCycle\343\200\221.iml" "b/\343\200\220141\343\200\221\343\200\220LinkedListCycle\343\200\221/\343\200\220141\343\200\221\343\200\220LinkedListCycle\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220141\343\200\221\343\200\220LinkedListCycle\343\200\221/\343\200\220141\343\200\221\343\200\220LinkedListCycle\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220142\343\200\221\343\200\220LinkedListCycleII\343\200\221/\343\200\220142\343\200\221\343\200\220LinkedListCycleII\343\200\221.iml" "b/\343\200\220142\343\200\221\343\200\220LinkedListCycleII\343\200\221/\343\200\220142\343\200\221\343\200\220LinkedListCycleII\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220142\343\200\221\343\200\220LinkedListCycleII\343\200\221/\343\200\220142\343\200\221\343\200\220LinkedListCycleII\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220143\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/\343\200\220143\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221.iml" "b/\343\200\220143\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/\343\200\220143\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220143\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221/\343\200\220143\343\200\221\343\200\220CopyListWithRandomPointer\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220144\343\200\221\343\200\220BinaryTreePreorderTraversal\343\200\221/\343\200\220144\343\200\221\343\200\220BinaryTreePreorderTraversal\343\200\221.iml" "b/\343\200\220144\343\200\221\343\200\220BinaryTreePreorderTraversal\343\200\221/\343\200\220144\343\200\221\343\200\220BinaryTreePreorderTraversal\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220144\343\200\221\343\200\220BinaryTreePreorderTraversal\343\200\221/\343\200\220144\343\200\221\343\200\220BinaryTreePreorderTraversal\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220145\343\200\221\343\200\220BinaryTreePostorderTraversal\343\200\221/\343\200\220145\343\200\221\343\200\220BinaryTreePostorderTraversal\343\200\221.iml" "b/\343\200\220145\343\200\221\343\200\220BinaryTreePostorderTraversal\343\200\221/\343\200\220145\343\200\221\343\200\220BinaryTreePostorderTraversal\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220145\343\200\221\343\200\220BinaryTreePostorderTraversal\343\200\221/\343\200\220145\343\200\221\343\200\220BinaryTreePostorderTraversal\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220147\343\200\221\343\200\220InsertionSortList\343\200\221/\343\200\220147\343\200\221\343\200\220InsertionSortList\343\200\221.iml" "b/\343\200\220147\343\200\221\343\200\220InsertionSortList\343\200\221/\343\200\220147\343\200\221\343\200\220InsertionSortList\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220147\343\200\221\343\200\220InsertionSortList\343\200\221/\343\200\220147\343\200\221\343\200\220InsertionSortList\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220150\343\200\221\343\200\220EvaluateReversePolishNotation\343\200\221/\343\200\220150\343\200\221\343\200\220EvaluateReversePolishNotation\343\200\221.iml" "b/\343\200\220150\343\200\221\343\200\220EvaluateReversePolishNotation\343\200\221/\343\200\220150\343\200\221\343\200\220EvaluateReversePolishNotation\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220150\343\200\221\343\200\220EvaluateReversePolishNotation\343\200\221/\343\200\220150\343\200\221\343\200\220EvaluateReversePolishNotation\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220151\343\200\221\343\200\220ReverseWordsInAString\343\200\221/\343\200\220151\343\200\221\343\200\220ReverseWordsInAString\343\200\221.iml" "b/\343\200\220151\343\200\221\343\200\220ReverseWordsInAString\343\200\221/\343\200\220151\343\200\221\343\200\220ReverseWordsInAString\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220151\343\200\221\343\200\220ReverseWordsInAString\343\200\221/\343\200\220151\343\200\221\343\200\220ReverseWordsInAString\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220152\343\200\221\343\200\220MaximumProductSubarray\343\200\221/\343\200\220152\343\200\221\343\200\220MaximumProductSubarray\343\200\221.iml" "b/\343\200\220152\343\200\221\343\200\220MaximumProductSubarray\343\200\221/\343\200\220152\343\200\221\343\200\220MaximumProductSubarray\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220152\343\200\221\343\200\220MaximumProductSubarray\343\200\221/\343\200\220152\343\200\221\343\200\220MaximumProductSubarray\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220153\343\200\221\343\200\220FindMinimumInRotatedSortedArray\343\200\221/\343\200\220153\343\200\221\343\200\220FindMinimumInRotatedSortedArray\343\200\221.iml" "b/\343\200\220153\343\200\221\343\200\220FindMinimumInRotatedSortedArray\343\200\221/\343\200\220153\343\200\221\343\200\220FindMinimumInRotatedSortedArray\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220153\343\200\221\343\200\220FindMinimumInRotatedSortedArray\343\200\221/\343\200\220153\343\200\221\343\200\220FindMinimumInRotatedSortedArray\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220154\343\200\221\343\200\220FindMinimumInRotatedSortedArrayII\343\200\221/\343\200\220154\343\200\221\343\200\220FindMinimumInRotatedSortedArrayII\343\200\221.iml" "b/\343\200\220154\343\200\221\343\200\220FindMinimumInRotatedSortedArrayII\343\200\221/\343\200\220154\343\200\221\343\200\220FindMinimumInRotatedSortedArrayII\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220154\343\200\221\343\200\220FindMinimumInRotatedSortedArrayII\343\200\221/\343\200\220154\343\200\221\343\200\220FindMinimumInRotatedSortedArrayII\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220155\343\200\221\343\200\220MinStack\343\200\221/\343\200\220155\343\200\221\343\200\220MinStack\343\200\221.iml" "b/\343\200\220155\343\200\221\343\200\220MinStack\343\200\221/\343\200\220155\343\200\221\343\200\220MinStack\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220155\343\200\221\343\200\220MinStack\343\200\221/\343\200\220155\343\200\221\343\200\220MinStack\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220162\346\234\252\343\200\221\343\200\220FindPeakElement\343\200\221/\343\200\220162\343\200\221\343\200\220FindPeakElement\343\200\221.iml" "b/\343\200\220162\346\234\252\343\200\221\343\200\220FindPeakElement\343\200\221/\343\200\220162\343\200\221\343\200\220FindPeakElement\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220162\346\234\252\343\200\221\343\200\220FindPeakElement\343\200\221/\343\200\220162\343\200\221\343\200\220FindPeakElement\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220167\343\200\221\343\200\220Two Sum II - Input array is sorted\343\200\221/\343\200\220167\343\200\221\343\200\220Two Sum II - Input array is sorted\343\200\221.iml" "b/\343\200\220167\343\200\221\343\200\220Two Sum II - Input array is sorted\343\200\221/\343\200\220167\343\200\221\343\200\220Two Sum II - Input array is sorted\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220167\343\200\221\343\200\220Two Sum II - Input array is sorted\343\200\221/\343\200\220167\343\200\221\343\200\220Two Sum II - Input array is sorted\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220191\343\200\221\343\200\220NumberOf1Bits\343\200\221/\343\200\220191\343\200\221\343\200\220NumberOf1Bits\343\200\221.iml" "b/\343\200\220191\343\200\221\343\200\220NumberOf1Bits\343\200\221/\343\200\220191\343\200\221\343\200\220NumberOf1Bits\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220191\343\200\221\343\200\220NumberOf1Bits\343\200\221/\343\200\220191\343\200\221\343\200\220NumberOf1Bits\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220198\343\200\221\343\200\220HouseRobber\343\200\221/\343\200\220198\343\200\221\343\200\220HouseRobber\343\200\221.iml" "b/\343\200\220198\343\200\221\343\200\220HouseRobber\343\200\221/\343\200\220198\343\200\221\343\200\220HouseRobber\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220198\343\200\221\343\200\220HouseRobber\343\200\221/\343\200\220198\343\200\221\343\200\220HouseRobber\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220199\343\200\221\343\200\220BinaryTreeRightSideView\343\200\221/\343\200\220199\343\200\221\343\200\220BinaryTreeRightSideView\343\200\221.iml" "b/\343\200\220199\343\200\221\343\200\220BinaryTreeRightSideView\343\200\221/\343\200\220199\343\200\221\343\200\220BinaryTreeRightSideView\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220199\343\200\221\343\200\220BinaryTreeRightSideView\343\200\221/\343\200\220199\343\200\221\343\200\220BinaryTreeRightSideView\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220200\343\200\221\343\200\220NumberOfIslands\343\200\221/\343\200\220200\343\200\221\343\200\220NumberOfIslands\343\200\221.iml" "b/\343\200\220200\343\200\221\343\200\220NumberOfIslands\343\200\221/\343\200\220200\343\200\221\343\200\220NumberOfIslands\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220200\343\200\221\343\200\220NumberOfIslands\343\200\221/\343\200\220200\343\200\221\343\200\220NumberOfIslands\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220201\343\200\221\343\200\220BitwiseANDOfNumbersRange\343\200\221/\343\200\220201\343\200\221\343\200\220BitwiseANDOfNumbersRange\343\200\221.iml" "b/\343\200\220201\343\200\221\343\200\220BitwiseANDOfNumbersRange\343\200\221/\343\200\220201\343\200\221\343\200\220BitwiseANDOfNumbersRange\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220201\343\200\221\343\200\220BitwiseANDOfNumbersRange\343\200\221/\343\200\220201\343\200\221\343\200\220BitwiseANDOfNumbersRange\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220202\343\200\221\343\200\220HappyNumber \343\200\221/\343\200\220202\343\200\221\343\200\220HappyNumber \343\200\221.iml" "b/\343\200\220202\343\200\221\343\200\220HappyNumber \343\200\221/\343\200\220202\343\200\221\343\200\220HappyNumber \343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220202\343\200\221\343\200\220HappyNumber \343\200\221/\343\200\220202\343\200\221\343\200\220HappyNumber \343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220203\343\200\221\343\200\220RemoveLinkedList Elements\343\200\221/\343\200\220203\343\200\221\343\200\220RemoveLinkedList Elements\343\200\221.iml" "b/\343\200\220203\343\200\221\343\200\220RemoveLinkedList Elements\343\200\221/\343\200\220203\343\200\221\343\200\220RemoveLinkedList Elements\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220203\343\200\221\343\200\220RemoveLinkedList Elements\343\200\221/\343\200\220203\343\200\221\343\200\220RemoveLinkedList Elements\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220204\343\200\221\343\200\220CountPrimes\343\200\221/\343\200\220204\343\200\221\343\200\220CountPrimes\343\200\221.iml" "b/\343\200\220204\343\200\221\343\200\220CountPrimes\343\200\221/\343\200\220204\343\200\221\343\200\220CountPrimes\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220204\343\200\221\343\200\220CountPrimes\343\200\221/\343\200\220204\343\200\221\343\200\220CountPrimes\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220205\343\200\221\343\200\220IsomorphicStrings\343\200\221/\343\200\220205\343\200\221\343\200\220IsomorphicStrings\343\200\221.iml" "b/\343\200\220205\343\200\221\343\200\220IsomorphicStrings\343\200\221/\343\200\220205\343\200\221\343\200\220IsomorphicStrings\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220205\343\200\221\343\200\220IsomorphicStrings\343\200\221/\343\200\220205\343\200\221\343\200\220IsomorphicStrings\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220206\343\200\221\343\200\220ReverseLinkedList\343\200\221/\343\200\220206\343\200\221\343\200\220ReverseLinkedList\343\200\221.iml" "b/\343\200\220206\343\200\221\343\200\220ReverseLinkedList\343\200\221/\343\200\220206\343\200\221\343\200\220ReverseLinkedList\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220206\343\200\221\343\200\220ReverseLinkedList\343\200\221/\343\200\220206\343\200\221\343\200\220ReverseLinkedList\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220215\343\200\221\343\200\220KthLargestElementInAnArray\343\200\221/\343\200\220215\343\200\221\343\200\220KthLargestElementInAnArray\343\200\221.iml" "b/\343\200\220215\343\200\221\343\200\220KthLargestElementInAnArray\343\200\221/\343\200\220215\343\200\221\343\200\220KthLargestElementInAnArray\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220215\343\200\221\343\200\220KthLargestElementInAnArray\343\200\221/\343\200\220215\343\200\221\343\200\220KthLargestElementInAnArray\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220216\343\200\221\343\200\220CombinationSumIII\343\200\221/\343\200\220216\343\200\221\343\200\220CombinationSumIII\343\200\221.iml" "b/\343\200\220216\343\200\221\343\200\220CombinationSumIII\343\200\221/\343\200\220216\343\200\221\343\200\220CombinationSumIII\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220216\343\200\221\343\200\220CombinationSumIII\343\200\221/\343\200\220216\343\200\221\343\200\220CombinationSumIII\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220217\343\200\221\343\200\220ContainsDuplicate \343\200\221/\343\200\220217\343\200\221\343\200\220ContainsDuplicate \343\200\221.iml" "b/\343\200\220217\343\200\221\343\200\220ContainsDuplicate \343\200\221/\343\200\220217\343\200\221\343\200\220ContainsDuplicate \343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220217\343\200\221\343\200\220ContainsDuplicate \343\200\221/\343\200\220217\343\200\221\343\200\220ContainsDuplicate \343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220219\343\200\221\343\200\220ContainsDuplicateII\343\200\221/\343\200\220219\343\200\221\343\200\220ContainsDuplicateII\343\200\221.iml" "b/\343\200\220219\343\200\221\343\200\220ContainsDuplicateII\343\200\221/\343\200\220219\343\200\221\343\200\220ContainsDuplicateII\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220219\343\200\221\343\200\220ContainsDuplicateII\343\200\221/\343\200\220219\343\200\221\343\200\220ContainsDuplicateII\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220223\343\200\221\343\200\220RectangleArea\343\200\221/\343\200\220223\343\200\221\343\200\220RectangleArea\343\200\221.iml" "b/\343\200\220223\343\200\221\343\200\220RectangleArea\343\200\221/\343\200\220223\343\200\221\343\200\220RectangleArea\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220223\343\200\221\343\200\220RectangleArea\343\200\221/\343\200\220223\343\200\221\343\200\220RectangleArea\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220225\343\200\221\343\200\220ImplementStackUsingQueues\343\200\221/\343\200\220225\343\200\221\343\200\220ImplementStackUsingQueues\343\200\221.iml" "b/\343\200\220225\343\200\221\343\200\220ImplementStackUsingQueues\343\200\221/\343\200\220225\343\200\221\343\200\220ImplementStackUsingQueues\343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220225\343\200\221\343\200\220ImplementStackUsingQueues\343\200\221/\343\200\220225\343\200\221\343\200\220ImplementStackUsingQueues\343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git "a/\343\200\220226\343\200\221\343\200\220InvertBinaryTree \343\200\221/\343\200\220226\343\200\221\343\200\220InvertBinaryTree \343\200\221.iml" "b/\343\200\220226\343\200\221\343\200\220InvertBinaryTree \343\200\221/\343\200\220226\343\200\221\343\200\220InvertBinaryTree \343\200\221.iml" deleted file mode 100644 index f080bef..0000000 --- "a/\343\200\220226\343\200\221\343\200\220InvertBinaryTree \343\200\221/\343\200\220226\343\200\221\343\200\220InvertBinaryTree \343\200\221.iml" +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file From 763737a92e95946a8107ea0fbfe404db91ca6707 Mon Sep 17 00:00:00 2001 From: Wang-Jun-Chao Date: Fri, 14 Jun 2019 20:52:47 +0800 Subject: [PATCH 038/108] commit --- .idea/modules.xml | 3 +- [001][Two Sum]/src/Main.java | 24 +++- [001][Two Sum]/src/Solution.java | 70 ++++------- [001][Two Sum]/src/Solution2.java | 94 ++++++++++++++ .../src/Main.java | 35 ++++++ .../src/Solution.java | 91 ++++++++------ [015][3 Sum]/src/Main.java | 45 ++++++- [015][3 Sum]/src/Solution.java | 109 ++++++---------- [015][3 Sum]/src/Solution2.java | 119 ++++++++++++++++++ [015][3 Sum]/src/Solution3.java | 68 ++++++++++ .../src/Main.java | 0 .../src/Solution.java | 0 .../src/Main.java | 17 +++ .../src/Solution.java | 59 +++++++++ 14 files changed, 571 insertions(+), 163 deletions(-) create mode 100644 [001][Two Sum]/src/Solution2.java create mode 100644 [004][Median of Two Sorted Arrays]/src/Main.java create mode 100644 [015][3 Sum]/src/Solution2.java create mode 100644 [015][3 Sum]/src/Solution3.java rename {[016][3 Sum Closest => [016][3 Sum Closest]}/src/Main.java (100%) rename {[016][3 Sum Closest => [016][3 Sum Closest]}/src/Solution.java (100%) create mode 100644 [128][Longest Consecutive Sequence]/src/Main.java create mode 100644 [128][Longest Consecutive Sequence]/src/Solution.java diff --git a/.idea/modules.xml b/.idea/modules.xml index 425286a..35b7d25 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -18,7 +18,7 @@ - + @@ -112,6 +112,7 @@ + diff --git a/[001][Two Sum]/src/Main.java b/[001][Two Sum]/src/Main.java index d83cdd8..7c82290 100644 --- a/[001][Two Sum]/src/Main.java +++ b/[001][Two Sum]/src/Main.java @@ -1,3 +1,5 @@ +import org.junit.Test; + /** * Author: 王俊超 * Date: 2015-06-18 @@ -5,9 +7,29 @@ * Declaration: All Rights Reserved !!! */ public class Main { - public static void main(String[] args) { + @Test + public void test0() { int[] result = new Solution().twoSum(new int[]{0, 4, 3, 0}, 0); System.out.println("[" + result[0] + " ," + result[1] + "]"); } + + @Test + public void test1() { + int[] result = new Solution().twoSum(new int[]{3, 2, 4}, 6); + System.out.println("[" + result[0] + " ," + result[1] + "]"); + } + + @Test + public void test2() { + int[] result = new Solution().twoSum(new int[]{3, 2, 4}, 6); + System.out.println("[" + result[0] + " ," + result[1] + "]"); + } + @Test + public void test3() { + int[] nums = {876,879,155,291,431,296,592,965,502,173,869,504,258,342,192,478,270,341,811,794,472,625,229,829,122,858,738,481,102,946,305,399,216,752,413,352,271,193,534,508,152,989,154,456,168,510,391,28,317,409,609,532,784,160,696,105,245,231,20,17,81,781,79,816,918,838,123,602,338,997,192,947,388,515,510,441,175,539,708,980,207,336,524,610,3,427,282,84,953,855,117,737,288,371,623,484,738,874,426,202,481,132,499,500,89,786,276,221,857,398,242,639,771,149,758,775,39,836,70,903,193,959,169,851,798,815,755,498,308,70,217,765,504,498,56,547,578,977,882,909,9,874,223,39,429,982,129,712,77,996,43,613,800,810,73,993,763,978,912,255,468,937,987,701,155,347,980,147,698,41,353,178,396,241,71,482,40,593,993,959,193,544,376,752,804,194,800,837,673,261,348,963,918,217,945,271,493,538,203,54,850,753,954,312,584,399,504,62,124,790,542,239,662,410,12,362,798,726,798,780,785,737,280,931,452,643,362,190,975,520,219,330,290,451,22,756,837,787,758,661,75,697,419,485,290,84,401,447,400,311,121,216,574,724,733,496,680,831,736,43,578,201,109,197,125,66,739,339,925,148,381,513,152,305,603,516,979,133,993,430,167,826,526,290,562,559,947,448,903,289,259,221,915,71,879,639,390,588,496,430,778,722,421,821,436,621,959,728,81,117,202,17,408,829,438,970,93,738,838,902,248,128,903,800,567,829,3,407,306,773,71,323,492,305,301,28,220,455,320,478,873,483,521,260,460,342,846,577,874,530,588,965,985,606,410,443,662,81,667,27,912,602,957,822,164,489,942,414,549,991,747,680,498,831,805,89,846,467,909,7,651,250,534,984,587,348,150,329,194,20,519,250,232,224,378,539,83,177,872,130,419,387,654,917,259,447,979,184,965,51,349,422,983,682,172,177,177,484,652,930,495,65,511,318,621,297,803,476,370,826,328,150,354,393,900,340,73,781,70,260,293,862,335,395,51,326,363,78,968,446,565,683,654,767,719,324,2,617,451,56,789,464,119,53,269,369,137,612,54,217,719,823,601,663,310,594,301,636,22,333,351,126,810,812,827,634,441,534,434,967,637,795,335,965,876,778,987,217,451,264,341,566,656,612,413,682,429,161,801,167,309,846,754,541,9,711,707,848,989,580,20,431,163,252,200,54,56,666,425,592,513,230,894,20,260,282,297,129,414,326,577,184,698,620,138,131,236,848,995,879,354,107,67,92,260,531,757,640,305,848,959,416,109,513,769,131,501,197,225,358,67,663,761,742,83,648,230,59,873,231,228,470,503,615,245,258,84,832,132,156,324,27,583,766,676,130,978,306,387,733,592,763,592,487,504,493,139,897,290,432,976,946,24,586,104,648,333,2,359,166,968,990,39,353,376,839,9,75,874,203,762,489,21,14,888,570,449,539,772,919,697,883,278,18,151,113,148,330,158,772,852,93,288,213,299,338,297,862,371,708,815,108,326,115,923,541,144,521,441,99,773,950,519,948,258,328,624,936,681,935,328,70,826,110,153,236,191,222,340,653,918,976,857,184,193,397,39,190,147,763,760,95,917,559,529,680,376,389,215,705,586,205,653,324,960,33,404,888,680,95,263,860,150,683,930,588,9,690,919,745,815,331,425,879,648,398,2,997,865,429,399,264,704,699,333,126,753,565,529,35,520,94,401,552,592,543,864,23,764,763,51,631,348,198,255,73,281,996,371,23,581,84,367,469,604,716,393,942,764,239,502,501,973,438,760,398,158,853,178,348,659,1000,739,296,444,587,528,355,867,615,847,885,160,357,618,959,330,82,182,59,224,355,250,270,447,534,97,590,284,909,406,954,419,909,158,626,818,350,994,609,540,957,152,827,830,386,380,318,580,853,440,789,432,710,955,381,241,930,880,632,750,876,189,662,127,434,38,144,20,424,27,466,538,158,416,508,990,650,698,990,970,663,121,9,713,489,977,530,694,141,930,169,695,305,567,368,777,442,668,746,618,86,592,185,328,772,213,644,440,178,243,774,467,991,455,404,919,197,830,568,661,826,841,695,52,982,515,47,47,198,9,272,425,975,472,9,302,338,470,542,247,492,367,180,708,521,592,58,572,887,670,314,191,280,256,845,971,157,725,862,452,76,200,538,44,324,992,459,196,18,64,147,423,187,191,246,305,973,802,832,436,444,242,979,351,733,459,825,833,691,372,861,617,618,190,57,848,527,56,378,533,308,430,473,701,401,871,790,459,216,983,305,61,391,251,447,661,951,150,28,572,206,299,477,703,301,227,960,866,450,335,337,852,906,956,873,893,867,196,131,456,608,688,840,569,91,922,606,961,906,836,168,838,91,607,186,754,708,477,248,138,211,458,17,509,645,629,816,47,185,661,856,508,984,320,763,297,9,446,970,472,12,386,476,686,940,387,721,546,206,110,349,88,781,150,308,136,809,670,291,767,889,926,999,832,462,706,13,9,753,458,309,984,404,801,366,56,611,38,691,174,670,306,229,12,151,697,415,180,655,418,975,781,40,448,625,775,722,350,163,397,634,102,961,322,354,836,652,877,997,397,957,640,70,467,976,901,792,173,869,248,829,919,89,324,9,639,560,744,890,846,452,197,558,756,988,771,573,494,64,423,348,296,587,327,909,371,24,369,174,132,197,412,142,257,790,770,171,875,724,608,329,256,626,868,22,311,499,933,173,78,631,931,191,132,970,194,778,33,832,75,76,63,271,905,164,970,716,216,828,56,131,898,565,791,47,634,205,118,280,605,896,433,38,39,303,242,746,673,541,759,588,990,586,244,152,586,371,666,361,691,815,658,537,371,482,656,117,316,327,368,657,848,557,761,221,147,673,945,914,976,579,804,405,182,89,429,133,485,939,586,452,20,292,108,747,188,899,293,125,976,573,162,592,880,241,685,191,539,361,430,84,791,903,475,96,388,485,416,583,944,939,987,939,545,474,272,494,664,543,480,812,212,400,728,28,379,410,127,607,59,614,883,509,695,765,533,665,754,848,268,159,678,807,325,125,92,208,216,337,697,778,466,861,22,950,74,804,925,617,159,73,676,712,558,487,711,774,383,817,737,555,811,304,743,27,67,535,426,766,615,102,437,765,291,718,641,951,255,375,442,204,108,455,592,364,457,758,486,593,780,277,789,323,404,473,258,953,318,898,555,390,727,510,783,427,806,92,33,474,858,851,783,12,752,356,942,307,235,397,915,502,939}; + int target = 28; + int[] result = new Solution().twoSum(nums, target); + System.out.println("[" + result[0] + " ," + result[1] + "]"); + } } diff --git a/[001][Two Sum]/src/Solution.java b/[001][Two Sum]/src/Solution.java index 2794018..01bd269 100644 --- a/[001][Two Sum]/src/Solution.java +++ b/[001][Two Sum]/src/Solution.java @@ -1,4 +1,7 @@ -import java.util.Arrays; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * Author: 王俊超 @@ -7,27 +10,6 @@ * Declaration: All Rights Reserved !!! */ public class Solution { - private static class Node implements Comparable { - int val; - int idx; - - public Node() { - } - - public Node(int val, int idx) { - this.val = val; - this.idx = idx; - } - - @Override - public int compareTo(Node o) { - if (o == null) { - return -1; - } - return this.val - o.val; - } - } - /** *

@@ -59,34 +41,34 @@ public int compareTo(Node o) {
     public int[] twoSum(int[] nums, int target) {
         int[] result = {0, 0};
 
-        Node[] tmp = new Node[nums.length];
+        // 因为无素可能会重复
+        Map> map = new HashMap<>(nums.length);
+
         for (int i = 0; i < nums.length; i++) {
-            tmp[i] = new Node(nums[i], i);
+            if (map.containsKey(nums[i])) {
+                map.get(nums[i]).add(i);
+            } else {
+                List list = new ArrayList<>();
+                list.add(i);
+                map.put(nums[i], list);
+            }
         }
 
-        Arrays.sort(tmp);
-
-        int lo = 0;
-        int hi = nums.length - 1;
-
-
-        while (lo < hi) {
-            if (tmp[lo].val + tmp[hi].val == target) {
-
-                if (tmp[lo].idx > tmp[hi].idx) {
-                    result[0] = tmp[hi].idx + 1;
-                    result[1] = tmp[lo].idx + 1;
-                } else {
-                    result[0] = tmp[lo].idx + 1;
-                    result[1] = tmp[hi].idx + 1;
+        for (int num : nums) {
+            int gap = target - num;
+            if (map.containsKey(gap)) {
+                // 同样的元素最多只可以有两个
+                if (gap == num && map.get(num).size() >= 2) {
+                    List list = map.get(num);
+                    result[0] = Math.min(list.get(0), list.get(1));
+                    result[1] = Math.max(list.get(0), list.get(1));
+                } else if (gap != num){
+                    result[0] = Math.min(map.get(num).get(0), map.get(gap).get(0));
+                    result[1] = Math.max(map.get(num).get(0), map.get(gap).get(0));
                 }
-                break;
-            } else if (tmp[lo].val + tmp[hi].val > target) {
-                hi--;
-            } else {
-                lo++;
             }
         }
+
         return result;
     }
 }
diff --git a/[001][Two Sum]/src/Solution2.java b/[001][Two Sum]/src/Solution2.java
new file mode 100644
index 0000000..37103d1
--- /dev/null
+++ b/[001][Two Sum]/src/Solution2.java	
@@ -0,0 +1,94 @@
+import java.util.Arrays;
+
+/**
+ * Author: 王俊超
+ * Date: 2015-06-17
+ * Time: 20:27
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution2 {
+    private static class Node implements Comparable {
+        int val;
+        int idx;
+
+        public Node() {
+        }
+
+        public Node(int val, int idx) {
+            this.val = val;
+            this.idx = idx;
+        }
+
+        @Override
+        public int compareTo(Node o) {
+            if (o == null) {
+                return -1;
+            }
+            return this.val - o.val;
+        }
+    }
+
+
+    /**
+     * 
+     * Given an array of integers, find two numbers such that they add up to a specific target number.
+     * The function twoSum should return indices of the two numbers such that they add up to the target,
+     * where index1 must be less than index2. Please note that your returned answers (both index1 and index2)
+     * are not zero-based.
+     * You may assume that each input would have exactly one solution.
+     *
+     * Input: numbers={2, 7, 11, 15}, target=9
+     * Output: index1=1, index2=2
+     *
+     * 题目大意
+     * 给定一个整数数组,找出其中两个数满足相加等于你指定的目标数字。
+     * 要求:这个函数twoSum必须要返回能够相加等于目标数字的两个数的索引,且index1必须要小于index2。
+     * 请注意一点,你返回的结果(包括index1和index2)都不是基于0开始的。你可以假设每一个输入肯定只有一个结果。
+     *
+     * 解题思路
+     * 创建一个辅助类数组,对辅助类进行排序,使用两个指针,开始时分别指向数组的两端,看这两个下标对应的值是否
+     * 等于目标值,如果等于就从辅助类中找出记录的下标,构造好返回结果,返回。如果大于就让右边的下标向左移,
+     * 进入下一次匹配,如果小于就让左边的下标向右移动,进入下一次匹配,直到所有的数据都处理完
+     * 
+ * + * @param nums + * @param target + * @return + */ + + public int[] twoSum(int[] nums, int target) { + int[] result = {0, 0}; + + Node[] tmp = new Node[nums.length]; + for (int i = 0; i < nums.length; i++) { + tmp[i] = new Node(nums[i], i); + } + + // 先排序,然后左右夹逼,排序O(n log n),左右夹逼O(n),最终O(n log n)。但是注 + // 意,这题需要返回的是下标,而不是数字本身,因此这个方法不好。 + Arrays.sort(tmp); + + int lo = 0; + int hi = nums.length - 1; + + + while (lo < hi) { + if (tmp[lo].val + tmp[hi].val == target) { + + if (tmp[lo].idx > tmp[hi].idx) { + result[0] = tmp[hi].idx + 1; + result[1] = tmp[lo].idx + 1; + } else { + result[0] = tmp[lo].idx + 1; + result[1] = tmp[hi].idx + 1; + } + break; + } else if (tmp[lo].val + tmp[hi].val > target) { + hi--; + } else { + lo++; + } + } + return result; + } +} diff --git a/[004][Median of Two Sorted Arrays]/src/Main.java b/[004][Median of Two Sorted Arrays]/src/Main.java new file mode 100644 index 0000000..06c2105 --- /dev/null +++ b/[004][Median of Two Sorted Arrays]/src/Main.java @@ -0,0 +1,35 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-14 13:21 + **/ +public class Main { + + @Test + public void test() { + int[] nums1 = {1, 3}; + int[] nums2 = {2}; + Solution solution = new Solution(); + Assert.assertEquals(2, solution.findMedianSortedArrays(nums1, nums2), 0.000001); + } + + @Test + public void test2() { + int[] nums1 = {1, 2}; + int[] nums2 = {3, 4}; + Solution solution = new Solution(); + Assert.assertEquals(2.5, solution.findMedianSortedArrays(nums1, nums2), 0.000001); + } + + @Test + public void test3() { + int[] nums1 = {6}; + int[] nums2 = {1, 2, 3, 4, 5}; + Solution solution = new Solution(); + Assert.assertEquals(3.5, solution.findMedianSortedArrays(nums1, nums2), 0.000001); + } + + +} diff --git a/[004][Median of Two Sorted Arrays]/src/Solution.java b/[004][Median of Two Sorted Arrays]/src/Solution.java index 2e8b9b2..4303371 100644 --- a/[004][Median of Two Sorted Arrays]/src/Solution.java +++ b/[004][Median of Two Sorted Arrays]/src/Solution.java @@ -23,57 +23,68 @@ public class Solution { * @return */ public double findMedianSortedArrays(int[] nums1, int[] nums2) { - - if (nums1 == null) { - nums1 = new int[0]; - } - - if (nums2 == null) { - nums2 = new int[0]; + int total = nums1.length + nums2.length; + if (total % 2 != 0) { + return findKth(nums1, 0, nums2, 0, total / 2 + 1); + } else { + return (findKth(nums1, 0, nums2, 0, total / 2) + + findKth(nums1, 0, nums2, 0, total / 2 + 1) + ) / 2.0; } + } - int len1 = nums1.length; - int len2 = nums2.length; + /** + * ҵkԪأk=1, 2, 3, ... + * + * @param nums1 + * @param nums2 + * @param k + * @return + **/ - if (len1 < len2) { - // ȷһȵڶ鳤ȴ - return findMedianSortedArrays(nums2, nums1); + public int findKth(int[] nums1, final int start1, + int[] nums2, final int start2, + final int k) { + // ҪҳСķǰ + if (nums1.length - start1 > nums2.length - start2) { + return findKth(nums2, start2, nums1, start1, k); } - // С鳤Ϊ0ͷǰһλ - if (len2 == 0) { - return (nums1[(len1 - 1) / 2] + nums1[len1 / 2]) / 2.0; + if (nums1.length == start1) { + return nums2[start2 + k - 1]; } + // һбȽС + if (k == 1) { + return Math.min(nums1[start1], nums2[start2]); + } - int lo = 0; - int hi = len2 * 2; - int mid1; - int mid2; - double l1; - double l2; - double r1; - double r2; - - while (lo <= hi) { - mid2 = (lo + hi) / 2; - mid1 = len1 + len2 - mid2; - - l1 = (mid1 == 0) ? Integer.MIN_VALUE : nums1[(mid1 - 1) / 2]; - l2 = (mid2 == 0) ? Integer.MIN_VALUE : nums2[(mid2 - 1) / 2]; - r1 = (mid1 == len1 * 2) ? Integer.MAX_VALUE : nums1[mid1 / 2]; - r2 = (mid2 == len2 * 2) ? Integer.MAX_VALUE : nums2[mid2 / 2]; + // num1, nums2иһ൱ÿζҪ1/4 + int half = Math.min(k / 2, nums1.length - start1); + // nums2пҵλ + int ia = half + start1; + // nums2пҵλ + int ib = k - half + start2; - if (l1 > r2) { - lo = mid2 + 1; - } else if (l2 > r1) { - hi = mid2 - 1; - } else { - return (Math.max(l1, l2) + Math.min(r1, r2)) / 2; - } + // nums1[start, ..., ia-1, ia, ..., nums1.length] + // nums2[start, ..., ib-1, ib, ..., nums2.length] + // ˵nums1[start, ..., ia-1]ˣҪҵֵnums1[ia, ..., nums1.length] + // nums2[start, ..., ib-1, ib, ..., nums2.length] + if (nums1[ia - 1] < nums2[ib - 1]) { + // k - (ia - start1) = k - (half + start1 - start1)=k - half + return findKth(nums1, ia, nums2, start2, k - (ia - start1)); } - return -1; + // ˵nums2[start, ..., ib-1]ˣҪҵֵnums2[ib, ..., nums2.length] + // nums1[start, ..., ia-1, ia, ..., nums1.length] + else if (nums1[ia - 1] > nums2[ib - 1]) { + // k - (ib - start2) = k - (k - half + start2 - start2) + return findKth(nums1, start1, nums2, ib, half); + } + // ֵ˵ҵˣ + else { + return nums1[ia - 1]; + } } } diff --git a/[015][3 Sum]/src/Main.java b/[015][3 Sum]/src/Main.java index 0ee6251..fc64650 100644 --- a/[015][3 Sum]/src/Main.java +++ b/[015][3 Sum]/src/Main.java @@ -1,3 +1,5 @@ +import org.junit.Test; + /** * Author: * Date: 2015-06-20 @@ -5,10 +7,47 @@ * Declaration: All Rights Reserved !!! */ public class Main { - public static void main(String[] args) { + + @Test + public void test0() { + Solution solution = new Solution(); + System.out.println(solution.threeSum(new int[]{0, 0, 0})); + } + + @Test + public void test1() { Solution solution = new Solution(); System.out.println(solution.threeSum(new int[]{0, 0, 0, 0})); -// System.out.println(solution.threeSum(new int[]{1, -1, -1, 0})); - System.out.println(solution.threeSum(new int[]{-2,0,1,1,2})); + } + + @Test + public void test2() { + Solution solution = new Solution(); + System.out.println(solution.threeSum(new int[]{1, -1, -1, 0})); + } + + @Test + public void test3() { + Solution solution = new Solution(); + System.out.println(solution.threeSum(new int[]{-2, 0, 1, 1, 2})); + } + + @Test + public void test4() { + Solution solution = new Solution(); + System.out.println(solution.threeSum(new int[]{-1, 0, 1, 2, -1, -4})); + } + + @Test + public void test5() { + Solution solution = new Solution(); + System.out.println(solution.threeSum(new int[]{82597,-9243,62390,83030,-97960,-26521,-61011,83390,-38677,12333,75987,46091,83794,19355,-71037,-6242,-28801,324,1202,-90885,-2989,-95597,-34333,35528,5680,89093,-90606,50360,-29393,-27012,53313,65213,99818,-82405,-41661,-3333,-51952,72135,-1523,26377,74685,96992,92263,15929,5467,-99555,-43348,-41689,-60383,-3990,32165,65265,-72973,-58372,12741,-48568,-46596,72419,-1859,34153,62937,81310,-61823,-96770,-54944,8845,-91184,24208,-29078,31495,65258,14198,85395,70506,-40908,56740,-12228,-40072,32429,93001,68445,-73927,25731,-91859,-24150,10093,-60271,-81683,-18126,51055,48189,-6468,25057,81194,-58628,74042,66158,-14452,-49851,-43667,11092,39189,-17025,-79173,13606,83172,92647,-59741,19343,-26644,-57607,82908,-20655,1637,80060,98994,39331,-31274,-61523,91225,-72953,13211,-75116,-98421,-41571,-69074,99587,39345,42151,-2460,98236,15690,-52507,-95803,-48935,-46492,-45606,-79254,-99851,52533,73486,39948,-7240,71815,-585,-96252,90990,-93815,93340,-71848,58733,-14859,-83082,-75794,-82082,-24871,-15206,91207,-56469,-93618,67131,-8682,75719,87429,-98757,-7535,-24890,-94160,85003,33928,75538,97456,-66424,-60074,-8527,-28697,-22308,2246,-70134,-82319,-10184,87081,-34949,-28645,-47352,-83966,-60418,-15293,-53067,-25921,55172,75064,95859,48049,34311,-86931,-38586,33686,-36714,96922,76713,-22165,-80585,-34503,-44516,39217,-28457,47227,-94036,43457,24626,-87359,26898,-70819,30528,-32397,-69486,84912,-1187,-98986,-32958,4280,-79129,-65604,9344,58964,50584,71128,-55480,24986,15086,-62360,-42977,-49482,-77256,-36895,-74818,20,3063,-49426,28152,-97329,6086,86035,-88743,35241,44249,19927,-10660,89404,24179,-26621,-6511,57745,-28750,96340,-97160,-97822,-49979,52307,79462,94273,-24808,77104,9255,-83057,77655,21361,55956,-9096,48599,-40490,-55107,2689,29608,20497,66834,-34678,23553,-81400,-66630,-96321,-34499,-12957,-20564,25610,-4322,-58462,20801,53700,71527,24669,-54534,57879,-3221,33636,3900,97832,-27688,-98715,5992,24520,-55401,-57613,-69926,57377,-77610,20123,52174,860,60429,-91994,-62403,-6218,-90610,-37263,-15052,62069,-96465,44254,89892,-3406,19121,-41842,-87783,-64125,-56120,73904,-22797,-58118,-4866,5356,75318,46119,21276,-19246,-9241,-97425,57333,-15802,93149,25689,-5532,95716,39209,-87672,-29470,-16324,-15331,27632,-39454,56530,-16000,29853,46475,78242,-46602,83192,-73440,-15816,50964,-36601,89758,38375,-40007,-36675,-94030,67576,46811,-64919,45595,76530,40398,35845,41791,67697,-30439,-82944,63115,33447,-36046,-50122,-34789,43003,-78947,-38763,-89210,32756,-20389,-31358,-90526,-81607,88741,86643,98422,47389,-75189,13091,95993,-15501,94260,-25584,-1483,-67261,-70753,25160,89614,-90620,-48542,83889,-12388,-9642,-37043,-67663,28794,-8801,13621,12241,55379,84290,21692,-95906,-85617,-17341,-63767,80183,-4942,-51478,30997,-13658,8838,17452,-82869,-39897,68449,31964,98158,-49489,62283,-62209,-92792,-59342,55146,-38533,20496,62667,62593,36095,-12470,5453,-50451,74716,-17902,3302,-16760,-71642,-34819,96459,-72860,21638,47342,-69897,-40180,44466,76496,84659,13848,-91600,-90887,-63742,-2156,-84981,-99280,94326,-33854,92029,-50811,98711,-36459,-75555,79110,-88164,-97397,-84217,97457,64387,30513,-53190,-83215,252,2344,-27177,-92945,-89010,82662,-11670,86069,53417,42702,97082,3695,-14530,-46334,17910,77999,28009,-12374,15498,-46941,97088,-35030,95040,92095,-59469,-24761,46491,67357,-66658,37446,-65130,-50416,99197,30925,27308,54122,-44719,12582,-99525,-38446,-69050,-22352,94757,-56062,33684,-40199,-46399,96842,-50881,-22380,-65021,40582,53623,-76034,77018,-97074,-84838,-22953,-74205,79715,-33920,-35794,-91369,73421,-82492,63680,-14915,-33295,37145,76852,-69442,60125,-74166,74308,-1900,-30195,-16267,-60781,-27760,5852,38917,25742,-3765,49097,-63541,98612,-92865,-30248,9612,-8798,53262,95781,-42278,-36529,7252,-27394,-5021,59178,80934,-48480,-75131,-54439,-19145,-48140,98457,-6601,-51616,-89730,78028,32083,-48904,16822,-81153,-8832,48720,-80728,-45133,-86647,-4259,-40453,2590,28613,50523,-4105,-27790,-74579,-17223,63721,33489,-47921,97628,-97691,-14782,-65644,18008,-93651,-71266,80990,-76732,-47104,35368,28632,59818,-86269,-89753,34557,-92230,-5933,-3487,-73557,-13174,-43981,-43630,-55171,30254,-83710,-99583,-13500,71787,5017,-25117,-78586,86941,-3251,-23867,-36315,75973,86272,-45575,77462,-98836,-10859,70168,-32971,-38739,-12761,93410,14014,-30706,-77356,-85965,-62316,63918,-59914,-64088,1591,-10957,38004,15129,-83602,-51791,34381,-89382,-26056,8942,5465,71458,-73805,-87445,-19921,-80784,69150,-34168,28301,-68955,18041,6059,82342,9947,39795,44047,-57313,48569,81936,-2863,-80932,32976,-86454,-84207,33033,32867,9104,-16580,-25727,80157,-70169,53741,86522,84651,68480,84018,61932,7332,-61322,-69663,76370,41206,12326,-34689,17016,82975,-23386,39417,72793,44774,-96259,3213,79952,29265,-61492,-49337,14162,65886,3342,-41622,-62659,-90402,-24751,88511,54739,-21383,-40161,-96610,-24944,-602,-76842,-21856,69964,43994,-15121,-85530,12718,13170,-13547,69222,62417,-75305,-81446,-38786,-52075,-23110,97681,-82800,-53178,11474,35857,94197,-58148,-23689,32506,92154,-64536,-73930,-77138,97446,-83459,70963,22452,68472,-3728,-25059,-49405,95129,-6167,12808,99918,30113,-12641,-26665,86362,-33505,50661,26714,33701,89012,-91540,40517,-12716,-57185,-87230,29914,-59560,13200,-72723,58272,23913,-45586,-96593,-26265,-2141,31087,81399,92511,-34049,20577,2803,26003,8940,42117,40887,-82715,38269,40969,-50022,72088,21291,-67280,-16523,90535,18669,94342,-39568,-88080,-99486,-20716,23108,-28037,63342,36863,-29420,-44016,75135,73415,16059,-4899,86893,43136,-7041,33483,-67612,25327,40830,6184,61805,4247,81119,-22854,-26104,-63466,63093,-63685,60369,51023,51644,-16350,74438,-83514,99083,10079,-58451,-79621,48471,67131,-86940,99093,11855,-22272,-67683,-44371,9541,18123,37766,-70922,80385,-57513,-76021,-47890,36154,72935,84387,-92681,-88303,-7810,59902,-90,-64704,-28396,-66403,8860,13343,33882,85680,7228,28160,-14003,54369,-58893,92606,-63492,-10101,64714,58486,29948,-44679,-22763,10151,-56695,4031,-18242,-36232,86168,-14263,9883,47124,47271,92761,-24958,-73263,-79661,-69147,-18874,29546,-92588,-85771,26451,-86650,-43306,-59094,-47492,-34821,-91763,-47670,33537,22843,67417,-759,92159,63075,94065,-26988,55276,65903,30414,-67129,-99508,-83092,-91493,-50426,14349,-83216,-76090,32742,-5306,-93310,-60750,-60620,-45484,-21108,-58341,-28048,-52803,69735,78906,81649,32565,-86804,-83202,-65688,-1760,89707,93322,-72750,84134,71900,-37720,19450,-78018,22001,-23604,26276,-21498,65892,-72117,-89834,-23867,55817,-77963,42518,93123,-83916,63260,-2243,-97108,85442,-36775,17984,-58810,99664,-19082,93075,-69329,87061,79713,16296,70996,13483,-74582,49900,-27669,-40562,1209,-20572,34660,83193,75579,7344,64925,88361,60969,3114,44611,-27445,53049,-16085,-92851,-53306,13859,-33532,86622,-75666,-18159,-98256,51875,-42251,-27977,-18080,23772,38160,41779,9147,94175,99905,-85755,62535,-88412,-52038,-68171,93255,-44684,-11242,-104,31796,62346,-54931,-55790,-70032,46221,56541,-91947,90592,93503,4071,20646,4856,-63598,15396,-50708,32138,-85164,38528,-89959,53852,57915,-42421,-88916,-75072,67030,-29066,49542,-71591,61708,-53985,-43051,28483,46991,-83216,80991,-46254,-48716,39356,-8270,-47763,-34410,874,-1186,-7049,28846,11276,21960,-13304,-11433,-4913,55754,79616,70423,-27523,64803,49277,14906,-97401,-92390,91075,70736,21971,-3303,55333,-93996,76538,54603,-75899,98801,46887,35041,48302,-52318,55439,24574,14079,-24889,83440,14961,34312,-89260,-22293,-81271,-2586,-71059,-10640,-93095,-5453,-70041,66543,74012,-11662,-52477,-37597,-70919,92971,-17452,-67306,-80418,7225,-89296,24296,86547,37154,-10696,74436,-63959,58860,33590,-88925,-97814,-83664,85484,-8385,-50879,57729,-74728,-87852,-15524,-91120,22062,28134,80917,32026,49707,-54252,-44319,-35139,13777,44660,85274,25043,58781,-89035,-76274,6364,-63625,72855,43242,-35033,12820,-27460,77372,-47578,-61162,-70758,-1343,-4159,64935,56024,-2151,43770,19758,-30186,-86040,24666,-62332,-67542,73180,-25821,-27826,-45504,-36858,-12041,20017,-24066,-56625,-52097,-47239,-90694,8959,7712,-14258,-5860,55349,61808,-4423,-93703,64681,-98641,-25222,46999,-83831,-54714,19997,-68477,66073,51801,-66491,52061,-52866,79907,-39736,-68331,68937,91464,98892,910,93501,31295,-85873,27036,-57340,50412,21,-2445,29471,71317,82093,-94823,-54458,-97410,39560,-7628,66452,39701,54029,37906,46773,58296,60370,-61090,85501,-86874,71443,-72702,-72047,14848,34102,77975,-66294,-36576,31349,52493,-70833,-80287,94435,39745,-98291,84524,-18942,10236,93448,50846,94023,-6939,47999,14740,30165,81048,84935,-19177,-13594,32289,62628,-90612,-542,-66627,64255,71199,-83841,-82943,-73885,8623,-67214,-9474,-35249,62254,-14087,-90969,21515,-83303,94377,-91619,19956,-98810,96727,-91939,29119,-85473,-82153,-69008,44850,74299,-76459,-86464,8315,-49912,-28665,59052,-69708,76024,-92738,50098,18683,-91438,18096,-19335,35659,91826,15779,-73070,67873,-12458,-71440,-46721,54856,97212,-81875,35805,36952,68498,81627,-34231,81712,27100,-9741,-82612,18766,-36392,2759,41728,69743,26825,48355,-17790,17165,56558,3295,-24375,55669,-16109,24079,73414,48990,-11931,-78214,90745,19878,35673,-15317,-89086,94675,-92513,88410,-93248,-19475,-74041,-19165,32329,-26266,-46828,-18747,45328,8990,-78219,-25874,-74801,-44956,-54577,-29756,-99822,-35731,-18348,-68915,-83518,-53451,95471,-2954,-13706,-8763,-21642,-37210,16814,-60070,-42743,27697,-36333,-42362,11576,85742,-82536,68767,-56103,-63012,71396,-78464,-68101,-15917,-11113,-3596,77626,-60191,-30585,-73584,6214,-84303,18403,23618,-15619,-89755,-59515,-59103,-74308,-63725,-29364,-52376,-96130,70894,-12609,50845,-2314,42264,-70825,64481,55752,4460,-68603,-88701,4713,-50441,-51333,-77907,97412,-66616,-49430,60489,-85262,-97621,-18980,44727,-69321,-57730,66287,-92566,-64427,-14270,11515,-92612,-87645,61557,24197,-81923,-39831,-10301,-23640,-76219,-68025,92761,-76493,68554,-77734,-95620,-11753,-51700,98234,-68544,-61838,29467,46603,-18221,-35441,74537,40327,-58293,75755,-57301,-7532,-94163,18179,-14388,-22258,-46417,-48285,18242,-77551,82620,250,-20060,-79568,-77259,82052,-98897,-75464,48773,-79040,-11293,45941,-67876,-69204,-46477,-46107,792,60546,-34573,-12879,-94562,20356,-48004,-62429,96242,40594,2099,99494,25724,-39394,-2388,-18563,-56510,-83570,-29214,3015,74454,74197,76678,-46597,60630,-76093,37578,-82045,-24077,62082,-87787,-74936,58687,12200,-98952,70155,-77370,21710,-84625,-60556,-84128,925,65474,-15741,-94619,88377,89334,44749,22002,-45750,-93081,-14600,-83447,46691,85040,-66447,-80085,56308,44310,24979,-29694,57991,4675,-71273,-44508,13615,-54710,23552,-78253,-34637,50497,68706,81543,-88408,-21405,6001,-33834,-21570,-46692,-25344,20310,71258,-97680,11721,59977,59247,-48949,98955,-50276,-80844,-27935,-76102,55858,-33492,40680,66691,-33188,8284,64893,-7528,6019,-85523,8434,-64366,-56663,26862,30008,-7611,-12179,-70076,21426,-11261,-36864,-61937,-59677,929,-21052,3848,-20888,-16065,98995,-32293,-86121,-54564,77831,68602,74977,31658,40699,29755,98424,80358,-69337,26339,13213,-46016,-18331,64713,-46883,-58451,-70024,-92393,-4088,70628,-51185,71164,-75791,-1636,-29102,-16929,-87650,-84589,-24229,-42137,-15653,94825,13042,88499,-47100,-90358,-7180,29754,-65727,-42659,-85560,-9037,-52459,20997,-47425,17318,21122,20472,-23037,65216,-63625,-7877,-91907,24100,-72516,22903,-85247,-8938,73878,54953,87480,-31466,-99524,35369,-78376,89984,-15982,94045,-7269,23319,-80456,-37653,-76756,2909,81936,54958,-12393,60560,-84664,-82413,66941,-26573,-97532,64460,18593,-85789,-38820,-92575,-43663,-89435,83272,-50585,13616,-71541,-53156,727,-27644,16538,34049,57745,34348,35009,16634,-18791,23271,-63844,95817,21781,16590,59669,15966,-6864,48050,-36143,97427,-59390,96931,78939,-1958,50777,43338,-51149,39235,-27054,-43492,67457,-83616,37179,10390,85818,2391,73635,87579,-49127,-81264,-79023,-81590,53554,-74972,-83940,-13726,-39095,29174,78072,76104,47778,25797,-29515,-6493,-92793,22481,-36197,-65560,42342,15750,97556,99634,-56048,-35688,13501,63969,-74291,50911,39225,93702,-3490,-59461,-30105,-46761,-80113,92906,-68487,50742,36152,-90240,-83631,24597,-50566,-15477,18470,77038,40223,-80364,-98676,70957,-63647,99537,13041,31679,86631,37633,-16866,13686,-71565,21652,-46053,-80578,-61382,68487,-6417,4656,20811,67013,-30868,-11219,46,74944,14627,56965,42275,-52480,52162,-84883,-52579,-90331,92792,42184,-73422,-58440,65308,-25069,5475,-57996,59557,-17561,2826,-56939,14996,-94855,-53707,99159,43645,-67719,-1331,21412,41704,31612,32622,1919,-69333,-69828,22422,-78842,57896,-17363,27979,-76897,35008,46482,-75289,65799,20057,7170,41326,-76069,90840,-81253,-50749,3649,-42315,45238,-33924,62101,96906,58884,-7617,-28689,-66578,62458,50876,-57553,6739,41014,-64040,-34916,37940,13048,-97478,-11318,-89440,-31933,-40357,-59737,-76718,-14104,-31774,28001,4103,41702,-25120,-31654,63085,-3642,84870,-83896,-76422,-61520,12900,88678,85547,33132,-88627,52820,63915,-27472,78867,-51439,33005,-23447,-3271,-39308,39726,-74260,-31874,-36893,93656,910,-98362,60450,-88048,99308,13947,83996,-90415,-35117,70858,-55332,-31721,97528,82982,-86218,6822,25227,36946,97077,-4257,-41526,56795,89870,75860,-70802,21779,14184,-16511,-89156,-31422,71470,69600,-78498,74079,-19410,40311,28501,26397,-67574,-32518,68510,38615,19355,-6088,-97159,-29255,-92523,3023,-42536,-88681,64255,41206,44119,52208,39522,-52108,91276,-70514,83436,63289,-79741,9623,99559,12642,85950,83735,-21156,-67208,98088,-7341,-27763,-30048,-44099,-14866,-45504,-91704,19369,13700,10481,-49344,-85686,33994,19672,36028,60842,66564,-24919,33950,-93616,-47430,-35391,-28279,56806,74690,39284,-96683,-7642,-75232,37657,-14531,-86870,-9274,-26173,98640,88652,64257,46457,37814,-19370,9337,-22556,-41525,39105,-28719,51611,-93252,98044,-90996,21710,-47605,-64259,-32727,53611,-31918,-3555,33316,-66472,21274,-37731,-2919,15016,48779,-88868,1897,41728,46344,-89667,37848,68092,-44011,85354,-43776,38739,-31423,-66330,65167,-22016,59405,34328,-60042,87660,-67698,-59174,-1408,-46809,-43485,-88807,-60489,13974,22319,55836,-62995,-37375,-4185,32687,-36551,-75237,58280,26942,-73756,71756,78775,-40573,14367,-71622,-77338,24112,23414,-7679,-51721,87492,85066,-21612,57045,10673,-96836,52461,-62218,-9310,65862,-22748,89906,-96987,-98698,26956,-43428,46141,47456,28095,55952,67323,-36455,-60202,-43302,-82932,42020,77036,10142,60406,70331,63836,58850,-66752,52109,21395,-10238,-98647,-41962,27778,69060,98535,-28680,-52263,-56679,66103,-42426,27203,80021,10153,58678,36398,63112,34911,20515,62082,-15659,-40785,27054,43767,-20289,65838,-6954,-60228,-72226,52236,-35464,25209,-15462,-79617,-41668,-84083,62404,-69062,18913,46545,20757,13805,24717,-18461,-47009,-25779,68834,64824,34473,39576,31570,14861,-15114,-41233,95509,68232,67846,84902,-83060,17642,-18422,73688,77671,-26930,64484,-99637,73875,6428,21034,-73471,19664,-68031,15922,-27028,48137,54955,-82793,-41144,-10218,-24921,-28299,-2288,68518,-54452,15686,-41814,66165,-72207,-61986,80020,50544,-99500,16244,78998,40989,14525,-56061,-24692,-94790,21111,37296,-90794,72100,70550,-31757,17708,-74290,61910,78039,-78629,-25033,73172,-91953,10052,64502,99585,-1741,90324,-73723,68942,28149,30218,24422,16659,10710,-62594,94249,96588,46192,34251,73500,-65995,-81168,41412,-98724,-63710,-54696,-52407,19746,45869,27821,-94866,-76705,-13417,-61995,-71560,43450,67384,-8838,-80293,-28937,23330,-89694,-40586,46918,80429,-5475,78013,25309,-34162,37236,-77577,86744,26281,-29033,-91813,35347,13033,-13631,-24459,3325,-71078,-75359,81311,19700,47678,-74680,-84113,45192,35502,37675,19553,76522,-51098,-18211,89717,4508,-82946,27749,85995,89912,-53678,-64727,-14778,32075,-63412,-40524,86440,-2707,-36821,63850,-30883,67294,-99468,-23708,34932,34386,98899,29239,-23385,5897,54882,98660,49098,70275,17718,88533,52161,63340,50061,-89457,19491,-99156,24873,-17008,64610,-55543,50495,17056,-10400,-56678,-29073,-42960,-76418,98562,-88104,-96255,10159,-90724,54011,12052,45871,-90933,-69420,67039,37202,78051,-52197,-40278,-58425,65414,-23394,-1415,6912,-53447,7352,17307,-78147,63727,98905,55412,-57658,-32884,-44878,22755,39730,3638,35111,39777,74193,38736,-11829,-61188,-92757,55946,-71232,-63032,-83947,39147,-96684,-99233,25131,-32197,24406,-55428,-61941,25874,-69453,64483,-19644,-68441,12783,87338,-48676,66451,-447,-61590,50932,-11270,29035,65698,-63544,10029,80499,-9461,86368,91365,-81810,-71914,-52056,-13782,44240,-30093,-2437,24007,67581,-17365,-69164,-8420,-69289,-29370,48010,90439,13141,69243,50668,39328,61731,78266,-81313,17921,-38196,55261,9948,-24970,75712,-72106,28696,7461,31621,61047,51476,56512,11839,-96916,-82739,28924,-99927,58449,37280,69357,11219,-32119,-62050,-48745,-83486,-52376,42668,82659,68882,38773,46269,-96005,97630,25009,-2951,-67811,99801,81587,-79793,-18547,-83086,69512,33127,-92145,-88497,47703,59527,1909,88785,-88882,69188,-46131,-5589,-15086,36255,-53238,-33009,82664,53901,35939,-42946,-25571,33298,69291,53199,74746,-40127,-39050,91033,51717,-98048,87240,36172,65453,-94425,-63694,-30027,59004,88660,3649,-20267,-52565,-67321,34037,4320,91515,-56753,60115,27134,68617,-61395,-26503,-98929,-8849,-63318,10709,-16151,61905,-95785,5262,23670,-25277,90206,-19391,45735,37208,-31992,-92450,18516,-90452,-58870,-58602,93383,14333,17994,82411,-54126,-32576,35440,-60526,-78764,-25069,-9022,-394,92186,-38057,55328,-61569,67780,77169,19546,-92664,-94948,44484,-13439,83529,27518,-48333,72998,38342,-90553,-98578,-76906,81515,-16464,78439,92529,35225,-39968,-10130,-7845,-32245,-74955,-74996,67731,-13897,-82493,33407,93619,59560,-24404,-57553,19486,-45341,34098,-24978,-33612,79058,71847,76713,-95422,6421,-96075,-59130,-28976,-16922,-62203,69970,68331,21874,40551,89650,51908,58181,66480,-68177,34323,-3046,-49656,-59758,43564,-10960,-30796,15473,-20216,46085,-85355,41515,-30669,-87498,57711,56067,63199,-83805,62042,91213,-14606,4394,-562,74913,10406,96810,-61595,32564,31640,-9732,42058,98052,-7908,-72330,1558,-80301,34878,32900,3939,-8824,88316,20937,21566,-3218,-66080,-31620,86859,54289,90476,-42889,-15016,-18838,75456,30159,-67101,42328,-92703,85850,-5475,23470,-80806,68206,17764,88235,46421,-41578,74005,-81142,80545,20868,-1560,64017,83784,68863,-97516,-13016,-72223,79630,-55692,82255,88467,28007,-34686,-69049,-41677,88535,-8217,68060,-51280,28971,49088,49235,26905,-81117,-44888,40623,74337,-24662,97476,79542,-72082,-35093,98175,-61761,-68169,59697,-62542,-72965,59883,-64026,-37656,-92392,-12113,-73495,98258,68379,-21545,64607,-70957,-92254,-97460,-63436,-8853,-19357,-51965,-76582,12687,-49712,45413,-60043,33496,31539,-57347,41837,67280,-68813,52088,-13155,-86430,-15239,-45030,96041,18749,-23992,46048,35243,-79450,85425,-58524,88781,-39454,53073,-48864,-82289,39086,82540,-11555,25014,-5431,-39585,-89526,2705,31953,-81611,36985,-56022,68684,-27101,11422,64655,-26965,-63081,-13840,-91003,-78147,-8966,41488,1988,99021,-61575,-47060,65260,-23844,-21781,-91865,-19607,44808,2890,63692,-88663,-58272,15970,-65195,-45416,-48444,-78226,-65332,-24568,42833,-1806,-71595,80002,-52250,30952,48452,-90106,31015,-22073,62339,63318,78391,28699,77900,-4026,-76870,-45943,33665,9174,-84360,-22684,-16832,-67949,-38077,-38987,-32847,51443,-53580,-13505,9344,-92337,26585,70458,-52764,-67471,-68411,-1119,-2072,-93476,67981,40887,-89304,-12235,41488,1454,5355,-34855,-72080,24514,-58305,3340,34331,8731,77451,-64983,-57876,82874,62481,-32754,-39902,22451,-79095,-23904,78409,-7418,77916})); + } + + + @Test + public void test6() { + Solution solution = new Solution(); + System.out.println(solution.threeSum(new int[]{-1, 0, 1, 2, -1, -4})); } } diff --git a/[015][3 Sum]/src/Solution.java b/[015][3 Sum]/src/Solution.java index f769078..514b228 100644 --- a/[015][3 Sum]/src/Solution.java +++ b/[015][3 Sum]/src/Solution.java @@ -25,27 +25,7 @@ public class Solution { * (-1, -1, 2) * * Ŀ⣺ - * һnԪص飬ǷabcԪأʹõa+b+c=0ҳзԪ * - * ע⣺ - * - ԪеԪرǷǵݼ - * - ܰظԪ - * - * ˼· - * 2sum Ļ3sum⣬3sumĿtargetÿδѡһk - * ʣµĿtarget-k2sum⡣ҪעиСtrickǴѡ - * iʱֻҪֵдӵi+1һΧ2sum⡣ - * - * ѡһ͵ڶΪA[],ܹnԪA1A2....AnȻѡA1ʱ - * [A2~An]Ŀλtarget-A12sum⣬Ҫ֤ǵѡA2ʱֻҪ - * [A3~An]мĿλtarget-A22sum⣬[A1,A3~An]У֤£ - * [A1,A3~An]Ŀλtarget-A22sumУA1 + m = target-A2mΪA3~An - * ijA2 + m = target-A1պǡ[A3~An],Ŀλtarget-A12sum⡱ - * һ⡣൱ڶ3sumA1+A2+m = targetظˡΪ˱ظ㣬 - * [A1A3~An]У԰A1ȥĿtarget-A22sum⡣ - * - * ڱҪӽ⣬ֻҪ浱ǰԼǰĿľ룬µĽӽ½⡣ - * 㷨ӶΪOn^2; *
* * @param nums @@ -54,66 +34,47 @@ public class Solution { public List> threeSum(int[] nums) { List> result = new LinkedList<>(); - if (nums != null && nums.length > 2) { - // ȶ - Arrays.sort(nums); - // iʾȡiΪ - for (int i = 0; i < nums.length - 2; ) { - // ڶܵʼλ - int j = i + 1; - // ǽλ - int k = nums.length - 1; + if (nums == null || nums.length < 3) { + return result; + } - while (j < k) { - // ҵĽ - if (nums[j] + nums[k] == -nums[i]) { - // ӵ - List list = new ArrayList<>(3); - list.add(nums[i]); - list.add(nums[j]); - list.add(nums[k]); - result.add(list); + Arrays.sort(nums); + int target = 0; - // ƶһλãһ - k--; - j++; + int a = 0; + while (a < nums.length - 2) { + int b = a + 1; + int c = nums.length - 1; + while (b < c) { + if (nums[a] + nums[b] + nums[c] < target) { + do { + ++b; + } while (b < c && nums[b] == nums[b - 1]); + } else if (nums[a] + nums[b] + nums[c] > target) { + do { + --c; + } while (b < c && nums[c] == nums[c + 1]); + } else { + List idxs = new ArrayList<>(); + idxs.add(nums[a]); + idxs.add(nums[b]); + idxs.add(nums[c]); + result.add(idxs); - // ҵһ֮ǰͬ± - while (j < k && nums[j] == nums[j - 1]) { - j++; - } - // ҵһ֮ǰͬ± - while (j < k && nums[k] == nums[k + 1]) { - k--; - } - } - // ʹ0 - else if (nums[j] + nums[k] > -nums[i]) { - k--; - // ҵһ֮ǰͬ± - while (j < k && nums[k] == nums[k + 1]) { - k--; - } - } - // С0 - else { - j++; - // ҵһ֮ǰͬ± - while (j < k && nums[j] == nums[j - 1]) { - j++; - } - } - } - - // ָһҪ - i++; - // ҵһ֮ǰͬ± - while (i < nums.length - 2 && nums[i] == nums[i - 1]) { - i++; + do { + ++b; + } while (b < c && nums[b] == nums[b - 1]); + do { + --c; + } while (b < c && nums[c] == nums[c + 1]); } } - } + do { + ++a; + }while (a < nums.length - 2 && nums[a - 1] == nums[a]); + } return result; } + } diff --git a/[015][3 Sum]/src/Solution2.java b/[015][3 Sum]/src/Solution2.java new file mode 100644 index 0000000..f840265 --- /dev/null +++ b/[015][3 Sum]/src/Solution2.java @@ -0,0 +1,119 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-06-20 + * Time: 21:46 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + /** + *
+     * Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0?
+     * Find all unique triplets in the array which gives the sum of zero.
+     *
+     * Note:
+     * Elements in a triplet (a,b,c) must be in non-descending order. (ie, a  b  c)
+     * The solution set must not contain duplicate triplets.
+     *
+     * For example, given array S = {-1 0 1 2 -1 -4},
+     * A solution set is:
+     * (-1, 0, 1)
+     * (-1, -1, 2)
+     *
+     * Ŀ⣺
+     * һnԪص飬ǷabcԪأʹõa+b+c=0ҳзԪ
+     *
+     * ע⣺
+     *   - ԪеԪرǷǵݼ
+     *   - ܰظԪ
+     *
+     * ˼·
+     *  2sum Ļ3sum⣬3sumĿtargetÿδѡһk
+     * ʣµĿtarget-k2sum⡣ҪעиСtrickǴѡ
+     * iʱֻҪֵдӵi+1һΧ2sum⡣
+     *
+     * ѡһ͵ڶΪA[],ܹnԪA1A2....AnȻѡA1ʱ
+     * [A2~An]Ŀλtarget-A12sum⣬Ҫ֤ǵѡA2ʱֻҪ
+     * [A3~An]мĿλtarget-A22sum⣬[A1,A3~An]У֤£
+     * [A1,A3~An]Ŀλtarget-A22sumУA1 + m = target-A2mΪA3~An
+     * ijA2 + m = target-A1պǡ[A3~An],Ŀλtarget-A12sum⡱
+     * һ⡣൱ڶ3sumA1+A2+m = targetظˡΪ˱ظ㣬
+     * [A1A3~An]У԰A1ȥĿtarget-A22sum⡣
+     *
+     * ڱҪӽ⣬ֻҪ浱ǰԼǰĿľ룬µĽӽ½⡣
+     * 㷨ӶΪOn^2;
+     * 
+ * + * @param nums + * @return + */ + public List> threeSum(int[] nums) { + List> result = new LinkedList<>(); + + if (nums != null && nums.length > 2) { + // ȶ + Arrays.sort(nums); + // iʾȡiΪ + for (int i = 0; i < nums.length - 2; ) { + // ڶܵʼλ + int j = i + 1; + // ǽλ + int k = nums.length - 1; + + while (j < k) { + // ҵĽ + if (nums[j] + nums[k] == -nums[i]) { + // ӵ + List list = new ArrayList<>(3); + list.add(nums[i]); + list.add(nums[j]); + list.add(nums[k]); + result.add(list); + + // ƶһλãһ + k--; + j++; + + // ҵһ֮ǰͬ± + while (j < k && nums[j] == nums[j - 1]) { + j++; + } + // ҵһ֮ǰͬ± + while (j < k && nums[k] == nums[k + 1]) { + k--; + } + } + // ʹ0 + else if (nums[j] + nums[k] > -nums[i]) { + k--; + // ҵһ֮ǰͬ± + while (j < k && nums[k] == nums[k + 1]) { + k--; + } + } + // С0 + else { + j++; + // ҵһ֮ǰͬ± + while (j < k && nums[j] == nums[j - 1]) { + j++; + } + } + } + + // ָһҪ + i++; + // ҵһ֮ǰͬ± + while (i < nums.length - 2 && nums[i] == nums[i - 1]) { + i++; + } + } + } + + return result; + } +} diff --git a/[015][3 Sum]/src/Solution3.java b/[015][3 Sum]/src/Solution3.java new file mode 100644 index 0000000..b0419b1 --- /dev/null +++ b/[015][3 Sum]/src/Solution3.java @@ -0,0 +1,68 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +/** + * Author: 王俊超 + * Date: 2015-06-20 + * Time: 21:46 + * Declaration: All Rights Reserved !!! + */ +public class Solution3 { + /** + *
+     * Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0?
+     * Find all unique triplets in the array which gives the sum of zero.
+     *
+     * Note:
+     * Elements in a triplet (a,b,c) must be in non-descending order. (ie, a ≤ b ≤ c)
+     * The solution set must not contain duplicate triplets.
+     *
+     * For example, given array S = {-1 0 1 2 -1 -4},
+     * A solution set is:
+     * (-1, 0, 1)
+     * (-1, -1, 2)
+     *
+     * 题目大意:
+     *
+     * 
+ * + * @param nums + * @return + */ + public List> threeSum(int[] nums) { + List> result = new LinkedList<>(); + + if (nums == null || nums.length < 3) { + return result; + } + + Arrays.sort(nums); + int target = 0; + for (int a = 0; a < nums.length - 2; ++a) { + + int b = a + 1; + int c = nums.length - 1; + while (b < c) { + if (nums[a] + nums[b] + nums[c] < target) { + ++b; + } else if (nums[a] + nums[b] + nums[c] > target) { + --c; + } else { + List idxs = new ArrayList<>(); + idxs.add(nums[a]); + idxs.add(nums[b]); + idxs.add(nums[c]); + if (!result.contains(idxs)) { + result.add(idxs); + } + ++b; + --c; + } + } + } + return result; + } + +} \ No newline at end of file diff --git a/[016][3 Sum Closest/src/Main.java b/[016][3 Sum Closest]/src/Main.java similarity index 100% rename from [016][3 Sum Closest/src/Main.java rename to [016][3 Sum Closest]/src/Main.java diff --git a/[016][3 Sum Closest/src/Solution.java b/[016][3 Sum Closest]/src/Solution.java similarity index 100% rename from [016][3 Sum Closest/src/Solution.java rename to [016][3 Sum Closest]/src/Solution.java diff --git a/[128][Longest Consecutive Sequence]/src/Main.java b/[128][Longest Consecutive Sequence]/src/Main.java new file mode 100644 index 0000000..d6d2e5c --- /dev/null +++ b/[128][Longest Consecutive Sequence]/src/Main.java @@ -0,0 +1,17 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-14 15:02 + **/ +public class Main { + @Test + public void test() { + int[] nums = {100, 4, 200, 1, 3, 2}; + + Solution solution = new Solution(); + + Assert.assertEquals(4, solution.longestConsecutive(nums)); + } +} diff --git a/[128][Longest Consecutive Sequence]/src/Solution.java b/[128][Longest Consecutive Sequence]/src/Solution.java new file mode 100644 index 0000000..b41b5ec --- /dev/null +++ b/[128][Longest Consecutive Sequence]/src/Solution.java @@ -0,0 +1,59 @@ +import java.util.HashSet; +import java.util.Set; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-14 14:48 + **/ +class Solution { + /** + *
+     * Given an unsorted array of integers, find the length of the longest consecutive elements sequence.
+     *
+     * Your algorithm should run in O(n) complexity.
+     *
+     * Example:
+     *
+     * Input: [100, 4, 200, 1, 3, 2]
+     * Output: 4
+     * Explanation: The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4.
+     *
+     * 这道题要求求最长连续序列,并给定了O(n)复杂度限制,我们的思路是,使用一个集合HashSet存入所有的数字,
+     * 然后遍历数组中的每个数字,如果其在集合中存在,那么将其移除,然后分别用两个变量pre和next算出其前一个
+     * 数跟后一个数,然后在集合中循环查找,如果pre在集合中,那么将pre移除集合,然后pre再自减1,直至pre不在
+     * 集合之中,对next采用同样的方法,那么next-pre-1就是当前数字的最长连续序列,更新res即可。这里再说下,
+     * 为啥当检测某数字在集合中存在当时候,都要移除数字。这是为了避免大量的重复计算,就拿题目中的例子来说吧,
+     * 我们在遍历到4的时候,会向下遍历3,2,1,如果都不移除数字的话,遍历到1的时候,还会遍历2,3,4。同样,
+     * 遍历到3的时候,向上遍历4,向下遍历2,1,等等等。如果数组中有大量的连续数字的话,那么就有大量的重复计算,
+     * 十分的不高效,所以我们要从HashSet中移除数字
+     * 
+ * + * @param nums + * @return + */ + public int longestConsecutive(int[] nums) { + int res = 0; + Set set = new HashSet<>(); + + for (int i : nums) { + set.add(i); + } + + for (int i : nums) { + if (set.remove(i)) { + int prev = i - 1; + int next = i + 1; + while (set.remove(prev)) { + --prev; + } + while (set.remove(next)) { + ++next; + } + + res = Math.max(res, next - prev - 1); + } + } + + return res; + } +} From 1842fcdf670e44e016e0abcf5fc25f3ec5ef2d6c Mon Sep 17 00:00:00 2001 From: Wang-Jun-Chao Date: Fri, 14 Jun 2019 22:20:00 +0800 Subject: [PATCH 039/108] commit --- .idea/modules.xml | 1 + [016][3 Sum Closest]/src/Solution.java | 14 ++- [016][3 Sum Closest]/src/Solution2.java | 89 +++++++++++++++++++ [018][4 Sum]/src/Solution.java | 34 ++++--- [027][Remove Element]/src/Solution.java | 21 +++-- [027][Remove Element]/src/Solution2.java | 40 +++++++++ [031][Next Permutation]/src/Main.java | 42 +++++++++ [031][Next Permutation]/src/Solution.java | 82 +++++++++++++++++ [060][Permutation Sequence]/src/Solution.java | 23 +++++ 9 files changed, 322 insertions(+), 24 deletions(-) create mode 100644 [016][3 Sum Closest]/src/Solution2.java create mode 100644 [027][Remove Element]/src/Solution2.java create mode 100644 [031][Next Permutation]/src/Main.java create mode 100644 [031][Next Permutation]/src/Solution.java diff --git a/.idea/modules.xml b/.idea/modules.xml index 35b7d25..798b720 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -33,6 +33,7 @@ + diff --git a/[016][3 Sum Closest]/src/Solution.java b/[016][3 Sum Closest]/src/Solution.java index af7e413..136d648 100644 --- a/[016][3 Sum Closest]/src/Solution.java +++ b/[016][3 Sum Closest]/src/Solution.java @@ -47,7 +47,7 @@ public int threeSumClosest(int[] nums, int target) { // iʾȡiΪ - for (int i = 0; i < nums.length - 2; i++) { + for (int i = 0; i < nums.length - 2;) { // ڶܵʼλ int j = i + 1; // ǽλ @@ -77,13 +77,21 @@ public int threeSumClosest(int[] nums, int target) { // ʹtarget if (sum > target) { - k--; + do { + k--; // ҵֵͬ + }while (j < k && nums[k]==nums[k + 1]); } // Сtarget else { - j++; + do { + j++; + }while (j < k && nums[j - 1] == nums[j]); } } + + do { + i++; + }while (i < nums.length - 2 && nums[i - 1] == nums[i]); } return (int) result; diff --git a/[016][3 Sum Closest]/src/Solution2.java b/[016][3 Sum Closest]/src/Solution2.java new file mode 100644 index 0000000..1ed9f61 --- /dev/null +++ b/[016][3 Sum Closest]/src/Solution2.java @@ -0,0 +1,89 @@ +import java.util.Arrays; + +/** + * Author: + * Date: 2015-06-21 + * Time: 09:29 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + /** + *
+     * Given an array S of n integers, find three integers in S such that the sum is
+     * closest to a given number, target. Return the sum of the three integers. You
+     * may assume that each input would have exactly one solution.
+     *
+     * For example,
+     * given array S = {-1 2 1 -4}, and target = 1.
+     * The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).
+     *
+     * Ŀ⣺
+     * nSҵSеӶʹ֮ӽ
+     * ܺ͡Լÿ뽫һȷеĽ
+     *
+     * ˼·
+     * 3sum
+     * 
+ * + * @param nums + * @param target + * @return + */ + public int threeSumClosest(int[] nums, int target) { + + // ¼СIJֵ + long minDiff = Long.MAX_VALUE; + // ¼СֵӦͺ + long result = 0; + // ÿõIJֵ + long diff; + // ÿõĺ + long sum; + + // ȶ + Arrays.sort(nums); + + + // iʾȡiΪ + for (int i = 0; i < nums.length - 2; i++) { + // ڶܵʼλ + int j = i + 1; + // ǽλ + int k = nums.length - 1; + + while (j < k) { + // ǰĺ + sum = nums[j] + nums[k] + nums[i]; + // ǰĿ֮IJֵ + diff = Math.abs(target - sum); + + // ֵΪ0ֱӷ + if (diff == 0) { + return (int) sum; + } + + // ǰIJֵ֮ǰ¼IJֵС + if (diff < minDiff) { + // СIJֵ + minDiff = diff; + // СֵӦĺ + result = sum; + + // ϵһԪشʱЧ + } + + + // ʹtarget + if (sum > target) { + k--; + } + // Сtarget + else { + j++; + } + } + } + + return (int) result; + } +} diff --git a/[018][4 Sum]/src/Solution.java b/[018][4 Sum]/src/Solution.java index f983189..96be97f 100644 --- a/[018][4 Sum]/src/Solution.java +++ b/[018][4 Sum]/src/Solution.java @@ -45,20 +45,27 @@ public List> fourSum(int[] num, int target) { return result; } - Arrays.sort(num); // + // + Arrays.sort(num); - for (int i = 0; i < num.length - 3; i++) { // һ - if (i > 0 && num[i] == num[i - 1]) { // һʹòظ + // һ + for (int i = 0; i < num.length - 3; i++) { + // һʹòظ + if (i > 0 && num[i] == num[i - 1]) { continue; } - for (int j = num.length - 1; j > i + 2; j--) { // ĸ - if (j < num.length - 1 && num[j] == num[j + 1]) { // ĸʹòظ + // ĸ + for (int j = num.length - 1; j > i + 2; j--) { + // ĸʹòظ + if (j < num.length - 1 && num[j] == num[j + 1]) { continue; } - int start = i + 1; // ڶ - int end = j - 1; // + // ڶ + int start = i + 1; + // + int end = j - 1; int n = target - num[i] - num[j]; while (start < end) { @@ -73,19 +80,22 @@ public List> fourSum(int[] num, int target) { do { start++; - } while (start < end && num[start] == num[start - 1]); // ֤ٴʹõڶظ - + // ֤ٴʹõڶظ + } while (start < end && num[start] == num[start - 1]); do { end--; - } while (start < end && num[end] == num[end + 1]); // ֤ٴʹõظ + // ֤ٴʹõظ + } while (start < end && num[end] == num[end + 1]); } else if (num[start] + num[end] < n) { do { start++; - } while (start < end && num[start] == num[start - 1]); // ֤ٴʹõڶظ + // ֤ٴʹõڶظ + } while (start < end && num[start] == num[start - 1]); } else { do { end--; - } while (start < end && num[end] == num[end + 1]); // ֤ٴʹõظ + // ֤ٴʹõظ + } while (start < end && num[end] == num[end + 1]); } } } diff --git a/[027][Remove Element]/src/Solution.java b/[027][Remove Element]/src/Solution.java index e7ae1e6..bfdcaf6 100644 --- a/[027][Remove Element]/src/Solution.java +++ b/[027][Remove Element]/src/Solution.java @@ -18,32 +18,35 @@ public class Solution { * ֵΪelemԪصλãjұֵΪelemԪصλãȻjλõֵƶiλá * * - * @param A - * @param elem + * @param nums + * @param val * @return */ - public int removeElement(int[] A, int elem) { + public int removeElement(int[] nums, int val) { int exchange = 0; // ¼ĴҲͳelemԪֵȵĸ // 㷨˼룺iֵΪelemԪصλãjұֵΪelemԪصλã // ȡȺóΪ1Խ - for (int i = 0, j = A.length - 1; i <= j; i++) { - if (A[i] == elem) { // ҵҪԪ + for (int i = 0, j = nums.length - 1; i <= j; i++) { + // ҵҪԪ + if (nums[i] == val) { exchange++; - while (j > i && A[j] == elem) { // 濪ʼǰҵһelemԪ - exchange++; // ֵΪelemԪ˵Ҫǽ̿ʡȥ + // 濪ʼǰҵһelemԪ + while (j > i && nums[j] == val) { + // ֵΪelemԪ˵Ҫǽ̿ʡȥ + exchange++; j--; } // 1ΪelemԪصλãjλõԪطŵiλ // 2ûҵelemԪصλãiԪֵeʱj=i // jеֵiûйϵ - A[i] = A[j]; + nums[i] = nums[j]; j--; // jѾʹԻҪǰƶһµλ } } - return A.length - exchange; + return nums.length - exchange; } } diff --git a/[027][Remove Element]/src/Solution2.java b/[027][Remove Element]/src/Solution2.java new file mode 100644 index 0000000..e87040c --- /dev/null +++ b/[027][Remove Element]/src/Solution2.java @@ -0,0 +1,40 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 16:43 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + /** + *
+     * ԭ
+     * Given an array and a value, remove all instances of that value in place and return the new length.
+     *  The order of elements can be changed. It doesnt matter what you leave beyond the new length.
+     *
+     * Ŀ
+     * һһֵɾֵȵԪأҷµijȡ
+     *
+     * ˼·
+     *
+     * 
+ * + * @param nums + * @param val + * @return + */ + public int removeElement(int[] nums, int val) { + + // [0, ..., index - 1]ʾѾųvalֵ飬indexʾ֮ԷԪصλã + // Ҳʾij + int index = 0; + for (int i = 0; i < nums.length; i++) { + // Ⱦƶ + if (nums[i] != val) { + nums[index] = nums[i]; + ++index; + } + } + + return index; + } +} diff --git a/[031][Next Permutation]/src/Main.java b/[031][Next Permutation]/src/Main.java new file mode 100644 index 0000000..1f5a159 --- /dev/null +++ b/[031][Next Permutation]/src/Main.java @@ -0,0 +1,42 @@ +import org.junit.Test; + +import java.util.Arrays; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-14 21:30 + **/ +public class Main { + + @Test + public void test1() { + Solution solution = new Solution(); + int[] nums = {1, 2, 3}; + solution.nextPermutation(nums); + System.out.println(Arrays.toString(nums)); + } + + @Test + public void test2() { + Solution solution = new Solution(); + int[] nums = {3, 2, 1}; + solution.nextPermutation(nums); + System.out.println(Arrays.toString(nums)); + } + + @Test + public void test3() { + Solution solution = new Solution(); + int[] nums = {1, 1, 5}; + solution.nextPermutation(nums); + System.out.println(Arrays.toString(nums)); + } + + @Test + public void test4() { + Solution solution = new Solution(); + int[] nums = {1, 3, 2}; + solution.nextPermutation(nums); + System.out.println(Arrays.toString(nums)); + } +} diff --git a/[031][Next Permutation]/src/Solution.java b/[031][Next Permutation]/src/Solution.java new file mode 100644 index 0000000..90a5a19 --- /dev/null +++ b/[031][Next Permutation]/src/Solution.java @@ -0,0 +1,82 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-14 21:17 + **/ +public class Solution { + /** + *
+     * Implement next permutation, which rearranges numbers into the lexicographically next
+     * greater permutation of numbers.
+     *
+     * If such arrangement is not possible, it must rearrange it as the lowest possible order
+     * (ie, sorted in ascending order).
+     *
+     * The replacement must be in-place and use only constant extra memory.
+     *
+     * Here are some examples. Inputs are in the left-hand column and its corresponding outputs
+     * are in the right-hand column.
+     *
+     * 1,2,3 → 1,3,2
+     * 3,2,1 → 1,2,3
+     * 1,1,5 → 1,5,1
+     *
+     * 1.首先从最尾端开始往前寻找一个元素,满足nums[i] < nums[i+1]。
+     * 如果没有找到即i < 0, 说明整个数组是递增的,已经到了最大值,此时只要反转数组即可
+     * 如果i >= 0
+     *
+     * 2.再从最尾端开始往前检验,找出第一个大于nums[i]的元素nums[j] 并且,j >= i
+     * 将nums[i],nums[j]元素对调(swap)。
+     *
+     * 3.再将i位置之后的所有元素颠倒(reverse)排序。
+     * 
+ * + * @param nums + */ + public void nextPermutation(int[] nums) { + int i = nums.length - 2; + // 从后向前查找第一个元素i,并且使用nums[i] >= nums[i+1]不成立。 + while (i >= 0 && nums[i] >= nums[i + 1]) { + i--; + } + + // 此时nums[i+1, ..., last]是递增的 + + + if (i >= 0) { + int j = nums.length - 1; + // 从右开始向左找,找第一个大于等num[i]的元素 + // 如果找到i==j,说明没有找到 + while (j > i && nums[j] <= nums[i]) { + j--; + } + + // 交换两者之间的值,当j == i时,交换也没有问题 + swap(nums, i, j); + + // 将nums[i+1, last]进行反转 + reverse(nums, i + 1); + } else { + // 说明整个序列是非递增的 + // 对子数组进行翻转 + reverse(nums, 0); + } + + + } + + private void reverse(int[] nums, int start) { + int i = start; + int j = nums.length - 1; + while (i < j) { + swap(nums, i, j); + i++; + j--; + } + } + + private void swap(int[] nums, int i, int j) { + int temp = nums[i]; + nums[i] = nums[j]; + nums[j] = temp; + } +} diff --git a/[060][Permutation Sequence]/src/Solution.java b/[060][Permutation Sequence]/src/Solution.java index 1234e44..3bc2edf 100644 --- a/[060][Permutation Sequence]/src/Solution.java +++ b/[060][Permutation Sequence]/src/Solution.java @@ -6,6 +6,25 @@ * @time: 2018-09-28 15:45 **/ public class Solution { + /** + *
+     * 利用康托编码的思路,假设有n 个不重复的元素,第k 个排列是a1; a2; a3; :::; an,那么a1 是
+     * 哪一个位置呢?
+     * 我们把a1 去掉,那么剩下的排列为a2; a3; :::; an, 共计n-1 个元素,n-1 个元素共有(n-1)!
+     * 个排列,于是就可以知道a1 = k/(n - 1)!。
+     * 同理,a2; a3; :::; an 的值推导如下:
+     * k2 = k%(n - 1)!
+     * a2 = k2/(n - 2)!
+     * ...
+     * k(n-1) = k(n-2)%2!
+     * a(n-1) = k(n-1)/1!
+     * an = 0
+     * 
+ * + * @param n + * @param k + * @return + */ public String getPermutation(int n, int k) { StringBuilder sb = new StringBuilder(); @@ -21,14 +40,18 @@ public String getPermutation(int n, int k) { int index; for (int i = 0, l = k - 1; i < n; i++) { // 从最大的阶乘数开始减少 + // fact的值说明,如果从 __1____ -> _2____ 至少要经过fact次变换 fact /= (n - i); // 计算剩下的数据中的索引 + // 说明类似 __1____ -> _2____ 的变化可以做 index 次,0表示不用变 index = (l / fact); // 将索引值添加到结果中 + // 每做一次__1____ -> _2____ 的变化,表示在num中取后一个更大的值 sb.append(num.remove(index)); // 余下要处理的数 l -= index * fact; } + return sb.toString(); } } From 1361e115a9fa56a12e2ca7e7240b41b08e6d789d Mon Sep 17 00:00:00 2001 From: Wang-Jun-Chao Date: Sat, 15 Jun 2019 06:47:20 +0800 Subject: [PATCH 040/108] commit --- [036][Valid Sudoku]/src/Solution.java | 15 +++++----- [042][Trapping Rain Water]/src/Solution.java | 29 ++++++++++++++------ 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/[036][Valid Sudoku]/src/Solution.java b/[036][Valid Sudoku]/src/Solution.java index d0147d6..80b5bcd 100644 --- a/[036][Valid Sudoku]/src/Solution.java +++ b/[036][Valid Sudoku]/src/Solution.java @@ -1,3 +1,5 @@ +import java.util.Arrays; + /** * Author: * Date: 2015-08-21 @@ -42,9 +44,12 @@ public boolean isValidSudoku(char[][] board) { record[board[i][j] - '.']++; } - if (!check(record)) { // Ǽʧ + // Ǽʧ + if (!check(record)) { return false; - } else { // ɹ + } + // ɹ + else { reset(record); } } @@ -83,11 +88,7 @@ public boolean isValidSudoku(char[][] board) { } private void reset(int[] a) { - for (int i = 0; i < a.length; i++) { - a[i] = 0; - } - - + Arrays.fill(a, 0); } /** diff --git a/[042][Trapping Rain Water]/src/Solution.java b/[042][Trapping Rain Water]/src/Solution.java index f057b8f..fbff8c5 100644 --- a/[042][Trapping Rain Water]/src/Solution.java +++ b/[042][Trapping Rain Water]/src/Solution.java @@ -11,20 +11,33 @@ public int trap(int[] height) { return trap4(height); } + /** + *
+     * 对于每个柱子,找到其左右两边最高的柱子,该柱子能容纳的面积就是min(max_left,max_right) - height。所以,
+     * 1. 从左往右扫描一遍,对于每个柱子,求取左边最大值;
+     * 2. 从右往左扫描一遍,对于每个柱子,求最大右值;
+     * 3. 再扫描一遍,把每个柱子的面积并累加。
+     * 
+ * + * @param height + * @return + */ public int trap1(int[] height) { int ans = 0; int size = height.length; for (int i = 1; i < size - 1; i++) { int maxLeft = 0; int maxRight = 0; - for (int j = i; j >= 0; j--) { //Search the left part for max bar size + // 找此柱左边最高的柱子 + for (int j = i - 1; j >= 0; j--) { maxLeft = Math.max(maxLeft, height[j]); } - for (int j = i; j < size; j++) { //Search the right part for max bar size + // 找此柱子右边最高的柱子 + for (int j = i + 2; j < size; j++) { maxRight = Math.max(maxRight, height[j]); } - // TODO 原理是什么? + // Math.min(maxLeft, maxRight) - height[i] 此柱子可以容纳的水 ans += Math.min(maxLeft, maxRight) - height[i]; } return ans; @@ -39,15 +52,13 @@ int trap2(int[] height) { int[] leftMax = new int[size]; int[] rightMax = new int[size]; - leftMax[0] = height[0]; - for (int i = 1; i < size; i++) { + + // 对于每个柱子求左右最大值,并保存起来 + for (int i = 1; i < size - 1; i++) { leftMax[i] = Math.max(height[i], leftMax[i - 1]); + rightMax[size - i - 1] = Math.max(height[size - i], rightMax[size - i]); } - rightMax[size - 1] = height[size - 1]; - for (int i = size - 2; i >= 0; i--) { - rightMax[i] = Math.max(height[i], rightMax[i + 1]); - } for (int i = 1; i < size - 1; i++) { ans += Math.min(leftMax[i], rightMax[i]) - height[i]; From 8222ebfdab44513a7d8980588a4f13442dfe5b73 Mon Sep 17 00:00:00 2001 From: Wang-Jun-Chao Date: Sat, 15 Jun 2019 07:08:40 +0800 Subject: [PATCH 041/108] commit --- [042][Trapping Rain Water]/src/Solution.java | 37 ++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/[042][Trapping Rain Water]/src/Solution.java b/[042][Trapping Rain Water]/src/Solution.java index fbff8c5..810a76c 100644 --- a/[042][Trapping Rain Water]/src/Solution.java +++ b/[042][Trapping Rain Water]/src/Solution.java @@ -66,25 +66,58 @@ int trap2(int[] height) { return ans; } + /** + *
+     * 用一个栈辅助,小于栈顶的元素压入,大于等于栈顶就把栈里所有小于或
+     * 等于当前值的元素全部出栈处理掉,计算面积,最后把当前元素入栈
+     *
+     *
+     *
+     *         =
+     *    =   === =
+     *  = == =======
+     * =============
+     * 0123456789012
+     * 
+ * @param height + * @return + */ int trap3(int[] height) { int ans = 0, current = 0; Deque st = new LinkedList<>(); while (current < height.length) { + // 当前元素比栈顶元素大 while (!st.isEmpty() && height[current] > height[st.getFirst()]) { - int top = st.peek(); - st.pop(); + int top = st.pop(); if (st.isEmpty()) { break; } + + // 求距离,如上图,比如current=7,此时top=4,top到current距离:current-top-1 int distance = current - st.peek() - 1; + // top以下的水位已经计算过了,top以上的水位就 + // height[current] - height[top], height[st.peek()] - height[top] + // 较小的值,简化为以下面的表达式 int boundedHeight = Math.min(height[current], height[st.peek()]) - height[top]; ans += distance * boundedHeight; } + + // 当前元素不大于栈顶元素 st.push(current++); } return ans; } + /** + *
+     * 1. 扫描一遍,找到最高的柱子,这个柱子将数组分为两半;
+     * 2. 处理左边一半;
+     * 3. 处理右边一半。
+     * 
+ * + * @param height + * @return + */ int trap4(int[] height) { int left = 0; int right = height.length - 1; From ca8df7d97de609b8f0692d7112b39e084f85ee73 Mon Sep 17 00:00:00 2001 From: Wang-Jun-Chao Date: Sat, 15 Jun 2019 14:08:25 +0800 Subject: [PATCH 042/108] commit --- [048][Rotate Image]/src/Solution.java | 2 +- [066][Plus One]/src/Solution.java | 15 ++++++++++----- [070][Climbing Stairs]/src/Solution.java | 10 ++++++++++ [089][Gray Code]/src/Solution.java | 24 ++++++++++++++++++++++-- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/[048][Rotate Image]/src/Solution.java b/[048][Rotate Image]/src/Solution.java index 8a32e23..bba7234 100644 --- a/[048][Rotate Image]/src/Solution.java +++ b/[048][Rotate Image]/src/Solution.java @@ -15,7 +15,7 @@ public void rotate(int[][] matrix) { } } - // 再对行进行水平转换 + // 再对行进行垂直转换 int half = matrix.length / 2; for (int i = 0; i < matrix.length; i++) { for (int j = 0; j < half; j++) { diff --git a/[066][Plus One]/src/Solution.java b/[066][Plus One]/src/Solution.java index baef319..efc7195 100644 --- a/[066][Plus One]/src/Solution.java +++ b/[066][Plus One]/src/Solution.java @@ -26,19 +26,24 @@ public class Solution { */ public int[] plusOne(int[] digits) { - int carry = 1; // λ־һλĽλ־ + // λ־һλĽλ־ + int carry = 1; int tmp; for (int i = digits.length - 1; i >= 0; i--) { tmp = digits[i]; - digits[i] = (tmp + carry) % 10; // 㵱ǰλֵ - carry = (tmp + carry) / 10; // µĽλ + // 㵱ǰλֵ + digits[i] = (tmp + carry) % 10; + // µĽλ + carry = (tmp + carry) / 10; - if (carry == 0) { // ûнλ˾Ϳ˳ + // ûнλ˾Ϳ˳ + if (carry == 0) { break; } } - if (carry == 1) { // һλ + // һλ + if (carry == 1) { int[] result = new int[digits.length + 1]; System.arraycopy(digits, 0, result, 1, digits.length); result[0] = carry; diff --git a/[070][Climbing Stairs]/src/Solution.java b/[070][Climbing Stairs]/src/Solution.java index 0ac8cfa..570efe8 100644 --- a/[070][Climbing Stairs]/src/Solution.java +++ b/[070][Climbing Stairs]/src/Solution.java @@ -5,6 +5,16 @@ * Declaration: All Rights Reserved !!! */ public class Solution { + /** + *
+     * f(n) ʾn ¥ݵIJͬΪn ¥ݣѡ
+     * - ӵn - 1 ǰ1 
+     * - ӵn - 1 ǰ2 
+     * ˣf(n) = f(n - 1) + f(n - 2)
+     * 
+ * @param n + * @return + */ public int climbStairs(int n) { int result = 0; diff --git a/[089][Gray Code]/src/Solution.java b/[089][Gray Code]/src/Solution.java index 4a53251..5611c15 100644 --- a/[089][Gray Code]/src/Solution.java +++ b/[089][Gray Code]/src/Solution.java @@ -29,12 +29,32 @@ public class Solution { * * Ŀ⣺ * nΪnĸ + * + * (Gray Code) Ķοhttp://en.wikipedia.org/wiki/Gray_code + * ȻתΪ룺g0 = b0; gi = bi^b(i-1) + * ȻλΪλθλΪĸλθλ + * λθλơ磬Ȼ1001תΪĹǣ + * λȻ󽫵1 λ1 ͵2 λ0 򣬵õ1Ϊĵ2 λ2 λ0 ͵3 λ + * 0 򣬵õ0Ϊĵ3 λ3 λ0 ͵4 λ1 򣬵õ1Ϊ + * 4 λգΪ1101 + * תΪȻ룺b0 = g0; bi = gi^b(i-1) + * λΪȻλθλΪȻƸλθλ + * λθλơ磬1000 תΪȻĹǣ + * λ1ΪȻλȻȻĵ1 λ1 ͸ĵ2 λ0 򣬵 + * 1ΪȻĵ2 λȻĵ2 λ1 ͸ĵ3 λ0 򣬵õ1 + * ΪȻĵ3 λȻĵ3 λ1 ͸ĵ4 λ0 򣬵õ1Ϊ + * Ȼĵ4 λգȻΪ1111 + * ѧʽn ĸn^(n/2) + * Ҫn صи롣 + * 1򵥵ķѧʽԴ0 ~2^n-1 תΪ롣 + * 2nصĸ룬Եݹشn - 1 صĸɡ + * * ˼· * ݹ * ַڸǷʵõݹ¹죺 * 1λ - * (n+1)λеǰ2nֵnλ֣˳дǰ׺0 - * (n+1)λеĺ2nֵnλ֣дǰ׺1 + * (n+1)λеǰ2^nֵnλ֣˳дǰ׺0 + * (n+1)λеĺ2^nֵnλ֣дǰ׺1 * * * @param n From 8a664b583de139025779ead4423dbedbdb821513 Mon Sep 17 00:00:00 2001 From: Wang-Jun-Chao Date: Mon, 17 Jun 2019 11:04:28 +0800 Subject: [PATCH 043/108] commit --- .../src/FileRename.java | 0 [000][common]/src/MaxSubArray.java | 47 +++++++++++ [002][Add Two Numbers]/src/Solution.java | 15 ++-- [009][Palindrome Number]/src/Main.java | 13 ++++ [089][Gray Code]/src/Solution.java | 2 +- [134][Gas Station]/src/Main.java | 17 ++++ [134][Gas Station]/src/Solution.java | 4 +- [135][Candy]/src/Main.java | 14 ++++ [135][Candy]/src/Solution.java | 77 +++++++++++++++++++ [136][Single Number]/src/Solution.java | 2 +- 10 files changed, 183 insertions(+), 8 deletions(-) rename {[000][utils] => [000][common]}/src/FileRename.java (100%) create mode 100644 [000][common]/src/MaxSubArray.java create mode 100644 [009][Palindrome Number]/src/Main.java create mode 100644 [134][Gas Station]/src/Main.java create mode 100644 [135][Candy]/src/Main.java create mode 100644 [135][Candy]/src/Solution.java diff --git a/[000][utils]/src/FileRename.java b/[000][common]/src/FileRename.java similarity index 100% rename from [000][utils]/src/FileRename.java rename to [000][common]/src/FileRename.java diff --git a/[000][common]/src/MaxSubArray.java b/[000][common]/src/MaxSubArray.java new file mode 100644 index 0000000..e19a385 --- /dev/null +++ b/[000][common]/src/MaxSubArray.java @@ -0,0 +1,47 @@ +import org.junit.Test; + +import java.util.Arrays; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-16 11:16 + **/ +public class MaxSubArray { + public int[] solve(int[] array) { + if (array == null || array.length < 1) { + return null; + } + + + // result[0] 最大的子数组和 + // result[1] 最大的子数组的起始位置 + // result[2] 最大的子数组的结束位置 + int[] result = {Integer.MIN_VALUE, -1, -1}; + + int sum = 0; + int begin = 0; + for (int i = 0; i < array.length; i++) { + if (sum >= 0) { + sum += array[i]; + } else { + sum = array[i]; + begin = i; + } + + if (result[0] <= sum) { + result[0] = sum; + result[1] = begin; + result[2] = i; + } + } + + return result; + } + + @Test + public void test1() { + MaxSubArray maxSubArray = new MaxSubArray(); + + System.out.println(Arrays.toString(maxSubArray.solve(new int[]{1, 2, 3, 4, 5, 6}))); + } +} diff --git a/[002][Add Two Numbers]/src/Solution.java b/[002][Add Two Numbers]/src/Solution.java index 1bb9d80..8839d26 100644 --- a/[002][Add Two Numbers]/src/Solution.java +++ b/[002][Add Two Numbers]/src/Solution.java @@ -39,19 +39,24 @@ public ListNode addTwoNumbers(ListNode l1, ListNode l2) { ListNode p1 = l1; ListNode p2 = l2; - ListNode root = new ListNode(0); // ͷ + // ͷ + ListNode root = new ListNode(0); ListNode r = root; root.next = l1; - int carry = 0; // ʼλ + // ʼλ + int carry = 0; int sum; while (p1 != null && p2 != null) { sum = p1.val + p2.val + carry; - p1.val = sum % 10; // λĽ - carry = sum / 10; // νλ + // λĽ + p1.val = sum % 10; + // νλ + carry = sum / 10; r.next = p1; - r = p1; // ָһӵĽ + // ָһӵĽ + r = p1; p1 = p1.next; p2 = p2.next; diff --git a/[009][Palindrome Number]/src/Main.java b/[009][Palindrome Number]/src/Main.java new file mode 100644 index 0000000..e04c77b --- /dev/null +++ b/[009][Palindrome Number]/src/Main.java @@ -0,0 +1,13 @@ +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-16 11:06 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + System.out.println(solution.isPalindrome(123321)); + } +} diff --git a/[089][Gray Code]/src/Solution.java b/[089][Gray Code]/src/Solution.java index 5611c15..4af4a3c 100644 --- a/[089][Gray Code]/src/Solution.java +++ b/[089][Gray Code]/src/Solution.java @@ -10,7 +10,7 @@ public class Solution { /** *
-     * The gray code is a binary numeral system where two successive values differ in only one bit.
+     * The nums[c] is a binary numeral system where two successive values differ in only one bit.
      * Given a non-negative integer n representing the total number of bits in the code, print the
      * sequence of gray code. A gray code sequence must begin with 0.
      *
diff --git a/[134][Gas Station]/src/Main.java b/[134][Gas Station]/src/Main.java
new file mode 100644
index 0000000..250a219
--- /dev/null
+++ b/[134][Gas Station]/src/Main.java	
@@ -0,0 +1,17 @@
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-16 11:06
+ **/
+public class Main {
+    @Test
+    public void test1() {
+        Solution solution = new Solution();
+        int[] gas = {1, 2, 3, 4, 5};
+        int[] cost = {3, 4, 5, 1, 2};
+        int pos = solution.canCompleteCircuit(gas, cost);
+        Assert.assertEquals(3, pos);
+    }
+}
diff --git a/[134][Gas Station]/src/Solution.java b/[134][Gas Station]/src/Solution.java
index 3b4e1ae..213926c 100644
--- a/[134][Gas Station]/src/Solution.java	
+++ b/[134][Gas Station]/src/Solution.java	
@@ -100,7 +100,9 @@ public int canCompleteCircuit(int[] gas, int[] cost) {
     }
 
 
-    // ķᳬʱO(N^2)ʱ临Ӷ
+    /**
+     * ķᳬʱO(N^2)ʱ临Ӷ
+     */
     public int canCompleteCircuit2(int[] gas, int[] cost) {
         // 
         if (gas == null || cost == null || gas.length == 0 || gas.length != cost.length) {
diff --git a/[135][Candy]/src/Main.java b/[135][Candy]/src/Main.java
new file mode 100644
index 0000000..54ea1af
--- /dev/null
+++ b/[135][Candy]/src/Main.java
@@ -0,0 +1,14 @@
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-16 11:37
+ **/
+public class Main {
+    @Test
+    public void test1() {
+        Solution solution = new Solution();
+        Assert.assertEquals(5, solution.candy(new int[]{1, 0, 2}));
+    }
+}
diff --git a/[135][Candy]/src/Solution.java b/[135][Candy]/src/Solution.java
new file mode 100644
index 0000000..ea602e0
--- /dev/null
+++ b/[135][Candy]/src/Solution.java
@@ -0,0 +1,77 @@
+/**
+ * @author: wangjunchao(王俊超)
+ * @time: 2019-06-16 11:27
+ **/
+public class Solution {
+    /**
+     * 
+     * There are N children standing in a line. Each child is assigned a rating value.
+     *
+     * You are giving candies to these children subjected to the following requirements:
+     *
+     * 1. Each child must have at least one candy.
+     * 2. Children with a higher rating get more candies than their neighbors.
+     * What is the minimum candies you must give?
+     *
+     * Example 1:
+     *
+     * Input: [1,0,2]
+     * Output: 5
+     * Explanation: You can allocate to the first, second and third child with 2, 1, 2 candies respectively.
+     * Example 2:
+     *
+     * Input: [1,2,2]
+     * Output: 4
+     * Explanation: You can allocate to the first, second and third child with 1, 2, 1 candies respectively.
+     *              The third child gets 1 candy because it satisfies the above two conditions.
+     * 
+ * + * @param ratings + * @return + */ + public int candy(int[] ratings) { + if (ratings == null || ratings.length < 1) { + return 0; + } + + + int[] increment = new int[ratings.length]; + // 左右各扫描一遍 + for (int i = 1, inc = 1; i < ratings.length; i++) { + // 右边的孩子分数比左边的孩子分数高 + if (ratings[i] > ratings[i - 1]) { + // 右边的孩子比左边的孩子多发至少一个糖果 + increment[i] = increment[i - 1] + 1; + } +// // 右边的孩子分数与左边的孩子分数相等,相等可以少发 +// else if (ratings[i] == ratings[i - 1]) { +// // 右边和左边的孩子增同样多颗糖 +// increment[i] = increment[i - 1]; +// } + // 可以不处理 +// else{ +// increment[i] = 0; +// } + } + + // 从右到左进行处理 + for (int i = ratings.length - 2, inc = 1; i >= 0; i--) { + // 左边的孩子分数比右边高 + if (ratings[i] > ratings[i + 1]) { + increment[i] = Math.max(increment[i], increment[i + 1] + 1); + } + // +// else if (ratings[i] == ratings[i + 1]) { +// // 总是成立了 +// increment[i] = increment[i - 1]; +// } + // ratings[i] < ratings[i + 1] 不需要操作 + } + + int sum = ratings.length; + for (int n : increment) { + sum += n; + } + return sum; + } +} diff --git a/[136][Single Number]/src/Solution.java b/[136][Single Number]/src/Solution.java index 4dce0d3..1ec5d37 100644 --- a/[136][Single Number]/src/Solution.java +++ b/[136][Single Number]/src/Solution.java @@ -23,7 +23,7 @@ public class Solution { public int singleNumber(int[] nums) { if (nums == null || nums.length < 1) { - throw new IllegalArgumentException("nums"); + throw new IllegalArgumentException("nums should contain at least one element"); } From bad4d98ef5b40badb724673548a8bbab0d17b81d Mon Sep 17 00:00:00 2001 From: Wang-Jun-Chao Date: Mon, 17 Jun 2019 19:20:41 +0800 Subject: [PATCH 044/108] commit --- .idea/modules.xml | 8 +- .../src/Solution.java | 2 +- [012][Integer To Roman]/src/Main.java | 39 +++++++ [012][Integer To Roman]/src/Solution2.java | 56 +++++++++ [013][Romar To Integer]/src/Main.java | 9 ++ [013][Romar To Integer]/src/Solution.java | 87 ++++---------- [013][Romar To Integer]/src/Solution2.java | 98 ++++++++++++++++ [014][Longest Common Prefix]/src/Main.java | 20 ++++ .../src/Solution.java | 27 ++--- .../src/Solution2.java | 65 +++++++++++ .../src/Solution.java | 1 + [020][Valid Parentheses]/src/Main.java | 22 ++++ [020][Valid Parentheses]/src/Solution.java | 67 ++--------- [020][Valid Parentheses]/src/Solution2.java | 97 ++++++++++++++++ [024][Swap Nodes In Pairs]/src/Solution.java | 5 +- .../src/Solution2.java | 59 ++++++++++ [061][Rotate List]/src/Solution.java | 49 +++----- [061][Rotate List]/src/Solution2.java | 62 ++++++++++ [065][Valid Number]/src/Main.java | 95 +++++++++++++++ [065][Valid Number]/src/Solution.java | 100 ++++++++++++++++ .../src/Solution.java | 51 ++++++--- .../src/Solution.java | 19 ++- .../src/Solution.java | 71 ++++++++++++ [086][Partition List]/src/Solution.java | 4 +- .../src/Solution.java | 3 +- .../src/Solution.java | 8 +- .../src/Solution.java | 9 +- .../src/Solution.java | 2 +- [141][Linked List Cycle]/src/Solution.java | 16 +++ .../src/RandomListNode.java | 14 --- .../src/Solution.java | 108 ------------------ [143][Reorder List]/src/ListNode.java | 14 +++ [143][Reorder List]/src/Solution.java | 78 +++++++++++++ .../src/Solution.java | 6 +- [146][LRU Cache]/src/LRUCache.java | 69 +++++++++++ [146][LRU Cache]/src/Main.java | 26 +++++ [206][Reverse Linked List]/src/Solution.java | 5 +- 37 files changed, 1136 insertions(+), 335 deletions(-) create mode 100644 [012][Integer To Roman]/src/Main.java create mode 100644 [012][Integer To Roman]/src/Solution2.java create mode 100644 [013][Romar To Integer]/src/Solution2.java create mode 100644 [014][Longest Common Prefix]/src/Main.java create mode 100644 [014][Longest Common Prefix]/src/Solution2.java create mode 100644 [020][Valid Parentheses]/src/Main.java create mode 100644 [020][Valid Parentheses]/src/Solution2.java create mode 100644 [032][Longest Valid Parentheses]/src/Solution2.java create mode 100644 [061][Rotate List]/src/Solution2.java create mode 100644 [065][Valid Number]/src/Main.java create mode 100644 [065][Valid Number]/src/Solution.java create mode 100644 [084][Largest Rectangle in Histogram]/src/Solution.java delete mode 100644 [143][Copy List With Random Pointer]/src/RandomListNode.java delete mode 100644 [143][Copy List With Random Pointer]/src/Solution.java create mode 100644 [143][Reorder List]/src/ListNode.java create mode 100644 [143][Reorder List]/src/Solution.java create mode 100644 [146][LRU Cache]/src/LRUCache.java create mode 100644 [146][LRU Cache]/src/Main.java diff --git a/.idea/modules.xml b/.idea/modules.xml index 798b720..0654150 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,7 +2,7 @@ - + @@ -67,6 +67,7 @@ + @@ -81,6 +82,7 @@ + @@ -117,15 +119,17 @@ + - + + diff --git a/[005][Longest Palindromic Substring Total]/src/Solution.java b/[005][Longest Palindromic Substring Total]/src/Solution.java index 7034ef0..7409c74 100644 --- a/[005][Longest Palindromic Substring Total]/src/Solution.java +++ b/[005][Longest Palindromic Substring Total]/src/Solution.java @@ -23,7 +23,7 @@ public class Solution { * Ҫ׼ϵĹʽ * * a. i + 1 = j -1ijΪ1ʱdp[ i ][ i ] = true; - * b. i +1 = (j - 1) -1ijΪ2ʱdp[ i ][ i + 1] = s[ i ] == s[ i + 1] + * b. i +1 = (j - 1) -1ijΪ2ʱdp[ i ][ i + 1] = (s[ i ] == s[ i + 1]) * * ϷͿдˡҪעǶ̬滮ҪO(n^2)Ŀռ䡣 *
diff --git a/[012][Integer To Roman]/src/Main.java b/[012][Integer To Roman]/src/Main.java new file mode 100644 index 0000000..395df1b --- /dev/null +++ b/[012][Integer To Roman]/src/Main.java @@ -0,0 +1,39 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-17 14:03 + **/ +public class Main { + + @Test + public void test1() { + Solution2 solution = new Solution2(); + Assert.assertEquals("III", solution.intToRoman(3)); + } + + @Test + public void test2() { + Solution2 solution = new Solution2(); + Assert.assertEquals("IV", solution.intToRoman(4)); + } + + @Test + public void test3() { + Solution2 solution = new Solution2(); + Assert.assertEquals("IX", solution.intToRoman(9)); + } + + @Test + public void test4() { + Solution2 solution = new Solution2(); + Assert.assertEquals("LVIII", solution.intToRoman(58)); + } + + @Test + public void test5() { + Solution2 solution = new Solution2(); + Assert.assertEquals("MCMXCIV", solution.intToRoman(1994)); + } +} diff --git a/[012][Integer To Roman]/src/Solution2.java b/[012][Integer To Roman]/src/Solution2.java new file mode 100644 index 0000000..f13fad7 --- /dev/null +++ b/[012][Integer To Roman]/src/Solution2.java @@ -0,0 +1,56 @@ +/** + * Author: + * Date: 2015-06-30 + * Time: 14:28 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + /** + *
+     * Given an integer, convert it to a roman numeral.
+     *
+     * Input is guaranteed to be within the range from 1 to 3999.
+     *
+     * ֵıʾ
+     * λ
+     * (I, 1)  (II, 2)  (III, 3)  (IV, 4)  (V, 5)  (VI, 6)  (VII, 7)  (VIII, 8)  (IX, 9)
+     *
+     * ʮλ
+     * (X, 10)  (XI, 11)  (XII, 12)  (XIII, 13)  (XIV, 14)  (XV, 15)  (XVI, 16)
+     * (XVII, 17)  (XVIII, 18)  (XIX, 19)  (XX, 20)  (XXI, 21)  (XXII, 22)
+     * (XXIX, 29)  (XXX, 30)  (XXXIV, 34)  (XXXV, 35)  (XXXIX, 39)  (XL, 40)
+     * (L, 50)  (LI, 51)  (LV, 55)  (LX, 60)  (LXV, 65)  (LXXX, 80)  (XC, 90)
+     * (XCIII, 93)  (XCV, 95)  (XCVIII, 98)  (XCIX, 99)
+     *
+     * λ
+     * (C, 100)  (CC, 200)  (CCC, 300)  (CD, 400)  (D, 500)  (DC, 600)  (DCC, 700)
+     * (DCCC, 800)  (CM, 900)  (CMXCIX, 999)
+     *
+     * ǧλ
+     * (M, 1000)  (MC, 1100)  (MCD, 1400)  (MD, 1500)  (MDC, 1600)  (MDCLXVI, 1666)
+     * (MDCCCLXXXVIII, 1888)  (MDCCCXCIX, 1899)  (MCM, 1900)  (MCMLXXVI, 1976)
+     * (MCMLXXXIV, 1984)  (MCMXC, 1990)  (MM, 2000)  (MMMCMXCIX, 3999)
+     *
+     * Ŀ⣺
+     * һ֣תһ֣[1, 3999]֮
+     *
+     * 
+ * + * @param num + * @return + */ + public String intToRoman(int num) { + + final int[] radix = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}; + final String[] symbol = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"}; + String roman = ""; + for (int i = 0; num > 0; ++i) { + int count = num / radix[i]; + num %= radix[i]; + for (; count > 0; --count) { + roman += symbol[i]; + } + } + return roman; + } +} diff --git a/[013][Romar To Integer]/src/Main.java b/[013][Romar To Integer]/src/Main.java index 78bbc1a..5d7ae8a 100644 --- a/[013][Romar To Integer]/src/Main.java +++ b/[013][Romar To Integer]/src/Main.java @@ -1,3 +1,6 @@ +import org.junit.Assert; +import org.junit.Test; + /** * Author: 王俊超 * Date: 2015-03-01 @@ -25,4 +28,10 @@ public static void main(String[] args) { System.out.println(solution.romanToInt("MCMLXXVI")); System.out.println(solution.romanToInt("MMMCMXCIX")); } + + @Test + public void test1() { + Solution solution = new Solution(); + Assert.assertEquals(1994, solution.romanToInt("MCMXCIV")); + } } diff --git a/[013][Romar To Integer]/src/Solution.java b/[013][Romar To Integer]/src/Solution.java index c6fca2b..f47e222 100644 --- a/[013][Romar To Integer]/src/Solution.java +++ b/[013][Romar To Integer]/src/Solution.java @@ -16,7 +16,9 @@ public class Solution { * 输入的数字在1-3999之间。 * * 解题思路 - * 根据罗马数字与整数数字对应关系进行加法操作,如果前一个数字比后一个大就相减,否则进行相加。 + * 从前往后扫描,用一个临时变量记录分段数字。 + * 如果当前比前一个大,说明这一段的值应该是当前这个值减去上一个值。比如IV = 5 – 1;否 + * 则,将当前值加入到结果中,然后开始下一段记录。比如VI = 5 + 1, II=1+1 * * * @param s @@ -25,74 +27,29 @@ public class Solution { public int romanToInt(String s) { int result = 0; - int prev = 0; // 记录前一个数字的值 - for (int i = s.length() - 1; i > -1; i--) { - switch (s.charAt(i)) { - case 'I': // 1 - if (1 < prev) { - result -= 1; - } else { - result += 1; - - } - prev = 1; - break; - - case 'V': // 5 - - if (5 < prev) { - result -= 5; - } else { - result += 5; - } - - prev = 5; - - break; - case 'X': // 10 - if (10 < prev) { - result -= 10; - } else { - result += 10; - } - - prev = 10; - break; - case 'L': // 50 - if (50 < prev) { - result -= 50; - } else { - result += 50; - } - - prev = 50; - break; - case 'C': // 100 - if (100 < prev) { - result -= 100; - } else { - result += 100; - } - - prev = 100; - break; - case 'D': // 500 - if (500 < prev) { - result -= 500; - } else { - result += 500; - } - - prev = 500; - break; - case 'M': // 1000 - result += 1000; - prev = 1000; - break; + for (int i = 0; i < s.length(); i++) { + // 当前的值比前一个值大,说明[i-1, i]组成一个值,并且值是s[i-1]-s[i] + if (i > 0 && charToInt(s.charAt(i)) > charToInt(s.charAt(i - 1))) { + // 要减去两倍之前前值才能回到真实值 + result += charToInt(s.charAt(i)) - 2 * charToInt(s.charAt(i - 1)); + } else { + result += charToInt(s.charAt(i)); } } return result; } + private int charToInt(char c) { + switch (c) { + case 'I': return 1; + case 'V': return 5; + case 'X': return 10; + case 'L': return 50; + case 'C': return 100; + case 'D': return 500; + case 'M': return 1000; + default: return 0; + } + } } diff --git a/[013][Romar To Integer]/src/Solution2.java b/[013][Romar To Integer]/src/Solution2.java new file mode 100644 index 0000000..9d08f55 --- /dev/null +++ b/[013][Romar To Integer]/src/Solution2.java @@ -0,0 +1,98 @@ +/** + * Author: 王俊超 + * Date: 2015-03-01 + * Time: 16:09 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + /** + *
+     * 原题
+     * Given a roman numeral, convert it to an integer.
+     * Input is guaranteed to be within the range from 1 to 3999.
+     *
+     * 题目大意
+     * 给定一个罗马数字,将其转换成对应的整数。
+     * 输入的数字在1-3999之间。
+     *
+     * 解题思路
+     * 根据罗马数字与整数数字对应关系进行加法操作,如果前一个数字比后一个大就相减,否则进行相加。
+     * 
+ * + * @param s + * @return + */ + public int romanToInt(String s) { + + int result = 0; + int prev = 0; // 记录前一个数字的值 + + for (int i = s.length() - 1; i > -1; i--) { + switch (s.charAt(i)) { + case 'I': // 1 + if (1 < prev) { + result -= 1; + } else { + result += 1; + + } + prev = 1; + break; + + case 'V': // 5 + + if (5 < prev) { + result -= 5; + } else { + result += 5; + } + + prev = 5; + + break; + case 'X': // 10 + if (10 < prev) { + result -= 10; + } else { + result += 10; + } + + prev = 10; + break; + case 'L': // 50 + if (50 < prev) { + result -= 50; + } else { + result += 50; + } + + prev = 50; + break; + case 'C': // 100 + if (100 < prev) { + result -= 100; + } else { + result += 100; + } + + prev = 100; + break; + case 'D': // 500 + if (500 < prev) { + result -= 500; + } else { + result += 500; + } + + prev = 500; + break; + case 'M': // 1000 + result += 1000; + prev = 1000; + break; + } + } + + return result; + } +} diff --git a/[014][Longest Common Prefix]/src/Main.java b/[014][Longest Common Prefix]/src/Main.java new file mode 100644 index 0000000..5a40b00 --- /dev/null +++ b/[014][Longest Common Prefix]/src/Main.java @@ -0,0 +1,20 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-17 13:05 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + Assert.assertEquals("fl", solution.longestCommonPrefix(new String[]{"flower", "flow", "flight"})); + } + + @Test + public void test2() { + Solution solution = new Solution(); + Assert.assertEquals("", solution.longestCommonPrefix(new String[]{"dog","racecar","car"})); + } +} diff --git a/[014][Longest Common Prefix]/src/Solution.java b/[014][Longest Common Prefix]/src/Solution.java index e5f1606..c7fd1ef 100644 --- a/[014][Longest Common Prefix]/src/Solution.java +++ b/[014][Longest Common Prefix]/src/Solution.java @@ -29,36 +29,31 @@ public String longestCommonPrefix(String[] strs) { return ""; } - int min = Integer.MAX_VALUE; // ¼̵ַij + // ¼̵ַij + int min = Integer.MAX_VALUE; // Ҷַij + String result = ""; for (String str : strs) { - if (str == null) { - return null; + if (str == null || str.length() == 0) { + return ""; } if (min > str.length()) { min = str.length(); + result = str; } } - int i; // ¼ǰ׺ַ - boolean flag; - for (i = 0; i < min; i++) { - flag = true; - for (int j = 1; j < strs.length; j++) { - if (strs[0].charAt(i) != strs[j].charAt(i)) { - flag = false; - break; + for (String s: strs) { + for (int i = 0; i < result.length(); i++) { + if (result.charAt(i) != s.charAt(i)) { + result = result.substring(0, i); } } - - if (!flag) { - break; - } } - return strs[0].substring(0, i); + return result; } } diff --git a/[014][Longest Common Prefix]/src/Solution2.java b/[014][Longest Common Prefix]/src/Solution2.java new file mode 100644 index 0000000..17eb282 --- /dev/null +++ b/[014][Longest Common Prefix]/src/Solution2.java @@ -0,0 +1,65 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 16:19 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + /** + *
+     * ԭ
+     * Write a function to find the longest common prefix string amongst an array of strings.
+     *
+     * Ŀ
+     * дһҳһִеĹǰ׺
+     *
+     * ˼·
+     * һҳСַȻַַҳ̵ǰ׺
+     * 
+ * + * @param strs + * @return + */ + public String longestCommonPrefix(String[] strs) { + if (strs == null) { + return null; + } + + if (strs.length == 0) { + return ""; + } + + // ¼̵ַij + int min = Integer.MAX_VALUE; + + // Ҷַij + for (String str : strs) { + + if (str == null) { + return null; + } + + if (min > str.length()) { + min = str.length(); + } + } + + int i; // ¼ǰ׺ַ + boolean flag; + for (i = 0; i < min; i++) { + flag = true; + for (int j = 1; j < strs.length; j++) { + if (strs[0].charAt(i) != strs[j].charAt(i)) { + flag = false; + break; + } + } + + if (!flag) { + break; + } + } + + return strs[0].substring(0, i); + } +} diff --git a/[019][Remove Nth Node From End Of List]/src/Solution.java b/[019][Remove Nth Node From End Of List]/src/Solution.java index 7c004d0..fb5db12 100644 --- a/[019][Remove Nth Node From End Of List]/src/Solution.java +++ b/[019][Remove Nth Node From End Of List]/src/Solution.java @@ -53,6 +53,7 @@ public ListNode removeNthFromEnd(ListNode head, int n) { } pb.next = pb.next.next; + return head; } } diff --git a/[020][Valid Parentheses]/src/Main.java b/[020][Valid Parentheses]/src/Main.java new file mode 100644 index 0000000..4fda8c6 --- /dev/null +++ b/[020][Valid Parentheses]/src/Main.java @@ -0,0 +1,22 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-17 14:46 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + + Assert.assertEquals(true, solution.isValid("()")); + } + + @Test + public void test2() { + Solution solution = new Solution(); + + Assert.assertEquals(false, solution.isValid("(]")); + } +} diff --git a/[020][Valid Parentheses]/src/Solution.java b/[020][Valid Parentheses]/src/Solution.java index 67bac1f..f248985 100644 --- a/[020][Valid Parentheses]/src/Solution.java +++ b/[020][Valid Parentheses]/src/Solution.java @@ -30,66 +30,21 @@ public class Solution { */ public boolean isValid(String s) { Deque stack = new LinkedList<>(); - int index = 0; - Character top; - while (index < s.length()) { - Character c = s.charAt(index); - switch (c) { - case '(': - case '[': - case '{': - stack.addFirst(c); - break; - case ')': + final String left = "([{"; + final String right = ")]}"; - if (stack.isEmpty()) { - return false; - } + for (int index = 0; index < s.length(); index++) { + char c = s.charAt(index); - top = stack.getFirst(); - if (top == '(') { - stack.removeFirst(); - } else if (top == '[' || top == '{') { - return false; - } else { - stack.addFirst(c); - } - break; - case ']': - - if (stack.isEmpty()) { - return false; - } - - top = stack.getFirst(); - if (top == '[') { - stack.removeFirst(); - } else if (top == '(' || top == '{') { - return false; - } else { - stack.addFirst(c); - } - break; - case '}': - - if (stack.isEmpty()) { - return false; - } - - top = stack.getFirst(); - if (top == '{') { - stack.removeFirst(); - } else if (top == '[' || top == '(') { - return false; - } else { - stack.addFirst(c); - } - break; - default: + if (left.indexOf(c) > -1) { + stack.push(c); + } else { + if (stack.isEmpty() || right.indexOf(c) != left.indexOf(stack.peek())) { return false; + } else { + stack.pop(); + } } - - index++; } return stack.isEmpty(); diff --git a/[020][Valid Parentheses]/src/Solution2.java b/[020][Valid Parentheses]/src/Solution2.java new file mode 100644 index 0000000..84aaaa5 --- /dev/null +++ b/[020][Valid Parentheses]/src/Solution2.java @@ -0,0 +1,97 @@ +import java.util.Deque; +import java.util.LinkedList; + +/** + * Author: + * Date: 2015-08-21 + * Time: 16:32 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + /** + *
+     * ԭ
+     * Given a string containing just the characters (, ), {, }, [ and ],
+     * determine if the input string is valid.
+     * The brackets must close in the correct order, () and ()[]{} are all valid
+     * but (] and ([)] are not.
+     *
+     * Ŀ
+     * һֻ(, ), {, }, [ ͡]ַ֤ǷЧġ
+     * űԣҪȷ˳
+     *
+     * ˼·
+     * һջŴдžջžջԪؿǷһţ
+     * ɾ͵Ҵһţƥֱӷؽ
+     * 
+ * + * @param s + * @return + */ + public boolean isValid(String s) { + Deque stack = new LinkedList<>(); + int index = 0; + Character top; + while (index < s.length()) { + Character c = s.charAt(index); + switch (c) { + case '(': + case '[': + case '{': + stack.addFirst(c); + break; + case ')': + + if (stack.isEmpty()) { + return false; + } + + top = stack.getFirst(); + if (top == '(') { + stack.removeFirst(); + } else if (top == '[' || top == '{') { + return false; + } else { + stack.addFirst(c); + } + break; + case ']': + + if (stack.isEmpty()) { + return false; + } + + top = stack.getFirst(); + if (top == '[') { + stack.removeFirst(); + } else if (top == '(' || top == '{') { + return false; + } else { + stack.addFirst(c); + } + break; + case '}': + + if (stack.isEmpty()) { + return false; + } + + top = stack.getFirst(); + if (top == '{') { + stack.removeFirst(); + } else if (top == '[' || top == '(') { + return false; + } else { + stack.addFirst(c); + } + break; + default: + return false; + } + + index++; + } + + return stack.isEmpty(); + } +} diff --git a/[024][Swap Nodes In Pairs]/src/Solution.java b/[024][Swap Nodes In Pairs]/src/Solution.java index 1f5afe5..780c049 100644 --- a/[024][Swap Nodes In Pairs]/src/Solution.java +++ b/[024][Swap Nodes In Pairs]/src/Solution.java @@ -25,10 +25,11 @@ public class Solution { * @return */ public ListNode swapPairs(ListNode head) { - ListNode node = new ListNode(0); // ͷ + // ͷ + ListNode node = new ListNode(0); node.next = head; - // pָµβ + // pָµβ㣬pָõĽ㣬ӵͷΪѾ ListNode p = node; ListNode tmp; diff --git a/[032][Longest Valid Parentheses]/src/Solution2.java b/[032][Longest Valid Parentheses]/src/Solution2.java new file mode 100644 index 0000000..fb9b995 --- /dev/null +++ b/[032][Longest Valid Parentheses]/src/Solution2.java @@ -0,0 +1,59 @@ +import java.util.Deque; +import java.util.LinkedList; + +/** + * Author: + * Date: 2015-06-25 + * Time: 09:12 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + /** + *
+     * Given a string containing just the characters '(' and ')',
+     * find the length of the longest valid (well-formed) parentheses substring.
+     *
+     * For "(()", the longest valid parentheses substring is "()", which has length = 2.
+     * Another example is ")()())", where the longest valid parentheses substring is "()()",
+     * which has length = 4.
+     *
+     * Ŀ⣺
+     * һַֻСźţĺϷСŵĿ
+     *
+     * ˼·
+     * ʹջʵ
+     * 
+ * + * @param s + * @return + */ + public int longestValidParentheses(String s) { + int result = 0; + int start = 0; + // ¼ŵλ + Deque m = new LinkedList<>(); + for (int i = 0; i < s.length(); ++i) { + // žͼ¼λ + if (s.charAt(i) == '(') { + m.push(i); + } + // + else if (s.charAt(i) == ')') { + // ֮ǰŶѾԣߴû + if (m.isEmpty()) { + // ǰλѾЧˣ¼һλǿʼԵλ + start = i + 1; + } else { + // ջӦ + m.pop(); + // ջΪգ˵startʼһֱƥ䣬ûֶţ + // ǣMath.max(result, i - start + 1) + // ջǿգ˵жţһŵλþm.peek() + // ƥž: Math.max(result, i - m.peek()) + result = m.isEmpty() ? Math.max(result, i - start + 1) : Math.max(result, i - m.peek()); + } + } + } + return result; + } +} diff --git a/[061][Rotate List]/src/Solution.java b/[061][Rotate List]/src/Solution.java index 5f75aba..9f4e91d 100644 --- a/[061][Rotate List]/src/Solution.java +++ b/[061][Rotate List]/src/Solution.java @@ -11,47 +11,24 @@ public ListNode rotateRight(ListNode head, int n) { return head; } - ListNode root = new ListNode(0); - root.next = head; - ListNode p = root; - ListNode q = root; - - int count = 0; - for (int i = 0; i <= n; i++) { + int length = 1; + ListNode p = head; + while (p.next != null) { p = p.next; - count++; - if (p == null) { - count--; // гͷݸ - n = n % count; // ʵҪλõλ - // Ϊ¿ʼλ׼ - i = 0; - p = head; - } + length++; } - // ҵһҪĽǰ - // qΪһҪĽǰ - while (p != null) { - p = p.next; - q = q.next; + // ҪĽڵΪheadǰһڵ + n = length - n % length; + // β + p.next = head; + for (int i = 0; i < n; i++) { + p = p.next; } - p = q; - q = root; - if (p != null && p.next != null) { // ҪλƵĽ - ListNode node; - while (p.next != null) { - // ժ - node = p.next; - p.next = node.next; - // Ͻ - node.next = q.next; - q.next = node; - q = node; // һƶĽڵ - } - } - - return root.next; + head = p.next; + p.next = null; + return head; } } diff --git a/[061][Rotate List]/src/Solution2.java b/[061][Rotate List]/src/Solution2.java new file mode 100644 index 0000000..00ca18f --- /dev/null +++ b/[061][Rotate List]/src/Solution2.java @@ -0,0 +1,62 @@ +/** + * Author: + * Date: 2015-07-21 + * Time: 18:46 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + public ListNode rotateRight(ListNode head, int n) { + + if (head == null || n < 1) { + return head; + } + + ListNode root = new ListNode(0); + root.next = head; + ListNode p = root; + ListNode q = root; + + // תλÿܱ + int count = 0; + for (int i = 0; i <= n; i++) { + p = p.next; + count++; + if (p == null) { + // гͷݸ + count--; + // ʵҪλõλ + n = n % count; + // Ϊ¿ʼλ׼ + i = 0; + p = head; + } + } + + // ҵһҪĽǰ + // qΪһҪĽǰ + while (p != null) { + p = p.next; + q = q.next; + + } + + p = q; + q = root; + // ҪλƵĽ + if (p != null && p.next != null) { + ListNode node; + while (p.next != null) { + // ժ + node = p.next; + p.next = node.next; + // Ͻ + node.next = q.next; + q.next = node; + // һƶĽڵ + q = node; + } + } + + return root.next; + } +} diff --git a/[065][Valid Number]/src/Main.java b/[065][Valid Number]/src/Main.java new file mode 100644 index 0000000..c039e9e --- /dev/null +++ b/[065][Valid Number]/src/Main.java @@ -0,0 +1,95 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-17 13:32 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + Assert.assertEquals(true, solution.isNumber("0")); + } + + @Test + public void test2() { + Solution solution = new Solution(); + Assert.assertEquals(true, solution.isNumber(" 0.1 ")); + } + + @Test + public void test3() { + Solution solution = new Solution(); + Assert.assertEquals(false, solution.isNumber("abc")); + } + + @Test + public void test4() { + Solution solution = new Solution(); + Assert.assertEquals(false, solution.isNumber("1 a")); + } + + @Test + public void test41() { + Solution solution = new Solution(); + Assert.assertEquals(true, solution.isNumber("2e10")); + } + + @Test + public void test42() { + Solution solution = new Solution(); + Assert.assertEquals(true, solution.isNumber(" -90e3 ")); + } + + @Test + public void test5() { + Solution solution = new Solution(); + Assert.assertEquals(false, solution.isNumber(" 1e")); + } + + @Test + public void test6() { + Solution solution = new Solution(); + Assert.assertEquals(false, solution.isNumber("e3")); + } + + + @Test + public void test7() { + Solution solution = new Solution(); + Assert.assertEquals(true, solution.isNumber(" 6e-1")); + } + + @Test + public void test8() { + Solution solution = new Solution(); + Assert.assertEquals(false, solution.isNumber(" 99e2.5 ")); + } + + + @Test + public void test9() { + Solution solution = new Solution(); + Assert.assertEquals(true, solution.isNumber("53.5e93")); + } + + @Test + public void test10() { + Solution solution = new Solution(); + Assert.assertEquals(false, solution.isNumber(" --6 ")); + } + + @Test + public void test11() { + Solution solution = new Solution(); + Assert.assertEquals(false, solution.isNumber("-+3")); + } + + @Test + public void test12() { + Solution solution = new Solution(); + Assert.assertEquals(false, solution.isNumber("95a54e53")); + } + +} diff --git a/[065][Valid Number]/src/Solution.java b/[065][Valid Number]/src/Solution.java new file mode 100644 index 0000000..3f6d642 --- /dev/null +++ b/[065][Valid Number]/src/Solution.java @@ -0,0 +1,100 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-17 13:20 + **/ +public class Solution { + + /** + * 序数就分别为0, 1, 2, 3, 4, 5, 6 + */ + private enum InputType { + INVALID, + SPACE, + SIGN, + DIGIT, + DOT, + EXPONENT + } + + // 状态转表 TODO 每个状态是什么意思? + private final static int[][] TRANSITION_TABLE = { + {-1, 0, 3, 1, 2, -1}, // next states for state 0 + {-1, 8, -1, 1, 4, 5}, // next states for state 1 + {-1, -1, -1, 4, -1, -1},// next states for state 2 + {-1, -1, -1, 1, 2, -1,},// next states for state 3 + {-1, 8, -1, 4, -1, 5},// next states for state 4 + {-1, -1, 6, 7, -1, -1},// next states for state 5 + {-1, -1, -1, 7, -1, -1},// next states for state 6 + {-1, 8, -1, 7, -1, -1},// next states for state 7 + {-1, 8, -1, -1, -1, -1},// next states for state 8 + }; + + /** + *
+     * Validate if a given string can be interpreted as a decimal number.
+     *
+     * Some examples:
+     * "0" => true
+     * " 0.1 " => true
+     * "abc" => false
+     * "1 a" => false
+     * "2e10" => true
+     * " -90e3   " => true
+     * " 1e" => false
+     * "e3" => false
+     * " 6e-1" => true
+     * " 99e2.5 " => false
+     * "53.5e93" => true
+     * " --6 " => false
+     * "-+3" => false
+     * "95a54e53" => false
+     *
+     * Note: It is intended for the problem statement to be ambiguous. You should gather all requirements
+     * up front before implementing one. However, here is a list of characters that can be in a valid decimal number:
+     *
+     * Numbers 0-9
+     * Exponent - "e"
+     * Positive/negative sign - "+"/"-"
+     * Decimal point - "."
+     * Of course, the context of these characters also matters in the input.
+     * 
+ * + * @param s + * @return + */ + public boolean isNumber(String s) { + int state = 0; + for (int i = 0; i < s.length(); i++) { + InputType inputType = InputType.INVALID; + if (Character.isSpaceChar(s.charAt(i))) { + inputType = InputType.SPACE; + } else if (s.charAt(i) == '+' || s.charAt(i) == '-') { + inputType = InputType.SIGN; + } else if (Character.isDigit(s.charAt(i))) { + inputType = InputType.DIGIT; + } else if (s.charAt(i) == '.') { + inputType = InputType.DOT; + } else if (s.charAt(i) == 'e' || s.charAt(i) == 'E') { + inputType = InputType.EXPONENT; + } + // Get next state from current state and input symbol + state = TRANSITION_TABLE[state][inputType.ordinal()]; + + // Invalid input + if (state == -1) { + return false; + } + } + // If the current state belongs to one of the accepting (final) states, + // then the number is valid + return state == 1 || state == 4 || state == 7 || state == 8; + } + + private boolean isDigit(char charAt) { + return charAt >= '0' && charAt <= '9'; + } + + private boolean isSpace(char charAt) { + return charAt == ' '; + } +} diff --git a/[082][Remove Duplicates From Sorted List II]/src/Solution.java b/[082][Remove Duplicates From Sorted List II]/src/Solution.java index 9a0c9a6..8e69cf6 100644 --- a/[082][Remove Duplicates From Sorted List II]/src/Solution.java +++ b/[082][Remove Duplicates From Sorted List II]/src/Solution.java @@ -26,33 +26,52 @@ public class Solution { */ public ListNode deleteDuplicates(ListNode head) { - ListNode root = new ListNode(0); // ͷ + // ͷ + ListNode root = new ListNode(0); root.next = head; ListNode p = head; - ListNode q = root; // ¼һûظԪأʼָͷ + // ¼һûظԪأʼָͷ + ListNode q = root; - int delta = 0; // Ԫظ + // Ԫظ + int delta = 0; while (p != null && p.next != null) { - if (p.val == p.next.val) { // ͬ + // ͬ + if (p.val == p.next.val) { delta++; - p = p.next; // ƶһ - } else { // 㲻ͬ - if (delta == 0) { // ֵΪp.valĽûظ - q.next = p; // ӵûиԪ - q = p; // ָһδظԪ - p = p.next; // ƶһ - } else { // ֵΪp.valĽظ - p = p.next; // ƶһԪ - q.next = p.next; // ȥظԪ - delta = 0; // ԪظΪ0 + // ƶһ + p = p.next; + } + // 㲻ͬ + else { + // ֵΪp.valĽûظ + if (delta == 0) { + // ӵûиԪ + q.next = p; + // ָһδظԪ + q = p; + // ƶһ + p = p.next; + } + // ֵΪp.valĽظ + else { + // ƶһԪ + p = p.next; + // ȥظԪ + q.next = p.next; + // ԪظΪ0 + delta = 0; } } } - if (delta != 0) { // һԪǸľȥ + // һԪǸľȥ + if (delta != 0) { q.next = null; - } else { // ûظͿӵβ + } + // ûظͿӵβ + else { q.next = p; } diff --git a/[083][Remove Duplicates From Sorted List]/src/Solution.java b/[083][Remove Duplicates From Sorted List]/src/Solution.java index abd32b4..97b28f2 100644 --- a/[083][Remove Duplicates From Sorted List]/src/Solution.java +++ b/[083][Remove Duplicates From Sorted List]/src/Solution.java @@ -26,21 +26,28 @@ public class Solution { */ public ListNode deleteDuplicates(ListNode head) { ListNode point; - ListNode tail = head; // ָ½βʼʱֻһԪأͷ + // ָ½βʼʱֻһԪأͷ + ListNode tail = head; if (head != null) { - point = head.next; // ָһͷ - while (point != null) { // һδĩβ + // ָͷһԪ + point = head.next; + // δĩβ + while (point != null) { - if (tail.val != point.val) { // βڵ㲻ͬͽͬĽڵӵtailһλ + // βڵ㲻ͬͽͬĽڵӵtailһλ + if (tail.val != point.val) { tail.next = point; - tail = tail.next; // ָβ + // ָβ + tail = tail.next; } + // ƶһλ point = point.next; } - tail.next = null; // βָ + // βָ + tail.next = null; } return head; diff --git a/[084][Largest Rectangle in Histogram]/src/Solution.java b/[084][Largest Rectangle in Histogram]/src/Solution.java new file mode 100644 index 0000000..72f516d --- /dev/null +++ b/[084][Largest Rectangle in Histogram]/src/Solution.java @@ -0,0 +1,71 @@ +import java.util.Arrays; +import java.util.Deque; +import java.util.LinkedList; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-17 15:29 + **/ +public class Solution { + /** + *
+     * Given n non-negative integers representing the histogram's bar height where the width
+     * of each bar is 1, find the area of largest rectangle in the histogram.
+     *
+     *
+     *    -
+     *   --
+     *   --
+     *   -- -
+     * - ----
+     * ------
+     * Above is a histogram where width of each bar is 1, given height = [2,1,5,6,2,3].
+     * The largest rectangle is shown in the shaded area, which has area = 10 unit.
+     *    -
+     *   ==
+     *   ==
+     *   == -
+     * - ==--
+     * --==--
+     * Example:
+     * Input: [2,1,5,6,2,3]
+     * Output: 10
+     *
+     * https://leetcode.com/problems/largest-rectangle-in-histogram/
+     * 
+ */ + public int largestRectangleArea(int[] heights) { + if (heights == null || heights.length < 1) { + return 0; + } + // 记录位置 + Deque stack = new LinkedList<>(); + + int i = 0; + int result = 0; + + // 复制数组,最后位置补0,方便计算 + int[] h = Arrays.copyOf(heights, heights.length + 1); + + while (i < h.length) { + // 之前的元素小于等于当前元素 + if (stack.isEmpty() || h[stack.peek()] <= h[i]) { + // 当前元素入栈 + stack.push(i); + i++; + } else { + // 栈顶元素位置出栈 + int t = stack.pop(); + // 高度是height[t] + // stack.isEmpty(): 说明栈里的所有元素都比height[i]大,i位置之前有i个元素,序列就是[0 ,1, ..., i-1] + // 所求的长度就是i + // stack不为空,说明计算的位置是[stack.peek(), ..., i-1] 长度 + result = Math.max(result, h[t] * (stack.isEmpty() ? i : i - stack.peek() - 1)); + } + } + + + return result; + + } +} diff --git a/[086][Partition List]/src/Solution.java b/[086][Partition List]/src/Solution.java index 1ba57eb..c241a4b 100644 --- a/[086][Partition List]/src/Solution.java +++ b/[086][Partition List]/src/Solution.java @@ -50,13 +50,15 @@ public ListNode partition(ListNode head, int x) { t2.next = null; - // ˵Сڵ + // пt1û + // t1ƶ˵Сڵ if (t1 != le) { t1.next = ge.next; head = le.next; } else { head = ge.next; } + return head; } } diff --git a/[092][Reverse Linked List II]/src/Solution.java b/[092][Reverse Linked List II]/src/Solution.java index ad51ffe..e1a7587 100644 --- a/[092][Reverse Linked List II]/src/Solution.java +++ b/[092][Reverse Linked List II]/src/Solution.java @@ -49,7 +49,8 @@ public ListNode reverseBetween(ListNode head, int m, int n) { m = 1; } - n = n - m + 1; // nΪҪĽĿ + // nΪҪĽĿ + n = n - m + 1; // ʱҪʹβ巨βĸΪn-1 for (int i = 1; i < n && q.next != null; i++) { // ΪҪβĽ diff --git a/[094][Binary Tree Inorder Traversal]/src/Solution.java b/[094][Binary Tree Inorder Traversal]/src/Solution.java index 012d8ed..c1cffb9 100644 --- a/[094][Binary Tree Inorder Traversal]/src/Solution.java +++ b/[094][Binary Tree Inorder Traversal]/src/Solution.java @@ -14,20 +14,24 @@ public List inorderTraversal(TreeNode root) { LinkedList stack = new LinkedList<>(); TreeNode node = root; + + // node1root㣬2Һ while (node != null || !stack.isEmpty()) { + // ջ while (node != null) { stack.addLast(node); node = node.left; } + // ʱջеջԪһûӵ if (!stack.isEmpty()) { + // ɾջԪ node = stack.removeLast(); result.add(node.val); + // ָҺ node = node.right; } } - - System.out.println(result); return result; } } diff --git a/[105][Construct Binary Tree From Preorder And Inorder Traversal]/src/Solution.java b/[105][Construct Binary Tree From Preorder And Inorder Traversal]/src/Solution.java index c639a9c..5922420 100644 --- a/[105][Construct Binary Tree From Preorder And Inorder Traversal]/src/Solution.java +++ b/[105][Construct Binary Tree From Preorder And Inorder Traversal]/src/Solution.java @@ -29,8 +29,7 @@ public class Solution { public TreeNode buildTree(int[] preorder, int[] inorder) { // У - if (preorder == null || inorder == null || preorder.length == 0 - || preorder.length != inorder.length) { + if (preorder == null || inorder == null || preorder.length == 0 || preorder.length != inorder.length) { return null; } return solve(preorder, 0, preorder.length - 1, inorder, 0, inorder.length - 1); @@ -53,7 +52,9 @@ public TreeNode solve(int[] preorder, int x, int y, int[] inorder, int i, int j) // ֻһԪ if (x == y) { return new TreeNode(preorder[x]); - } else if (x < y) { + } + // xܴy + else if (x < y) { // ¼ int idx = i; while (idx <= j && inorder[idx] != preorder[x]) { @@ -64,6 +65,7 @@ public TreeNode solve(int[] preorder, int x, int y, int[] inorder, int i, int j) TreeNode root = new TreeNode(inorder[idx]); // Ľ + //[i, i+1, ..., idx - 1] -> ܼidx - i int leftLength = idx - i; // if (leftLength > 0) { @@ -72,6 +74,7 @@ public TreeNode solve(int[] preorder, int x, int y, int[] inorder, int i, int j) } // Ľ + // [idx+1, idx+2, ..., j] -> ܼƣj - idx int rightLength = j - idx; if (rightLength > 0) { // x + leftLength + 1, yʼͽλ diff --git a/[138][Copy List With Random Pointer]/src/Solution.java b/[138][Copy List With Random Pointer]/src/Solution.java index 6b6df56..5501ab5 100644 --- a/[138][Copy List With Random Pointer]/src/Solution.java +++ b/[138][Copy List With Random Pointer]/src/Solution.java @@ -18,7 +18,7 @@ public class Solution { * ˼· * һƽ㣬ƵĽڴƵĽȻһ * ڶָ - * + * ָƺ * * * @param head diff --git a/[141][Linked List Cycle]/src/Solution.java b/[141][Linked List Cycle]/src/Solution.java index cee01cb..1bac274 100644 --- a/[141][Linked List Cycle]/src/Solution.java +++ b/[141][Linked List Cycle]/src/Solution.java @@ -28,6 +28,22 @@ public boolean hasCycle(ListNode head) { ListNode fast = head; ListNode slow = head; + while (fast != null && fast.next != null) { + fast = fast.next.next; + slow = slow.next; + if (slow == fast) { + return true; + } + } + + return false; + } + + public boolean hasCycle2(ListNode head) { + + ListNode fast = head; + ListNode slow = head; + while (fast != null && fast.next != null) { fast = fast.next.next; slow = slow.next; diff --git a/[143][Copy List With Random Pointer]/src/RandomListNode.java b/[143][Copy List With Random Pointer]/src/RandomListNode.java deleted file mode 100644 index fabb62e..0000000 --- a/[143][Copy List With Random Pointer]/src/RandomListNode.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 19:22 - * Declaration: All Rights Reserved !!! - */ -public class RandomListNode { - int label; - RandomListNode next, random; - - RandomListNode(int x) { - this.label = x; - } -} diff --git a/[143][Copy List With Random Pointer]/src/Solution.java b/[143][Copy List With Random Pointer]/src/Solution.java deleted file mode 100644 index 5128823..0000000 --- a/[143][Copy List With Random Pointer]/src/Solution.java +++ /dev/null @@ -1,108 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 19:21 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * A linked list is given such that each node contains an additional random pointer
-     * which could point to any node in the list or null.
-     * Return a deep copy of the list.
-     *
-     * Ŀ
-     * һһָnullĽָ룬
-     *
-     * ˼·
-     * һƽ㣬ƵĽڴƵĽȻһ
-     * ڶָ
-     * ֡ԭ͸
-     * 
- * - * @param head - * @return - */ - public RandomListNode copyRandomList(RandomListNode head) { - if (head == null) { - return null; - } - - copyNode(head); - linkRandomPointer(head); - - return splitList(head); - } - - /** - * ƽ㣬ƵĽڴƵĽȻһ - * - * @param head ͷ - */ - public void copyNode(RandomListNode head) { - // ¼ǰҪƵ - RandomListNode node = head; - while (node != null) { - // һµĽ - RandomListNode copyNode = new RandomListNode(node.label); - // 㴮ӵƵĽ󣬲Ȼɵ - copyNode.next = node.next; - node.next = copyNode; - node = copyNode.next; - } - } - - /** - * ָ - * - * @param head ͷ - */ - public void linkRandomPointer(RandomListNode head) { - // ¼ǰҪƵ - RandomListNode node = head; - while (node != null) { - // ָָijĽ - if (node.random != null) { - // nodeƽָ - node.next.random = node.random.next; - } - - // ָһƵĽ - node = node.next.next; - } - } - - /** - * ֣ԭԭװ - * - * @param head ͷ - * @return ͷ - */ - public RandomListNode splitList(RandomListNode head) { - // ͷ - RandomListNode copyHead = head.next; - // ǰıƵĽ - RandomListNode node = head; - // ǰƵĽ - RandomListNode copy; - - while (node != null) { - // ָƽ - copy = node.next; - - // node.nextָһƵĽ - node.next = copy.next; - - // һƵĽ㲻Ϊnull - if (node.next != null) { - // copy.nextָһƵĽ - copy.next = node.next.next; - } - - // nodeָһҪıƽ - node = node.next; - } - return copyHead; - } -} diff --git a/[143][Reorder List]/src/ListNode.java b/[143][Reorder List]/src/ListNode.java new file mode 100644 index 0000000..1f6cb21 --- /dev/null +++ b/[143][Reorder List]/src/ListNode.java @@ -0,0 +1,14 @@ +/** + * Author: 王俊超 + * Date: 2015-08-21 + * Time: 19:22 + * Declaration: All Rights Reserved !!! + */ +public class ListNode { + int val; + ListNode next; + + ListNode(int x) { + val = x; + } +} diff --git a/[143][Reorder List]/src/Solution.java b/[143][Reorder List]/src/Solution.java new file mode 100644 index 0000000..8c489cf --- /dev/null +++ b/[143][Reorder List]/src/Solution.java @@ -0,0 +1,78 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 19:21 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Given a singly linked list L: L0L1Ln-1Ln,
+     * reorder it to: L0LnL1Ln-1L2Ln-2
+     *
+     * You may not modify the values in the list's nodes, only nodes itself may be changed.
+     *
+     * Example 1:
+     *
+     * Given 1->2->3->4, reorder it to 1->4->2->3.
+     * Example 2:
+     *
+     * Given 1->2->3->4->5, reorder it to 1->5->2->4->3.
+     *
+     * ˼·
+     * 1ҵм
+     * 2㣬ͽм֮в֣
+     *
+     * 
+ * @param head + */ + public void reorderList(ListNode head) { + if (head == null || head.next == null) { + return; + } + + ListNode root = new ListNode(-1); + root.next = head; + ListNode fast = head; + // мǰ + ListNode slow = root; + + while (fast != null && fast.next != null) { + fast = fast.next.next; + slow = slow.next; + } + + // ˵żڵ + if (fast == null) { + root.next = slow.next; + slow.next = null; + + } else { // + slow = slow.next; + root.next = slow.next; + slow.next = null; + } + + // һҪͷ巨 + fast = root.next; + ListNode tmp; + // 벿 + while (fast.next != null) { + tmp = fast.next; + fast.next = tmp.next; + tmp.next = root.next; + root.next = tmp; + } + + slow = head; + fast = root.next; + + while (fast != null) { + tmp = fast.next; + fast.next = slow.next; + slow.next = fast; + slow = slow.next.next; + fast = tmp; + } + } +} diff --git a/[145][Binary Tree Postorder Traversal]/src/Solution.java b/[145][Binary Tree Postorder Traversal]/src/Solution.java index 0bba339..2adec07 100644 --- a/[145][Binary Tree Postorder Traversal]/src/Solution.java +++ b/[145][Binary Tree Postorder Traversal]/src/Solution.java @@ -66,8 +66,8 @@ public List postorderTraversal(TreeNode root) { // ȡջԪأɾ curr = deque.getLast(); if ((curr.left == null && curr.right == null) // ǰԪ - // prev == null && curr.left == prevǰֻѾ - // prev == null && curr.right == prevǰѾ + // prev != null && curr.left == prevǰֻѾ + // prev != null && curr.right == prevǰѾ || (prev != null && (curr.left == prev || curr.right == prev))) { // ɾջԪ curr = deque.removeLast(); @@ -78,11 +78,9 @@ public List postorderTraversal(TreeNode root) { } else { // δ꣬ǿջ - if (curr.right != null) { deque.addLast(curr.right); } - if (curr.left != null) { deque.addLast(curr.left); } diff --git a/[146][LRU Cache]/src/LRUCache.java b/[146][LRU Cache]/src/LRUCache.java new file mode 100644 index 0000000..3d26ca7 --- /dev/null +++ b/[146][LRU Cache]/src/LRUCache.java @@ -0,0 +1,69 @@ +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-17 17:34 + **/ +public class LRUCache extends LinkedHashMap { + /** + *
+     * Design and implement a data structure for Least Recently Used (LRU) cache.
+     * It should support the following operations: get and put.
+     *
+     * get(key) - Get the value (will always be positive) of the key if the key exists
+     * in the cache, otherwise return -1.
+     * put(key, value) - Set or insert the value if the key is not already present. When
+     * the cache reached its capacity, it should invalidate the least recently used item
+     * before inserting a new item.
+     *
+     * The cache is initialized with a positive capacity.
+     *
+     * Follow up:
+     * Could you do both operations in O(1) time complexity?
+     *
+     * Example:
+     *
+     * LRUCache cache = new LRUCache( 2  );// capacity
+     *
+     * cache.put(1,1);
+     * cache.put(2,2);
+     * cache.get(1);       // returns 1
+     * cache.put(3,3);    // evicts key 2
+     * cache.get(2);       // returns -1 (not found)
+     * cache.put(4,4);    // evicts key 1
+     * cache.get(1);       // returns -1 (not found)
+     * cache.get(3);       // returns 3
+     * cache.get(4);       // returns 4
+     * 
+ * + * @param capacity + */ + + private int capacity; + + + public LRUCache(int capacity) { + super(capacity, 0.75F, true); + this.capacity = capacity; + } + + public int get(int key) { + Integer value = super.get(key); + if (value == null) { + return -1; + } else { + return value; + } + } + + public void put(int key, int value) { + super.put(key, value); + } + + + @Override + protected boolean removeEldestEntry(Map.Entry eldest) { + return size() > capacity; + } +} diff --git a/[146][LRU Cache]/src/Main.java b/[146][LRU Cache]/src/Main.java new file mode 100644 index 0000000..61644cc --- /dev/null +++ b/[146][LRU Cache]/src/Main.java @@ -0,0 +1,26 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-17 17:41 + **/ +public class Main { + + @Test + public void test1() { + LRUCache cache = new LRUCache(2); + + cache.put(1, 1); + cache.put(2, 2); + cache.get(1); // returns 1 + cache.put(3, 3); // evicts key 2 + cache.get(2); // returns -1 (not found) + Assert.assertEquals(-1, cache.get(2)); + cache.put(4, 4); // evicts key 1 + cache.get(1); // returns -1 (not found) + Assert.assertEquals(-1, cache.get(1)); + cache.get(3); // returns 3 + cache.get(4); // returns 4 + } +} diff --git a/[206][Reverse Linked List]/src/Solution.java b/[206][Reverse Linked List]/src/Solution.java index 202cdf3..3799055 100644 --- a/[206][Reverse Linked List]/src/Solution.java +++ b/[206][Reverse Linked List]/src/Solution.java @@ -24,7 +24,10 @@ public ListNode reverseList(ListNode head) { head = nextNode; } - return root.next; + head = root.next; + root.next = null; + + return head; } /** From e15dd02296607544c83c55901aa5266cd9b12398 Mon Sep 17 00:00:00 2001 From: Wang-Jun-Chao Date: Tue, 18 Jun 2019 10:54:07 +0800 Subject: [PATCH 045/108] commit --- .../src/Solution.java | 28 +++++----- .../src/Solution2.java | 51 +++++++++++++++++++ .../src/Solution.java | 5 +- 3 files changed, 67 insertions(+), 17 deletions(-) create mode 100644 [096][Unique Binary Search Trees]/src/Solution2.java diff --git a/[096][Unique Binary Search Trees]/src/Solution.java b/[096][Unique Binary Search Trees]/src/Solution.java index b2ee0d9..ab0f547 100644 --- a/[096][Unique Binary Search Trees]/src/Solution.java +++ b/[096][Unique Binary Search Trees]/src/Solution.java @@ -7,19 +7,19 @@ public class Solution { /** * Given n, how many structurally unique BST's (binary search trees) that store values 1...n? - * + *

* For example, * Given n = 3, there are a total of 5 unique BST's. - * 1 3 3 2 1 - * \ / / / \ \ - * 3 2 1 1 3 2 - * / / \ \ + * 1 3 3 2 1 + * \ / / / \ \ + * 3 2 1 1 3 2 + * / / \ \ * 2 1 2 3 - * + *

* ƹʽ - * f(k)*f(n-1-k)f(k)ʾk㣬е״f(k)f(n-1-k)ʾn-1-k - * - * f(n) = 2*f(n-1) + f(1)*f(n-2) + f(2)f(n-3) + f(3)f(n-4) + ... +f(n-2)*f(1) + * f(0) = 1 + * f(1) = 1 + * f(i) = f(0)f(i-1) + f(1)f(i-1) + ... + f(i-1)f(0) * * @param n * @return @@ -27,22 +27,20 @@ public class Solution { public int numTrees(int n) { if (n <= 0) { - return 0; + return 1; } else if (n == 1) { return 1; } int[] result = new int[n + 1]; - result[0] = 0; + result[0] = 1; result[1] = 1; // f(2)...f(n) for (int i = 2; i <= n; i++) { - // f(i) - result[i] = 2 * result[i - 1]; - for (int j = 1; j <= i - 1 ; j++) { - result[i] += result[j]*result[i - 1 -j]; + for (int j = 1; j <= i; j++) { + result[i] += result[j - 1] * result[i - j]; } } diff --git a/[096][Unique Binary Search Trees]/src/Solution2.java b/[096][Unique Binary Search Trees]/src/Solution2.java new file mode 100644 index 0000000..753d48c --- /dev/null +++ b/[096][Unique Binary Search Trees]/src/Solution2.java @@ -0,0 +1,51 @@ +/** + * Author: + * Date: 2015-06-18 + * Time: 17:36 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + /** + * Given n, how many structurally unique BST's (binary search trees) that store values 1...n? + * + * For example, + * Given n = 3, there are a total of 5 unique BST's. + * 1 3 3 2 1 + * \ / / / \ \ + * 3 2 1 1 3 2 + * / / \ \ + * 2 1 2 3 + * + * ƹʽ + * f(k)*f(n-1-k)f(k)ʾk㣬е״f(k)f(n-1-k)ʾn-1-k + * + * f(n) = 2*f(n-1) + f(1)*f(n-2) + f(2)f(n-3) + f(3)f(n-4) + ... +f(n-2)*f(1) + * + * @param n + * @return + */ + public int numTrees(int n) { + + if (n <= 0) { + return 1; + } else if (n == 1) { + return 1; + } + + int[] result = new int[n + 1]; + result[0] = 0; + result[1] = 1; + + + // f(2)...f(n) + for (int i = 2; i <= n; i++) { + // f(i) + result[i] = 2 * result[i - 1]; + for (int j = 1; j <= i - 1 ; j++) { + result[i] += result[j]*result[i - 1 -j]; + } + + } + return result[n]; + } +} diff --git a/[106][Construct Binary Tree From Inorder And Postorder Traversal]/src/Solution.java b/[106][Construct Binary Tree From Inorder And Postorder Traversal]/src/Solution.java index 351a346..83cccad 100644 --- a/[106][Construct Binary Tree From Inorder And Postorder Traversal]/src/Solution.java +++ b/[106][Construct Binary Tree From Inorder And Postorder Traversal]/src/Solution.java @@ -31,8 +31,7 @@ public class Solution { public TreeNode buildTree(int[] inorder, int[] postorder) { // - if (inorder == null || postorder == null || inorder.length == 0 - || inorder.length != postorder.length) { + if (inorder == null || postorder == null || inorder.length == 0 || inorder.length != postorder.length) { return null; } @@ -70,6 +69,7 @@ else if (x < y) { } // ǿգ + // [x, x+1, ..., idx-1] -> ܼ idx-x int leftLength = idx - x; if (leftLength > 0) { // i, i + leftLength - 1ǰʼλ @@ -77,6 +77,7 @@ else if (x < y) { } // ǿգ + // [idx+1, idx+2, ..., y] -> ܼ y-idx int rightLength = y - idx; if (rightLength > 0) { // i + leftLength, j - 1ǰʼλ From 557c1e5001aae3cd40f6cd6af2f5ecd615d43425 Mon Sep 17 00:00:00 2001 From: Wang-Jun-Chao Date: Tue, 18 Jun 2019 20:46:39 +0800 Subject: [PATCH 046/108] commit --- .../src/Solution.java | 6 +- [088][Merge Sorted Array]/src/Solution.java | 19 +++--- .../src/Solution.java | 42 +++--------- .../src/Solution2.java | 64 +++++++++++++++++++ 4 files changed, 87 insertions(+), 44 deletions(-) create mode 100644 [111][Minimum Depth Of Binary Tree]/src/Solution2.java diff --git a/[021][Merge Two Sorted Lists]/src/Solution.java b/[021][Merge Two Sorted Lists]/src/Solution.java index 15b4d85..c3281f8 100644 --- a/[021][Merge Two Sorted Lists]/src/Solution.java +++ b/[021][Merge Two Sorted Lists]/src/Solution.java @@ -40,11 +40,13 @@ public ListNode mergeTwoLists(ListNode l1, ListNode l2) { l2 = l2.next; } - tail = tail.next; // ƶµβ + // ƶµβ + tail = tail.next; } tail.next = (l1 != null ? l1 : l2); - return head.next; // headһڵǵһݽ + // headһڵǵһݽ + return head.next; } } diff --git a/[088][Merge Sorted Array]/src/Solution.java b/[088][Merge Sorted Array]/src/Solution.java index 1a4970c..d25ea04 100644 --- a/[088][Merge Sorted Array]/src/Solution.java +++ b/[088][Merge Sorted Array]/src/Solution.java @@ -23,28 +23,29 @@ public class Solution { * λֵǰƶһλãٽͬIJֱеԪشꡣ * * - * @param A + * @param arr * @param m - * @param B + * @param brr * @param n */ - public void merge(int A[], int m, int B[], int n) { + public void merge(int arr[], int m, int brr[], int n) { int pa = m - 1; int pb = n - 1; int index = m + n - 1; while (pa >= 0 && pb >= 0) { - if (A[pa] >= B[pb]) { - A[index--] = A[pa--]; + if (arr[pa] >= brr[pb]) { + arr[index--] = arr[pa--]; } else { - A[index--] = B[pb--]; + arr[index--] = brr[pb--]; } } - while (pb >= 0) { // ˵paһΪ0 - A[index--] = B[pb--]; + // ˵paһΪ0 + while (pb >= 0) { + arr[index--] = brr[pb--]; } - // pa >= 0˵[0, pa]ûнжϣΪ[0, pa]AУԲҪƶ + // pa >= 0˵[0, pa]ûнжϣΪ[0, pa]arrУԲҪƶ } } diff --git a/[111][Minimum Depth Of Binary Tree]/src/Solution.java b/[111][Minimum Depth Of Binary Tree]/src/Solution.java index beab356..836fb49 100644 --- a/[111][Minimum Depth Of Binary Tree]/src/Solution.java +++ b/[111][Minimum Depth Of Binary Tree]/src/Solution.java @@ -5,9 +5,6 @@ * Declaration: All Rights Reserved !!! */ public class Solution { - private int min = Integer.MAX_VALUE; // ¼С - private int cur = 0; // iǰij - /** *

      * ԭ
@@ -26,39 +23,18 @@ public class Solution {
      * @return
      */
     public int minDepth(TreeNode root) {
-
-        depth(root);
-        return min;
+        return minDepth(root, false);
     }
 
-    /**
-     * 
-     *
-     * @param node ǰ
-     */
-    private void depth(TreeNode node) {
-
-        if (node == null) {
-            min = cur;
-            return;
+    public int minDepth(TreeNode root, boolean hasBrother) {
+        if (root == null) {
+            // ԼΪnullֵܲΪnullϲӽ㣬˵ǰûҵС
+            // ûֵܣ˵ǰʱֲСѾҵ
+            return hasBrother ? Integer.MAX_VALUE : 0;
         }
 
-        cur++; // ǰIJμ1
-        // Ҷڵ㣬·ȼ¼СС
-        if (node.left == null && node.right == null && cur < min) {
-            min = cur; // Сֵ
-        }
-        // 
-        if (node.left != null) {
-            depth(node.left);
-        }
-
-        // 
-        if (node.right != null) {
-            depth(node.right);
-        }
-
-        cur--; // ԭ
-
+        return 1 + Math.min(minDepth(root.left, root.right != null),
+                minDepth(root.right, root.left != null));
     }
+
 }
diff --git a/[111][Minimum Depth Of Binary Tree]/src/Solution2.java b/[111][Minimum Depth Of Binary Tree]/src/Solution2.java
new file mode 100644
index 0000000..6dfcd46
--- /dev/null
+++ b/[111][Minimum Depth Of Binary Tree]/src/Solution2.java	
@@ -0,0 +1,64 @@
+/**
+ * Author: 
+ * Date: 2015-08-21
+ * Time: 18:51
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution2 {
+    private int min = Integer.MAX_VALUE; // ¼С
+    private int cur = 0; // iǰij
+
+    /**
+     * 
+     * ԭ
+     * Given a binary tree, find its minimum depth.
+     * The minimum depth is the number of nodes along the shortest path from
+     * the root node down to the nearest leaf node.
+     *
+     * Ŀ
+     * һСȡ
+     *
+     * ˼·
+     * бҳСȡ
+     * 
+ * + * @param root + * @return + */ + public int minDepth(TreeNode root) { + + depth(root); + return min; + } + + /** + * + * + * @param node ǰ + */ + private void depth(TreeNode node) { + + if (node == null) { + min = cur; + return; + } + + cur++; // ǰIJμ1 + // Ҷڵ㣬·ȼ¼СС + if (node.left == null && node.right == null && cur < min) { + min = cur; // Сֵ + } + // + if (node.left != null) { + depth(node.left); + } + + // + if (node.right != null) { + depth(node.right); + } + + cur--; // ԭ + + } +} From 9a732aa8eab237a60c951a7219811898304be6c1 Mon Sep 17 00:00:00 2001 From: Wang-Jun-Chao Date: Wed, 19 Jun 2019 21:47:25 +0800 Subject: [PATCH 047/108] commit --- .idea/modules.xml | 2 + .../src/Main.java | 14 ++ .../src/Solution.java | 61 +++------ .../src/Solution2.java | 95 ++++++++++++++ [041][First Missing Positive]/src/Main.java | 20 +++ .../src/Solution.java | 24 ++++ [046][Permutations]/src/Solution.java | 24 ++-- [047][Permutations II]/src/Main.java | 14 ++ [047][Permutations II]/src/Solution.java | 9 +- [074][Search A 2D Matrix]/src/Main.java | 16 +++ [074][Search A 2D Matrix]/src/Solution.java | 38 +----- [074][Search A 2D Matrix]/src/Solution2.java | 88 +++++++++++++ [075][Sort Colors]/src/Main.java | 33 +++++ [075][Sort Colors]/src/Solution.java | 59 +++++---- [075][Sort Colors]/src/Solution2.java | 71 ++++++++++ [077][Combinations]/src/Main.java | 15 +++ [077][Combinations]/src/Solution.java | 43 ++---- [077][Combinations]/src/Solution2.java | 80 ++++++++++++ [078][Subsets]/src/Main.java | 16 +++ [078][Subsets]/src/Solution.java | 88 +++---------- [078][Subsets]/src/Solution2.java | 123 ++++++++++++++++++ [078][Subsets]/src/Solution3.java | 86 ++++++++++++ [090][Subsets II]/src/Main.java | 23 ++++ [090][Subsets II]/src/Solution.java | 66 ++++++++++ [148][Sort List]/src/ListNode.java | 14 ++ [148][Sort List]/src/Solution.java | 84 ++++++++++++ 26 files changed, 992 insertions(+), 214 deletions(-) create mode 100644 [017][Letter Combinations Of A Phon Number/src/Main.java create mode 100644 [017][Letter Combinations Of A Phon Number/src/Solution2.java create mode 100644 [041][First Missing Positive]/src/Main.java create mode 100644 [047][Permutations II]/src/Main.java create mode 100644 [074][Search A 2D Matrix]/src/Main.java create mode 100644 [074][Search A 2D Matrix]/src/Solution2.java create mode 100644 [075][Sort Colors]/src/Main.java create mode 100644 [075][Sort Colors]/src/Solution2.java create mode 100644 [077][Combinations]/src/Main.java create mode 100644 [077][Combinations]/src/Solution2.java create mode 100644 [078][Subsets]/src/Main.java create mode 100644 [078][Subsets]/src/Solution2.java create mode 100644 [078][Subsets]/src/Solution3.java create mode 100644 [090][Subsets II]/src/Main.java create mode 100644 [090][Subsets II]/src/Solution.java create mode 100644 [148][Sort List]/src/ListNode.java create mode 100644 [148][Sort List]/src/Solution.java diff --git a/.idea/modules.xml b/.idea/modules.xml index 0654150..c3d1766 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -86,6 +86,7 @@ + @@ -131,6 +132,7 @@ + diff --git a/[017][Letter Combinations Of A Phon Number/src/Main.java b/[017][Letter Combinations Of A Phon Number/src/Main.java new file mode 100644 index 0000000..d120486 --- /dev/null +++ b/[017][Letter Combinations Of A Phon Number/src/Main.java @@ -0,0 +1,14 @@ +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-19 19:26 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + + System.out.println(solution.letterCombinations("23")); + } +} diff --git a/[017][Letter Combinations Of A Phon Number/src/Solution.java b/[017][Letter Combinations Of A Phon Number/src/Solution.java index 1f26d6f..d9ec4a0 100644 --- a/[017][Letter Combinations Of A Phon Number/src/Solution.java +++ b/[017][Letter Combinations Of A Phon Number/src/Solution.java @@ -9,7 +9,7 @@ */ public class Solution { - private String[] map = { + private final static String[] S = { "abc", "def", "ghi", @@ -19,11 +19,7 @@ public class Solution { "tuv", "wxyz", }; - private List result; // 洢ս - private char[] chars; // ȥ01ַĽ - private char[] curResult; // 洢м - private int end = 0; // ַеĵһδʹõλ - private int handle = 0; // ǰǵڼַ + /** *
@@ -49,47 +45,30 @@ public class Solution {
      * @return
      */
     public List letterCombinations(String digits) {
-        result = new LinkedList<>();
-
-        if (digits != null && digits.length() > 0) {
-
-            chars = digits.toCharArray();
+        List result = new LinkedList<>();
 
-            // ַдȥ01
-            // ҵһ01λ
-            while (end < digits.length() && chars[end] != '0' && chars[end] != '1') {
-                end++;
-            }
-
-            handle = end + 1;
-            while (handle < chars.length) {
-                if (chars[handle] != '0' && chars[handle] != '1') {
-                    chars[end] = chars[handle];
-                    end++;
-                }
-                handle++;
-            }
+        if (digits == null || digits.length() < 1) {
+            return result;
+        }
 
-            curResult = new char[end];
-            // whileendΪЧַij
-            handle = 0; // ָһЧַλ
+        StringBuilder builder = new StringBuilder();
+        letterCombinations(digits, 0, builder, result);
 
-            letterCombinations();
-        }
         return result;
     }
 
-    private void letterCombinations() {
-        if (handle >= end) {
-            result.add(new String(curResult));
-        } else {
-            int num = chars[handle] - '2';
-            for (int i = 0; i < map[num].length(); i++) {
-                curResult[handle] = map[num].charAt(i);
-                handle++;
-                letterCombinations();
-                handle--;
-            }
+    private void letterCombinations(String digits, int index, StringBuilder builder, List result) {
+        if (index == digits.length()) {
+            result.add(builder.toString());
+            return;
+        }
+
+        String t = S[digits.charAt(index) - '2'];
+
+        for (int i = 0; i < t.length(); i++) {
+            builder.append(t.charAt(i));
+            letterCombinations(digits, index + 1, builder, result);
+            builder.deleteCharAt(builder.length() - 1);
         }
     }
 }
diff --git a/[017][Letter Combinations Of A Phon Number/src/Solution2.java b/[017][Letter Combinations Of A Phon Number/src/Solution2.java
new file mode 100644
index 0000000..4dc400d
--- /dev/null
+++ b/[017][Letter Combinations Of A Phon Number/src/Solution2.java	
@@ -0,0 +1,95 @@
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Author: 
+ * Date: 2015-08-21
+ * Time: 16:23
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution2 {
+
+    private String[] map = {
+            "abc",
+            "def",
+            "ghi",
+            "jkl",
+            "mno",
+            "pqrs",
+            "tuv",
+            "wxyz",
+    };
+    private List result;    // 洢ս
+    private char[] chars;           // ȥ01ַĽ
+    private char[] curResult;       // 洢м
+    private int end = 0;            // ַеĵһδʹõλ
+    private int handle = 0;         // ǰǵڼַ
+
+    /**
+     * 
+     * ԭ
+     * Given a digit string, return all possible letter combinations that the number could represent.
+     * A mapping of digit to letters (just like on the telephone buttons) is given below.
+     *
+     * Input:Digit string "23"
+     * Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].
+     *
+     * Note: Although the above answer is in lexicographical order, your answer
+     * could be in any order you want.
+     *
+     * Ŀ
+     * һִַϣֵַӳͼʾ
+     * ע⣺ Ľַ˳еģκ˳򷵻ؽ
+     *
+     * ˼·
+     * һ鱣ֵֺӳϵִ룬ҵӦַϽ
+     * 
+ * + * @param digits + * @return + */ + public List letterCombinations(String digits) { + result = new LinkedList<>(); + + if (digits != null && digits.length() > 0) { + + chars = digits.toCharArray(); + + // ַдȥ01 + // ҵһ01λ + while (end < digits.length() && chars[end] != '0' && chars[end] != '1') { + end++; + } + + handle = end + 1; + while (handle < chars.length) { + if (chars[handle] != '0' && chars[handle] != '1') { + chars[end] = chars[handle]; + end++; + } + handle++; + } + + curResult = new char[end]; + // whileendΪЧַij + handle = 0; // ָһЧַλ + + letterCombinations(); + } + return result; + } + + private void letterCombinations() { + if (handle >= end) { + result.add(new String(curResult)); + } else { + int num = chars[handle] - '2'; + for (int i = 0; i < map[num].length(); i++) { + curResult[handle] = map[num].charAt(i); + handle++; + letterCombinations(); + handle--; + } + } + } +} diff --git a/[041][First Missing Positive]/src/Main.java b/[041][First Missing Positive]/src/Main.java new file mode 100644 index 0000000..3a25e0e --- /dev/null +++ b/[041][First Missing Positive]/src/Main.java @@ -0,0 +1,20 @@ +import org.junit.Assert; +import org.junit.Test; + +import java.util.Arrays; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-19 14:38 + **/ +public class Main { + + @Test + public void test1() { + Solution solution = new Solution(); + int[] arr = {1, 4, 3, 3, 2}; + int result = solution.firstMissingPositive(arr); + System.out.println(Arrays.toString(arr)); + Assert.assertEquals(5, result); + } +} diff --git a/[041][First Missing Positive]/src/Solution.java b/[041][First Missing Positive]/src/Solution.java index 7fb1d3c..b551643 100644 --- a/[041][First Missing Positive]/src/Solution.java +++ b/[041][First Missing Positive]/src/Solution.java @@ -3,9 +3,33 @@ * @time: 2018-09-28 15:18 **/ public class Solution { + /** + *
+     * Given an unsorted integer array, find the smallest missing positive integer.
+     *
+     * Example 1:
+     *
+     * Input: [1,2,0]
+     * Output: 3
+     * Example 2:
+     *
+     * Input: [3,4,-1,1]
+     * Output: 2
+     * Example 3:
+     *
+     * Input: [7,8,9,11,12]
+     * Output: 1
+     *
+     * 本质上是桶排序(bucket sort),每当A[i]!= i+1 的时候,将A[i] 与A[A[i]-1] 交换,
+     * 直到无法交换为止,终止条件是A[i]== A[A[i]-1]。
+     * 
+ * @param nums + * @return + */ public int firstMissingPositive(int[] nums) { int n = nums.length; for (int i = 0; i < n; i++) { + // nums[i] == nums[nums[i] - 1] 说明出现了两个同样的元素或者两个是同一个元素 while (nums[i] > 0 && nums[i] <= n && nums[i] != nums[nums[i] - 1]) { swap(nums, i, nums[i] - 1); } diff --git a/[046][Permutations]/src/Solution.java b/[046][Permutations]/src/Solution.java index 317ceda..b08b4bb 100644 --- a/[046][Permutations]/src/Solution.java +++ b/[046][Permutations]/src/Solution.java @@ -1,4 +1,5 @@ import java.util.ArrayList; +import java.util.Collections; import java.util.LinkedList; import java.util.List; @@ -39,28 +40,27 @@ public List> permute(int[] num) { return result; } - private void permute(int i, int[] num) { + private void permute(int i, int[] nums) { - if (i == num.length) { + if (i == nums.length) { List l = new ArrayList<>(); - for (int n : num) { + for (int n : nums) { l.add(n); } - result.add(l); } else { - for (int j = i; j < num.length; j++) { - swap(num, j, i); - permute(i + 1, num); - swap(num, j, i); + for (int j = i; j < nums.length; j++) { + swap(nums, j, i); + permute(i + 1, nums); + swap(nums, j, i); } } } - private void swap(int[] A, int x, int y) { - int tmp = A[x]; - A[x] = A[y]; - A[y] = tmp; + private void swap(int[] nums, int x, int y) { + int tmp = nums[x]; + nums[x] = nums[y]; + nums[y] = tmp; } } diff --git a/[047][Permutations II]/src/Main.java b/[047][Permutations II]/src/Main.java new file mode 100644 index 0000000..050363c --- /dev/null +++ b/[047][Permutations II]/src/Main.java @@ -0,0 +1,14 @@ +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-19 18:01 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + int[] nums = {1, 1, 2}; + System.out.println(solution.permuteUnique(nums)); + } +} diff --git a/[047][Permutations II]/src/Solution.java b/[047][Permutations II]/src/Solution.java index ff6c4b5..859454a 100644 --- a/[047][Permutations II]/src/Solution.java +++ b/[047][Permutations II]/src/Solution.java @@ -24,6 +24,13 @@ public List> permuteUnique(int[] nums) { return res; } + /** + * 时间复杂度:n! + * @param nums + * @param used + * @param list + * @param res + */ private void permuteUnique(int[] nums, boolean[] used, List list, List> res) { if (list.size() == nums.length) { res.add(new ArrayList<>(list)); @@ -36,7 +43,7 @@ private void permuteUnique(int[] nums, boolean[] used, List list, List< continue; } - // 第不个字符与前一个字符相等,并且第i-1个字符没有使用,说明此次不应该交换 + // 第i个字符与前一个字符相等,并且第i-1个字符没有使用,说明此次不应该交换 if (i > 0 && nums[i - 1] == nums[i] && !used[i - 1]) { continue; } diff --git a/[074][Search A 2D Matrix]/src/Main.java b/[074][Search A 2D Matrix]/src/Main.java new file mode 100644 index 0000000..4206b6b --- /dev/null +++ b/[074][Search A 2D Matrix]/src/Main.java @@ -0,0 +1,16 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-19 16:11 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + + int[][] matrix = {{1, 3}}; + Assert.assertEquals(true, solution.searchMatrix(matrix, 3)); + } +} diff --git a/[074][Search A 2D Matrix]/src/Solution.java b/[074][Search A 2D Matrix]/src/Solution.java index 65e7be7..4942ee4 100644 --- a/[074][Search A 2D Matrix]/src/Solution.java +++ b/[074][Search A 2D Matrix]/src/Solution.java @@ -41,45 +41,19 @@ public boolean searchMatrix(int[][] matrix, int target) { int row = matrix.length; int column = matrix[0].length; int low = 0; - int high = row - 1; - int mid = 0; + int high = row * column - 1; + int mid; // ҽڵ while (low <= high) { mid = low + (high - low) / 2; - - if (target < matrix[mid][column - 1]) { - high = mid - 1; - } else if (target > matrix[mid][column - 1]) { - low = mid + 1; - } else { + int value = matrix[mid / column][mid % column]; + if (value == target) { return true; - } - } - - // ڵλ - int targetRow = mid; - if (matrix[mid][column - 1] < target) { - targetRow++; - } - - // Ŀг޽ - if (targetRow >= row) { - return false; - } - - low = 0; - high = column - 1; - // ڵУҵtrueûзfalse - while (low <= high) { - mid = low + (high - low) / 2; - - if (target < matrix[targetRow][mid]) { - high = mid - 1; - } else if (target > matrix[targetRow][mid]) { + } else if (value < target) { low = mid + 1; } else { - return true; + high = mid - 1; } } diff --git a/[074][Search A 2D Matrix]/src/Solution2.java b/[074][Search A 2D Matrix]/src/Solution2.java new file mode 100644 index 0000000..0a5ed46 --- /dev/null +++ b/[074][Search A 2D Matrix]/src/Solution2.java @@ -0,0 +1,88 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 19:36 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + /** + *
+     * ԭ
+     * Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:
+     * Integers in each row are sorted from left to right.
+     * The first integer of each row is greater than the last integer of the previous row.
+     * For example,
+     * Consider the following matrix:Given target = 3, return true.
+     *
+     * [
+     *  [1,   3,  5,  7],
+     *  [10, 11, 16, 20],
+     *  [23, 30, 34, 50]
+     * ]
+     *
+     * Ŀ
+     * һάʵһ㷨ھʵֿkھk
+     * ʣÿһÿһжźģÿһеĵһһеһ
+     *
+     * ˼·
+     * ⷨһö鿴㷨ҵڵУö㷨ڵСҵͷtrue򷵻false
+     * 
+ * + * @param matrix + * @param target + * @return + */ + public boolean searchMatrix(int[][] matrix, int target) { + + if (matrix == null || matrix.length == 0 || matrix[0].length == 0) { + return false; + } + + int row = matrix.length; + int column = matrix[0].length; + int low = 0; + int high = row - 1; + int mid = 0; + + // ҽڵ + while (low <= high) { + mid = low + (high - low) / 2; + + if (target < matrix[mid][column - 1]) { + high = mid - 1; + } else if (target > matrix[mid][column - 1]) { + low = mid + 1; + } else { + return true; + } + } + + // ڵλ + int targetRow = mid; + if (matrix[mid][column - 1] < target) { + targetRow++; + } + + // Ŀг޽ + if (targetRow >= row) { + return false; + } + + low = 0; + high = column - 1; + // ڵУҵtrueûзfalse + while (low <= high) { + mid = low + (high - low) / 2; + + if (target < matrix[targetRow][mid]) { + high = mid - 1; + } else if (target > matrix[targetRow][mid]) { + low = mid + 1; + } else { + return true; + } + } + + return false; + } +} diff --git a/[075][Sort Colors]/src/Main.java b/[075][Sort Colors]/src/Main.java new file mode 100644 index 0000000..a29defe --- /dev/null +++ b/[075][Sort Colors]/src/Main.java @@ -0,0 +1,33 @@ +import org.junit.Test; + +import java.util.Arrays; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-19 14:52 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + int[] colors = {2, 0, 2, 1, 1, 0}; + solution.sortColors(colors); + System.out.println(Arrays.toString(colors)); + } + + @Test + public void test2() { + Solution solution = new Solution(); + int[] colors = {2, 0, 1}; + solution.sortColors(colors); + System.out.println(Arrays.toString(colors)); + } + + @Test + public void test3() { + Solution solution = new Solution(); + int[] colors = {0}; + solution.sortColors(colors); + System.out.println(Arrays.toString(colors)); + } +} diff --git a/[075][Sort Colors]/src/Solution.java b/[075][Sort Colors]/src/Solution.java index 639fd06..2f930cc 100644 --- a/[075][Sort Colors]/src/Solution.java +++ b/[075][Sort Colors]/src/Solution.java @@ -21,45 +21,48 @@ public class Solution { * ע⣺ʹÿ⺯ * * ˼· - * ɨ裬¼1ĸĺ͡ɨԵó1Ŀt2Ŀ(sum-t)/2 - * Եó0ĿӸ012Ŀٶֵ + * һֱ012ֵĴٽ鸳ֵ *
* - * @param A + * @param nums */ - public void sortColors(int[] A) { + public void sortColors(int[] nums) { - if (A == null) { + if (nums == null) { return; } - int count = 0; // ͳ1ĸ - int sum = 0; // ͳĺ + int[] count = new int[3]; - for (int i : A) { - if (i == 1) { - count++; - } - - sum += i; - } - - sum = (sum - count) / 2; // 2Ŀ - - count = A.length - count - sum; // 1ʼֵλ - - sum = A.length - sum; // 2ʼֵλ - - for (int i = 0; i < count; i++) { - A[i] = 0; + for (int n : nums) { + count[n]++; } - for (int i = count; i < sum; i++) { - A[i] = 1; + int start = 0; + int end = 0; + for (int i = 0; i < count.length; i++) { + if (i == 0) { + start = 0; + } else { + start += count[i - 1]; + } + end += count[i]; + for (int j = start; j < end; j++) { + nums[j] = i; + } } - for (int i = sum; i < A.length; i++) { - A[i] = 2; - } + // ϶ĸĽ +// for (int i = 0; i < count[0]; i++) { +// nums[i] = 0; +// } +// +// for (int i = count[0]; i < count[0] + count[1]; i++) { +// nums[i] = 1; +// } +// +// for (int i = count[0] + count[1]; i < nums.length; i++) { +// nums[i] = 2; +// } } } diff --git a/[075][Sort Colors]/src/Solution2.java b/[075][Sort Colors]/src/Solution2.java new file mode 100644 index 0000000..ac7b270 --- /dev/null +++ b/[075][Sort Colors]/src/Solution2.java @@ -0,0 +1,71 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 19:37 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + /** + *
+     * ԭ
+     * Given an array with n objects colored red, white or blue, sort them so that objects
+     * of the same color are adjacent, with the colors in the order red, white and blue.
+     * Here, we will use the integers 0, 1, and 2 to represent the color red, white,
+     * and blue respectively.
+     * Note:
+     * You are not suppose to use the librarys sort function for this problem.
+     *
+     * Ŀ
+     * һ飬Ǻɫɫɫɫ򣬺죬ף
+     * ʹ012ֱ죬ף
+     * ע⣺ʹÿ⺯
+     *
+     * ˼·
+     * ɨ裬¼1ĸĺ͡ɨԵó1Ŀt2Ŀ(sum-t)/2
+     * Եó0ĿӸ012Ŀٶֵ
+     * 
+ * + * @param A + */ + public void sortColors(int[] A) { + + if (A == null) { + return; + } + + // ͳ1ĸ + int count = 0; + + // ͳĺ + int sum = 0; + + for (int i : A) { + if (i == 1) { + count++; + } + + sum += i; + } + + // 2Ŀ + sum = (sum - count) / 2; + + // 1ʼֵλ + count = A.length - count - sum; + + // 2ʼֵλ + sum = A.length - sum; + + for (int i = 0; i < count; i++) { + A[i] = 0; + } + + for (int i = count; i < sum; i++) { + A[i] = 1; + } + + for (int i = sum; i < A.length; i++) { + A[i] = 2; + } + } +} diff --git a/[077][Combinations]/src/Main.java b/[077][Combinations]/src/Main.java new file mode 100644 index 0000000..e4021a1 --- /dev/null +++ b/[077][Combinations]/src/Main.java @@ -0,0 +1,15 @@ +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-19 19:04 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + + System.out.println(solution.combine(4, 2)); + } + +} diff --git a/[077][Combinations]/src/Solution.java b/[077][Combinations]/src/Solution.java index 0e2f1db..7d055e8 100644 --- a/[077][Combinations]/src/Solution.java +++ b/[077][Combinations]/src/Solution.java @@ -1,4 +1,3 @@ -import java.util.ArrayList; import java.util.LinkedList; import java.util.List; @@ -9,8 +8,6 @@ * Declaration: All Rights Reserved !!! */ public class Solution { - private List> result; - private List l; /** *
@@ -32,7 +29,7 @@ public class Solution {
      * nk1-nkϡ
      *
      * ˼·
-     * õݹη⣬롣
+     * ʹùŻ㷨
      * 
* * @param n @@ -40,40 +37,26 @@ public class Solution { * @return */ public List> combine(int n, int k) { - result = new LinkedList<>(); + List> result = new LinkedList<>(); + List current = new LinkedList<>(); - if (n > 0 && k > 0 && n >= k) { - l = new LinkedList<>(); - combine(1, n, k); - } + dfs(1, n, k, current, result); return result; } - /** - * - * - * @param start ѡʼλ - * @param end ѡĽλ - * @param num [start, end]ѡĿ - */ - private void combine(int start, int end, int num) { - - if (num == 0) { - List tmp = new ArrayList<>(); - for (Integer i : l) { - tmp.add(i); - } - - result.add(tmp); + private void dfs(int start, int end, int k, List current, List> result) { + if (k == current.size()) { + result.add(new LinkedList<>(current)); return; } - int endFirst = end - num + 1; // һѡֵ - for (int i = start; i <= endFirst; i++) { - l.add(i); - combine(i + 1, end, num - 1); - l.remove(new Integer(i)); + for (int i = start; i <= end; i++) { + current.add(i); + dfs(i + 1, end, k, current, result); + current.remove((Integer) i); } } + + } diff --git a/[077][Combinations]/src/Solution2.java b/[077][Combinations]/src/Solution2.java new file mode 100644 index 0000000..8e1fb2f --- /dev/null +++ b/[077][Combinations]/src/Solution2.java @@ -0,0 +1,80 @@ +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-08-21 + * Time: 19:39 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + private List> result; + private List l; + + /** + *
+     * ԭ
+     * Given two integers n and k, return all possible combinations of k numbers out of 1  n.
+     * For example,
+     * If n = 4 and k = 2, a solution is:
+     *
+     * [
+     *  [2,4],
+     *  [3,4],
+     *  [2,3],
+     *  [1,2],
+     *  [1,3],
+     *  [1,4],
+     * ]
+     *
+     * Ŀ
+     * nk1-nkϡ
+     *
+     * ˼·
+     * õݹη⣬롣
+     * 
+ * + * @param n + * @param k + * @return + */ + public List> combine(int n, int k) { + result = new LinkedList<>(); + + if (n > 0 && k > 0 && n >= k) { + l = new LinkedList<>(); + combine(1, n, k); + } + + return result; + } + + /** + * + * + * @param start ѡʼλ + * @param end ѡĽλ + * @param num [start, end]ѡĿ + */ + private void combine(int start, int end, int num) { + + if (num == 0) { + List tmp = new ArrayList<>(); + for (Integer i : l) { + tmp.add(i); + } + + result.add(tmp); + return; + } + + // һѡֵ + int endFirst = end - num + 1; + for (int i = start; i <= endFirst; i++) { + l.add(i); + combine(i + 1, end, num - 1); + l.remove(new Integer(i)); + } + } +} diff --git a/[078][Subsets]/src/Main.java b/[078][Subsets]/src/Main.java new file mode 100644 index 0000000..9295524 --- /dev/null +++ b/[078][Subsets]/src/Main.java @@ -0,0 +1,16 @@ +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-19 16:27 + **/ +public class Main { + @Test + public void test1() { + int[] nums = {1, 2, 3}; + + Solution solution = new Solution(); + + System.out.println(solution.subsets(nums)); + } +} diff --git a/[078][Subsets]/src/Solution.java b/[078][Subsets]/src/Solution.java index a270ee0..9db75ec 100644 --- a/[078][Subsets]/src/Solution.java +++ b/[078][Subsets]/src/Solution.java @@ -1,4 +1,4 @@ -import java.util.ArrayList; +import java.util.Arrays; import java.util.LinkedList; import java.util.List; @@ -9,10 +9,6 @@ * Declaration: All Rights Reserved !!! */ public class Solution { - private List> result; - private List l; - private int[] set; - private int num; // setлҪѡԪظ /** *
@@ -39,85 +35,37 @@ public class Solution {
      * һֵͬ飬Ӽ
      *
      * ˼·
-     * ȶеԪؽȻõݹη⡣
+     * ȶеԪؽȻʹùŻ
      * 
* - * @param S + * @param nums * @return */ - public List> subsets(int[] S) { - result = new LinkedList<>(); - - if (S != null) { - l = new ArrayList<>(); - + public List> subsets(int[] nums) { + List> result = new LinkedList<>(); + List curr = new LinkedList<>(); + if (nums != null) { // S - quickSort(S, 0, S.length - 1); - - set = S; - for (int i = 0; i <= S.length; i++) { - num = i; - subset(0); - } + Arrays.sort(nums); + dfs(nums, 0, result, curr); } - // գӿ - set = null; - l = null; - return result; } - /** - * ԪظnumӼ - * - * @param start ʣҪѡnumԪУһС± - */ - public void subset(int start) { - if (num == 0) { - List tmp = new ArrayList<>(); - for (Integer i : l) { - tmp.add(i); - } + private void dfs(int[] nums, int index, List> result, List curr) { - result.add(tmp); - return; - } - int endFirst = set.length - num; // ʣҪѡnumԪУһ± - for (int i = start; i <= endFirst; i++) { - l.add(set[i]); - num--; - subset(i + 1); - num++; - l.remove(new Integer(set[i])); - } - } + // ӵУ˵һµĽ + result.add(new LinkedList<>(curr)); - private void quickSort(int[] arr, int lo, int hi) { - if (lo < hi) { - int mid = getMid(arr, lo, hi); - quickSort(arr, lo, mid - 1); - quickSort(arr, mid + 1, hi); - } - } - private int getMid(int[] arr, int lo, int hi) { - int tmp = arr[lo]; - while (lo < hi) { - while (lo < hi && arr[hi] > tmp) { - hi--; - } - arr[lo] = arr[hi]; - - while (lo < hi && arr[lo] < tmp) { - lo++; - } - - arr[hi] = arr[lo]; + for (int j = index; j < nums.length; j++) { + // Ԫ + curr.add(nums[j]); + dfs(nums, j + 1, result, curr); + // ԭ + curr.remove((Integer) nums[j]); } - - arr[lo] = tmp; - return lo; } } diff --git a/[078][Subsets]/src/Solution2.java b/[078][Subsets]/src/Solution2.java new file mode 100644 index 0000000..ce86399 --- /dev/null +++ b/[078][Subsets]/src/Solution2.java @@ -0,0 +1,123 @@ +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-08-21 + * Time: 19:41 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + private List> result; + private List l; + private int[] set; + private int num; // setлҪѡԪظ + + /** + *
+     * ԭ
+     * Given a set of distinct integers, nums, return all possible subsets.
+     * Note:
+     * Elements in a subset must be in non-descending order.
+     * The solution set must not contain duplicate subsets.
+     * For example,
+     * If nums = [1,2,3], a solution is:
+     *
+     * [
+     *  [3],
+     *  [1],
+     *  [2],
+     *  [1,2,3],
+     *  [1,3],
+     *  [2,3],
+     *  [1,2],
+     *  []
+     * ]
+     *
+     * Ŀ
+     * һֵͬ飬Ӽ
+     *
+     * ˼·
+     * ȶеԪؽȻõݹη⡣
+     * 
+ * + * @param S + * @return + */ + public List> subsets(int[] S) { + result = new LinkedList<>(); + + if (S != null) { + l = new ArrayList<>(); + + // S + quickSort(S, 0, S.length - 1); + + set = S; + for (int i = 0; i <= S.length; i++) { + num = i; + subset(0); + } + } + + // գӿ + set = null; + l = null; + + return result; + } + + /** + * ԪظnumӼ + * + * @param start ʣҪѡnumԪУһС± + */ + public void subset(int start) { + if (num == 0) { + List tmp = new ArrayList<>(); + for (Integer i : l) { + tmp.add(i); + } + + result.add(tmp); + return; + } + + int endFirst = set.length - num; // ʣҪѡnumԪУһ± + for (int i = start; i <= endFirst; i++) { + l.add(set[i]); + num--; + subset(i + 1); + num++; + l.remove(new Integer(set[i])); + } + } + + private void quickSort(int[] arr, int lo, int hi) { + if (lo < hi) { + int mid = getMid(arr, lo, hi); + quickSort(arr, lo, mid - 1); + quickSort(arr, mid + 1, hi); + } + } + + private int getMid(int[] arr, int lo, int hi) { + int tmp = arr[lo]; + while (lo < hi) { + while (lo < hi && arr[hi] > tmp) { + hi--; + } + arr[lo] = arr[hi]; + + while (lo < hi && arr[lo] < tmp) { + lo++; + } + + arr[hi] = arr[lo]; + } + + arr[lo] = tmp; + return lo; + } +} diff --git a/[078][Subsets]/src/Solution3.java b/[078][Subsets]/src/Solution3.java new file mode 100644 index 0000000..4ad1f20 --- /dev/null +++ b/[078][Subsets]/src/Solution3.java @@ -0,0 +1,86 @@ +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-08-21 + * Time: 19:41 + * Declaration: All Rights Reserved !!! + */ +public class Solution3 { + + /** + *
+     * ԭ
+     * Given a set of distinct integers, nums, return all possible subsets.
+     * Note:
+     * Elements in a subset must be in non-descending order.
+     * The solution set must not contain duplicate subsets.
+     * For example,
+     * If nums = [1,2,3], a solution is:
+     *
+     * [
+     *  [3],
+     *  [1],
+     *  [2],
+     *  [1,2,3],
+     *  [1,3],
+     *  [2,3],
+     *  [1,2],
+     *  []
+     * ]
+     *
+     * Ŀ
+     * һֵͬ飬Ӽ
+     *
+     * ˼·
+     * ȶеԪؽȻõݹη⡣
+     * 
+ * + * @param nums + * @return + */ + public List> subsets(int[] nums) { + List> result = new LinkedList<>(); + List curr = new LinkedList<>(); + if (nums != null) { + + // S + Arrays.sort(nums); + // iʾӼԪظ + for (int i = 0; i <= nums.length; i++) { + subset(nums, 0, i, result, curr); + } + } + + return result; + } + + /** + * ԪnӼ + * + * @param nums Ԫؼ + * @param idx ȡԪصʼλ + * @param n Ԫظ + * @param result + * @param curr ʱ + */ + private void subset(int[] nums, int idx, int n, List> result, List curr) { + + // Ѿĩβˣ˵һ + if (n == 0) { + result.add(new LinkedList<>(curr)); + return; + } + + // ûд꣬ݹ鴦һԪ + for (int i = idx; i < nums.length - n + 1; i++) { + curr.add(nums[i]); + subset(nums, i + 1, n - 1, result, curr); + curr.remove((Integer) nums[i]); + } + } + + +} diff --git a/[090][Subsets II]/src/Main.java b/[090][Subsets II]/src/Main.java new file mode 100644 index 0000000..c656a4c --- /dev/null +++ b/[090][Subsets II]/src/Main.java @@ -0,0 +1,23 @@ +import org.junit.Test; + +import java.util.Arrays; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-19 17:33 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + int[] nums = {1, 2, 2}; + System.out.println(solution.subsetsWithDup(nums)); + } + + @Test + public void test2() { + Solution solution = new Solution(); + int[] nums = {1, 2, 2}; + System.out.println(solution.subsetsWithDup(nums)); + } +} diff --git a/[090][Subsets II]/src/Solution.java b/[090][Subsets II]/src/Solution.java new file mode 100644 index 0000000..7593613 --- /dev/null +++ b/[090][Subsets II]/src/Solution.java @@ -0,0 +1,66 @@ +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-19 16:43 + **/ +public class Solution { + + /** + *
+     * Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set).
+     *
+     * Note: The solution set must not contain duplicate subsets.
+     *
+     * Example:
+     *
+     * Input: [1,2,2]
+     * Output:
+     * [
+     *   [2],
+     *   [1],
+     *   [1,2,2],
+     *   [2,2],
+     *   [1,2],
+     *   []
+     * ]
+     * 
+ * + * @param nums + * @return + */ + public List> subsetsWithDup(int[] nums) { + List> result = new LinkedList<>(); + List curr = new LinkedList<>(); + if (nums != null) { + // 对S进行排序处理 + Arrays.sort(nums); + dfs(nums, 0, result, curr); + } + + return result; + } + + private void dfs(int[] nums, int index, List> result, List curr) { + + + // 添加到结果中,说明有一种新的结产生 + result.add(new LinkedList<>(curr)); + + + for (int j = index; j < nums.length; j++) { + // 在当前可选择的范围内,相同的只能选择一次 + if (j > index && nums[j] == nums[j - 1]) { + continue; + } + + // 添加元素 + curr.add(nums[j]); + dfs(nums, j + 1, result, curr); + // 还原 + curr.remove((Integer) nums[j]); + } + } +} diff --git a/[148][Sort List]/src/ListNode.java b/[148][Sort List]/src/ListNode.java new file mode 100644 index 0000000..0c7f1c1 --- /dev/null +++ b/[148][Sort List]/src/ListNode.java @@ -0,0 +1,14 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 19:24 + * Declaration: All Rights Reserved !!! + */ +public class ListNode { + int val; + ListNode next; + + ListNode(int v) { + val = v; + } +} diff --git a/[148][Sort List]/src/Solution.java b/[148][Sort List]/src/Solution.java new file mode 100644 index 0000000..7cbd141 --- /dev/null +++ b/[148][Sort List]/src/Solution.java @@ -0,0 +1,84 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-19 14:28 + **/ +public class Solution { + /** + *
+     * Sort a linked list in O(n log n) time using constant space complexity.
+     *
+     * Example 1:
+     *
+     * Input: 4->2->1->3
+     * Output: 1->2->3->4
+     * Example 2:
+     *
+     * Input: -1->5->3->4->0
+     * Output: -1->0->3->4->5
+     *
+     * 使用链表的归并排序可以解决
+     * 
+ * + * @param head + * @return + */ + public ListNode sortList(ListNode head) { + + if (head == null || head.next == null) { + return head; + } + return mergeSort(head); + } + + private ListNode mergeSort(ListNode head) { + + if (head == null || head.next == null) { + return head; + } + + ListNode p = head; + ListNode q = head; + // 记录前驱 + ListNode r = null; + + // 将链表分害割成两半 + while (p != null && p.next != null) { + p = p.next.next; + r = q; + q = q.next; + } + + r.next = null; + + // 两个链接分别进行排序 + ListNode h1 = mergeSort(head); + ListNode h2 = mergeSort(q); + + return merge(h1, h2); + } + + private ListNode merge(ListNode l1, ListNode l2) { + + ListNode head = new ListNode(0); + ListNode p = head; + while (l1 != null && l2 != null) { + if (l1.val <= l2.val) { + p.next = l1; + l1 = l1.next; + } else { + p.next = l2; + l2 = l2.next; + } + + p = p.next; + } + + if (l1 != null) { + p.next = l1; + } else { + p.next = l2; + } + + return head.next; + } +} From 33a0feca618e46724204b5dd2a265660a589876b Mon Sep 17 00:00:00 2001 From: Wang-Jun-Chao Date: Fri, 21 Jun 2019 21:43:12 +0800 Subject: [PATCH 048/108] commit --- .idea/modules.xml | 2 + [062][Unique Paths]/src/Solution.java | 4 +- [126][Word Ladder II]/src/Main.java | 51 ++++ [126][Word Ladder II]/src/Solution.java | 130 +++++++++ [126][Word Ladder II]/src/Solution2.java | 113 ++++++++ [126][Word Ladder II]/src/Solution3.java | 128 +++++++++ [127][Word Ladder]/src/Main.java | 21 ++ [127][Word Ladder]/src/Solution.java | 51 +++- [130][Surrounded Regions]/src/Main.java | 25 +- [130][Surrounded Regions]/src/Solution.java | 229 ++-------------- [130][Surrounded Regions]/src/Solution2.java | 258 ++++++++++++++++++ [131][Palindrome Partitioning]/src/Main.java | 15 + .../src/Solution.java | 70 +++++ 13 files changed, 880 insertions(+), 217 deletions(-) create mode 100644 [126][Word Ladder II]/src/Main.java create mode 100644 [126][Word Ladder II]/src/Solution.java create mode 100644 [126][Word Ladder II]/src/Solution2.java create mode 100644 [126][Word Ladder II]/src/Solution3.java create mode 100644 [127][Word Ladder]/src/Main.java create mode 100644 [130][Surrounded Regions]/src/Solution2.java create mode 100644 [131][Palindrome Partitioning]/src/Main.java create mode 100644 [131][Palindrome Partitioning]/src/Solution.java diff --git a/.idea/modules.xml b/.idea/modules.xml index c3d1766..bf707cd 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -115,10 +115,12 @@ + + diff --git a/[062][Unique Paths]/src/Solution.java b/[062][Unique Paths]/src/Solution.java index d379e68..43be774 100644 --- a/[062][Unique Paths]/src/Solution.java +++ b/[062][Unique Paths]/src/Solution.java @@ -26,10 +26,10 @@ public class Solution { * * ˼· * ͵Ķ̬滮⣬ʹö̬滮ķ⡣ - * һ*nA + * һm*nA * AеԪС * 1x=0y=0ʱA[x][y] = 1 - * 2x>=1y>=1ʱA[\x][\y] = A[x-1][y]+A[\x][y-1] + * 2x>=1y>=1ʱA[x][y] = A[x-1][y]+A[x][y-1] * 3ĽA[m-1][n-1] *
* diff --git a/[126][Word Ladder II]/src/Main.java b/[126][Word Ladder II]/src/Main.java new file mode 100644 index 0000000..356b93f --- /dev/null +++ b/[126][Word Ladder II]/src/Main.java @@ -0,0 +1,51 @@ +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-20 08:17 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + String beginWord = "hit"; + String endWord = "cog"; + List wordList = new LinkedList<>(Arrays.asList("hot", "dot", "dog", "lot", "log", "cog")); + System.out.println(solution.findLadders(beginWord, endWord, wordList)); + } + + @Test + public void test2() { + Solution solution = new Solution(); + String beginWord = "hot"; + String endWord = "dog"; + List wordList = new LinkedList<>(Arrays.asList("hot","dog","dot")); + System.out.println(solution.findLadders(beginWord, endWord, wordList)); + } + + @Test + public void test3() { + Solution solution = new Solution(); + String beginWord = "cet"; + String endWord = "ism"; + String[] words = {"kid","tag","pup","ail","tun","woo","erg","luz","brr","gay","sip","kay","per","val","mes","ohs","now","boa","cet","pal","bar","die","war","hay","eco","pub","lob","rue","fry","lit","rex","jan","cot","bid","ali","pay","col","gum","ger","row","won","dan","rum","fad","tut","sag","yip","sui","ark","has","zip","fez","own","ump","dis","ads","max","jaw","out","btu","ana","gap","cry","led","abe","box","ore","pig","fie","toy","fat","cal","lie","noh","sew","ono","tam","flu","mgm","ply","awe","pry","tit","tie","yet","too","tax","jim","san","pan","map","ski","ova","wed","non","wac","nut","why","bye","lye","oct","old","fin","feb","chi","sap","owl","log","tod","dot","bow","fob","for","joe","ivy","fan","age","fax","hip","jib","mel","hus","sob","ifs","tab","ara","dab","jag","jar","arm","lot","tom","sax","tex","yum","pei","wen","wry","ire","irk","far","mew","wit","doe","gas","rte","ian","pot","ask","wag","hag","amy","nag","ron","soy","gin","don","tug","fay","vic","boo","nam","ave","buy","sop","but","orb","fen","paw","his","sub","bob","yea","oft","inn","rod","yam","pew","web","hod","hun","gyp","wei","wis","rob","gad","pie","mon","dog","bib","rub","ere","dig","era","cat","fox","bee","mod","day","apr","vie","nev","jam","pam","new","aye","ani","and","ibm","yap","can","pyx","tar","kin","fog","hum","pip","cup","dye","lyx","jog","nun","par","wan","fey","bus","oak","bad","ats","set","qom","vat","eat","pus","rev","axe","ion","six","ila","lao","mom","mas","pro","few","opt","poe","art","ash","oar","cap","lop","may","shy","rid","bat","sum","rim","fee","bmw","sky","maj","hue","thy","ava","rap","den","fla","auk","cox","ibo","hey","saw","vim","sec","ltd","you","its","tat","dew","eva","tog","ram","let","see","zit","maw","nix","ate","gig","rep","owe","ind","hog","eve","sam","zoo","any","dow","cod","bed","vet","ham","sis","hex","via","fir","nod","mao","aug","mum","hoe","bah","hal","keg","hew","zed","tow","gog","ass","dem","who","bet","gos","son","ear","spy","kit","boy","due","sen","oaf","mix","hep","fur","ada","bin","nil","mia","ewe","hit","fix","sad","rib","eye","hop","haw","wax","mid","tad","ken","wad","rye","pap","bog","gut","ito","woe","our","ado","sin","mad","ray","hon","roy","dip","hen","iva","lug","asp","hui","yak","bay","poi","yep","bun","try","lad","elm","nat","wyo","gym","dug","toe","dee","wig","sly","rip","geo","cog","pas","zen","odd","nan","lay","pod","fit","hem","joy","bum","rio","yon","dec","leg","put","sue","dim","pet","yaw","nub","bit","bur","sid","sun","oil","red","doc","moe","caw","eel","dix","cub","end","gem","off","yew","hug","pop","tub","sgt","lid","pun","ton","sol","din","yup","jab","pea","bug","gag","mil","jig","hub","low","did","tin","get","gte","sox","lei","mig","fig","lon","use","ban","flo","nov","jut","bag","mir","sty","lap","two","ins","con","ant","net","tux","ode","stu","mug","cad","nap","gun","fop","tot","sow","sal","sic","ted","wot","del","imp","cob","way","ann","tan","mci","job","wet","ism","err","him","all","pad","hah","hie","aim","ike","jed","ego","mac","baa","min","com","ill","was","cab","ago","ina","big","ilk","gal","tap","duh","ola","ran","lab","top","gob","hot","ora","tia","kip","han","met","hut","she","sac","fed","goo","tee","ell","not","act","gil","rut","ala","ape","rig","cid","god","duo","lin","aid","gel","awl","lag","elf","liz","ref","aha","fib","oho","tho","her","nor","ace","adz","fun","ned","coo","win","tao","coy","van","man","pit","guy","foe","hid","mai","sup","jay","hob","mow","jot","are","pol","arc","lax","aft","alb","len","air","pug","pox","vow","got","meg","zoe","amp","ale","bud","gee","pin","dun","pat","ten","mob"}; +// List wordList = new ArrayList<>(); +// wordList.addAll(Arrays.asList(words)); + System.out.println(solution.findLadders(beginWord, endWord, Arrays.asList(words))); + } + + @Test + public void test4() { + Solution solution = new Solution(); + String beginWord = "hit"; + String endWord = "cog"; + List wordList = new LinkedList<>(Arrays.asList("hot", "dot", "dog", "lot", "log")); + System.out.println(solution.findLadders(beginWord, endWord, wordList)); + } +} diff --git a/[126][Word Ladder II]/src/Solution.java b/[126][Word Ladder II]/src/Solution.java new file mode 100644 index 0000000..bc6ce38 --- /dev/null +++ b/[126][Word Ladder II]/src/Solution.java @@ -0,0 +1,130 @@ +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; +import java.util.Set; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-20 08:42 + **/ +public class Solution { + /** + *
+     * Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:
+     *
+     * Only one letter can be changed at a time
+     * Each transformed word must exist in the word list. Note that beginWord is not a transformed word.
+     * Note:
+     *
+     * Return an empty list if there is no such transformation sequence.
+     * All words have the same length.
+     * All words contain only lowercase alphabetic characters.
+     * You may assume no duplicates in the word list.
+     * You may assume beginWord and endWord are non-empty and are not the same.
+     * Example 1:
+     *
+     * Input:
+     * beginWord = "hit",
+     * endWord = "cog",
+     * wordList = ["hot","dot","dog","lot","log","cog"]
+     *
+     * Output:
+     * [
+     *   ["hit","hot","dot","dog","cog"],
+     *   ["hit","hot","lot","log","cog"]
+     * ]
+     * Example 2:
+     *
+     * Input:
+     * beginWord = "hit"
+     * endWord = "cog"
+     * wordList = ["hot","dot","dog","lot","log"]
+     *
+     * Output: []
+     *
+     * Explanation: The endWord "cog" is not in wordList, therefore no possible transformation.
+     *
+     * 使用了图的遍历
+     * https://www.cnblogs.com/splash/p/4102786.html
+     * 
+ * + * @param beginWord + * @param endWord + * @param wordList + * @return + */ + HashMap> nodeSet = new HashMap<>(); + + public List> findLadders(String start, String end, List wordList) { + Set wordDict = new HashSet<>(wordList); + + List> result = new ArrayList>(); + + if (!wordDict.contains(end)) { + return result; + } + + Queue q = new LinkedList(); + HashSet hs = new HashSet(); + HashMap dist = new HashMap(); + q.add(start); + nodeSet.put(start, new ArrayList()); + nodeSet.put(end, new ArrayList()); + dist.put(start, 1); + + while (!q.isEmpty()) { + String temp = q.poll(); + int l = dist.get(temp); + hs.add(temp); + for (int i = 0; i < temp.length(); i++) { + for (char c = 'a'; c <= 'z'; c++) { + if (temp.charAt(i) == c) { + continue; + } + StringBuilder sb = new StringBuilder(temp); + sb.setCharAt(i, c); + String next = sb.toString(); + if (next.equals(end)) { + if (!dist.containsKey(end)) { + dist.put(end, l + 1); + nodeSet.get(end).add(temp); + } else if (dist.get(end) == l + 1) { + nodeSet.get(end).add(temp); + } + } else if (wordDict.contains(next) && !hs.contains(next)) { + if (!dist.containsKey(next)) { + q.add(next); + dist.put(next, l + 1); + ArrayList arr = new ArrayList(); + arr.add(temp); + nodeSet.put(next, arr); + } else if (dist.get(next) == l + 1) { + nodeSet.get(next).add(temp); + } + } + } + } + } + List path = new ArrayList(); + path.add(end); + + collect(start, result, path, nodeSet.get(end)); + return result; + } + + public void collect(String start, List> re, List path, ArrayList prevNodes) { + for (int i = 0; i < prevNodes.size(); i++) { + path.add(0, prevNodes.get(i)); + if (prevNodes.get(i).equals(start)) { + List pathCopy = new ArrayList(path); + re.add(pathCopy); + } else { + collect(start, re, path, nodeSet.get(prevNodes.get(i))); + } + path.remove(0); + } + } +} diff --git a/[126][Word Ladder II]/src/Solution2.java b/[126][Word Ladder II]/src/Solution2.java new file mode 100644 index 0000000..7315d8d --- /dev/null +++ b/[126][Word Ladder II]/src/Solution2.java @@ -0,0 +1,113 @@ +import java.util.Deque; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-20 08:42 + **/ +public class Solution2 { + /** + *
+     * Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:
+     *
+     * Only one letter can be changed at a time
+     * Each transformed word must exist in the word list. Note that beginWord is not a transformed word.
+     * Note:
+     *
+     * Return an empty list if there is no such transformation sequence.
+     * All words have the same length.
+     * All words contain only lowercase alphabetic characters.
+     * You may assume no duplicates in the word list.
+     * You may assume beginWord and endWord are non-empty and are not the same.
+     * Example 1:
+     *
+     * Input:
+     * beginWord = "hit",
+     * endWord = "cog",
+     * wordList = ["hot","dot","dog","lot","log","cog"]
+     *
+     * Output:
+     * [
+     *   ["hit","hot","dot","dog","cog"],
+     *   ["hit","hot","lot","log","cog"]
+     * ]
+     * Example 2:
+     *
+     * Input:
+     * beginWord = "hit"
+     * endWord = "cog"
+     * wordList = ["hot","dot","dog","lot","log"]
+     *
+     * Output: []
+     *
+     * Explanation: The endWord "cog" is not in wordList, therefore no possible transformation.
+     *
+     * 使用了深度优化遍历方案,会超时
+     * 
+ * + * @param beginWord + * @param endWord + * @param wordList + * @return + */ + public List> findLadders(String beginWord, String endWord, List wordList) { + Set wordDict = new HashSet<>(wordList); + List> result = new LinkedList<>(); + Deque current = new LinkedList<>(); + findLadders(beginWord, endWord, wordDict, current, result); + for(List r: result) { + r.add(0, beginWord); + } + return result; + } + + private void findLadders(String beginWord, String endWord, Set wordDict, Deque current, List> result) { + + if (beginWord.equals(endWord)) { + + // 还没有结果,或者有的最优解,就添加结果 + if (result.isEmpty() || result.get(0).size() == current.size()) { + result.add(new LinkedList<>(current)); + } + // 当前解不是最优解,记录最优化解 + else if (result.get(0).size() > current.size()) { + result.clear(); + result.add(new LinkedList<>(current)); + } + + return; + } + + // 已经找到至少一个可能的最优解,当前还没有找到最优化解,但是转换次数已经等于目前找到的最优化解的次数, + // 目前的方案一定不存在最优化解 + if (!result.isEmpty() && current.size() >= result.get(0).size()) { + return; + } + + char[] chars = beginWord.toCharArray(); + + for (int i = 0; i < chars.length; i++) { + for (char ch = 'a'; ch <= 'z'; ch++) { + char temp = chars[i]; + chars[i] = ch; + String s = new String(chars); + + if (wordDict.contains(s) ) { + wordDict.remove(s); + current.add(s); + + findLadders(s, endWord, wordDict, current, result); + // 还原 + wordDict.add(s); + current.remove(s); + } + + // 还原 + chars[i] = temp; + } + } + } +} diff --git a/[126][Word Ladder II]/src/Solution3.java b/[126][Word Ladder II]/src/Solution3.java new file mode 100644 index 0000000..906bc48 --- /dev/null +++ b/[126][Word Ladder II]/src/Solution3.java @@ -0,0 +1,128 @@ +import java.util.Deque; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-20 08:42 + **/ +public class Solution3 { + /** + *
+     * Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:
+     *
+     * Only one letter can be changed at a time
+     * Each transformed word must exist in the word list. Note that beginWord is not a transformed word.
+     * Note:
+     *
+     * Return an empty list if there is no such transformation sequence.
+     * All words have the same length.
+     * All words contain only lowercase alphabetic characters.
+     * You may assume no duplicates in the word list.
+     * You may assume beginWord and endWord are non-empty and are not the same.
+     * Example 1:
+     *
+     * Input:
+     * beginWord = "hit",
+     * endWord = "cog",
+     * wordList = ["hot","dot","dog","lot","log","cog"]
+     *
+     * Output:
+     * [
+     *   ["hit","hot","dot","dog","cog"],
+     *   ["hit","hot","lot","log","cog"]
+     * ]
+     * Example 2:
+     *
+     * Input:
+     * beginWord = "hit"
+     * endWord = "cog"
+     * wordList = ["hot","dot","dog","lot","log"]
+     *
+     * Output: []
+     *
+     * Explanation: The endWord "cog" is not in wordList, therefore no possible transformation.
+     *
+     * 使用了广度优化遍历方案,会超时
+     * 
+ * + * @param beginWord + * @param endWord + * @param wordList + * @return + */ + public List> findLadders(String beginWord, String endWord, List wordList) { + + + Set wordDict = new HashSet<>(wordList); + List> result = new LinkedList<>(); + // 用于保存所有中间结果 + Deque> paths = new LinkedList<>(); + + + Deque deque = new LinkedList<>(); + deque.addLast(beginWord); + paths.addLast(deque); + + boolean find = false; + + while (!paths.isEmpty() && !find) { + // 先遍历看是否找到结果,如果找到了,一定是最优化解 + for (Deque path : paths) { + if (path.getLast().equals(endWord)) { + result.add(new LinkedList<>(path)); + find = true; + } + } + + // find表示已经找到了 + // paths.getFirst().size() >=beginWord.length()说明不可能找到结果,path最 + System.out.println(paths.getFirst().size()); + if (find || paths.getFirst().size() >= wordDict.size()) { + break; + } + + // TODO 什么时候判断找不到,path中可能形成环 + + + // 没有找到最优化解,构建下一层 + for (int k = paths.size(); k > 0; k--) { + + // 取路径的最后一个元素 + Deque path = paths.removeFirst(); + String s = path.getLast(); + + // 当前路径下,还可以使用的字词 + Set set = new HashSet<>(wordDict); + set.removeAll(path); + + System.out.println(set); + + // 找出当前层的每个元素经过一次变化后,是否在剩余的wordDict中找到, + // 如果找到就放到下一层的处理中 + char[] chars = s.toCharArray(); + for (int i = 0; i < beginWord.length(); i++) { + for (char j = 'a'; j <= 'z'; j++) { + char temp = chars[i]; + chars[i] = j; + String t = new String(chars); + + // 一次变换后可以找到单词,放到下一层处理中 + if (set.contains(t) && !t.equals(s)) { + path.addLast(t); + paths.addLast(new LinkedList<>(path)); + path.removeLast(); + } + // 还原 + chars[i] = temp; + } + } + + } + } + + return result; + } +} diff --git a/[127][Word Ladder]/src/Main.java b/[127][Word Ladder]/src/Main.java new file mode 100644 index 0000000..2a6d29a --- /dev/null +++ b/[127][Word Ladder]/src/Main.java @@ -0,0 +1,21 @@ +import org.junit.Assert; +import org.junit.Test; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-20 08:17 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + String beginWord = "hit"; + String endWord = "cog"; + List wordList = new LinkedList<>(Arrays.asList("hot", "dot", "dog", "lot", "log", "cog")); + Assert.assertEquals(5, solution.ladderLength(beginWord, endWord, wordList)); + } +} diff --git a/[127][Word Ladder]/src/Solution.java b/[127][Word Ladder]/src/Solution.java index 5880a2f..5366850 100644 --- a/[127][Word Ladder]/src/Solution.java +++ b/[127][Word Ladder]/src/Solution.java @@ -1,3 +1,7 @@ +import java.util.Deque; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; import java.util.Set; /** @@ -40,14 +44,57 @@ public class Solution { * - еֻСдĸַ * * ˼· + * Ż * * * @param beginWord * @param endWord - * @param wordDict + * @param wordList * @return */ - public int ladderLength(String beginWord, String endWord, Set wordDict) { + public int ladderLength(String beginWord, String endWord, List wordList) { + + Set wordDict = new HashSet<>(wordList); + + char[] chars; + Deque deque = new LinkedList<>(); + deque.addLast(beginWord); + int result = 0; + String s; + String t; + while (!deque.isEmpty()) { + + // ǰ + for (int k = deque.size(); k > 0; k--) { + s = deque.removeFirst(); + + if (s.equalsIgnoreCase(endWord)) { + return result + 1; + } + + // ҳǰÿԪؾһα仯ǷʣwordDictҵ + // ҵͷŵһĴ + chars = s.toCharArray(); + for (int i = 0; i < beginWord.length(); i++) { + for (char j = 'a'; j <= 'z'; j++) { + char temp = chars[i]; + chars[i] = j; + t = new String(chars); + // һα任ҵʣŵһ㴦УwordDictɾ¼ + if (wordDict.contains(t) && !t.equals(s)) { + deque.addLast(t); + wordDict.remove(t); + } + // ԭ + chars[i] = temp; + } + } + } + + + result++; + } + return 0; } } diff --git a/[130][Surrounded Regions]/src/Main.java b/[130][Surrounded Regions]/src/Main.java index 6ebf6cb..6c22ca8 100644 --- a/[130][Surrounded Regions]/src/Main.java +++ b/[130][Surrounded Regions]/src/Main.java @@ -1,3 +1,5 @@ +import org.junit.Test; + /** * Author: * Date: 2015-06-22 @@ -5,15 +7,9 @@ * Declaration: All Rights Reserved !!! */ public class Main { - public static void main(String[] args) { -// test01(); -// test02(); -// test03(); - test04(); - } - - private static void test01() { + @Test + public void test01() { Solution solution = new Solution(); char[][] board = { "XXXX".toCharArray(), @@ -27,9 +23,11 @@ private static void test01() { for (char[] line : board) { System.out.println(new String(line)); } + System.out.println(); } - private static void test02() { + @Test + public void test02() { Solution solution = new Solution(); char[][] board = { "XOXX".toCharArray(), @@ -45,9 +43,11 @@ private static void test02() { for (char[] line : board) { System.out.println(new String(line)); } + System.out.println(); } - private static void test03() { + @Test + public void test03() { Solution solution = new Solution(); char[][] board = { "OO".toCharArray(), @@ -59,9 +59,11 @@ private static void test03() { for (char[] line : board) { System.out.println(new String(line)); } + System.out.println(); } - private static void test04() { + @Test + public void test04() { Solution solution = new Solution(); char[][] board = { "OOO".toCharArray(), @@ -74,5 +76,6 @@ private static void test04() { for (char[] line : board) { System.out.println(new String(line)); } + System.out.println(); } } diff --git a/[130][Surrounded Regions]/src/Solution.java b/[130][Surrounded Regions]/src/Solution.java index 4b460f9..636f0a0 100644 --- a/[130][Surrounded Regions]/src/Solution.java +++ b/[130][Surrounded Regions]/src/Solution.java @@ -1,6 +1,3 @@ -import java.util.LinkedList; -import java.util.List; - /** * Author: * Date: 2015-06-22 @@ -28,231 +25,59 @@ public class Solution { * Ŀ⣺ * һά񣬰'X''O'ԱXΧOX * ˼· - * ùȱķʽҲԲóȵķʽջ,dzеıΧĵ㣬ʣµľDzΧĵ + * ȶȱķʽҳXΧOΪ$ * * * @param board */ - //////////////////////////////////////////////////////////////////////////////////////////////// - // ùȶȱķʽҳеġΧĵ - //////////////////////////////////////////////////////////////////////////////////////////////// - public void solve(char[][] board) { + void solve(char[][] board) { + // У if (board == null || board.length < 1 || board[0].length < 1) { return; } - boolean[][] visited = new boolean[board.length][board[0].length]; - // ʱΧһȦԪ - List round = new LinkedList<>(); - // - for (int col = 0; col < board[0].length; col++) { - // УҵOҵδʹ - if (!visited[0][col] && board[0][col] == 'O') { - round.clear(); - round.add(new Coordinate(0, col)); - bfs(board, visited, round); - } + // һк + for (int i = 0; i < board[0].length; i++) { + dfs(board, 0, i); + dfs(board, board.length - 1, i); } - // ײ - for (int col = 0; col < board[0].length; col++) { - // УҵOҵδʹ - if (!visited[board.length - 1][col] && board[board.length - 1][col] == 'O') { - round.clear(); - round.add(new Coordinate(board.length - 1, col)); - bfs(board, visited, round); - } + // һкһ + for (int i = 1; i < board.length - 1; i++) { + dfs(board, i, 0); + dfs(board, i, board[0].length - 1); } - // - for (int row = 1; row < board.length - 1; row++) { - // УҵOҵδʹ - if (!visited[row][0] && board[row][0] == 'O') { - round.clear(); - round.add(new Coordinate(row, 0)); - bfs(board, visited, round); - } - } - // ұ - for (int row = 1; row < board.length - 1; row++) { - // УҵOҵδʹ - if (!visited[row][board[0].length - 1] && board[row][board[0].length - 1] == 'O') { - round.clear(); - round.add(new Coordinate(row, board[0].length - 1)); - bfs(board, visited, round); - } - } - // - for (int i = 0; i < board.length; i++) { - for (int j = 0; j < board[0].length; j++) { - // δʹֿܣһX㣬ڶO㣬OһDZXΧ - // ʱδʹĵΪXȷ - if (!visited[i][j]) { + for (int i = 0; i < board.length; ++i) { + for (int j = 0; j < board[i].length; ++j) { + if (board[i][j] == 'O') { board[i][j] = 'X'; } - } - } - } - - /** - * ȣҲΧĵ - * - * @param board ά - * @param visited ʱ - * @param round ʱΧһȦԪ - */ - public void bfs(char[][] board, boolean[][] visited, List round) { - Coordinate c; - while (round.size() > 0) { - c = round.remove(0); - if (c.x >= 0 && c.x < board.length && c.y >= 0 && c.y < board[0].length && board[c.x][c.y] == 'O' && !visited[c.x][c.y]) { - visited[c.x][c.y] = true; - round.add(new Coordinate(c.x - 1, c.y)); - round.add(new Coordinate(c.x, c.y + 1)); - round.add(new Coordinate(c.x + 1, c.y)); - round.add(new Coordinate(c.x, c.y - 1)); - } - } - } - - //////////////////////////////////////////////////////////////////////////////////////////////// - // ùȶȱķʽҳеıΧĵ㣬ұǻᳬʱ - //////////////////////////////////////////////////////////////////////////////////////////////// - public void solve2(char[][] board) { - // У - if (board == null || board.length < 1 || board[0].length < 1) { - return; - } - - boolean[][] visited = new boolean[board.length][board[0].length]; - - // ʱΧһȦԪ - List round = new LinkedList<>(); - // Ԫ - List all = new LinkedList<>(); - - for (int i = 0; i < board.length; i++) { - for (int j = 0; j < board[0].length; j++) { - if (!visited[i][j] && board[i][j] == 'O') { - // һȦԪ - round.add(new Coordinate(i, j)); - boolean result = bfs(board, visited, round, all); - // һOڣҲڱ߽ - if (result) { - // ñ - for (Coordinate c : all) { - board[c.x][c.y] = 'X'; - } - } - - // Ԫ - round.clear(); - all.clear(); + if (board[i][j] == '$') { + board[i][j] = 'O'; } } } - } - /** - * ȱ - * - * @param board ά - * @param visited ʱ - * @param round ʱΧһȦԪ - * @param all Ԫ - * @return trueOڣҲڱ߽ϣXܷtrue - */ - public boolean bfs(char[][] board, boolean[][] visited, List round, List all) { - boolean result = true; - int size = round.size(); - Coordinate c; - while (size > 0) { - size--; - - // ȡԪ - c = round.remove(0); - // ӵ¼Ԫؼ - all.add(c); - // Ѿʹ - visited[c.x][c.y] = true; - // жcǷOڵ - result &= isInner(board, c.x, c.y); - - // cһǷOûзʹӵround - if (isO(board, c.x - 1, c.y) && !visited[c.x - 1][c.y]) { - round.add(new Coordinate(c.x - 1, c.y)); + void dfs(char[][] board, int i, int j) { + if (board[i][j] == 'O') { + board[i][j] = '$'; + if (i > 0 && board[i - 1][j] == 'O') { + dfs(board, i - 1, j); } - - // cһǷOûзʹӵround - if (isO(board, c.x, c.y + 1) && !visited[c.x][c.y + 1]) { - round.add(new Coordinate(c.x, c.y + 1)); + if (j < board[i].length - 1 && board[i][j + 1] == 'O') { + dfs(board, i, j + 1); } - - // cһǷOûзʹӵround - if (isO(board, c.x + 1, c.y) && !visited[c.x + 1][c.y]) { - round.add(new Coordinate(c.x + 1, c.y)); + if (i < board.length - 1 && board[i + 1][j] == 'O') { + dfs(board, i + 1, j); } - - // cһǷOûзʹӵround - if (isO(board, c.x, c.y - 1) && !visited[c.x][c.y - 1]) { - round.add(new Coordinate(c.x, c.y - 1)); + if (j > 1 && board[i][j - 1] == 'O') { + dfs(board, i, j - 1); } } - - if (round.size() > 0) { - return bfs(board, visited, round, all) && result; - } else { - return result; - } - - } - - /** - * жϵڶάڲҲڱ߽ - * - * @param board ά - * @param x - * @param y - * @return true - */ - public boolean isInner(char[][] board, int x, int y) { - return x > 0 && x < board.length - 1 && y > 0 && y < board[0].length - 1; - } - - /** - * жϵǷO - * - * @param board ά - * @param x - * @param y - * @return true - */ - public boolean isO(char[][] board, int x, int y) { - return x >= 0 && x < board.length && y >= 0 && y < board[0].length && board[x][y] == 'O'; - } - - /** - * - */ - public static class Coordinate { - private int x; - private int y; - - public Coordinate() { - } - - public Coordinate(int x, int y) { - this.x = x; - this.y = y; - } - - @Override - public String toString() { - return "(" + x + ", " + y + ")"; - } } } diff --git a/[130][Surrounded Regions]/src/Solution2.java b/[130][Surrounded Regions]/src/Solution2.java new file mode 100644 index 0000000..3308a10 --- /dev/null +++ b/[130][Surrounded Regions]/src/Solution2.java @@ -0,0 +1,258 @@ +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-06-22 + * Time: 08:51 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + /** + *
+     * Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.
+     * A region is captured by flipping all 'O's into 'X's in that surrounded region.
+     *
+     * For example,
+     * X X X X
+     * X O O X
+     * X X O X
+     * X O X X
+     *
+     * After running your function, the board should be:
+     * X X X X
+     * X X X X
+     * X X X X
+     * X O X X
+     *
+     * Ŀ⣺
+     * һά񣬰'X''O'ԱXΧOX
+     * ˼·
+     * ùȱķʽҲԲóȵķʽջ,dzеıΧĵ㣬ʣµľDzΧĵ
+     * 
+ * + * @param board + */ + //////////////////////////////////////////////////////////////////////////////////////////////// + // ùȶȱķʽҳеġΧĵ + //////////////////////////////////////////////////////////////////////////////////////////////// + public void solve(char[][] board) { + // У + if (board == null || board.length < 1 || board[0].length < 1) { + return; + } + + boolean[][] visited = new boolean[board.length][board[0].length]; + // ʱΧһȦԪ + List round = new LinkedList<>(); + // + for (int col = 0; col < board[0].length; col++) { + // УҵOҵδʹ + if (!visited[0][col] && board[0][col] == 'O') { + round.clear(); + round.add(new Coordinate(0, col)); + bfs(board, visited, round); + } + } + + // ײ + for (int col = 0; col < board[0].length; col++) { + // УҵOҵδʹ + if (!visited[board.length - 1][col] && board[board.length - 1][col] == 'O') { + round.clear(); + round.add(new Coordinate(board.length - 1, col)); + bfs(board, visited, round); + } + } + + // + for (int row = 1; row < board.length - 1; row++) { + // УҵOҵδʹ + if (!visited[row][0] && board[row][0] == 'O') { + round.clear(); + round.add(new Coordinate(row, 0)); + bfs(board, visited, round); + } + } + + // ұ + for (int row = 1; row < board.length - 1; row++) { + // УҵOҵδʹ + if (!visited[row][board[0].length - 1] && board[row][board[0].length - 1] == 'O') { + round.clear(); + round.add(new Coordinate(row, board[0].length - 1)); + bfs(board, visited, round); + } + } + + // + for (int i = 0; i < board.length; i++) { + for (int j = 0; j < board[0].length; j++) { + // δʹֿܣһX㣬ڶO㣬OһDZXΧ + // ʱδʹĵΪXȷ + if (!visited[i][j]) { + board[i][j] = 'X'; + } + } + } + } + + /** + * ȣҲΧĵ + * + * @param board ά + * @param visited ʱ + * @param round ʱΧһȦԪ + */ + public void bfs(char[][] board, boolean[][] visited, List round) { + Coordinate c; + while (round.size() > 0) { + c = round.remove(0); + if (c.x >= 0 && c.x < board.length && c.y >= 0 && c.y < board[0].length && board[c.x][c.y] == 'O' && !visited[c.x][c.y]) { + visited[c.x][c.y] = true; + round.add(new Coordinate(c.x - 1, c.y)); + round.add(new Coordinate(c.x, c.y + 1)); + round.add(new Coordinate(c.x + 1, c.y)); + round.add(new Coordinate(c.x, c.y - 1)); + } + } + } + + //////////////////////////////////////////////////////////////////////////////////////////////// + // ùȶȱķʽҳеıΧĵ㣬ұǻᳬʱ + //////////////////////////////////////////////////////////////////////////////////////////////// + public void solve2(char[][] board) { + // У + if (board == null || board.length < 1 || board[0].length < 1) { + return; + } + + boolean[][] visited = new boolean[board.length][board[0].length]; + + // ʱΧһȦԪ + List round = new LinkedList<>(); + // Ԫ + List all = new LinkedList<>(); + + for (int i = 0; i < board.length; i++) { + for (int j = 0; j < board[0].length; j++) { + if (!visited[i][j] && board[i][j] == 'O') { + // һȦԪ + round.add(new Coordinate(i, j)); + boolean result = bfs(board, visited, round, all); + // һOڣҲڱ߽ + if (result) { + // ñ + for (Coordinate c : all) { + board[c.x][c.y] = 'X'; + } + } + + // Ԫ + round.clear(); + all.clear(); + } + } + } + + } + + /** + * ȱ + * + * @param board ά + * @param visited ʱ + * @param round ʱΧһȦԪ + * @param all Ԫ + * @return trueOڣҲڱ߽ϣXܷtrue + */ + public boolean bfs(char[][] board, boolean[][] visited, List round, List all) { + boolean result = true; + int size = round.size(); + Coordinate c; + while (size > 0) { + size--; + + // ȡԪ + c = round.remove(0); + // ӵ¼Ԫؼ + all.add(c); + // Ѿʹ + visited[c.x][c.y] = true; + // жcǷOڵ + result &= isInner(board, c.x, c.y); + + // cһǷOûзʹӵround + if (isO(board, c.x - 1, c.y) && !visited[c.x - 1][c.y]) { + round.add(new Coordinate(c.x - 1, c.y)); + } + + // cһǷOûзʹӵround + if (isO(board, c.x, c.y + 1) && !visited[c.x][c.y + 1]) { + round.add(new Coordinate(c.x, c.y + 1)); + } + + // cһǷOûзʹӵround + if (isO(board, c.x + 1, c.y) && !visited[c.x + 1][c.y]) { + round.add(new Coordinate(c.x + 1, c.y)); + } + + // cһǷOûзʹӵround + if (isO(board, c.x, c.y - 1) && !visited[c.x][c.y - 1]) { + round.add(new Coordinate(c.x, c.y - 1)); + } + } + + if (round.size() > 0) { + return bfs(board, visited, round, all) && result; + } else { + return result; + } + + } + + /** + * жϵڶάڲҲڱ߽ + * + * @param board ά + * @param x + * @param y + * @return true + */ + public boolean isInner(char[][] board, int x, int y) { + return x > 0 && x < board.length - 1 && y > 0 && y < board[0].length - 1; + } + + /** + * жϵǷO + * + * @param board ά + * @param x + * @param y + * @return true + */ + public boolean isO(char[][] board, int x, int y) { + return x >= 0 && x < board.length && y >= 0 && y < board[0].length && board[x][y] == 'O'; + } + + /** + * + */ + public static class Coordinate { + private int x; + private int y; + + public Coordinate() { + } + + public Coordinate(int x, int y) { + this.x = x; + this.y = y; + } + + @Override + public String toString() { + return "(" + x + ", " + y + ")"; + } + } +} diff --git a/[131][Palindrome Partitioning]/src/Main.java b/[131][Palindrome Partitioning]/src/Main.java new file mode 100644 index 0000000..8266432 --- /dev/null +++ b/[131][Palindrome Partitioning]/src/Main.java @@ -0,0 +1,15 @@ +import org.junit.Test; + +import java.util.Arrays; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-21 18:36 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + System.out.println(solution.partition("aab")); + } +} diff --git a/[131][Palindrome Partitioning]/src/Solution.java b/[131][Palindrome Partitioning]/src/Solution.java new file mode 100644 index 0000000..e3efdab --- /dev/null +++ b/[131][Palindrome Partitioning]/src/Solution.java @@ -0,0 +1,70 @@ +import java.util.Deque; +import java.util.LinkedList; +import java.util.List; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-21 18:29 + **/ +public class Solution { + /** + *
+     * Given a string s, partition s such that every substring of the partition is a palindrome.
+     *
+     * Return all possible palindrome partitioning of s.
+     *
+     * Example:
+     *
+     * Input: "aab"
+     * Output:
+     * [
+     *   ["aa","b"],
+     *   ["a","a","b"]
+     * ]
+     *
+     * 解决方案:可以使用回溯法
+     * TODO : 可以构建一个回文表,再进行判定
+     * 
+ * + * @param s + * @return + */ + public List> partition(String s) { + List> result = new LinkedList<>(); + Deque current = new LinkedList<>(); + + partition(s, 0, current, result); + + return result; + } + + private void partition(String s, int index, Deque current, List> result) { + if (index == s.length()) { + result.add(new LinkedList<>(current)); + return; + } + + for (int i = index; i < s.length(); i++) { + String t = s.substring(index, i + 1); + if (isPalindrome(s, index, i)) { + current.addLast(t); + partition(s, i + 1, current, result); + // 还原 + current.removeLast(); + } + } + } + + private boolean isPalindrome(String s, int start, int end) { + while (start < end) { + + if (s.charAt(start) != s.charAt(end)) { + return false; + } else { + start++; + end--; + } + } + return true; + } +} From 9ed2893779143a851fdd3f0d9a9cf825d580a293 Mon Sep 17 00:00:00 2001 From: Wang-Jun-Chao Date: Sun, 23 Jun 2019 06:50:47 +0800 Subject: [PATCH 049/108] commit --- .idea/modules.xml | 1 + [093][Restore IP Addresses]/src/Solution.java | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 [093][Restore IP Addresses]/src/Solution.java diff --git a/.idea/modules.xml b/.idea/modules.xml index bf707cd..30980ec 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -88,6 +88,7 @@ + diff --git a/[093][Restore IP Addresses]/src/Solution.java b/[093][Restore IP Addresses]/src/Solution.java new file mode 100644 index 0000000..ad998bc --- /dev/null +++ b/[093][Restore IP Addresses]/src/Solution.java @@ -0,0 +1,32 @@ +import java.util.ArrayList; +import java.util.List; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-23 06:48 + **/ +public class Solution { + public List restoreIpAddresses(String s) { + List result = new ArrayList<>(); + doRestore(result, "", s, 0); + return result; + } + + private void doRestore(List result, String path, String s, int k) { + if (s.isEmpty() || k == 4) { + if (s.isEmpty() && k == 4) { + result.add(path.substring(1)); + } + return; + } + + int length = (s.charAt(0) == '0' ? 1 : 3); // 避免前导0 + length = length < s.length() ? length : s.length(); + for (int i = 1; i <= length; i++) { + String part = s.substring(0, i); + if (Integer.valueOf(part) <= 255) { + doRestore(result, path + "." + part, s.substring(i), k + 1); + } + } + } +} From 034603eabc371f68aed21c5e40d36414684b8834 Mon Sep 17 00:00:00 2001 From: Wang-Jun-Chao Date: Sun, 23 Jun 2019 14:30:47 +0800 Subject: [PATCH 050/108] commit --- [022][Generate Parentheses]/src/Solution.java | 3 ++- [040][Combination Sum II]/src/Solution.java | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/[022][Generate Parentheses]/src/Solution.java b/[022][Generate Parentheses]/src/Solution.java index ce980c4..75a6eb1 100644 --- a/[022][Generate Parentheses]/src/Solution.java +++ b/[022][Generate Parentheses]/src/Solution.java @@ -32,7 +32,7 @@ public List generateParenthesis(int n) { List result = new ArrayList<>(); // 0 if (n > 0) { - // ʹ + // char[] parentheses = new char[2 * n]; // solve(n, n, parentheses, result); @@ -51,6 +51,7 @@ public void solve(int left, int right, char[] parentheses, List result) // ʣµС0ÿʣµС if (left < 0 || right < 0 || right < left) { // ʲô + return; } // Ŷʹ else if (left == 0 && right == 0) { diff --git a/[040][Combination Sum II]/src/Solution.java b/[040][Combination Sum II]/src/Solution.java index e809d3a..c766df0 100644 --- a/[040][Combination Sum II]/src/Solution.java +++ b/[040][Combination Sum II]/src/Solution.java @@ -29,6 +29,8 @@ private void backtrack(List> list, List tempList, int[] n list.add(new LinkedList<>(tempList)); } else { for (int i = start; i < nums.length; i++) { + // 如果上一轮循环没有选nums[i],则本次循环就不能再选nums[i], + // 确保nums[i] 最多只用一次 if (i > start && nums[i] == nums[i - 1]) { continue; } From ed99e74220917abd3b06ec5e3c9300028b677ebe Mon Sep 17 00:00:00 2001 From: Wang-Jun-Chao Date: Sun, 23 Jun 2019 15:37:30 +0800 Subject: [PATCH 051/108] commit --- .gitignore | 4 +- .idea/.name | 1 - .idea/compiler.xml | 16 -- .idea/copyright/profiles_settings.xml | 3 - .idea/misc.xml | 16 -- .idea/modules.xml | 184 ------------- .idea/uiDesigner.xml | 124 --------- .idea/vcs.xml | 6 - [000][common]/src/FileRename.java | 30 -- [000][common]/src/MaxSubArray.java | 47 ---- [001][Two Sum]/src/Main.java | 35 --- [001][Two Sum]/src/Solution.java | 74 ----- [001][Two Sum]/src/Solution2.java | 94 ------- [002][Add Two Numbers]/src/ListNode.java | 14 - [002][Add Two Numbers]/src/Solution.java | 89 ------ .../src/Solution.java | 91 ------ .../src/Main.java | 35 --- .../src/Solution.java | 90 ------ .../src/Solution2.java | 79 ------ .../src/Main.java | 12 - .../src/Solution.java | 82 ------ [006][Zig Zag Conversion]/src/Solution.java | 94 ------- [007][Reverse Integer]/src/Solution.java | 42 --- .../src/Solution.java | 104 ------- [009][Palindrome Number]/src/Main.java | 13 - [009][Palindrome Number]/src/Solution.java | 46 ---- .../src/Main.java | 12 - .../src/Solution.java | 120 -------- .../src/Solution.java | 88 ------ [012][Integer To Roman]/src/Main.java | 39 --- [012][Integer To Roman]/src/Solution.java | 65 ----- [012][Integer To Roman]/src/Solution2.java | 56 ---- [013][Romar To Integer]/src/Main.java | 37 --- [013][Romar To Integer]/src/Solution.java | 55 ---- [013][Romar To Integer]/src/Solution2.java | 98 ------- [014][Longest Common Prefix]/src/Main.java | 20 -- .../src/Solution.java | 59 ---- .../src/Solution2.java | 65 ----- [015][3 Sum]/src/Main.java | 53 ---- [015][3 Sum]/src/Solution.java | 80 ------ [015][3 Sum]/src/Solution2.java | 119 -------- [015][3 Sum]/src/Solution3.java | 68 ----- [016][3 Sum Closest]/src/Main.java | 12 - [016][3 Sum Closest]/src/Solution.java | 99 ------- [016][3 Sum Closest]/src/Solution2.java | 89 ------ .../src/Main.java | 14 - .../src/Solution.java | 74 ----- .../src/Solution2.java | 95 ------- .../src/phone-number.png | Bin 25417 -> 0 bytes [018][4 Sum]/src/Solution.java | 105 ------- .../src/ListNode.java | 15 - .../src/Solution.java | 59 ---- [020][Valid Parentheses]/src/Main.java | 22 -- [020][Valid Parentheses]/src/Solution.java | 52 ---- [020][Valid Parentheses]/src/Solution2.java | 97 ------- .../src/ListNode.java | 15 - .../src/Solution.java | 52 ---- [022][Generate Parentheses]/src/Main.java | 17 -- [022][Generate Parentheses]/src/Solution.java | 73 ----- [023][Merge K Sorted Lists]/src/ListNode.java | 14 - [023][Merge K Sorted Lists]/src/Solution.java | 214 --------------- [024][Swap Nodes In Pairs]/src/ListNode.java | 15 - [024][Swap Nodes In Pairs]/src/Solution.java | 53 ---- .../src/ListNode.java | 14 - [025][Reverse Nodes In K-Group]/src/Main.java | 42 --- .../src/Solution.java | 106 ------- .../src/Solution.java | 54 ---- .../src/Solution2.java | 57 ---- [027][Remove Element]/src/Solution.java | 52 ---- [027][Remove Element]/src/Solution2.java | 40 --- [028][Implement-strStr()]/src/Solution.java | 97 ------- [029][Divide Two Integers]/src/Main.java | 13 - [029][Divide Two Integers]/src/Solution.java | 68 ----- .../src/Solution.java | 33 --- [031][Next Permutation]/src/Main.java | 42 --- [031][Next Permutation]/src/Solution.java | 82 ------ .../src/Main.java | 15 - .../src/Solution.java | 54 ---- .../src/Solution2.java | 59 ---- .../src/Main.java | 14 - .../src/Solution.java | 120 -------- .../src/Solution2.java | 65 ----- [034][Search For A Range]/src/Solution.java | 124 --------- .../src/Solution.java | 70 ----- [036][Valid Sudoku]/src/Solution.java | 108 -------- [036][Valid Sudoku]/src/sodoku.png | Bin 14593 -> 0 bytes [037][Sudoku Solver]/src/Solution.java | 56 ---- [038][Count And Say]/src/Solution.java | 67 ----- [039][Combination Sum]/src/Solution.java | 43 --- [040][Combination Sum II]/src/Solution.java | 44 --- [041][First Missing Positive]/src/Main.java | 20 -- .../src/Solution.java | 51 ---- [042][Trapping Rain Water]/src/Solution.java | 149 ---------- [043][Multiply Strings]/src/Solution.java | 42 --- [044][Wildcard Matching]/src/Solution.java | 54 ---- [045][Jump Game II]/src/Solution.java | 49 ---- [046][Permutations]/src/Solution.java | 66 ----- [047][Permutations II]/src/Main.java | 14 - [047][Permutations II]/src/Solution.java | 62 ----- [048][Rotate Image]/src/Solution.java | 28 -- [049][Group Anagrams]/src/Solution.java | 80 ------ [050][Pow(x,n)]/src/Solution.java | 59 ---- [051][N-Queens]/src/Solution.java | 69 ----- [052][N-Queens II]/src/Solution.java | 63 ----- [053][Maximum Subarray]/src/Solution.java | 53 ---- [054][Spiral Matrix]/src/Solution.java | 111 -------- [055][Jump Game]/src/Solution.java | 65 ----- [056][Merge Intervals]/src/Interval.java | 20 -- [056][Merge Intervals]/src/Solution.java | 60 ---- [057][Insert Interval]/src/Interval.java | 20 -- [057][Insert Interval]/src/Solution.java | 76 ------ [058][Length Of Last Word]/src/Solution.java | 54 ---- [059][Spiral Matrix II]/src/Solution.java | 75 ----- [060][Permutation Sequence]/src/Solution.java | 57 ---- [061][Rotate List]/src/ListNode.java | 14 - [061][Rotate List]/src/Solution.java | 34 --- [061][Rotate List]/src/Solution2.java | 62 ----- [062][Unique Paths]/src/Solution.java | 63 ----- [063][Unique Paths II]/src/Solution.java | 99 ------- [064][Minimum Path Sum]/src/Main.java | 24 -- [064][Minimum Path Sum]/src/Solution.java | 110 -------- [065][Valid Number]/src/Main.java | 95 ------- [065][Valid Number]/src/Solution.java | 100 ------- [066][Plus One]/src/Solution.java | 55 ---- [067][Add Binary]/src/Solution.java | 105 ------- [070][Climbing Stairs]/src/Solution.java | 47 ---- [071][Simplify Path]/src/Solution.java | 32 --- [073][Set Matrix Zeroes]/src/Solution.java | 58 ---- [074][Search A 2D Matrix]/src/Main.java | 16 -- [074][Search A 2D Matrix]/src/Solution.java | 62 ----- [074][Search A 2D Matrix]/src/Solution2.java | 88 ------ [075][Sort Colors]/src/Main.java | 33 --- [075][Sort Colors]/src/Solution.java | 68 ----- [075][Sort Colors]/src/Solution2.java | 71 ----- [077][Combinations]/src/Main.java | 15 - [077][Combinations]/src/Solution.java | 62 ----- [077][Combinations]/src/Solution2.java | 80 ------ [078][Subsets]/src/Main.java | 16 -- [078][Subsets]/src/Solution.java | 71 ----- [078][Subsets]/src/Solution2.java | 123 --------- [078][Subsets]/src/Solution3.java | 86 ------ [079][Word Search]/src/Main.java | 14 - [079][Word Search]/src/Solution.java | 113 -------- .../src/Main.java | 15 - .../src/Solution.java | 24 -- .../src/Solution2.java | 24 -- .../src/Main.java | 13 - .../src/Solution.java | 136 --------- .../src/Solution2.java | 56 ---- .../src/ListNode.java | 14 - .../src/Solution.java | 80 ------ .../src/ListNode.java | 15 - .../src/Solution.java | 55 ---- .../src/Solution.java | 71 ----- [086][Partition List]/src/ListNode.java | 11 - [086][Partition List]/src/Solution.java | 64 ----- [088][Merge Sorted Array]/src/Solution.java | 51 ---- [089][Gray Code]/src/Main.java | 18 -- [089][Gray Code]/src/Solution.java | 82 ------ [090][Subsets II]/src/Main.java | 23 -- [090][Subsets II]/src/Solution.java | 66 ----- .../src/ListNode.java | 11 - .../src/Solution.java | 70 ----- [093][Restore IP Addresses]/src/Solution.java | 32 --- .../src/Main.java | 22 -- .../src/Solution.java | 37 --- .../src/TreeNode.java | 15 - .../src/Main.java | 16 -- .../src/Solution.java | 49 ---- .../src/Solution2.java | 51 ---- .../src/Solution.java | 67 ----- .../src/TreeNode.java | 15 - [100][Same Tree]/src/Solution.java | 45 --- [100][Same Tree]/src/TreeNode.java | 12 - [101][Symmetric Tree]/src/Solution.java | 62 ----- [101][Symmetric Tree]/src/TreeNode.java | 15 - .../src/Solution.java | 83 ------ .../src/TreeNode.java | 15 - .../src/Main.java | 27 -- .../src/Solution.java | 104 ------- .../src/TreeNode.java | 15 - .../src/Solution.java | 38 --- .../src/TreeNode.java | 15 - .../src/Solution.java | 89 ------ .../src/TreeNode.java | 15 - .../src/Main.java | 24 -- .../src/Solution.java | 93 ------- .../src/TreeNode.java | 15 - .../src/Solution.java | 83 ------ .../src/TreeNode.java | 15 - .../src/Solution.java | 58 ---- .../src/TreeNode.java | 15 - .../src/ListNode.java | 14 - .../src/Main.java | 63 ----- .../src/Solution.java | 64 ----- .../src/TreeNode.java | 15 - [110][Balanced Binary Tree]/src/Solution.java | 61 ----- [110][Balanced Binary Tree]/src/TreeNode.java | 15 - .../src/Solution.java | 40 --- .../src/Solution2.java | 64 ----- .../src/TreeNode.java | 15 - [112][Path Sum]/src/Solution.java | 70 ----- [112][Path Sum]/src/TreeNode.java | 15 - [113][Path Sum II]/src/Solution.java | 90 ------ [113][Path Sum II]/src/TreeNode.java | 15 - .../src/Solution.java | 68 ----- .../src/TreeNode.java | 12 - .../src/Solution.java | 84 ------ .../src/TreeLinkNode.java | 14 - .../src/Main.java | 46 ---- .../src/Solution.java | 100 ------- .../src/TreeLinkNode.java | 14 - [118][Pascal's Triangle]/src/Solution.java | 76 ------ [119][Pascal's Triangle II]/src/Solution.java | 83 ------ [120][Triangle]/src/Main.java | 33 --- [120][Triangle]/src/Solution.java | 80 ------ .../src/Solution.java | 54 ---- .../src/Solution.java | 37 --- .../src/Test.java | 18 -- .../src/Solution.java | 59 ---- .../src/TreeNode.java | 15 - [125][Valid Palindrome]/src/Solution.java | 78 ------ [126][Word Ladder II]/src/Main.java | 51 ---- [126][Word Ladder II]/src/Solution.java | 130 --------- [126][Word Ladder II]/src/Solution2.java | 113 -------- [126][Word Ladder II]/src/Solution3.java | 128 --------- [127][Word Ladder]/src/Main.java | 21 -- [127][Word Ladder]/src/Solution.java | 100 ------- .../src/Main.java | 17 -- .../src/Solution.java | 59 ---- .../src/Solution.java | 56 ---- .../src/TreeNode.java | 15 - [130][Surrounded Regions]/src/Main.java | 81 ------ [130][Surrounded Regions]/src/Solution.java | 83 ------ [130][Surrounded Regions]/src/Solution2.java | 258 ------------------ [131][Palindrome Partitioning]/src/Main.java | 15 - .../src/Solution.java | 70 ----- [134][Gas Station]/src/Main.java | 17 -- [134][Gas Station]/src/Solution.java | 146 ---------- [135][Candy]/src/Main.java | 14 - [135][Candy]/src/Solution.java | 77 ------ [136][Single Number]/src/Solution.java | 35 --- [137][Single Number II]/src/Solution.java | 78 ------ .../src/Main.java | 32 --- .../src/RandomListNode.java | 14 - .../src/Solution.java | 108 -------- [139][Word Break]/src/Main.java | 50 ---- [139][Word Break]/src/Solution.java | 121 -------- [141][Linked List Cycle]/src/ListNode.java | 14 - [141][Linked List Cycle]/src/Solution.java | 57 ---- [142][Linked List Cycle II]/src/ListNode.java | 14 - [142][Linked List Cycle II]/src/Solution.java | 53 ---- [143][Reorder List]/src/ListNode.java | 14 - [143][Reorder List]/src/Solution.java | 78 ------ .../src/Solution.java | 34 --- .../src/TreeNode.java | 15 - .../src/Solution.java | 93 ------- .../src/TreeNode.java | 15 - [146][LRU Cache]/src/LRUCache.java | 69 ----- [146][LRU Cache]/src/Main.java | 26 -- [147][Insertion Sort List]/src/ListNode.java | 14 - [147][Insertion Sort List]/src/Solution.java | 52 ---- [148][Sort List]/src/ListNode.java | 14 - [148][Sort List]/src/Solution.java | 84 ------ .../src/Main.java | 12 - .../src/Solution.java | 75 ----- .../src/Main.java | 26 -- .../src/Solution.java | 141 ---------- [152][Maximum Product Subarray]/src/Main.java | 12 - .../src/Solution.java | 63 ----- .../src/Main.java | 14 - .../src/Solution.java | 65 ----- .../src/Main.java | 12 - .../src/Solution.java | 92 ------- [155][Min Stack]/src/MinStack.java | 89 ------ [162][Find Peak Element]/src/Solution.java | 46 ---- .../src/Solution.java | 58 ---- [191][Number Of 1 Bits]/src/Main.java | 12 - [191][Number Of 1 Bits]/src/Solution.java | 30 -- [198][House Robber]/src/Main.java | 12 - [198][House Robber]/src/Solution.java | 61 ----- .../src/Solution.java | 77 ------ .../src/TreeNode.java | 15 - [200][Number Of Islands]/src/Solution.java | 89 ------ .../src/Solution.java | 40 --- [202][Happy Number ]/src/Main.java | 12 - [202][Happy Number ]/src/Solution.java | 51 ---- .../src/ListNode.java | 14 - .../src/Solution.java | 46 ---- [204][Count Primes]/src/Solution.java | 52 ---- [205][Isomorphic Strings]/src/Solution.java | 109 -------- [206][Reverse Linked List]/src/ListNode.java | 14 - [206][Reverse Linked List]/src/Main.java | 8 - [206][Reverse Linked List]/src/Solution.java | 47 ---- .../src/Main.java | 12 - .../src/Solution.java | 81 ------ [216][Combination Sum III]/src/Main.java | 15 - [216][Combination Sum III]/src/Solution.java | 101 ------- [217][Contains Duplicate ]/src/Main.java | 13 - [217][Contains Duplicate ]/src/Solution.java | 46 ---- .../src/Solution.java | 55 ---- [223][Rectangle Area]/src/Main.java | 14 - [223][Rectangle Area]/src/Solution.java | 78 ------ .../src/MyStack.java | 102 ------- [226][Invert Binary Tree]/src/Solution.java | 27 -- [226][Invert Binary Tree]/src/TreeNode.java | 15 - [231][Power of Two]/src/Solution.java | 28 -- [231][Power of Two]/src/Test.java | 16 -- .../src/MyQueue.java | 56 ---- .../src/Test.java | 15 - .../src/ListNode.java | 12 - .../src/Solution.java | 58 ---- .../src/Solution2.java | 38 --- [234][Palindrome Linked List]/src/Test.java | 42 --- .../src/Solution.java | 56 ---- .../src/TreeNode.java | 13 - .../src/ListNode.java | 12 - .../src/Solution.java | 31 --- .../src/Test.java | 32 --- [242][Valid Anagram]/src/Solution.java | 48 ---- [242][Valid Anagram]/src/Test.java | 12 - [257][Binary Tree Paths]/src/Solution.java | 56 ---- [257][Binary Tree Paths]/src/Test.java | 16 -- [257][Binary Tree Paths]/src/TreeNode.java | 15 - [258][Add Digits]/src/Solution.java | 27 -- [258][Add Digits]/src/Test.java | 13 - [263][Ugly Number]/src/Solution.java | 28 -- [263][Ugly Number]/src/Test.java | 16 -- [268][Missing Number]/src/Solution.java | 39 --- [268][Missing Number]/src/Test.java | 21 -- [278][First Bad Version]/src/Solution.java | 39 --- [278][First Bad Version]/src/Test.java | 12 - .../src/VersionControl.java | 20 -- [283][Move Zeroes]/src/Solution.java | 44 --- [283][Move Zeroes]/src/Test.java | 20 -- [290][Word Pattern]/src/Solution.java | 48 ---- [290][Word Pattern]/src/Test.java | 14 - .../src/NumArray.java | 34 --- .../src/Test.java | 12 - [326][Power of Three]/src/Solution.java | 25 -- [326][Power of Three]/src/Test.java | 13 - [342][Power of Four]/src/Solution.java | 29 -- [344][Reverse String]/src/Solution.java | 25 -- 343 files changed, 2 insertions(+), 17371 deletions(-) delete mode 100644 .idea/.name delete mode 100644 .idea/compiler.xml delete mode 100644 .idea/copyright/profiles_settings.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/uiDesigner.xml delete mode 100644 .idea/vcs.xml delete mode 100644 [000][common]/src/FileRename.java delete mode 100644 [000][common]/src/MaxSubArray.java delete mode 100644 [001][Two Sum]/src/Main.java delete mode 100644 [001][Two Sum]/src/Solution.java delete mode 100644 [001][Two Sum]/src/Solution2.java delete mode 100644 [002][Add Two Numbers]/src/ListNode.java delete mode 100644 [002][Add Two Numbers]/src/Solution.java delete mode 100644 [003][Longest Substring Without Repeating Characters]/src/Solution.java delete mode 100644 [004][Median of Two Sorted Arrays]/src/Main.java delete mode 100644 [004][Median of Two Sorted Arrays]/src/Solution.java delete mode 100644 [004][Median of Two Sorted Arrays]/src/Solution2.java delete mode 100644 [005][Longest Palindromic Substring Total]/src/Main.java delete mode 100644 [005][Longest Palindromic Substring Total]/src/Solution.java delete mode 100644 [006][Zig Zag Conversion]/src/Solution.java delete mode 100644 [007][Reverse Integer]/src/Solution.java delete mode 100644 [008][String To Integer (atoi)]/src/Solution.java delete mode 100644 [009][Palindrome Number]/src/Main.java delete mode 100644 [009][Palindrome Number]/src/Solution.java delete mode 100644 [010][Regular Expression Matching]/src/Main.java delete mode 100644 [010][Regular Expression Matching]/src/Solution.java delete mode 100644 [011][Container With Most Water]/src/Solution.java delete mode 100644 [012][Integer To Roman]/src/Main.java delete mode 100644 [012][Integer To Roman]/src/Solution.java delete mode 100644 [012][Integer To Roman]/src/Solution2.java delete mode 100644 [013][Romar To Integer]/src/Main.java delete mode 100644 [013][Romar To Integer]/src/Solution.java delete mode 100644 [013][Romar To Integer]/src/Solution2.java delete mode 100644 [014][Longest Common Prefix]/src/Main.java delete mode 100644 [014][Longest Common Prefix]/src/Solution.java delete mode 100644 [014][Longest Common Prefix]/src/Solution2.java delete mode 100644 [015][3 Sum]/src/Main.java delete mode 100644 [015][3 Sum]/src/Solution.java delete mode 100644 [015][3 Sum]/src/Solution2.java delete mode 100644 [015][3 Sum]/src/Solution3.java delete mode 100644 [016][3 Sum Closest]/src/Main.java delete mode 100644 [016][3 Sum Closest]/src/Solution.java delete mode 100644 [016][3 Sum Closest]/src/Solution2.java delete mode 100644 [017][Letter Combinations Of A Phon Number/src/Main.java delete mode 100644 [017][Letter Combinations Of A Phon Number/src/Solution.java delete mode 100644 [017][Letter Combinations Of A Phon Number/src/Solution2.java delete mode 100644 [017][Letter Combinations Of A Phon Number/src/phone-number.png delete mode 100644 [018][4 Sum]/src/Solution.java delete mode 100644 [019][Remove Nth Node From End Of List]/src/ListNode.java delete mode 100644 [019][Remove Nth Node From End Of List]/src/Solution.java delete mode 100644 [020][Valid Parentheses]/src/Main.java delete mode 100644 [020][Valid Parentheses]/src/Solution.java delete mode 100644 [020][Valid Parentheses]/src/Solution2.java delete mode 100644 [021][Merge Two Sorted Lists]/src/ListNode.java delete mode 100644 [021][Merge Two Sorted Lists]/src/Solution.java delete mode 100644 [022][Generate Parentheses]/src/Main.java delete mode 100644 [022][Generate Parentheses]/src/Solution.java delete mode 100644 [023][Merge K Sorted Lists]/src/ListNode.java delete mode 100644 [023][Merge K Sorted Lists]/src/Solution.java delete mode 100644 [024][Swap Nodes In Pairs]/src/ListNode.java delete mode 100644 [024][Swap Nodes In Pairs]/src/Solution.java delete mode 100644 [025][Reverse Nodes In K-Group]/src/ListNode.java delete mode 100644 [025][Reverse Nodes In K-Group]/src/Main.java delete mode 100644 [025][Reverse Nodes In K-Group]/src/Solution.java delete mode 100644 [026][Remove Duplicates from Sorted Array]/src/Solution.java delete mode 100644 [026][Remove Duplicates from Sorted Array]/src/Solution2.java delete mode 100644 [027][Remove Element]/src/Solution.java delete mode 100644 [027][Remove Element]/src/Solution2.java delete mode 100644 [028][Implement-strStr()]/src/Solution.java delete mode 100644 [029][Divide Two Integers]/src/Main.java delete mode 100644 [029][Divide Two Integers]/src/Solution.java delete mode 100644 [030][Substring With Concatenation Of All Words]/src/Solution.java delete mode 100644 [031][Next Permutation]/src/Main.java delete mode 100644 [031][Next Permutation]/src/Solution.java delete mode 100644 [032][Longest Valid Parentheses]/src/Main.java delete mode 100644 [032][Longest Valid Parentheses]/src/Solution.java delete mode 100644 [032][Longest Valid Parentheses]/src/Solution2.java delete mode 100644 [033][Search In Rotated Sorted Array]/src/Main.java delete mode 100644 [033][Search In Rotated Sorted Array]/src/Solution.java delete mode 100644 [033][Search In Rotated Sorted Array]/src/Solution2.java delete mode 100644 [034][Search For A Range]/src/Solution.java delete mode 100644 [035][Search Insert Position]/src/Solution.java delete mode 100644 [036][Valid Sudoku]/src/Solution.java delete mode 100644 [036][Valid Sudoku]/src/sodoku.png delete mode 100644 [037][Sudoku Solver]/src/Solution.java delete mode 100644 [038][Count And Say]/src/Solution.java delete mode 100644 [039][Combination Sum]/src/Solution.java delete mode 100644 [040][Combination Sum II]/src/Solution.java delete mode 100644 [041][First Missing Positive]/src/Main.java delete mode 100644 [041][First Missing Positive]/src/Solution.java delete mode 100644 [042][Trapping Rain Water]/src/Solution.java delete mode 100644 [043][Multiply Strings]/src/Solution.java delete mode 100644 [044][Wildcard Matching]/src/Solution.java delete mode 100644 [045][Jump Game II]/src/Solution.java delete mode 100644 [046][Permutations]/src/Solution.java delete mode 100644 [047][Permutations II]/src/Main.java delete mode 100644 [047][Permutations II]/src/Solution.java delete mode 100644 [048][Rotate Image]/src/Solution.java delete mode 100644 [049][Group Anagrams]/src/Solution.java delete mode 100644 [050][Pow(x,n)]/src/Solution.java delete mode 100644 [051][N-Queens]/src/Solution.java delete mode 100644 [052][N-Queens II]/src/Solution.java delete mode 100644 [053][Maximum Subarray]/src/Solution.java delete mode 100644 [054][Spiral Matrix]/src/Solution.java delete mode 100644 [055][Jump Game]/src/Solution.java delete mode 100644 [056][Merge Intervals]/src/Interval.java delete mode 100644 [056][Merge Intervals]/src/Solution.java delete mode 100644 [057][Insert Interval]/src/Interval.java delete mode 100644 [057][Insert Interval]/src/Solution.java delete mode 100644 [058][Length Of Last Word]/src/Solution.java delete mode 100644 [059][Spiral Matrix II]/src/Solution.java delete mode 100644 [060][Permutation Sequence]/src/Solution.java delete mode 100644 [061][Rotate List]/src/ListNode.java delete mode 100644 [061][Rotate List]/src/Solution.java delete mode 100644 [061][Rotate List]/src/Solution2.java delete mode 100644 [062][Unique Paths]/src/Solution.java delete mode 100644 [063][Unique Paths II]/src/Solution.java delete mode 100644 [064][Minimum Path Sum]/src/Main.java delete mode 100644 [064][Minimum Path Sum]/src/Solution.java delete mode 100644 [065][Valid Number]/src/Main.java delete mode 100644 [065][Valid Number]/src/Solution.java delete mode 100644 [066][Plus One]/src/Solution.java delete mode 100644 [067][Add Binary]/src/Solution.java delete mode 100644 [070][Climbing Stairs]/src/Solution.java delete mode 100644 [071][Simplify Path]/src/Solution.java delete mode 100644 [073][Set Matrix Zeroes]/src/Solution.java delete mode 100644 [074][Search A 2D Matrix]/src/Main.java delete mode 100644 [074][Search A 2D Matrix]/src/Solution.java delete mode 100644 [074][Search A 2D Matrix]/src/Solution2.java delete mode 100644 [075][Sort Colors]/src/Main.java delete mode 100644 [075][Sort Colors]/src/Solution.java delete mode 100644 [075][Sort Colors]/src/Solution2.java delete mode 100644 [077][Combinations]/src/Main.java delete mode 100644 [077][Combinations]/src/Solution.java delete mode 100644 [077][Combinations]/src/Solution2.java delete mode 100644 [078][Subsets]/src/Main.java delete mode 100644 [078][Subsets]/src/Solution.java delete mode 100644 [078][Subsets]/src/Solution2.java delete mode 100644 [078][Subsets]/src/Solution3.java delete mode 100644 [079][Word Search]/src/Main.java delete mode 100644 [079][Word Search]/src/Solution.java delete mode 100644 [080][Remove Duplicates from Sorted Array II]/src/Main.java delete mode 100644 [080][Remove Duplicates from Sorted Array II]/src/Solution.java delete mode 100644 [080][Remove Duplicates from Sorted Array II]/src/Solution2.java delete mode 100644 [081][Search In Rotated Sorted Array II]/src/Main.java delete mode 100644 [081][Search In Rotated Sorted Array II]/src/Solution.java delete mode 100644 [081][Search In Rotated Sorted Array II]/src/Solution2.java delete mode 100644 [082][Remove Duplicates From Sorted List II]/src/ListNode.java delete mode 100644 [082][Remove Duplicates From Sorted List II]/src/Solution.java delete mode 100644 [083][Remove Duplicates From Sorted List]/src/ListNode.java delete mode 100644 [083][Remove Duplicates From Sorted List]/src/Solution.java delete mode 100644 [084][Largest Rectangle in Histogram]/src/Solution.java delete mode 100644 [086][Partition List]/src/ListNode.java delete mode 100644 [086][Partition List]/src/Solution.java delete mode 100644 [088][Merge Sorted Array]/src/Solution.java delete mode 100644 [089][Gray Code]/src/Main.java delete mode 100644 [089][Gray Code]/src/Solution.java delete mode 100644 [090][Subsets II]/src/Main.java delete mode 100644 [090][Subsets II]/src/Solution.java delete mode 100644 [092][Reverse Linked List II]/src/ListNode.java delete mode 100644 [092][Reverse Linked List II]/src/Solution.java delete mode 100644 [093][Restore IP Addresses]/src/Solution.java delete mode 100644 [094][Binary Tree Inorder Traversal]/src/Main.java delete mode 100644 [094][Binary Tree Inorder Traversal]/src/Solution.java delete mode 100644 [094][Binary Tree Inorder Traversal]/src/TreeNode.java delete mode 100644 [096][Unique Binary Search Trees]/src/Main.java delete mode 100644 [096][Unique Binary Search Trees]/src/Solution.java delete mode 100644 [096][Unique Binary Search Trees]/src/Solution2.java delete mode 100644 [098][Validate Binary Search Tree]/src/Solution.java delete mode 100644 [098][Validate Binary Search Tree]/src/TreeNode.java delete mode 100644 [100][Same Tree]/src/Solution.java delete mode 100644 [100][Same Tree]/src/TreeNode.java delete mode 100644 [101][Symmetric Tree]/src/Solution.java delete mode 100644 [101][Symmetric Tree]/src/TreeNode.java delete mode 100644 [102][Binary Tree Level Order Traversal]/src/Solution.java delete mode 100644 [102][Binary Tree Level Order Traversal]/src/TreeNode.java delete mode 100644 [103][Binary Tree Zigzag LevelOrder Traversal]/src/Main.java delete mode 100644 [103][Binary Tree Zigzag LevelOrder Traversal]/src/Solution.java delete mode 100644 [103][Binary Tree Zigzag LevelOrder Traversal]/src/TreeNode.java delete mode 100644 [104][Maximum Depth Of Binary Tree]/src/Solution.java delete mode 100644 [104][Maximum Depth Of Binary Tree]/src/TreeNode.java delete mode 100644 [105][Construct Binary Tree From Preorder And Inorder Traversal]/src/Solution.java delete mode 100644 [105][Construct Binary Tree From Preorder And Inorder Traversal]/src/TreeNode.java delete mode 100644 [106][Construct Binary Tree From Inorder And Postorder Traversal]/src/Main.java delete mode 100644 [106][Construct Binary Tree From Inorder And Postorder Traversal]/src/Solution.java delete mode 100644 [106][Construct Binary Tree From Inorder And Postorder Traversal]/src/TreeNode.java delete mode 100644 [107][Binary Tree Level Order Traversa lII]/src/Solution.java delete mode 100644 [107][Binary Tree Level Order Traversa lII]/src/TreeNode.java delete mode 100644 [108][Convert Sorted Array To Binary Search Tree]/src/Solution.java delete mode 100644 [108][Convert Sorted Array To Binary Search Tree]/src/TreeNode.java delete mode 100644 [109][Convert Sorted List To Binary Search Tree]/src/ListNode.java delete mode 100644 [109][Convert Sorted List To Binary Search Tree]/src/Main.java delete mode 100644 [109][Convert Sorted List To Binary Search Tree]/src/Solution.java delete mode 100644 [109][Convert Sorted List To Binary Search Tree]/src/TreeNode.java delete mode 100644 [110][Balanced Binary Tree]/src/Solution.java delete mode 100644 [110][Balanced Binary Tree]/src/TreeNode.java delete mode 100644 [111][Minimum Depth Of Binary Tree]/src/Solution.java delete mode 100644 [111][Minimum Depth Of Binary Tree]/src/Solution2.java delete mode 100644 [111][Minimum Depth Of Binary Tree]/src/TreeNode.java delete mode 100644 [112][Path Sum]/src/Solution.java delete mode 100644 [112][Path Sum]/src/TreeNode.java delete mode 100644 [113][Path Sum II]/src/Solution.java delete mode 100644 [113][Path Sum II]/src/TreeNode.java delete mode 100644 [114][Flatten Binary Tree To Linked List]/src/Solution.java delete mode 100644 [114][Flatten Binary Tree To Linked List]/src/TreeNode.java delete mode 100644 [116][Populating Next Right Pointersin Each Node]/src/Solution.java delete mode 100644 [116][Populating Next Right Pointersin Each Node]/src/TreeLinkNode.java delete mode 100644 [117][Populating Next Right Pointers In Each Node II]/src/Main.java delete mode 100644 [117][Populating Next Right Pointers In Each Node II]/src/Solution.java delete mode 100644 [117][Populating Next Right Pointers In Each Node II]/src/TreeLinkNode.java delete mode 100644 [118][Pascal's Triangle]/src/Solution.java delete mode 100644 [119][Pascal's Triangle II]/src/Solution.java delete mode 100644 [120][Triangle]/src/Main.java delete mode 100644 [120][Triangle]/src/Solution.java delete mode 100644 [121][Best Time To Buy And Sell Stock]/src/Solution.java delete mode 100644 [122][Best Time to Buy and Sell Stock II]/src/Solution.java delete mode 100644 [122][Best Time to Buy and Sell Stock II]/src/Test.java delete mode 100644 [124][Binary Tree Maximum Path Sum]/src/Solution.java delete mode 100644 [124][Binary Tree Maximum Path Sum]/src/TreeNode.java delete mode 100644 [125][Valid Palindrome]/src/Solution.java delete mode 100644 [126][Word Ladder II]/src/Main.java delete mode 100644 [126][Word Ladder II]/src/Solution.java delete mode 100644 [126][Word Ladder II]/src/Solution2.java delete mode 100644 [126][Word Ladder II]/src/Solution3.java delete mode 100644 [127][Word Ladder]/src/Main.java delete mode 100644 [127][Word Ladder]/src/Solution.java delete mode 100644 [128][Longest Consecutive Sequence]/src/Main.java delete mode 100644 [128][Longest Consecutive Sequence]/src/Solution.java delete mode 100644 [129][Sum Root To Leaf Numbers]/src/Solution.java delete mode 100644 [129][Sum Root To Leaf Numbers]/src/TreeNode.java delete mode 100644 [130][Surrounded Regions]/src/Main.java delete mode 100644 [130][Surrounded Regions]/src/Solution.java delete mode 100644 [130][Surrounded Regions]/src/Solution2.java delete mode 100644 [131][Palindrome Partitioning]/src/Main.java delete mode 100644 [131][Palindrome Partitioning]/src/Solution.java delete mode 100644 [134][Gas Station]/src/Main.java delete mode 100644 [134][Gas Station]/src/Solution.java delete mode 100644 [135][Candy]/src/Main.java delete mode 100644 [135][Candy]/src/Solution.java delete mode 100644 [136][Single Number]/src/Solution.java delete mode 100644 [137][Single Number II]/src/Solution.java delete mode 100644 [138][Copy List With Random Pointer]/src/Main.java delete mode 100644 [138][Copy List With Random Pointer]/src/RandomListNode.java delete mode 100644 [138][Copy List With Random Pointer]/src/Solution.java delete mode 100644 [139][Word Break]/src/Main.java delete mode 100644 [139][Word Break]/src/Solution.java delete mode 100644 [141][Linked List Cycle]/src/ListNode.java delete mode 100644 [141][Linked List Cycle]/src/Solution.java delete mode 100644 [142][Linked List Cycle II]/src/ListNode.java delete mode 100644 [142][Linked List Cycle II]/src/Solution.java delete mode 100644 [143][Reorder List]/src/ListNode.java delete mode 100644 [143][Reorder List]/src/Solution.java delete mode 100644 [144][Binary Tree Preorder Traversal]/src/Solution.java delete mode 100644 [144][Binary Tree Preorder Traversal]/src/TreeNode.java delete mode 100644 [145][Binary Tree Postorder Traversal]/src/Solution.java delete mode 100644 [145][Binary Tree Postorder Traversal]/src/TreeNode.java delete mode 100644 [146][LRU Cache]/src/LRUCache.java delete mode 100644 [146][LRU Cache]/src/Main.java delete mode 100644 [147][Insertion Sort List]/src/ListNode.java delete mode 100644 [147][Insertion Sort List]/src/Solution.java delete mode 100644 [148][Sort List]/src/ListNode.java delete mode 100644 [148][Sort List]/src/Solution.java delete mode 100644 [150][Evaluate Reverse Polish Notation]/src/Main.java delete mode 100644 [150][Evaluate Reverse Polish Notation]/src/Solution.java delete mode 100644 [151][Reverse Words In A String]/src/Main.java delete mode 100644 [151][Reverse Words In A String]/src/Solution.java delete mode 100644 [152][Maximum Product Subarray]/src/Main.java delete mode 100644 [152][Maximum Product Subarray]/src/Solution.java delete mode 100644 [153][Find Minimum In Rotated Sorted Array]/src/Main.java delete mode 100644 [153][Find Minimum In Rotated Sorted Array]/src/Solution.java delete mode 100644 [154][Find Minimum In Rotated Sorted Array II]/src/Main.java delete mode 100644 [154][Find Minimum In Rotated Sorted Array II]/src/Solution.java delete mode 100644 [155][Min Stack]/src/MinStack.java delete mode 100644 [162][Find Peak Element]/src/Solution.java delete mode 100644 [167][Two Sum II - Input array is sorted]/src/Solution.java delete mode 100644 [191][Number Of 1 Bits]/src/Main.java delete mode 100644 [191][Number Of 1 Bits]/src/Solution.java delete mode 100644 [198][House Robber]/src/Main.java delete mode 100644 [198][House Robber]/src/Solution.java delete mode 100644 [199][Binary Tree Right Side View]/src/Solution.java delete mode 100644 [199][Binary Tree Right Side View]/src/TreeNode.java delete mode 100644 [200][Number Of Islands]/src/Solution.java delete mode 100644 [201][Bitwise AND Of Numbers Range]/src/Solution.java delete mode 100644 [202][Happy Number ]/src/Main.java delete mode 100644 [202][Happy Number ]/src/Solution.java delete mode 100644 [203][Remove Linked List Elements]/src/ListNode.java delete mode 100644 [203][Remove Linked List Elements]/src/Solution.java delete mode 100644 [204][Count Primes]/src/Solution.java delete mode 100644 [205][Isomorphic Strings]/src/Solution.java delete mode 100644 [206][Reverse Linked List]/src/ListNode.java delete mode 100644 [206][Reverse Linked List]/src/Main.java delete mode 100644 [206][Reverse Linked List]/src/Solution.java delete mode 100644 [215][Kth Largest Element In An Array]/src/Main.java delete mode 100644 [215][Kth Largest Element In An Array]/src/Solution.java delete mode 100644 [216][Combination Sum III]/src/Main.java delete mode 100644 [216][Combination Sum III]/src/Solution.java delete mode 100644 [217][Contains Duplicate ]/src/Main.java delete mode 100644 [217][Contains Duplicate ]/src/Solution.java delete mode 100644 [219][Contains Duplicate II]/src/Solution.java delete mode 100644 [223][Rectangle Area]/src/Main.java delete mode 100644 [223][Rectangle Area]/src/Solution.java delete mode 100644 [225][Implement Stack Using Queues]/src/MyStack.java delete mode 100644 [226][Invert Binary Tree]/src/Solution.java delete mode 100644 [226][Invert Binary Tree]/src/TreeNode.java delete mode 100644 [231][Power of Two]/src/Solution.java delete mode 100644 [231][Power of Two]/src/Test.java delete mode 100644 [232][Implement Queue using Stacks]/src/MyQueue.java delete mode 100644 [232][Implement Queue using Stacks]/src/Test.java delete mode 100644 [234][Palindrome Linked List]/src/ListNode.java delete mode 100644 [234][Palindrome Linked List]/src/Solution.java delete mode 100644 [234][Palindrome Linked List]/src/Solution2.java delete mode 100644 [234][Palindrome Linked List]/src/Test.java delete mode 100644 [235][Lowest Common Ancestor of a Binary Search Tree]/src/Solution.java delete mode 100644 [235][Lowest Common Ancestor of a Binary Search Tree]/src/TreeNode.java delete mode 100644 [237][Delete Node in a Linked List]/src/ListNode.java delete mode 100644 [237][Delete Node in a Linked List]/src/Solution.java delete mode 100644 [237][Delete Node in a Linked List]/src/Test.java delete mode 100644 [242][Valid Anagram]/src/Solution.java delete mode 100644 [242][Valid Anagram]/src/Test.java delete mode 100644 [257][Binary Tree Paths]/src/Solution.java delete mode 100644 [257][Binary Tree Paths]/src/Test.java delete mode 100644 [257][Binary Tree Paths]/src/TreeNode.java delete mode 100644 [258][Add Digits]/src/Solution.java delete mode 100644 [258][Add Digits]/src/Test.java delete mode 100644 [263][Ugly Number]/src/Solution.java delete mode 100644 [263][Ugly Number]/src/Test.java delete mode 100644 [268][Missing Number]/src/Solution.java delete mode 100644 [268][Missing Number]/src/Test.java delete mode 100644 [278][First Bad Version]/src/Solution.java delete mode 100644 [278][First Bad Version]/src/Test.java delete mode 100644 [278][First Bad Version]/src/VersionControl.java delete mode 100644 [283][Move Zeroes]/src/Solution.java delete mode 100644 [283][Move Zeroes]/src/Test.java delete mode 100644 [290][Word Pattern]/src/Solution.java delete mode 100644 [290][Word Pattern]/src/Test.java delete mode 100644 [303][Range Sum Query - Immutable]/src/NumArray.java delete mode 100644 [303][Range Sum Query - Immutable]/src/Test.java delete mode 100644 [326][Power of Three]/src/Solution.java delete mode 100644 [326][Power of Three]/src/Test.java delete mode 100644 [342][Power of Four]/src/Solution.java delete mode 100644 [344][Reverse String]/src/Solution.java diff --git a/.gitignore b/.gitignore index 2ea5840..2304249 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ # Created by .ignore support plugin (hsz.mobi) out -.idea -*.iml +#.idea +#*.iml ### Java template # Compiled class file *.class diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index 612003b..0000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -LeetCode \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index ab52643..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf3..0000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index a46b26f..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 30980ec..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,184 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml deleted file mode 100644 index e96534f..0000000 --- a/.idea/uiDesigner.xml +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/[000][common]/src/FileRename.java b/[000][common]/src/FileRename.java deleted file mode 100644 index e0b062d..0000000 --- a/[000][common]/src/FileRename.java +++ /dev/null @@ -1,30 +0,0 @@ -import java.io.File; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-14 10:00 - **/ -public class FileRename { - public static void main(String[] args) { - String pathName = "/Users/wangjunchao/Project/leetcode"; - File path = new File("/Users/wangjunchao/Project/leetcode"); - - File[] files = path.listFiles(); - renameFile(files); - } - - public static void renameFile(File[] files) { - for (File f : files) { - if (f.isDirectory()) { - renameFile(f.listFiles()); - } - } - - for (File f : files) { - String name = f.getName(); - name = name.replaceAll("【", "["); - name = name.replaceAll("】", "]"); - f.renameTo(new File(f.getParent() + "/" + name)); - } - } -} diff --git a/[000][common]/src/MaxSubArray.java b/[000][common]/src/MaxSubArray.java deleted file mode 100644 index e19a385..0000000 --- a/[000][common]/src/MaxSubArray.java +++ /dev/null @@ -1,47 +0,0 @@ -import org.junit.Test; - -import java.util.Arrays; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-16 11:16 - **/ -public class MaxSubArray { - public int[] solve(int[] array) { - if (array == null || array.length < 1) { - return null; - } - - - // result[0] 最大的子数组和 - // result[1] 最大的子数组的起始位置 - // result[2] 最大的子数组的结束位置 - int[] result = {Integer.MIN_VALUE, -1, -1}; - - int sum = 0; - int begin = 0; - for (int i = 0; i < array.length; i++) { - if (sum >= 0) { - sum += array[i]; - } else { - sum = array[i]; - begin = i; - } - - if (result[0] <= sum) { - result[0] = sum; - result[1] = begin; - result[2] = i; - } - } - - return result; - } - - @Test - public void test1() { - MaxSubArray maxSubArray = new MaxSubArray(); - - System.out.println(Arrays.toString(maxSubArray.solve(new int[]{1, 2, 3, 4, 5, 6}))); - } -} diff --git a/[001][Two Sum]/src/Main.java b/[001][Two Sum]/src/Main.java deleted file mode 100644 index 7c82290..0000000 --- a/[001][Two Sum]/src/Main.java +++ /dev/null @@ -1,35 +0,0 @@ -import org.junit.Test; - -/** - * Author: 王俊超 - * Date: 2015-06-18 - * Time: 09:17 - * Declaration: All Rights Reserved !!! - */ -public class Main { - @Test - public void test0() { - int[] result = new Solution().twoSum(new int[]{0, 4, 3, 0}, 0); - - System.out.println("[" + result[0] + " ," + result[1] + "]"); - } - - @Test - public void test1() { - int[] result = new Solution().twoSum(new int[]{3, 2, 4}, 6); - System.out.println("[" + result[0] + " ," + result[1] + "]"); - } - - @Test - public void test2() { - int[] result = new Solution().twoSum(new int[]{3, 2, 4}, 6); - System.out.println("[" + result[0] + " ," + result[1] + "]"); - } - @Test - public void test3() { - int[] nums = {876,879,155,291,431,296,592,965,502,173,869,504,258,342,192,478,270,341,811,794,472,625,229,829,122,858,738,481,102,946,305,399,216,752,413,352,271,193,534,508,152,989,154,456,168,510,391,28,317,409,609,532,784,160,696,105,245,231,20,17,81,781,79,816,918,838,123,602,338,997,192,947,388,515,510,441,175,539,708,980,207,336,524,610,3,427,282,84,953,855,117,737,288,371,623,484,738,874,426,202,481,132,499,500,89,786,276,221,857,398,242,639,771,149,758,775,39,836,70,903,193,959,169,851,798,815,755,498,308,70,217,765,504,498,56,547,578,977,882,909,9,874,223,39,429,982,129,712,77,996,43,613,800,810,73,993,763,978,912,255,468,937,987,701,155,347,980,147,698,41,353,178,396,241,71,482,40,593,993,959,193,544,376,752,804,194,800,837,673,261,348,963,918,217,945,271,493,538,203,54,850,753,954,312,584,399,504,62,124,790,542,239,662,410,12,362,798,726,798,780,785,737,280,931,452,643,362,190,975,520,219,330,290,451,22,756,837,787,758,661,75,697,419,485,290,84,401,447,400,311,121,216,574,724,733,496,680,831,736,43,578,201,109,197,125,66,739,339,925,148,381,513,152,305,603,516,979,133,993,430,167,826,526,290,562,559,947,448,903,289,259,221,915,71,879,639,390,588,496,430,778,722,421,821,436,621,959,728,81,117,202,17,408,829,438,970,93,738,838,902,248,128,903,800,567,829,3,407,306,773,71,323,492,305,301,28,220,455,320,478,873,483,521,260,460,342,846,577,874,530,588,965,985,606,410,443,662,81,667,27,912,602,957,822,164,489,942,414,549,991,747,680,498,831,805,89,846,467,909,7,651,250,534,984,587,348,150,329,194,20,519,250,232,224,378,539,83,177,872,130,419,387,654,917,259,447,979,184,965,51,349,422,983,682,172,177,177,484,652,930,495,65,511,318,621,297,803,476,370,826,328,150,354,393,900,340,73,781,70,260,293,862,335,395,51,326,363,78,968,446,565,683,654,767,719,324,2,617,451,56,789,464,119,53,269,369,137,612,54,217,719,823,601,663,310,594,301,636,22,333,351,126,810,812,827,634,441,534,434,967,637,795,335,965,876,778,987,217,451,264,341,566,656,612,413,682,429,161,801,167,309,846,754,541,9,711,707,848,989,580,20,431,163,252,200,54,56,666,425,592,513,230,894,20,260,282,297,129,414,326,577,184,698,620,138,131,236,848,995,879,354,107,67,92,260,531,757,640,305,848,959,416,109,513,769,131,501,197,225,358,67,663,761,742,83,648,230,59,873,231,228,470,503,615,245,258,84,832,132,156,324,27,583,766,676,130,978,306,387,733,592,763,592,487,504,493,139,897,290,432,976,946,24,586,104,648,333,2,359,166,968,990,39,353,376,839,9,75,874,203,762,489,21,14,888,570,449,539,772,919,697,883,278,18,151,113,148,330,158,772,852,93,288,213,299,338,297,862,371,708,815,108,326,115,923,541,144,521,441,99,773,950,519,948,258,328,624,936,681,935,328,70,826,110,153,236,191,222,340,653,918,976,857,184,193,397,39,190,147,763,760,95,917,559,529,680,376,389,215,705,586,205,653,324,960,33,404,888,680,95,263,860,150,683,930,588,9,690,919,745,815,331,425,879,648,398,2,997,865,429,399,264,704,699,333,126,753,565,529,35,520,94,401,552,592,543,864,23,764,763,51,631,348,198,255,73,281,996,371,23,581,84,367,469,604,716,393,942,764,239,502,501,973,438,760,398,158,853,178,348,659,1000,739,296,444,587,528,355,867,615,847,885,160,357,618,959,330,82,182,59,224,355,250,270,447,534,97,590,284,909,406,954,419,909,158,626,818,350,994,609,540,957,152,827,830,386,380,318,580,853,440,789,432,710,955,381,241,930,880,632,750,876,189,662,127,434,38,144,20,424,27,466,538,158,416,508,990,650,698,990,970,663,121,9,713,489,977,530,694,141,930,169,695,305,567,368,777,442,668,746,618,86,592,185,328,772,213,644,440,178,243,774,467,991,455,404,919,197,830,568,661,826,841,695,52,982,515,47,47,198,9,272,425,975,472,9,302,338,470,542,247,492,367,180,708,521,592,58,572,887,670,314,191,280,256,845,971,157,725,862,452,76,200,538,44,324,992,459,196,18,64,147,423,187,191,246,305,973,802,832,436,444,242,979,351,733,459,825,833,691,372,861,617,618,190,57,848,527,56,378,533,308,430,473,701,401,871,790,459,216,983,305,61,391,251,447,661,951,150,28,572,206,299,477,703,301,227,960,866,450,335,337,852,906,956,873,893,867,196,131,456,608,688,840,569,91,922,606,961,906,836,168,838,91,607,186,754,708,477,248,138,211,458,17,509,645,629,816,47,185,661,856,508,984,320,763,297,9,446,970,472,12,386,476,686,940,387,721,546,206,110,349,88,781,150,308,136,809,670,291,767,889,926,999,832,462,706,13,9,753,458,309,984,404,801,366,56,611,38,691,174,670,306,229,12,151,697,415,180,655,418,975,781,40,448,625,775,722,350,163,397,634,102,961,322,354,836,652,877,997,397,957,640,70,467,976,901,792,173,869,248,829,919,89,324,9,639,560,744,890,846,452,197,558,756,988,771,573,494,64,423,348,296,587,327,909,371,24,369,174,132,197,412,142,257,790,770,171,875,724,608,329,256,626,868,22,311,499,933,173,78,631,931,191,132,970,194,778,33,832,75,76,63,271,905,164,970,716,216,828,56,131,898,565,791,47,634,205,118,280,605,896,433,38,39,303,242,746,673,541,759,588,990,586,244,152,586,371,666,361,691,815,658,537,371,482,656,117,316,327,368,657,848,557,761,221,147,673,945,914,976,579,804,405,182,89,429,133,485,939,586,452,20,292,108,747,188,899,293,125,976,573,162,592,880,241,685,191,539,361,430,84,791,903,475,96,388,485,416,583,944,939,987,939,545,474,272,494,664,543,480,812,212,400,728,28,379,410,127,607,59,614,883,509,695,765,533,665,754,848,268,159,678,807,325,125,92,208,216,337,697,778,466,861,22,950,74,804,925,617,159,73,676,712,558,487,711,774,383,817,737,555,811,304,743,27,67,535,426,766,615,102,437,765,291,718,641,951,255,375,442,204,108,455,592,364,457,758,486,593,780,277,789,323,404,473,258,953,318,898,555,390,727,510,783,427,806,92,33,474,858,851,783,12,752,356,942,307,235,397,915,502,939}; - int target = 28; - int[] result = new Solution().twoSum(nums, target); - System.out.println("[" + result[0] + " ," + result[1] + "]"); - } -} diff --git a/[001][Two Sum]/src/Solution.java b/[001][Two Sum]/src/Solution.java deleted file mode 100644 index 01bd269..0000000 --- a/[001][Two Sum]/src/Solution.java +++ /dev/null @@ -1,74 +0,0 @@ -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Author: 王俊超 - * Date: 2015-06-17 - * Time: 20:27 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - - /** - *
-     * Given an array of integers, find two numbers such that they add up to a specific target number.
-     * The function twoSum should return indices of the two numbers such that they add up to the target,
-     * where index1 must be less than index2. Please note that your returned answers (both index1 and index2)
-     * are not zero-based.
-     * You may assume that each input would have exactly one solution.
-     *
-     * Input: numbers={2, 7, 11, 15}, target=9
-     * Output: index1=1, index2=2
-     *
-     * 题目大意
-     * 给定一个整数数组,找出其中两个数满足相加等于你指定的目标数字。
-     * 要求:这个函数twoSum必须要返回能够相加等于目标数字的两个数的索引,且index1必须要小于index2。
-     * 请注意一点,你返回的结果(包括index1和index2)都不是基于0开始的。你可以假设每一个输入肯定只有一个结果。
-     *
-     * 解题思路
-     * 创建一个辅助类数组,对辅助类进行排序,使用两个指针,开始时分别指向数组的两端,看这两个下标对应的值是否
-     * 等于目标值,如果等于就从辅助类中找出记录的下标,构造好返回结果,返回。如果大于就让右边的下标向左移,
-     * 进入下一次匹配,如果小于就让左边的下标向右移动,进入下一次匹配,直到所有的数据都处理完
-     * 
- * - * @param nums - * @param target - * @return - */ - - public int[] twoSum(int[] nums, int target) { - int[] result = {0, 0}; - - // 因为无素可能会重复 - Map> map = new HashMap<>(nums.length); - - for (int i = 0; i < nums.length; i++) { - if (map.containsKey(nums[i])) { - map.get(nums[i]).add(i); - } else { - List list = new ArrayList<>(); - list.add(i); - map.put(nums[i], list); - } - } - - for (int num : nums) { - int gap = target - num; - if (map.containsKey(gap)) { - // 同样的元素最多只可以有两个 - if (gap == num && map.get(num).size() >= 2) { - List list = map.get(num); - result[0] = Math.min(list.get(0), list.get(1)); - result[1] = Math.max(list.get(0), list.get(1)); - } else if (gap != num){ - result[0] = Math.min(map.get(num).get(0), map.get(gap).get(0)); - result[1] = Math.max(map.get(num).get(0), map.get(gap).get(0)); - } - } - } - - return result; - } -} diff --git a/[001][Two Sum]/src/Solution2.java b/[001][Two Sum]/src/Solution2.java deleted file mode 100644 index 37103d1..0000000 --- a/[001][Two Sum]/src/Solution2.java +++ /dev/null @@ -1,94 +0,0 @@ -import java.util.Arrays; - -/** - * Author: 王俊超 - * Date: 2015-06-17 - * Time: 20:27 - * Declaration: All Rights Reserved !!! - */ -public class Solution2 { - private static class Node implements Comparable { - int val; - int idx; - - public Node() { - } - - public Node(int val, int idx) { - this.val = val; - this.idx = idx; - } - - @Override - public int compareTo(Node o) { - if (o == null) { - return -1; - } - return this.val - o.val; - } - } - - - /** - *
-     * Given an array of integers, find two numbers such that they add up to a specific target number.
-     * The function twoSum should return indices of the two numbers such that they add up to the target,
-     * where index1 must be less than index2. Please note that your returned answers (both index1 and index2)
-     * are not zero-based.
-     * You may assume that each input would have exactly one solution.
-     *
-     * Input: numbers={2, 7, 11, 15}, target=9
-     * Output: index1=1, index2=2
-     *
-     * 题目大意
-     * 给定一个整数数组,找出其中两个数满足相加等于你指定的目标数字。
-     * 要求:这个函数twoSum必须要返回能够相加等于目标数字的两个数的索引,且index1必须要小于index2。
-     * 请注意一点,你返回的结果(包括index1和index2)都不是基于0开始的。你可以假设每一个输入肯定只有一个结果。
-     *
-     * 解题思路
-     * 创建一个辅助类数组,对辅助类进行排序,使用两个指针,开始时分别指向数组的两端,看这两个下标对应的值是否
-     * 等于目标值,如果等于就从辅助类中找出记录的下标,构造好返回结果,返回。如果大于就让右边的下标向左移,
-     * 进入下一次匹配,如果小于就让左边的下标向右移动,进入下一次匹配,直到所有的数据都处理完
-     * 
- * - * @param nums - * @param target - * @return - */ - - public int[] twoSum(int[] nums, int target) { - int[] result = {0, 0}; - - Node[] tmp = new Node[nums.length]; - for (int i = 0; i < nums.length; i++) { - tmp[i] = new Node(nums[i], i); - } - - // 先排序,然后左右夹逼,排序O(n log n),左右夹逼O(n),最终O(n log n)。但是注 - // 意,这题需要返回的是下标,而不是数字本身,因此这个方法不好。 - Arrays.sort(tmp); - - int lo = 0; - int hi = nums.length - 1; - - - while (lo < hi) { - if (tmp[lo].val + tmp[hi].val == target) { - - if (tmp[lo].idx > tmp[hi].idx) { - result[0] = tmp[hi].idx + 1; - result[1] = tmp[lo].idx + 1; - } else { - result[0] = tmp[lo].idx + 1; - result[1] = tmp[hi].idx + 1; - } - break; - } else if (tmp[lo].val + tmp[hi].val > target) { - hi--; - } else { - lo++; - } - } - return result; - } -} diff --git a/[002][Add Two Numbers]/src/ListNode.java b/[002][Add Two Numbers]/src/ListNode.java deleted file mode 100644 index 2292cb5..0000000 --- a/[002][Add Two Numbers]/src/ListNode.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 16:05 - * Declaration: All Rights Reserved !!! - */ -public class ListNode { - int val; - ListNode next; - - ListNode(int val) { - this.val = val; - } -} diff --git a/[002][Add Two Numbers]/src/Solution.java b/[002][Add Two Numbers]/src/Solution.java deleted file mode 100644 index 8839d26..0000000 --- a/[002][Add Two Numbers]/src/Solution.java +++ /dev/null @@ -1,89 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 16:04 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * You are given two linked lists representing two non-negative numbers.
-     * The digits are stored in reverse order and each of their nodes contain
-     * a single digit. Add the two numbers and return it as a linked list.
-     * Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
-     * Output: 7 -> 0 -> 8
-     *
-     * Ŀ
-     * ǸÿһڵһλǷ洢ģ
-     * һʾλһʾλӺͣʽء
-     *
-     * ˼·
-     * ӵһʼӣٳ10̣ΪһλӵĽλ
-     * ͬʱ¼ΪλĽһֱֱеĽ㶼ꡣ
-     * 
- * - * @param l1 һ - * @param l2 ڶ - * @return - */ - public ListNode addTwoNumbers(ListNode l1, ListNode l2) { - - if (l1 == null) { - return l2; - } - - if (l2 == null) { - return l1; - } - - ListNode p1 = l1; - ListNode p2 = l2; - // ͷ - ListNode root = new ListNode(0); - ListNode r = root; - root.next = l1; - - // ʼλ - int carry = 0; - int sum; - while (p1 != null && p2 != null) { - sum = p1.val + p2.val + carry; - // λĽ - p1.val = sum % 10; - // νλ - carry = sum / 10; - - r.next = p1; - // ָһӵĽ - r = p1; - p1 = p1.next; - p2 = p2.next; - - } - - if (p1 == null) { - r.next = p2; - } else { - r.next = p1; - } - - // һӻнλ - if (carry == 1) { - // ʼʱr.nextǵһҪӵĽ - while (r.next != null) { - sum = r.next.val + carry; - r.next.val = sum % 10; - carry = sum / 10; - r = r.next; - } - - // ˻нλҪһµĽ - if (carry == 1) { - r.next = new ListNode(1); - } - } - - return root.next; - } -} diff --git a/[003][Longest Substring Without Repeating Characters]/src/Solution.java b/[003][Longest Substring Without Repeating Characters]/src/Solution.java deleted file mode 100644 index be83bb1..0000000 --- a/[003][Longest Substring Without Repeating Characters]/src/Solution.java +++ /dev/null @@ -1,91 +0,0 @@ -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - -/** - * Author: - * Date: 2015-06-17 - * Time: 20:46 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Given a string, find the length of the longest substring without repeating characters.
-     * For example, the longest substring without repeating letters for "abcabcbb" is "abc",
-     * which the length is 3. For "bbbbb" the longest substring is "b", with the length of 1.
-     *
-     * Ŀ⣺
-     * һַַеظӴ
-     *
-     * ˼·
-     * start¼Ŀʼλ
-     * ַǰַӿʼλstartʼѾֹʱӴʼλ+1mapеhashֵΪǰλá
-     * 
- * - * @param s - * @return - */ - // ԴеUTF-8ַ - public int lengthOfLongestSubstring(String s) { - // ַ벻Ϸ - if (s == null) { - return 0; - } - - // ǰĿʼλ - int start = 0; - // - int result = 0; - // ʱǣ¼һηʵַλ - Map map = new HashMap<>(s.length()); - - for (int i = 0; i < s.length(); i++) { - char ch = s.charAt(i); - // ַѾֹ(ڱǿλ)±start - if (map.containsKey(ch) && map.get(ch) >= start) { - start = map.get(ch) + 1; - } - // ûгֹķظӴij - else { - result = Math.max(result, i - start + 1); - } - - // ·ʼ¼ - map.put(ch, i); - } - return result; - } - - // ֻASCIIַ - public int lengthOfLongestSubstring2(String s) { - // ַ벻Ϸ - if (s == null) { - return 0; - } - - // ַǷֹҼ¼ǵһηʵԪصλ - int[] appear = new int[256]; - // ʼΪ-1 - Arrays.fill(appear, -1); - // ǰĿʼλ - int start = 0; - // - int result = 0; - - for (int i = 0; i < s.length(); i++) { - // ַѾֹ(ڱǿλ)±start - if (appear[s.charAt(i)] >= start) { - start = i + 1; - } - // ûгֹķظӴij - else { - result = Math.max(result, i - start + 1); - } - // ǵiַѾʹǵiλã - appear[s.charAt(i)] = i; - } - - return result; - } -} diff --git a/[004][Median of Two Sorted Arrays]/src/Main.java b/[004][Median of Two Sorted Arrays]/src/Main.java deleted file mode 100644 index 06c2105..0000000 --- a/[004][Median of Two Sorted Arrays]/src/Main.java +++ /dev/null @@ -1,35 +0,0 @@ -import org.junit.Assert; -import org.junit.Test; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-14 13:21 - **/ -public class Main { - - @Test - public void test() { - int[] nums1 = {1, 3}; - int[] nums2 = {2}; - Solution solution = new Solution(); - Assert.assertEquals(2, solution.findMedianSortedArrays(nums1, nums2), 0.000001); - } - - @Test - public void test2() { - int[] nums1 = {1, 2}; - int[] nums2 = {3, 4}; - Solution solution = new Solution(); - Assert.assertEquals(2.5, solution.findMedianSortedArrays(nums1, nums2), 0.000001); - } - - @Test - public void test3() { - int[] nums1 = {6}; - int[] nums2 = {1, 2, 3, 4, 5}; - Solution solution = new Solution(); - Assert.assertEquals(3.5, solution.findMedianSortedArrays(nums1, nums2), 0.000001); - } - - -} diff --git a/[004][Median of Two Sorted Arrays]/src/Solution.java b/[004][Median of Two Sorted Arrays]/src/Solution.java deleted file mode 100644 index 4303371..0000000 --- a/[004][Median of Two Sorted Arrays]/src/Solution.java +++ /dev/null @@ -1,90 +0,0 @@ -/** - * Author: - * Date: 2015-06-17 - * Time: 20:54 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * There are two sorted arrays nums1 and nums2 of size m and n respectively.
-     * Find the median of the two sorted arrays. The overall run time complexity
-     * should be O(log (m+n)).
-     *
-     * Ŀ⣺
-     * 飬λʱ临ӶΪO(log(m+n))
-     *
-     * ˼·
-     * ݹ
-     * 
- * - * @param nums1 - * @param nums2 - * @return - */ - public double findMedianSortedArrays(int[] nums1, int[] nums2) { - int total = nums1.length + nums2.length; - if (total % 2 != 0) { - return findKth(nums1, 0, nums2, 0, total / 2 + 1); - } else { - return (findKth(nums1, 0, nums2, 0, total / 2) - + findKth(nums1, 0, nums2, 0, total / 2 + 1) - ) / 2.0; - } - } - - /** - * ҵkԪأk=1, 2, 3, ... - * - * @param nums1 - * @param nums2 - * @param k - * @return - **/ - - public int findKth(int[] nums1, final int start1, - int[] nums2, final int start2, - final int k) { - // ҪҳСķǰ - if (nums1.length - start1 > nums2.length - start2) { - return findKth(nums2, start2, nums1, start1, k); - } - - if (nums1.length == start1) { - return nums2[start2 + k - 1]; - } - - // һбȽС - if (k == 1) { - return Math.min(nums1[start1], nums2[start2]); - } - - - // num1, nums2иһ൱ÿζҪ1/4 - int half = Math.min(k / 2, nums1.length - start1); - // nums2пҵλ - int ia = half + start1; - // nums2пҵλ - int ib = k - half + start2; - - // nums1[start, ..., ia-1, ia, ..., nums1.length] - // nums2[start, ..., ib-1, ib, ..., nums2.length] - // ˵nums1[start, ..., ia-1]ˣҪҵֵnums1[ia, ..., nums1.length] - // nums2[start, ..., ib-1, ib, ..., nums2.length] - if (nums1[ia - 1] < nums2[ib - 1]) { - // k - (ia - start1) = k - (half + start1 - start1)=k - half - return findKth(nums1, ia, nums2, start2, k - (ia - start1)); - } - - // ˵nums2[start, ..., ib-1]ˣҪҵֵnums2[ib, ..., nums2.length] - // nums1[start, ..., ia-1, ia, ..., nums1.length] - else if (nums1[ia - 1] > nums2[ib - 1]) { - // k - (ib - start2) = k - (k - half + start2 - start2) - return findKth(nums1, start1, nums2, ib, half); - } - // ֵ˵ҵˣ - else { - return nums1[ia - 1]; - } - } -} diff --git a/[004][Median of Two Sorted Arrays]/src/Solution2.java b/[004][Median of Two Sorted Arrays]/src/Solution2.java deleted file mode 100644 index 601e821..0000000 --- a/[004][Median of Two Sorted Arrays]/src/Solution2.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * Author: - * Date: 2015-06-17 - * Time: 20:54 - * Declaration: All Rights Reserved !!! - */ -public class Solution2 { - /** - *
-     * There are two sorted arrays nums1 and nums2 of size m and n respectively.
-     * Find the median of the two sorted arrays. The overall run time complexity
-     * should be O(log (m+n)).
-     *
-     * Ŀ⣺
-     * 飬λʱ临ӶΪO(log(m+n))
-     *
-     * ˼·
-     * ݹ
-     * 
- * - * @param nums1 - * @param nums2 - * @return - */ - public double findMedianSortedArrays(int[] nums1, int[] nums2) { - - if (nums1 == null) { - nums1 = new int[0]; - } - - if (nums2 == null) { - nums2 = new int[0]; - } - - int len1 = nums1.length; - int len2 = nums2.length; - - if (len1 < len2) { - // ȷһȵڶ鳤ȴ - return findMedianSortedArrays(nums2, nums1); - } - - // С鳤Ϊ0ͷǰһλ - if (len2 == 0) { - return (nums1[(len1 - 1) / 2] + nums1[len1 / 2]) / 2.0; - } - - - int lo = 0; - int hi = len2 * 2; - int mid1; - int mid2; - double l1; - double l2; - double r1; - double r2; - - while (lo <= hi) { - mid2 = (lo + hi) / 2; - mid1 = len1 + len2 - mid2; - - l1 = (mid1 == 0) ? Integer.MIN_VALUE : nums1[(mid1 - 1) / 2]; - l2 = (mid2 == 0) ? Integer.MIN_VALUE : nums2[(mid2 - 1) / 2]; - - r1 = (mid1 == len1 * 2) ? Integer.MAX_VALUE : nums1[mid1 / 2]; - r2 = (mid2 == len2 * 2) ? Integer.MAX_VALUE : nums2[mid2 / 2]; - - if (l1 > r2) { - lo = mid2 + 1; - } else if (l2 > r1) { - hi = mid2 - 1; - } else { - return (Math.max(l1, l2) + Math.min(r1, r2)) / 2; - } - } - - return -1; - } -} diff --git a/[005][Longest Palindromic Substring Total]/src/Main.java b/[005][Longest Palindromic Substring Total]/src/Main.java deleted file mode 100644 index 4edaf03..0000000 --- a/[005][Longest Palindromic Substring Total]/src/Main.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Author: - * Date: 2015-06-29 - * Time: 21:01 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { - Solution solution = new Solution(); - System.out.println(solution.longestPalindrome("abcba")); - } -} diff --git a/[005][Longest Palindromic Substring Total]/src/Solution.java b/[005][Longest Palindromic Substring Total]/src/Solution.java deleted file mode 100644 index 7409c74..0000000 --- a/[005][Longest Palindromic Substring Total]/src/Solution.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Author: - * Date: 2015-06-17 - * Time: 21:24 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Given a string S, find the longest palindromic substring in S.
-     * You may assume that the maximum length of S is 1000, and there
-     * exists one unique longest palindromic substring.
-     *
-     * Ŀ⣺
-     * һַSҳĻӴԼַ󳤶1000
-     * ҴΨһӴ
-     *
-     * ˼·
-     * ̬滮
-     * dp[ i ][ j ]ֵΪtrueʾַs± i  j ַɵӴǻĴôƳ
-     * dp[ i ][ j ] = dp[ i + 1][ j - 1] && s[ i ] == s[ j ]
-     * һҪi+1, j -1п i + 1 = j -1, i +1 = (j - 1) -1
-     * Ҫ׼ϵĹʽ
-     *
-     * a. i + 1 = j -1ijΪ1ʱdp[ i ][ i ] = true;
-     * b. i +1 = (j - 1) -1ijΪ2ʱdp[ i ][ i + 1] = (s[ i ] == s[ i + 1])
-     *
-     * ϷͿдˡҪעǶ̬滮ҪO(n^2)Ŀռ䡣
-     * 
- * - * @param s - * @return - */ - public String longestPalindrome(String s) { - - if (s == null || s.length() < 2) { - return s; - } - - int maxLength = 0; - String longest = null; - - int length = s.length(); - boolean[][] table = new boolean[length][length]; - - // ַǻ - for (int i = 0; i < length; i++) { - table[i][i] = true; - longest = s.substring(i, i + 1); - maxLength = 1; - } - - // жַǷǻ - for (int i = 0; i < length - 1; i++) { - if (s.charAt(i) == s.charAt(i + 1)) { - table[i][i + 1] = true; - longest = s.substring(i, i + 2); - maxLength = 2; - } - } - - - // 󳤶ȴ2ӴǷǻĴ - for (int len = 3; len <= length; len++) { - for (int i = 0, j; (j = i + len - 1) <= length - 1; i++) { - if (s.charAt(i) == s.charAt(j)) { - table[i][j] = table[i + 1][j - 1]; - if (table[i][j] && maxLength < len) { - longest = s.substring(i, j + 1); - maxLength = len; - } - } else { - table[i][j] = false; - } - } - } - - return longest; - } - - -} diff --git a/[006][Zig Zag Conversion]/src/Solution.java b/[006][Zig Zag Conversion]/src/Solution.java deleted file mode 100644 index 3de4a90..0000000 --- a/[006][Zig Zag Conversion]/src/Solution.java +++ /dev/null @@ -1,94 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 16:08 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     *     ԭ
-     * The string PAYPALISHIRING is written in a zigzag pattern on a given number
-     * of rows like this: (you may want to display this pattern in a fixed font for
-     * better legibility)
-     * P A H N
-     * APLSIIG
-     * Y I R
-     * And then read line by line: PAHNAPLSIIGYIR
-     * Write the code that will take a string and make this conversion given a number of rows:
-     * string convert(string text, int nRows);
-     * convert(PAYPALISHIRING,3) should return PAHNAPLSIIGYIR.
-     * Ŀ
-     * һַַָZ
-     *
-     * ˼·
-     * ַһһά飬ټÿַһάеλã
-     * ٶһάеַнղؽ
-     * 
- * - * @param s - * @param nRows - * @return - */ - public String convert(String s, int nRows) { - - if (s == null || s.length() <= nRows || nRows == 1) { - return s; - } - - int index = s.length(); - int rowLength = 0; // еijȣַ - - int slash = nRows - 2; // һб߳ȥβռõ - - while (index > 0) { - // εһ - index -= nRows; - rowLength++; - - // бŵ - for (int i = 0; i < slash && index > 0; i++) { - rowLength++; - index--; - } - } - - char[] result = new char[nRows * rowLength]; // 飬һڱ滻з - for (int i = 0; i < result.length; i++) { // ʼΪո - result[i] = ' '; - } - - int curColumn = 0; // ǰ - index = 0; - while (index < s.length()) { - // - for (int i = 0; i < nRows && index < s.length(); i++) { - result[rowLength * i + curColumn] = s.charAt(index); - index++; - } - curColumn++; - // б - for (int i = nRows - 2; i > 0 && index < s.length(); i--) { - result[rowLength * i + curColumn] = s.charAt(index); - curColumn++; - index++; - } - } - - // ַнղ - index = 0; - while (index < s.length() && result[index] != ' ') { // ҵһǿոַλ - index++; - } - int next = index + 1; - while (index < s.length()) { - while (next < result.length && result[next] == ' ') { // ҲǿոԪ - next++; - } - result[index] = result[next]; - index++; - next++; - } - return new String(result, 0, index); - } -} diff --git a/[007][Reverse Integer]/src/Solution.java b/[007][Reverse Integer]/src/Solution.java deleted file mode 100644 index 00d3d95..0000000 --- a/[007][Reverse Integer]/src/Solution.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 16:10 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Reverse digits of an integer.
-     * Example1: x = 123, return 321
-     * Example2: x = -123, return -321
-     *
-     * Ŀ
-     * һзת
-     *
-     * ˼·
-     * ̷ͨв
-     * 
- * - * @param x - * @return - */ - public int reverse(int x) { - long tmp = x; - // ֹ - long result = 0; - - while (tmp != 0) { - result = result * 10 + tmp % 10; - tmp = tmp / 10; - } - - // ж - if (result < Integer.MIN_VALUE || result > Integer.MAX_VALUE) { - result = 0; - } - - return (int) result; - } -} diff --git a/[008][String To Integer (atoi)]/src/Solution.java b/[008][String To Integer (atoi)]/src/Solution.java deleted file mode 100644 index 6010b26..0000000 --- a/[008][String To Integer (atoi)]/src/Solution.java +++ /dev/null @@ -1,104 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 16:13 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Implement atoi to convert a string to an integer.
-     * Hint: Carefully consider all possible input cases. If you want a challenge,
-     * please do not see below and ask yourself what are the possible input cases.
-     * Notes: It is intended for this problem to be specified vaguely (ie, no given
-     * input specs). You are responsible to gather all the input requirements up front.
-     *
-     * Ŀ
-     * ʵһatoiַת
-     * Ҫ㣺е
-     *
-     * ˼·
-     * ǰַ+-ûУֲ֣ܱʾС
-     * ͷضӦССֵ
-     * 
- * - * @param str - * @return - */ - public int atoi(String str) { - - if (str == null || str.length() == 0) { -// throw new NumberFormatException("Invalid input string: " + str); - return 0; - } - - // ַԿոʼ - int start = 0; //ӿʼҵһǿո - boolean positive = true; // ǷΪĬΪtrue - - if (str.charAt(start) == ' ') { - while (str.charAt(start) == ' ') { - start++; - if (start >= str.length()) { // ȫǿո -// throw new NumberFormatException("Invalid input string: " + str); - return 0; - } - } - } - - if (str.charAt(start) == '-') { // һǿհַ- - positive = false; - start++; - } else if (str.charAt(start) == '+') {// һǿհַ+ - start++; - } else if (str.charAt(start) >= '0' && str.charAt(start) <= '9') { // һǿհַ - return cal(str, start, true); - } else { // ׳쳣 -// throw new NumberFormatException("Invalid input string: " + str); - return 0; - } - - - if (start >= str.length()) { // һǿհַ+-Ҳһַ -// throw new NumberFormatException("Invalid input string: " + str); - return 0; - } - - if (str.charAt(start) > '9' || str.charAt(start) < '0') { // +-ӵIJ -// throw new NumberFormatException("Invalid input string: " + str); - return 0; - } else { - return cal(str, start, positive); - } - } - - private int cal(String str, int start, boolean positive) { - - long result = 0; - while (start < str.length() && str.charAt(start) >= '0' && str.charAt(start) <= '9') { - result = result * 10 + (str.charAt(start) - '0'); - - if (positive) { // - if (result > Integer.MAX_VALUE) { -// throw new NumberFormatException("Invalid input string: " + str); - return Integer.MAX_VALUE; - } - - } else { - if (-result < Integer.MIN_VALUE) { -// throw new NumberFormatException("Invalid input string: " + str); - return Integer.MIN_VALUE; - } - } - - start++; - } - - if (positive) { - return (int) result; - } else { - return (int) -result; - } - } -} diff --git a/[009][Palindrome Number]/src/Main.java b/[009][Palindrome Number]/src/Main.java deleted file mode 100644 index e04c77b..0000000 --- a/[009][Palindrome Number]/src/Main.java +++ /dev/null @@ -1,13 +0,0 @@ -import org.junit.Test; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-16 11:06 - **/ -public class Main { - @Test - public void test1() { - Solution solution = new Solution(); - System.out.println(solution.isPalindrome(123321)); - } -} diff --git a/[009][Palindrome Number]/src/Solution.java b/[009][Palindrome Number]/src/Solution.java deleted file mode 100644 index 318a64d..0000000 --- a/[009][Palindrome Number]/src/Solution.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 16:52 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Determine whether an integer is a palindrome. Do this without extra space.
-     *
-     * Ŀ
-     * жһǷǻطҪʹöĿռ䡣
-     *
-     * ˼·
-     * Ϊ˲ʹöĿռ䣬οĽЩⷨisPalindromeûʹö
-     * ȴʹ˷ãһĵĿռ ûдﵽĿҪǼٵʵ֣
-     * ԱȻһĿռʵ֡
-     *  ȣǻ֣ζֽת123321任˵ǻ֡
-     * 
- * - * @param x - * @return - */ - public boolean isPalindrome(int x) { - - // ǻط - if (x < 0) { - return false; - } - - // תֵΪ˲ʹlong - long reverse = 0; - int tmp = x; - - // תֵ - while (tmp != 0) { - reverse = reverse * 10 + tmp % 10; - tmp /= 10; - } - - // жǷǻ - return x == reverse; - } -} diff --git a/[010][Regular Expression Matching]/src/Main.java b/[010][Regular Expression Matching]/src/Main.java deleted file mode 100644 index 8d9da5d..0000000 --- a/[010][Regular Expression Matching]/src/Main.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Author: - * Date: 2015-06-24 - * Time: 21:34 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { - Solution solution = new Solution(); - System.out.println(solution.isMatch("aa", "a*")); - } -} diff --git a/[010][Regular Expression Matching]/src/Solution.java b/[010][Regular Expression Matching]/src/Solution.java deleted file mode 100644 index b462e2f..0000000 --- a/[010][Regular Expression Matching]/src/Solution.java +++ /dev/null @@ -1,120 +0,0 @@ -import java.util.Arrays; - -/** - * Author: - * Date: 2015-06-24 - * Time: 20:42 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Implement regular expression matching with support for '.' and '*'.
-     * '.' Matches any single character.
-     * '*' Matches zero or more of the preceding element.
-     *
-     * The matching should cover the entire input string (not partial).
-     *
-     * The function prototype should be:
-     * bool isMatch(const char *s, const char *p)
-     * Some examples:
-     * isMatch("aa","a")  false
-     * isMatch("aa","aa")  true
-     * isMatch("aaa","aa")  false
-     * isMatch("aa", "a*")  true
-     * isMatch("aa", ".*")  true
-     * isMatch("ab", ".*")  true
-     * isMatch("aab", "c*a*b")  true
-     *
-     * Ŀ⣺
-     * ʵһʽƥ㷨.ƥһַ*ƥ0߶ǰַ
-     *
-     * Կ˼·
-     * ע
-     *
-     * 
- * - * @param s - * @param p - * @return - */ - public boolean isMatch(String s, String p) { - boolean[] match = new boolean[s.length() + 1]; - Arrays.fill(match, false); - match[s.length()] = true; - for (int i = p.length() - 1; i >= 0; i--) { - if (p.charAt(i) == '*') { - for (int j = s.length() - 1; j >= 0; j--) { - match[j] = match[j] || match[j + 1] - && (p.charAt(i - 1) == '.' || s.charAt(j) == p.charAt(i - 1)); - } - i--; - } else { - for (int j = 0; j < s.length(); j++) { - match[j] = match[j + 1] - && (p.charAt(i) == '.' || p.charAt(i) == s.charAt(j)); - } - - match[s.length()] = false; - } - } - return match[0]; - } - - // ĴʱȽϳ - public boolean isMatch2(String s, String p) { - // 붼Ϊnull - if (s == null && p == null) { - return true; - } - // һΪnull - else if (s == null || p == null) { - return false; - } - - return isMatch(s, 0, p, 0); - } - - /** - * ʽƥ - * - * @param s ƥ䴮 - * @param sIdx ǰƥλ - * @param p ģʽ - * @param pIdx ģʽƥλ - * @return ƥ - */ - public boolean isMatch(String s, int sIdx, String p, int pIdx) { - // ͬʱԵĩβ - if (s.length() == sIdx && p.length() == pIdx) { - return true; - } - // ƥ䴮ûеĩβģʽѾĩβ - else if (s.length() != sIdx && p.length() == pIdx) { - return false; - } - // - else { - // ǰƥһַ* - if (pIdx < p.length() - 1 && p.charAt(pIdx + 1) == '*') { - // ƥ䴮δҵǰַƥ䣨ַȻ.ţ - if (sIdx < s.length() && (s.charAt(sIdx) == p.charAt(pIdx) || p.charAt(pIdx) == '.')) { - return isMatch(s, sIdx + 1, p, pIdx + 2) // ƥ䴮ǰƶһַֻƥһΣ - || isMatch(s, sIdx + 1, p, pIdx) // ƥ䴮ǰƶһַһƥͬģģʽ - || isMatch(s, sIdx, p, pIdx + 2); // ƥģʽ - } else { - // * - return isMatch(s, sIdx, p, pIdx + 2); - } - } - - // ƥһַ - if (sIdx < s.length() && (s.charAt(sIdx) == p.charAt(pIdx) || p.charAt(pIdx) == '.')) { - return isMatch(s, sIdx + 1, p, pIdx + 1); - } - } - - return false; - } - -} diff --git a/[011][Container With Most Water]/src/Solution.java b/[011][Container With Most Water]/src/Solution.java deleted file mode 100644 index 7a40cf8..0000000 --- a/[011][Container With Most Water]/src/Solution.java +++ /dev/null @@ -1,88 +0,0 @@ -/** - * Author: - * Date: 2015-06-30 - * Time: 07:25 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Given n non-negative integers a1, a2, ..., an, where each represents
-     * a point at coordinate (i, ai). n vertical lines are drawn such that
-     * the two endpoints of line i is at (i, ai) and (i, 0). Find two lines,
-     * which together with x-axis forms a container, such that the container
-     * contains the most water.
-     *
-     * Note: You may not slant the container.
-     *
-     * Ŀ⣺
-     * ȻԼXṹɵˮ
-     *
-     * ˼·
-     * ʹ̰㷨
-     *      1.ȼҵȡݻΪ i, j (ٶi aj) 
-     *          ô   ak > aj min(ai, aj, ak) =min(ai, aj) 
-     *          i, kɵݻC' = min(ai, aj) * (k - i) > C
-     *          CֵìܣԵ֤jĺ߲бߵߣ
-     *
-     *          :ͬiҲбߵߣ˵ʲôأ
-     *          Ŀǰõĺѡ Ϊ x, yߣx< y)ôܹõ
-     *          ݻµ߱Ȼ[x, y]ڲ ax' >= ax , ay' >= ay;
-     *
-     *      3.Ǵͷм俿£ͬʱºѡֵʱȴ
-     *      x, yнСı߿ʼ
-     * 
- * - * @param height - * @return - */ - public int maxArea(int[] height) { - - // У - if (height == null || height.length < 2) { - return 0; - } - - - // ¼Ľ - int result = 0; - - // ߵ - int left = 0; - // ұߵ - int right = height.length - 1; - - while (left < right) { - // 㵱ǰֵ - result = Math.max(result, Math.min(height[left], height[right]) * (right - left)); - // ұ߸ - if (height[left] < height[right]) { - int k = left; - // [left, right - 1]Уңҵһ߶ȱheight[left]ߵλ - while (k < right && height[k] <= height[left]) { - k++; - } - - // [left, right - 1]У¼һԭheight[left]ߵλ - left = k; - } - // ߵ߸ - else { - int k = right; - // [left + 1, right]Уңҵһ߶ȱheight[right]ߵλ - while (k > left && height[k] <= height[right]) { - k--; - } - - // [left, right - 1]У¼һԭheight[right]ߵλ - right = k; - } - } - - return result; - } -} diff --git a/[012][Integer To Roman]/src/Main.java b/[012][Integer To Roman]/src/Main.java deleted file mode 100644 index 395df1b..0000000 --- a/[012][Integer To Roman]/src/Main.java +++ /dev/null @@ -1,39 +0,0 @@ -import org.junit.Assert; -import org.junit.Test; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-17 14:03 - **/ -public class Main { - - @Test - public void test1() { - Solution2 solution = new Solution2(); - Assert.assertEquals("III", solution.intToRoman(3)); - } - - @Test - public void test2() { - Solution2 solution = new Solution2(); - Assert.assertEquals("IV", solution.intToRoman(4)); - } - - @Test - public void test3() { - Solution2 solution = new Solution2(); - Assert.assertEquals("IX", solution.intToRoman(9)); - } - - @Test - public void test4() { - Solution2 solution = new Solution2(); - Assert.assertEquals("LVIII", solution.intToRoman(58)); - } - - @Test - public void test5() { - Solution2 solution = new Solution2(); - Assert.assertEquals("MCMXCIV", solution.intToRoman(1994)); - } -} diff --git a/[012][Integer To Roman]/src/Solution.java b/[012][Integer To Roman]/src/Solution.java deleted file mode 100644 index 2224976..0000000 --- a/[012][Integer To Roman]/src/Solution.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Author: - * Date: 2015-06-30 - * Time: 14:28 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Given an integer, convert it to a roman numeral.
-     *
-     * Input is guaranteed to be within the range from 1 to 3999.
-     *
-     * ֵıʾ
-     * λ
-     * (I, 1)  (II, 2)  (III, 3)  (IV, 4)  (V, 5)  (VI, 6)  (VII, 7)  (VIII, 8)  (IX, 9)
-     *
-     * ʮλ
-     * (X, 10)  (XI, 11)  (XII, 12)  (XIII, 13)  (XIV, 14)  (XV, 15)  (XVI, 16)
-     * (XVII, 17)  (XVIII, 18)  (XIX, 19)  (XX, 20)  (XXI, 21)  (XXII, 22)
-     * (XXIX, 29)  (XXX, 30)  (XXXIV, 34)  (XXXV, 35)  (XXXIX, 39)  (XL, 40)
-     * (L, 50)  (LI, 51)  (LV, 55)  (LX, 60)  (LXV, 65)  (LXXX, 80)  (XC, 90)
-     * (XCIII, 93)  (XCV, 95)  (XCVIII, 98)  (XCIX, 99)
-     *
-     * λ
-     * (C, 100)  (CC, 200)  (CCC, 300)  (CD, 400)  (D, 500)  (DC, 600)  (DCC, 700)
-     * (DCCC, 800)  (CM, 900)  (CMXCIX, 999)
-     *
-     * ǧλ
-     * (M, 1000)  (MC, 1100)  (MCD, 1400)  (MD, 1500)  (MDC, 1600)  (MDCLXVI, 1666)
-     * (MDCCCLXXXVIII, 1888)  (MDCCCXCIX, 1899)  (MCM, 1900)  (MCMLXXVI, 1976)
-     * (MCMLXXXIV, 1984)  (MCMXC, 1990)  (MM, 2000)  (MMMCMXCIX, 3999)
-     *
-     * Ŀ⣺
-     * һ֣תһ֣[1, 3999]֮
-     *
-     * 
- * - * @param num - * @return - */ - public String intToRoman(int num) { - - String[][] base = new String[][]{ - {"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"}, // λıʾ - {"X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"}, // ʮλıʾ - {"C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"}, // ٱıʾ - {"M", "MM", "MMM", "", "", "", "", "", ""}}; // ǧλıʾ - - - String result = ""; - - // ÿһξʾһλС - // i¼ǰǵڼλ - for (int i = 0; num != 0; num /= 10, i++) { - // Ϊ0˵λֵҪӲ - if (num % 10 != 0) { - // ƴӽ - result = base[i][num % 10 - 1] + result; - } - } - - return result; - } -} diff --git a/[012][Integer To Roman]/src/Solution2.java b/[012][Integer To Roman]/src/Solution2.java deleted file mode 100644 index f13fad7..0000000 --- a/[012][Integer To Roman]/src/Solution2.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Author: - * Date: 2015-06-30 - * Time: 14:28 - * Declaration: All Rights Reserved !!! - */ -public class Solution2 { - /** - *
-     * Given an integer, convert it to a roman numeral.
-     *
-     * Input is guaranteed to be within the range from 1 to 3999.
-     *
-     * ֵıʾ
-     * λ
-     * (I, 1)  (II, 2)  (III, 3)  (IV, 4)  (V, 5)  (VI, 6)  (VII, 7)  (VIII, 8)  (IX, 9)
-     *
-     * ʮλ
-     * (X, 10)  (XI, 11)  (XII, 12)  (XIII, 13)  (XIV, 14)  (XV, 15)  (XVI, 16)
-     * (XVII, 17)  (XVIII, 18)  (XIX, 19)  (XX, 20)  (XXI, 21)  (XXII, 22)
-     * (XXIX, 29)  (XXX, 30)  (XXXIV, 34)  (XXXV, 35)  (XXXIX, 39)  (XL, 40)
-     * (L, 50)  (LI, 51)  (LV, 55)  (LX, 60)  (LXV, 65)  (LXXX, 80)  (XC, 90)
-     * (XCIII, 93)  (XCV, 95)  (XCVIII, 98)  (XCIX, 99)
-     *
-     * λ
-     * (C, 100)  (CC, 200)  (CCC, 300)  (CD, 400)  (D, 500)  (DC, 600)  (DCC, 700)
-     * (DCCC, 800)  (CM, 900)  (CMXCIX, 999)
-     *
-     * ǧλ
-     * (M, 1000)  (MC, 1100)  (MCD, 1400)  (MD, 1500)  (MDC, 1600)  (MDCLXVI, 1666)
-     * (MDCCCLXXXVIII, 1888)  (MDCCCXCIX, 1899)  (MCM, 1900)  (MCMLXXVI, 1976)
-     * (MCMLXXXIV, 1984)  (MCMXC, 1990)  (MM, 2000)  (MMMCMXCIX, 3999)
-     *
-     * Ŀ⣺
-     * һ֣תһ֣[1, 3999]֮
-     *
-     * 
- * - * @param num - * @return - */ - public String intToRoman(int num) { - - final int[] radix = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}; - final String[] symbol = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"}; - String roman = ""; - for (int i = 0; num > 0; ++i) { - int count = num / radix[i]; - num %= radix[i]; - for (; count > 0; --count) { - roman += symbol[i]; - } - } - return roman; - } -} diff --git a/[013][Romar To Integer]/src/Main.java b/[013][Romar To Integer]/src/Main.java deleted file mode 100644 index 5d7ae8a..0000000 --- a/[013][Romar To Integer]/src/Main.java +++ /dev/null @@ -1,37 +0,0 @@ -import org.junit.Assert; -import org.junit.Test; - -/** - * Author: 王俊超 - * Date: 2015-03-01 - * Time: 16:35 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { - Solution solution = new Solution(); - - System.out.println(solution.romanToInt("I")); - System.out.println(solution.romanToInt("II")); - System.out.println(solution.romanToInt("III")); - System.out.println(solution.romanToInt("IV")); - System.out.println(solution.romanToInt("V")); - System.out.println(solution.romanToInt("VI")); - - System.out.println(solution.romanToInt("XCVIII")); - System.out.println(solution.romanToInt("XCIX")); - - System.out.println(solution.romanToInt("CM")); - System.out.println(solution.romanToInt("CMXCIX")); - - System.out.println(solution.romanToInt("MDCLXVI")); - System.out.println(solution.romanToInt("MCMLXXVI")); - System.out.println(solution.romanToInt("MMMCMXCIX")); - } - - @Test - public void test1() { - Solution solution = new Solution(); - Assert.assertEquals(1994, solution.romanToInt("MCMXCIV")); - } -} diff --git a/[013][Romar To Integer]/src/Solution.java b/[013][Romar To Integer]/src/Solution.java deleted file mode 100644 index f47e222..0000000 --- a/[013][Romar To Integer]/src/Solution.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Author: 王俊超 - * Date: 2015-03-01 - * Time: 16:09 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * 原题
-     * Given a roman numeral, convert it to an integer.
-     * Input is guaranteed to be within the range from 1 to 3999.
-     *
-     * 题目大意
-     * 给定一个罗马数字,将其转换成对应的整数。
-     * 输入的数字在1-3999之间。
-     *
-     * 解题思路
-     * 从前往后扫描,用一个临时变量记录分段数字。
-     * 如果当前比前一个大,说明这一段的值应该是当前这个值减去上一个值。比如IV = 5 – 1;否
-     * 则,将当前值加入到结果中,然后开始下一段记录。比如VI = 5 + 1, II=1+1
-     * 
- * - * @param s - * @return - */ - public int romanToInt(String s) { - - int result = 0; - - for (int i = 0; i < s.length(); i++) { - // 当前的值比前一个值大,说明[i-1, i]组成一个值,并且值是s[i-1]-s[i] - if (i > 0 && charToInt(s.charAt(i)) > charToInt(s.charAt(i - 1))) { - // 要减去两倍之前前值才能回到真实值 - result += charToInt(s.charAt(i)) - 2 * charToInt(s.charAt(i - 1)); - } else { - result += charToInt(s.charAt(i)); - } - } - - return result; - } - private int charToInt(char c) { - switch (c) { - case 'I': return 1; - case 'V': return 5; - case 'X': return 10; - case 'L': return 50; - case 'C': return 100; - case 'D': return 500; - case 'M': return 1000; - default: return 0; - } - } -} diff --git a/[013][Romar To Integer]/src/Solution2.java b/[013][Romar To Integer]/src/Solution2.java deleted file mode 100644 index 9d08f55..0000000 --- a/[013][Romar To Integer]/src/Solution2.java +++ /dev/null @@ -1,98 +0,0 @@ -/** - * Author: 王俊超 - * Date: 2015-03-01 - * Time: 16:09 - * Declaration: All Rights Reserved !!! - */ -public class Solution2 { - /** - *
-     * 原题
-     * Given a roman numeral, convert it to an integer.
-     * Input is guaranteed to be within the range from 1 to 3999.
-     *
-     * 题目大意
-     * 给定一个罗马数字,将其转换成对应的整数。
-     * 输入的数字在1-3999之间。
-     *
-     * 解题思路
-     * 根据罗马数字与整数数字对应关系进行加法操作,如果前一个数字比后一个大就相减,否则进行相加。
-     * 
- * - * @param s - * @return - */ - public int romanToInt(String s) { - - int result = 0; - int prev = 0; // 记录前一个数字的值 - - for (int i = s.length() - 1; i > -1; i--) { - switch (s.charAt(i)) { - case 'I': // 1 - if (1 < prev) { - result -= 1; - } else { - result += 1; - - } - prev = 1; - break; - - case 'V': // 5 - - if (5 < prev) { - result -= 5; - } else { - result += 5; - } - - prev = 5; - - break; - case 'X': // 10 - if (10 < prev) { - result -= 10; - } else { - result += 10; - } - - prev = 10; - break; - case 'L': // 50 - if (50 < prev) { - result -= 50; - } else { - result += 50; - } - - prev = 50; - break; - case 'C': // 100 - if (100 < prev) { - result -= 100; - } else { - result += 100; - } - - prev = 100; - break; - case 'D': // 500 - if (500 < prev) { - result -= 500; - } else { - result += 500; - } - - prev = 500; - break; - case 'M': // 1000 - result += 1000; - prev = 1000; - break; - } - } - - return result; - } -} diff --git a/[014][Longest Common Prefix]/src/Main.java b/[014][Longest Common Prefix]/src/Main.java deleted file mode 100644 index 5a40b00..0000000 --- a/[014][Longest Common Prefix]/src/Main.java +++ /dev/null @@ -1,20 +0,0 @@ -import org.junit.Assert; -import org.junit.Test; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-17 13:05 - **/ -public class Main { - @Test - public void test1() { - Solution solution = new Solution(); - Assert.assertEquals("fl", solution.longestCommonPrefix(new String[]{"flower", "flow", "flight"})); - } - - @Test - public void test2() { - Solution solution = new Solution(); - Assert.assertEquals("", solution.longestCommonPrefix(new String[]{"dog","racecar","car"})); - } -} diff --git a/[014][Longest Common Prefix]/src/Solution.java b/[014][Longest Common Prefix]/src/Solution.java deleted file mode 100644 index c7fd1ef..0000000 --- a/[014][Longest Common Prefix]/src/Solution.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 16:19 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Write a function to find the longest common prefix string amongst an array of strings.
-     *
-     * Ŀ
-     * дһҳһִеĹǰ׺
-     *
-     * ˼·
-     * һҳСַȻַַҳ̵ǰ׺
-     * 
- * - * @param strs - * @return - */ - public String longestCommonPrefix(String[] strs) { - if (strs == null) { - return null; - } - - if (strs.length == 0) { - return ""; - } - - // ¼̵ַij - int min = Integer.MAX_VALUE; - - // Ҷַij - String result = ""; - for (String str : strs) { - - if (str == null || str.length() == 0) { - return ""; - } - - if (min > str.length()) { - min = str.length(); - result = str; - } - } - - for (String s: strs) { - for (int i = 0; i < result.length(); i++) { - if (result.charAt(i) != s.charAt(i)) { - result = result.substring(0, i); - } - } - } - - return result; - } -} diff --git a/[014][Longest Common Prefix]/src/Solution2.java b/[014][Longest Common Prefix]/src/Solution2.java deleted file mode 100644 index 17eb282..0000000 --- a/[014][Longest Common Prefix]/src/Solution2.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 16:19 - * Declaration: All Rights Reserved !!! - */ -public class Solution2 { - /** - *
-     * ԭ
-     * Write a function to find the longest common prefix string amongst an array of strings.
-     *
-     * Ŀ
-     * дһҳһִеĹǰ׺
-     *
-     * ˼·
-     * һҳСַȻַַҳ̵ǰ׺
-     * 
- * - * @param strs - * @return - */ - public String longestCommonPrefix(String[] strs) { - if (strs == null) { - return null; - } - - if (strs.length == 0) { - return ""; - } - - // ¼̵ַij - int min = Integer.MAX_VALUE; - - // Ҷַij - for (String str : strs) { - - if (str == null) { - return null; - } - - if (min > str.length()) { - min = str.length(); - } - } - - int i; // ¼ǰ׺ַ - boolean flag; - for (i = 0; i < min; i++) { - flag = true; - for (int j = 1; j < strs.length; j++) { - if (strs[0].charAt(i) != strs[j].charAt(i)) { - flag = false; - break; - } - } - - if (!flag) { - break; - } - } - - return strs[0].substring(0, i); - } -} diff --git a/[015][3 Sum]/src/Main.java b/[015][3 Sum]/src/Main.java deleted file mode 100644 index fc64650..0000000 --- a/[015][3 Sum]/src/Main.java +++ /dev/null @@ -1,53 +0,0 @@ -import org.junit.Test; - -/** - * Author: - * Date: 2015-06-20 - * Time: 22:56 - * Declaration: All Rights Reserved !!! - */ -public class Main { - - @Test - public void test0() { - Solution solution = new Solution(); - System.out.println(solution.threeSum(new int[]{0, 0, 0})); - } - - @Test - public void test1() { - Solution solution = new Solution(); - System.out.println(solution.threeSum(new int[]{0, 0, 0, 0})); - } - - @Test - public void test2() { - Solution solution = new Solution(); - System.out.println(solution.threeSum(new int[]{1, -1, -1, 0})); - } - - @Test - public void test3() { - Solution solution = new Solution(); - System.out.println(solution.threeSum(new int[]{-2, 0, 1, 1, 2})); - } - - @Test - public void test4() { - Solution solution = new Solution(); - System.out.println(solution.threeSum(new int[]{-1, 0, 1, 2, -1, -4})); - } - - @Test - public void test5() { - Solution solution = new Solution(); - System.out.println(solution.threeSum(new int[]{82597,-9243,62390,83030,-97960,-26521,-61011,83390,-38677,12333,75987,46091,83794,19355,-71037,-6242,-28801,324,1202,-90885,-2989,-95597,-34333,35528,5680,89093,-90606,50360,-29393,-27012,53313,65213,99818,-82405,-41661,-3333,-51952,72135,-1523,26377,74685,96992,92263,15929,5467,-99555,-43348,-41689,-60383,-3990,32165,65265,-72973,-58372,12741,-48568,-46596,72419,-1859,34153,62937,81310,-61823,-96770,-54944,8845,-91184,24208,-29078,31495,65258,14198,85395,70506,-40908,56740,-12228,-40072,32429,93001,68445,-73927,25731,-91859,-24150,10093,-60271,-81683,-18126,51055,48189,-6468,25057,81194,-58628,74042,66158,-14452,-49851,-43667,11092,39189,-17025,-79173,13606,83172,92647,-59741,19343,-26644,-57607,82908,-20655,1637,80060,98994,39331,-31274,-61523,91225,-72953,13211,-75116,-98421,-41571,-69074,99587,39345,42151,-2460,98236,15690,-52507,-95803,-48935,-46492,-45606,-79254,-99851,52533,73486,39948,-7240,71815,-585,-96252,90990,-93815,93340,-71848,58733,-14859,-83082,-75794,-82082,-24871,-15206,91207,-56469,-93618,67131,-8682,75719,87429,-98757,-7535,-24890,-94160,85003,33928,75538,97456,-66424,-60074,-8527,-28697,-22308,2246,-70134,-82319,-10184,87081,-34949,-28645,-47352,-83966,-60418,-15293,-53067,-25921,55172,75064,95859,48049,34311,-86931,-38586,33686,-36714,96922,76713,-22165,-80585,-34503,-44516,39217,-28457,47227,-94036,43457,24626,-87359,26898,-70819,30528,-32397,-69486,84912,-1187,-98986,-32958,4280,-79129,-65604,9344,58964,50584,71128,-55480,24986,15086,-62360,-42977,-49482,-77256,-36895,-74818,20,3063,-49426,28152,-97329,6086,86035,-88743,35241,44249,19927,-10660,89404,24179,-26621,-6511,57745,-28750,96340,-97160,-97822,-49979,52307,79462,94273,-24808,77104,9255,-83057,77655,21361,55956,-9096,48599,-40490,-55107,2689,29608,20497,66834,-34678,23553,-81400,-66630,-96321,-34499,-12957,-20564,25610,-4322,-58462,20801,53700,71527,24669,-54534,57879,-3221,33636,3900,97832,-27688,-98715,5992,24520,-55401,-57613,-69926,57377,-77610,20123,52174,860,60429,-91994,-62403,-6218,-90610,-37263,-15052,62069,-96465,44254,89892,-3406,19121,-41842,-87783,-64125,-56120,73904,-22797,-58118,-4866,5356,75318,46119,21276,-19246,-9241,-97425,57333,-15802,93149,25689,-5532,95716,39209,-87672,-29470,-16324,-15331,27632,-39454,56530,-16000,29853,46475,78242,-46602,83192,-73440,-15816,50964,-36601,89758,38375,-40007,-36675,-94030,67576,46811,-64919,45595,76530,40398,35845,41791,67697,-30439,-82944,63115,33447,-36046,-50122,-34789,43003,-78947,-38763,-89210,32756,-20389,-31358,-90526,-81607,88741,86643,98422,47389,-75189,13091,95993,-15501,94260,-25584,-1483,-67261,-70753,25160,89614,-90620,-48542,83889,-12388,-9642,-37043,-67663,28794,-8801,13621,12241,55379,84290,21692,-95906,-85617,-17341,-63767,80183,-4942,-51478,30997,-13658,8838,17452,-82869,-39897,68449,31964,98158,-49489,62283,-62209,-92792,-59342,55146,-38533,20496,62667,62593,36095,-12470,5453,-50451,74716,-17902,3302,-16760,-71642,-34819,96459,-72860,21638,47342,-69897,-40180,44466,76496,84659,13848,-91600,-90887,-63742,-2156,-84981,-99280,94326,-33854,92029,-50811,98711,-36459,-75555,79110,-88164,-97397,-84217,97457,64387,30513,-53190,-83215,252,2344,-27177,-92945,-89010,82662,-11670,86069,53417,42702,97082,3695,-14530,-46334,17910,77999,28009,-12374,15498,-46941,97088,-35030,95040,92095,-59469,-24761,46491,67357,-66658,37446,-65130,-50416,99197,30925,27308,54122,-44719,12582,-99525,-38446,-69050,-22352,94757,-56062,33684,-40199,-46399,96842,-50881,-22380,-65021,40582,53623,-76034,77018,-97074,-84838,-22953,-74205,79715,-33920,-35794,-91369,73421,-82492,63680,-14915,-33295,37145,76852,-69442,60125,-74166,74308,-1900,-30195,-16267,-60781,-27760,5852,38917,25742,-3765,49097,-63541,98612,-92865,-30248,9612,-8798,53262,95781,-42278,-36529,7252,-27394,-5021,59178,80934,-48480,-75131,-54439,-19145,-48140,98457,-6601,-51616,-89730,78028,32083,-48904,16822,-81153,-8832,48720,-80728,-45133,-86647,-4259,-40453,2590,28613,50523,-4105,-27790,-74579,-17223,63721,33489,-47921,97628,-97691,-14782,-65644,18008,-93651,-71266,80990,-76732,-47104,35368,28632,59818,-86269,-89753,34557,-92230,-5933,-3487,-73557,-13174,-43981,-43630,-55171,30254,-83710,-99583,-13500,71787,5017,-25117,-78586,86941,-3251,-23867,-36315,75973,86272,-45575,77462,-98836,-10859,70168,-32971,-38739,-12761,93410,14014,-30706,-77356,-85965,-62316,63918,-59914,-64088,1591,-10957,38004,15129,-83602,-51791,34381,-89382,-26056,8942,5465,71458,-73805,-87445,-19921,-80784,69150,-34168,28301,-68955,18041,6059,82342,9947,39795,44047,-57313,48569,81936,-2863,-80932,32976,-86454,-84207,33033,32867,9104,-16580,-25727,80157,-70169,53741,86522,84651,68480,84018,61932,7332,-61322,-69663,76370,41206,12326,-34689,17016,82975,-23386,39417,72793,44774,-96259,3213,79952,29265,-61492,-49337,14162,65886,3342,-41622,-62659,-90402,-24751,88511,54739,-21383,-40161,-96610,-24944,-602,-76842,-21856,69964,43994,-15121,-85530,12718,13170,-13547,69222,62417,-75305,-81446,-38786,-52075,-23110,97681,-82800,-53178,11474,35857,94197,-58148,-23689,32506,92154,-64536,-73930,-77138,97446,-83459,70963,22452,68472,-3728,-25059,-49405,95129,-6167,12808,99918,30113,-12641,-26665,86362,-33505,50661,26714,33701,89012,-91540,40517,-12716,-57185,-87230,29914,-59560,13200,-72723,58272,23913,-45586,-96593,-26265,-2141,31087,81399,92511,-34049,20577,2803,26003,8940,42117,40887,-82715,38269,40969,-50022,72088,21291,-67280,-16523,90535,18669,94342,-39568,-88080,-99486,-20716,23108,-28037,63342,36863,-29420,-44016,75135,73415,16059,-4899,86893,43136,-7041,33483,-67612,25327,40830,6184,61805,4247,81119,-22854,-26104,-63466,63093,-63685,60369,51023,51644,-16350,74438,-83514,99083,10079,-58451,-79621,48471,67131,-86940,99093,11855,-22272,-67683,-44371,9541,18123,37766,-70922,80385,-57513,-76021,-47890,36154,72935,84387,-92681,-88303,-7810,59902,-90,-64704,-28396,-66403,8860,13343,33882,85680,7228,28160,-14003,54369,-58893,92606,-63492,-10101,64714,58486,29948,-44679,-22763,10151,-56695,4031,-18242,-36232,86168,-14263,9883,47124,47271,92761,-24958,-73263,-79661,-69147,-18874,29546,-92588,-85771,26451,-86650,-43306,-59094,-47492,-34821,-91763,-47670,33537,22843,67417,-759,92159,63075,94065,-26988,55276,65903,30414,-67129,-99508,-83092,-91493,-50426,14349,-83216,-76090,32742,-5306,-93310,-60750,-60620,-45484,-21108,-58341,-28048,-52803,69735,78906,81649,32565,-86804,-83202,-65688,-1760,89707,93322,-72750,84134,71900,-37720,19450,-78018,22001,-23604,26276,-21498,65892,-72117,-89834,-23867,55817,-77963,42518,93123,-83916,63260,-2243,-97108,85442,-36775,17984,-58810,99664,-19082,93075,-69329,87061,79713,16296,70996,13483,-74582,49900,-27669,-40562,1209,-20572,34660,83193,75579,7344,64925,88361,60969,3114,44611,-27445,53049,-16085,-92851,-53306,13859,-33532,86622,-75666,-18159,-98256,51875,-42251,-27977,-18080,23772,38160,41779,9147,94175,99905,-85755,62535,-88412,-52038,-68171,93255,-44684,-11242,-104,31796,62346,-54931,-55790,-70032,46221,56541,-91947,90592,93503,4071,20646,4856,-63598,15396,-50708,32138,-85164,38528,-89959,53852,57915,-42421,-88916,-75072,67030,-29066,49542,-71591,61708,-53985,-43051,28483,46991,-83216,80991,-46254,-48716,39356,-8270,-47763,-34410,874,-1186,-7049,28846,11276,21960,-13304,-11433,-4913,55754,79616,70423,-27523,64803,49277,14906,-97401,-92390,91075,70736,21971,-3303,55333,-93996,76538,54603,-75899,98801,46887,35041,48302,-52318,55439,24574,14079,-24889,83440,14961,34312,-89260,-22293,-81271,-2586,-71059,-10640,-93095,-5453,-70041,66543,74012,-11662,-52477,-37597,-70919,92971,-17452,-67306,-80418,7225,-89296,24296,86547,37154,-10696,74436,-63959,58860,33590,-88925,-97814,-83664,85484,-8385,-50879,57729,-74728,-87852,-15524,-91120,22062,28134,80917,32026,49707,-54252,-44319,-35139,13777,44660,85274,25043,58781,-89035,-76274,6364,-63625,72855,43242,-35033,12820,-27460,77372,-47578,-61162,-70758,-1343,-4159,64935,56024,-2151,43770,19758,-30186,-86040,24666,-62332,-67542,73180,-25821,-27826,-45504,-36858,-12041,20017,-24066,-56625,-52097,-47239,-90694,8959,7712,-14258,-5860,55349,61808,-4423,-93703,64681,-98641,-25222,46999,-83831,-54714,19997,-68477,66073,51801,-66491,52061,-52866,79907,-39736,-68331,68937,91464,98892,910,93501,31295,-85873,27036,-57340,50412,21,-2445,29471,71317,82093,-94823,-54458,-97410,39560,-7628,66452,39701,54029,37906,46773,58296,60370,-61090,85501,-86874,71443,-72702,-72047,14848,34102,77975,-66294,-36576,31349,52493,-70833,-80287,94435,39745,-98291,84524,-18942,10236,93448,50846,94023,-6939,47999,14740,30165,81048,84935,-19177,-13594,32289,62628,-90612,-542,-66627,64255,71199,-83841,-82943,-73885,8623,-67214,-9474,-35249,62254,-14087,-90969,21515,-83303,94377,-91619,19956,-98810,96727,-91939,29119,-85473,-82153,-69008,44850,74299,-76459,-86464,8315,-49912,-28665,59052,-69708,76024,-92738,50098,18683,-91438,18096,-19335,35659,91826,15779,-73070,67873,-12458,-71440,-46721,54856,97212,-81875,35805,36952,68498,81627,-34231,81712,27100,-9741,-82612,18766,-36392,2759,41728,69743,26825,48355,-17790,17165,56558,3295,-24375,55669,-16109,24079,73414,48990,-11931,-78214,90745,19878,35673,-15317,-89086,94675,-92513,88410,-93248,-19475,-74041,-19165,32329,-26266,-46828,-18747,45328,8990,-78219,-25874,-74801,-44956,-54577,-29756,-99822,-35731,-18348,-68915,-83518,-53451,95471,-2954,-13706,-8763,-21642,-37210,16814,-60070,-42743,27697,-36333,-42362,11576,85742,-82536,68767,-56103,-63012,71396,-78464,-68101,-15917,-11113,-3596,77626,-60191,-30585,-73584,6214,-84303,18403,23618,-15619,-89755,-59515,-59103,-74308,-63725,-29364,-52376,-96130,70894,-12609,50845,-2314,42264,-70825,64481,55752,4460,-68603,-88701,4713,-50441,-51333,-77907,97412,-66616,-49430,60489,-85262,-97621,-18980,44727,-69321,-57730,66287,-92566,-64427,-14270,11515,-92612,-87645,61557,24197,-81923,-39831,-10301,-23640,-76219,-68025,92761,-76493,68554,-77734,-95620,-11753,-51700,98234,-68544,-61838,29467,46603,-18221,-35441,74537,40327,-58293,75755,-57301,-7532,-94163,18179,-14388,-22258,-46417,-48285,18242,-77551,82620,250,-20060,-79568,-77259,82052,-98897,-75464,48773,-79040,-11293,45941,-67876,-69204,-46477,-46107,792,60546,-34573,-12879,-94562,20356,-48004,-62429,96242,40594,2099,99494,25724,-39394,-2388,-18563,-56510,-83570,-29214,3015,74454,74197,76678,-46597,60630,-76093,37578,-82045,-24077,62082,-87787,-74936,58687,12200,-98952,70155,-77370,21710,-84625,-60556,-84128,925,65474,-15741,-94619,88377,89334,44749,22002,-45750,-93081,-14600,-83447,46691,85040,-66447,-80085,56308,44310,24979,-29694,57991,4675,-71273,-44508,13615,-54710,23552,-78253,-34637,50497,68706,81543,-88408,-21405,6001,-33834,-21570,-46692,-25344,20310,71258,-97680,11721,59977,59247,-48949,98955,-50276,-80844,-27935,-76102,55858,-33492,40680,66691,-33188,8284,64893,-7528,6019,-85523,8434,-64366,-56663,26862,30008,-7611,-12179,-70076,21426,-11261,-36864,-61937,-59677,929,-21052,3848,-20888,-16065,98995,-32293,-86121,-54564,77831,68602,74977,31658,40699,29755,98424,80358,-69337,26339,13213,-46016,-18331,64713,-46883,-58451,-70024,-92393,-4088,70628,-51185,71164,-75791,-1636,-29102,-16929,-87650,-84589,-24229,-42137,-15653,94825,13042,88499,-47100,-90358,-7180,29754,-65727,-42659,-85560,-9037,-52459,20997,-47425,17318,21122,20472,-23037,65216,-63625,-7877,-91907,24100,-72516,22903,-85247,-8938,73878,54953,87480,-31466,-99524,35369,-78376,89984,-15982,94045,-7269,23319,-80456,-37653,-76756,2909,81936,54958,-12393,60560,-84664,-82413,66941,-26573,-97532,64460,18593,-85789,-38820,-92575,-43663,-89435,83272,-50585,13616,-71541,-53156,727,-27644,16538,34049,57745,34348,35009,16634,-18791,23271,-63844,95817,21781,16590,59669,15966,-6864,48050,-36143,97427,-59390,96931,78939,-1958,50777,43338,-51149,39235,-27054,-43492,67457,-83616,37179,10390,85818,2391,73635,87579,-49127,-81264,-79023,-81590,53554,-74972,-83940,-13726,-39095,29174,78072,76104,47778,25797,-29515,-6493,-92793,22481,-36197,-65560,42342,15750,97556,99634,-56048,-35688,13501,63969,-74291,50911,39225,93702,-3490,-59461,-30105,-46761,-80113,92906,-68487,50742,36152,-90240,-83631,24597,-50566,-15477,18470,77038,40223,-80364,-98676,70957,-63647,99537,13041,31679,86631,37633,-16866,13686,-71565,21652,-46053,-80578,-61382,68487,-6417,4656,20811,67013,-30868,-11219,46,74944,14627,56965,42275,-52480,52162,-84883,-52579,-90331,92792,42184,-73422,-58440,65308,-25069,5475,-57996,59557,-17561,2826,-56939,14996,-94855,-53707,99159,43645,-67719,-1331,21412,41704,31612,32622,1919,-69333,-69828,22422,-78842,57896,-17363,27979,-76897,35008,46482,-75289,65799,20057,7170,41326,-76069,90840,-81253,-50749,3649,-42315,45238,-33924,62101,96906,58884,-7617,-28689,-66578,62458,50876,-57553,6739,41014,-64040,-34916,37940,13048,-97478,-11318,-89440,-31933,-40357,-59737,-76718,-14104,-31774,28001,4103,41702,-25120,-31654,63085,-3642,84870,-83896,-76422,-61520,12900,88678,85547,33132,-88627,52820,63915,-27472,78867,-51439,33005,-23447,-3271,-39308,39726,-74260,-31874,-36893,93656,910,-98362,60450,-88048,99308,13947,83996,-90415,-35117,70858,-55332,-31721,97528,82982,-86218,6822,25227,36946,97077,-4257,-41526,56795,89870,75860,-70802,21779,14184,-16511,-89156,-31422,71470,69600,-78498,74079,-19410,40311,28501,26397,-67574,-32518,68510,38615,19355,-6088,-97159,-29255,-92523,3023,-42536,-88681,64255,41206,44119,52208,39522,-52108,91276,-70514,83436,63289,-79741,9623,99559,12642,85950,83735,-21156,-67208,98088,-7341,-27763,-30048,-44099,-14866,-45504,-91704,19369,13700,10481,-49344,-85686,33994,19672,36028,60842,66564,-24919,33950,-93616,-47430,-35391,-28279,56806,74690,39284,-96683,-7642,-75232,37657,-14531,-86870,-9274,-26173,98640,88652,64257,46457,37814,-19370,9337,-22556,-41525,39105,-28719,51611,-93252,98044,-90996,21710,-47605,-64259,-32727,53611,-31918,-3555,33316,-66472,21274,-37731,-2919,15016,48779,-88868,1897,41728,46344,-89667,37848,68092,-44011,85354,-43776,38739,-31423,-66330,65167,-22016,59405,34328,-60042,87660,-67698,-59174,-1408,-46809,-43485,-88807,-60489,13974,22319,55836,-62995,-37375,-4185,32687,-36551,-75237,58280,26942,-73756,71756,78775,-40573,14367,-71622,-77338,24112,23414,-7679,-51721,87492,85066,-21612,57045,10673,-96836,52461,-62218,-9310,65862,-22748,89906,-96987,-98698,26956,-43428,46141,47456,28095,55952,67323,-36455,-60202,-43302,-82932,42020,77036,10142,60406,70331,63836,58850,-66752,52109,21395,-10238,-98647,-41962,27778,69060,98535,-28680,-52263,-56679,66103,-42426,27203,80021,10153,58678,36398,63112,34911,20515,62082,-15659,-40785,27054,43767,-20289,65838,-6954,-60228,-72226,52236,-35464,25209,-15462,-79617,-41668,-84083,62404,-69062,18913,46545,20757,13805,24717,-18461,-47009,-25779,68834,64824,34473,39576,31570,14861,-15114,-41233,95509,68232,67846,84902,-83060,17642,-18422,73688,77671,-26930,64484,-99637,73875,6428,21034,-73471,19664,-68031,15922,-27028,48137,54955,-82793,-41144,-10218,-24921,-28299,-2288,68518,-54452,15686,-41814,66165,-72207,-61986,80020,50544,-99500,16244,78998,40989,14525,-56061,-24692,-94790,21111,37296,-90794,72100,70550,-31757,17708,-74290,61910,78039,-78629,-25033,73172,-91953,10052,64502,99585,-1741,90324,-73723,68942,28149,30218,24422,16659,10710,-62594,94249,96588,46192,34251,73500,-65995,-81168,41412,-98724,-63710,-54696,-52407,19746,45869,27821,-94866,-76705,-13417,-61995,-71560,43450,67384,-8838,-80293,-28937,23330,-89694,-40586,46918,80429,-5475,78013,25309,-34162,37236,-77577,86744,26281,-29033,-91813,35347,13033,-13631,-24459,3325,-71078,-75359,81311,19700,47678,-74680,-84113,45192,35502,37675,19553,76522,-51098,-18211,89717,4508,-82946,27749,85995,89912,-53678,-64727,-14778,32075,-63412,-40524,86440,-2707,-36821,63850,-30883,67294,-99468,-23708,34932,34386,98899,29239,-23385,5897,54882,98660,49098,70275,17718,88533,52161,63340,50061,-89457,19491,-99156,24873,-17008,64610,-55543,50495,17056,-10400,-56678,-29073,-42960,-76418,98562,-88104,-96255,10159,-90724,54011,12052,45871,-90933,-69420,67039,37202,78051,-52197,-40278,-58425,65414,-23394,-1415,6912,-53447,7352,17307,-78147,63727,98905,55412,-57658,-32884,-44878,22755,39730,3638,35111,39777,74193,38736,-11829,-61188,-92757,55946,-71232,-63032,-83947,39147,-96684,-99233,25131,-32197,24406,-55428,-61941,25874,-69453,64483,-19644,-68441,12783,87338,-48676,66451,-447,-61590,50932,-11270,29035,65698,-63544,10029,80499,-9461,86368,91365,-81810,-71914,-52056,-13782,44240,-30093,-2437,24007,67581,-17365,-69164,-8420,-69289,-29370,48010,90439,13141,69243,50668,39328,61731,78266,-81313,17921,-38196,55261,9948,-24970,75712,-72106,28696,7461,31621,61047,51476,56512,11839,-96916,-82739,28924,-99927,58449,37280,69357,11219,-32119,-62050,-48745,-83486,-52376,42668,82659,68882,38773,46269,-96005,97630,25009,-2951,-67811,99801,81587,-79793,-18547,-83086,69512,33127,-92145,-88497,47703,59527,1909,88785,-88882,69188,-46131,-5589,-15086,36255,-53238,-33009,82664,53901,35939,-42946,-25571,33298,69291,53199,74746,-40127,-39050,91033,51717,-98048,87240,36172,65453,-94425,-63694,-30027,59004,88660,3649,-20267,-52565,-67321,34037,4320,91515,-56753,60115,27134,68617,-61395,-26503,-98929,-8849,-63318,10709,-16151,61905,-95785,5262,23670,-25277,90206,-19391,45735,37208,-31992,-92450,18516,-90452,-58870,-58602,93383,14333,17994,82411,-54126,-32576,35440,-60526,-78764,-25069,-9022,-394,92186,-38057,55328,-61569,67780,77169,19546,-92664,-94948,44484,-13439,83529,27518,-48333,72998,38342,-90553,-98578,-76906,81515,-16464,78439,92529,35225,-39968,-10130,-7845,-32245,-74955,-74996,67731,-13897,-82493,33407,93619,59560,-24404,-57553,19486,-45341,34098,-24978,-33612,79058,71847,76713,-95422,6421,-96075,-59130,-28976,-16922,-62203,69970,68331,21874,40551,89650,51908,58181,66480,-68177,34323,-3046,-49656,-59758,43564,-10960,-30796,15473,-20216,46085,-85355,41515,-30669,-87498,57711,56067,63199,-83805,62042,91213,-14606,4394,-562,74913,10406,96810,-61595,32564,31640,-9732,42058,98052,-7908,-72330,1558,-80301,34878,32900,3939,-8824,88316,20937,21566,-3218,-66080,-31620,86859,54289,90476,-42889,-15016,-18838,75456,30159,-67101,42328,-92703,85850,-5475,23470,-80806,68206,17764,88235,46421,-41578,74005,-81142,80545,20868,-1560,64017,83784,68863,-97516,-13016,-72223,79630,-55692,82255,88467,28007,-34686,-69049,-41677,88535,-8217,68060,-51280,28971,49088,49235,26905,-81117,-44888,40623,74337,-24662,97476,79542,-72082,-35093,98175,-61761,-68169,59697,-62542,-72965,59883,-64026,-37656,-92392,-12113,-73495,98258,68379,-21545,64607,-70957,-92254,-97460,-63436,-8853,-19357,-51965,-76582,12687,-49712,45413,-60043,33496,31539,-57347,41837,67280,-68813,52088,-13155,-86430,-15239,-45030,96041,18749,-23992,46048,35243,-79450,85425,-58524,88781,-39454,53073,-48864,-82289,39086,82540,-11555,25014,-5431,-39585,-89526,2705,31953,-81611,36985,-56022,68684,-27101,11422,64655,-26965,-63081,-13840,-91003,-78147,-8966,41488,1988,99021,-61575,-47060,65260,-23844,-21781,-91865,-19607,44808,2890,63692,-88663,-58272,15970,-65195,-45416,-48444,-78226,-65332,-24568,42833,-1806,-71595,80002,-52250,30952,48452,-90106,31015,-22073,62339,63318,78391,28699,77900,-4026,-76870,-45943,33665,9174,-84360,-22684,-16832,-67949,-38077,-38987,-32847,51443,-53580,-13505,9344,-92337,26585,70458,-52764,-67471,-68411,-1119,-2072,-93476,67981,40887,-89304,-12235,41488,1454,5355,-34855,-72080,24514,-58305,3340,34331,8731,77451,-64983,-57876,82874,62481,-32754,-39902,22451,-79095,-23904,78409,-7418,77916})); - } - - - @Test - public void test6() { - Solution solution = new Solution(); - System.out.println(solution.threeSum(new int[]{-1, 0, 1, 2, -1, -4})); - } -} diff --git a/[015][3 Sum]/src/Solution.java b/[015][3 Sum]/src/Solution.java deleted file mode 100644 index 514b228..0000000 --- a/[015][3 Sum]/src/Solution.java +++ /dev/null @@ -1,80 +0,0 @@ -import java.util.ArrayList; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; - -/** - * Author: - * Date: 2015-06-20 - * Time: 21:46 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0?
-     * Find all unique triplets in the array which gives the sum of zero.
-     *
-     * Note:
-     * Elements in a triplet (a,b,c) must be in non-descending order. (ie, a  b  c)
-     * The solution set must not contain duplicate triplets.
-     *
-     * For example, given array S = {-1 0 1 2 -1 -4},
-     * A solution set is:
-     * (-1, 0, 1)
-     * (-1, -1, 2)
-     *
-     * Ŀ⣺
-     *
-     * 
- * - * @param nums - * @return - */ - public List> threeSum(int[] nums) { - List> result = new LinkedList<>(); - - if (nums == null || nums.length < 3) { - return result; - } - - Arrays.sort(nums); - int target = 0; - - int a = 0; - while (a < nums.length - 2) { - int b = a + 1; - int c = nums.length - 1; - while (b < c) { - if (nums[a] + nums[b] + nums[c] < target) { - do { - ++b; - } while (b < c && nums[b] == nums[b - 1]); - } else if (nums[a] + nums[b] + nums[c] > target) { - do { - --c; - } while (b < c && nums[c] == nums[c + 1]); - } else { - List idxs = new ArrayList<>(); - idxs.add(nums[a]); - idxs.add(nums[b]); - idxs.add(nums[c]); - result.add(idxs); - - do { - ++b; - } while (b < c && nums[b] == nums[b - 1]); - do { - --c; - } while (b < c && nums[c] == nums[c + 1]); - } - } - - do { - ++a; - }while (a < nums.length - 2 && nums[a - 1] == nums[a]); - } - return result; - } - -} diff --git a/[015][3 Sum]/src/Solution2.java b/[015][3 Sum]/src/Solution2.java deleted file mode 100644 index f840265..0000000 --- a/[015][3 Sum]/src/Solution2.java +++ /dev/null @@ -1,119 +0,0 @@ -import java.util.ArrayList; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; - -/** - * Author: - * Date: 2015-06-20 - * Time: 21:46 - * Declaration: All Rights Reserved !!! - */ -public class Solution2 { - /** - *
-     * Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0?
-     * Find all unique triplets in the array which gives the sum of zero.
-     *
-     * Note:
-     * Elements in a triplet (a,b,c) must be in non-descending order. (ie, a  b  c)
-     * The solution set must not contain duplicate triplets.
-     *
-     * For example, given array S = {-1 0 1 2 -1 -4},
-     * A solution set is:
-     * (-1, 0, 1)
-     * (-1, -1, 2)
-     *
-     * Ŀ⣺
-     * һnԪص飬ǷabcԪأʹõa+b+c=0ҳзԪ
-     *
-     * ע⣺
-     *   - ԪеԪرǷǵݼ
-     *   - ܰظԪ
-     *
-     * ˼·
-     *  2sum Ļ3sum⣬3sumĿtargetÿδѡһk
-     * ʣµĿtarget-k2sum⡣ҪעиСtrickǴѡ
-     * iʱֻҪֵдӵi+1һΧ2sum⡣
-     *
-     * ѡһ͵ڶΪA[],ܹnԪA1A2....AnȻѡA1ʱ
-     * [A2~An]Ŀλtarget-A12sum⣬Ҫ֤ǵѡA2ʱֻҪ
-     * [A3~An]мĿλtarget-A22sum⣬[A1,A3~An]У֤£
-     * [A1,A3~An]Ŀλtarget-A22sumУA1 + m = target-A2mΪA3~An
-     * ijA2 + m = target-A1պǡ[A3~An],Ŀλtarget-A12sum⡱
-     * һ⡣൱ڶ3sumA1+A2+m = targetظˡΪ˱ظ㣬
-     * [A1A3~An]У԰A1ȥĿtarget-A22sum⡣
-     *
-     * ڱҪӽ⣬ֻҪ浱ǰԼǰĿľ룬µĽӽ½⡣
-     * 㷨ӶΪOn^2;
-     * 
- * - * @param nums - * @return - */ - public List> threeSum(int[] nums) { - List> result = new LinkedList<>(); - - if (nums != null && nums.length > 2) { - // ȶ - Arrays.sort(nums); - // iʾȡiΪ - for (int i = 0; i < nums.length - 2; ) { - // ڶܵʼλ - int j = i + 1; - // ǽλ - int k = nums.length - 1; - - while (j < k) { - // ҵĽ - if (nums[j] + nums[k] == -nums[i]) { - // ӵ - List list = new ArrayList<>(3); - list.add(nums[i]); - list.add(nums[j]); - list.add(nums[k]); - result.add(list); - - // ƶһλãһ - k--; - j++; - - // ҵһ֮ǰͬ± - while (j < k && nums[j] == nums[j - 1]) { - j++; - } - // ҵһ֮ǰͬ± - while (j < k && nums[k] == nums[k + 1]) { - k--; - } - } - // ʹ0 - else if (nums[j] + nums[k] > -nums[i]) { - k--; - // ҵһ֮ǰͬ± - while (j < k && nums[k] == nums[k + 1]) { - k--; - } - } - // С0 - else { - j++; - // ҵһ֮ǰͬ± - while (j < k && nums[j] == nums[j - 1]) { - j++; - } - } - } - - // ָһҪ - i++; - // ҵһ֮ǰͬ± - while (i < nums.length - 2 && nums[i] == nums[i - 1]) { - i++; - } - } - } - - return result; - } -} diff --git a/[015][3 Sum]/src/Solution3.java b/[015][3 Sum]/src/Solution3.java deleted file mode 100644 index b0419b1..0000000 --- a/[015][3 Sum]/src/Solution3.java +++ /dev/null @@ -1,68 +0,0 @@ -import java.util.ArrayList; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; - -/** - * Author: 王俊超 - * Date: 2015-06-20 - * Time: 21:46 - * Declaration: All Rights Reserved !!! - */ -public class Solution3 { - /** - *
-     * Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0?
-     * Find all unique triplets in the array which gives the sum of zero.
-     *
-     * Note:
-     * Elements in a triplet (a,b,c) must be in non-descending order. (ie, a ≤ b ≤ c)
-     * The solution set must not contain duplicate triplets.
-     *
-     * For example, given array S = {-1 0 1 2 -1 -4},
-     * A solution set is:
-     * (-1, 0, 1)
-     * (-1, -1, 2)
-     *
-     * 题目大意:
-     *
-     * 
- * - * @param nums - * @return - */ - public List> threeSum(int[] nums) { - List> result = new LinkedList<>(); - - if (nums == null || nums.length < 3) { - return result; - } - - Arrays.sort(nums); - int target = 0; - for (int a = 0; a < nums.length - 2; ++a) { - - int b = a + 1; - int c = nums.length - 1; - while (b < c) { - if (nums[a] + nums[b] + nums[c] < target) { - ++b; - } else if (nums[a] + nums[b] + nums[c] > target) { - --c; - } else { - List idxs = new ArrayList<>(); - idxs.add(nums[a]); - idxs.add(nums[b]); - idxs.add(nums[c]); - if (!result.contains(idxs)) { - result.add(idxs); - } - ++b; - --c; - } - } - } - return result; - } - -} \ No newline at end of file diff --git a/[016][3 Sum Closest]/src/Main.java b/[016][3 Sum Closest]/src/Main.java deleted file mode 100644 index ecb9b20..0000000 --- a/[016][3 Sum Closest]/src/Main.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Author: - * Date: 2015-06-21 - * Time: 09:58 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { - Solution solution = new Solution(); - System.out.println(solution.threeSumClosest(new int[]{0, 1 , 2}, 3)); - } -} diff --git a/[016][3 Sum Closest]/src/Solution.java b/[016][3 Sum Closest]/src/Solution.java deleted file mode 100644 index 136d648..0000000 --- a/[016][3 Sum Closest]/src/Solution.java +++ /dev/null @@ -1,99 +0,0 @@ -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * Author: - * Date: 2015-06-21 - * Time: 09:29 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Given an array S of n integers, find three integers in S such that the sum is
-     * closest to a given number, target. Return the sum of the three integers. You
-     * may assume that each input would have exactly one solution.
-     *
-     * For example,
-     * given array S = {-1 2 1 -4}, and target = 1.
-     * The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).
-     *
-     * Ŀ⣺
-     * nSҵSеӶʹ֮ӽ
-     * ܺ͡Լÿ뽫һȷеĽ
-     *
-     * ˼·
-     * 3sum
-     * 
- * - * @param nums - * @param target - * @return - */ - public int threeSumClosest(int[] nums, int target) { - - // ¼СIJֵ - long minDiff = Long.MAX_VALUE; - // ¼СֵӦͺ - long result = 0; - // ÿõIJֵ - long diff; - // ÿõĺ - long sum; - - // ȶ - Arrays.sort(nums); - - - // iʾȡiΪ - for (int i = 0; i < nums.length - 2;) { - // ڶܵʼλ - int j = i + 1; - // ǽλ - int k = nums.length - 1; - - while (j < k) { - // ǰĺ - sum = nums[j] + nums[k] + nums[i]; - // ǰĿ֮IJֵ - diff = Math.abs(target - sum); - - // ֵΪ0ֱӷ - if (diff == 0) { - return (int) sum; - } - - // ǰIJֵ֮ǰ¼IJֵС - if (diff < minDiff) { - // СIJֵ - minDiff = diff; - // СֵӦĺ - result = sum; - - // ϵһԪشʱЧ - } - - - // ʹtarget - if (sum > target) { - do { - k--; // ҵֵͬ - }while (j < k && nums[k]==nums[k + 1]); - } - // Сtarget - else { - do { - j++; - }while (j < k && nums[j - 1] == nums[j]); - } - } - - do { - i++; - }while (i < nums.length - 2 && nums[i - 1] == nums[i]); - } - - return (int) result; - } -} diff --git a/[016][3 Sum Closest]/src/Solution2.java b/[016][3 Sum Closest]/src/Solution2.java deleted file mode 100644 index 1ed9f61..0000000 --- a/[016][3 Sum Closest]/src/Solution2.java +++ /dev/null @@ -1,89 +0,0 @@ -import java.util.Arrays; - -/** - * Author: - * Date: 2015-06-21 - * Time: 09:29 - * Declaration: All Rights Reserved !!! - */ -public class Solution2 { - /** - *
-     * Given an array S of n integers, find three integers in S such that the sum is
-     * closest to a given number, target. Return the sum of the three integers. You
-     * may assume that each input would have exactly one solution.
-     *
-     * For example,
-     * given array S = {-1 2 1 -4}, and target = 1.
-     * The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).
-     *
-     * Ŀ⣺
-     * nSҵSеӶʹ֮ӽ
-     * ܺ͡Լÿ뽫һȷеĽ
-     *
-     * ˼·
-     * 3sum
-     * 
- * - * @param nums - * @param target - * @return - */ - public int threeSumClosest(int[] nums, int target) { - - // ¼СIJֵ - long minDiff = Long.MAX_VALUE; - // ¼СֵӦͺ - long result = 0; - // ÿõIJֵ - long diff; - // ÿõĺ - long sum; - - // ȶ - Arrays.sort(nums); - - - // iʾȡiΪ - for (int i = 0; i < nums.length - 2; i++) { - // ڶܵʼλ - int j = i + 1; - // ǽλ - int k = nums.length - 1; - - while (j < k) { - // ǰĺ - sum = nums[j] + nums[k] + nums[i]; - // ǰĿ֮IJֵ - diff = Math.abs(target - sum); - - // ֵΪ0ֱӷ - if (diff == 0) { - return (int) sum; - } - - // ǰIJֵ֮ǰ¼IJֵС - if (diff < minDiff) { - // СIJֵ - minDiff = diff; - // СֵӦĺ - result = sum; - - // ϵһԪشʱЧ - } - - - // ʹtarget - if (sum > target) { - k--; - } - // Сtarget - else { - j++; - } - } - } - - return (int) result; - } -} diff --git a/[017][Letter Combinations Of A Phon Number/src/Main.java b/[017][Letter Combinations Of A Phon Number/src/Main.java deleted file mode 100644 index d120486..0000000 --- a/[017][Letter Combinations Of A Phon Number/src/Main.java +++ /dev/null @@ -1,14 +0,0 @@ -import org.junit.Test; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-19 19:26 - **/ -public class Main { - @Test - public void test1() { - Solution solution = new Solution(); - - System.out.println(solution.letterCombinations("23")); - } -} diff --git a/[017][Letter Combinations Of A Phon Number/src/Solution.java b/[017][Letter Combinations Of A Phon Number/src/Solution.java deleted file mode 100644 index d9ec4a0..0000000 --- a/[017][Letter Combinations Of A Phon Number/src/Solution.java +++ /dev/null @@ -1,74 +0,0 @@ -import java.util.LinkedList; -import java.util.List; - -/** - * Author: - * Date: 2015-08-21 - * Time: 16:23 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - - private final static String[] S = { - "abc", - "def", - "ghi", - "jkl", - "mno", - "pqrs", - "tuv", - "wxyz", - }; - - - /** - *
-     * ԭ
-     * Given a digit string, return all possible letter combinations that the number could represent.
-     * A mapping of digit to letters (just like on the telephone buttons) is given below.
-     *
-     * Input:Digit string "23"
-     * Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].
-     *
-     * Note: Although the above answer is in lexicographical order, your answer
-     * could be in any order you want.
-     *
-     * Ŀ
-     * һִַϣֵַӳͼʾ
-     * ע⣺ Ľַ˳еģκ˳򷵻ؽ
-     *
-     * ˼·
-     * һ鱣ֵֺӳϵִ룬ҵӦַϽ
-     * 
- * - * @param digits - * @return - */ - public List letterCombinations(String digits) { - List result = new LinkedList<>(); - - if (digits == null || digits.length() < 1) { - return result; - } - - StringBuilder builder = new StringBuilder(); - letterCombinations(digits, 0, builder, result); - - return result; - } - - private void letterCombinations(String digits, int index, StringBuilder builder, List result) { - if (index == digits.length()) { - result.add(builder.toString()); - return; - } - - String t = S[digits.charAt(index) - '2']; - - for (int i = 0; i < t.length(); i++) { - builder.append(t.charAt(i)); - letterCombinations(digits, index + 1, builder, result); - builder.deleteCharAt(builder.length() - 1); - } - } -} diff --git a/[017][Letter Combinations Of A Phon Number/src/Solution2.java b/[017][Letter Combinations Of A Phon Number/src/Solution2.java deleted file mode 100644 index 4dc400d..0000000 --- a/[017][Letter Combinations Of A Phon Number/src/Solution2.java +++ /dev/null @@ -1,95 +0,0 @@ -import java.util.LinkedList; -import java.util.List; - -/** - * Author: - * Date: 2015-08-21 - * Time: 16:23 - * Declaration: All Rights Reserved !!! - */ -public class Solution2 { - - private String[] map = { - "abc", - "def", - "ghi", - "jkl", - "mno", - "pqrs", - "tuv", - "wxyz", - }; - private List result; // 洢ս - private char[] chars; // ȥ01ַĽ - private char[] curResult; // 洢м - private int end = 0; // ַеĵһδʹõλ - private int handle = 0; // ǰǵڼַ - - /** - *
-     * ԭ
-     * Given a digit string, return all possible letter combinations that the number could represent.
-     * A mapping of digit to letters (just like on the telephone buttons) is given below.
-     *
-     * Input:Digit string "23"
-     * Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].
-     *
-     * Note: Although the above answer is in lexicographical order, your answer
-     * could be in any order you want.
-     *
-     * Ŀ
-     * һִַϣֵַӳͼʾ
-     * ע⣺ Ľַ˳еģκ˳򷵻ؽ
-     *
-     * ˼·
-     * һ鱣ֵֺӳϵִ룬ҵӦַϽ
-     * 
- * - * @param digits - * @return - */ - public List letterCombinations(String digits) { - result = new LinkedList<>(); - - if (digits != null && digits.length() > 0) { - - chars = digits.toCharArray(); - - // ַдȥ01 - // ҵһ01λ - while (end < digits.length() && chars[end] != '0' && chars[end] != '1') { - end++; - } - - handle = end + 1; - while (handle < chars.length) { - if (chars[handle] != '0' && chars[handle] != '1') { - chars[end] = chars[handle]; - end++; - } - handle++; - } - - curResult = new char[end]; - // whileendΪЧַij - handle = 0; // ָһЧַλ - - letterCombinations(); - } - return result; - } - - private void letterCombinations() { - if (handle >= end) { - result.add(new String(curResult)); - } else { - int num = chars[handle] - '2'; - for (int i = 0; i < map[num].length(); i++) { - curResult[handle] = map[num].charAt(i); - handle++; - letterCombinations(); - handle--; - } - } - } -} diff --git a/[017][Letter Combinations Of A Phon Number/src/phone-number.png b/[017][Letter Combinations Of A Phon Number/src/phone-number.png deleted file mode 100644 index f740b9f24cfc17ed67eee7c9a88fb15fde735338..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 25417 zcmbT7hc}$x7w%I;h+d+%=%V*dM2qMI8NH4gz4z!{^iGWEq7BhW^kLMA-oh}5ZlbsQ zet+xUf8Z`_%vj#>j&t_ed!NtqoLDUlWxN+uFCIO5gs1XOK?isq1|ASBOyE0)Xcz=| z!n9OXR(SOA-`Cf!^0Y^f7#^u8$bIn5-|zAXG&aa-eOMMzNBqv?Hc&b28f-xJ?|Q%B zASA|m_3AUmNB`(j?s}XB7B1>S`qqDLxxX4c&AXamOax(_K7r@<$A5gDVvs8BK$LWP1# zgkyxuUEkbL($HAj*~PqJ2(7A0>nT>`J&%X035AB>zQ z^RdCnL*YY6@jZBNfzPVnpi)fj9xg8KY4VV~sVQA#WTaTZxL~A6)i=S5fBy&*m7v|4h^9@Z zf(0;?1V0)Zmw*Hpb5aOTC6!R|+d4W z`Q8{AQL85=dU|?JB4$*SZ6)uzRzSjWL&)OR*6gsbCkop64scx5`MI}*q@8o zSHV?AMtXX>mX7gTke|2*3jXV8f;LT@kfN-st6(q+6S#8s@bA}ZXm~e&w(9%$!xIy- zNMIhA7bdLuvobSvj6bMdB~Zc(r2~xNw6wHBzvq(U7xvC{jEw`8vLhuATdhVg-w9Eb zHaBM!7Sc_ti<->2iRFLL<2C;k<}h1lG|_p5KKAe0+1bf0Hu<0@PrD^vOEr<3c?r^u zRYd+fKhrVt$S;Y;cW-P<89z^>G*s3mjf;=xc>Ox}6jSP@hnJV|3=Ua+@Es;Rl%nX-;_WLCae3;!_2L(0_xlv%?THRcB9ibro3yYDxOE z#AAKFzc5ewOq-NY;ql|AT611PCYmDIU>Qe4!*EJ)w%5;()WQ_FS_T36CX!~wyZvsS z+|HC--W>&}r|y9=YrBjkdlJBifpTzO#D9c>X_t69zkr}%^_T^JbV7354-`d*Pq&(G z&;g~bh%GDy9;rA`V+zguv{V)&ezI7Zok#63sVtVe?=2|^hX33PJdS$`H$FdHOhv!ScMMmJ-i)zPx?vW9(x{mA_7j zU6qEh;Oy&@)`j6g$EsY19be-uYY(OXpRV`vD?}J8i=n|iMU9P(Dvmj>Vrm{9(1F0; zUbJ;{Lv6M(;sq{Ts1@MftUSaDGe4NEG?(!^wN{e7xeXR6@_C#m>helfcFjCfLBT=* z{keghxPtSX|77b-MB!7`vTkBgS|*J@OZGnf8~irqlWJ7?<5gxznf^KEDYC z*3+nCDi`#s^Ha^5FONtbo(ge_!mEXksSFG;QA$8MGeP+MBj_1A@b*|&B&SZyn&jKX zE3@}ElxL+oA8ah~1)|bC8 z&DXmjvf*7_(zkam$sUkH3l1Ymzn{3UKnyndA`4@2&6aDx-1Wog3&VdJUPO$2=O2W``p3FNrt+fTbeFf zeXyc7J1;N2C^XXR>U7I2XD1pm#cpC^f@Qz>R^KV#=a)^*$2LsQNuil~S`v|OxqIRT*kOna~^aFp!M=2$) zGS*;nCOU)IK}*<#vQ?D2=|_q1`+K>!pM$MI8V>)3nTE!AYtCaF^cA_u`02}P4Ok#r z{fJpqG?_&;bK}JKYAc-Jc#!(}g6nu285n6Re3rXF2FkW-_&6&fn1k~k%*V&)xd>;v zxw^&SwOxqQ`?_bB8wa)!E?hD+y1ELw(CIRNH8X=lgz@?2@Q!0Bncn7Z&|{ns`c4jp zi}^en4;4}Uan6e|1jIw1J;VN#I>{Vs zD<>qBz(A4Q)nT^%e61%s%=TT9&A%9#PFRjT&jc(DUwbj+pw=4;ApzN4ORtqK|%9z}6x@23pVomLy zrmsvNm+;UuAU|o1 z;}w;KJ|5s`$Ckd-gF31`b zQ7TdAzi!!m(?y?BWcH4W%4QHA*9268%vz7zd7|Lk@PO8%ReHCFiKEi$YRQGKJ70GR z69@fH>q0iy&6bDy2vvx<~wg!*>W=R3?h&C*$3lYeKdRfQe#st~WcQt0UoSG=zArNBjz6IbZ#%r? zFAVzYf)Vx@2ih>K!arfu8rSM(b|4qiy)fUqrgL8G~||Qera1$*iub&PXhk_zDW5IxloC$DN~uBQZ?G$nj(ZSMmk+YklxI@!`fW_EPTO#EER#cx)f3@xPX##DHr4 z>ir-iXiivx*1x^O-ofclS4#*(v7&INDSgZ8yG8@dTSC zC7)8hOtU1zuyb)lZeQGIPXwJ*ziUjWpyruG&9dHKU(##qB~l7<&U;VUh?^N$)D zIyhPP6eoH{r1E|N62`zhOIs!@H5JM%6#r-_iEe$dW$nvkl0-WXWY5+7K}N)BF@b9o z_84L>0bv%j9S@X{T;kx)`}Ok;J9O*c=j1ZCg~$!m`_T^pw!$ zb(ZW9OO}bsT`bk?r}_TBUerKXGw@132wgo>w96gDI|?ouh-a#xf>f~N=xHne#s!-> z)1_|I*JEM3O#5a_)A8b$GktPllZ0l^Ul8)u9*nq6X~~8nb~jIH4c5^&+;Hgv+Ro!; zMBpY#5gQPupO>61hxF!7m!j#chn8xYL|Z~-rLQFy4fEQLQ#mPUXg1ra*CctsA*M1A zOL}s&oxnP!^=4T-JM3L*{*R9&M9*HeeH0XhF_`3ql{x&LrLkIvl*XiH^U;&wMJGY# z2^A={C-Is&DKJ}WDC(n3xL&~oDyZ7OQnF@zWhwI`Qqg&%Mf8DI@16R9NZy$51Xku0 z_=_5tNG0`qJi?97$IJ7$GC3q>%xHXjFmKJ#X4b3F?^?wniC#HXA?(*92s6KwP=A!V z(WDS<5pUKzX866dq~FnvEYSU{fb|e>CP`SMf93m|$ZI>rK&&l@Ff5kgsa%@bSJMXu z%sx{g4;|50Ep>sP&F;?manSJ-vZIPwrWXA+*iSNMa89n>#s3WkJ9&4kGwj;go-}3% z2^X3l-o9p5p(BTKaj1|Se}I?3BEW=lgaU!E20P|YuWZ#?Qti~*!pvJ0o)J%|sLFr+ zfx_Z3z~2&l4R=;?$kcP3J;{>2|6Dq%PZckut;vO{M@6kse^<5l=yCGU=;R*;nUGrk zF;=nwFXdJ9^Un9Aib}ux`}ZyEsMQgZzr|9&zETkxRZscO4Il7p@3-Pdg86Ne-T3Ba zX|_FzuGx<|ccqOz?j!}X31}tW1ews%U;a_vJvdljr4J#HBiubaRLFcOq>el;e#&Ls zlu$d4|A=%U)0#|3H_d?(4zc6IdCRIQf~vWbq62#js_oelKegWb5r1`mamY%D`{%?r zEshUp+O@P|xL}?aUawRI+=K@kUsktm1^KWPNavQJJEG~#@5HxXjmBAU=ZAsjJ}Agh z|1WT!>N1tDYPrUI{`@#DF7EpxbFoQ(#5pNRZI1$hmd7o7d?uIT`)u(jlDEpwM@GP@ zd07)_no{GXStdF2G;ybUX1Dn`Jngu7V@Xx^#y)*OeH>cbit_0p2r+#ODbqGH=o_7Q z2+wnQz>;8op2Xk~le&Jtzw6Xzq05D58?~GqElxvWZs!^r)(eRc5&m?v53lPwC0@I| z&bs`!{gC0&l3#Q#stcE?E2=%zI6qh!^O%r=?Te%B#k5tW=(ZzmA3oRi#kM1jy$70G z-It|~q4f1Oh=bb2wj*!B?}8HpImvI zT%idc(OTg(-sg|qu7`y5m5ptqliBEO$2;G5n#!(geVH@$BQi*$j_!jkU(I+nHEWsj zQ+rx5RFs<^I=Bq()+gtQ=V8qmdyGXae{AG3qSDmU1H)@kkkMMTJcmeYd2D+`edPxX zjP9#uUL8aI!S5|=8NXTI^k&%mLQVay{0f7vRoXiwc6SfU8vP%e7RicB@3m_Pks&Wr zL}Lal;e|#jDhp~ntHFuuyHj{`4ZH5Yg%Vwv;W(PNpK0=5N>U{z`9Z%44k6uMqqsME zRlW05uQZcodLM50l>_$ zMRIhoZ&%)38+Dokg>kZLDAHP6;Ya(e!vsg2PVw>ZEL#@b#AsE}f13?VH>)46LCz09 zquZ_*TWtS%$jj3neEI~hHVl2V>DyUxB6b6WC2^vTUKdvRsJf9O&ND@poD{MWKG}zh zhk=87rQ4)|eD#Rxx^DlsPZbC;jCrzbp0ZNuwf+0+!{<0_496O`?qfk2A$WwzYFv?L zl9!XpGGpS~&MKyCZN7-Jh=SbHki25-D9z=+@&sb9}n4xx#6^$iRAf*pY9o1d^9OB@YVm^ju?t_2G0GS1uvJ=?}N(a~vET zeFx{0)6)sEqFGCamkdih?OawX!aOJ;LB|hZVPUNgddM?_LU08%_$?f?v|d$Rn|rL$ zzT!M_%;FdZXE89=3=WoipJv$f8ush)6WUMQo8+X$?C%Y6%L+x_O=CvYvP=+v+h`V` z=9YHmv?|d-R7wVCmsxeVb?jI6RP5p6;UzklCJxr@Nw}G8oK~;#zxFWqjVb>1i`k={ z$3v`O6Sbv@?IBTT6KW?RtPJo7Fz+Ev^i~G}K7OH28rW*~S)^)Rdm+$6CoJ^sZ)@=l z!_w3vbE$^VdUM$dDtK{mk!-I4 zPMf;+b3W4{<2CV%$`+1a5SBri5YqM+Sl!j8S%@gkcL&{kdyYjxHF$JkWJ*nk&#>tJ zvE7|^fW-#(teub1SN+X9?hhoEcIm&H937|-BEmvdNwuZ+)T4|2cCEm^(^2>70b4S1 zqQPb!A}uYAoP{tAz}ZuIKARJ2^JmA$sjiWt?6{Ov(by7sjwc-x#L%&^#*94f^wKjX z6x2qQQfp17@1}PXZ5*p?8xnR?pIB#BRN@1aa)-%#0!* zMgD8!pJKE2)>aLNmAC}YV|Izf3ytGO!C&&SLNK!>clQnylB13TXvAo|M@yMfuz<}n zi3rmWu^eIQU4FNG!TA2kmi7lrKGg;M67^JZ3f$=>#IHA+Y=%M#wR3)hIg#vD|67R+*e$i|ekG^?qPKr7t54XlX|mWB$X1DkIs6UD1u#5CgBCOvPN zOCHS#@5=~hOimUD&@L`Mzm(V;F5)+2p36KoA5e#f&Qa0PYadXq#>)CMy8Sc?WWvki zYT$Qcsk&oa#-3A(x)N`u2LR4|aRYE>P_pEpB|v2Prdr<%fm?SJELg)6z{L_7ez$>_;6u-Ez7*wBl zEBdPn?08L4Y8a5 z`|8gWGg&+l76t_sm8GleaTA%1E{C|dI84`xCySHm(Xl6UfuEh7-Lz?LW#+$NnKZa< zbx|Y^PwSr=T*6WMml!no%8XqVw9$RXG5|RG{f4Oz1Xt!FW1>nV20(UnA3)nj8zx(- z^5guhL;t)(y<>jMOw2!>iuoiH+2f)|gz>6v;c{Yx%W0+ktcKtVpd5sdi9=yVZaun&fyKesz8#*H~V^T&r3XQ*&#{1pB$=tGjk^6w-{u+$_R@V0Qu7}~l z32wX6A2(nb@wWII`3P5sNU=w6V*-R7VDlw}@rYQ&Zr~_>zC9|$6uh3Q$|GK4%4IT# zjqwE7S(9L440^&?nWRZ9o`0dFl*rZRU#a+S97rFW;>##4h-}mRtUq2aWL8?!Iikdt z;JQ@t89c>W|21;J)C)F6`AO8*)Fc4d_Py#T`)i)TJ@mR~yQ^3}j7DW}aFQWhULGSV zYIpabw4^H$*c>h{8De8T0g2MSRQv_Nk~9Aa!zO1Y)U44BpANkAmGhn9zVJ5x zlJAjk%zfd(=U0KY-<;Re70_j>41{0n>Ugbe4G==N_r_$rrv0gYzHIQ^5i`NBLKfAkxX6L4seV?dH-oX3%`u?4rC60A^ zQc{aL0nmc9XCj&zmIiiqs@eW?9|Q;ku8j@rHT*^AeuTP=Deq?I1Jn_qb|=cbmi(c1 zuRRWKZpD<+rpn*`_rBI=#lD8_s1NqF{h=xWn(U-y-K`cAV4J(GlPQJGM2S2ozaQ)EbDp+sSsB*#4&%+3I1opO_o5#PTJ$;(g#G!ryM{4}#Y+ZDs9wD*;KEQ9N z19lFaptz*kq_ELZ$%E#dZxi3bi6jLDQgskQr>8h=fkPQiQf%7hEIEn18G@W%!3)Fs z_)N(OucAoJC*8XK+H+Bc{n6ATayjGgu z%}awui;|25wOa2V+0ju^es?q5V%~NHhRf|*g$}6OUPf+wALKm3d z{lGI&QcnYcdb845uJ9Jyope zKyPhCR+3xR;5k6Wvlh$(wDu(e7X<&HwimU(2Z*C1m_cB4CVCtTy~isn@9XeP@%#5M{llqfr)kLRiBL(M&iBq~6b@&x;$UVu!T9B;G z`M!82Vu6LFH1HHrq`tWA&`T!!(qqJ1l=Ej&?`vybbB0=JFLR^XQ7nwUI1sPnovO+lG2@9-gZ%b9LhFLJRQn;?beCK5m4Th@8e%ju(qO#-uEjLizV%fu_kPeBhn8;P?{~~$E6zpr z(T=@OfpS({RW-1^f3gkS8m%SFG^!xb)?m#u`_9@}vovzbE72wJfV0M^hp1ykN$>0l z;}koXHQ8DTM_rjVMg1spyAV7G2c@SQFuSC>vcqvEWMC*XuZqS*RT(Jm%_5Bk>O%4X44&=brl z^81VZ*TL~}N;4$M(u28`1RnN=nONFJ*7hSd(=59czX9A#sc))aKK=IvLF8Md0U>$B z|MLQXAF!9vB>2LyL&!{}cqJ+N+iUHI)=Y?RZ4fUh9XW91ahR>dbHYzN!t38Wpv8Rfp_LLu`v#e z=$0xLobN#E3Mnb2leTQu)zhQZ>#(*mZFG9+3~U~rM`P~%Jp^P!3kX?Uv5MkU;JCGS z+cJ=b@#F}xBEyuTe5Qu&R##>c8JALPVBf|{1SZN#O4pmRktbpRQKS?_Gxgly9d+FC z7}utQJYJ)$WpM@_!^&84#)9<~KN-Wf1h*%r79VLlO21b}ur|d?6jS!&;=FSa%Uc=f ztojS5dbOL#_D#o~5$pDR-E4Yc>epQN34IJ?c&a4YZ^=uPAujbq)N}ILXFD!9GUT2~ zTH3^E(f#qkckY@MSDxImlMS>cVr6C^6V1yiS{GV|REF_#DP@vQJ1Tso!sE%FfV^3# zxe}sXu!qH1c*1u+rHniIwC5PKnJ>eY3Frr%q3ENvORCR5`CdX%u4lq?+J+)ef8n;g z<73+S8vmP4_MOTCuAzpAHoqf&BNzG>s;Ld?%0`v>qsHqrW?>W{awckzUAUhReL&DM zyuCKreB8ox>+-s-vf=aiI6jTWbNYv2lix)ZOrpF+Ktk!q6J1H*f{~%J%!2U&fN~!c zFyFc>1<($$z#TjQ<-Q%*Z=;d+1q>A8p02WfSI?ZpE&?(1%FnE&Z!WqqC2C|Z-qL6o zV0x&I@x*h8XX*^ITE4c~tfUVuWrr}U_yz_`(U~z)w}zz;zu*}iYpmBe`t!)2ET!o9O6g6+5U$-)x zR9(Au(GvvdDSmg&^(x zh4Nh8PYylugcz!KF+l-7=${X_2?4>bymWQ+a-k*4_<}CMFTJA$xp|56ouuTnwXyYP zaHfO`#L-pR;vQsde;rykPpjEExY>X#$Sz_%pd>`a!nV#RQf>w{Phxl zE)4R~#}L{aS-VFG$B%YghKDiKd*4M_|8@d@m4Bp)xI` z&P0~DG2*6c;E@1)kdxIV*_b7yppD-2^Yr&R)G|G<%p0Ni8x9W%#*xMtyZzE;~UkgT_9*{i7^LoDf9Boiw*?b+&kB zm#d)y65kVbX05dsGXaF3UO;6y3VP^y^h8{o&dFPn_jZ@a+5hNy%1g;e5wf-e+*`?fI;J_vyfdEBd>SYhzn1U?+G~7;tWX z+tvnXDe*wkTOWbR5q|9`kEVozDM8l?cFt9{ODs!QqgKiF!ALS@6-aS+Qrv<^>;Rmpq1J#}Ba5w8V)+QAs;bJ(h^|q5tsKvo!3;|!B4nV7XN2jD;FC8B;$UUlz%T?G zg5Fk<^8l^sOMbT?xku{cM9&Je#1ar0;mj&_?MX|>;+{H!B3S|xw#t=fav0oW>BLRi zIl?CLq(ehe0y$4YsgjfPK+0CT(=U}Irkfn$g_1?CV*Rdsp>uokgkOu-F@Rux^`4lP z_B%Y!ERsP51M~Ut*r>9uUSRj~=GYoQUF`jywd2>)w5+eh4W({Ja^2N9#z16vP*c|b zsDuPIx}OSiT8H8ua>3pkYWH2J!&zzuvh#7DEC+p0+R z*vOh=;I)le^!)qvP7BKWQ ztu(lt5w^+wxPoGn@$xBy15UY&X*N7O999qAT`JKLfPzoUA}UG{;vC#K@?or@1P}o* zK>A|ZM)GH2io=a+pT_vfxQu&YC?yoUz{QD+HFb31llLjk3-N`Inks(JLazGyoECo2 zg7j$$IW(SllE{|=420NI5H3-#-!=t3VZIfX?KiL$?q8&tFh}urfj?mX9@J6x>4)4>_fpIX2}lg zPayTm-ke;tp{{)(!|zl5lm=?P`P9`{WamJ^OrrwNo+)nfvRi)bNygiDR@5hjOkt55 zchZ7V+D@eD|G0!)0j1|~Gat=ktu)Yy5fImQXT9=G^M(9n^0D-h$d(S^xeE&VPksH!H6ktBncNxn_MO$NSAm_-$hs)L>w)BI zBtsl2S;kifDi#|-b{_7Qe*RZG4Eecj-RJD7WD1$z;pOl5rBbgh*YCItJ8{hzovegV z5QvU*`;~}{>rzLX(~#b9BOLK?DG78wo0%6YIYOLXwEA@mp&)ICg^?LpV&Aj)EI@_z zdlsnz?l7?iwj+Q~Fj{wW#L-y|$9#rR=&_t&)qP=wblA5@HhBKjh3Hx!IznDusSw9N z?`1h#(I_AZck~r{-jsGe{&w)STmV_*rmIbUb8AGC!XD6TJRCPhc@bxsk#us&{eqvtYoSWo?mjEo@W zSKz6&Ah3h|R^9)~t26dXNVre$|BqBGfSw%mO zejMgj$MPk{3UmZ18aE=T0J1dQN%g%bnMUI0;hY&utwW7*bJWY~S!){+@w0w_q6qkS z{eT{Au??RYJ|FVE_WOo)=T@r(9 z9}Ug;qE&OIQTNgz$5PS7;U}D^LkCSCw&;t_H-&Q+SF0z!fyR_K7;?k&k%>wrt$~sG zEeG5q%QNG}(!8lh9vYM$Tx5M)oR*`{vN~CEI)KKib2}0jENFyOQ1m?tSd*-L%!u{& zZTvSOH6bcRMT@QWG19DbM%J?Uf73tT_71=9? zZg}MWO`4i=&+j$X9845QxvdRj_~R)dh^ayoDNOxC>*I&hGX6Y0Q*~6-B9mwHEa2p0 zkDEU@hX<26)foElC=Te(O~5|$W1~K*l@=dTNOKF5Zu$veo>`|E;k2y!?|qvH&kko^ zQT=L9b@#N7G;_>yH%@ro$y;@%_}^WqCx3J76+Jh1_5>HXlh8-Qm6)d8xvEbIgETZd z<>$kX^K~$a=BT=;Vii~opgjEVlx9~CX(_&a3*=GFtScl%567vd+0gAAm7gEWr#j)m!bv&R%yEyt+RFsnH!G)Bx^aQ17!F4CQZ5C}SCQ&r#&jeH=n{CoSD1G$$wZ z#-f(3#47yPAA6R!WEih<;#ku_Y<2Ys;^=DEHurHV4>L{C?_*wACk)SQLn+^}ex-xa zB)v6tql9kj7s^00yICpo+FDxjW}^%hxZhb6^2*ykd-55ZcSJeP_2!^O6PDwtk_tFx zC?)IHU9&$I6MAQ5K^k*5x5zDZ8;5$o3B~UoHuG#uBAR3M`Y@jK{qy#jUPDAJ@q8)D z1Em3uAHagl+NnjYuAt4##>U2p{^N>~hfsH0P;*zdnAKGp+RToQ-rd`Uv~)a6Her_K zOZlYi*a_35KU^HJPo9efS3?jm^ zs@L*;kHgj}+8K}&-2DeC$GIh@M`C`OgXgVWCN7X0gyd){TqJ zFKNg|J6`my93O>L=^RRp|M^>O!k4#gk(<6jt;XVMmiQP^*qBjxs7VHV#h*toScOW( zUORtY#9wJ;!yhJ+fSOqJr)F)UmkO=nCcaQ{zxL7osTaz!1x@JUdj08_d z0>Yv%qoRdhXWB7FE#q7&18_0-ty83llO_=+^~VnC5i-AdL&(Au>Vg5KN~T;h(Ir}i zz{~$`zhQVIM$AH-ND^C`Jr+!+h^?I-GlYloqCvPmXMkt*w4mV-p9gHcf>b(@5CMuA27b!z+ zY^8GTLj`kUwJpSj`mKEA%4|3})3+9B(=0DqQ$vZebOijMrqX#u%k*?4)ii;>X&^7i zBmez42K4Hxr79cFr0NnM+o%743wOymeO`7eNDu}ad2ob3sEs(c_x=X(IK^pZo?MxY z;p%$<={Lah;1|(>en8rT*Vlyww#|?`>__0H3t(D4@$|`j7`9&3QOE z`?k>q+?&iE0RfUhK|xjm6WRP}w_#zi{1;~oZ}h==V@ehl>y$QRGIzV0n!AsHBL+gk z!c(iOh5V6&NVh;4SsZenuT|~2RU@wfA-ex)Vjv?eycQ?>nN{OVxRzexJLdOhA+pjd zCPJdZ)ARFhbmgT#ajVx6v{+Q6E1C4X^2LYU- zE4Xc$bto`GR#r^kzkes=hU`fIrf-|kEU5n(RVKHQlA8*DBQqNTB0D7yEap))@+IY$ zq)~I}zrdPx*NE9!vLw3T@b=u2CXqQNm08TDr2}}5U^D~*sr=c@*V5GVQ4Jfg>r0qm zqH~40OxhDRHX!^t$SVJlD#KlPv1|7E50NAqiFcpIEEaRACti3+(Un(LayZIL7Vu=& zeS}rbRD;?*cXKS9KWz=Cgac6I{S7QC;j_RDyw_ItW&uIR0LZU^Q6EhD5%7t>Ciqt>m7C*F7-HUTgeDNda@0Q8<-lUUFS2C7j9CgR*fR>L%=GjC#@8%7B-VQ2 zWtgkM@Iqe-2v|M68G8fegM)+8vNG22g`&J6z%@MYe}4t9$_CtOl^Bk?Bl%TTFJqM| ztEC6KP3op*r$b{h7PisaAduf8yyVQo)bugnUf$^ZZd92K;>QQ?y{b!Sr-v!vS_uLG zVeoU8r2Quui+l%~U&eZRUL)D{y0OP?6G6_?PZj38sHmy!U0ho1wA2wFyWR1YTFg}B zEaVuayJOf(iIcEnjkQr%p_}&nXeAXPbN?VhuO{2kiP#*rTKC4v&n9(UZ_Erh8=b}` z`CV3}PESu+$CiQ7@iReq>em>LZAsQbzA`+hTRA&8m|s*+Al6nyO5u2Tcug%WwgPpg zqvr<(sYOM$78)!K6tW&wo4-EBF%CG9-8wnd*aFuJ&My_F#M<27UTvaK8rch^>o{hY zz27in%Itwj_)q-^RG;(eyf+^2_`{gV4ayvzaR3{Wrg3lr62Ub7WtvocjiUrl7LEy_ zPV|YU9+RcD-m*1SAd_&g7!4{hsKc&CI)d3y+jgQ*-OcSJBHPiyVdvw>>5oNjGFG}6aZKZGVMRaI3PRY1R5bE2c80f$d1QsrhbDFC=DNTX&5%PJCmA1{M+8#GvQj54J*Pi;>E99#2o5hR^i8c$!hzJ7 zeJtVBE4d4tKN7deg*en(AoLZqS!t3ON?(5D=fr1G^~ib3e2_aKeSv$%_V;q0O-7!b zRK;I%n!I7REtzYThdU3Y}D2z!2VJ;ELPL1)c^VMlv=K%Q_= z0~FdrT+|HpI4wCkNcILBa4W9Vm~^~?1>Q+IZ|;Uj!A5y|;8in@6AT`&R(oIc290Iv z#&C0U182OF+~1yE znE`>X?P5rFQ=a}_td_>-^ddF=+)qV7U|6*>msIC;TY(lIq@+*m#Yv1EZ=<4=sk^3^ z`4R;;ieYV^Hcd;5Ze#70ax@i=9AJSR*$Pk#%hkXEQ-v5ceJpdEmx=9Kch?7f?qT!Q zyX$cdn?h+9qN<&GKIM|Bgo3{f*}w(ooenQ>;x%D3FCr_ezppQk8KrevZWs!3f~OXz zQ%j4sDi5}=;>TrJQIOkF?q~zj5@Ok~w^Yeq^jt&wP5smW5K8y3C1w~Cw@|6`6 z2CRQ)-Xt$DE5*IBRMIP|#ozbEA{jy<^V4)MM54pP8edp8WJi|N)wz5)1eVQcz%y;| zI>ZK)Q%Y380ec|`)^}alGB~DRyOjV=7BWQ>oLo%=64wolcDS^0&%~zoPW44!E+IoU zhu6a^a+SidIn%W(s(_3Ajaq_`-`4>us3}>g zUi#n%YU4uy`pxj}?C*R9_DRo=ddORb`aCpce*vd2qWcd2OeEhW**=_zHP#%@GZ8Sp zc;XEtj>OOc!4)Y4};&2 z0%Xl@PkSs{B-4(FSYo^HWsr*^lEOntZu>hH){1iJ%=hQzYl47~+C66m5G24m;fwr9 zSJIeTW3Gyu>jaM+u;~{LGKT*$=W~=z&RRG)X>^^kq`RKsC7$C?6};WJzX2wsZ+ldo zT|RP6_LLfshF$Hx1RUOznV1v++=ZUb536Gob`*kUU^vcu9-@&1oVN-Ig0tU!t(Lmj zG}9ur`Z@s7F1$n^rT$7{^-!DPq5*&1^rb&lNR1t^Y)JSN*s=1Ni*q*8aGFfr##eNu z9efpT&hYc%es3x8lBuYFdqQzeuJi*^klE{pD$4ZeI5v78c9#;4r`Qpi#JmN&4` z%NBRU|Bt18v58zSmUHewBX?r<{qAg}OaUbr#r8=Lx|q&D5&6obmIh-g*F%5qtR{8_ zGPPsRugpYre^70vK#FmAe@FnE;Qce#;~(15bEn>YR&bLrkc!TcKmQN3T_yBMnv1B(D=>QcwpUi17Q0IPt50-!=s$$YpW*d=@cxF-WC%Aw)R-X64IAhmL6h2 z8-LMx)OUL|wFU?TpFLVk!?H!*DX7TDIAYs=7A{mK9jL(*r9=I*6ky5;`F9rpV1>(R zgKmp`_NP9}XBL(x6teffe6CO}JE~`bcXW)>fAw{aVa`GV+$s=5T61Dh3 z^C=im@|jz1g3*1Ch4i4=6e>%B80bP1$+qK-(S*p-bOCw&I?zOH`yw;6ZQjYnu{03; zER_p57_IH}qN?h&rAJCh4|1K#uF`ou4b2ak+Om(7!t0*O4*z9go#F;C3f1p$CF1sf zkb)Bayt{qRwvS!j(&Q%Y0Q3Q5-r#fHA7)n~@=&(yPa=}Z4_ExPzDsB6nPYz@sh=NT z2X1b?JO*@M9r-iAZ9~(Pj0M(sq-7y7 z$!I5NI{Y_d3L#q_HK^Vd8@!&MaB3WuvugxMLZ?9ScujvfImFJxql(ZBt!3JAy`8t< z>E3@4e7p9bC`Pl9xpdUK?(TMnceFnA5F~oPZ0sMH*A(~N{&wM34#(v>wKv%?vLr*m+3@4$rLRw zOMOr;uV_sN$TKi|zav04q*Fv%B#PEb0zUadzyuo+Co4FX?LE9u|t!yVkMxL@u7 zNn<=oAHVaOSti*_(6dIm-U*(%GBz`}=J_5K9egG`e}In~t7ay|J-!%v=>L2d(0Wry zuM28sSePKONveMR5Ogu;w`M}GtnXwc;M3IXetZ`4$HPceo~`{zbe$4IAYMvIKD_gC zS=ZQgYD=kG50|@gkJ(Yd?&svsN3^sDf#>mN%7hBjOJ%p5hqDJpMdKuje5iMf$GCEO$sL`V{N)WvZMs$LZC>cbF-WiM#oe;f-7`-Ok z^R4^m{<*)-nzhcE^RE5AXP^B(&$FMCl{DP$H5IsY+1>XSgJE4?1QxY_Tk=R{wA|m@ zE(24e2fOi&^zjB*3pwZZ-9
0V-(K*p{oj=eyYBQ3XtsuJz!4y3n`;5{A9slP^1 zr=DJR-8}@F!$*u=uYnAcgxc5ss)K0x^eyA%%DrKeO`}3d49va)$VnfKRJ7@|O+B!wGlzI$6`x*PAd|C{+B=}GoeaAQ? zq-3@J8?RXW2^52*?bYkGsPA)s@-6s&goNfj=At5f@6v6AooUqP;M~ygBf7KGiVX7x zuSQ8tLu=UM<}Ydy(BS{4MYcgc>nvJZ!=8OTpY-chSR%M9X|Bgv{L^JUdTXf*R#i}Z0IJSK$k!^>q8bt(Y4$>Q|A>33PRP?4zK{(=q+uR2R z>Bh0?;vD>>8I?kr=CSrw^7gZFVp3hBK0&JiTb1UhOHzHpRaa`5!@ zTxU{w4@j07=ZH{v&#RZ!uSd;1WKQFAmCgbr(lOs;H~~uz92^|OLASG0)mQBcqZ15% zk7IW+ZY9>Zr}no1eDJ%fM*a(RbUJrhUY=`C0wj}wgBcHhTn&Pf8mYEy=`Z{y5{KjCI`HF0BcF$X>Y!KeH{C#kr;3^n6( zgA>50LEcA;y5I}n(LA2FcQx^e_@Eq3_m-e_=uG;Pc)$+geb5q_=Z@+AM<8k`j2@D# zl>P_vU>?WGr>x`vY{}@qvg%0z^%k?ckV{BF56V4omZY)fR~jVzlWujSKht0z3H0Mk zF3gU4hS6JnLg<_FvXD(pO^H{?yx~%zz?EYq5AAvu83?i#%Nm!F9ewmg8~3K|xS3nd zgYMMx=-vZ^j@*zM3l94w9&Dp)flGKqh0)^VNh??W{o%}BKS^5yVY?7yU^e@P+yCUC zvb`UfZ!BHVKddF-MJ0>u*ZF%uzd!s{SlU2nF`g`eMl_y6^zG$a=EROyuN;G9!p?lh zM<3uqAFx+c{xc>GXuNKwy;0IUwbuz$|5~^BO@`{N^kT zOW4Crryom7mQ++Y8_9ez73%fIszm)*`k7L`&FG|FZX9I1Eh?22%!y50TCK%SIwW2B zKHAm>R|)5-*a%*~M2as&(go~pMhD=)dO~!fKW9?->JKK2@&rWa5>}17~ zA+UOqF*hfg!qEz_11lqA51{@>=%gRpk8OE7xwtSHzUukx(DzD2!OzK@hO|QBOdUX+ zlsRp3a&S<{-nvJos*Eva_}Ms`(p36?@-G8r9C(?Zyw3N=d&tR}%9VxY$otM|M$M(^ zIcA($CKo#@-EBc;NnZd4mHm*=Hg-wDoAc8L(Yzbq0Ye}W=z(Slvz$mZlV>o<6G=(V zjA2;YXcCwvaX^bxyyZ{RV!1Ii0$_aie3?i|Bci}*>hPI-`sE+VV0`pfJ&`OM27Jx3 zNuIh~`ULYFKtKoV3O+g@jRZiMnxHK7)X^6{0)8Jzjxr?YuO1rqy6fMCRyn&}D7MFx z{-p1)z=E}#pl}NNH<|*?L0i|G+SL#U+P}biXRgWJ^u2M`HDop6!?Sna6GU-MdM^t} zenWIgvR-TpDnfsM-q2LB1P*pA)6zuy{~ewV@kGIV%-=`5G!hM;i_m}SA${tXKj$jR zekEa>;M$R*71rQ=;xnjV zmBlj~2i>4oVPwrj3$$&On189o=RN#=DQJ$ov7!a<%NOw|KW*++DOf|31SyTG zs$K;GEH_^xWGHM+KlQ=4#Qf=5>m%^0zNHY@vUP$Ck1Up#m+PaVKN02o zY@P=GmtdWz8SKiq3o!f%C*{mq=1iiP*i)%DH#EQ_c_KiCFyPM6*z}hE zZw^X?HV@k{ogay88Sqc8lI9swD?T8s&c1`)D+*oZ6w5QK^{_$g(|3<*o zXLJ3Kqf*sHfX@_|7+u|Q(1539iUZojdTo86+5f!Jv>pBs$WUp+A1M-5jR|NDz2`@v zEk-@+#o-yBbc%0}Yz|iL<;mFOlkC*mW-bZ(TLpo%kTGmwFs^>svQwy4!v0nDB`_`0 zfOX1jwOJ(dYl~Flsu~p^A3-cm#9Odb3h^*Ex5&0bX!{OQ5E1jRjFFYKx6pEN;`~tO ztl%lOu$aEDrCM8;W4znC@#W&Zxl(N=`6Up&FpuT4aO zG$D?@Pi}q0g|EknqaXNp)stEV2Xuqz6^SU5RVOAVAv~(Ka5w|7K#J!8Lh89yJySr4 zFEz6B6>a)3{x0iQA=23j%xV1n6zht0x{ce}wZ(RIexelah+3R)bLC56-G6?WP7wj) zjRaPQm+SM<)HCwY1uAL`o19-puR!GXdGT;}{gKmzaw}_S( zE?&YtF7vFLUj9@dgsP#gVgtuwffB>^#RDwMRO??id0undsayp*6~iBz^%WhPR4&P| zN_B?#%ibjussy}hj=4B(-$YIO;IV}-H8 zmrFpLO%lxob-}p%hgQ_O__wyo#iY&=CCT!% zfq;p$Mq6YygCXYa-Cd~PGwB`ES~#Qpad%%rq5&up|JT0LXIC1aiDWP#Q&3g7HS(8c zghljPW0oVuBLV`l1Jt-xFy5z>Hy_$#&yuES{nKtSU11}%Q9daEE^7RKl;OWYdSPa7 zYkh|eY&0H>eroIo^#)&!P_Tf?gdQhQ-*s6WwMxytA#7U?dEBoHN=>#R6haeuQ9n@N zrbBgHJ_XPS$J=5AoxMeRVWjQ&VZqgR(SI_mfoEO-08S>`g4|pC5I+BX-^Hxod?S2OZ)KpUX(bf63AcwaD4ZD zE2IY67+yl*wsOI{yioUOz?QP>j`^jc+*)+Ag%r*fG*F>DoW%PV52nW1xXy8BasGHV zti;85n(=CIaL}hvDTkziR`B`X6x~G0YpsTS#^-^-Sj~IeFOG)^*i^N&s!phy{&f4Z z96K!*qbl9|{QEIdO{9x;GZ>SO6~`@S8x&%%JA}PW_-QA>m+cg z#aY~7PvX6hWy0lhF#R>4L3l56x*32FYU2C0G5>j_Xn|EX@umewt;0&Td_7QdE+I`3 zyUEOmXL~XMz5I&01vVAsoU0kC2zuRiYUflifj=xdWJ!-iuR`#*A#TB^q`rQC`lxlE z0%BOY^_u(NqIEYv_p#%Cv@tc;tc0xvhTOiqW88n;{;+9dRh<0I13{!&v@$1SdOVn3 z_=|hCbTI2pP>^*Ft;$xnv`Mgyp`Z4ieB6HP(9Y>~{C|pj!JR9_e19vQvp}NR9qVXiYDJPLa&pfXnvCrkwf*`xzewj+MTQ1tz9p zWaHKQzh$Rvz~I81nU(@_J1q6v-%)?@BAT>GidPnN&DACX->qJU-G*h$ddR zYu(Nt=x*-)g7?Pj5@Jh~m!b`<$r=Br?5jSAF!Z+Cxi=9WA8*;#RC;^FA$PW?W|Pb7 zoveMec^|?McEcAI_4011hLb5VRwf&GY*l&lB5lk;G^#)5<`Q8|8lKtHaMf7wM+38^ zlL=w??fIP8bO5A3H*?sYmwQTC;gjYR7D%uv&~m|J-c#`T%WwEGX3;j;%MRUQFr#*~ z7>s4Ui>>Ik%<&!DSf9keVPKtUFMZgbu(cmO|7wM7I;tzn{O8?YOhe3OD&fC^tAn1= zKh|AO7^M2KPRhYaJ9ZuAV3!nqM;Eo8>pBNlhLp&*eWW6uh<9d^BDA_b*1DQUVdxMJ zZxc2AO||pYF8TL2gW;A_v>iE@xgw!z6DcYWa3#}QVSX>?Cf;e5R=AUei&4JYkfLVA zG3#JoOp}xxS7>zUX@Gg;3ul+(^)W?%m?(F~s}yJ-KefUsHf{9BNnc>plw540#r{FN z1-0Likv^)b>B4?ey|P+%WnY;QlbeWLf*$BqN%Z=a+X%l4UKvm-3MF9|2|Zf>R%gHG z4NxmINr4vhqXSR6j^}nU`zmD?s&%H_!_=s5Y1FK4DE@+lILnAaHvaEscEnpLCXhp% z3iS`y1Z+M|*&UWfX47F9llz~7I8Z0a1F9i&ygV7U<&|iIia5U~uaBIDLe4HOtY@pG z0rQpoR`&eJ*3d=fmP7VsA4N+&(LNOmdXcRNZj>Lif*5F0O@Zrdxh}7KKgf@be1oD) zjPB}F#)Nt5W2DF?bMjFfrg;@qTU_Mwe;G+gFYM;V9+jZwi%n~-DS;IE5Yri4m`;51 zp|gic>A&F+@D=0S?JLI&Ok z!?el5bnk#YWEt^m=l$;Q-~XPXlK)<9sM_zq1SEZz@Q z=b1C2hKjXQ6|>Uk^G%yj6LP8Gf^&ooIs02I-N6EAB^CV?X>aT^3I~&;Gf#`^M8srjI z#t7xo!zK?e-?JmBX@DI1I>P-+K*?$5=FQG1xd)9tgYl_ zuN>uTARSl3Z2-mX%fPR6Wj~r+#um*Tb~ye;Z>9LsgN^n64CiV#;3aMu)7`r6J%zZe zj2A{!{xifMxgSA+uPDuZ8Qg(_^axr-f}SKl-W$g=6J}AKK}Jwi+E?>rqNN^| zoOE_--M!~N#)#fiFuz`obF<4}P#c4OUY(tiAXSP~k_y_ynaFr9{K`S4zRP2BZV^W@ z-UDO-mQV85o1X=cGFqz?WDt9l8}s%7!D-B5T+~ zaaszO>z&*S-kJ)L&28=O|LO5_^$0KD4>#~NVT{&aqbp`t?)$4EczicDN0A(4HS)qy z2j6fVYERfJt>)?~yMCF zkFIDSk#{ful09zgx^{*C-P@`4z1D0r)7&y`WvN11Mpl`;WOG`Tqa#(wW>Y%srEXEU z^j~}EXOpW!6C3nSJEo1z%1I-Ln@XQK8W7K{-nP}*Uu)V!7Q%OqFacVw%$-+@VHD;* z_{a4{?Gg9zEeC-32scRRx*1{Xt8-7=KMk~7EniDFzs>55L%GhyDhp9qwDA;FZxWRExEnt2R7NeQwMuPeT>hrO4~1e ztNyRGhuhkwf!}{CNXJXy7W!QfI#}JNW*ujW-eaqt^bI|hT&w#O`tb7CeFatyiOKgo z2cTWb9KT}7C_dyfH;-PfL8+MclYhxYog@a2$at9Thy20sF7v@L_Wt;xYlXV(OvzC+ z%F7-OG&nh09Cf0%9&e6`O#{ze06IZQD&z?3?sBJSAixT4{3i^rf-FM9)o!NZ-vMex zN%2zJLnJtk7MA6b8>1L%y19?DPtNGArz`IAEKP5<=vq+O+QCIp&2b$U9E1 z`6n!Y8NEVSCY!T~9e_t5#RY4z{B0mM0?m%`cBTM!C$z~qaHmKQNOFE8wNTkUP>mG< zBeXeeuaYC@d;*Q6#%cEIQ(b~jsbgIjB7sbvpWBKy&I-=*=QkU&9N7W~tZN+|sCT7Ch&wHeq9SC{-#`&t)zlJE4 z)LaTB3~;U=&+n>KwYw|>4flrdwQJ0J-pZXkY$^gR%^G^fFLzQATo;Ibvzz}^&1}#b zPALGm3uFRx+Ck9%V+lNj(%IXNE0w&4=ALSGk|#Q2$4!xj zHA7FNaVIS)lK-Qv=d@m$*I}m5(L3*`_@@JQjpizIh3>1{Vv~EG$>|Pe8BNs?UyU*Y zhJ&YXv%-#^F8QNG+38ZNyx!R~*3dT=@!QM2`OR&<_|rO)%;VI%nCXGq4TCK#k2}QsE`oUFX3s zRVC8GZJ0bQ73NB>CNX#5$vq)hA1<+Wgn|>Lkhd>GN{A=ce-=Vob~1>=yo98f>P8|# z4JymF<^E$Xw$+!lf?{M}sZjJRSb74q zb?^nEP4DkwFlu%h^mAl{jcMn%O>B`~{pHE3O@B9*-#_EG-L9;&tLd6e-|-c~Z6{~i zkKuBgDkss9S!CCvM+Nmpt>O&+Sa(dyLC;pwgE;Ubz*o}iueVVj2htw2F8?A+&P@CM z5&Nn?*>FOGo6vGj?QvYK5V1;WLLl*byTf+8IOWoj7gXoEr0{S)92@cynn*jCz*lz5 zulWiCw%B|rEV$ya6F+InVHr=8KLrUzSk5!rfe_lhqh@imCNFo~Ph!L!-V$mJ3$aDV z(s;ygTVz3;R3JAFs!HW}e>3Pdov$dwdy+_z|B>HeFz97}$=00h z^55vSTBWi;oK-tgM3*(GPK3G13nap8)0%$d+Nwd~8U=oY(x)w)!q%+#t;43=V)0hr zVMy|u-Jx-!(Zh?D>g>Ov@{VjY8|f@KEpQW7uB#Erqdt!k@z%vv!= zzDy`XikY&HNLk9HOiHOao+Xibiz`|mHr1~_f#rmoVsNDZI}Sw+=Ide(67q`=E{L?(KPC|9B-`MxLc}pPu$DO~diz^ee!F7R2ph0OlfU)F z5}rD4GpF%p_^|`ommY)~R^)iw9thRPneaR!+20HVhy-K{2-;5!&Q|iFYIH6Yoxb=Sb8rnGz6AOH-j_Hvm)? zR!UN8gllK)y zoFeF6yNKnBc2~<_C9`KbE6b%R1F!sPK@*DQo)|Rt)aUNc2z`Efn-{!<0qW2T=k@wo!#`qO%BBtBHeW) z{k|W-i{XP7l4pVWJ~Pa2np& z^Myd)?W9OKf+#F^7VmDJb5{-SIIOsL4;WE|b6 zT(0@*;7H(VuzC zb5q3=yBzQ_hof64B*><~_*2V4MnS}TH~h55wZ+syNA%k#L>E3^1~TOs#|Rbz;E=0Y zwCF7nPN;jn1XCm5O+LiuOFw=u9ZRCJV)iq;YT13Ol!wEzGB diff --git a/[018][4 Sum]/src/Solution.java b/[018][4 Sum]/src/Solution.java deleted file mode 100644 index 96be97f..0000000 --- a/[018][4 Sum]/src/Solution.java +++ /dev/null @@ -1,105 +0,0 @@ -import java.util.ArrayList; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; - -/** - * Author: - * Date: 2015-08-21 - * Time: 16:28 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Given an array S of n integers, are there elements a, b, c, and d in S
-     * such that a + b + c + d = target? Find all unique quadruplets in the array
-     * which gives the sum of target.
-     * Note:
-     * Elements in a quadruplet (a,b,c,d) must be in non-descending order. (ie, a  b  c  d)
-     * The solution set must not contain duplicate quadruplets.
-     *
-     * For example, given array S = {1 0 -1 0 -2 2}, and target = 0.
-     *
-     * A solution set is:
-     * (-1,  0, 0, 1)
-     * (-2, -1, 1, 2)
-     * (-2,  0, 0, 2)
-     *
-     * Ŀ
-     * һ飬ҳa + b + c + d = targetΨһ⡣
-     *
-     * ˼·
-     * ȷadadͬʱظʹáȻȷbcͬҲ
-     * ͬʱظʹáҳĽ⣬ͬʱԱ֤ⲻظ
-     * 
- * - * @param num - * @param target - * @return - */ - public List> fourSum(int[] num, int target) { - List> result = new LinkedList<>(); - if (num == null || num.length < 4) { - return result; - } - - // - Arrays.sort(num); - - // һ - for (int i = 0; i < num.length - 3; i++) { - // һʹòظ - if (i > 0 && num[i] == num[i - 1]) { - continue; - } - - // ĸ - for (int j = num.length - 1; j > i + 2; j--) { - // ĸʹòظ - if (j < num.length - 1 && num[j] == num[j + 1]) { - continue; - } - - // ڶ - int start = i + 1; - // - int end = j - 1; - int n = target - num[i] - num[j]; - - while (start < end) { - if (num[start] + num[end] == n) { - List four = new ArrayList<>(4); - four.add(num[i]); - four.add(num[start]); - four.add(num[end]); - four.add(num[j]); - - result.add(four); - - do { - start++; - // ֤ٴʹõڶظ - } while (start < end && num[start] == num[start - 1]); - do { - end--; - // ֤ٴʹõظ - } while (start < end && num[end] == num[end + 1]); - } else if (num[start] + num[end] < n) { - do { - start++; - // ֤ٴʹõڶظ - } while (start < end && num[start] == num[start - 1]); - } else { - do { - end--; - // ֤ٴʹõظ - } while (start < end && num[end] == num[end + 1]); - } - } - } - } - return result; - } -} diff --git a/[019][Remove Nth Node From End Of List]/src/ListNode.java b/[019][Remove Nth Node From End Of List]/src/ListNode.java deleted file mode 100644 index d011c54..0000000 --- a/[019][Remove Nth Node From End Of List]/src/ListNode.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 16:30 - * Declaration: All Rights Reserved !!! - */ -public class ListNode { - int val; - ListNode next; - - ListNode(int x) { - val = x; - next = null; - } -} diff --git a/[019][Remove Nth Node From End Of List]/src/Solution.java b/[019][Remove Nth Node From End Of List]/src/Solution.java deleted file mode 100644 index fb5db12..0000000 --- a/[019][Remove Nth Node From End Of List]/src/Solution.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 16:30 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Given a linked list, remove the nth node from the end of list and return its head.
-     * For example,
-     *
-     * Given linked list: 1->2->3->4->5, and n = 2.
-     * After removing the second node from the end, the linked list becomes 1->2->3->5.
-     *
-     * Note:
-     * Given n will always be valid.
-     * Try to do this in one pass.
-     *
-     * Ŀ
-     * ɾĵڣθ㣬ע⣺ģζǺϷһαɲ
-     *
-     * ˼·
-     * һָҵNڵ㣬Ȼһָָͷ㣬Ȼָһߣ
-     * ֱǰһֱָĩβһָǵN+1㣬ɾNͿˡ
-     * 
- * - * @param head - * @param n - * @return - */ - public ListNode removeNthFromEnd(ListNode head, int n) { - ListNode pa = head; - ListNode pb = head; - - // ҵn - for (int i = 0; i < n && pa != null; i++) { - pa = pa.next; - } - - - if (pa == null) { - head = head.next; - return head; - } - - // pbpan-1 - // pa.nextΪnullpbڵn+1λ - while (pa.next != null) { - pa = pa.next; - pb = pb.next; - } - - pb.next = pb.next.next; - - return head; - } -} diff --git a/[020][Valid Parentheses]/src/Main.java b/[020][Valid Parentheses]/src/Main.java deleted file mode 100644 index 4fda8c6..0000000 --- a/[020][Valid Parentheses]/src/Main.java +++ /dev/null @@ -1,22 +0,0 @@ -import org.junit.Assert; -import org.junit.Test; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-17 14:46 - **/ -public class Main { - @Test - public void test1() { - Solution solution = new Solution(); - - Assert.assertEquals(true, solution.isValid("()")); - } - - @Test - public void test2() { - Solution solution = new Solution(); - - Assert.assertEquals(false, solution.isValid("(]")); - } -} diff --git a/[020][Valid Parentheses]/src/Solution.java b/[020][Valid Parentheses]/src/Solution.java deleted file mode 100644 index f248985..0000000 --- a/[020][Valid Parentheses]/src/Solution.java +++ /dev/null @@ -1,52 +0,0 @@ -import java.util.Deque; -import java.util.LinkedList; - -/** - * Author: - * Date: 2015-08-21 - * Time: 16:32 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Given a string containing just the characters (, ), {, }, [ and ],
-     * determine if the input string is valid.
-     * The brackets must close in the correct order, () and ()[]{} are all valid
-     * but (] and ([)] are not.
-     *
-     * Ŀ
-     * һֻ(, ), {, }, [ ͡]ַ֤ǷЧġ
-     * űԣҪȷ˳
-     *
-     * ˼·
-     * һջŴдžջžջԪؿǷһţ
-     * ɾ͵Ҵһţƥֱӷؽ
-     * 
- * - * @param s - * @return - */ - public boolean isValid(String s) { - Deque stack = new LinkedList<>(); - final String left = "([{"; - final String right = ")]}"; - - for (int index = 0; index < s.length(); index++) { - char c = s.charAt(index); - - if (left.indexOf(c) > -1) { - stack.push(c); - } else { - if (stack.isEmpty() || right.indexOf(c) != left.indexOf(stack.peek())) { - return false; - } else { - stack.pop(); - } - } - } - - return stack.isEmpty(); - } -} diff --git a/[020][Valid Parentheses]/src/Solution2.java b/[020][Valid Parentheses]/src/Solution2.java deleted file mode 100644 index 84aaaa5..0000000 --- a/[020][Valid Parentheses]/src/Solution2.java +++ /dev/null @@ -1,97 +0,0 @@ -import java.util.Deque; -import java.util.LinkedList; - -/** - * Author: - * Date: 2015-08-21 - * Time: 16:32 - * Declaration: All Rights Reserved !!! - */ -public class Solution2 { - /** - *
-     * ԭ
-     * Given a string containing just the characters (, ), {, }, [ and ],
-     * determine if the input string is valid.
-     * The brackets must close in the correct order, () and ()[]{} are all valid
-     * but (] and ([)] are not.
-     *
-     * Ŀ
-     * һֻ(, ), {, }, [ ͡]ַ֤ǷЧġ
-     * űԣҪȷ˳
-     *
-     * ˼·
-     * һջŴдžջžջԪؿǷһţ
-     * ɾ͵Ҵһţƥֱӷؽ
-     * 
- * - * @param s - * @return - */ - public boolean isValid(String s) { - Deque stack = new LinkedList<>(); - int index = 0; - Character top; - while (index < s.length()) { - Character c = s.charAt(index); - switch (c) { - case '(': - case '[': - case '{': - stack.addFirst(c); - break; - case ')': - - if (stack.isEmpty()) { - return false; - } - - top = stack.getFirst(); - if (top == '(') { - stack.removeFirst(); - } else if (top == '[' || top == '{') { - return false; - } else { - stack.addFirst(c); - } - break; - case ']': - - if (stack.isEmpty()) { - return false; - } - - top = stack.getFirst(); - if (top == '[') { - stack.removeFirst(); - } else if (top == '(' || top == '{') { - return false; - } else { - stack.addFirst(c); - } - break; - case '}': - - if (stack.isEmpty()) { - return false; - } - - top = stack.getFirst(); - if (top == '{') { - stack.removeFirst(); - } else if (top == '[' || top == '(') { - return false; - } else { - stack.addFirst(c); - } - break; - default: - return false; - } - - index++; - } - - return stack.isEmpty(); - } -} diff --git a/[021][Merge Two Sorted Lists]/src/ListNode.java b/[021][Merge Two Sorted Lists]/src/ListNode.java deleted file mode 100644 index 165ba3b..0000000 --- a/[021][Merge Two Sorted Lists]/src/ListNode.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 16:35 - * Declaration: All Rights Reserved !!! - */ -public class ListNode { - int val; - ListNode next; - - ListNode(int x) { - val = x; - next = null; - } -} diff --git a/[021][Merge Two Sorted Lists]/src/Solution.java b/[021][Merge Two Sorted Lists]/src/Solution.java deleted file mode 100644 index c3281f8..0000000 --- a/[021][Merge Two Sorted Lists]/src/Solution.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 16:35 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Merge two sorted linked lists and return it as a new list.
-     * The new list should be made by splicing together the nodes of the first two lists.
-     *
-     * Ŀ
-     * ϲһµбµĽԭȵɣ
-     * ҲDzܺϲܰ´Ľ㡣
-     *
-     * ˼·
-     * ʹͷrootиһͷ㣬ʹָͷ㣬
-     * СĽֵĽժӵrootĩβͬʱժͷƶһ㣬
-     * һֱԭһΪգٽʣµĽӵrootĩβ
-     * 󷵻rootһ㣬Ϊµͷ
-     * 
- * - * @param l1 - * @param l2 - * @return - */ - public ListNode mergeTwoLists(ListNode l1, ListNode l2) { - - ListNode head = new ListNode(0); // һͷ㣬Ҫɾ - ListNode tail = head; - - while (l1 != null && l2 != null) { - if (l1.val <= l2.val) { - tail.next = l1; - l1 = l1.next; - } else { - tail.next = l2; - l2 = l2.next; - } - - // ƶµβ - tail = tail.next; - } - - tail.next = (l1 != null ? l1 : l2); - - // headһڵǵһݽ - return head.next; - } -} diff --git a/[022][Generate Parentheses]/src/Main.java b/[022][Generate Parentheses]/src/Main.java deleted file mode 100644 index 41be2f7..0000000 --- a/[022][Generate Parentheses]/src/Main.java +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Author: - * Date: 2015-06-22 - * Time: 12:00 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { - Solution solution = new Solution(); - System.out.println(solution.generateParenthesis(0)); - System.out.println(solution.generateParenthesis(1)); - System.out.println(solution.generateParenthesis(2)); - System.out.println(solution.generateParenthesis(3)); - System.out.println(solution.generateParenthesis(4)); - System.out.println(solution.generateParenthesis(5)); - } -} diff --git a/[022][Generate Parentheses]/src/Solution.java b/[022][Generate Parentheses]/src/Solution.java deleted file mode 100644 index 75a6eb1..0000000 --- a/[022][Generate Parentheses]/src/Solution.java +++ /dev/null @@ -1,73 +0,0 @@ -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - -/** - * Author: - * Date: 2015-06-22 - * Time: 11:13 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Given n pairs of parentheses, write a function to generate all combinations
-     * of well-formed parentheses.
-     *
-     * For example, given n = 3, a solution set is:
-     * "((()))", "(()())", "(())()", "()(())", "()()()"
-     *
-     * Ŀ⣺
-     * nţȷ
-     *
-     * ˼·
-     * õݹ
-     * 
- * - * @param n - * @return - */ - public List generateParenthesis(int n) { - // Ķ - List result = new ArrayList<>(); - // 0 - if (n > 0) { - // - char[] parentheses = new char[2 * n]; - // - solve(n, n, parentheses, result); - } - return result; - } - - /** - * @param left ʣõ - * @param right ʣõ - * @param parentheses һΪֹʹõ - * @param result Žļ - */ - public void solve(int left, int right, char[] parentheses, List result) { - - // ʣµС0ÿʣµС - if (left < 0 || right < 0 || right < left) { - // ʲô - return; - } - // Ŷʹ - else if (left == 0 && right == 0) { - result.add(new String(parentheses)); - } - // ʹ - else { - // ǰʹõλ - int idx = parentheses.length - left - right; - // ʹ - parentheses[idx] = '('; - // ݹ - solve(left - 1, right, parentheses, result); - // ʹ - parentheses[idx] = ')'; - solve(left, right - 1, parentheses, result); - } - } -} diff --git a/[023][Merge K Sorted Lists]/src/ListNode.java b/[023][Merge K Sorted Lists]/src/ListNode.java deleted file mode 100644 index 0782835..0000000 --- a/[023][Merge K Sorted Lists]/src/ListNode.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Author: - * Date: 2015-06-30 - * Time: 17:12 - * Declaration: All Rights Reserved !!! - */ -public class ListNode { - int val; - ListNode next; - - ListNode(int x) { - val = x; - } -} diff --git a/[023][Merge K Sorted Lists]/src/Solution.java b/[023][Merge K Sorted Lists]/src/Solution.java deleted file mode 100644 index 243ebc1..0000000 --- a/[023][Merge K Sorted Lists]/src/Solution.java +++ /dev/null @@ -1,214 +0,0 @@ -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; - -/** - * Author: - * Date: 2015-06-30 - * Time: 19:21 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Merge k sorted linked lists and return it as one sorted list.
-     * Analyze and describe its complexity.
-     *
-     * Ŀ⣺
-     * ϲkźõĵĵ
-     *
-     * ˼·
-     * ʹһСвȽkĵһѣȡеСأΪСԪأ
-     * ԪصһѣȡСģβֱΪ
-     * 
- * - * @param lists - * @return - */ - public ListNode mergeKLists(ListNode[] lists) { - - // ΪջûԪ - if (lists == null || lists.length < 1) { - return null; - } - - // ֻһԪ - if (lists.length == 1) { - return lists[0]; - } - - // һСѣʹһڲΪȽ - MinHeap minHeap = new MinHeap(new Comparator() { - @Override - public int compare(ListNode o1, ListNode o2) { - if (o1 == null) { - return -1; - } - - if (o2 == null) { - return 1; - } - - return o1.val - o2.val; - } - }); - - - // ĵһ - for (ListNode node : lists) { - if (node != null) { - minHeap.add(node); - } - } - - // ͷ㣬ʹ - ListNode head = new ListNode(0); - // ǰĽ - ListNode curr = head; - - while (!minHeap.isEmpty()) { - ListNode node = minHeap.deleteTop(); - - // һ㲻Ϊվͽһ - if (node.next != null) { - minHeap.add(node.next); - } - - curr.next = node; - curr = node; - } - - return head.next; - } - - /** - * С - * - * @param - */ - private static class MinHeap { - // Ԫشŵļ - private List items; - - private Comparator comp; - - /** - * һ׵ʼС32 - */ - public MinHeap(Comparator comp) { - this(32, comp); - } - - /** - * һָʼСĶ - * - * @param size ʼС - */ - public MinHeap(int size, Comparator comp) { - items = new ArrayList<>(size); - this.comp = comp; - } - - /** - * ϵ - * - * @param index Ԫصʼλ - */ - public void siftUp(int index) { - T intent = items.get(index); // ȡʼԪض - - while (index > 0) { // ǸԪ - int parentIndex = (index - 1) / 2; // ҸԪضλ - T parent = items.get(parentIndex); // ȡԪض - if (comp.compare(intent, parent) < 0) { //ƵӽڵȸڵС - items.set(index, parent); // ڵ· - index = parentIndex; // ¼ڵ·ŵλ - } else { // ӽڵ㲻ȸڵС˵·ѾСź˳ˣҪ - break; - } - } - - // indexʱ¼ǵһ·ŵĸڵλãҲ - // ԽʼĵԪֵindexλü - items.set(index, intent); - } - - /** - * µ - * - * @param index ƵԪصʼλ - */ - public void siftDown(int index) { - T intent = items.get(index); // ȡʼԪض - int leftIndex = 2 * index + 1; // // ȡʼԪضӽԪλ - - while (leftIndex < items.size()) { // ӽ - T minChild = items.get(leftIndex); // ȡӽԪض󣬲ҼٶΪӽС - int minIndex = leftIndex; // ӽڵСڵԪصλãٶʼʱΪӽλ - - int rightIndex = leftIndex + 1; // ȡӽλ - if (rightIndex < items.size()) { // ӽ - T rightChild = items.get(rightIndex); // ȡӽԪض - if (comp.compare(rightChild, minChild) < 0) { // ҳӽڵеСӽ - minChild = rightChild; - minIndex = rightIndex; - } - } - - // СӽڵȸڵСҪµ - if (comp.compare(minChild, intent) < 0) { - items.set(index, minChild); // ӽڵ - index = minIndex; // ¼ƽڵλ - leftIndex = index * 2 + 1; // ҵƽڵӽڵλ - } else { // Сӽڵ㲻ȸڵС˵·ѾСź˳ˣҪ - break; - } - } - - // indexʱ¼ǵһƵӽڵλãҲ - // ԽʼĵԪֵindexλü - items.set(index, intent); - } - - /** - * һԪ - * - * @param item ȴӵԪ - */ - public void add(T item) { - items.add(item); // Ԫӵ - siftUp(items.size() - 1); // ѭƣع - } - - /** - * ɾѶԪ - * - * @return ѶԪ - */ - public T deleteTop() { - if (items.isEmpty()) { // ѾΪգͱ쳣 - throw new RuntimeException("The heap is empty."); - } - - T maxItem = items.get(0); // ȡѶԪ - T lastItem = items.remove(items.size() - 1); // ɾһԪ - if (items.isEmpty()) { // ɾԪغΪյ˵ɾԪҲǶѶԪ - return lastItem; - } - - items.set(0, lastItem); // ɾԪطѶ - siftDown(0); // µ - return maxItem; // ضѶԪ - } - - /** - * ж϶ǷΪ - * - * @return trueǿգfalse - */ - public boolean isEmpty() { - return items.isEmpty(); - } - } - -} diff --git a/[024][Swap Nodes In Pairs]/src/ListNode.java b/[024][Swap Nodes In Pairs]/src/ListNode.java deleted file mode 100644 index 71c954d..0000000 --- a/[024][Swap Nodes In Pairs]/src/ListNode.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 16:37 - * Declaration: All Rights Reserved !!! - */ -public class ListNode { - int val; - ListNode next; - - ListNode(int x) { - val = x; - next = null; - } -} diff --git a/[024][Swap Nodes In Pairs]/src/Solution.java b/[024][Swap Nodes In Pairs]/src/Solution.java deleted file mode 100644 index 780c049..0000000 --- a/[024][Swap Nodes In Pairs]/src/Solution.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 16:37 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Given a linked list, swap every two adjacent nodes and return its head.
-     * For example,
-     * Given 1->2->3->4, you should return the list as 2->1->4->3.
-     * Your algorithm should use only constant space. You may not modify the values in the list, only nodes itself can be changed.
-     *
-     * Ŀ
-     * һɶԽڵĽ㡣㷨Ӧռ䣬ܸĽֵֻܽ㡣
-     *
-     * ˼·
-     * ʹһͷrootҪнÿλýн
-     * ҰѽĽӵrootϣֱеĽ㶼ꡣ
-     * 
- * - * @param head - * @return - */ - public ListNode swapPairs(ListNode head) { - // ͷ - ListNode node = new ListNode(0); - node.next = head; - - // pָµβ㣬pָõĽ㣬ӵͷΪѾ - ListNode p = node; - ListNode tmp; - - // ÿв - while (p.next != null && p.next.next != null) { - // ¼һҪдλ - tmp = p.next.next; - // 㽻 - p.next.next = tmp.next; - tmp.next = p.next; - p.next = tmp; - // ָ򷵻µβ - p = tmp.next; - } - - head = node.next; - node.next = null; - - return head; - } -} diff --git a/[025][Reverse Nodes In K-Group]/src/ListNode.java b/[025][Reverse Nodes In K-Group]/src/ListNode.java deleted file mode 100644 index a590f24..0000000 --- a/[025][Reverse Nodes In K-Group]/src/ListNode.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Author: - * Date: 2015-06-30 - * Time: 21:20 - * Declaration: All Rights Reserved !!! - */ -public class ListNode { - int val; - ListNode next; - - ListNode(int x) { - val = x; - } -} diff --git a/[025][Reverse Nodes In K-Group]/src/Main.java b/[025][Reverse Nodes In K-Group]/src/Main.java deleted file mode 100644 index 120f95b..0000000 --- a/[025][Reverse Nodes In K-Group]/src/Main.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Author: - * Date: 2015-06-30 - * Time: 21:40 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { - test01(1); - test01(2); - test01(3); - test01(4); - test01(5); - test01(6); - } - - private static void test01(int k) { - ListNode n1 = new ListNode(1); - ListNode n2 = new ListNode(2); - ListNode n3 = new ListNode(3); - ListNode n4 = new ListNode(4); - ListNode n5 = new ListNode(5); - n1.next = n2; - n2.next = n3; - n3.next = n4; - n4.next = n5; - - Solution solution = new Solution(); - ListNode head = solution.reverseKGroup(n1, k); - - print(head); - } - - private static void print(ListNode head) { - while (head != null) { - System.out.print(head.val + "->"); - head = head.next; - } - - System.out.println("null"); - } -} diff --git a/[025][Reverse Nodes In K-Group]/src/Solution.java b/[025][Reverse Nodes In K-Group]/src/Solution.java deleted file mode 100644 index 0e4cfb0..0000000 --- a/[025][Reverse Nodes In K-Group]/src/Solution.java +++ /dev/null @@ -1,106 +0,0 @@ -/** - * Author: - * Date: 2015-06-30 - * Time: 21:20 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Given a linked list, reverse the nodes of a linked list k at a time
-     * and return its modified list.
-     *
-     * If the number of nodes is not a multiple of k then left-out nodes
-     * in the end should remain as it is.
-     *
-     * You may not alter the values in the nodes, only nodes itself may
-     * be changed.
-     *
-     * Only constant memory is allowed.
-     *
-     * For example,
-     * Given this linked list: 1->2->3->4->5
-     * For k = 2, you should return: 2->1->4->3->5
-     * For k = 3, you should return: 3->2->1->4->5
-     *
-     * Ŀ⣺
-     * һһKÿKзתĽK
-     * ԭ˳򲻱䡣
-     *
-     * ˼·
-     *
-     * һָ¼Ӻõһ㣨tail
-     * һָ¼һӺõIJֵһ㣨head
-     * δĽheadβ巨kԪأٽheadƶtail
-     * tail¼¼β㣬ֱеԪض˲
-     * һԪزkΪйβ巨ԻҪлԭ
-     * headԪؽβ巨Ϳ
-     *
-     * 
- * - * @param head - * @param k - * @return - */ - public ListNode reverseKGroup(ListNode head, int k) { - - if (k <= 1) { - return head; - } - - ListNode root = new ListNode(0); - // ͷһԪصǰ - ListNode groupHead = root; - // ǰҪĽ - ListNode curr = head; - // õβ - ListNode groupTail = head; - // ǰҪĽĺ - ListNode next; - - // ÿ飬˶ٸ - int count = 0; - - - while (curr != null) { - - // ǷĵһԪؾͼ¼ - if (count == 0) { - groupTail = curr; - } - - // ¼Ԫظ - count++; - // ¼һ - next = curr.next; - // β巨 - curr.next = groupHead.next; - groupHead.next = curr; - curr = next; - - // Ѿk㣬ͷǰƶһӺõĽ - if (count == k) { - groupHead = groupTail; - // - count = 0; - } - } - - - // ˵kĸԪصĽ㣬 - // ٴʹβ巨лԭ - if (count != 0) { - curr = groupHead.next; - groupHead.next = null; - - while (curr != null) { - next = curr.next; - curr.next = groupHead.next; - groupHead.next = curr; - curr = next; - } - } - - return root.next; - } -} diff --git a/[026][Remove Duplicates from Sorted Array]/src/Solution.java b/[026][Remove Duplicates from Sorted Array]/src/Solution.java deleted file mode 100644 index 9131cb0..0000000 --- a/[026][Remove Duplicates from Sorted Array]/src/Solution.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 16:40 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Given a sorted array, remove the duplicates in place such that each element
-     * appear only once and return the new length.
-     * Do not allocate extra space for another array, you must do this in place
-     * with constant memory.
-     * For example,
-     * Given input array nums = [1,1,2],
-     * Your function should return length = 2, with the first two elements of nums
-     * being 1 and 2 respectively. It doesnt matter what you leave beyond the new length.
-     *
-     * Ŀ
-     * һ飬еظԪȥֻͬһҷµԪظ
-     * Ҫһµڳʱڽ
-     *
-     * ˼·
-     * ӵڶԪؿʼΪǰԪأǰԪǰһԪͬɾԪأ
-     * ͬͽƶȷλãԪ˸
-     * 
- * - * @param A - * @return - */ - public int removeDuplicates(int[] A) { - - if (A == null) { - return 0; - } - - if (A.length < 2) { - return A.length; - } - - // ָһλ - int index = 1; - for (int i = 1; i < A.length; i++) { - // index - 1ʾǰһźõλ - if (A[index - 1] < A[i]) { - A[index] = A[i]; - index++; - } - } - - return index; - } -} diff --git a/[026][Remove Duplicates from Sorted Array]/src/Solution2.java b/[026][Remove Duplicates from Sorted Array]/src/Solution2.java deleted file mode 100644 index fc801b2..0000000 --- a/[026][Remove Duplicates from Sorted Array]/src/Solution2.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 16:40 - * Declaration: All Rights Reserved !!! - */ -public class Solution2 { - /** - *
-     * ԭ
-     * Given a sorted array, remove the duplicates in place such that each element
-     * appear only once and return the new length.
-     * Do not allocate extra space for another array, you must do this in place
-     * with constant memory.
-     * For example,
-     * Given input array nums = [1,1,2],
-     * Your function should return length = 2, with the first two elements of nums
-     * being 1 and 2 respectively. It doesnt matter what you leave beyond the new length.
-     *
-     * Ŀ
-     * һ飬еظԪȥֻͬһҷµԪظ
-     * Ҫһµڳʱڽ
-     *
-     * ˼·
-     * ӵڶԪؿʼΪǰԪأǰԪǰһԪͬɾԪأ
-     * ͬͽƶȷλãԪ˸
-     * 
- * - * @param A - * @return - */ - public int removeDuplicates(int[] A) { - - if (A.length == 0) { - return 0; - } - - int index = 0;//[0,index]ֻ¼гֵİСΨһһѾź - int next = 1; - - // 㷨˼룺index֮ıA[index]ҵƶA[index+1] - // indexƶһλãnextƶһλãұA[index] - - while (next < A.length) { - while (next < A.length && A[index] == A[next]) { // Ҳ - next++; - } - - if (next < A.length) { - index++; - A[index] = A[next]; - next++; - } - } - return index + 1; - } -} diff --git a/[027][Remove Element]/src/Solution.java b/[027][Remove Element]/src/Solution.java deleted file mode 100644 index bfdcaf6..0000000 --- a/[027][Remove Element]/src/Solution.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 16:43 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Given an array and a value, remove all instances of that value in place and return the new length.
-     *  The order of elements can be changed. It doesnt matter what you leave beyond the new length.
-     *
-     * Ŀ
-     * һһֵɾֵȵԪأҷµijȡ
-     *
-     * ˼·
-     * ֵΪelemԪصλãjұֵΪelemԪصλãȻjλõֵƶiλá
-     * 
- * - * @param nums - * @param val - * @return - */ - public int removeElement(int[] nums, int val) { - int exchange = 0; // ¼ĴҲͳelemԪֵȵĸ - - // 㷨˼룺iֵΪelemԪصλãjұֵΪelemԪصλã - // ȡȺóΪ1Խ - for (int i = 0, j = nums.length - 1; i <= j; i++) { - // ҵҪԪ - if (nums[i] == val) { - exchange++; - - // 濪ʼǰҵһelemԪ - while (j > i && nums[j] == val) { - // ֵΪelemԪ˵Ҫǽ̿ʡȥ - exchange++; - j--; - } - - // 1ΪelemԪصλãjλõԪطŵiλ - // 2ûҵelemԪصλãiԪֵeʱj=i - // jеֵiûйϵ - nums[i] = nums[j]; - j--; // jѾʹԻҪǰƶһµλ - } - } - - return nums.length - exchange; - } -} diff --git a/[027][Remove Element]/src/Solution2.java b/[027][Remove Element]/src/Solution2.java deleted file mode 100644 index e87040c..0000000 --- a/[027][Remove Element]/src/Solution2.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 16:43 - * Declaration: All Rights Reserved !!! - */ -public class Solution2 { - /** - *
-     * ԭ
-     * Given an array and a value, remove all instances of that value in place and return the new length.
-     *  The order of elements can be changed. It doesnt matter what you leave beyond the new length.
-     *
-     * Ŀ
-     * һһֵɾֵȵԪأҷµijȡ
-     *
-     * ˼·
-     *
-     * 
- * - * @param nums - * @param val - * @return - */ - public int removeElement(int[] nums, int val) { - - // [0, ..., index - 1]ʾѾųvalֵ飬indexʾ֮ԷԪصλã - // Ҳʾij - int index = 0; - for (int i = 0; i < nums.length; i++) { - // Ⱦƶ - if (nums[i] != val) { - nums[index] = nums[i]; - ++index; - } - } - - return index; - } -} diff --git a/[028][Implement-strStr()]/src/Solution.java b/[028][Implement-strStr()]/src/Solution.java deleted file mode 100644 index 2f84bbe..0000000 --- a/[028][Implement-strStr()]/src/Solution.java +++ /dev/null @@ -1,97 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 16:45 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Implement strStr().
-     * Returns the index of the first occurrence of needle in haystack, or -1
-     * if needle is not part of haystack.
-     *
-     * Ŀ
-     * ʵʵstrStr()жһַһַгֵλáƥͷ-1
-     *
-     * ˼·
-     * ʹKMP㷨ʵ
-     * 
- * - * @param haystack - * @param needle - * @return - */ - public int strStr(String haystack, String needle) { - - if (haystack == null || needle == null) { - return -1; - } - - if (needle.length() > haystack.length()) { - return -1; - } - - if ("".equals(haystack)) { - if ("".equals(needle)) { - return 0; - } else { - return -1; - } - } else { - if ("".equals(needle)) { - return 0; - } - } - - - return kmpIndex(haystack, needle); - } - - private int kmpIndex(String haystack, String needle) { - - - int i = 0; - int j = 0; - int[] next = next(needle); - while (i < haystack.length() && j < needle.length()) { - if (j == -1 || haystack.charAt(i) == needle.charAt(j)) { - ++i; - ++j; - } else { - j = next[j]; - } - } - - if (j == needle.length()) { - return i - j; - } else { - return -1; - } - } - - private int[] next(String needle) { - int[] next = new int[needle.length()]; - next[0] = -1; - int i = 0; - int j = -1; - int k = needle.length() - 1; - while (i < k) { - if (j == -1 || needle.charAt(i) == needle.charAt(j)) { - ++i; - ++j; - if (needle.charAt(i) != needle.charAt(j)) { - next[i] = j; - } else { - next[i] = next[j]; - } - - } else { - j = next[j]; - } - } - - return next; - } -} diff --git a/[029][Divide Two Integers]/src/Main.java b/[029][Divide Two Integers]/src/Main.java deleted file mode 100644 index ac26ef0..0000000 --- a/[029][Divide Two Integers]/src/Main.java +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Author: - * Date: 2015-06-30 - * Time: 21:05 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { - Solution solution = new Solution(); - - System.out.println(solution.divide(-1010369383, -2147483648)); - } -} diff --git a/[029][Divide Two Integers]/src/Solution.java b/[029][Divide Two Integers]/src/Solution.java deleted file mode 100644 index 7a9e147..0000000 --- a/[029][Divide Two Integers]/src/Solution.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Author: - * Date: 2015-06-30 - * Time: 20:46 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Divide two integers without using multiplication, division and mod operator.
-     * If it is overflow, return MAX_INT.
-     *
-     * Ŀ⣺
-     * ʹó˷ȡ࣬Ľͷ
-     *
-     * ˼·
-     * κһԱʾ2Ϊ׵һϣ
-     * num=a_0*2^0+a_1*2^1+a_2*2^2+...+a_n*2^n
-     * ʽԼһλ൱ڳ2ó
-     * ֱڱ֮ǰõһĻȻ
-     * ÿγԼȥӼ2^k,Ȼ
-     * ƵֱΪ0ΪֹΪĵǰ2֪
-     * ʱ临ӶΪO(log(n))
-     *
-     * 
- * - * @param dividend - * @param divisor - * @return - */ - public int divide(int dividend, int divisor) { - // ʱ - if (divisor == 0 || dividend == Integer.MIN_VALUE && divisor == -1) { - return Integer.MAX_VALUE; - } - - // λ - int sign = ((dividend < 0) ^ (divisor < 0)) ? -1 : 1; - - // ֵΪֹʹlong - long dvd = Math.abs((long) dividend); - long dvs = Math.abs((long) divisor); - - // ¼ - int result = 0; - - // ڳ - while (dvd >= dvs) { - // ¼ - long tmp = dvs; - // ¼̵ĴС - long mul = 1; - - while (dvd >= (tmp << 1)) { - tmp <<= 1; - mul <<= 1; - } - - // ȥӽdvddvsֵֵָΪtmp - dvd -= tmp; - - // - result += mul; - } - - return result * sign; - } -} diff --git a/[030][Substring With Concatenation Of All Words]/src/Solution.java b/[030][Substring With Concatenation Of All Words]/src/Solution.java deleted file mode 100644 index b6d432d..0000000 --- a/[030][Substring With Concatenation Of All Words]/src/Solution.java +++ /dev/null @@ -1,33 +0,0 @@ -import java.util.List; - -/** - * Author: - * Date: 2015-07-01 - * Time: 08:23 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * You are given a string, s, and a list of words, words,
-     * that are all of the same length. Find all starting indices
-     * of substring(s) in s that is a concatenation of each word
-     * in words exactly once and without any intervening characters.
-     *
-     * For example, given:
-     * s: "barfoothefoobarman"
-     * words: ["foo", "bar"]
-     * You should return the indices: [0,9].
-     * (order does not matter).
-     * 
- * - * @param s - * @param words - * @return - */ - public List findSubstring(String s, String[] words) { - - - return null; - } -} diff --git a/[031][Next Permutation]/src/Main.java b/[031][Next Permutation]/src/Main.java deleted file mode 100644 index 1f5a159..0000000 --- a/[031][Next Permutation]/src/Main.java +++ /dev/null @@ -1,42 +0,0 @@ -import org.junit.Test; - -import java.util.Arrays; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-14 21:30 - **/ -public class Main { - - @Test - public void test1() { - Solution solution = new Solution(); - int[] nums = {1, 2, 3}; - solution.nextPermutation(nums); - System.out.println(Arrays.toString(nums)); - } - - @Test - public void test2() { - Solution solution = new Solution(); - int[] nums = {3, 2, 1}; - solution.nextPermutation(nums); - System.out.println(Arrays.toString(nums)); - } - - @Test - public void test3() { - Solution solution = new Solution(); - int[] nums = {1, 1, 5}; - solution.nextPermutation(nums); - System.out.println(Arrays.toString(nums)); - } - - @Test - public void test4() { - Solution solution = new Solution(); - int[] nums = {1, 3, 2}; - solution.nextPermutation(nums); - System.out.println(Arrays.toString(nums)); - } -} diff --git a/[031][Next Permutation]/src/Solution.java b/[031][Next Permutation]/src/Solution.java deleted file mode 100644 index 90a5a19..0000000 --- a/[031][Next Permutation]/src/Solution.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-14 21:17 - **/ -public class Solution { - /** - *
-     * Implement next permutation, which rearranges numbers into the lexicographically next
-     * greater permutation of numbers.
-     *
-     * If such arrangement is not possible, it must rearrange it as the lowest possible order
-     * (ie, sorted in ascending order).
-     *
-     * The replacement must be in-place and use only constant extra memory.
-     *
-     * Here are some examples. Inputs are in the left-hand column and its corresponding outputs
-     * are in the right-hand column.
-     *
-     * 1,2,3 → 1,3,2
-     * 3,2,1 → 1,2,3
-     * 1,1,5 → 1,5,1
-     *
-     * 1.首先从最尾端开始往前寻找一个元素,满足nums[i] < nums[i+1]。
-     * 如果没有找到即i < 0, 说明整个数组是递增的,已经到了最大值,此时只要反转数组即可
-     * 如果i >= 0
-     *
-     * 2.再从最尾端开始往前检验,找出第一个大于nums[i]的元素nums[j] 并且,j >= i
-     * 将nums[i],nums[j]元素对调(swap)。
-     *
-     * 3.再将i位置之后的所有元素颠倒(reverse)排序。
-     * 
- * - * @param nums - */ - public void nextPermutation(int[] nums) { - int i = nums.length - 2; - // 从后向前查找第一个元素i,并且使用nums[i] >= nums[i+1]不成立。 - while (i >= 0 && nums[i] >= nums[i + 1]) { - i--; - } - - // 此时nums[i+1, ..., last]是递增的 - - - if (i >= 0) { - int j = nums.length - 1; - // 从右开始向左找,找第一个大于等num[i]的元素 - // 如果找到i==j,说明没有找到 - while (j > i && nums[j] <= nums[i]) { - j--; - } - - // 交换两者之间的值,当j == i时,交换也没有问题 - swap(nums, i, j); - - // 将nums[i+1, last]进行反转 - reverse(nums, i + 1); - } else { - // 说明整个序列是非递增的 - // 对子数组进行翻转 - reverse(nums, 0); - } - - - } - - private void reverse(int[] nums, int start) { - int i = start; - int j = nums.length - 1; - while (i < j) { - swap(nums, i, j); - i++; - j--; - } - } - - private void swap(int[] nums, int i, int j) { - int temp = nums[i]; - nums[i] = nums[j]; - nums[j] = temp; - } -} diff --git a/[032][Longest Valid Parentheses]/src/Main.java b/[032][Longest Valid Parentheses]/src/Main.java deleted file mode 100644 index aafc2f1..0000000 --- a/[032][Longest Valid Parentheses]/src/Main.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Author: - * Date: 2015-06-25 - * Time: 09:22 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { - Solution solution = new Solution(); - System.out.println(solution.longestValidParentheses("(()")); - System.out.println(solution.longestValidParentheses(")()())")); - System.out.println(solution.longestValidParentheses(")()())()")); - System.out.println(solution.longestValidParentheses(")()(()()))()()()")); - } -} diff --git a/[032][Longest Valid Parentheses]/src/Solution.java b/[032][Longest Valid Parentheses]/src/Solution.java deleted file mode 100644 index 2e4f5d1..0000000 --- a/[032][Longest Valid Parentheses]/src/Solution.java +++ /dev/null @@ -1,54 +0,0 @@ -import java.util.Deque; -import java.util.LinkedList; -import java.util.Stack; - -/** - * Author: - * Date: 2015-06-25 - * Time: 09:12 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Given a string containing just the characters '(' and ')',
-     * find the length of the longest valid (well-formed) parentheses substring.
-     *
-     * For "(()", the longest valid parentheses substring is "()", which has length = 2.
-     * Another example is ")()())", where the longest valid parentheses substring is "()()",
-     * which has length = 4.
-     *
-     * Ŀ⣺
-     * һַֻСźţĺϷСŵĿ
-     *
-     * ˼·
-     * ʹջʵ
-     * 
- * - * @param s - * @return - */ - public int longestValidParentheses(String s) { - // ڼ¼ƥźŵλ - Stack st = new Stack<>(); - int max = 0; - for (int i = 0; i < s.length(); i++) { - - // ǵǰַţҼ¼ջǿգǰһַ - if (s.charAt(i) == ')' && !st.isEmpty() && s.charAt(st.peek()) == '(') { - // ųջ - st.pop(); - // ֵ - // ʱ(ƥ)ѾջջҪôΪգҪô뵱ǰ)) - // Ҫô뵱ǰ)ڶ( - max = Math.max(max, i - ((st.isEmpty()) ? -1 : st.peek())); - } - // ͽַջ - else { - st.push(i); - } - } - - return max; - } -} diff --git a/[032][Longest Valid Parentheses]/src/Solution2.java b/[032][Longest Valid Parentheses]/src/Solution2.java deleted file mode 100644 index fb9b995..0000000 --- a/[032][Longest Valid Parentheses]/src/Solution2.java +++ /dev/null @@ -1,59 +0,0 @@ -import java.util.Deque; -import java.util.LinkedList; - -/** - * Author: - * Date: 2015-06-25 - * Time: 09:12 - * Declaration: All Rights Reserved !!! - */ -public class Solution2 { - /** - *
-     * Given a string containing just the characters '(' and ')',
-     * find the length of the longest valid (well-formed) parentheses substring.
-     *
-     * For "(()", the longest valid parentheses substring is "()", which has length = 2.
-     * Another example is ")()())", where the longest valid parentheses substring is "()()",
-     * which has length = 4.
-     *
-     * Ŀ⣺
-     * һַֻСźţĺϷСŵĿ
-     *
-     * ˼·
-     * ʹջʵ
-     * 
- * - * @param s - * @return - */ - public int longestValidParentheses(String s) { - int result = 0; - int start = 0; - // ¼ŵλ - Deque m = new LinkedList<>(); - for (int i = 0; i < s.length(); ++i) { - // žͼ¼λ - if (s.charAt(i) == '(') { - m.push(i); - } - // - else if (s.charAt(i) == ')') { - // ֮ǰŶѾԣߴû - if (m.isEmpty()) { - // ǰλѾЧˣ¼һλǿʼԵλ - start = i + 1; - } else { - // ջӦ - m.pop(); - // ջΪգ˵startʼһֱƥ䣬ûֶţ - // ǣMath.max(result, i - start + 1) - // ջǿգ˵жţһŵλþm.peek() - // ƥž: Math.max(result, i - m.peek()) - result = m.isEmpty() ? Math.max(result, i - start + 1) : Math.max(result, i - m.peek()); - } - } - } - return result; - } -} diff --git a/[033][Search In Rotated Sorted Array]/src/Main.java b/[033][Search In Rotated Sorted Array]/src/Main.java deleted file mode 100644 index 7665c43..0000000 --- a/[033][Search In Rotated Sorted Array]/src/Main.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-12 23:22 - **/ -public class Main { - public static void main(String[] args) { - int[] nums = {4,5,6,7,0,1,2} - ; - Solution2 solution = new Solution2(); - - System.out.println(solution.search(nums, 4)); - System.out.println(solution.search(nums, 3)); - } -} diff --git a/[033][Search In Rotated Sorted Array]/src/Solution.java b/[033][Search In Rotated Sorted Array]/src/Solution.java deleted file mode 100644 index 4f3e4eb..0000000 --- a/[033][Search In Rotated Sorted Array]/src/Solution.java +++ /dev/null @@ -1,120 +0,0 @@ -/** - * Author: 王俊超 - * Date: 2015-06-21 - * Time: 14:48 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Suppose a sorted array is rotated at some pivot unknown to you beforehand.
-     * (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).
-     * You are given a target value to search. If found in the array return its
-     * index, otherwise return -1.
-     *
-     * You may assume no duplicate exists in the array.
-     *
-     * 题目大意:
-     * 假设一个排序的数组以一个未知的的枢轴旋转。(即,0 1 2 4 5 6 7可能成为4 5 6 7 0 1 2)。
-     * 给定一个目标值,在数组中搜寻。如果存在就返回其对应的下标,否则返回-1。
-     * 假设数组中不存在重复值。
-     *
-     * 解题思路:
-     * 找旋转数组最小值的位置minIndex(见LeetCode第153题 ),如果minIndex不为,说明其在分隔成
-     * 两个有序数组,并且前一个中的第一个元素都大于后一个数组的每一个元素,判断target中哪一个数组区
-     * 间中使用二叉搜索算法查找,如果minIndex=0,说明全局有序,对整个数组进行二叉查找,返回查找结果
-     * 
- * - * @param nums - * @param target - * @return - */ - public int search(int[] nums, int target) { - - if (nums != null && nums.length > 0) { - - // 找最小元素对应的下标 - int minIndex = searchMinIndex(nums, 0, nums.length - 1); - - // 整个数组全局有序 - if (minIndex == 0) { - return binarySearch(nums, 0, nums.length - 1, target); - } - // 有两个局部有序区间, 如 4 5 6 7 8 9 0 1 2 3 - else { - // 恬好和后一个有序区间的最后一个元素相等,返回对应的下标 - if (nums[nums.length - 1] == target) { - return nums.length - 1; - } - // target可能在后一个有序区间中 - else if (nums[nums.length - 1] > target) { - return binarySearch(nums, minIndex, nums.length - 1, target); - } - // target可能是前一个有序区间中 - else { - return binarySearch(nums, 0, minIndex - 1, target); - } - } - } - - return -1; - } - - /** - * 二分搜索 - * - * @param nums 数组 - * @param start 起始位置 - * @param end 结束位置 - * @param target 搜索目标 - * @return 匹配元素的下标 - */ - public int binarySearch(int[] nums, int start, int end, int target) { - - int mid; - while (start <= end) { - mid = start + ((end - start) >> 1); - - if (nums[mid] == target) { - return mid; - } else if (nums[mid] > target) { - end = mid - 1; - } else { - start = mid + 1; - } - } - - return -1; - } - - /** - * 找最小元素的下标 - * - * @param nums 数组 - * @param start 起始位置 - * @param end 结束位置 - * @return 最小元素的下标 - */ - public int searchMinIndex(int[] nums, int start, int end) { - - int mid; - while (start < end) { - mid = start + ((end - start) >> 1); - // 后一个数比前个数小就找到了 - if (nums[mid] > nums[mid + 1]) { - return mid + 1; - } - // 说明中间值在第一个有序的数组中 - else if (nums[mid] > nums[start]) { - start = mid; - } - // 说明中间值在第二个有序的数组中 - else { - end = mid; - } - } - - // 说明整个数组是有序的 - return 0; - } -} diff --git a/[033][Search In Rotated Sorted Array]/src/Solution2.java b/[033][Search In Rotated Sorted Array]/src/Solution2.java deleted file mode 100644 index 59a71a5..0000000 --- a/[033][Search In Rotated Sorted Array]/src/Solution2.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Author: 王俊超 - * Date: 2015-06-21 - * Time: 14:48 - * Declaration: All Rights Reserved !!! - */ -public class Solution2 { - /** - *
-     * Suppose a sorted array is rotated at some pivot unknown to you beforehand.
-     * (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).
-     * You are given a target value to search. If found in the array return its
-     * index, otherwise return -1.
-     *
-     * You may assume no duplicate exists in the array.
-     *
-     * 题目大意:
-     * 假设一个排序的数组以一个未知的的枢轴旋转。(即,0 1 2 4 5 6 7可能成为4 5 6 7 0 1 2)。
-     * 给定一个目标值,在数组中搜寻。如果存在就返回其对应的下标,否则返回-1。
-     * 假设数组中不存在重复值。
-     *
-     * 解题思路:
-     * 找旋转数组最小值的位置minIndex(见LeetCode第153题 ),如果minIndex不为,说明其在分隔成
-     * 两个有序数组,并且前一个中的第一个元素都大于后一个数组的每一个元素,判断target中哪一个数组区
-     * 间中使用二叉搜索算法查找,如果minIndex=0,说明全局有序,对整个数组进行二叉查找,返回查找结果
-     * 
- * - * @param nums - * @param target - * @return - */ - public int search(int[] nums, int target) { - if (nums == null || nums.length == 0) { - return -1; - } - - int left = 0; - int right = nums.length - 1; - int mid; - while (left <= right) { - mid = left + (right - left) / 2; - if (nums[mid] == target) { - return mid; - } - - // 说明first,mid都在同一个递增子序列中 - if (nums[left] <= nums[mid]) { - if (nums[left] <= target && target < nums[mid]) { - right = mid - 1; - } else { - left = mid + 1; - } - } else { - if (nums[mid] < target && target <= nums[right]) { - left = mid + 1; - } else { - right = mid - 1; - } - } - } - - return -1; - } - -} diff --git a/[034][Search For A Range]/src/Solution.java b/[034][Search For A Range]/src/Solution.java deleted file mode 100644 index 9314e1b..0000000 --- a/[034][Search For A Range]/src/Solution.java +++ /dev/null @@ -1,124 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 16:55 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Given a sorted array of integers, find the starting and ending position of a given target value.
-     * Your algorithms runtime complexity must be in the order of O(log n).
-     * If the target is not found in the array, return [-1, -1].
-     * For example,
-     * Given [5, 7, 7, 8, 8, 10] and target value 8,
-     * return [3, 4].
-     *
-     * Ŀ
-     * һź飬ͬʱһҪҵֵ ҳеijʼͽλá
-     * 㷨ʱ临ӶҪΪlog(N)
-     * ûҵͷ[-1, -1]
-     *
-     * ˼·
-     * ٶǵģöֲ㷨Ƿھͷ[-1,-1]
-     * ھͷֱһγֵλúʼֵλáֵλʱȴ
-     * һλÿʼңڴҵֵǰһλãھǰ22ָӣ
-     * Сھ˻صԭλõĺһвң°124ӵķʽУֱҵΪֹ
-     * ȵԪҲһġ
-     * 
- * - * @param A - * @param target - * @return - */ - public int[] searchRange(int[] A, int target) { - - if (A == null || A.length == 0) { - return new int[]{-1, -1}; - } - - int lo = 0; - int hi = A.length - 1; - int mi = 0; - // ǷֵΪtargetԪ - while (lo <= hi) { - mi = lo + (hi - lo) / 2; - if (target < A[mi]) { - hi = mi - 1; - } else if (target > A[mi]) { - lo = mi + 1; - } else { - break; - } - - } - - if (A[mi] != target) { - return new int[]{-1, -1}; - } - - lo = searchFirst(A, 0, mi, target); - hi = searchLast(A, mi, A.length - 1, target); - - return new int[]{lo, hi}; - } - - /** - * targetȳֵλãҵķΧ[lo, hi]A[hi]targetAΪ - * - * @param A ҵ - * @param lo ҵʼλ - * @param hi ҵĽλ - * @param target ҵֵ - * @return targetȳֵλ - */ - private int searchFirst(int[] A, int lo, int hi, int target) { - - int gap = 1; - do { - hi -= gap; - if (hi < lo || A[hi] != target) { - hi += gap; - - if (hi <= lo || A[hi - 1] != target) { - return hi; - } else { - gap = 1; - hi--; - } - } else {// һελúgapȻ - gap *= 2; - } - } while (true); - - } - - /** - * targetֵλãҵķΧ[lo, hi]A[lo]targetAΪ - * - * @param A ҵ - * @param lo ҵʼλ - * @param hi ҵĽλ - * @param target ҵֵ - * @return targetֵλ - */ - private int searchLast(int[] A, int lo, int hi, int target) { - int gap = 1; - do { - lo += gap; - if (lo > hi || A[lo] != target) { - lo -= gap; - - if (lo >= hi || A[lo + 1] != target) { - return lo; - } else { - gap = 1; - lo++; - } - } else {// һελǰgapȻ - gap *= 2; - } - } while (true); - } -} diff --git a/[035][Search Insert Position]/src/Solution.java b/[035][Search Insert Position]/src/Solution.java deleted file mode 100644 index 90057f0..0000000 --- a/[035][Search Insert Position]/src/Solution.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 16:57 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Given a sorted array and a target value, return the index if the target is found.
-     * If not, return the index where it would be if it were inserted in order.
-     * You may assume no duplicates in the array.
-     * Here are few examples.
-     *
-     * [1,3,5,6], 5  2
-     * [1,3,5,6], 2  1
-     * [1,3,5,6], 7  4
-     * [1,3,5,6], 0  0
-     *
-     * Ŀ
-     * һ飬һֵָҵֵֵλãûҵֵеIJλá
-     * ûظԪء
-     *
-     * ˼·
-     * һֱӵIJ㷨
-     * ʹöֲ㷨
-     * 
- * - * @param A - * @param target - * @return - */ - public int searchInsert(int[] A, int target) { - - int mid; - int lo = 0; - int hi = A.length - 1; - - while (lo <= hi) { - mid = lo + (hi - lo) / 2; - - if (A[mid] == target) { - return mid; - } else if (A[mid] < target) { - lo = mid + 1; - } else { - hi = mid - 1; - } - } - - return lo; - } - - public int searchInsert2(int[] A, int target) { - - if (A == null) { - return -1; - } - - int i; - for (i = 0; i < A.length; i++) { - if (A[i] >= target) { - return i; - } - } - - return i; - } -} diff --git a/[036][Valid Sudoku]/src/Solution.java b/[036][Valid Sudoku]/src/Solution.java deleted file mode 100644 index 80b5bcd..0000000 --- a/[036][Valid Sudoku]/src/Solution.java +++ /dev/null @@ -1,108 +0,0 @@ -import java.util.Arrays; - -/** - * Author: - * Date: 2015-08-21 - * Time: 16:59 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.
-     * The Sudoku board could be partially filled, where empty cells are filled
-     * with the character '.'.
-     *
-     * A partially filled sudoku which is valid.
-     * Note:
-     * A valid Sudoku board (partially filled) is not necessarily solvable.
-     * Only the filled cells need to be validated.
-     *
-     * Ŀ
-     * ֤һǷϷ̵֤ӶӦҳ档
-     * Dzģյλʹõ档
-     * ע⣺Ϸ̲һҪĿɽģֻҪҪͿԡ
-     *
-     * ˼·
-     * ȶнм飬ٶнм飬飳*ķ
-     * 
- * - * @param board - * @return - */ - public boolean isValidSudoku(char[][] board) { - // .ASCIIֵ460ASCIIֵ48/ASCIIֵ47 - int number = board[0].length; - int[] record = new int[10 + 2]; //.9ֵݵλ[2, 10] - boolean isValid; - reset(record); - - // нм - for (int i = 0; i < number; i++) { - for (int j = 0; j < number; j++) { - record[board[i][j] - '.']++; - } - - // Ǽʧ - if (!check(record)) { - return false; - } - // ɹ - else { - reset(record); - } - } - - // нм - for (int i = 0; i < number; i++) { - for (int j = 0; j < number; j++) { - record[board[j][i] - '.']++; - } - - if (!check(record)) { // Ǽʧ - return false; - } else { // ɹ - reset(record); - } - } - - // 3*3 - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 3; j++) { - - for (int k = i * 3; k < (i + 1) * 3; k++) { - for (int l = j * 3; l < (j + 1) * 3; l++) { - record[board[k][l] - '.']++; - } - } - - if (!check(record)) { // Ǽʧ - return false; - } else { // ɹ - reset(record); - } - } - } - return true; - } - - private void reset(int[] a) { - Arrays.fill(a, 0); - } - - /** - * һУһУ3*3ķǷϷ1-9еָ1ͲϷ - * - * @param a ֤ - * @return ؽ - */ - private boolean check(int[] a) { - for (int i = 2; i < a.length; i++) { - if (a[i] > 1) { - return false; - } - } - return true; - } -} diff --git a/[036][Valid Sudoku]/src/sodoku.png b/[036][Valid Sudoku]/src/sodoku.png deleted file mode 100644 index e37925927203736ee9bf73ce716e3e8a54191f46..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 14593 zcmZvD2RPRK|1XsWnq+15$Ow^9*`l&Tk(rS_LK%?}ky2Jxl2MB6kR-cdtL%~N5y{S; z=kd()m7#9k~5H#kdW+ER5*Vb|6L{i*}W704w%rB z#D8|0D9fKG*&_aWQJNA#Lc&U-cwR=+EpD>MRY$X9ab|W}o$Ndr*$!oD9&Q@yQ(6<9 z^@k4yF|3`+tvnxm$+SZ!np{JOSl`m5Tu zD$>!fL0>l|LL0V^_UqcxwSSFqTI^Nc$#rl?qNY%j>o#9jg$9)c|NQ(@)1^xZNuTEC z<^mo)dZ`q}9m%7u+N?veXV0Fbq$KqMdxKij3-a=8(e}3I~16+?R$#qPTO^j4d-6CaN#)VNLBC=_Rzxz4!qcuEGjNmW_B3; z9C-@e0?!C-8*`))!;yo50|sd$!#wi$v*84kfq(h zX1w@|r8YVu;#{_2sbR7AV8z4v={_SKMbh=9@~x5O*`e-|+Yy{<2_*gF<4O$)k}(pu z-wtc%D+eCt(Yk@3_Fj+SFI(Q`;NZYyer(LI%Kwcz*Y17$s=B(K)kX2pc0GUgEWNGb zw0*aNg2L|LBWGTl*FWK+Cg(FKs)!SH>dZCWHQMkz#ia6)Ua&5Mq{m{=+R`*_;dIk0 z`Qed~+#3V3OqT3p&+xK?BO@1#jbBg~Qs+31D2=ygDgStD-u6>aNN9F;_UOrzkGIxG zrFnJVo}ZKGb;;1mGHFY{;{U#{&}rA1GiMmi*neG{F3*1Ob%%jqXTumXGc(yE#*cM% zk79%@x82xSb@58NVspK(jLGL9o7~u`{W51L-!~d@vaxNiVe#UKR8dvk_p`vEy16-g z;LC$Q;!HBT9vO^9^BcX^%F@%!)CuFb_-v+@^Z5ZLrV|(J$;>P*ou;})U#rGH%E~&S z@meKJ!ou2RqEq0|p+jRo3$j0azjh42fBN)kVXHl(|vJmTWwcJJBq>D#x9;civNf7-K1f*4LIHN@;LdO2Gu;^gG?#-La( zg5zTA&$oGbx^K<)1k#)s{IXwqc&ev3^0_4 zeJ+)?u$KGWd$Vx$Ph1>h+43Mo+192cXFVhI+b*?!t)f?yL9rvxGdX6?c6o z$8|JIqGj@D!LG;ac}0bVq8ZxRRaI5@4T^6iYCbw8^yplg=3AFPS}H0k71qUJO-hLw zJL`3HbgYJMY}IskGkSP*(q#GG_~4GPrj{(*0e6&_U;mL$XF#o<7gNd(YT+ zv$C=IwYF;BS(`jl$?e&d~+`POYqpj6wV%=1R0&gx&_l>4Jzhly#sq4S!@~1sG zUfk8@L|RFS#Nxz{FW3``N#MxH-v;T?K>o5uJqgns@2xw6f`W8Xo*&w$gLdCn!{;n@ zKgDuq`6wcYzH8SmMN`uCxqAL%?Cb(}*4=7N z?S8%wwrofs&899&PG;Y?Z(sO6W^L}MimIx*x+f=;{mBm>V@XYji{q{T{=KTUR&h=T zsPGo&kc3++Gd0q^)lgQ}_iIJP4h;>BT9(+$X^|tt!^So?+_y`xFSs`5kEOeH$493| z>Z9LAMpEDfs!^5NeTAi!4?@uPXhK0rJL+Yx}gz;8N z$@cn!_@UqL*jrLBy^361Tok)~T}DO*Xbc#rHT_-0uA!sz^pHBU$c?ka&s)_V+wFVr zzt)$!h?VZH$(b8I>pZW(8^5qpHD-e2Z5i@E-`ib?O){zb_Kp3Ye|+!V+rh}h#9kT| z`SfYc@0OI?pb{{X^JG_)UcQaB`xIyC*WIC zQ{%f!P>79(hXTux#jdS4*;^Wm6M7Q>2p}b;6Sg|AYaip|W4%C><>3f51vNEo2O$B0 zYgIw?yaq+oF)FX~bpmPmEw(l{E=<|Br5~o{yV|J7E8|qjJ#X9bhB#U(7cc6Td5Yo~ zR03adUvWk9S9fVV+gKTWe(%A9q2IqBMnq6;Zf=HGt`3Dt(}_AB!|9#q%=LS3_j7Lk zw}#Z#y3>;r`f?+6QS7>G-T*xR?=usVlljc@jX|ISO>X*AHq&IqA?;cE8B17v z>--2C>jDr4uASe*hkF3dPu?{~^BE}F+wHGhuK$xC1$CjiCr(4hkIVImiHT32Jrgwk=p!rYJk_nc@xy?t zNBEBXesc0{bK)t-I60~4=oIASc4Ft9$6FOk+>fNr&pThge*KYWwU(r%_vQ*G&U=SV zcc1rGJlGyeHC?_{rXz0{D$F+zcG=pz+h=Jxx@}F9R+B~2J!#=XSy>rbnL}sJQSfH8=U}9|aIld{L`1~h^^Ek% zu6#BLiMZuuH>~bmtO+1)v^iNhoSi#T1s9Zrd?9@Qo;?F!V}w3#xumw;hfbKAEa;o7 zX7N5iPhXpO?!g!kabRG;`FHaL$ylYvER%e*Z8vV-9Edi$^QpP{kk7R*_rsn&s{_vH z=2`6ZSeyvs&`3Q0>wA1X7+kmfj$~6)(|E=d!JTbwQDb9PS%v{?;~ClHo<PgZAvwTs$K%XDZ)O^V`JAuB4!)f7Pk&$PxpGfBM-u{@JXa-ij|vmnc34WDXj_xQYfCtPc~$KU$uSiG3aHZI|RrrPWXk@%$f zP|}l_n1|)%(m0YW?z_5QUM=&a_rdj4W>)4>8IpDAE0ZK3nU&Q?zra4NfG0}n37-M^ z3+Bg1=|Vu?vePde3*%;os;OvctApr;a&mKlrA$DvM)55>keVFWLP1gSsEEi@`A}wo8~tZ3zCKNi5+QM&>P}RS<`Z`4 zjf0-OlxuQfs=M%&vse`tMcd=ebF3ZEY24v+*ZhN%whHE-rdfotdT0Hm&}kIP8u}?PEsdSfKA%5-c0N?! z-mX=eZlk0`4t*V7%G!~BCD3bak#t2P20)gkp6JVEzg_+1$`}a^4UOLO-A5HNJXhw# z0?h&NE8!i!zbg7o|A*>*u^E&Q6;(tj*wc0*F5}d_y}h8OZAXqAvG^XBwxI8XdjfNiWBh5Gqm$F@-@jiv zI--G?uhpJ^|9E$M<%SKZ&%&RMmiKo0zP`Rzy(I+EBwKuY#whA|Z)WC(SIUwedqOEk za%LuPRS1(Z!2jscqwlO+cGgTwjSmfd0kh4_&L$d_-_d*M+W(Q1&#*+H_|_!xSu8A8 z%AdfW4E+9Gi=!*z^otUQU+*DjN$mIM(hbA45yW$R`t(UNL+fHGKjb6cMABlZfpU&X z^4PI^xXZgLfJIV?Q z0q$!!Zp*(@o?A61?ZIVjRN@`z0kpH@gG^0LEw8P$ytCFIw(Dx4px@5DgHR!>s z*3^tR!jRNq+gc|R4dWSB-$O)*dM=;5lCGHugms?ojfZ1TE1;;l=#qE>Bq!?h>i{)% zMf#Nt5$CZ3M^0a7J#iwqHiGkyXnluJjqEOhV@~M3GsdOROuI~`tgMW!y7>3kx7%AA zOLwY;K_^3`dk>+s;n{MR2af;;moz=AVkc{zNw?F~1Yns{v7mP%Q zehm+w#}##(8{X5AZN#6$&%tpY0`HoorF>73%R=OUv{0vPUx5RQ^yV^KSXda8`pt#$ zE1sU7GfPV;I1_qylR`GFTqGQ7312_??NU@z<3uI`D83ILHKp%T-y%sef(Wg`&iSfHp|%iHO3TPxHb5p z5RhM3LPE%^S8SyoORovDQV}ce$_J1dKU<&;&#LMq3;p#(eLcPASMvMgLliO$icdp_wCYL>^k}}43wC|ul=JD1 z9PJJnkN?8fp0vuYF1!O**ipWFHSTjlUKS5LU`b|;^ zx0$n&a^EFNO&&i42PcJ>fP5s!7xdeXR|bp{ii^&_dJdeP6$Rb)M_g{JR-@%2p2e!5*BvdW4iq z`%T<%=rnFR$vdki**RJP5^-_yLsV2Qn`e%z_WYlii5_i;x z4<8y!JzQ(2v&kL!ffvMm$Nu{JlOa6%QePhkjQK5oDsi`3g2cf3%HN9W>WHW)f4G;u zM^0C?wB&VGb896|_mw|~g*~iy|3`cK6XXX2qodjrJ9hLek3<_iJ$cR7J>LDWrKRNp zxw!8DaVV)cRAA8X{67jDjBXq@<*j^nyDO4H7{D48_BspkrKI0nq8=;*yEGfiUJc-fS~EwSX+kn-}0>uHI=`@C+X?wgIJ^! z-kR4t&JEXYTY3axu3TW>GygPxMhq8>r&T{kHD2u9^&f}uNI>NuWnRVZzyF?TT4pk6 zyZ8<(=D(Qs{$a?g`=j9NW50>O4ygAW)h%%oKq@9GWcj@Ut{1=><-N7m=ZRGBYWbZWxzyvztM@Jd@tEUe*Qv6VUq=x3{)@qz z>$h`#DVjA-J-FWTdM}c@B;=(!`ucyH>TecM@bJ1-%R+R(Bt@;FzNQi8Pi zcbLnN*w`b)VY_9tJ($9)^3h?~?>ty!$fXM{uP<6d1{mF0VJGr17=q(7b!>Dy+qTiA zhw5dI_Y|M;S)EWhc@;r#5_XGG(w!PSO?)OZv!tpmqaoRH*fEk)_XX~EYWb7M7#McZ zIKR5Hu}X5m&{?B&cdFLWgOty4nc${m(==%^IE$#bRB_%>-ax{%F{ zHKbghp^4i950I3=;%$^z=aojiV5$ybViOX|Yg|N>d;^CIVkR*Ev`>|GPl{@M9sC|4 zBA^4*vky2S&m@A=V1`r6gMs|Q`*_FhqZNof<6!a8ht$p8UC?dD7?Nfgju;JrN#hF{ zN(NztK5KGsA@e$FWT|pc0myrH{`m0&n;Z|5YieOph2(;qmv@$fq5KsQxPhO9a09|4 zB6N#yodEQ*3kZa%Nv+(YpydPb8@=4cu8;w|Cp;GP0+5uMNK{cv=)Av9U%oyUxLjlI z14pe4?^Ni$B~|P?Z86qA{r^JXf5rc){8j9noKC;K(kuFM-&qJwQd}7aSZ6yf-ZK zJYN6pTNHQ*7dNAvrnIB?nqZ6y@8VIb^BW<(Ns3e;EOzUYg;!PaH1r}jjB_pfA}b(* zly2QR4UHEi(H?M+Eg(3U%=nWp8Kj_Gvl}kQFW@jEVzg!vlHA-}BGy7COE^VE)1ERf z{hs@2jw5v{@nTn+-S#s}^dsZ`*w7G)WCK3S7}5m_`6RS=t*O`AWC0n?rsg&!et!Ps zR^V-vk7IL^VtDms?kFWlj^xc%{;^A4?)kvQ?0N=l_Qit=!4FR4Qp#xgDvc*?fDe^yj=)ZgNQUCBN43u@#OER2H zq|)c~Md|&)MNO|S9>D<)t2Gl56(yoI*>mR>;=A+-3<79XefmU7MMZ@he-279M$r7x zYC`^u1x_Q<`kY&ndiVDpk*j}l0xx_a%&GO%r3sEeZX6<0um{SOM0Kv3`g)$Xg#`zj zT#&lj;0M=fX6VNXSb*%ZRiy^{vQpFs;o;$KtMkVJ9hMMcs1DQnevtKWw_DDG%nvd% ztK!Xb8A|q$VMjt>ZUm8rb8Ej*!CpX7rzl2nV6Pj~ukd)KEVoNYN=9I=%e+w{Pa3@9nwXTM~02kY@JVnZ7Xr zp`oNE%Xy%i+Q$2At&IV`b0hUQQj8LA>V3cI*n@kUzJ2?4)5V3IhbIsRmbNpc$k7w*N|a3> zW6lJGhVF8+`>Efyh>R4g`#P^A$->;+KPHAASp*YIu@Y0CivoYVI1{uF?2Gya>`Y&#BgK7lJqBr_Uw(q1g zhD5&p^L^IG%@8K>Ippl)$BPSKhv=aYHHQ5wfH;3!)TEn|m1!l-7VV#jx!5Fzia|MP zdG{1LS@s-W1-2eF3q+Jl-X*`T#Mz3VvfIlb?Dq2<9XrrV%=!1}^Qt5y zbm_z_z}Sm~L`}WU&dx@B1eXGX#Nl^^I>|b2vj1;!{ldO>xWAuuC7lB(fen8w<}yB( z#3P54lz@$~rgL*Tgc^{PWby&Np<(^Ux+Ev( zD+b+@3l{=GbC4WoD36ek#_QEpAV8gVij~q)NlAkz5fQHI+QRo^wbWv*rE7X$eL2^@bQZbr{QC9Fy+)<60?CF>iQCP@ z(T0|m28wDYFW|6c*uAOL{QS*V_{`jPHZkLaA791|vG_yD-@eA^DbcajLc zhlkDJ84S|fMR-nN{Ne(Bnd17N&RjNdMH1919H{|y5vlw9*g?cWub@hH?Ak?37dAFL ztZ8+v>CEjvfj1#X$c%Bf9Xz;Xwt4eAMxkB?396xZRZ1TAdw0*I>%H9(Ft5sUDFdD_ zA$>Lj4{>^&X8L6ioc{hN^%E?G@YYOM72u6GZo%hvV@ z2??1A(j#2{8Ydb7I&I3g)ea6_(n^_1zd&g;S$CAK3_c^*X;fA3{q@=;#fbU%5OoAY znh076^$25u6vrR!Cm}#Vcc=p&7s>l@C|w=XesgsI_(i}N9zAOQq;Ck(9Rkb;r>0a9 z8;DQ|spGT2d)(j0L28%8t8b zszX?$zoVzSi8cxZAf~%~mP-^V843DeeXHj-cPX!k3tx;(ZS>w)&?X*6!tF-b!`=5s zYQoqs;=)2pON$C6)v&avOyf}R3ozo@JH>P58g?1Fd9U#~FC_+gj82Dq{CIZfe&!(5 zZ@BM#?aNj&-h`~eAtL1beikWB2X7EK)^5kg>T3C+p~Gv7UEo&{uT^1td;3b}c($=# zLg>_wzzdh$iZ6pTukEm)dPEGp5LD7h9gkLKKl(5;bMvOuOKcpfaRJ%c z4!I#$CS<4K;3(1 z+=w#F1pGPD!NkAiiZ03=G6$6SZ;li51YYCzrluO1M_t$hNKIh?L=rG%d}|Zi^H2kEQ*T z$78~P#u&>Q8XiuH80f}tplq7!^_W&<<^ifrOk7`B68ls71f|Z7NbGo&#FNWunus&5 zSlilWL~NS5jJF=oFYQ2d66xcJjcA{+*chZC zS`1i15o{$&k?eRsqeHN;CO8x#A|fZ9eyOBurpY1#f$O9I;}3NgI=Q*IS)E8YjgV7b zUjFZFHH${F(qUX2@_Y~UKaCm|zKLTU*(}6R5Av{&i`nIy&#-?&P?t#X)1!0{C=u*{ zmXPo22cL`#9ug!HAHRI@0}JEL8IU@sMY(lZ1vq?AYU|s0+lv(|_t=pKZ!g^bCHy^MKF)%;RYAyT*ov$=KMW zCkRpXk^z{Yo{X)n)ACKVkpAPtKo6*MQIjoJ5=k$r=&Z_?(|CoN8U=8;b>jjyy;lTSo56Zr2D+p`|Cem zPA!X~F2*cKrM8h*Wn<#GN=p}+6HpounBfTt-+N0v(k{KauN4Z^vIe5d!)&8G{POA3 zT?kvJxnV`QQ08xterWqTY*g$7YFy{F16?5+$+}kE-P{_{1>)d~cyE?SHB(WlU%q?@ z+H?p)C)23BtTQ92tQHXlQ3D~*Lm!99gHPzm_w3te0d_?++5AGhg~2Q_!|)-bd0^ak zZ8X)a-U1#n=&2J?QeQ1~kAfjlzI+3=k}&Iz!!@$;_UQ5gk(&W(cu$^aeN1PTSp4CG zI&24S+@q4_gr`q;v#xYoeVQqCo81OO4A7py34%8p=;m?8jD>Wh`I&|ByM0oboOB;nc!~BReZ&> zrRf*&L3bexENN`;+*}#e`%T)HXQ>7UQU$)GJ7doXp^l#MF5)5qSm9wuQIrZ5t*!G} zri!18DSDck!usy41%np;0tEC+d(iM8g3iT#lC!C+V=YPi7l7`&!Ua${Cz zrilAI7p%qgA8-9n=)X^0ih269MyjNmW;;zo!!s&{^C{!=fv$#V`7@1 z;l*61GN(0nY}aUI+?|H@1{O7t(bS=aa?vD?b$8c)Vd}plsi_{>q9P*wBP0I?L*Ic_ zFd6x(d`U#URvpUHg224ilu7)SN~y>-q5~+e2K>o+dP<;>2@~FT*4(0XSj5PHs#reqe9SXA3+@CQ%6MtZ8jNAS05d{LT{kWz zs?T5)Nf$(q>ljs1Xo|E;B~iV9VuJTJF}V?A?;6gUy}HPN$M zfKMXbJ8#1NH$0b)mf5`e0ESC>bs5Li3@j^b*QL3#6lI!pfR2vK>Bfy0Xj8+b9kA!b z^x48v@_Y7(2M-=JW9F07F0i}1+qo+|?SBsd!vZ)ccASV|WMrg9U)7|@+Z3*NASmen zp6s15?Fp8FS%K~r!exXkvdJ$FP{Kzdh9BW%fnku}#9Fiukw7`jVhH61IO~5;C$V_W zkP?%26+FQ}OA*{d+ok;s!U1?{Yfp(wV>^w}$?;zOaKH!N*CxNwsKiYMeh+MZ>+a4d zY*J)WBgDr8bf1_4!hyJEZ?B4Xr=a0wMY#%7W+Q1~O?~+A6=V0szEcjpB|83msyz$5 z_-LR3jq*EQiXqSA<1b=+aT(1KTVY)GY`6#sQmFYq9ibQ}qCr9B?q1}cgP9Cw@+QnDuCK2@#q?&osff5ZQQB^9Vjv0^SO3pV z5@HhcpMU;A0VaR_EGegko0wDb@V9qM%FUWR+c#U8n#xFq`#2h&Nq3nPm#!7{9>%G+w1 zRzeXPT0I}{k%Cu+k@Pb-(bl+LI{6obL?>Xf14(w(SCzkWUP}$MeKNM~nMYCE!3)~t z52ci0CWiu*J=hlj72xgxO26AM@v>kew(!G;oSQ>(KsZd|5VbB$41rA8uU1!UVRobp zSfr;ymiy3(rl4lQr^(>Hl3sy%Bj}-IL^ShwacOC3VyqOsrMu1BvFIfWXsc`381UOJ zgah1~sUH!Ntn_VdK0rkPpu4if)q0Q1nMuRo<`i;AT!nFONXN5x&NTM-8#7CJrdIPR z+gAh}jFa?u0)nCfOd%Dc6Exe6viBcRQF_d0`q`ad=DXqQnu2;VDLFZ9%R>05)T=+8 zNa1TS8CqSPQnLXwXAaMZdB#X0iL3r$O$=F5>Yuaw3PHBi; z4*mlw`AbX-lG|bAZxAqUR`d8MCEdvv=e4!={s8&iU7zBXtz~CtKS)D!AMs+PF4sBg zq7ck{=hjT7bKF680pQKna}?mkA|vm5cO|pI{nmyV8%iDNZOl01-KF-wtAY1m7bF zMHWJ|A6f6@1$W}Q8KZS_1(jk@Tr6($IwcVD5?){|a@ zts=%EjEaq7DGuL3Rfviu92q4Q3ri?Sm?$do?uWI1243qexxHiO&O^-1-;t=2SarN% zLLp=VwNhzVa~Ur@)|oqGtM;d_9a@rI)cz8@-R$Bb1afm-M+YtDQ?i)Ux(Rvx|EnjC z9m|1>SM|;I)iO7tNd=QMr<0nrz{>61n@w&`)BGV+@y?1X^ ziCq(>3R;cu%*va~Q@y1W!&?{AH>HvzV`6HNo;%N#V7vYu*gDiJ$-%*afX6H4D7Bvo z$GNmtuiCV}CVi+V)I1mwd-hBTT6KBxr-Mr~V-9AA&}r~^11@4(bHOXBm|P*jw8Tps z_8Ay}qZ*Ku3;Jmb{HGm?xzY2wT`}?v;Fcv00g+kZ z`zHwr33bRRYH>8!ZfBz0IB@VFY02d=EiJ7|266pENDzoQRwZVNxg+x2)a3CM?k+Vc z7zP*?u(Puh5D;jpHLb6&-#(X;sKnHOS?G;?e}8|>tEChaxqT-AxF6SlpZR@r^Ge14 z(?;|Jz`$b#Z*Q&_mT4S(bQHo7gQXGAp6Lym2FRY-hV=dgt_Ko2LVJOM2$7317>9*w zQx(jF2bGp?NN@gWP7c&E#nFhsVID$?i7~{SygZ^&$K^Y`rem_GcRc#(Q-!s~$%nzg z=E!<5Hv15Kgzy=@S3e*qXc$0|{POO-Nbu%Tm;P&lv)~9bGPa@SiA7En@#IO>Qvp+A zmI>b36sMOkND$V9oDUA=BrlEpS?I(G6G+J<7Kt5CFHn1Wk`$rQ_XNp$oZ+L-SjuG3 zO?IOE4O^3tknmZTvhEVJ>k>v>fE#n}ZgMrTxx}|#q`bs12hqIjHfUZF8TjxaDVMN3 zu3Q|@opc6;W&G$BJwmx+SDTAmY_m?)Mb?i%?S`Wi5x|t)wly4l0{IGQ4{iGTH3*S>X`XHM5u%SLk`n=wds>zYy88M< z0|TFcH;4kv?q;l9x^!ur{!aGyr=C>A!(8RF1iTY7x!9bRG!0JNN1|*^dUstmGc^Z)^J=QBJ z7XkSgwEo>r6lk4YT{M4GWJ_K}JA!w&_v33%7?PlIX>8vxGQBxivB$*31QTGdaahEH zOR*%lg7ngNJj3{Vv)Ou^lnbHY9r0sQE5lTqtAF?xDnD%BwJ!&1ALD5B_;L%%niPfG z2USN1AEuM*i+QGj{(hv#JJC(9enjMy^Fy-@$@VLYFB#2+e&7(f8w$)ThmLEicr zb(D#qvH;SdgJ24%v?Q-ym;_?z`UAcQf{XM8ksv-}^ztiTE@!q&s3VB3dRn;mHmpWv zQP#p~V%-`O{j@^Z4Zr`7=^dXUjlirdyIieIu7@!CM0HOL$Q2Ys3)7rEe|`rfE+`G( z(tv!#1R3j=%`M_Ai2T?GH~ii^hre=e1}y8yZHrMH(mTvhv9bO;PqZ%mF;PRAl%a4I-)SUKyr6pi JjjXZn{{pe9VGsZS diff --git a/[037][Sudoku Solver]/src/Solution.java b/[037][Sudoku Solver]/src/Solution.java deleted file mode 100644 index 299431d..0000000 --- a/[037][Sudoku Solver]/src/Solution.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-09-28 15:06 - **/ -public class Solution { - public void solveSudoku(char[][] board) { - if(board == null || board.length == 0) { - return; - } - solve(board); - } - - public boolean solve(char[][] board){ - for(int i = 0; i < board.length; i++){ - for(int j = 0; j < board[0].length; j++){ - if(board[i][j] == '.'){ - // 尝试1到9的数字 - for(char c = '1'; c <= '9'; c++){ - if(isValid(board, i, j, c)){ - // 将字符放入单元格 - board[i][j] = c; - - // 如果字符可以放入单元格返回true - if(solve(board)){ - return true; - }else { // 如果字符不能放入单元格就是还原成点号 - board[i][j] = '.'; - } - } - } - return false; - } - } - } - return true; - } - - private boolean isValid(char[][] board, int row, int col, char c){ - for(int i = 0; i < 9; i++) { - // 检查行 - if(board[i][col] != '.' && board[i][col] == c) { - return false; - } - // 检查列 - if(board[row][i] != '.' && board[row][i] == c) { - return false; - } - // 检查3*3的单元格 - if(board[3 * (row / 3) + i / 3][ 3 * (col / 3) + i % 3] != '.' - && board[3 * (row / 3) + i / 3][3 * (col / 3) + i % 3] == c) { - return false; - } - } - return true; - } -} diff --git a/[038][Count And Say]/src/Solution.java b/[038][Count And Say]/src/Solution.java deleted file mode 100644 index 59b80b5..0000000 --- a/[038][Count And Say]/src/Solution.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 16:47 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * The count-and-say sequence is the sequence of integers beginning as follows:
-     * 1, 11, 21, 1211, 111221, ...
-     * 1 is read off as "one 1" or 11.
-     * 11 is read off as "two 1s" or 21.
-     * 21 is read off as "one 2, then one 1" or 1211.
-     * Given an integer n, generate the nth sequence.
-     * Note: The sequence of integers will be represented as a string.
-     *
-     * Ŀ
-     * n=1ʱַ1n=2ʱϴַеֵΪϴַ11
-     * 11n=3ʱϴַ112121n=4ʱϴַ21
-     * 12111211ƣдcountAndSay(n)ַ
-     *
-     * ˼·
-     * һn<0ʱnull
-     * ڶn=1ʱ1
-     * n>1ʱn-1صַssĴдԲͬ
-     * з112365477899ֳ112365477899о21
-     * 12131615һ4271829211213161614271829ش˽
-     * 
- * - * @param n - * @return - */ - public String countAndSay(int n) { - - if (n < 1) { - return null; - } - - String result = "1"; - for (int i = 2; i <= n; i++) { - result = countAndSay(result); - } - - return result; - } - - public String countAndSay(String str) { - StringBuilder builder = new StringBuilder(128); - - int count = 1; - for (int i = 1; i < str.length(); i++) { - if (str.charAt(i) == str.charAt(i - 1)) { - count++; - } else { - builder.append(count); - builder.append(str.charAt(i - 1)); - count = 1; - } - } - - builder.append(count); - builder.append(str.charAt(str.length() - 1)); - return builder.toString(); - } -} diff --git a/[039][Combination Sum]/src/Solution.java b/[039][Combination Sum]/src/Solution.java deleted file mode 100644 index 05d51b7..0000000 --- a/[039][Combination Sum]/src/Solution.java +++ /dev/null @@ -1,43 +0,0 @@ -import java.util.ArrayList; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; - -/** - * @author: wangjunchao(王俊超) - * @time: 2018-09-28 15:11 - **/ -public class Solution { - public List> combinationSum(int[] nums, int target) { - // 用于保存结果 - List> list = new LinkedList<>(); - Arrays.sort(nums); - backtrack(list, new ArrayList<>(), nums, target, 0); - return list; - } - - // 回溯法 - // list:保存总的结果 - // tempList:保存临时结果 - // nums:输入的数组 - // remain:剩下的值 - // start:可用的值在数组中的起始位置 - private void backtrack(List> list, List tempList, int [] nums, int remain, int start){ - // 不够减 - if(remain < 0) { - return; - } else if(remain == 0) { // 刚好够减 - list.add(new LinkedList<>(tempList)); - } else { - // 从剩下的数中一个一个尝试 - for(int i = start; i < nums.length; i++){ - // 假设这个值是临时结果中的一个值 - tempList.add(nums[i]); - // 处理下一步 - backtrack(list, tempList, nums, remain - nums[i], i); - // 现场还原 - tempList.remove(tempList.size() - 1); - } - } - } -} diff --git a/[040][Combination Sum II]/src/Solution.java b/[040][Combination Sum II]/src/Solution.java deleted file mode 100644 index c766df0..0000000 --- a/[040][Combination Sum II]/src/Solution.java +++ /dev/null @@ -1,44 +0,0 @@ -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; - -/** - * @author: wangjunchao(王俊超) - * @time: 2018-09-28 15:15 - **/ -public class Solution { - public List> combinationSum2(int[] nums, int target) { - List> list = new LinkedList<>(); - Arrays.sort(nums); - backtrack(list, new LinkedList<>(), nums, target, 0); - return list; - - } - - /** - * @param list 结果集 - * @param tempList 临时结果集 - * @param nums 可选值数组 - * @param remain 剩余值 - * @param start 可选值的起始下标 - */ - private void backtrack(List> list, List tempList, int[] nums, int remain, int start) { - if (remain < 0) { - return; - } else if (remain == 0) { - list.add(new LinkedList<>(tempList)); - } else { - for (int i = start; i < nums.length; i++) { - // 如果上一轮循环没有选nums[i],则本次循环就不能再选nums[i], - // 确保nums[i] 最多只用一次 - if (i > start && nums[i] == nums[i - 1]) { - continue; - } - tempList.add(nums[i]); - // 数值不可以被重用 - backtrack(list, tempList, nums, remain - nums[i], i + 1); - tempList.remove(tempList.size() - 1); - } - } - } -} diff --git a/[041][First Missing Positive]/src/Main.java b/[041][First Missing Positive]/src/Main.java deleted file mode 100644 index 3a25e0e..0000000 --- a/[041][First Missing Positive]/src/Main.java +++ /dev/null @@ -1,20 +0,0 @@ -import org.junit.Assert; -import org.junit.Test; - -import java.util.Arrays; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-19 14:38 - **/ -public class Main { - - @Test - public void test1() { - Solution solution = new Solution(); - int[] arr = {1, 4, 3, 3, 2}; - int result = solution.firstMissingPositive(arr); - System.out.println(Arrays.toString(arr)); - Assert.assertEquals(5, result); - } -} diff --git a/[041][First Missing Positive]/src/Solution.java b/[041][First Missing Positive]/src/Solution.java deleted file mode 100644 index b551643..0000000 --- a/[041][First Missing Positive]/src/Solution.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-09-28 15:18 - **/ -public class Solution { - /** - *
-     * Given an unsorted integer array, find the smallest missing positive integer.
-     *
-     * Example 1:
-     *
-     * Input: [1,2,0]
-     * Output: 3
-     * Example 2:
-     *
-     * Input: [3,4,-1,1]
-     * Output: 2
-     * Example 3:
-     *
-     * Input: [7,8,9,11,12]
-     * Output: 1
-     *
-     * 本质上是桶排序(bucket sort),每当A[i]!= i+1 的时候,将A[i] 与A[A[i]-1] 交换,
-     * 直到无法交换为止,终止条件是A[i]== A[A[i]-1]。
-     * 
- * @param nums - * @return - */ - public int firstMissingPositive(int[] nums) { - int n = nums.length; - for (int i = 0; i < n; i++) { - // nums[i] == nums[nums[i] - 1] 说明出现了两个同样的元素或者两个是同一个元素 - while (nums[i] > 0 && nums[i] <= n && nums[i] != nums[nums[i] - 1]) { - swap(nums, i, nums[i] - 1); - } - } - for (int i = 0; i < n; i++) { - if (nums[i] != i + 1) { - return i + 1; - } - } - - return n + 1; - } - - private void swap(int[] nums, int i, int j) { - int temp = nums[i]; - nums[i] = nums[j]; - nums[j] = temp; - } -} diff --git a/[042][Trapping Rain Water]/src/Solution.java b/[042][Trapping Rain Water]/src/Solution.java deleted file mode 100644 index 810a76c..0000000 --- a/[042][Trapping Rain Water]/src/Solution.java +++ /dev/null @@ -1,149 +0,0 @@ -import java.util.Deque; -import java.util.LinkedList; - -/** - * @author: wangjunchao(王俊超) - * @time: 2018-09-28 15:20 - **/ -class Solution { - - public int trap(int[] height) { - return trap4(height); - } - - /** - *
-     * 对于每个柱子,找到其左右两边最高的柱子,该柱子能容纳的面积就是min(max_left,max_right) - height。所以,
-     * 1. 从左往右扫描一遍,对于每个柱子,求取左边最大值;
-     * 2. 从右往左扫描一遍,对于每个柱子,求最大右值;
-     * 3. 再扫描一遍,把每个柱子的面积并累加。
-     * 
- * - * @param height - * @return - */ - public int trap1(int[] height) { - int ans = 0; - int size = height.length; - for (int i = 1; i < size - 1; i++) { - int maxLeft = 0; - int maxRight = 0; - // 找此柱左边最高的柱子 - for (int j = i - 1; j >= 0; j--) { - maxLeft = Math.max(maxLeft, height[j]); - } - // 找此柱子右边最高的柱子 - for (int j = i + 2; j < size; j++) { - maxRight = Math.max(maxRight, height[j]); - } - - // Math.min(maxLeft, maxRight) - height[i] 此柱子可以容纳的水 - ans += Math.min(maxLeft, maxRight) - height[i]; - } - return ans; - } - - int trap2(int[] height) { - if (height == null || height.length == 0) { - return 0; - } - int ans = 0; - int size = height.length; - int[] leftMax = new int[size]; - int[] rightMax = new int[size]; - - - // 对于每个柱子求左右最大值,并保存起来 - for (int i = 1; i < size - 1; i++) { - leftMax[i] = Math.max(height[i], leftMax[i - 1]); - rightMax[size - i - 1] = Math.max(height[size - i], rightMax[size - i]); - } - - - for (int i = 1; i < size - 1; i++) { - ans += Math.min(leftMax[i], rightMax[i]) - height[i]; - } - return ans; - } - - /** - *
-     * 用一个栈辅助,小于栈顶的元素压入,大于等于栈顶就把栈里所有小于或
-     * 等于当前值的元素全部出栈处理掉,计算面积,最后把当前元素入栈
-     *
-     *
-     *
-     *         =
-     *    =   === =
-     *  = == =======
-     * =============
-     * 0123456789012
-     * 
- * @param height - * @return - */ - int trap3(int[] height) { - int ans = 0, current = 0; - Deque st = new LinkedList<>(); - while (current < height.length) { - // 当前元素比栈顶元素大 - while (!st.isEmpty() && height[current] > height[st.getFirst()]) { - int top = st.pop(); - if (st.isEmpty()) { - break; - } - - // 求距离,如上图,比如current=7,此时top=4,top到current距离:current-top-1 - int distance = current - st.peek() - 1; - // top以下的水位已经计算过了,top以上的水位就 - // height[current] - height[top], height[st.peek()] - height[top] - // 较小的值,简化为以下面的表达式 - int boundedHeight = Math.min(height[current], height[st.peek()]) - height[top]; - ans += distance * boundedHeight; - } - - // 当前元素不大于栈顶元素 - st.push(current++); - } - return ans; - } - - /** - *
-     * 1. 扫描一遍,找到最高的柱子,这个柱子将数组分为两半;
-     * 2. 处理左边一半;
-     * 3. 处理右边一半。
-     * 
- * - * @param height - * @return - */ - int trap4(int[] height) { - int left = 0; - int right = height.length - 1; - int ans = 0; - int leftMax = 0; - int rightMax = 0; - - while (left < right) { - if (height[left] < height[right]) { - if (height[left] >= leftMax) { - leftMax = height[left]; - } else { - ans += leftMax - height[left]; - } - - ++left; - } else { - if (height[right] >= rightMax) { - rightMax = height[right]; - } else { - ans += rightMax - height[right]; - } - - --right; - } - } - return ans; - } -} diff --git a/[043][Multiply Strings]/src/Solution.java b/[043][Multiply Strings]/src/Solution.java deleted file mode 100644 index 1570a3f..0000000 --- a/[043][Multiply Strings]/src/Solution.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-09-28 15:23 - **/ -public class Solution { - public String multiply(String num1, String num2) { - int m = num1.length(), n = num2.length(); - int[] pos = new int[m + n]; - - int mul; - int index; - int temp; - for (int i = m - 1; i >= 0; i--) { - for (int j = n - 1; j >= 0; j--) { - // 求积 - mul = (num1.charAt(i) - '0') * (num2.charAt(j) - '0'); - // 积的最低位所在的位置 - index = i + j + 1; - - // 最低低求和 - pos[index] += mul; - - // 做进位处理 - while (pos[index] > 9) { - temp = pos[index]; - pos[index] = temp % 10; - --index; - pos[index] += temp / 10; - } - - } - } - - StringBuilder sb = new StringBuilder(); - for (int p : pos) { - if (!(sb.length() == 0 && p == 0)) { - sb.append(p); - } - } - return sb.length() == 0 ? "0" : sb.toString(); - } -} diff --git a/[044][Wildcard Matching]/src/Solution.java b/[044][Wildcard Matching]/src/Solution.java deleted file mode 100644 index 2f5d7e2..0000000 --- a/[044][Wildcard Matching]/src/Solution.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-09-28 15:25 - **/ -public class Solution { - public boolean isMatch(String str, String pattern) { - // 匹配串的索引 - int s = 0; - // 模式串的索引 - int p = 0; - // 记录匹配的匹配位置 - int match = 0; - // 星号的起始索引 - int starIdx = -1; - while (s < str.length()) { - // 两个指针都往前推进 - if (p < pattern.length() && (pattern.charAt(p) == '?' || str.charAt(s) == pattern.charAt(p))) { - s++; - p++; - } - // 发现一个*,只前进模式串索引 - else if (p < pattern.length() && pattern.charAt(p) == '*') { - // 记录最后一次发现*的位置 - starIdx = p; - // 记录在匹配串中匹配*时的位置 - match = s; - // 模式串索引向前推进 - p++; - } - // last pattern pointer was *, advancing string pointer - // 最后的模式串索引是*,匹配串索引向前推进。这个条件隐含p >= pattern.length(),再加上starIdx != -1 - // 说明存在*号匹配,在星号匹配的 - else if (starIdx != -1) { - // 记录模式串最后处理的*号的下一个位置 - p = starIdx + 1; - // 记录在匹配串中匹配*时的位置 - match++; - // 匹配串索引向前推进 - s = match; - } - // 当前的模式索引指向的不是*号,最后一个模式索引指向的也不是*号,说明不匹配 - else { - return false; - } - } - - // 检查余下的模式串,模式串必须全都是*号才行 - while (p < pattern.length() && pattern.charAt(p) == '*') { - p++; - } - - return p == pattern.length(); - } -} diff --git a/[045][Jump Game II]/src/Solution.java b/[045][Jump Game II]/src/Solution.java deleted file mode 100644 index 3f11ba2..0000000 --- a/[045][Jump Game II]/src/Solution.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * 使用贪心算法,每次都移动最远的距离 - * - * @author: wangjunchao(王俊超) - * @time: 2018-09-28 15:27 - **/ -public class Solution { - - public int jump(int[] nums) { - - if (nums == null || nums.length < 2) { - return 0; - } - - // 记录跳跃次数 - int jump = 0; - // 记录当前可以到达的最远的位置 - int currentMax = 0; - // 下一次可以到达的最远的位置 - int nextMax = 0; - // 记录处理的位置 - int i = 0; - - // 还没有到最未位置,还可以移动 - while (currentMax - i + 1 > 0) { - // 跳数增加 - jump++; - // 找下一次最远可以移动的位置 - for (; i <= currentMax; i++) { - nextMax = Math.max(nextMax, nums[i] + i); - // 如果下一次可以移动到最末的位置,则返回跳数 - if (nextMax >= nums.length - 1) { - return jump; - } - } - - // 本次处理不能使移动位增加,并且不能到达最末位置,说明永远到不了最后的位置 - if (currentMax == nextMax) { - return Integer.MAX_VALUE; - } - - // 更新当前可以移动的最远位置 - currentMax = nextMax; - } - - return 0; - } - -} diff --git a/[046][Permutations]/src/Solution.java b/[046][Permutations]/src/Solution.java deleted file mode 100644 index b08b4bb..0000000 --- a/[046][Permutations]/src/Solution.java +++ /dev/null @@ -1,66 +0,0 @@ -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; - -/** - * Author: - * Date: 2015-08-21 - * Time: 16:50 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - private List> result; - - /** - *
-     * ԭ
-     * Given a collection of numbers, return all possible permutations.
-     * For example,
-     * [1,2,3] have the following permutations:
-     * [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].
-     *
-     * Ŀ
-     * һ飬С
-     *
-     * ˼·
-     * ʹ÷η⡣
-     * 
- * - * @param num - * @return - */ - public List> permute(int[] num) { - - result = new LinkedList<>(); - if (num != null) { - permute(0, num); - } - - return result; - } - - private void permute(int i, int[] nums) { - - if (i == nums.length) { - List l = new ArrayList<>(); - for (int n : nums) { - l.add(n); - } - result.add(l); - } else { - - for (int j = i; j < nums.length; j++) { - swap(nums, j, i); - permute(i + 1, nums); - swap(nums, j, i); - } - } - } - - private void swap(int[] nums, int x, int y) { - int tmp = nums[x]; - nums[x] = nums[y]; - nums[y] = tmp; - } -} diff --git a/[047][Permutations II]/src/Main.java b/[047][Permutations II]/src/Main.java deleted file mode 100644 index 050363c..0000000 --- a/[047][Permutations II]/src/Main.java +++ /dev/null @@ -1,14 +0,0 @@ -import org.junit.Test; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-19 18:01 - **/ -public class Main { - @Test - public void test1() { - Solution solution = new Solution(); - int[] nums = {1, 1, 2}; - System.out.println(solution.permuteUnique(nums)); - } -} diff --git a/[047][Permutations II]/src/Solution.java b/[047][Permutations II]/src/Solution.java deleted file mode 100644 index 859454a..0000000 --- a/[047][Permutations II]/src/Solution.java +++ /dev/null @@ -1,62 +0,0 @@ -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * @author: wangjunchao(王俊超) - * @time: 2018-09-28 15:29 - **/ -public class Solution { - - public List> permuteUnique(int[] nums) { - List> res = new ArrayList<>(); - - if (nums == null || nums.length == 0){ - return res; - } - - boolean[] used = new boolean[nums.length]; - List list = new ArrayList<>(); - - Arrays.sort(nums); - - permuteUnique(nums, used, list, res); - return res; - } - - /** - * 时间复杂度:n! - * @param nums - * @param used - * @param list - * @param res - */ - private void permuteUnique(int[] nums, boolean[] used, List list, List> res) { - if (list.size() == nums.length) { - res.add(new ArrayList<>(list)); - return; - } - - for (int i = 0; i < nums.length; i++) { - // 第i个数值已经被使用过 - if (used[i]) { - continue; - } - - // 第i个字符与前一个字符相等,并且第i-1个字符没有使用,说明此次不应该交换 - if (i > 0 && nums[i - 1] == nums[i] && !used[i - 1]) { - continue; - } - - // 标记第i个字符已经被使用 - used[i] = true; - // 添加到临时结果中 - list.add(nums[i]); - // 下一次处理 - permuteUnique(nums, used, list, res); - // 现场还原 - used[i] = false; - list.remove(list.size() - 1); - } - } -} diff --git a/[048][Rotate Image]/src/Solution.java b/[048][Rotate Image]/src/Solution.java deleted file mode 100644 index bba7234..0000000 --- a/[048][Rotate Image]/src/Solution.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-09-28 15:31 - **/ -public class Solution { - public void rotate(int[][] matrix) { - int temp; - - // 先做y=x对称转换 - for (int i = 0; i < matrix.length; i++) { - for (int j = i; j < matrix.length; j++) { - temp = matrix[i][j]; - matrix[i][j] = matrix[j][i]; - matrix[j][i] = temp; - } - } - - // 再对行进行垂直转换 - int half = matrix.length / 2; - for (int i = 0; i < matrix.length; i++) { - for (int j = 0; j < half; j++) { - temp = matrix[i][j]; - matrix[i][j] = matrix[i][matrix.length - 1 - j]; - matrix[i][matrix.length - 1 - j] = temp; - } - } - } -} diff --git a/[049][Group Anagrams]/src/Solution.java b/[049][Group Anagrams]/src/Solution.java deleted file mode 100644 index 3ff45ad..0000000 --- a/[049][Group Anagrams]/src/Solution.java +++ /dev/null @@ -1,80 +0,0 @@ -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * @author: wangjunchao(王俊超) - * @time: 2018-09-28 15:33 - **/ -public class Solution { - - public List> groupAnagrams(String[] strs) { - return groupAnagrams2(strs); - } - - /** - * 算法原理:对字符串进行排序,相同类型的字符串排序后的字符串都是一样的 - * - * @param strs - * @return - */ - public List> groupAnagrams1(String[] strs) { - if (strs.length == 0) { - return new ArrayList(); - } - Map ans = new HashMap<>(); - // 处理每一个字符串 - for (String s : strs) { - char[] ca = s.toCharArray(); - // 对象字符串对应的字符数组进行排序,再转成排序后的字符串 - Arrays.sort(ca); - String key = String.valueOf(ca); - // 如果map中不包含已经排序后的字符串,那么就创建一个新容器要放入结果 - if (!ans.containsKey(key)) { - ans.put(key, new ArrayList()); - } - - // 结果放入对应的集合中 - ans.get(key).add(s); - } - return new ArrayList(ans.values()); - } - - /** - * 算法原理:统计每个字符出现的次数,然后使用#字符将每个字符出现的次数拼成一个字符串, - * 相同类型的字符串通过上面的方式拼出来的字符串都是一样的 - * - * @param strs - * @return - */ - public List> groupAnagrams2(String[] strs) { - if (strs.length == 0) { - return new ArrayList(); - } - Map ans = new HashMap<>(); - int[] count = new int[26]; - - for (String s : strs) { - // 清零操作 - Arrays.fill(count, 0); - for (char c : s.toCharArray()) { - count[c - 'a']++; - } - - // 字符串拼接 - StringBuilder sb = new StringBuilder(""); - for (int i = 0; i < 26; i++) { - sb.append('#'); - sb.append(count[i]); - } - String key = sb.toString(); - if (!ans.containsKey(key)) { - ans.put(key, new ArrayList()); - } - ans.get(key).add(s); - } - return new ArrayList(ans.values()); - } -} diff --git a/[050][Pow(x,n)]/src/Solution.java b/[050][Pow(x,n)]/src/Solution.java deleted file mode 100644 index 43aafc9..0000000 --- a/[050][Pow(x,n)]/src/Solution.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Author: - * Date: 2015-06-23 - * Time: 10:56 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Implement pow(x, n).
-     *
-     * Ŀ⣺
-     * ʵxnη
-     *
-     * ⷽ
-     * ݹ
-     * 
- * - * @param x - * @param n - * @return - */ - public double myPow(double x, int n) { - if (x == 0 && n == 0) { - throw new IllegalArgumentException(); - } - - // ָ - boolean isNegative = false; - - // nľֵ - if (n < 0) { - n = -n; - isNegative = true; - } - - double result = pow(x, n); - - if (isNegative) { - return 1.0 / result; - } else { - return result; - } - } - - public double pow(double x, int n) { - if (n == 0) { - return 1; - } else { - double result = pow(x, n / 2); - // n - if (n % 2 != 0) { - return x * result * result; - } else { - return result * result; - } - } - } -} diff --git a/[051][N-Queens]/src/Solution.java b/[051][N-Queens]/src/Solution.java deleted file mode 100644 index 7d31661..0000000 --- a/[051][N-Queens]/src/Solution.java +++ /dev/null @@ -1,69 +0,0 @@ -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * @author: wangjunchao(王俊超) - * @time: 2018-09-28 15:36 - **/ -public class Solution { - public List> solveNQueens(int n) { - List> result = new ArrayList<>(); - - if (n < 1) { - return result; - } - - char[][] board = new char[n][]; - for (int i = 0; i < n; i++) { - board[i] = new char[n]; - Arrays.fill(board[i], '.'); - } - - solveNQueens(board, 0, result); - return result; - } - - private void solveNQueens(char[][] board, int row, List> result) { - if (board.length == row) { - List list = new ArrayList<>(); - for (char[] chs : board) { - list.add(new String(chs)); - } - result.add(list); - } - - for (int col = 0; col < board.length; col++) { - if (canPlace(board, row, col)) { - board[row][col] = 'Q'; - solveNQueens(board, row + 1, result); - board[row][col] = '.'; - } - } - } - - private boolean canPlace(char[][] board, int row, int col) { - // 检测之前的列上是否已经放过皇后 - for (int i = 0; i < row; ++i) { - if (board[i][col] == 'Q') { - return false; - } - } - - // 45度角(左下角)上是否已经存在过皇后 - for (int i = row - 1, j = col - 1; i >= 0 && j >= 0; --i, --j) { - if (board[i][j] == 'Q') { - return false; - } - } - - // 135度角上(左上角)是否已经存在过皇后 - for (int i = row - 1, j = col + 1; i >= 0 && j < board.length; --i, ++j) { - if (board[i][j] == 'Q') { - return false; - } - } - - return true; - } -} diff --git a/[052][N-Queens II]/src/Solution.java b/[052][N-Queens II]/src/Solution.java deleted file mode 100644 index 5638da5..0000000 --- a/[052][N-Queens II]/src/Solution.java +++ /dev/null @@ -1,63 +0,0 @@ -import java.util.Arrays; - -/** - * @author: wangjunchao(王俊超) - * @time: 2018-09-28 15:38 - **/ -public class Solution { - public int totalNQueens(int n) { - int[] result = {0}; - - if (n < 1) { - return result[0]; - } - - char[][] board = new char[n][]; - for (int i = 0; i < n; i++) { - board[i] = new char[n]; - Arrays.fill(board[i], '.'); - } - - solveNQueens(board, 0, result); - return result[0]; - } - - private void solveNQueens(char[][] board, int row, int[] result) { - if (board.length == row) { - result[0]++; - } - - for (int col = 0; col < board.length; col++) { - if (canPlace(board, row, col)) { - board[row][col] = 'Q'; - solveNQueens(board, row + 1, result); - board[row][col] = '.'; - } - } - } - - private boolean canPlace(char[][] board, int row, int col) { - // 检测之前的列上是否已经放过皇后 - for (int i = 0; i < row; ++i) { - if (board[i][col] == 'Q') { - return false; - } - } - - // 45度角(左下角)上是否已经存在过皇后 - for (int i = row - 1, j = col - 1; i >= 0 && j >= 0; --i, --j) { - if (board[i][j] == 'Q') { - return false; - } - } - - // 135度角上(左上角)是否已经存在过皇后 - for (int i = row - 1, j = col + 1; i >= 0 && j < board.length; --i, ++j) { - if (board[i][j] == 'Q') { - return false; - } - } - - return true; - } -} \ No newline at end of file diff --git a/[053][Maximum Subarray]/src/Solution.java b/[053][Maximum Subarray]/src/Solution.java deleted file mode 100644 index 9c2d79b..0000000 --- a/[053][Maximum Subarray]/src/Solution.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Author: - * Date: 2015-06-22 - * Time: 12:05 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Find the contiguous subarray within an array (containing at least one number)
-     * which has the largest sum.
-     *
-     * For example, given the array [?2,1,?3,4,?1,2,1,?5,4],
-     * the contiguous subarray [4,?1,2,1] has the largest sum = 6.
-     *
-     * Ŀ⣺
-     * ĺ
-     * ˼·
-     * ̬滮⣬֪ǰkԪصкΪmaxSubѾ¼ˣԼһʱsum
-     * ˵k+1Ԫأƣk+1Ԫ֮ǰĺС0ģ
-     * ôk+1ԪشӶȥûй׵ģԿ԰sum 0
-     *
- * @param nums - * @return - */ - public int maxSubArray(int[] nums) { - // У - if (nums == null || nums.length < 1) { - throw new IllegalArgumentException(); - } - - int max = Integer.MIN_VALUE; - int curSum = 0; - - for (int i : nums) { - // ǰС0ͽǰֵcurSum - if (curSum <= 0){ - curSum = i; - } - // ۼ - else { - curSum += i; - } - - // ϴֵ - if (max < curSum) { - max = curSum; - } - } - - return max; - } -} diff --git a/[054][Spiral Matrix]/src/Solution.java b/[054][Spiral Matrix]/src/Solution.java deleted file mode 100644 index 1d632f7..0000000 --- a/[054][Spiral Matrix]/src/Solution.java +++ /dev/null @@ -1,111 +0,0 @@ -import java.util.ArrayList; -import java.util.List; - -/** - * Author: - * Date: 2015-08-21 - * Time: 17:11 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Given a matrix of m x n elements (m rows, n columns), return all elements
-     * of the matrix in spiral order.
-     * For example,
-     * Given the following matrix:
-     *
-     * [
-     * [ 1, 2, 3 ],
-     * [ 4, 5, 6 ],
-     * [ 7, 8, 9 ]
-     * ]
-     *
-     * You should return [1,2,3,6,9,8,7,4,5].
-     * Ŀ
-     * һm*nľԪص˳
-     *
-     * ˼·
-     * ʹüķȴһУٴұһУٴһУٴһУ
-     * һֱֱеԪضꡣ
-     * 
- * - * @param matrix - * @return - */ - public List spiralOrder(int[][] matrix) { - List result = new ArrayList<>(50); - - if (matrix == null || matrix.length == 0 || matrix[0].length == 0) { - return result; - } - - // ֻһе - if (matrix.length == 1) { - for (int i : matrix[0]) { - result.add(i); - } - - return result; - } - - // ֻһе - if (matrix[0].length == 1) { - for (int i = 0; i < matrix.length; i++) { - result.add(matrix[i][0]); - } - - return result; - } - - // жȦ - int row = matrix.length; - int col = matrix[0].length; - int cycle = row < col ? row : col; - cycle = (cycle + 1) / 2; - - int round = 0; // ¼ǰǵڼȦ - int left = 0; - int right = matrix[0].length - 1; - int top = 0; - int down = matrix.length - 1; - int total = col * row; - int count = 0; - while (round < cycle) { - - // һ - for (int i = left; i <= right && count < total; i++) { - count++; - result.add(matrix[round][i]); - } - top++; // - - // ұһ - for (int i = top; i <= down && count < total; i++) { - count++; - result.add(matrix[i][col - round - 1]); - } - right--; - - // һ - for (int i = right; i >= left && count < total; i--) { - count++; - result.add(matrix[row - round - 1][i]); - - } - down--; - - // һ - for (int i = down; i >= top && count < total; i--) { - count++; - result.add(matrix[i][round]); - } - left++; - - round++; - } - - return result; - } -} diff --git a/[055][Jump Game]/src/Solution.java b/[055][Jump Game]/src/Solution.java deleted file mode 100644 index 2fabd87..0000000 --- a/[055][Jump Game]/src/Solution.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Author: 王俊超 - * Date: 2015-06-19 - * Time: 19:29 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Given an array of non-negative integers, you are initially positioned at the
-     * first index of the array.
-     *
-     * Each element in the array represents your maximum jump length at that position.
-     *
-     * Determine if you are able to reach the last index.
-     *
-     * For example:
-     * A = [2,3,1,1,4], return true.
-     * A = [3,2,1,0,4], return false.
-     *
-     * 题目大意:
-     * 给定的非负整数的数组,则最初定位在数组的第一个位置。数组中的每个元素都代表你的最大跳跃长度在那个位置。
-     * 决定你是否能到达最后一个索引。
-     *
-     * 
- * - * @param nums - * @return - */ - public boolean canJump(int[] nums) { - return canJump2(nums); - } - public boolean canJump1(int[] nums) { - if (nums == null || nums.length < 2) { - return true; - } - - // 最后可以移动的位置 - int lastPos = 0; - - // 处理每一个位置 - for (int i = 0; i < nums.length; i++) { - // i不能比lastPos大,否则说明不能走到i,走不到i也就不能走到最后 - // 如果在i位置可以移动的距离比已经记录到的最大距离还要大,那么更新最大的移动距离 - if (i <= lastPos && i + nums[i] > lastPos ) { - lastPos = i + nums[i]; - } else if (i > lastPos) { - return false; - } - } - - // 最后的位置必然可以达到最后 - return lastPos >= nums.length - 1; - } - - public boolean canJump2(int[] nums) { - int lastPos = nums.length - 1; - for (int i = nums.length - 1; i >= 0; i--) { - if (i + nums[i] >= lastPos) { - lastPos = i; - } - } - return lastPos == 0; - } -} diff --git a/[056][Merge Intervals]/src/Interval.java b/[056][Merge Intervals]/src/Interval.java deleted file mode 100644 index 0905b1b..0000000 --- a/[056][Merge Intervals]/src/Interval.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Author: - * Date: 2015-06-23 - * Time: 19:40 - * Declaration: All Rights Reserved !!! - */ -public class Interval { - int start; - int end; - - Interval() { - start = 0; - end = 0; - } - - Interval(int s, int e) { - start = s; - end = e; - } -} diff --git a/[056][Merge Intervals]/src/Solution.java b/[056][Merge Intervals]/src/Solution.java deleted file mode 100644 index 312eac5..0000000 --- a/[056][Merge Intervals]/src/Solution.java +++ /dev/null @@ -1,60 +0,0 @@ -import java.util.*; - -/** - * Author: - * Date: 2015-06-23 - * Time: 19:39 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Given a collection of intervals, merge all overlapping intervals.
-     *
-     * For example,
-     * Given [1,3],[2,6],[8,10],[15,18],
-     * return [1,6],[8,10],[15,18].
-     *
-     * Ŀ⣬
-     * һ伯ϣϲص
-     *
-     * ˼·
-     * ȶ򣬰ʼһһкϲ
-     * 
- * - * @param intervals - * @return - */ - public List merge(List intervals) { - List result = new LinkedList<>(); - - if (intervals == null || intervals.size() < 1) { - return result; - } - - // ȶʹһڲ - Collections.sort(intervals, new Comparator() { - @Override - public int compare(Interval o1, Interval o2) { - return o1.start - o2.start; - } - }); - - // 󣬺һԪأΪnextstartһDzСǰһΪprevstartģ - // ӵ䣬next.startprev.end˵ǷֿģҪ - // һµ䣬˵next.start[prev.start, prev.end]ڣֻҪ - // next.endǷǴprev.endھҪϲ䣨 - Interval prev = null; - for (Interval item : intervals) { - - if (prev == null || prev.end < item.start) { - result.add(item); - prev = item; - } else if (prev.end < item.end) { - prev.end = item.end; - } - } - - return result; - } -} diff --git a/[057][Insert Interval]/src/Interval.java b/[057][Insert Interval]/src/Interval.java deleted file mode 100644 index 196e728..0000000 --- a/[057][Insert Interval]/src/Interval.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Author: - * Date: 2015-06-24 - * Time: 19:34 - * Declaration: All Rights Reserved !!! - */ -public class Interval { - int start; - int end; - - Interval() { - start = 0; - end = 0; - } - - Interval(int s, int e) { - start = s; - end = e; - } -} diff --git a/[057][Insert Interval]/src/Solution.java b/[057][Insert Interval]/src/Solution.java deleted file mode 100644 index d158b09..0000000 --- a/[057][Insert Interval]/src/Solution.java +++ /dev/null @@ -1,76 +0,0 @@ -import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ; - -import java.util.LinkedList; -import java.util.List; - -/** - * Author: - * Date: 2015-06-24 - * Time: 19:33 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Given a set of non-overlapping intervals, insert a new interval into the intervals
-     * (merge if necessary).
-     *
-     * You may assume that the intervals were initially sorted according to their start times.
-     *
-     * Example 1:
-     * Given intervals [1,3],[6,9], insert and merge [2,5] in as [1,5],[6,9].
-     *
-     * Example 2:
-     * Given [1,2],[3,5],[6,7],[8,10],[12,16], insert and merge [4,9] in as [1,2],[3,10],[12,16].
-     *
-     * This is because the new interval [4,9] overlaps with [3,5],[6,7],[8,10].
-     *
-     * Ŀ⣺
-     * һϵзǸǵ䣬һµ䣬бҪʱϲ
-     * 俪ʼʼʱкϲ
-     *
-     * ˼·
-     * ԭȲСͲص²䣬
-     * Сԭ䣬Ȳ䣬Ӵ
-     * 
- * - * @param intervals - * @param newInterval - * @return - */ - public List insert(List intervals, Interval newInterval) { - - // ļ - List result = new LinkedList<>(); - - // 뼯ǿ - if (intervals != null) { - // Ԫ - for (Interval item : intervals) { - // newInterval == null ʾѾ - // ȲС - if (newInterval == null || item.end < newInterval.start) { - result.add(item); - } - // ȲУͬʱ - else if (item.start > newInterval.end) { - result.add(newInterval); - result.add(item); - newInterval = null; - } - // ص² - else { - newInterval.start = Math.min(newInterval.start, item.start); - newInterval.end = Math.max(newInterval.end, item.end); - } - } - } - - // ǿ˵仹δ - if (newInterval != null) { - result.add(newInterval); - } - - return result; - } -} diff --git a/[058][Length Of Last Word]/src/Solution.java b/[058][Length Of Last Word]/src/Solution.java deleted file mode 100644 index 98d71cb..0000000 --- a/[058][Length Of Last Word]/src/Solution.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 19:27 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Given a string s consists of upper/lower-case alphabets and empty space characters ' ',
-     * return the length of last word in the string.
-     * If the last word does not exist, return 0.
-     * Note: A word is defined as a character sequence consists of non-space characters only.
-     * For example,
-     * Given s = "Hello World",
-     * return 5.
-     *
-     * Ŀ
-     * һɴСдĸͿոɵַַеһʳȡ
-     *
-     * ˼·
-     * ȴӺҵһĸλxûҵͷ0ҵҵһոλΪy(y-1
-     * Ϊûҵո)ؽx-y
-     * 
- * - * @param s - * @return - */ - public int lengthOfLastWord(String s) { - - int index = s.length() - 1; - - // Ӻǰҵһ' 'ַ - while (index >= 0 && s.charAt(index) == ' ') { - index--; - } - - if (index < 0) { - return 0; - } - - int tmp = index; - - // ִе˵һ - - // Ӻǰҵһ' 'ַ - while (index >= 0 && s.charAt(index) != ' ') { - index--; - } - - return tmp - index; - } -} diff --git a/[059][Spiral Matrix II]/src/Solution.java b/[059][Spiral Matrix II]/src/Solution.java deleted file mode 100644 index 3470f7f..0000000 --- a/[059][Spiral Matrix II]/src/Solution.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 19:28 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.
-     * For example,
-     * Given n = 3,
-     * You should return the following matrix:
-     *
-     * [
-     *  [ 1, 2, 3 ],
-     *  [ 8, 9, 4 ],
-     *  [ 7, 6, 5 ]
-     * ]
-     *
-     * Ŀ
-     * һnһn*nľ1-n^2ֽ䡣
-     *
-     * ˼·
-     * üɷÿһλüӦ
-     * 
- * - * @param n - * @return - */ - public int[][] generateMatrix(int n) { - int[][] result = new int[n][n]; - - int layer; - int k; - for (int i = 0; i < n; i++) { - for (int j = 0; j < n; j++) { - layer = layer(i, j, n); // ǰм - // n * n - layer * layerΧʹõһ֣Ҳģ - // ڵĵǰʹõĵһ - k = n * n - (n - 2 * layer) * (n - 2 * layer) + 1; - result[i][j] = k; - - // (n - 2 * layer - 1)ĸ(n - 2 * layer - 1)ǣxyڲԪظ - if (i == layer) { // һϱ߽ - result[i][j] = k + j - layer; - } else if (j == n - layer - 1) { // ұ߽ - result[i][j] = k + (n - 2 * layer - 1) + i - layer; - } else if (i == n - layer - 1) { // ±߽ - result[i][j] = k + 3 * (n - 2 * layer - 1) - (j - layer); - } else { // ߽ - result[i][j] = k + 4 * (n - 2 * layer - 1) - (i - layer); - } - } - } - - return result; - } - - /** - * һn*nľУ㣨x,yжٲ㣬0ʼ - * - * @param x - * @param y - * @param n С - * @return IJ - */ - public int layer(int x, int y, int n) { - x = x < n - 1 - x ? x : n - 1 - x; // ±߽ - y = y < n - 1 - y ? y : n - 1 - y; // ұ߽ - - return x < y ? x : y; // СֵΪΧ - } -} diff --git a/[060][Permutation Sequence]/src/Solution.java b/[060][Permutation Sequence]/src/Solution.java deleted file mode 100644 index 3bc2edf..0000000 --- a/[060][Permutation Sequence]/src/Solution.java +++ /dev/null @@ -1,57 +0,0 @@ -import java.util.ArrayList; -import java.util.List; - -/** - * @author: wangjunchao(王俊超) - * @time: 2018-09-28 15:45 - **/ -public class Solution { - /** - *
-     * 利用康托编码的思路,假设有n 个不重复的元素,第k 个排列是a1; a2; a3; :::; an,那么a1 是
-     * 哪一个位置呢?
-     * 我们把a1 去掉,那么剩下的排列为a2; a3; :::; an, 共计n-1 个元素,n-1 个元素共有(n-1)!
-     * 个排列,于是就可以知道a1 = k/(n - 1)!。
-     * 同理,a2; a3; :::; an 的值推导如下:
-     * k2 = k%(n - 1)!
-     * a2 = k2/(n - 2)!
-     * ...
-     * k(n-1) = k(n-2)%2!
-     * a(n-1) = k(n-1)/1!
-     * an = 0
-     * 
- * - * @param n - * @param k - * @return - */ - public String getPermutation(int n, int k) { - - StringBuilder sb = new StringBuilder(); - List num = new ArrayList<>(); - // 用于计录最大的阶乘数 - int fact = 1; - for (int i = 1; i <= n; i++) { - fact *= i; - num.add(i); - } - - // l = k - 1;为了方便从0开始计数 - int index; - for (int i = 0, l = k - 1; i < n; i++) { - // 从最大的阶乘数开始减少 - // fact的值说明,如果从 __1____ -> _2____ 至少要经过fact次变换 - fact /= (n - i); - // 计算剩下的数据中的索引 - // 说明类似 __1____ -> _2____ 的变化可以做 index 次,0表示不用变 - index = (l / fact); - // 将索引值添加到结果中 - // 每做一次__1____ -> _2____ 的变化,表示在num中取后一个更大的值 - sb.append(num.remove(index)); - // 余下要处理的数 - l -= index * fact; - } - - return sb.toString(); - } -} diff --git a/[061][Rotate List]/src/ListNode.java b/[061][Rotate List]/src/ListNode.java deleted file mode 100644 index 43e96df..0000000 --- a/[061][Rotate List]/src/ListNode.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Author: - * Date: 2015-07-21 - * Time: 18:46 - * Declaration: All Rights Reserved !!! - */ -public class ListNode { - int val; - ListNode next; - - ListNode(int x) { - val = x; - } -} diff --git a/[061][Rotate List]/src/Solution.java b/[061][Rotate List]/src/Solution.java deleted file mode 100644 index 9f4e91d..0000000 --- a/[061][Rotate List]/src/Solution.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Author: - * Date: 2015-07-21 - * Time: 18:46 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - public ListNode rotateRight(ListNode head, int n) { - - if (head == null || n < 1) { - return head; - } - - int length = 1; - ListNode p = head; - while (p.next != null) { - p = p.next; - length++; - } - - // ҪĽڵΪheadǰһڵ - n = length - n % length; - - // β - p.next = head; - for (int i = 0; i < n; i++) { - p = p.next; - } - - head = p.next; - p.next = null; - return head; - } -} diff --git a/[061][Rotate List]/src/Solution2.java b/[061][Rotate List]/src/Solution2.java deleted file mode 100644 index 00ca18f..0000000 --- a/[061][Rotate List]/src/Solution2.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Author: - * Date: 2015-07-21 - * Time: 18:46 - * Declaration: All Rights Reserved !!! - */ -public class Solution2 { - public ListNode rotateRight(ListNode head, int n) { - - if (head == null || n < 1) { - return head; - } - - ListNode root = new ListNode(0); - root.next = head; - ListNode p = root; - ListNode q = root; - - // תλÿܱ - int count = 0; - for (int i = 0; i <= n; i++) { - p = p.next; - count++; - if (p == null) { - // гͷݸ - count--; - // ʵҪλõλ - n = n % count; - // Ϊ¿ʼλ׼ - i = 0; - p = head; - } - } - - // ҵһҪĽǰ - // qΪһҪĽǰ - while (p != null) { - p = p.next; - q = q.next; - - } - - p = q; - q = root; - // ҪλƵĽ - if (p != null && p.next != null) { - ListNode node; - while (p.next != null) { - // ժ - node = p.next; - p.next = node.next; - // Ͻ - node.next = q.next; - q.next = node; - // һƶĽڵ - q = node; - } - } - - return root.next; - } -} diff --git a/[062][Unique Paths]/src/Solution.java b/[062][Unique Paths]/src/Solution.java deleted file mode 100644 index 43be774..0000000 --- a/[062][Unique Paths]/src/Solution.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 19:30 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * A robot is located at the top-left corner of a m x n grid
-     * (marked Start in the diagram below).
-     * The robot can only move either down or right at any point in time.
-     * The robot is trying to reach the bottom-right corner of the grid
-     * (marked Finish in the diagram below).
-     * How many possible unique paths are there?
-     *
-     * Above is a 3 x 7 grid. How many possible unique paths are there?
-     * Note: m and n will be at most 100.
-     *
-     * Ŀ
-     * һһm*nķϽǡ
-     * ֻһһ񣬻Ҫ½ǵķ
-     * һжΨһ·
-     * ע⣺ͣ󲻳100
-     *
-     * ˼·
-     * ͵Ķ̬滮⣬ʹö̬滮ķ⡣
-     * һm*nA
-     * AеԪС
-     * 1x=0y=0ʱA[x][y] = 1
-     * 2x>=1y>=1ʱA[x][y] = A[x-1][y]+A[x][y-1]
-     * 3ĽA[m-1][n-1]
-     * 
- * - * @param m - * @param n - * @return - */ - public int uniquePaths(int m, int n) { - int[][] result = new int[m][n]; - - // һеĽ - for (int i = 0; i < m; i++) { - result[i][0] = 1; - } - - // һеĽ - for (int i = 1; i < n; i++) { - result[0][i] = 1; - } - - // λõĽ - for (int i = 1; i < m; i++) { - for (int j = 1; j < n; j++) { - result[i][j] = result[i - 1][j] + result[i][j - 1]; - } - } - - // Ľ - return result[m - 1][n - 1]; - } -} diff --git a/[063][Unique Paths II]/src/Solution.java b/[063][Unique Paths II]/src/Solution.java deleted file mode 100644 index 66ce05d..0000000 --- a/[063][Unique Paths II]/src/Solution.java +++ /dev/null @@ -1,99 +0,0 @@ -/** - * Author: - * Date: 2015-06-22 - * Time: 21:38 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Follow up for "Unique Paths":
-     * Now consider if some obstacles are added to the grids. How many unique paths would there be?
-     * An obstacle and empty space is marked as 1 and 0 respectively in the grid.
-     *
-     * For example,
-     * There is one obstacle in the middle of a 3x3 grid as illustrated below.
-     * [
-     *      [0,0,0],
-     *      [0,1,0],
-     *      [0,0,0]
-     * ]
-     *
-     * The total number of unique paths is 2.
-     * Note: m and n will be at most 100.
-     *
-     * Ŀ⣺
-     * Ψһ··ϰܵ·
-     * ע⣺
-     * 100
-     *
-     * ˼·
-     * ÷ⷽ
-     *
-     * 
- * - * @param obstacleGrid - * @return - */ - public int uniquePathsWithObstacles(int[][] obstacleGrid) { - // У - if (obstacleGrid == null || obstacleGrid.length < 1 || obstacleGrid[0].length < 1 - || obstacleGrid[0][0] == 1 - || obstacleGrid[obstacleGrid.length - 1][obstacleGrid[0].length - 1] == 1) { - return 0; - } - - int rows = obstacleGrid.length; - int cols = obstacleGrid[0].length; - int[][] result = new int[rows][cols]; - - // һλжַϰ1֣ϰ0 - result[0][0] = obstacleGrid[0][0] == 0 ? 1 : 0; - - // һж߷ϰ0 - for (int i = 1; i < cols; i++) { - result[0][i] = obstacleGrid[0][i] == 0 ? result[0][i - 1] : 0; - } - - // һж߷ϰ0 - for (int i = 1; i < rows; i++) { - result[i][0] = obstacleGrid[i][0] == 0 ? result[i - 1][0] : 0; - } - - // λõĽⷨϰ0 - for (int i = 1; i < rows; i++) { - for (int j = 1; j < cols; j++) { - result[i][j] = obstacleGrid[i][j] == 0 ? result[i - 1][j] + result[i][j - 1] : 0; - } - } - - return result[rows - 1][cols - 1]; - } - - - // ʹõݹ鷽ᳬʱ - public int uniquePathsWithObstacles2(int[][] obstacleGrid) { - // У - if (obstacleGrid == null || obstacleGrid.length < 1 || obstacleGrid[0].length < 1 - || obstacleGrid[obstacleGrid.length - 1][obstacleGrid[0].length - 1] == 1) { - return 0; - } - int[] result = {0}; - solve(obstacleGrid, 0, 0, result); - return result[0]; - } - - public void solve(int[][] grid, int row, int col, int[] sum) { - // յ - if (row == grid.length - 1 && col == grid[0].length - 1) { - sum[0]++; - } - // ûеյ㣬ڣҵǰλò - else if (row >= 0 && row < grid.length && col >= 0 && col < grid[0].length && grid[row][col] == 0) { - // - solve(grid, row, col + 1, sum); - // - solve(grid, row + 1, col, sum); - } - } -} diff --git a/[064][Minimum Path Sum]/src/Main.java b/[064][Minimum Path Sum]/src/Main.java deleted file mode 100644 index 8709016..0000000 --- a/[064][Minimum Path Sum]/src/Main.java +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Author: - * Date: 2015-06-22 - * Time: 16:29 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { - Solution solution = new Solution(); - - int[][] grid = {{5, 0, 1, 1, 2, 1, 0, 1, 3, 6, 3, 0, 7, 3, 3, 3, 1}, {1, 4, 1, 8, 5, 5, 5, 6, 8, 7, 0, 4, 3, 9, 9, 6, 0}, {2, 8, 3, 3, 1, 6, 1, 4, 9, 0, 9, 2, 3, 3, 3, 8, 4}, {3, 5, 1, 9, 3, 0, 8, 3, 4, 3, 4, 6, 9, 6, 8, 9, 9}, {3, 0, 7, 4, 6, 6, 4, 6, 8, 8, 9, 3, 8, 3, 9, 3, 4}, {8, 8, 6, 8, 3, 3, 1, 7, 9, 3, 3, 9, 2, 4, 3, 5, 1}, {7, 1, 0, 4, 7, 8, 4, 6, 4, 2, 1, 3, 7, 8, 3, 5, 4}, {3, 0, 9, 6, 7, 8, 9, 2, 0, 4, 6, 3, 9, 7, 2, 0, 7}, {8, 0, 8, 2, 6, 4, 4, 0, 9, 3, 8, 4, 0, 4, 7, 0, 4}, {3, 7, 4, 5, 9, 4, 9, 7, 9, 8, 7, 4, 0, 4, 2, 0, 4}, {5, 9, 0, 1, 9, 1, 5, 9, 5, 5, 3, 4, 6, 9, 8, 5, 6}, {5, 7, 2, 4, 4, 4, 2, 1, 8, 4, 8, 0, 5, 4, 7, 4, 7}, {9, 5, 8, 6, 4, 4, 3, 9, 8, 1, 1, 8, 7, 7, 3, 6, 9}, {7, 2, 3, 1, 6, 3, 6, 6, 6, 3, 2, 3, 9, 9, 4, 4, 8}}; - -// System.out.println(solution.minPathSum(grid)); - - int[][] grid2 = {{4, 1, 7, 8, 4, 9, 2, 9, 9, 0, 2, 9, 4, 0, 2}, {2, 2, 7, 7, 3, 9, 0, 8, 4, 7, 8, 2, 5, 5, 5}, {2, 9, 8, 1, 7, 2, 0, 2, 1, 9, 4, 5, 0, 1, 5}, {4, 3, 0, 1, 1, 5, 2, 3, 5, 8, 3, 3, 0, 0, 8}, {7, 2, 9, 5, 3, 7, 7, 6, 1, 1, 7, 5, 6, 8, 6}, {4, 4, 2, 6, 6, 3, 1, 0, 8, 7, 9, 1, 0, 1, 3}, {1, 9, 5, 0, 4, 1, 9, 4, 7, 0, 5, 6, 8, 3, 6}, {4, 7, 1, 6, 3, 7, 1, 7, 9, 0, 6, 8, 3, 8, 0}, {7, 9, 1, 4, 2, 5, 7, 1, 1, 6, 4, 6, 3, 2, 2}, {9, 8, 9, 0, 7, 5, 9, 8, 4, 9, 0, 0, 9, 4, 8}, {1, 3, 0, 2, 7, 2, 0, 5, 5, 1, 1, 9, 0, 4, 3}, {2, 4, 4, 3, 6, 1, 0, 6, 1, 4, 5, 2, 4, 4, 8}, {5, 8, 1, 5, 0, 0, 9, 0, 5, 4, 4, 9, 6, 4, 5}}; - -// System.out.println(solution.minPathSum(grid2)); - - - int[][] grid3 = {{0, 7, 7, 8, 1, 2, 4, 3, 0, 0, 5, 9, 8, 3, 6, 5, 1, 0}, {2, 1, 1, 0, 8, 1, 3, 3, 9, 9, 5, 8, 7, 5, 7, 5, 5, 8}, {9, 2, 3, 1, 2, 8, 1, 2, 3, 7, 9, 7, 9, 3, 0, 0, 3, 8}, {3, 9, 3, 4, 8, 1, 2, 6, 8, 9, 3, 4, 9, 4, 8, 3, 6, 2}, {3, 7, 4, 7, 6, 5, 6, 5, 8, 6, 7, 3, 6, 2, 2, 9, 9, 3}, {2, 3, 1, 1, 5, 4, 7, 4, 0, 7, 7, 6, 9, 1, 5, 5, 0, 3}, {0, 8, 8, 8, 4, 7, 1, 0, 2, 6, 1, 1, 1, 6, 4, 2, 7, 9}, {8, 6, 6, 8, 3, 3, 5, 4, 6, 2, 9, 8, 6, 9, 6, 6, 9, 2}, {6, 2, 2, 8, 0, 6, 1, 1, 4, 5, 3, 1, 7, 3, 9, 3, 2, 2}, {8, 9, 8, 5, 3, 7, 5, 9, 8, 2, 8, 7, 4, 4, 1, 9, 2, 2}, {7, 3, 3, 1, 0, 9, 4, 7, 2, 3, 2, 6, 7, 1, 7, 7, 8, 1}, {4, 3, 2, 2, 7, 0, 1, 4, 4, 4, 3, 8, 6, 2, 1, 2, 5, 4}, {1, 9, 3, 5, 4, 6, 4, 3, 7, 1, 0, 7, 2, 4, 0, 7, 8, 0}, {7, 1, 4, 2, 5, 9, 0, 4, 1, 4, 6, 6, 8, 9, 7, 1, 4, 3}, {9, 8, 6, 8, 2, 6, 5, 6, 2, 8, 3, 2, 8, 1, 5, 4, 5, 2}, {3, 7, 8, 6, 3, 4, 2, 3, 5, 1, 7, 2, 4, 6, 0, 2, 5, 4}, {8, 2, 1, 2, 2, 6, 6, 0, 7, 3, 6, 4, 5, 9, 4, 4, 5, 7}}; - System.out.println(solution.minPathSum(grid3)); - - } -} diff --git a/[064][Minimum Path Sum]/src/Solution.java b/[064][Minimum Path Sum]/src/Solution.java deleted file mode 100644 index 295e70c..0000000 --- a/[064][Minimum Path Sum]/src/Solution.java +++ /dev/null @@ -1,110 +0,0 @@ -/** - * Author: - * Date: 2015-06-22 - * Time: 15:59 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - - /** - *
-     * Given a m x n grid filled with non-negative numbers, find a path from top
-     * left to bottom right which minimizes the sum of all numbers along its path.
-     *
-     * Note: You can only move either down or right at any point in time.
-     *
-     * Ŀ⣺
-     * һm x nķÿԪصֵǷǸģҳϽǶ㣬½Ƕ͵ֵС·
-     * ҵС
-     *
-     * ע⣺
-     *   - ÿֻ»ȡƶһ
-     *
-     * Կ˼·
-     * η
-     * һ  S[0][0] = grid[0][0]
-     * һУ  S[0][j] = S[0][j - 1] + grid[0][j]
-     * һУ  S[i][0] = S[i - 1][0] + grid[i][0]
-     * S[i][j] = min(S[i - 1][j], S[i][j - 1]) + grid[i][j]
-     * 
- * - * @param grid - * @return - */ - - public int minPathSum(int[][] grid) { - // - if (grid == null || grid.length < 1 || grid[0].length < 1) { - return 0; - } - - - int[][] result = new int[grid.length][grid[0].length]; - // һ - result[0][0] = grid[0][0]; - - // һ - for (int i = 1; i < result[0].length; i++) { - result[0][i] = result[0][i - 1] + grid[0][i]; - } - - // һ - for (int i = 1; i < result.length; i++) { - result[i][0] = result[i - 1][0] + grid[i][0]; - } - - // - for (int i = 1; i < result.length; i++) { - for (int j = 1; j < result[0].length; j++) { - result[i][j] = Math.min(result[i - 1][j], result[i][j - 1]) + grid[i][j]; - } - } - - return result[result.length - 1][result[0].length - 1]; - } - - //////////////////////////////////////////////////////////////////////////////////////////////// - // ̬黮ͷ֦޽磬ķᳬʱ - //////////////////////////////////////////////////////////////////////////////////////////////// - public int minPathSum2(int[][] grid) { - // - if (grid == null || grid.length < 1 || grid[0].length < 1) { - return 0; - } - - // ڼ¼С· - int[] minSum = {Integer.MAX_VALUE}; - int[] curSum = {0}; - // - solve(grid, 0, 0, curSum, minSum); - - // ؽ - return minSum[0]; - } - - public void solve(int[][] grid, int row, int col, int[] curSum, int[] minSum) { - // Ѿյ - if (row == grid.length - 1 && col == grid[0].length - 1) { - curSum[0] += grid[row][col]; - - // Сĺ - if (curSum[0] < minSum[0]) { - minSum[0] = curSum[0]; - } - - curSum[0] -= grid[row][col]; - } - // δյ㣬 - else if (row >= 0 && row < grid.length && col >= 0 && col < grid[0].length) { - curSum[0] += grid[row][col]; - // ǰĺֻвСڼ¼С·ֵܽһ - if (curSum[0] <= minSum[0]) { - // - solve(grid, row, col + 1, curSum, minSum); - // - solve(grid, row + 1, col, curSum, minSum); - } - curSum[0] -= grid[row][col]; - } - } -} diff --git a/[065][Valid Number]/src/Main.java b/[065][Valid Number]/src/Main.java deleted file mode 100644 index c039e9e..0000000 --- a/[065][Valid Number]/src/Main.java +++ /dev/null @@ -1,95 +0,0 @@ -import org.junit.Assert; -import org.junit.Test; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-17 13:32 - **/ -public class Main { - @Test - public void test1() { - Solution solution = new Solution(); - Assert.assertEquals(true, solution.isNumber("0")); - } - - @Test - public void test2() { - Solution solution = new Solution(); - Assert.assertEquals(true, solution.isNumber(" 0.1 ")); - } - - @Test - public void test3() { - Solution solution = new Solution(); - Assert.assertEquals(false, solution.isNumber("abc")); - } - - @Test - public void test4() { - Solution solution = new Solution(); - Assert.assertEquals(false, solution.isNumber("1 a")); - } - - @Test - public void test41() { - Solution solution = new Solution(); - Assert.assertEquals(true, solution.isNumber("2e10")); - } - - @Test - public void test42() { - Solution solution = new Solution(); - Assert.assertEquals(true, solution.isNumber(" -90e3 ")); - } - - @Test - public void test5() { - Solution solution = new Solution(); - Assert.assertEquals(false, solution.isNumber(" 1e")); - } - - @Test - public void test6() { - Solution solution = new Solution(); - Assert.assertEquals(false, solution.isNumber("e3")); - } - - - @Test - public void test7() { - Solution solution = new Solution(); - Assert.assertEquals(true, solution.isNumber(" 6e-1")); - } - - @Test - public void test8() { - Solution solution = new Solution(); - Assert.assertEquals(false, solution.isNumber(" 99e2.5 ")); - } - - - @Test - public void test9() { - Solution solution = new Solution(); - Assert.assertEquals(true, solution.isNumber("53.5e93")); - } - - @Test - public void test10() { - Solution solution = new Solution(); - Assert.assertEquals(false, solution.isNumber(" --6 ")); - } - - @Test - public void test11() { - Solution solution = new Solution(); - Assert.assertEquals(false, solution.isNumber("-+3")); - } - - @Test - public void test12() { - Solution solution = new Solution(); - Assert.assertEquals(false, solution.isNumber("95a54e53")); - } - -} diff --git a/[065][Valid Number]/src/Solution.java b/[065][Valid Number]/src/Solution.java deleted file mode 100644 index 3f6d642..0000000 --- a/[065][Valid Number]/src/Solution.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-17 13:20 - **/ -public class Solution { - - /** - * 序数就分别为0, 1, 2, 3, 4, 5, 6 - */ - private enum InputType { - INVALID, - SPACE, - SIGN, - DIGIT, - DOT, - EXPONENT - } - - // 状态转表 TODO 每个状态是什么意思? - private final static int[][] TRANSITION_TABLE = { - {-1, 0, 3, 1, 2, -1}, // next states for state 0 - {-1, 8, -1, 1, 4, 5}, // next states for state 1 - {-1, -1, -1, 4, -1, -1},// next states for state 2 - {-1, -1, -1, 1, 2, -1,},// next states for state 3 - {-1, 8, -1, 4, -1, 5},// next states for state 4 - {-1, -1, 6, 7, -1, -1},// next states for state 5 - {-1, -1, -1, 7, -1, -1},// next states for state 6 - {-1, 8, -1, 7, -1, -1},// next states for state 7 - {-1, 8, -1, -1, -1, -1},// next states for state 8 - }; - - /** - *
-     * Validate if a given string can be interpreted as a decimal number.
-     *
-     * Some examples:
-     * "0" => true
-     * " 0.1 " => true
-     * "abc" => false
-     * "1 a" => false
-     * "2e10" => true
-     * " -90e3   " => true
-     * " 1e" => false
-     * "e3" => false
-     * " 6e-1" => true
-     * " 99e2.5 " => false
-     * "53.5e93" => true
-     * " --6 " => false
-     * "-+3" => false
-     * "95a54e53" => false
-     *
-     * Note: It is intended for the problem statement to be ambiguous. You should gather all requirements
-     * up front before implementing one. However, here is a list of characters that can be in a valid decimal number:
-     *
-     * Numbers 0-9
-     * Exponent - "e"
-     * Positive/negative sign - "+"/"-"
-     * Decimal point - "."
-     * Of course, the context of these characters also matters in the input.
-     * 
- * - * @param s - * @return - */ - public boolean isNumber(String s) { - int state = 0; - for (int i = 0; i < s.length(); i++) { - InputType inputType = InputType.INVALID; - if (Character.isSpaceChar(s.charAt(i))) { - inputType = InputType.SPACE; - } else if (s.charAt(i) == '+' || s.charAt(i) == '-') { - inputType = InputType.SIGN; - } else if (Character.isDigit(s.charAt(i))) { - inputType = InputType.DIGIT; - } else if (s.charAt(i) == '.') { - inputType = InputType.DOT; - } else if (s.charAt(i) == 'e' || s.charAt(i) == 'E') { - inputType = InputType.EXPONENT; - } - // Get next state from current state and input symbol - state = TRANSITION_TABLE[state][inputType.ordinal()]; - - // Invalid input - if (state == -1) { - return false; - } - } - // If the current state belongs to one of the accepting (final) states, - // then the number is valid - return state == 1 || state == 4 || state == 7 || state == 8; - } - - private boolean isDigit(char charAt) { - return charAt >= '0' && charAt <= '9'; - } - - private boolean isSpace(char charAt) { - return charAt == ' '; - } -} diff --git a/[066][Plus One]/src/Solution.java b/[066][Plus One]/src/Solution.java deleted file mode 100644 index efc7195..0000000 --- a/[066][Plus One]/src/Solution.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 19:32 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Given a non-negative number represented as an array of digits, plus one to the number.
-     * The digits are stored such that the most significant digit is at the head of the list.
-     *
-     * Ŀ
-     * һʾһмһ
-     * ÿһλ洢һλϡ±ӴСʾλӵλλ
-     *
-     * ˼·
-     * ֱ⣬һλ־carryֵΪ1ʾ1λʼtmp = a[x] + carry
-     * a[x] = tmp%10carry = tmp/10carryΪ0һλٽвֱеλcarray
-     * Ϊ0˳carrayΪ0˵Ҫչһλ
-     * 
- * - * @param digits - * @return - */ - public int[] plusOne(int[] digits) { - - // λ־һλĽλ־ - int carry = 1; - int tmp; - for (int i = digits.length - 1; i >= 0; i--) { - tmp = digits[i]; - // 㵱ǰλֵ - digits[i] = (tmp + carry) % 10; - // µĽλ - carry = (tmp + carry) / 10; - - // ûнλ˾Ϳ˳ - if (carry == 0) { - break; - } - } - - // һλ - if (carry == 1) { - int[] result = new int[digits.length + 1]; - System.arraycopy(digits, 0, result, 1, digits.length); - result[0] = carry; - return result; - } else { - return digits; - } - } -} diff --git a/[067][Add Binary]/src/Solution.java b/[067][Add Binary]/src/Solution.java deleted file mode 100644 index a79aab6..0000000 --- a/[067][Add Binary]/src/Solution.java +++ /dev/null @@ -1,105 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 19:34 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Given two binary strings, return their sum (also a binary string).
-     * For example,
-     * a = "11"
-     * b = "1"
-     * Return "100"
-     *
-     * Ŀ
-     * ƵַǵĺͣҲǶַ
-     *
-     * ˼·
-     * ȽӦַתɶӦ飬ӵλλӣͬʱҪǵ
-     * ӻҪչһλʵ֡
-     * 
- * - * @param a - * @param b - * @return - */ - public String addBinary(String a, String b) { - - int[] ca = new int[a.length()]; - int[] cb = new int[b.length()]; - - // ַеֵתֵ01 - for (int i = 0; i < a.length(); i++) { - ca[i] = a.charAt(i) - '0'; - } - - // ַеֵתֵ01 - for (int i = 0; i < b.length(); i++) { - cb[i] = b.charAt(i) - '0'; - } - - // ʹcaijȳ - if (ca.length < cb.length) { - int[] tmp = ca; - ca = cb; - cb = tmp; - } - - - int ai = ca.length - 1; // ַcaһ± - int bi = cb.length - 1; // ַcbһ± - int carry = 0; // λĽλʶ - int result; // صĽ - - // 磺1010101101 + 10100 - while (ai >= 0 && bi >= 0) { - result = ca[ai] + cb[bi] + carry; - ca[ai] = result % 2; - carry = result / 2; - - ai--; - bi--; - } - - // µ - while (ai >= 0) { - result = ca[ai] + carry; - ca[ai] = result % 2; - carry = result / 2; - - if (carry == 0) { - break; - } - - ai--; - } - - // ַеֵתַ01 - for (int i = 0; i < ca.length; i++) { - ca[i] += '0'; - } - - // Ҫչһλ - if (carry == 0) { - - char[] ch = new char[ca.length]; - for (int i = 0; i < ca.length; i++) { - ch[i] = (char) (ca[i]); - } - - return new String(ch); - } - // Ҫչһλ - else { - char[] ch = new char[ca.length + 1]; - ch[0] = '1'; - for (int i = 0; i < ca.length; i++) { - ch[i + 1] = (char) (ca[i]); - } - return new String(ch); - } - } -} diff --git a/[070][Climbing Stairs]/src/Solution.java b/[070][Climbing Stairs]/src/Solution.java deleted file mode 100644 index 570efe8..0000000 --- a/[070][Climbing Stairs]/src/Solution.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Author: - * Date: 2015-07-25 - * Time: 09:10 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * f(n) ʾn ¥ݵIJͬΪn ¥ݣѡ
-     * - ӵn - 1 ǰ1 
-     * - ӵn - 1 ǰ2 
-     * ˣf(n) = f(n - 1) + f(n - 2)
-     * 
- * @param n - * @return - */ - public int climbStairs(int n) { - - int result = 0; - - // ֻһ - if (n == 1) { - result = 1; - } - // ֻ - else if (n == 2) { - result = 2; - } - // ¥ݽ2 - else if (n > 2) { - // еĽⷨ - int[] ways = new int[n]; - - ways[0] = 1; - ways[1] = 2; - - for (int i = 2; i < ways.length; i++) { - ways[i] = ways[i - 1] + ways[i - 2]; - } - - result = ways[ways.length - 1]; - } - - return result; - } -} diff --git a/[071][Simplify Path]/src/Solution.java b/[071][Simplify Path]/src/Solution.java deleted file mode 100644 index c17fc59..0000000 --- a/[071][Simplify Path]/src/Solution.java +++ /dev/null @@ -1,32 +0,0 @@ -import java.util.LinkedList; -import java.util.List; - -/** - * @author: wangjunchao(王俊超) - * @time: 2018-09-28 15:50 - **/ -public class Solution { - public String simplifyPath(String path) { - String[] ss = path.split("/"); - List result = new LinkedList<>(); - - for (String part : ss) { - if (".".equals(part)) { - continue; - } else if ("..".equals(part)) { - if (result.size() > 0) { - result.remove(result.size() - 1); - } - } else if (!"".equals(part.trim())) { - result.add(part); - } - } - - StringBuilder builder = new StringBuilder(); - for (String part : result) { - builder.append("/").append(part); - } - - return builder.length() == 0 ? "/" : builder.toString(); - } -} diff --git a/[073][Set Matrix Zeroes]/src/Solution.java b/[073][Set Matrix Zeroes]/src/Solution.java deleted file mode 100644 index 1d25618..0000000 --- a/[073][Set Matrix Zeroes]/src/Solution.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Author: - * Date: 2015-07-25 - * Time: 09:27 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - public void setZeroes(int[][] matrix) { - // һбõı־ - boolean rowFlag = false; - // һбõı־ - boolean colFlag = false; - - for (int i = 0; i < matrix.length; i++) { - for (int j = 0; j < matrix[0].length; j++) { - if (matrix[i][j] == 0) { - // ǵһҪ - if (i == 0) { - rowFlag = true; - } - - // ǵһҪ - if (j == 0){ - colFlag = true; - } - - // ڱҪΪ0к - matrix[0][j] = 0; - matrix[i][0] = 0; - } - } - } - - // ԵڶеڶпʼԪ0 - for (int i = 1; i < matrix.length; i++) { - for (int j = 1; j < matrix[0].length; j++) { - if (matrix[i][0] == 0 || matrix[0][j] == 0) { - matrix[i][j] = 0; - } - } - } - - // õһΪ0 - if (rowFlag) { - for (int j = 0; j < matrix[0].length; j++) { - matrix[0][j] = 0; - } - } - - // õһΪ0 - if (colFlag) { - for (int i = 0; i < matrix.length; i++) { - matrix[i][0] = 0; - } - } - - } -} diff --git a/[074][Search A 2D Matrix]/src/Main.java b/[074][Search A 2D Matrix]/src/Main.java deleted file mode 100644 index 4206b6b..0000000 --- a/[074][Search A 2D Matrix]/src/Main.java +++ /dev/null @@ -1,16 +0,0 @@ -import org.junit.Assert; -import org.junit.Test; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-19 16:11 - **/ -public class Main { - @Test - public void test1() { - Solution solution = new Solution(); - - int[][] matrix = {{1, 3}}; - Assert.assertEquals(true, solution.searchMatrix(matrix, 3)); - } -} diff --git a/[074][Search A 2D Matrix]/src/Solution.java b/[074][Search A 2D Matrix]/src/Solution.java deleted file mode 100644 index 4942ee4..0000000 --- a/[074][Search A 2D Matrix]/src/Solution.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 19:36 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:
-     * Integers in each row are sorted from left to right.
-     * The first integer of each row is greater than the last integer of the previous row.
-     * For example,
-     * Consider the following matrix:Given target = 3, return true.
-     *
-     * [
-     *  [1,   3,  5,  7],
-     *  [10, 11, 16, 20],
-     *  [23, 30, 34, 50]
-     * ]
-     *
-     * Ŀ
-     * һάʵһ㷨ھʵֿkھk
-     * ʣÿһÿһжźģÿһеĵһһеһ
-     *
-     * ˼·
-     * ⷨһö鿴㷨ҵڵУö㷨ڵСҵͷtrue򷵻false
-     * 
- * - * @param matrix - * @param target - * @return - */ - public boolean searchMatrix(int[][] matrix, int target) { - - if (matrix == null || matrix.length == 0 || matrix[0].length == 0) { - return false; - } - - int row = matrix.length; - int column = matrix[0].length; - int low = 0; - int high = row * column - 1; - int mid; - - // ҽڵ - while (low <= high) { - mid = low + (high - low) / 2; - int value = matrix[mid / column][mid % column]; - if (value == target) { - return true; - } else if (value < target) { - low = mid + 1; - } else { - high = mid - 1; - } - } - - return false; - } -} diff --git a/[074][Search A 2D Matrix]/src/Solution2.java b/[074][Search A 2D Matrix]/src/Solution2.java deleted file mode 100644 index 0a5ed46..0000000 --- a/[074][Search A 2D Matrix]/src/Solution2.java +++ /dev/null @@ -1,88 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 19:36 - * Declaration: All Rights Reserved !!! - */ -public class Solution2 { - /** - *
-     * ԭ
-     * Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:
-     * Integers in each row are sorted from left to right.
-     * The first integer of each row is greater than the last integer of the previous row.
-     * For example,
-     * Consider the following matrix:Given target = 3, return true.
-     *
-     * [
-     *  [1,   3,  5,  7],
-     *  [10, 11, 16, 20],
-     *  [23, 30, 34, 50]
-     * ]
-     *
-     * Ŀ
-     * һάʵһ㷨ھʵֿkھk
-     * ʣÿһÿһжźģÿһеĵһһеһ
-     *
-     * ˼·
-     * ⷨһö鿴㷨ҵڵУö㷨ڵСҵͷtrue򷵻false
-     * 
- * - * @param matrix - * @param target - * @return - */ - public boolean searchMatrix(int[][] matrix, int target) { - - if (matrix == null || matrix.length == 0 || matrix[0].length == 0) { - return false; - } - - int row = matrix.length; - int column = matrix[0].length; - int low = 0; - int high = row - 1; - int mid = 0; - - // ҽڵ - while (low <= high) { - mid = low + (high - low) / 2; - - if (target < matrix[mid][column - 1]) { - high = mid - 1; - } else if (target > matrix[mid][column - 1]) { - low = mid + 1; - } else { - return true; - } - } - - // ڵλ - int targetRow = mid; - if (matrix[mid][column - 1] < target) { - targetRow++; - } - - // Ŀг޽ - if (targetRow >= row) { - return false; - } - - low = 0; - high = column - 1; - // ڵУҵtrueûзfalse - while (low <= high) { - mid = low + (high - low) / 2; - - if (target < matrix[targetRow][mid]) { - high = mid - 1; - } else if (target > matrix[targetRow][mid]) { - low = mid + 1; - } else { - return true; - } - } - - return false; - } -} diff --git a/[075][Sort Colors]/src/Main.java b/[075][Sort Colors]/src/Main.java deleted file mode 100644 index a29defe..0000000 --- a/[075][Sort Colors]/src/Main.java +++ /dev/null @@ -1,33 +0,0 @@ -import org.junit.Test; - -import java.util.Arrays; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-19 14:52 - **/ -public class Main { - @Test - public void test1() { - Solution solution = new Solution(); - int[] colors = {2, 0, 2, 1, 1, 0}; - solution.sortColors(colors); - System.out.println(Arrays.toString(colors)); - } - - @Test - public void test2() { - Solution solution = new Solution(); - int[] colors = {2, 0, 1}; - solution.sortColors(colors); - System.out.println(Arrays.toString(colors)); - } - - @Test - public void test3() { - Solution solution = new Solution(); - int[] colors = {0}; - solution.sortColors(colors); - System.out.println(Arrays.toString(colors)); - } -} diff --git a/[075][Sort Colors]/src/Solution.java b/[075][Sort Colors]/src/Solution.java deleted file mode 100644 index 2f930cc..0000000 --- a/[075][Sort Colors]/src/Solution.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 19:37 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Given an array with n objects colored red, white or blue, sort them so that objects
-     * of the same color are adjacent, with the colors in the order red, white and blue.
-     * Here, we will use the integers 0, 1, and 2 to represent the color red, white,
-     * and blue respectively.
-     * Note:
-     * You are not suppose to use the librarys sort function for this problem.
-     *
-     * Ŀ
-     * һ飬Ǻɫɫɫɫ򣬺죬ף
-     * ʹ012ֱ죬ף
-     * ע⣺ʹÿ⺯
-     *
-     * ˼·
-     * һֱ012ֵĴٽ鸳ֵ
-     * 
- * - * @param nums - */ - public void sortColors(int[] nums) { - - if (nums == null) { - return; - } - - int[] count = new int[3]; - - for (int n : nums) { - count[n]++; - } - - int start = 0; - int end = 0; - for (int i = 0; i < count.length; i++) { - if (i == 0) { - start = 0; - } else { - start += count[i - 1]; - } - end += count[i]; - for (int j = start; j < end; j++) { - nums[j] = i; - } - } - - // ϶ĸĽ -// for (int i = 0; i < count[0]; i++) { -// nums[i] = 0; -// } -// -// for (int i = count[0]; i < count[0] + count[1]; i++) { -// nums[i] = 1; -// } -// -// for (int i = count[0] + count[1]; i < nums.length; i++) { -// nums[i] = 2; -// } - } -} diff --git a/[075][Sort Colors]/src/Solution2.java b/[075][Sort Colors]/src/Solution2.java deleted file mode 100644 index ac7b270..0000000 --- a/[075][Sort Colors]/src/Solution2.java +++ /dev/null @@ -1,71 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 19:37 - * Declaration: All Rights Reserved !!! - */ -public class Solution2 { - /** - *
-     * ԭ
-     * Given an array with n objects colored red, white or blue, sort them so that objects
-     * of the same color are adjacent, with the colors in the order red, white and blue.
-     * Here, we will use the integers 0, 1, and 2 to represent the color red, white,
-     * and blue respectively.
-     * Note:
-     * You are not suppose to use the librarys sort function for this problem.
-     *
-     * Ŀ
-     * һ飬Ǻɫɫɫɫ򣬺죬ף
-     * ʹ012ֱ죬ף
-     * ע⣺ʹÿ⺯
-     *
-     * ˼·
-     * ɨ裬¼1ĸĺ͡ɨԵó1Ŀt2Ŀ(sum-t)/2
-     * Եó0ĿӸ012Ŀٶֵ
-     * 
- * - * @param A - */ - public void sortColors(int[] A) { - - if (A == null) { - return; - } - - // ͳ1ĸ - int count = 0; - - // ͳĺ - int sum = 0; - - for (int i : A) { - if (i == 1) { - count++; - } - - sum += i; - } - - // 2Ŀ - sum = (sum - count) / 2; - - // 1ʼֵλ - count = A.length - count - sum; - - // 2ʼֵλ - sum = A.length - sum; - - for (int i = 0; i < count; i++) { - A[i] = 0; - } - - for (int i = count; i < sum; i++) { - A[i] = 1; - } - - for (int i = sum; i < A.length; i++) { - A[i] = 2; - } - } -} diff --git a/[077][Combinations]/src/Main.java b/[077][Combinations]/src/Main.java deleted file mode 100644 index e4021a1..0000000 --- a/[077][Combinations]/src/Main.java +++ /dev/null @@ -1,15 +0,0 @@ -import org.junit.Test; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-19 19:04 - **/ -public class Main { - @Test - public void test1() { - Solution solution = new Solution(); - - System.out.println(solution.combine(4, 2)); - } - -} diff --git a/[077][Combinations]/src/Solution.java b/[077][Combinations]/src/Solution.java deleted file mode 100644 index 7d055e8..0000000 --- a/[077][Combinations]/src/Solution.java +++ /dev/null @@ -1,62 +0,0 @@ -import java.util.LinkedList; -import java.util.List; - -/** - * Author: - * Date: 2015-08-21 - * Time: 19:39 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - - /** - *
-     * ԭ
-     * Given two integers n and k, return all possible combinations of k numbers out of 1  n.
-     * For example,
-     * If n = 4 and k = 2, a solution is:
-     *
-     * [
-     *  [2,4],
-     *  [3,4],
-     *  [2,3],
-     *  [1,2],
-     *  [1,3],
-     *  [1,4],
-     * ]
-     *
-     * Ŀ
-     * nk1-nkϡ
-     *
-     * ˼·
-     * ʹùŻ㷨
-     * 
- * - * @param n - * @param k - * @return - */ - public List> combine(int n, int k) { - List> result = new LinkedList<>(); - List current = new LinkedList<>(); - - dfs(1, n, k, current, result); - - return result; - } - - private void dfs(int start, int end, int k, List current, List> result) { - if (k == current.size()) { - result.add(new LinkedList<>(current)); - return; - } - - for (int i = start; i <= end; i++) { - current.add(i); - dfs(i + 1, end, k, current, result); - current.remove((Integer) i); - } - } - - -} diff --git a/[077][Combinations]/src/Solution2.java b/[077][Combinations]/src/Solution2.java deleted file mode 100644 index 8e1fb2f..0000000 --- a/[077][Combinations]/src/Solution2.java +++ /dev/null @@ -1,80 +0,0 @@ -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - -/** - * Author: - * Date: 2015-08-21 - * Time: 19:39 - * Declaration: All Rights Reserved !!! - */ -public class Solution2 { - private List> result; - private List l; - - /** - *
-     * ԭ
-     * Given two integers n and k, return all possible combinations of k numbers out of 1  n.
-     * For example,
-     * If n = 4 and k = 2, a solution is:
-     *
-     * [
-     *  [2,4],
-     *  [3,4],
-     *  [2,3],
-     *  [1,2],
-     *  [1,3],
-     *  [1,4],
-     * ]
-     *
-     * Ŀ
-     * nk1-nkϡ
-     *
-     * ˼·
-     * õݹη⣬롣
-     * 
- * - * @param n - * @param k - * @return - */ - public List> combine(int n, int k) { - result = new LinkedList<>(); - - if (n > 0 && k > 0 && n >= k) { - l = new LinkedList<>(); - combine(1, n, k); - } - - return result; - } - - /** - * - * - * @param start ѡʼλ - * @param end ѡĽλ - * @param num [start, end]ѡĿ - */ - private void combine(int start, int end, int num) { - - if (num == 0) { - List tmp = new ArrayList<>(); - for (Integer i : l) { - tmp.add(i); - } - - result.add(tmp); - return; - } - - // һѡֵ - int endFirst = end - num + 1; - for (int i = start; i <= endFirst; i++) { - l.add(i); - combine(i + 1, end, num - 1); - l.remove(new Integer(i)); - } - } -} diff --git a/[078][Subsets]/src/Main.java b/[078][Subsets]/src/Main.java deleted file mode 100644 index 9295524..0000000 --- a/[078][Subsets]/src/Main.java +++ /dev/null @@ -1,16 +0,0 @@ -import org.junit.Test; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-19 16:27 - **/ -public class Main { - @Test - public void test1() { - int[] nums = {1, 2, 3}; - - Solution solution = new Solution(); - - System.out.println(solution.subsets(nums)); - } -} diff --git a/[078][Subsets]/src/Solution.java b/[078][Subsets]/src/Solution.java deleted file mode 100644 index 9db75ec..0000000 --- a/[078][Subsets]/src/Solution.java +++ /dev/null @@ -1,71 +0,0 @@ -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; - -/** - * Author: - * Date: 2015-08-21 - * Time: 19:41 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - - /** - *
-     * ԭ
-     * Given a set of distinct integers, nums, return all possible subsets.
-     * Note:
-     * Elements in a subset must be in non-descending order.
-     * The solution set must not contain duplicate subsets.
-     * For example,
-     * If nums = [1,2,3], a solution is:
-     *
-     * [
-     *  [3],
-     *  [1],
-     *  [2],
-     *  [1,2,3],
-     *  [1,3],
-     *  [2,3],
-     *  [1,2],
-     *  []
-     * ]
-     *
-     * Ŀ
-     * һֵͬ飬Ӽ
-     *
-     * ˼·
-     * ȶеԪؽȻʹùŻ
-     * 
- * - * @param nums - * @return - */ - public List> subsets(int[] nums) { - List> result = new LinkedList<>(); - List curr = new LinkedList<>(); - if (nums != null) { - // S - Arrays.sort(nums); - dfs(nums, 0, result, curr); - } - - return result; - } - - private void dfs(int[] nums, int index, List> result, List curr) { - - - // ӵУ˵һµĽ - result.add(new LinkedList<>(curr)); - - - for (int j = index; j < nums.length; j++) { - // Ԫ - curr.add(nums[j]); - dfs(nums, j + 1, result, curr); - // ԭ - curr.remove((Integer) nums[j]); - } - } -} diff --git a/[078][Subsets]/src/Solution2.java b/[078][Subsets]/src/Solution2.java deleted file mode 100644 index ce86399..0000000 --- a/[078][Subsets]/src/Solution2.java +++ /dev/null @@ -1,123 +0,0 @@ -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - -/** - * Author: - * Date: 2015-08-21 - * Time: 19:41 - * Declaration: All Rights Reserved !!! - */ -public class Solution2 { - private List> result; - private List l; - private int[] set; - private int num; // setлҪѡԪظ - - /** - *
-     * ԭ
-     * Given a set of distinct integers, nums, return all possible subsets.
-     * Note:
-     * Elements in a subset must be in non-descending order.
-     * The solution set must not contain duplicate subsets.
-     * For example,
-     * If nums = [1,2,3], a solution is:
-     *
-     * [
-     *  [3],
-     *  [1],
-     *  [2],
-     *  [1,2,3],
-     *  [1,3],
-     *  [2,3],
-     *  [1,2],
-     *  []
-     * ]
-     *
-     * Ŀ
-     * һֵͬ飬Ӽ
-     *
-     * ˼·
-     * ȶеԪؽȻõݹη⡣
-     * 
- * - * @param S - * @return - */ - public List> subsets(int[] S) { - result = new LinkedList<>(); - - if (S != null) { - l = new ArrayList<>(); - - // S - quickSort(S, 0, S.length - 1); - - set = S; - for (int i = 0; i <= S.length; i++) { - num = i; - subset(0); - } - } - - // գӿ - set = null; - l = null; - - return result; - } - - /** - * ԪظnumӼ - * - * @param start ʣҪѡnumԪУһС± - */ - public void subset(int start) { - if (num == 0) { - List tmp = new ArrayList<>(); - for (Integer i : l) { - tmp.add(i); - } - - result.add(tmp); - return; - } - - int endFirst = set.length - num; // ʣҪѡnumԪУһ± - for (int i = start; i <= endFirst; i++) { - l.add(set[i]); - num--; - subset(i + 1); - num++; - l.remove(new Integer(set[i])); - } - } - - private void quickSort(int[] arr, int lo, int hi) { - if (lo < hi) { - int mid = getMid(arr, lo, hi); - quickSort(arr, lo, mid - 1); - quickSort(arr, mid + 1, hi); - } - } - - private int getMid(int[] arr, int lo, int hi) { - int tmp = arr[lo]; - while (lo < hi) { - while (lo < hi && arr[hi] > tmp) { - hi--; - } - arr[lo] = arr[hi]; - - while (lo < hi && arr[lo] < tmp) { - lo++; - } - - arr[hi] = arr[lo]; - } - - arr[lo] = tmp; - return lo; - } -} diff --git a/[078][Subsets]/src/Solution3.java b/[078][Subsets]/src/Solution3.java deleted file mode 100644 index 4ad1f20..0000000 --- a/[078][Subsets]/src/Solution3.java +++ /dev/null @@ -1,86 +0,0 @@ -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; - -/** - * Author: - * Date: 2015-08-21 - * Time: 19:41 - * Declaration: All Rights Reserved !!! - */ -public class Solution3 { - - /** - *
-     * ԭ
-     * Given a set of distinct integers, nums, return all possible subsets.
-     * Note:
-     * Elements in a subset must be in non-descending order.
-     * The solution set must not contain duplicate subsets.
-     * For example,
-     * If nums = [1,2,3], a solution is:
-     *
-     * [
-     *  [3],
-     *  [1],
-     *  [2],
-     *  [1,2,3],
-     *  [1,3],
-     *  [2,3],
-     *  [1,2],
-     *  []
-     * ]
-     *
-     * Ŀ
-     * һֵͬ飬Ӽ
-     *
-     * ˼·
-     * ȶеԪؽȻõݹη⡣
-     * 
- * - * @param nums - * @return - */ - public List> subsets(int[] nums) { - List> result = new LinkedList<>(); - List curr = new LinkedList<>(); - if (nums != null) { - - // S - Arrays.sort(nums); - // iʾӼԪظ - for (int i = 0; i <= nums.length; i++) { - subset(nums, 0, i, result, curr); - } - } - - return result; - } - - /** - * ԪnӼ - * - * @param nums Ԫؼ - * @param idx ȡԪصʼλ - * @param n Ԫظ - * @param result - * @param curr ʱ - */ - private void subset(int[] nums, int idx, int n, List> result, List curr) { - - // Ѿĩβˣ˵һ - if (n == 0) { - result.add(new LinkedList<>(curr)); - return; - } - - // ûд꣬ݹ鴦һԪ - for (int i = idx; i < nums.length - n + 1; i++) { - curr.add(nums[i]); - subset(nums, i + 1, n - 1, result, curr); - curr.remove((Integer) nums[i]); - } - } - - -} diff --git a/[079][Word Search]/src/Main.java b/[079][Word Search]/src/Main.java deleted file mode 100644 index 2491d90..0000000 --- a/[079][Word Search]/src/Main.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Author: - * Date: 2015-06-20 - * Time: 08:02 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { - Solution solution = new Solution(); - System.out.println(solution.exist(new char[][]{ - "abc".toCharArray(),"aed".toCharArray(),"afg".toCharArray() - }, "abcdefg")); - } -} diff --git a/[079][Word Search]/src/Solution.java b/[079][Word Search]/src/Solution.java deleted file mode 100644 index e510517..0000000 --- a/[079][Word Search]/src/Solution.java +++ /dev/null @@ -1,113 +0,0 @@ -/** - * Author: - * Date: 2015-06-20 - * Time: 07:19 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Given a 2D board and a word, find if the word exists in the grid.
-     *
-     * The word can be constructed from letters of sequentially adjacent cell,
-     * where "adjacent" cells are those horizontally or vertically neighboring.
-     * The same letter cell may not be used more than once.
-     *
-     * For example,
-     * Given board =
-     * [
-     *      ["ABCE"],
-     *      ["SFCS"],
-     *      ["ADEE"]
-     * ]
-     * word = "ABCCED", -> returns true,
-     * word = "SEE", -> returns true,
-     * word = "ABCB", -> returns false.
-     *
-     * Ŀ⣺
-     * һboardַ󣬿Դһ㿪ʼҵķʽߣÿֻһΣ
-     * һ·߹ַڸַôtrue
-     *
-     * ˼·
-     * ÿһΪ㣬ʹûݷ
-     * 
- * - * @param board - * @param word - * @return - */ - public boolean exist(char[][] board, String word) { - // עǼٶIJǺϷ - - // ʱǾ󣬳ʼֵĬϻΪfalse - boolean[][] visited = new boolean[board.length][board[0].length]; - - // ÿһλΪҵһ·ֹͣ - for (int i = 0; i < board.length; i++) { - for (int j = 0; j < board[0].length; j++) { - if (search(board, visited, i, j, word, new int[]{0})) { - return true; - } - } - } - - return false; - } - - /** - * @param board ַ - * @param visited ʱǾ - * @param row ʵк - * @param col ʵк - * @param word ƥַ - * @param idx ƥλãȡǸºֵԱ - * @return - */ - private boolean search(char[][] board, boolean[][] visited, int row, int col, String word, int[] idx) { - // λõִijȣ˵Ѿҵҵƥ - if (idx[0] == word.length()) { - return true; - } - - boolean hasPath = false; - // ǰλúϷ - if (check(board, visited, row, col, word, idx[0])) { - // λñʹ - visited[row][col] = true; - idx[0]++; - // ϣң£ĸ - hasPath = search(board, visited, row - 1, col, word, idx ) // - || search(board, visited, row, col + 1, word, idx) // - || search(board, visited, row + 1, col, word, idx) // - || search(board, visited, row, col - 1, word, idx); // - - - // ûҵ·ͻ - if (!hasPath) { - visited[row][col] = false; - idx[0]--; - } - } - - return hasPath; - } - - /** - * жʵλǷϷ - * - * @param board ַ - * @param visited ʱǾ - * @param row ʵк - * @param col ʵк - * @param word ƥַ - * @param idx ƥλ - * @return - */ - - public boolean check(char[][] board, boolean[][] visited, int row, int col, String word, int idx) { - return row >= 0 && row < board.length // кźϷ - && col >= 0 && col < board[0].length // кźϷ - && !visited[row][col] // ûбʹ - && board[row][col] == word.charAt(idx); // ַ - } -} diff --git a/[080][Remove Duplicates from Sorted Array II]/src/Main.java b/[080][Remove Duplicates from Sorted Array II]/src/Main.java deleted file mode 100644 index 83f9e74..0000000 --- a/[080][Remove Duplicates from Sorted Array II]/src/Main.java +++ /dev/null @@ -1,15 +0,0 @@ -import java.util.Arrays; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-12 22:29 - **/ -public class Main { - public static void main(String[] args) { - Solution solution = new Solution(); - int[] nums = {1, 1, 1, 2, 2, 3}; - int i = solution.removeDuplicates(nums); - System.out.println(i + ": "+ Arrays.toString(nums)); - - } -} diff --git a/[080][Remove Duplicates from Sorted Array II]/src/Solution.java b/[080][Remove Duplicates from Sorted Array II]/src/Solution.java deleted file mode 100644 index 9109816..0000000 --- a/[080][Remove Duplicates from Sorted Array II]/src/Solution.java +++ /dev/null @@ -1,24 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-12 22:29 - **/ -public class Solution { - public int removeDuplicates(int[] nums) { - if (nums == null) { - return 0; - } - if (nums.length < 3) { - return nums.length; - } - - int index = 2; - for (int i = 2; i < nums.length; i++) { - if (nums[index - 2] < nums[i] ) { - nums[index] = nums[i]; - index++; - } - } - - return index; - } -} diff --git a/[080][Remove Duplicates from Sorted Array II]/src/Solution2.java b/[080][Remove Duplicates from Sorted Array II]/src/Solution2.java deleted file mode 100644 index c3e4f83..0000000 --- a/[080][Remove Duplicates from Sorted Array II]/src/Solution2.java +++ /dev/null @@ -1,24 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-12 22:53 - **/ -/** - * 删除重复出现的数字,使之最多出现两次 - */ -public class Solution2 { - public int removeDuplicates(int[] nums) { - int i = 0; - - // 处理每一个数字 - for (int n : nums) { - // i < 2 处理前两个数字 - // n > nums[i - 2]说明n不与nums[i - 2]重复,并且因为数组有序,那么必然n > nums[i - 2] - if (i < 2 || n > nums[i - 2]) { - nums[i++] = n; - } - } - - return i; - } -} - diff --git a/[081][Search In Rotated Sorted Array II]/src/Main.java b/[081][Search In Rotated Sorted Array II]/src/Main.java deleted file mode 100644 index be94e08..0000000 --- a/[081][Search In Rotated Sorted Array II]/src/Main.java +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Author: 王俊超 - * Date: 2015-06-21 - * Time: 16:38 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { - Solution2 solution = new Solution2(); - System.out.println(solution.search(new int[]{1, 1, 3, 1}, 3)); - System.out.println(solution.search(new int[]{5, 1, 3}, 3)); - } -} diff --git a/[081][Search In Rotated Sorted Array II]/src/Solution.java b/[081][Search In Rotated Sorted Array II]/src/Solution.java deleted file mode 100644 index 3a86418..0000000 --- a/[081][Search In Rotated Sorted Array II]/src/Solution.java +++ /dev/null @@ -1,136 +0,0 @@ -/** - * Author: - * Date: 2015-06-21 - * Time: 14:46 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Follow up for "Search in Rotated Sorted Array":
-     * What if duplicates are allowed?
-     * Would this affect the run-time complexity? How and why?
-     * Write a function to determine if a given target is in the array
-     *
-     * Ŀ⣺
-     * "תֵ"ĺеֵظ
-     * дһȷһֵǷ
-     * 
- * @param nums - * @param target - * @return - */ - public boolean search(int[] nums, int target) { - if (nums != null && nums.length > 0) { - // СԪضӦ± - int minIndex = findMinIndex(nums); - - // ȫ - if (minIndex == 0) { - return binarySearch(nums, 0, nums.length - 1, target); - } - // ֲ, 4 5 6 7 8 9 0 1 2 3 - else { - // úͺһһԪȣضӦ± - if (nums[nums.length - 1] == target) { - return true; - } - // targetںһ - else if (nums[nums.length - 1] > target) { - return binarySearch(nums, minIndex, nums.length - 1, target); - } - // targetǰһ - else { - return binarySearch(nums, 0, minIndex - 1, target); - } - } - } - - return false; - } - - /** - * - * - * @param nums - * @param start ʼλ - * @param end λ - * @param target Ŀ - * @return trueҵfalseûҵ - */ - public boolean binarySearch(int[] nums, int start, int end, int target) { - - int mid; - while (start <= end) { - mid = start + ((end - start) >> 1); - - if (nums[mid] == target) { - return true; - } else if (nums[mid] > target) { - end = mid - 1; - } else { - start = mid + 1; - } - } - - return false; - } - - - public int findMinIndex(int[] nums) { - // У - if (nums == null || nums.length < 1) { - throw new IllegalArgumentException(); - } - - int lo = 0; - int hi = nums.length - 1; - int mid = 0; - - // ųȫ - while (nums[lo] >= nums[hi]) { - // ֻԪأغһ - if (hi - lo == 1) { - mid = hi; - break; - } - - mid = lo + ((hi - lo) >> 1); - - if (nums[mid] == nums[lo] && nums[mid] == nums[hi]) { - // ֻܲ˳ܲlo++hi--ķʽ - // Ϊloǰһһ - // hiҲǺһĵһ - return sequenceSearchMinIndex(nums, lo, hi); - } - - // midǰһ - if (nums[mid] >= nums[lo]) { - lo = mid; - } - // midںһ - else if (nums[mid] <= nums[hi]) { - hi = mid; - } - } - - return mid; - } - - /** - * ˳еСֵ±꣬nums鰴ijת - * - * @param nums - * @param start ʼλ - * @param end λ - * @return Сֵ± - */ - public int sequenceSearchMinIndex(int[] nums, int start, int end) { - for (int i = start; i < end; i++) { - if (nums[i] > nums[i + 1]) { - return i + 1; - } - } - return start; - } -} diff --git a/[081][Search In Rotated Sorted Array II]/src/Solution2.java b/[081][Search In Rotated Sorted Array II]/src/Solution2.java deleted file mode 100644 index 9e48b6c..0000000 --- a/[081][Search In Rotated Sorted Array II]/src/Solution2.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-13 06:19 - **/ -public class Solution2 { - /** - * 分析 - * 允许重复元素,则上一题中如果A[mid]>=A[left], 那么[left,mid] 为递增序列的假设就不能成立了,比 - * 如[1,3,1,1,1]。 - * 如果A[mid]>=A[left] 不能确定递增,那就把它拆分成两个条件: - * • 若A[mid]>A[left],则区间[left,mid] 一定递增 - * • 若A[mid]==A[left] 确定不了,那就l++,往下看一步即可。 - * - * @param nums - * @param target - * @return - */ - public boolean search(int[] nums, int target) { - if (nums == null || nums.length < 1) { - return false; - } - - int left = 0; - int right = nums.length - 1; - int mid; - while (left <= right) { - mid = left + (right - left) / 2; - if (nums[mid] == target) { - return true; - } - - // [left, mid]区间递增 - if (nums[left] < nums[mid]) { - // target在[nums[left], nums[mid]]之间 - if (nums[left] <= target && target < nums[mid]) { - right = mid - 1; - } else { - left = mid + 1; - } - } else if (nums[left] > nums[mid]) { // [mid, right]区间递增 - // target在[nums[mid], nums[right]]之间 - if (nums[mid] < target && target <= nums[right]) { - left = mid + 1; - } else { - right = mid - 1; - } - } else { - // 无法区分递增区间,向右移动一个位置 - left++; - } - } - - - return false; - } -} diff --git a/[082][Remove Duplicates From Sorted List II]/src/ListNode.java b/[082][Remove Duplicates From Sorted List II]/src/ListNode.java deleted file mode 100644 index 2afe199..0000000 --- a/[082][Remove Duplicates From Sorted List II]/src/ListNode.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 19:43 - * Declaration: All Rights Reserved !!! - */ -public class ListNode { - int val; - ListNode next; - - ListNode(int v) { - val = v; - } -} diff --git a/[082][Remove Duplicates From Sorted List II]/src/Solution.java b/[082][Remove Duplicates From Sorted List II]/src/Solution.java deleted file mode 100644 index 8e69cf6..0000000 --- a/[082][Remove Duplicates From Sorted List II]/src/Solution.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 19:43 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Given a sorted linked list, delete all nodes that have duplicate numbers,
-     * leaving only distinct numbers from the original list.
-     * For example,
-     * Given 1->2->3->3->4->4->5, return 1->2->5.
-     * Given 1->1->1->2->3, return 2->3.
-     *
-     * Ŀ
-     * һźĵɾظԪءֻֻһֵԪء
-     *
-     * ˼·
-     * һrootrootӵԭͷͷ͸ָ룬صԪؽɾ
-     * 
- * - * @param head - * @return - */ - public ListNode deleteDuplicates(ListNode head) { - - // ͷ - ListNode root = new ListNode(0); - root.next = head; - ListNode p = head; - // ¼һûظԪأʼָͷ - ListNode q = root; - - // Ԫظ - int delta = 0; - - while (p != null && p.next != null) { - // ͬ - if (p.val == p.next.val) { - delta++; - // ƶһ - p = p.next; - } - // 㲻ͬ - else { - // ֵΪp.valĽûظ - if (delta == 0) { - // ӵûиԪ - q.next = p; - // ָһδظԪ - q = p; - // ƶһ - p = p.next; - } - // ֵΪp.valĽظ - else { - // ƶһԪ - p = p.next; - // ȥظԪ - q.next = p.next; - // ԪظΪ0 - delta = 0; - } - } - } - - // һԪǸľȥ - if (delta != 0) { - q.next = null; - } - // ûظͿӵβ - else { - q.next = p; - } - - return root.next; - } -} diff --git a/[083][Remove Duplicates From Sorted List]/src/ListNode.java b/[083][Remove Duplicates From Sorted List]/src/ListNode.java deleted file mode 100644 index a9499a6..0000000 --- a/[083][Remove Duplicates From Sorted List]/src/ListNode.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 19:46 - * Declaration: All Rights Reserved !!! - */ -public class ListNode { - int val; - ListNode next; - - ListNode(int x) { - val = x; - next = null; - } -} diff --git a/[083][Remove Duplicates From Sorted List]/src/Solution.java b/[083][Remove Duplicates From Sorted List]/src/Solution.java deleted file mode 100644 index 97b28f2..0000000 --- a/[083][Remove Duplicates From Sorted List]/src/Solution.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 19:45 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Given a sorted linked list, delete all duplicates such that each element appear only once.
-     * For example,
-     * Given 1->1->2, return 1->2.
-     * Given 1->1->2->3->3, return 1->2->3.
-     *
-     * Ŀ
-     * һɾظԪأֻͬһ
-     *
-     * ˼·
-     * ʹһָָͷһ뵱ǰĽɾֱһͬģָָ
-     * µĽ㣬ظֱеĽ㶼ꡣ
-     * 
- * - * @param head - * @return - */ - public ListNode deleteDuplicates(ListNode head) { - ListNode point; - // ָ½βʼʱֻһԪأͷ - ListNode tail = head; - - if (head != null) { - // ָͷһԪ - point = head.next; - // δĩβ - while (point != null) { - - // βڵ㲻ͬͽͬĽڵӵtailһλ - if (tail.val != point.val) { - tail.next = point; - // ָβ - tail = tail.next; - } - - // ƶһλ - point = point.next; - } - - // βָ - tail.next = null; - } - - return head; - } -} diff --git a/[084][Largest Rectangle in Histogram]/src/Solution.java b/[084][Largest Rectangle in Histogram]/src/Solution.java deleted file mode 100644 index 72f516d..0000000 --- a/[084][Largest Rectangle in Histogram]/src/Solution.java +++ /dev/null @@ -1,71 +0,0 @@ -import java.util.Arrays; -import java.util.Deque; -import java.util.LinkedList; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-17 15:29 - **/ -public class Solution { - /** - *
-     * Given n non-negative integers representing the histogram's bar height where the width
-     * of each bar is 1, find the area of largest rectangle in the histogram.
-     *
-     *
-     *    -
-     *   --
-     *   --
-     *   -- -
-     * - ----
-     * ------
-     * Above is a histogram where width of each bar is 1, given height = [2,1,5,6,2,3].
-     * The largest rectangle is shown in the shaded area, which has area = 10 unit.
-     *    -
-     *   ==
-     *   ==
-     *   == -
-     * - ==--
-     * --==--
-     * Example:
-     * Input: [2,1,5,6,2,3]
-     * Output: 10
-     *
-     * https://leetcode.com/problems/largest-rectangle-in-histogram/
-     * 
- */ - public int largestRectangleArea(int[] heights) { - if (heights == null || heights.length < 1) { - return 0; - } - // 记录位置 - Deque stack = new LinkedList<>(); - - int i = 0; - int result = 0; - - // 复制数组,最后位置补0,方便计算 - int[] h = Arrays.copyOf(heights, heights.length + 1); - - while (i < h.length) { - // 之前的元素小于等于当前元素 - if (stack.isEmpty() || h[stack.peek()] <= h[i]) { - // 当前元素入栈 - stack.push(i); - i++; - } else { - // 栈顶元素位置出栈 - int t = stack.pop(); - // 高度是height[t] - // stack.isEmpty(): 说明栈里的所有元素都比height[i]大,i位置之前有i个元素,序列就是[0 ,1, ..., i-1] - // 所求的长度就是i - // stack不为空,说明计算的位置是[stack.peek(), ..., i-1] 长度 - result = Math.max(result, h[t] * (stack.isEmpty() ? i : i - stack.peek() - 1)); - } - } - - - return result; - - } -} diff --git a/[086][Partition List]/src/ListNode.java b/[086][Partition List]/src/ListNode.java deleted file mode 100644 index b0946e7..0000000 --- a/[086][Partition List]/src/ListNode.java +++ /dev/null @@ -1,11 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 17:18 - * Declaration: All Rights Reserved !!! - */ -public class ListNode { - int val; - ListNode next; - ListNode(int x) { val = x; } -} diff --git a/[086][Partition List]/src/Solution.java b/[086][Partition List]/src/Solution.java deleted file mode 100644 index c241a4b..0000000 --- a/[086][Partition List]/src/Solution.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 17:18 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Given a linked list and a value x, partition it such that all nodes less
-     * than x come before nodes greater than or equal to x.
-     * You should preserve the original relative order of the nodes in each of
-     * the two partitions.
-     *
-     * For example,
-     * Given 1->4->3->2->5->2 and x = 3,
-     * return 1->2->2->4->3->5.
-     *
-     * Ŀ
-     * һһֵxֳСڵxIJֺʹxIJ֡ͬʱԭ˳
-     *
-     * ˼·
-     * abԭеÿ㣬СڵxĽaĩβǴھͷb
-     * ĩβbͷӵaĩβ
-     * 
- * - * @param head - * @param x - * @return - */ - public ListNode partition(ListNode head, int x) { - - ListNode le = new ListNode(0); // Сx - ListNode ge = new ListNode(0); // ڵx - ListNode t1 = le; - ListNode t2 = ge; - ListNode p = head; - - while (p != null) { - if (p.val < x) { - t1.next = p; - t1 = p; - } else { - t2.next = p; - t2 = p; - } - p = p.next; - } - - t2.next = null; - - // пt1û - // t1ƶ˵Сڵ - if (t1 != le) { - t1.next = ge.next; - head = le.next; - } else { - head = ge.next; - } - - return head; - } -} diff --git a/[088][Merge Sorted Array]/src/Solution.java b/[088][Merge Sorted Array]/src/Solution.java deleted file mode 100644 index d25ea04..0000000 --- a/[088][Merge Sorted Array]/src/Solution.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 17:20 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.
-     * Note:
-     * You may assume that nums1 has enough space (size that is greater or equal to m + n) to
-     * hold additional elements from nums2. The number of elements initialized in nums1 and
-     * nums2 are m and n respectively.
-     *
-     * Ŀ
-     * 飬кϲϲҲģϲnums1С
-     * nums1㹻Ŀռnums2
-     *
-     * ˼·
-     * еһλÿʼкϲнϴƶλãǸ
-     * λֵǰƶһλãٽͬIJֱеԪشꡣ
-     * 
- * - * @param arr - * @param m - * @param brr - * @param n - */ - public void merge(int arr[], int m, int brr[], int n) { - int pa = m - 1; - int pb = n - 1; - int index = m + n - 1; - - while (pa >= 0 && pb >= 0) { - if (arr[pa] >= brr[pb]) { - arr[index--] = arr[pa--]; - } else { - arr[index--] = brr[pb--]; - } - } - - // ˵paһΪ0 - while (pb >= 0) { - arr[index--] = brr[pb--]; - } - - // pa >= 0˵[0, pa]ûнжϣΪ[0, pa]arrУԲҪƶ - } -} diff --git a/[089][Gray Code]/src/Main.java b/[089][Gray Code]/src/Main.java deleted file mode 100644 index ba43581..0000000 --- a/[089][Gray Code]/src/Main.java +++ /dev/null @@ -1,18 +0,0 @@ -import java.util.List; - -/** - * Author: - * Date: 2015-06-22 - * Time: 13:27 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { - Solution solution = new Solution(); - List result = solution.grayCode(2); - - for (Integer i: result) { - System.out.printf("%s\n", Integer.toBinaryString(i)); - } - } -} diff --git a/[089][Gray Code]/src/Solution.java b/[089][Gray Code]/src/Solution.java deleted file mode 100644 index 4af4a3c..0000000 --- a/[089][Gray Code]/src/Solution.java +++ /dev/null @@ -1,82 +0,0 @@ -import java.util.LinkedList; -import java.util.List; - -/** - * Author: - * Date: 2015-06-22 - * Time: 13:16 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * The nums[c] is a binary numeral system where two successive values differ in only one bit.
-     * Given a non-negative integer n representing the total number of bits in the code, print the
-     * sequence of gray code. A gray code sequence must begin with 0.
-     *
-     * For example, given n = 2, return [0,1,3,2]. Its gray code sequence is:
-     * 00 - 0
-     * 01 - 1
-     * 11 - 3
-     * 10 - 2
-     *
-     * Note:
-     *   - For a given n, a gray code sequence is not uniquely defined.
-     *   - For example, [0,2,3,1] is also a valid gray code sequence according to the above
-     *          definition.
-     *   - For now, the judge is able to judge based on one instance of gray code sequence.
-     *          Sorry about that.
-     *
-     * Ŀ⣺
-     * nΪnĸ
-     *
-     * (Gray Code) Ķοhttp://en.wikipedia.org/wiki/Gray_code
-     * ȻתΪ룺g0 = b0; gi = bi^b(i-1)
-     * ȻλΪλθλΪĸλθλ
-     * λθλơ磬Ȼ1001תΪĹǣ
-     * λȻ󽫵1 λ1 ͵2 λ0 򣬵õ1Ϊĵ2 λ2 λ0 ͵3 λ
-     * 0 򣬵õ0Ϊĵ3 λ3 λ0 ͵4 λ1 򣬵õ1Ϊ
-     * 4 λգΪ1101
-     * תΪȻ룺b0 = g0; bi = gi^b(i-1)
-     * λΪȻλθλΪȻƸλθλ
-     * λθλơ磬1000 תΪȻĹǣ
-     * λ1ΪȻλȻȻĵ1 λ1 ͸ĵ2 λ0 򣬵
-     * 1ΪȻĵ2 λȻĵ2 λ1 ͸ĵ3 λ0 򣬵õ1
-     * ΪȻĵ3 λȻĵ3 λ1 ͸ĵ4 λ0 򣬵õ1Ϊ
-     * Ȼĵ4 λգȻΪ1111
-     * ѧʽn ĸn^(n/2)
-     * Ҫn صи롣
-     * 1򵥵ķѧʽԴ0 ~2^n-1 תΪ롣
-     * 2nصĸ룬Եݹشn - 1 صĸɡ
-     *
-     * ˼·
-     * ݹ
-     *  ַڸǷʵõݹ¹죺
-     *  1λ
-     *  (n+1)λеǰ2^nֵnλ֣˳дǰ׺0
-     *  (n+1)λеĺ2^nֵnλ֣дǰ׺1
-     * 
- * - * @param n - * @return - */ - public List grayCode(int n) { - List result = new LinkedList<>(); - if (n >= 0) { - // ǰ벿 - result.add(0); - // λֵ0ʱ - int t = 1; - // ÿһѭλi+1λĸ൱ڳΪi+1λĸǰ벿 - for (int i = 0; i < n; i++) { - // ijΪi+1λĺ벿֣ǰ벿ɳΪiλĸ - for (int j = result.size() - 1; j >= 0; j--) { - result.add(result.get(j) ^ t); - } - // λ - t <<= 1; - } - } - return result; - } -} diff --git a/[090][Subsets II]/src/Main.java b/[090][Subsets II]/src/Main.java deleted file mode 100644 index c656a4c..0000000 --- a/[090][Subsets II]/src/Main.java +++ /dev/null @@ -1,23 +0,0 @@ -import org.junit.Test; - -import java.util.Arrays; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-19 17:33 - **/ -public class Main { - @Test - public void test1() { - Solution solution = new Solution(); - int[] nums = {1, 2, 2}; - System.out.println(solution.subsetsWithDup(nums)); - } - - @Test - public void test2() { - Solution solution = new Solution(); - int[] nums = {1, 2, 2}; - System.out.println(solution.subsetsWithDup(nums)); - } -} diff --git a/[090][Subsets II]/src/Solution.java b/[090][Subsets II]/src/Solution.java deleted file mode 100644 index 7593613..0000000 --- a/[090][Subsets II]/src/Solution.java +++ /dev/null @@ -1,66 +0,0 @@ -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-19 16:43 - **/ -public class Solution { - - /** - *
-     * Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set).
-     *
-     * Note: The solution set must not contain duplicate subsets.
-     *
-     * Example:
-     *
-     * Input: [1,2,2]
-     * Output:
-     * [
-     *   [2],
-     *   [1],
-     *   [1,2,2],
-     *   [2,2],
-     *   [1,2],
-     *   []
-     * ]
-     * 
- * - * @param nums - * @return - */ - public List> subsetsWithDup(int[] nums) { - List> result = new LinkedList<>(); - List curr = new LinkedList<>(); - if (nums != null) { - // 对S进行排序处理 - Arrays.sort(nums); - dfs(nums, 0, result, curr); - } - - return result; - } - - private void dfs(int[] nums, int index, List> result, List curr) { - - - // 添加到结果中,说明有一种新的结产生 - result.add(new LinkedList<>(curr)); - - - for (int j = index; j < nums.length; j++) { - // 在当前可选择的范围内,相同的只能选择一次 - if (j > index && nums[j] == nums[j - 1]) { - continue; - } - - // 添加元素 - curr.add(nums[j]); - dfs(nums, j + 1, result, curr); - // 还原 - curr.remove((Integer) nums[j]); - } - } -} diff --git a/[092][Reverse Linked List II]/src/ListNode.java b/[092][Reverse Linked List II]/src/ListNode.java deleted file mode 100644 index 69ec703..0000000 --- a/[092][Reverse Linked List II]/src/ListNode.java +++ /dev/null @@ -1,11 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 17:23 - * Declaration: All Rights Reserved !!! - */ -public class ListNode { - int val; - ListNode next; - ListNode(int x) { val = x; } -} diff --git a/[092][Reverse Linked List II]/src/Solution.java b/[092][Reverse Linked List II]/src/Solution.java deleted file mode 100644 index e1a7587..0000000 --- a/[092][Reverse Linked List II]/src/Solution.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 17:23 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Reverse a linked list from position m to n. Do it in-place and in one-pass.
-     * For example:
-     * Given 1->2->3->4->5->NULL, m = 2 and n = 4,
-     * return 1->4->3->2->5->NULL.
-     * Note:
-     * Given m, n satisfy the following condition:
-     * 1  m  n  length of list.
-     *
-     * Ŀ
-     * һmn֮Ԫؽת
-     * nmǺϷģʹԭطнʹóռ䣩
-     *
-     * ˼·
-     * ҵһҪתԪصǰprevټҪзתԪظԪؽͷ巨
-     * prev棬ͬʱϿ
-     * 
- * - * @param head - * @param m - * @param n - * @return - */ - public ListNode reverseBetween(ListNode head, int m, int n) { - - ListNode root = new ListNode(0); - ListNode p = root; - root.next = head; - - for (int i = 1; i < m && p != null; i++) { - p = p.next; - } - - if (p != null) { - ListNode q = p.next; - ListNode r; - - // mΪΪǴӵһʼ - if (m < 1) { - m = 1; - } - - // nΪҪĽĿ - n = n - m + 1; - // ʱҪʹβ巨βĸΪn-1 - for (int i = 1; i < n && q.next != null; i++) { - // ΪҪβĽ - r = q.next; - - // qĺβ - q.next = r.next; - r.next = p.next; - p.next = r; - } - - head = root.next; - } - - return head; - } -} diff --git a/[093][Restore IP Addresses]/src/Solution.java b/[093][Restore IP Addresses]/src/Solution.java deleted file mode 100644 index ad998bc..0000000 --- a/[093][Restore IP Addresses]/src/Solution.java +++ /dev/null @@ -1,32 +0,0 @@ -import java.util.ArrayList; -import java.util.List; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-23 06:48 - **/ -public class Solution { - public List restoreIpAddresses(String s) { - List result = new ArrayList<>(); - doRestore(result, "", s, 0); - return result; - } - - private void doRestore(List result, String path, String s, int k) { - if (s.isEmpty() || k == 4) { - if (s.isEmpty() && k == 4) { - result.add(path.substring(1)); - } - return; - } - - int length = (s.charAt(0) == '0' ? 1 : 3); // 避免前导0 - length = length < s.length() ? length : s.length(); - for (int i = 1; i <= length; i++) { - String part = s.substring(0, i); - if (Integer.valueOf(part) <= 255) { - doRestore(result, path + "." + part, s.substring(i), k + 1); - } - } - } -} diff --git a/[094][Binary Tree Inorder Traversal]/src/Main.java b/[094][Binary Tree Inorder Traversal]/src/Main.java deleted file mode 100644 index c5cc83f..0000000 --- a/[094][Binary Tree Inorder Traversal]/src/Main.java +++ /dev/null @@ -1,22 +0,0 @@ -import java.util.List; - -/** - * Author: - * Date: 2015-07-25 - * Time: 18:33 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { - TreeNode n1 = new TreeNode(1); - TreeNode n2 = new TreeNode(2); - TreeNode n3 = new TreeNode(3); - - n1.left = n2; - n1.right = n3; - - Solution solution = new Solution(); - List result = solution.inorderTraversal(n1); - System.out.println(result); - } -} diff --git a/[094][Binary Tree Inorder Traversal]/src/Solution.java b/[094][Binary Tree Inorder Traversal]/src/Solution.java deleted file mode 100644 index c1cffb9..0000000 --- a/[094][Binary Tree Inorder Traversal]/src/Solution.java +++ /dev/null @@ -1,37 +0,0 @@ -import java.util.LinkedList; -import java.util.List; - -/** - * Author: - * Date: 2015-07-25 - * Time: 18:19 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - public List inorderTraversal(TreeNode root) { - - List result = new LinkedList<>(); - LinkedList stack = new LinkedList<>(); - TreeNode node = root; - - - // node1root㣬2Һ - while (node != null || !stack.isEmpty()) { - // ջ - while (node != null) { - stack.addLast(node); - node = node.left; - } - - // ʱջеջԪһûӵ - if (!stack.isEmpty()) { - // ɾջԪ - node = stack.removeLast(); - result.add(node.val); - // ָҺ - node = node.right; - } - } - return result; - } -} diff --git a/[094][Binary Tree Inorder Traversal]/src/TreeNode.java b/[094][Binary Tree Inorder Traversal]/src/TreeNode.java deleted file mode 100644 index bb8c0d2..0000000 --- a/[094][Binary Tree Inorder Traversal]/src/TreeNode.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Author: - * Date: 2015-07-25 - * Time: 18:19 - * Declaration: All Rights Reserved !!! - */ -public class TreeNode { - int val; - TreeNode left; - TreeNode right; - - TreeNode(int x) { - val = x; - } -} \ No newline at end of file diff --git a/[096][Unique Binary Search Trees]/src/Main.java b/[096][Unique Binary Search Trees]/src/Main.java deleted file mode 100644 index 71f13cf..0000000 --- a/[096][Unique Binary Search Trees]/src/Main.java +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Author: - * Date: 2015-06-18 - * Time: 17:40 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { - Solution solution = new Solution(); - System.out.println(solution.numTrees(0)); - System.out.println(solution.numTrees(1)); - System.out.println(solution.numTrees(2)); - System.out.println(solution.numTrees(3)); - System.out.println(solution.numTrees(4)); - } -} diff --git a/[096][Unique Binary Search Trees]/src/Solution.java b/[096][Unique Binary Search Trees]/src/Solution.java deleted file mode 100644 index ab0f547..0000000 --- a/[096][Unique Binary Search Trees]/src/Solution.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Author: - * Date: 2015-06-18 - * Time: 17:36 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - * Given n, how many structurally unique BST's (binary search trees) that store values 1...n? - *

- * For example, - * Given n = 3, there are a total of 5 unique BST's. - * 1 3 3 2 1 - * \ / / / \ \ - * 3 2 1 1 3 2 - * / / \ \ - * 2 1 2 3 - *

- * ƹʽ - * f(0) = 1 - * f(1) = 1 - * f(i) = f(0)f(i-1) + f(1)f(i-1) + ... + f(i-1)f(0) - * - * @param n - * @return - */ - public int numTrees(int n) { - - if (n <= 0) { - return 1; - } else if (n == 1) { - return 1; - } - - int[] result = new int[n + 1]; - result[0] = 1; - result[1] = 1; - - - // f(2)...f(n) - for (int i = 2; i <= n; i++) { - for (int j = 1; j <= i; j++) { - result[i] += result[j - 1] * result[i - j]; - } - - } - return result[n]; - } -} diff --git a/[096][Unique Binary Search Trees]/src/Solution2.java b/[096][Unique Binary Search Trees]/src/Solution2.java deleted file mode 100644 index 753d48c..0000000 --- a/[096][Unique Binary Search Trees]/src/Solution2.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Author: - * Date: 2015-06-18 - * Time: 17:36 - * Declaration: All Rights Reserved !!! - */ -public class Solution2 { - /** - * Given n, how many structurally unique BST's (binary search trees) that store values 1...n? - * - * For example, - * Given n = 3, there are a total of 5 unique BST's. - * 1 3 3 2 1 - * \ / / / \ \ - * 3 2 1 1 3 2 - * / / \ \ - * 2 1 2 3 - * - * ƹʽ - * f(k)*f(n-1-k)f(k)ʾk㣬е״f(k)f(n-1-k)ʾn-1-k - * - * f(n) = 2*f(n-1) + f(1)*f(n-2) + f(2)f(n-3) + f(3)f(n-4) + ... +f(n-2)*f(1) - * - * @param n - * @return - */ - public int numTrees(int n) { - - if (n <= 0) { - return 1; - } else if (n == 1) { - return 1; - } - - int[] result = new int[n + 1]; - result[0] = 0; - result[1] = 1; - - - // f(2)...f(n) - for (int i = 2; i <= n; i++) { - // f(i) - result[i] = 2 * result[i - 1]; - for (int j = 1; j <= i - 1 ; j++) { - result[i] += result[j]*result[i - 1 -j]; - } - - } - return result[n]; - } -} diff --git a/[098][Validate Binary Search Tree]/src/Solution.java b/[098][Validate Binary Search Tree]/src/Solution.java deleted file mode 100644 index 26ed700..0000000 --- a/[098][Validate Binary Search Tree]/src/Solution.java +++ /dev/null @@ -1,67 +0,0 @@ -import java.util.Stack; - -/** - * Author: - * Date: 2015-08-21 - * Time: 18:37 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - private Stack stack; - - /** - *

-     * ԭ
-     * Given a binary tree, determine if it is a valid binary search tree (BST).
-     * Assume a BST is defined as follows:
-     * The left subtree of a node contains only nodes with keys less than the nodes key.
-     * The right subtree of a node contains only nodes with keys greater than the nodes key.
-     * Both the left and right subtrees must also be binary search trees.
-     *
-     * Ŀ
-     * ֤
-     *
-     * ˼·
-     * Զ˳򱣴ڶ
-     * һСеУûԪأɴ˿жһǷǶ
-     * 
- * - * @param root - * @return - */ - public boolean isValidBST(TreeNode root) { - - if (root == null) { - return true; - } - - stack = new Stack<>(); - inOrder(root); - - int i = stack.pop(); - int j; - while (!stack.isEmpty()) { - j = stack.pop(); - if (i <= j) { - return false; - } - - i = j; - } - - return true; - } - - /** - * һöر - * - * @param root - */ - public void inOrder(TreeNode root) { - if (root != null) { - inOrder(root.left); - stack.push(root.val); - inOrder(root.right); - } - } -} diff --git a/[098][Validate Binary Search Tree]/src/TreeNode.java b/[098][Validate Binary Search Tree]/src/TreeNode.java deleted file mode 100644 index c9e75e7..0000000 --- a/[098][Validate Binary Search Tree]/src/TreeNode.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 18:38 - * Declaration: All Rights Reserved !!! - */ -public class TreeNode { - int val; - TreeNode left; - TreeNode right; - - TreeNode(int x) { - val = x; - } -} diff --git a/[100][Same Tree]/src/Solution.java b/[100][Same Tree]/src/Solution.java deleted file mode 100644 index 06cf0a2..0000000 --- a/[100][Same Tree]/src/Solution.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 18:40 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Given two binary trees, write a function to check if they are equal or not.
-     * Two binary trees are considered equal if they are structurally identical and
-     * the nodes have the same value.
-     *
-     * Ŀ
-     * жǷȡ
-     * Ľṹֵͬʱȡ
-     *
-     * ˼·
-     * ʹõݹ⣬жϵǰֵǷȣȾٱȽ
-     * ֻееĽ㶼Ȳȡ
-     * 
- * - * @param p - * @param q - * @return - */ - public boolean isSameTree(TreeNode p, TreeNode q) { - - if (p == null && q == null) { - return true; - } - - if (p != null && q == null) { - return false; - } - - if (p == null && q != null) { - return false; - } - - - return p.val == q.val && isSameTree(p.left, q.left) && isSameTree(p.right, q.right); - } -} diff --git a/[100][Same Tree]/src/TreeNode.java b/[100][Same Tree]/src/TreeNode.java deleted file mode 100644 index 58ea6f4..0000000 --- a/[100][Same Tree]/src/TreeNode.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 18:40 - * Declaration: All Rights Reserved !!! - */ -public class TreeNode { - int val; - TreeNode left; - TreeNode right; - TreeNode(int x) { val = x; } -} diff --git a/[101][Symmetric Tree]/src/Solution.java b/[101][Symmetric Tree]/src/Solution.java deleted file mode 100644 index d1be230..0000000 --- a/[101][Symmetric Tree]/src/Solution.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 18:42 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
-     * For example, this binary tree is symmetric:
-     *
-     *     1
-     *    / \
-     *   2   2
-     *  / \ / \
-     * 3  4 4  3
-     *
-     * But the following is not:
-     *
-     *   1
-     *  / \
-     * 2   2
-     * \   \
-     * 3    3
-     *
-     * Note:
-     * Bonus points if you could solve it both recursively and iteratively.
-     * Ŀ
-     * һжǷǶԳƵġǷľ
-     *
-     * ˼·
-     * ʹõݹ⣬жӽǷȣȾͷfalseȾͽӽ
-     * ӽӽбȽϲͬʱӽӽбȽϣֻ
-     * ͬʱΪDzŷtrue򷵻false
-     * 
- * - * @param root - * @return - */ - public boolean isSymmetric(TreeNode root) { - - if (root == null) { - return true; - } else { - return isSame(root.left, root.right); - } - } - - private boolean isSame(TreeNode left, TreeNode right) { - if (left == null && right == null) { - return true; - } - if (left != null && right == null || left == null && right != null) { - return false; - } else { - return left.val == right.val && isSame(left.left, right.right) - && isSame(left.right, right.left); - } - } -} diff --git a/[101][Symmetric Tree]/src/TreeNode.java b/[101][Symmetric Tree]/src/TreeNode.java deleted file mode 100644 index 6834d90..0000000 --- a/[101][Symmetric Tree]/src/TreeNode.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 18:42 - * Declaration: All Rights Reserved !!! - */ -public class TreeNode { - int val; - TreeNode left; - TreeNode right; - - TreeNode(int x) { - val = x; - } -} diff --git a/[102][Binary Tree Level Order Traversal]/src/Solution.java b/[102][Binary Tree Level Order Traversal]/src/Solution.java deleted file mode 100644 index 0f940e9..0000000 --- a/[102][Binary Tree Level Order Traversal]/src/Solution.java +++ /dev/null @@ -1,83 +0,0 @@ -import java.util.ArrayList; -import java.util.Deque; -import java.util.LinkedList; -import java.util.List; - -/** - * Author: - * Date: 2015-08-21 - * Time: 18:44 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * 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,#,#,15,7},
-     *
-     *    3
-     *   / \
-     *  9  20
-     *    /  \
-     *   15   7
-     *
-     * return its level order traversal as:
-     *
-     * [
-     *  [3],
-     *  [9,20],
-     *  [15,7]
-     * ]
-     * Ŀ
-     * һÿһĽ㡣
-     *
-     * ˼·
-     * ʹУһ浱ǰIJ㣬һһҪIJ㡣ֻÿһ㶼ꡣ
-     * 
- * - * @param root - * @return - */ - public List> levelOrder(TreeNode root) { - - List> result = new ArrayList<>(); - - if (root == null) { - return result; - } - - Deque cur = new LinkedList<>(); - Deque sub = new LinkedList<>(); - Deque exc; - - TreeNode node; - cur.addLast(root); - - while (!cur.isEmpty()) { - List layout = new LinkedList<>(); - while (!cur.isEmpty()) { - node = cur.removeFirst(); - layout.add(node.val); - - if (node.left != null) { - sub.addLast(node.left); - } - - if (node.right != null) { - sub.addLast(node.right); - } - } - - exc = cur; - cur = sub; - sub = exc; - - result.add(layout); - } - - return result; - } -} diff --git a/[102][Binary Tree Level Order Traversal]/src/TreeNode.java b/[102][Binary Tree Level Order Traversal]/src/TreeNode.java deleted file mode 100644 index fa1fe26..0000000 --- a/[102][Binary Tree Level Order Traversal]/src/TreeNode.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 18:45 - * Declaration: All Rights Reserved !!! - */ -public class TreeNode { - int val; - TreeNode left; - TreeNode right; - - TreeNode(int x) { - val = x; - } -} diff --git a/[103][Binary Tree Zigzag LevelOrder Traversal]/src/Main.java b/[103][Binary Tree Zigzag LevelOrder Traversal]/src/Main.java deleted file mode 100644 index a33d650..0000000 --- a/[103][Binary Tree Zigzag LevelOrder Traversal]/src/Main.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Author: - * Date: 2015-06-23 - * Time: 13:43 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { - Solution solution = new Solution(); - TreeNode n1 = new TreeNode(1); - TreeNode n2 = new TreeNode(2); - TreeNode n3 = new TreeNode(3); - TreeNode n4 = new TreeNode(4); - TreeNode n5 = new TreeNode(5); - TreeNode n6 = new TreeNode(6); - TreeNode n7 = new TreeNode(7); - - n1.left = n2; - n1.right = n3; - n2.left = n4; - n3.right = n5; - n4.left = n6; - n5.right = n7; - - solution.zigzagLevelOrder(n1); - } -} diff --git a/[103][Binary Tree Zigzag LevelOrder Traversal]/src/Solution.java b/[103][Binary Tree Zigzag LevelOrder Traversal]/src/Solution.java deleted file mode 100644 index 9c60b4e..0000000 --- a/[103][Binary Tree Zigzag LevelOrder Traversal]/src/Solution.java +++ /dev/null @@ -1,104 +0,0 @@ -import java.util.Deque; -import java.util.LinkedList; -import java.util.List; - -/** - * Author: - * Date: 2015-06-23 - * Time: 13:24 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Given a binary tree, return the zigzag level order traversal of its nodes' values.
-     * (ie, from left to right, then right to left for the next level and alternate between).
-     *
-     * For example:
-     * Given binary tree {3,9,20,#,#,15,7},
-     * 3
-     * / \
-     * 9  20
-     * /  \
-     * 15   7
-     * return its zigzag level order traversal as:
-     * [
-     *      [3],
-     *      [20,9],
-     *      [15,7]
-     * ]
-     *
-     * Ŀ⣺
-     * һöӶ£ZηֲǴҵģ²Ǵ
-     *
-     * ˼·
-     * ֲиĽʹջ
-     * 
- * - * @param root - * @return - */ - public List> zigzagLevelOrder(TreeNode root) { - List> result = new LinkedList<>(); - - if (root == null) { - return result; - } - // ־0ʾң1ʾҵ - int flag = 0; - TreeNode node; - // ¼ÿһԪ - List lay = new LinkedList<>(); - // ˫Уջʹã¼ǰ - Deque stack = new LinkedList<>(); - // ¼һ - Deque nextStack = new LinkedList<>(); - - stack.add(root); - - while (!stack.isEmpty()) { - // ɾջԪ - node = stack.removeLast(); - - // - lay.add(node.val); - - // ǰǴұ˳ - if (flag == 0) { - if (node.left != null) { - nextStack.addLast(node.left); - } - - if (node.right != null) { - nextStack.addLast(node.right); - } - } - // ǰǴҵ˳ - else { - if (node.right != null) { - nextStack.addLast(node.right); - } - - if (node.left != null) { - nextStack.addLast(node.left); - } - } - - // ǰѾ - if (stack.isEmpty()) { - Deque temp = nextStack; - nextStack = stack; - stack = temp; - - // һ㴦ķ - flag = 1 - flag; - // 汾 - result.add(lay); - // µһĽ - lay = new LinkedList<>(); - } - } - - return result; - } -} diff --git a/[103][Binary Tree Zigzag LevelOrder Traversal]/src/TreeNode.java b/[103][Binary Tree Zigzag LevelOrder Traversal]/src/TreeNode.java deleted file mode 100644 index efc9fd5..0000000 --- a/[103][Binary Tree Zigzag LevelOrder Traversal]/src/TreeNode.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Author: - * Date: 2015-06-23 - * Time: 13:25 - * Declaration: All Rights Reserved !!! - */ -public class TreeNode { - int val; - TreeNode left; - TreeNode right; - - TreeNode(int x) { - val = x; - } -} diff --git a/[104][Maximum Depth Of Binary Tree]/src/Solution.java b/[104][Maximum Depth Of Binary Tree]/src/Solution.java deleted file mode 100644 index 95106ad..0000000 --- a/[104][Maximum Depth Of Binary Tree]/src/Solution.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 18:47 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Given a binary tree, find its maximum depth.
-     * The maximum depth is the number of nodes along the longest path
-     * from the root node down to the farthest leaf node.
-     *
-     * Ŀ
-     * һȡ
-     *
-     * ˼·
-     * ݹ⣬ݹ鹫ʽ
-     * f(n) = 0; n=null,
-     * f(n) = 1+ max(f(n) f(n))
-     * 
- * - * @param root - * @return - */ - public int maxDepth(TreeNode root) { - if (root == null) { - return 0; - } else if (root.left == null && root.right == null) { - return 1; - } else { - int left = maxDepth(root.left); - int right = maxDepth(root.right); - return 1 + (left > right ? left : right); - } - } -} diff --git a/[104][Maximum Depth Of Binary Tree]/src/TreeNode.java b/[104][Maximum Depth Of Binary Tree]/src/TreeNode.java deleted file mode 100644 index 9ab5aa7..0000000 --- a/[104][Maximum Depth Of Binary Tree]/src/TreeNode.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 18:47 - * Declaration: All Rights Reserved !!! - */ -public class TreeNode { - int val; - TreeNode left; - TreeNode right; - - TreeNode(int x) { - val = x; - } -} diff --git a/[105][Construct Binary Tree From Preorder And Inorder Traversal]/src/Solution.java b/[105][Construct Binary Tree From Preorder And Inorder Traversal]/src/Solution.java deleted file mode 100644 index 5922420..0000000 --- a/[105][Construct Binary Tree From Preorder And Inorder Traversal]/src/Solution.java +++ /dev/null @@ -1,89 +0,0 @@ -/** - * Author: - * Date: 2015-06-23 - * Time: 14:04 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Given preorder and inorder traversal of a tree, construct the binary tree.
-     *
-     * Note:
-     * You may assume that duplicates do not exist in the tree.
-     *
-     * Ŀ⣺
-     * һǰУһ
-     * ע⣺
-     *   - ԪظԪ
-     *
-     * ˼·
-     * ǰһԪǸ㣨kֵΪk±idx
-     * idxзֳǰҲһɽеݹ
-     * 
- * - * @param preorder - * @param inorder - * @return - */ - public TreeNode buildTree(int[] preorder, int[] inorder) { - - // У - if (preorder == null || inorder == null || preorder.length == 0 || preorder.length != inorder.length) { - return null; - } - return solve(preorder, 0, preorder.length - 1, inorder, 0, inorder.length - 1); - } - - /** - * ȷԼ֤ - * - * @param preorder Ľ - * @param x Ŀʼλ - * @param y Ľλ - * @param inorder Ľ - * @param i Ŀʼλ - * @param j Ľλ - * @return ĸ - */ - public TreeNode solve(int[] preorder, int x, int y, int[] inorder, int i, int j) { - - if (x >= 0 && x <= y && i >= 0 && i <= j) { - // ֻһԪ - if (x == y) { - return new TreeNode(preorder[x]); - } - // xܴy - else if (x < y) { - // ¼ - int idx = i; - while (idx <= j && inorder[idx] != preorder[x]) { - idx++; - } - - // - TreeNode root = new TreeNode(inorder[idx]); - - // Ľ - //[i, i+1, ..., idx - 1] -> ܼidx - i - int leftLength = idx - i; - // - if (leftLength > 0) { - // x + 1, x + leftLengthʼͽλ - root.left = solve(preorder, x + 1, x + leftLength, inorder, i, idx - 1); - } - - // Ľ - // [idx+1, idx+2, ..., j] -> ܼƣj - idx - int rightLength = j - idx; - if (rightLength > 0) { - // x + leftLength + 1, yʼͽλ - root.right = solve(preorder, x + leftLength + 1, y, inorder, idx + 1, j); - } - return root; - } - } - - return null; - } -} diff --git a/[105][Construct Binary Tree From Preorder And Inorder Traversal]/src/TreeNode.java b/[105][Construct Binary Tree From Preorder And Inorder Traversal]/src/TreeNode.java deleted file mode 100644 index c4a28e9..0000000 --- a/[105][Construct Binary Tree From Preorder And Inorder Traversal]/src/TreeNode.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Author: - * Date: 2015-06-23 - * Time: 14:04 - * Declaration: All Rights Reserved !!! - */ -public class TreeNode { - int val; - TreeNode left; - TreeNode right; - - TreeNode(int x) { - val = x; - } -} diff --git a/[106][Construct Binary Tree From Inorder And Postorder Traversal]/src/Main.java b/[106][Construct Binary Tree From Inorder And Postorder Traversal]/src/Main.java deleted file mode 100644 index 232e3c8..0000000 --- a/[106][Construct Binary Tree From Inorder And Postorder Traversal]/src/Main.java +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Author: - * Date: 2015-06-23 - * Time: 10:32 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { - Solution solution = new Solution(); - int[] inorder = {1,2,3,4}; - int[] postorder = {3,2,4,1}; - - TreeNode root = solution.buildTree(inorder, postorder); - print(root); - } - - public static void print(TreeNode root) { - if (root != null) { - print(root.left); - System.out.print(root.val + " "); - print(root.right); - } - } -} diff --git a/[106][Construct Binary Tree From Inorder And Postorder Traversal]/src/Solution.java b/[106][Construct Binary Tree From Inorder And Postorder Traversal]/src/Solution.java deleted file mode 100644 index 83cccad..0000000 --- a/[106][Construct Binary Tree From Inorder And Postorder Traversal]/src/Solution.java +++ /dev/null @@ -1,93 +0,0 @@ - -/** - * Author: - * Date: 2015-06-23 - * Time: 10:05 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Given inorder and postorder traversal of a tree, construct the binary tree.
-     *
-     * Note:
-     * You may assume that duplicates do not exist in the tree.
-     *
-     * Ŀ⣺
-     * һͺУһö
-     * ע⣺
-     * ûظԪ
-     *
-     * ˼·
-     * һԪؾĸ(ֵΪr)
-     * ֵΪrλidxidxзΪ
-     * ӦԽзݹ
-     * 
- * - * @param inorder - * @param postorder - * @return - */ - public TreeNode buildTree(int[] inorder, int[] postorder) { - - // - if (inorder == null || postorder == null || inorder.length == 0 || inorder.length != postorder.length) { - return null; - } - - // - return solve(inorder, 0, inorder.length - 1, postorder, 0, postorder.length - 1); - } - - /** - * - * - * @param inorder Ľ - * @param x Ŀʼλ - * @param y Ľλ - * @param postorder Ľ - * @param i Ŀʼλ - * @param j Ľλ - * @return - */ - public TreeNode solve(int[] inorder, int x, int y, int[] postorder, int i, int j) { - - if (x >= 0 && x <= y && i >= 0 && i <= j) { - // ֻһԪأʱҲi=jɣ - if (x == y) { - return new TreeNode(postorder[j]); - } - // һԪأʱҲi ܼ idx-x - int leftLength = idx - x; - if (leftLength > 0) { - // i, i + leftLength - 1ǰʼλ - root.left = solve(inorder, x, idx - 1, postorder, i, i + leftLength - 1); - } - - // ǿգ - // [idx+1, idx+2, ..., y] -> ܼ y-idx - int rightLength = y - idx; - if (rightLength > 0) { - // i + leftLength, j - 1ǰʼλ - root.right = solve(inorder, idx + 1, y, postorder, i + leftLength, j - 1); - } - - return root; - } - } - - return null; - } -} diff --git a/[106][Construct Binary Tree From Inorder And Postorder Traversal]/src/TreeNode.java b/[106][Construct Binary Tree From Inorder And Postorder Traversal]/src/TreeNode.java deleted file mode 100644 index b25eb0f..0000000 --- a/[106][Construct Binary Tree From Inorder And Postorder Traversal]/src/TreeNode.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Author: - * Date: 2015-06-23 - * Time: 10:05 - * Declaration: All Rights Reserved !!! - */ -public class TreeNode { - int val; - TreeNode left; - TreeNode right; - - TreeNode(int x) { - val = x; - } -} diff --git a/[107][Binary Tree Level Order Traversa lII]/src/Solution.java b/[107][Binary Tree Level Order Traversa lII]/src/Solution.java deleted file mode 100644 index 02173b2..0000000 --- a/[107][Binary Tree Level Order Traversa lII]/src/Solution.java +++ /dev/null @@ -1,83 +0,0 @@ -import java.util.ArrayList; -import java.util.Deque; -import java.util.LinkedList; -import java.util.List; - -/** - * Author: - * Date: 2015-08-21 - * Time: 18:49 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Given a binary tree, return the bottom-up level order traversal of its nodes values.
-     * (ie, from left to right, level by level from leaf to root).
-     * For example:
-     * Given binary tree {3,9,20,#,#,15,7},
-     *
-     *     3
-     *    / \
-     *   9  20
-     *     /  \
-     *    15   7
-     * return its bottom-up level order traversal as:
-     *
-     * [
-     *  [15,7],
-     *  [9,20],
-     *  [3]
-     * ]
-     *
-     * Ŀ
-     * һöԵ½в
-     *
-     * ˼·
-     * вÿĽڽͷ
-     * 
- * - * @param root - * @return - */ - public List> levelOrderBottom(TreeNode root) { - - List> list = new LinkedList<>(); - if (root == null) { - return list; - } - - Deque cur = new LinkedList<>(); - Deque nxt = new LinkedList<>(); - Deque exc = new LinkedList<>(); - - TreeNode tmp; - - cur.add(root); - while (!cur.isEmpty()) { - List layout = new ArrayList<>(); - - while (!cur.isEmpty()) { - tmp = cur.remove(); - - if (tmp.left != null) { - nxt.add(tmp.left); - } - - if (tmp.right != null) { - nxt.add(tmp.right); - } - - layout.add(tmp.val); - } - - exc = cur; - cur = nxt; - nxt = exc; - - list.add(0, layout); - } - - return list; - } -} diff --git a/[107][Binary Tree Level Order Traversa lII]/src/TreeNode.java b/[107][Binary Tree Level Order Traversa lII]/src/TreeNode.java deleted file mode 100644 index ea4ddea..0000000 --- a/[107][Binary Tree Level Order Traversa lII]/src/TreeNode.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 18:49 - * Declaration: All Rights Reserved !!! - */ -public class TreeNode { - int val; - TreeNode left; - TreeNode right; - - TreeNode(int x) { - val = x; - } -} diff --git a/[108][Convert Sorted Array To Binary Search Tree]/src/Solution.java b/[108][Convert Sorted Array To Binary Search Tree]/src/Solution.java deleted file mode 100644 index a123565..0000000 --- a/[108][Convert Sorted Array To Binary Search Tree]/src/Solution.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Author: - * Date: 2015-06-22 - * Time: 12:56 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Given an array where elements are sorted in ascending order,
-     * convert it to a height balanced BST.
-     *
-     * Ŀ⣺
-     * һ飬תһ߶ƽ
-     *
-     * ˼·
-     * õݹη
-     * 
- * - * @param nums - * @return - */ - public TreeNode sortedArrayToBST(int[] nums) { - // - if (nums == null || nums.length < 1) { - return null; - } - - // ݹη - return solve(nums, 0, nums.length - 1); - } - - /** - * ݹⷽ - * - * @param nums - * @param start ʼλ - * @param end λ - * @return - */ - public TreeNode solve(int[] nums, int start, int end) { - // δ - if (start <= end) { - // Ҳλ - int mid = start + ((end - start) >> 1); - // - TreeNode root = new TreeNode(nums[mid]); - // - root.left = solve(nums, start, mid - 1); - // - root.right = solve(nums, mid + 1, end); - // ؽ - return root; - } - - return null; - } -} diff --git a/[108][Convert Sorted Array To Binary Search Tree]/src/TreeNode.java b/[108][Convert Sorted Array To Binary Search Tree]/src/TreeNode.java deleted file mode 100644 index 3784d5f..0000000 --- a/[108][Convert Sorted Array To Binary Search Tree]/src/TreeNode.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Author: - * Date: 2015-06-22 - * Time: 12:57 - * Declaration: All Rights Reserved !!! - */ -public class TreeNode { - int val; - TreeNode left; - TreeNode right; - - TreeNode(int x) { - val = x; - } -} diff --git a/[109][Convert Sorted List To Binary Search Tree]/src/ListNode.java b/[109][Convert Sorted List To Binary Search Tree]/src/ListNode.java deleted file mode 100644 index 22946ff..0000000 --- a/[109][Convert Sorted List To Binary Search Tree]/src/ListNode.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Author: - * Date: 2015-06-23 - * Time: 07:17 - * Declaration: All Rights Reserved !!! - */ -public class ListNode { - int val; - ListNode next; - - ListNode(int x) { - val = x; - } -} diff --git a/[109][Convert Sorted List To Binary Search Tree]/src/Main.java b/[109][Convert Sorted List To Binary Search Tree]/src/Main.java deleted file mode 100644 index 3f5d483..0000000 --- a/[109][Convert Sorted List To Binary Search Tree]/src/Main.java +++ /dev/null @@ -1,63 +0,0 @@ -import java.util.LinkedList; -import java.util.List; - -/** - * Author: - * Date: 2015-06-23 - * Time: 08:08 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { - Solution solution = new Solution(); - ListNode n1 = new ListNode(-1); - ListNode n2 = new ListNode(0); - ListNode n3 = new ListNode(1); - ListNode n4 = new ListNode(2); - n1.next = n2; - n2.next = n3; - n3.next = n4; - - TreeNode root = solution.sortedListToBST(n1); - print2(root); - } - - public static void print(TreeNode root) { - if (root != null) { - print(root.left); - System.out.print(root.val + ", "); - print(root.right); - } - } - - public static void print2(TreeNode root) { - if (root != null) { - List list = new LinkedList<>(); - list.add(root); - TreeNode node; - int curr = 1; - int next = 0; - while (!list.isEmpty()) { - node = list.remove(0); - curr--; - System.out.print(node.val + ", "); - - if (node.left != null) { - list.add(node.left); - next++; - } - - if (node.right != null) { - list.add(node.right); - next++; - } - - if (curr == 0) { - System.out.println(); - curr = next; - next = 0; - } - } - } - } -} diff --git a/[109][Convert Sorted List To Binary Search Tree]/src/Solution.java b/[109][Convert Sorted List To Binary Search Tree]/src/Solution.java deleted file mode 100644 index 087b4bb..0000000 --- a/[109][Convert Sorted List To Binary Search Tree]/src/Solution.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Author: - * Date: 2015-06-23 - * Time: 07:16 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Given a singly linked list where elements are sorted in ascending order,
-     * convert it to a height balanced BST.
-     *
-     * Ŀ⣺
-     * һĵתһŸ߶ƽĶ
-     *
-     * ˼·
-     * ⷨһеֵһУͨ㷨ʱ临ӶǣO(n)ռ临ӶǣO(n)
-     * ⷨõݹķʽ
-     *      һм㣬㣬
-     *      м벿ֹ
-     *      мҲֹ
-     * õڶֽⷨ
-     * 
- * - * @param head - * @return - */ - public TreeNode sortedListToBST(ListNode head) { - // Ϊվֱӷnull - if (head == null) { - return null; - } - - // ֻһ - if (head.next == null) { - return new TreeNode(head.val); - } - - // ƶ㣬ÿƶλ - ListNode fast = head.next.next; - // ¼м - ListNode mid = head; - // м - while (fast != null && fast.next != null) { - mid = mid.next; - fast = fast.next.next; - } - - // мһΪ - TreeNode root = new TreeNode(mid.next.val); - // - root.right = sortedListToBST(mid.next.next); - // ¼ҪϿĵ - ListNode midNext = mid.next; - // ϿƻԭĽṹ - mid.next = null; - // - root.left = sortedListToBST(head); - // ½Ӻ - mid.next = midNext; - // ؽ - return root; - } -} diff --git a/[109][Convert Sorted List To Binary Search Tree]/src/TreeNode.java b/[109][Convert Sorted List To Binary Search Tree]/src/TreeNode.java deleted file mode 100644 index b19643b..0000000 --- a/[109][Convert Sorted List To Binary Search Tree]/src/TreeNode.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Author: - * Date: 2015-06-23 - * Time: 07:17 - * Declaration: All Rights Reserved !!! - */ -public class TreeNode { - int val; - TreeNode left; - TreeNode right; - - TreeNode(int x) { - val = x; - } -} diff --git a/[110][Balanced Binary Tree]/src/Solution.java b/[110][Balanced Binary Tree]/src/Solution.java deleted file mode 100644 index 51147b9..0000000 --- a/[110][Balanced Binary Tree]/src/Solution.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 18:53 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - - /** - *
-     * ԭ
-     * Given a binary tree, determine if it is height-balanced.
-     * For this problem, a height-balanced binary tree is defined as a binary tree
-     * in which the depth of the two subtrees of every node never differ by more than 1.
-     *
-     * Ŀ
-     * һƽжǷǸ߶ƽġһø߶ƽĶĸ߶1
-     * Ҳˡ
-     *
-     * ˼·
-     * ݹη⡣
-     * 
- * - * @param root - * @return - */ - public boolean isBalanced(TreeNode root) { - - if (root == null) { - return true; - } - - int left = depth(root.left); - int right = depth(root.right); - if (left - right > 1 || left - right < -1) { - return false; - } else { - return isBalanced(root.left) && isBalanced(root.right); - } - } - - /** - * ĸ߶ - * - * @param n ĸ - * @return ĸ߶ - */ - private int depth(TreeNode n) { - if (n == null) { - return 0; - } - if (n.left == null && n.right == null) { - return 1; - } else { - int left = depth(n.left); - int right = depth(n.right); - return 1 + (left > right ? left : right); - } - } - -} diff --git a/[110][Balanced Binary Tree]/src/TreeNode.java b/[110][Balanced Binary Tree]/src/TreeNode.java deleted file mode 100644 index b36baee..0000000 --- a/[110][Balanced Binary Tree]/src/TreeNode.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 18:54 - * Declaration: All Rights Reserved !!! - */ -public class TreeNode { - int val; - TreeNode left; - TreeNode right; - - TreeNode(int x) { - val = x; - } -} diff --git a/[111][Minimum Depth Of Binary Tree]/src/Solution.java b/[111][Minimum Depth Of Binary Tree]/src/Solution.java deleted file mode 100644 index 836fb49..0000000 --- a/[111][Minimum Depth Of Binary Tree]/src/Solution.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 18:51 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Given a binary tree, find its minimum depth.
-     * The minimum depth is the number of nodes along the shortest path from
-     * the root node down to the nearest leaf node.
-     *
-     * Ŀ
-     * һСȡ
-     *
-     * ˼·
-     * бҳСȡ
-     * 
- * - * @param root - * @return - */ - public int minDepth(TreeNode root) { - return minDepth(root, false); - } - - public int minDepth(TreeNode root, boolean hasBrother) { - if (root == null) { - // ԼΪnullֵܲΪnullϲӽ㣬˵ǰûҵС - // ûֵܣ˵ǰʱֲСѾҵ - return hasBrother ? Integer.MAX_VALUE : 0; - } - - return 1 + Math.min(minDepth(root.left, root.right != null), - minDepth(root.right, root.left != null)); - } - -} diff --git a/[111][Minimum Depth Of Binary Tree]/src/Solution2.java b/[111][Minimum Depth Of Binary Tree]/src/Solution2.java deleted file mode 100644 index 6dfcd46..0000000 --- a/[111][Minimum Depth Of Binary Tree]/src/Solution2.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 18:51 - * Declaration: All Rights Reserved !!! - */ -public class Solution2 { - private int min = Integer.MAX_VALUE; // ¼С - private int cur = 0; // iǰij - - /** - *
-     * ԭ
-     * Given a binary tree, find its minimum depth.
-     * The minimum depth is the number of nodes along the shortest path from
-     * the root node down to the nearest leaf node.
-     *
-     * Ŀ
-     * һСȡ
-     *
-     * ˼·
-     * бҳСȡ
-     * 
- * - * @param root - * @return - */ - public int minDepth(TreeNode root) { - - depth(root); - return min; - } - - /** - * - * - * @param node ǰ - */ - private void depth(TreeNode node) { - - if (node == null) { - min = cur; - return; - } - - cur++; // ǰIJμ1 - // Ҷڵ㣬·ȼ¼СС - if (node.left == null && node.right == null && cur < min) { - min = cur; // Сֵ - } - // - if (node.left != null) { - depth(node.left); - } - - // - if (node.right != null) { - depth(node.right); - } - - cur--; // ԭ - - } -} diff --git a/[111][Minimum Depth Of Binary Tree]/src/TreeNode.java b/[111][Minimum Depth Of Binary Tree]/src/TreeNode.java deleted file mode 100644 index d4f5960..0000000 --- a/[111][Minimum Depth Of Binary Tree]/src/TreeNode.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 18:52 - * Declaration: All Rights Reserved !!! - */ -public class TreeNode { - int val; - TreeNode left; - TreeNode right; - - TreeNode(int x) { - val = x; - } -} diff --git a/[112][Path Sum]/src/Solution.java b/[112][Path Sum]/src/Solution.java deleted file mode 100644 index 6f66723..0000000 --- a/[112][Path Sum]/src/Solution.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 18:56 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - private boolean stop = false; // жǷѾҵ - - /** - *
-     * ԭ
-     * Given a binary tree and a sum, determine if the tree has a root-to-leaf path
-     * such that adding up all the values along the path equals the given sum.
-     * For example:
-     * Given the below binary tree and sum = 22,
-     *
-     *       5
-     *      / \
-     *     4   8
-     *    /   / \
-     *   11  13  4
-     *  /  \      \
-     * 7    2      1
-     *
-     * return true, as there exist a root-to-leaf path 5->4->11->2 which sum is 22.
-     *
-     * Ŀ
-     * һöһͣжϴĸ㵽ҶӽнĺǷڸĺͣڣ
-     * ͷtrue򷵻false
-     *
-     * ˼·
-     * бʹûݷ⡣
-     * 
- * - * @param root - * @param sum - * @return - */ - public boolean hasPathSum(TreeNode root, int sum) { - calculate(root, 0, sum); - return stop; - } - - /** - * Ҷӽĺ - * - * @param node ǰĽڵ - * @param cur Ӹڵ㵽ǰ֮ǰнڵ - * @param sum Ҫĺ - */ - private void calculate(TreeNode node, int cur, int sum) { - if (!stop && node != null) { // ûҵ𰸣ҪĽڵ㲻Ϊ - - // Ҷڵ㣬ͼӸǰҶڵĺǷΪsumǾ˵Ѿҵıstop - if (node.left == null && node.right == null && (node.val + cur == sum)) { - stop = true; - } - - // ǷҶڵ㣬 - if (node.left != null) { - calculate(node.left, cur + node.val, sum); - } - - if (node.right != null) { - calculate(node.right, cur + node.val, sum); - } - } - } -} diff --git a/[112][Path Sum]/src/TreeNode.java b/[112][Path Sum]/src/TreeNode.java deleted file mode 100644 index 0076620..0000000 --- a/[112][Path Sum]/src/TreeNode.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 18:56 - * Declaration: All Rights Reserved !!! - */ -public class TreeNode { - int val; - TreeNode left; - TreeNode right; - - TreeNode(int x) { - val = x; - } -} diff --git a/[113][Path Sum II]/src/Solution.java b/[113][Path Sum II]/src/Solution.java deleted file mode 100644 index 230a216..0000000 --- a/[113][Path Sum II]/src/Solution.java +++ /dev/null @@ -1,90 +0,0 @@ -import java.util.LinkedList; -import java.util.List; - -/** - * Author: - * Date: 2015-08-21 - * Time: 18:59 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - private List> result; - private List l; - private int sum; - private int curSum = 0; - - /** - *
-     * ԭ
-     * Given a binary tree and a sum, find all root-to-leaf paths where each paths
-     * sum equals the given sum.
-     * For example:
-     * Given the below binary tree and sum = 22,
-     *
-     *       5
-     *      / \
-     *     4   8
-     *    /   / \
-     *   11  13  4
-     *  /  \    / \
-     * 7    2  5   1
-     *
-     *  return
-     *
-     * [
-     *  [5,4,11,2],
-     *  [5,8,4,5]
-     * ]
-     *
-     * Ŀ
-     * һöһͣжϴĸ㵽ҶӽнĺǷڸĺͣھͼ¼·
-     *
-     * ˼·
-     * бʹûݷ⡣
-     * 
- * - * @param root - * @param sum - * @return - */ - public List> pathSum(TreeNode root, int sum) { - - result = new LinkedList<>(); - - if (root != null) { - this.sum = sum; - l = new LinkedList<>(); - pathSum(root); - } - - return result; - } - - private void pathSum(TreeNode root) { - if (root != null) { - - l.add(root.val); - curSum += root.val; - - if (root.left == null && root.right == null && curSum == sum) { - List list = new LinkedList<>(); - for (Integer i : l) { - list.add(i); - } - - result.add(list); - } - - if (root.left != null) { - pathSum(root.left); - } - - if (root.right != null) { - pathSum(root.right); - } - - curSum -= root.val; - l.remove(l.size() - 1); // ɾһ - } - } -} diff --git a/[113][Path Sum II]/src/TreeNode.java b/[113][Path Sum II]/src/TreeNode.java deleted file mode 100644 index 8bf40e8..0000000 --- a/[113][Path Sum II]/src/TreeNode.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 18:59 - * Declaration: All Rights Reserved !!! - */ -public class TreeNode { - int val; - TreeNode left; - TreeNode right; - - TreeNode(int x) { - val = x; - } -} diff --git a/[114][Flatten Binary Tree To Linked List]/src/Solution.java b/[114][Flatten Binary Tree To Linked List]/src/Solution.java deleted file mode 100644 index fad9b71..0000000 --- a/[114][Flatten Binary Tree To Linked List]/src/Solution.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 19:02 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Given a binary tree, flatten it to a linked list in-place.
-     * For example,
-     * Given
-     *
-     *      1
-     *     / \
-     *    2   5
-     *   / \   \
-     *  3   4   6
-     *
-     * The flattened tree should look like:
-     *
-     * 1
-     *  \
-     *   2
-     *    \
-     *     3
-     *      \
-     *       4
-     *        \
-     *         5
-     *          \
-     *           6
-     *
-     * Ŀ
-     * һöתɵʹԭ㷨
-     *
-     * ˼·
-     * Ӹ㣨rootlӽ㣨xrootrӵxϣxΪգ
-     * rootΪrootա
-     * 
- * - * @param root - */ - public void flatten(TreeNode root) { - TreeNode head = new TreeNode(-1); - head.right = root; - TreeNode node = head; - - while (node.right != null) { - node = node.right; - if (node.left != null) { - TreeNode end = node.left; - while (end.right != null) { - end = end.right; - } - - TreeNode tmp = node.right; - - node.right = node.left; - node.left = null; - end.right = tmp; - } - } - - head.right = null; // ȥ÷ - } -} diff --git a/[114][Flatten Binary Tree To Linked List]/src/TreeNode.java b/[114][Flatten Binary Tree To Linked List]/src/TreeNode.java deleted file mode 100644 index c988e88..0000000 --- a/[114][Flatten Binary Tree To Linked List]/src/TreeNode.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 19:02 - * Declaration: All Rights Reserved !!! - */ -public class TreeNode { - int val; - TreeNode left; - TreeNode right; - TreeNode(int x) { val = x; } -} diff --git a/[116][Populating Next Right Pointersin Each Node]/src/Solution.java b/[116][Populating Next Right Pointersin Each Node]/src/Solution.java deleted file mode 100644 index 7765517..0000000 --- a/[116][Populating Next Right Pointersin Each Node]/src/Solution.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * Author: - * Date: 2015-06-18 - * Time: 10:43 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - - /** - *
-     * Given a binary tree
-     *      struct TreeLinkNode {
-     *          TreeLinkNode *left;
-     *          TreeLinkNode *right;
-     *          TreeLinkNode *next;
-     *      }
-     * Populate each next pointer to point to its next right node. If there is no next right node,
-     * the next pointer should be set to NULL.
-     *
-     * Initially, all next pointers are set to NULL.
-     *
-     * Note:
-     *      - You may only use constant extra space.
-     *      - You may assume that it is a perfect binary tree (ie, all leaves are at the same level,
-     *        and every parent has two children).
-     *
-     * For example,
-     * Given the following perfect binary tree,
-     *      1
-     *    /  \
-     *   2    3
-     *  / \  / \
-     * 4  5  6  7
-     *
-     * After calling your function, the tree should look like:
-     *
-     *      1 -> NULL
-     *    /  \
-     *   2 -> 3 -> NULL
-     *  / \  / \
-     * 4->5->6->7 -> NULL
-     *
-     * ˼·
-     * ÿһڵnextÿһҲγһ
-     * ÿͷǣӣӣӡ
-     * ˫ѭѭŸӣһֱ¡
-     * ڲѭһĽڵ㴮
-     *
-     * ԼҺӷŵӵnextϣҺӣͨԼnextָ룬ҵھӡ
-     * 
- * - * @param root - */ - public void connect(TreeLinkNode root) { - - TreeLinkNode node; - // мһȫ - // һѭ - // root.left != nullãһûĽ - while (root != null && root.left != null) { - // ÿrootʾһĵһ - // node¼ÿһĵһ - node = root; - - // ÿ - while (node != null) { - // ʾӵͬһµӽ - node.left.next = node.right; - // nodeijһ - if (node.next != null) { - // ӽӵͬڽӽ - node.right.next = node.next.left; - } - - // ƶͬһ - node = node.next; - } - - // ƶһĵһ - root = root.left; - } - - } -} diff --git a/[116][Populating Next Right Pointersin Each Node]/src/TreeLinkNode.java b/[116][Populating Next Right Pointersin Each Node]/src/TreeLinkNode.java deleted file mode 100644 index 47a84b5..0000000 --- a/[116][Populating Next Right Pointersin Each Node]/src/TreeLinkNode.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Author: - * Date: 2015-06-18 - * Time: 10:43 - * Declaration: All Rights Reserved !!! - */ -public class TreeLinkNode { - int val; - TreeLinkNode left, right, next; - - TreeLinkNode(int x) { - val = x; - } -} diff --git a/[117][Populating Next Right Pointers In Each Node II]/src/Main.java b/[117][Populating Next Right Pointers In Each Node II]/src/Main.java deleted file mode 100644 index 4945afa..0000000 --- a/[117][Populating Next Right Pointers In Each Node II]/src/Main.java +++ /dev/null @@ -1,46 +0,0 @@ -import java.util.LinkedList; -import java.util.List; - -/** - * Author: - * Date: 2015-06-22 - * Time: 19:49 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { - TreeLinkNode n1 = new TreeLinkNode(1); - TreeLinkNode n2 = new TreeLinkNode(2); - TreeLinkNode n3 = new TreeLinkNode(3); - TreeLinkNode n4 = new TreeLinkNode(4); - TreeLinkNode n5 = new TreeLinkNode(5); - TreeLinkNode n6 = new TreeLinkNode(6); - TreeLinkNode n7 = new TreeLinkNode(7); - - n1.left = n2; - n1.right = n3; - - n2.left = n4; - n2.right = n5; - - n3.left = n7; - - Solution solution = new Solution(); - solution.connect(n1); -// print(n1); - - - } - - public static void print(TreeLinkNode root) { - if (root != null) { - TreeLinkNode curr; - List list = new LinkedList<>(); - list.add(root); - - while (list.size() > 0) { - curr = list.get(0); - } - } - } -} diff --git a/[117][Populating Next Right Pointers In Each Node II]/src/Solution.java b/[117][Populating Next Right Pointers In Each Node II]/src/Solution.java deleted file mode 100644 index 0aa6600..0000000 --- a/[117][Populating Next Right Pointers In Each Node II]/src/Solution.java +++ /dev/null @@ -1,100 +0,0 @@ -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -/** - * Author: - * Date: 2015-06-22 - * Time: 19:27 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Follow up for problem "Populating Next Right Pointers in Each Node".
-     *
-     * What if the given tree could be any binary tree? Would your previous solution still work?
-     * Note:
-     *
-     * You may only use constant extra space.
-     * For example,
-     * Given the following binary tree,
-     *      1
-     *    /  \
-     *   2    3
-     *  / \    \
-     * 4   5    7
-     * After calling your function, the tree should look like:
-     *      1 -> NULL
-     *    /  \
-     *   2 -> 3 -> NULL
-     *  / \    \
-     * 4-> 5 -> 7 -> NULL
-     *
-     * Ŀ⣺
-     * һöÿڵһnextָ룬ָͬһڵұߵĽڵ㡣ͬĽ㶼
-     *
-     * ˼·
-     * вαÿһ㴮
-     * 
- * - * @param root - */ - public void connect(TreeLinkNode root) { - if (root != null) { - // - List list = new LinkedList<>(); - // ǰĽǰһ - TreeLinkNode prev = null; - // ǰĽ - TreeLinkNode node; - // ǰʣĽ - int curr = 1; - // ¼һԪظ - int next = 0; - - // - list.add(root); - - // зǿ - while (list.size() > 0) { - // ɾԪ - node = list.remove(0); - // ǰʣ - curr--; - - // ǿգӽ - if (node.left != null) { - list.add(node.left); - next++; - } - - // ǿգӽ - if (node.right != null) { - list.add(node.right); - next++; - } - - // ǰ㴦 - if (curr == 0) { - - // һԪؽд - Iterator iterable = list.iterator(); - if (iterable.hasNext()) { - prev = iterable.next(); - while (iterable.hasNext()) { - node = iterable.next(); - prev.next = node; - prev = node; - } - } - - // µǰʣĽ - curr = next; - // ͳ² - next = 0; - } - } - } - } -} diff --git a/[117][Populating Next Right Pointers In Each Node II]/src/TreeLinkNode.java b/[117][Populating Next Right Pointers In Each Node II]/src/TreeLinkNode.java deleted file mode 100644 index 253335a..0000000 --- a/[117][Populating Next Right Pointers In Each Node II]/src/TreeLinkNode.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Author: - * Date: 2015-06-22 - * Time: 19:28 - * Declaration: All Rights Reserved !!! - */ -public class TreeLinkNode { - int val; - TreeLinkNode left, right, next; - - TreeLinkNode(int x) { - val = x; - } -} diff --git a/[118][Pascal's Triangle]/src/Solution.java b/[118][Pascal's Triangle]/src/Solution.java deleted file mode 100644 index 4eb8ab8..0000000 --- a/[118][Pascal's Triangle]/src/Solution.java +++ /dev/null @@ -1,76 +0,0 @@ -import java.util.ArrayList; -import java.util.List; - -/** - * Author: - * Date: 2015-08-21 - * Time: 19:05 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Given numRows, generate the first numRows of Pascals triangle.
-     * For example, given numRows = 5,
-     * Return
-     *
-     * [
-     * [1],
-     * [1,1],
-     * [1,2,1],
-     * [1,3,3,1],
-     * [1,4,6,4,1]
-     * ]
-     *
-     * Ŀ
-     * һnn˹Ρ
-     *
-     * ˼·
-     * n>0
-     * f(1, n)=1(n>0)
-     * f(1, 2)=1(n=2)
-     * f(i,j) = f(i-1, j-1)+f(i, j-1)i>2,j>2
-     * 
- * - * @param numRows - * @return - */ - public List> generate(int numRows) { - - if (numRows < 0) { - return null; - } - - List> list = new ArrayList<>(); - - if (numRows >= 1) { - List data = new ArrayList<>(); - data.add(1); - list.add(data); - } - - if (numRows >= 2) { - List data = new ArrayList<>(); - data.add(1); - data.add(1); - list.add(data); - } - - if (numRows >= 3) { - for (int i = 3; i <= numRows; i++) { - List data = new ArrayList<>(); - List prev = list.get(i - 2); - data.add(1); - for (int j = 2; j <= i - 1; j++) { - data.add(prev.get(j - 2) + prev.get(j - 1)); - } - data.add(1); - - list.add(data); - } - } - - return list; - } -} diff --git a/[119][Pascal's Triangle II]/src/Solution.java b/[119][Pascal's Triangle II]/src/Solution.java deleted file mode 100644 index ef8b077..0000000 --- a/[119][Pascal's Triangle II]/src/Solution.java +++ /dev/null @@ -1,83 +0,0 @@ -import java.util.ArrayList; -import java.util.List; - -/** - * Author: - * Date: 2015-08-21 - * Time: 19:09 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Given an index k, return the kth row of the Pascals triangle.
-     * For example, given k = 3,
-     * Return [1,3,3,1].
-     * Note:
-     * Could you optimize your algorithm to use only O(k) extra space?
-     *
-     * Ŀ
-     * һk˹ĵkС
-     *
-     * ˼·
-     * n>0
-     * f(1, n)=1(n>0)
-     * f(n, n)=1(n>2)
-     * f(i,j) = f(i-1, j-1)+f(i, j-1)i>2,j>2
-     * kС
-     * 
- * - * @param rowIndex - * @return - */ - public List getRow(int rowIndex) { - - rowIndex++; // rowIndexʵĿ - - if (rowIndex < 0) { - return null; - } - - List result = new ArrayList<>(rowIndex); - - if (rowIndex >= 1) { - result.add(1); - } - - if (rowIndex >= 2) { - result.add(1); - } - - int line = 0; // ¼ǰʹһ - int prev; // һһ - if (rowIndex >= 3) { - - int[][] data = new int[2][rowIndex]; - // 1 - data[0][0] = 1; - data[1][0] = 1; - data[1][1] = 1; - - for (int i = 2; i < rowIndex; i++) { - line = i % 2; // ¼ݱڵ0ߵ1 - prev = (i - 1 + 2) % 2; -// data[line][0] = 1; // õһ֣Բã1Ѿˣdata[x][0]Ϊ1 - for (int j = 1; j < i; j++) { - data[line][j] = data[prev][j - 1] + data[prev][j]; - } - - data[line][i] = 1; // һ - } - - // - result.clear(); - for (int i = 0; i < rowIndex; i++) { - result.add(data[line][i]); - } - - } - - return result; - } -} diff --git a/[120][Triangle]/src/Main.java b/[120][Triangle]/src/Main.java deleted file mode 100644 index 419cba9..0000000 --- a/[120][Triangle]/src/Main.java +++ /dev/null @@ -1,33 +0,0 @@ -import java.util.LinkedList; -import java.util.List; - -/** - * Author: - * Date: 2015-06-23 - * Time: 09:24 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { - Solution solution = new Solution(); - int[][] t = { - {2}, - {3, 4}, - {6, 5, 7}, - {4, 1, 8, 3} - }; - - List> tri = new LinkedList<>(); - for (int i = 0; i < t.length; i++) { - List line = new LinkedList<>(); - for (int j = 0; j < t[i].length; j++) { - line.add(t[i][j]); - } - - tri.add(line); - } - - System.out.println(tri); - System.out.println(solution.minimumTotal(tri)); - } -} diff --git a/[120][Triangle]/src/Solution.java b/[120][Triangle]/src/Solution.java deleted file mode 100644 index d3e6b5c..0000000 --- a/[120][Triangle]/src/Solution.java +++ /dev/null @@ -1,80 +0,0 @@ -import java.util.List; - -/** - * Author: - * Date: 2015-06-23 - * Time: 08:51 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Given a triangle, find the minimum path sum from top to bottom.
-     * Each step you may move to adjacent numbers on the row below.
-     *
-     * For example, given the following triangle
-     * [
-     *      [2],
-     *     [3,4],
-     *    [6,5,7],
-     *   [4,1,8,3]
-     * ]
-     *
-     * The minimum path sum from top to bottom is 11 (i.e., 2 + 3 + 5 + 1 = 11).
-     * Note:
-     * Bonus point if you are able to do this using only O(n) extra space,
-     * where n is the total number of rows in the triangle.
-     *
-     * Ŀ⣺
-     * һΣҳӶ׵С·ͣÿһԴһƶһڵ
-     *
-     * ˼·
-     * Ʒ̣
-     * f(0,0)=a[0][0]
-     * f(i,0)=a[i][0]+f(i-1,0) (i>0)
-     * f(i,i)=a[i][i]+f(i-1,i-1)(i>0)
-     * f(i,j)=a[i][j]+MIN(f(i-1,j),f(i-1,j-1))(0
-     *
-     * @param triangle
-     * @return
-     */
-    public int minimumTotal(List> triangle) {
-
-        if (triangle == null || triangle.size() < 1) {
-            return 0;
-        }
-        // ĵڶά
-        int[][] minSum = new int[triangle.size()][];
-
-        // ĵһά
-        for (int i = 0; i < minSum.length; i++) {
-            minSum[i] = new int[i + 1];
-        }
-        // õһ
-        minSum[0][0] = triangle.get(0).get(0);
-        // 
-        for (int i = 1; i < minSum.length; i++) {
-            List line = triangle.get(i);
-            for (int j = 0; j < minSum[i].length; j++) {
-                if (j == 0) {
-                    minSum[i][0] = line.get(0) + minSum[i - 1][0];
-                } else if (i == j) {
-                    minSum[i][j] = line.get(j) + minSum[i - 1][j - 1];
-                } else if (j < i) {
-                    minSum[i][j] = line.get(j) + Math.min(minSum[i - 1][j], minSum[i - 1][j - 1]);
-                }
-            }
-        }
-        //һеСֵĽ
-        int min = minSum[minSum.length - 1][0];
-        int length = minSum[minSum.length - 1].length;
-        for (int i = 1; i < length; i++) {
-            if (min > minSum[length - 1][i]) {
-                min = minSum[length - 1][i];
-            }
-        }
-
-        return min;
-    }
-}
diff --git a/[121][Best Time To Buy And Sell Stock]/src/Solution.java b/[121][Best Time To Buy And Sell Stock]/src/Solution.java
deleted file mode 100644
index f779c93..0000000
--- a/[121][Best Time To Buy And Sell Stock]/src/Solution.java	
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * Author: 
- * Date: 2015-06-22
- * Time: 15:42
- * Declaration: All Rights Reserved !!!
- */
-public class Solution {
-    /**
-     * 
-     * Say you have an array for which the ith element is the price of a given stock on day i.
-     *
-     * If you were only permitted to complete at most one transaction (ie, buy one and sell
-     * one share of the stock), design an algorithm to find the maximum profit.
-     *
-     * Ŀ⣺
-     * һprices[]prices[i]Ʊڵiۼֻۣһν(һ)ܵõ档
-     *
-     * ˼·
-     * ֻҪҳIJֵɣ max(prices[j] C prices[i]) i < jһαɣڱʱñ
-     * low¼ prices[o....i] еСֵǵǰΪֹۼۣʱ临ӶΪ O(n)
-     * 
- * - * @param prices - * @return - */ - public int maxProfit(int[] prices) { - - if (prices == null || prices.length < 1) { - return 0; - } - - int min = prices[0]; - int profit = 0; - - // iļ۸ԿҲԿ - for (int i = 1; i < prices.length; i++) { - // ҵ͵ - if (min > prices[i]) { - // - min = prices[i]; - } - // ļ۸񲻵 - else { - // ļ۸֮ǰļ۸ - if (profit < prices[i] - min) { - // - profit = prices[i] - min; - } - } - } - - return profit; - } -} diff --git a/[122][Best Time to Buy and Sell Stock II]/src/Solution.java b/[122][Best Time to Buy and Sell Stock II]/src/Solution.java deleted file mode 100644 index bef6708..0000000 --- a/[122][Best Time to Buy and Sell Stock II]/src/Solution.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-10-09 08:46 - **/ -public class Solution { - public int maxProfit(int[] prices) { - - if (prices == null || prices.length < 2) { - return 0; - } - - int buy = 0; - int sell = 1; - - int sum = 0; - while (sell < prices.length) { - // 从buy的位置开始找降序子序列中最小的值 - while (buy + 1 < prices.length && prices[buy] >= prices[buy + 1]) { - buy++; - } - // 从buy的位置开始找升序子序列中最大的值 - sell = buy + 1; - while (sell + 1 < prices.length && prices[sell] <= prices[sell + 1]) { - sell++; - } - - if (sell < prices.length) { - sum += prices[sell] - prices[buy]; - } - - buy = sell + 1; - - } - - return sum; - } -} diff --git a/[122][Best Time to Buy and Sell Stock II]/src/Test.java b/[122][Best Time to Buy and Sell Stock II]/src/Test.java deleted file mode 100644 index 2b9341e..0000000 --- a/[122][Best Time to Buy and Sell Stock II]/src/Test.java +++ /dev/null @@ -1,18 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-10-09 09:13 - **/ -public class Test { - public static void main(String[] args) { - Solution solution = new Solution(); - - int[] prices = {7, 1, 5, 3, 6, 4}; - System.out.println(solution.maxProfit(prices) == 7); - - int[] prices2 = {1, 2, 3, 4, 5}; - System.out.println(solution.maxProfit(prices2) == 4); - - int[] prices3 = {7, 6, 4, 3, 1}; - System.out.println(solution.maxProfit(prices3) == 0); - } -} diff --git a/[124][Binary Tree Maximum Path Sum]/src/Solution.java b/[124][Binary Tree Maximum Path Sum]/src/Solution.java deleted file mode 100644 index 0322f49..0000000 --- a/[124][Binary Tree Maximum Path Sum]/src/Solution.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Author: - * Date: 2015-06-25 - * Time: 09:00 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - // ¼· - private int max; - // ¼ǰ· - private int cur; - - /** - *
-     * Given a binary tree, find the maximum path sum.
-     * The path may start and end at any node in the tree.
-     * For example:
-     * Given the below binary tree,
-     *   1
-     *  / \
-     * 2   3
-     * Return 6.
-     *
-     * Ŀ⣺
-     * ·ͣ·ʼյ
-     *
-     *
-     * 
- * - * @param root - * @return - */ - public int maxPathSum(TreeNode root) { - - - if (root == null) { - throw new IllegalArgumentException(); - } - - max = Integer.MIN_VALUE; - cur = 0; - maxPathSumHelper(root); - return max; - } - - public void maxPathSumHelper(TreeNode root) { - if (root != null) { - cur += root.val; - - if (max < cur) { - max = cur; - } - - maxPathSumHelper(root.left); - maxPathSumHelper(root.right); - } - } - -} diff --git a/[124][Binary Tree Maximum Path Sum]/src/TreeNode.java b/[124][Binary Tree Maximum Path Sum]/src/TreeNode.java deleted file mode 100644 index 25c6a36..0000000 --- a/[124][Binary Tree Maximum Path Sum]/src/TreeNode.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Author: - * Date: 2015-06-25 - * Time: 09:01 - * Declaration: All Rights Reserved !!! - */ -public class TreeNode { - int val; - TreeNode left; - TreeNode right; - - TreeNode(int x) { - val = x; - } -} diff --git a/[125][Valid Palindrome]/src/Solution.java b/[125][Valid Palindrome]/src/Solution.java deleted file mode 100644 index 853e8cf..0000000 --- a/[125][Valid Palindrome]/src/Solution.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 19:10 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Given a string, determine if it is a palindrome, considering only
-     * alphanumeric characters and ignoring cases.
-     * For example,
-     * "A man, a plan, a canal: Panama" is a palindrome.
-     * "race a car" is not a palindrome.
-     * Note:
-     * Have you consider that the string might be empty? This is a good
-     * question to ask during an interview.
-     * For the purpose of this problem, we define empty string as valid palindrome.
-     *
-     * Ŀ
-     * һַжǷǻַĸҺԴСд
-     *
-     * ˼·
-     * ʹβָ룬ֱҵһλãбȽϣȾͽһȽϣ
-     * Ⱦͷfalseֱеĸꡣ
-     * 
- * - * @param s - * @return - */ - public boolean isPalindrome(String s) { - - if (s == null) { - return false; - } - - int left = 0; - int right = s.length() - 1; - - int delta = 'A' - 'a'; - char l; - char r; - - while (left < right) { - while (left < s.length() && !isAlphanumericCharacters(s.charAt(left))) { // ĸ - left++; - } - - while (right >= 0 && !isAlphanumericCharacters(s.charAt(right))) { // ĸ - right--; - } - - if (left < right) { - l = s.charAt(left); - r = s.charAt(right); - if (l == r || l - r == delta || r - l == delta) { - left++; - right--; - } else { - return false; - } - } - } - - return true; - } - - /** - * жǷĸ - * - * @param c жϵ - * @return жϽ - */ - private boolean isAlphanumericCharacters(char c) { - return c >= '0' && c <= '9' || c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z'; - } -} diff --git a/[126][Word Ladder II]/src/Main.java b/[126][Word Ladder II]/src/Main.java deleted file mode 100644 index 356b93f..0000000 --- a/[126][Word Ladder II]/src/Main.java +++ /dev/null @@ -1,51 +0,0 @@ -import org.junit.Assert; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-20 08:17 - **/ -public class Main { - @Test - public void test1() { - Solution solution = new Solution(); - String beginWord = "hit"; - String endWord = "cog"; - List wordList = new LinkedList<>(Arrays.asList("hot", "dot", "dog", "lot", "log", "cog")); - System.out.println(solution.findLadders(beginWord, endWord, wordList)); - } - - @Test - public void test2() { - Solution solution = new Solution(); - String beginWord = "hot"; - String endWord = "dog"; - List wordList = new LinkedList<>(Arrays.asList("hot","dog","dot")); - System.out.println(solution.findLadders(beginWord, endWord, wordList)); - } - - @Test - public void test3() { - Solution solution = new Solution(); - String beginWord = "cet"; - String endWord = "ism"; - String[] words = {"kid","tag","pup","ail","tun","woo","erg","luz","brr","gay","sip","kay","per","val","mes","ohs","now","boa","cet","pal","bar","die","war","hay","eco","pub","lob","rue","fry","lit","rex","jan","cot","bid","ali","pay","col","gum","ger","row","won","dan","rum","fad","tut","sag","yip","sui","ark","has","zip","fez","own","ump","dis","ads","max","jaw","out","btu","ana","gap","cry","led","abe","box","ore","pig","fie","toy","fat","cal","lie","noh","sew","ono","tam","flu","mgm","ply","awe","pry","tit","tie","yet","too","tax","jim","san","pan","map","ski","ova","wed","non","wac","nut","why","bye","lye","oct","old","fin","feb","chi","sap","owl","log","tod","dot","bow","fob","for","joe","ivy","fan","age","fax","hip","jib","mel","hus","sob","ifs","tab","ara","dab","jag","jar","arm","lot","tom","sax","tex","yum","pei","wen","wry","ire","irk","far","mew","wit","doe","gas","rte","ian","pot","ask","wag","hag","amy","nag","ron","soy","gin","don","tug","fay","vic","boo","nam","ave","buy","sop","but","orb","fen","paw","his","sub","bob","yea","oft","inn","rod","yam","pew","web","hod","hun","gyp","wei","wis","rob","gad","pie","mon","dog","bib","rub","ere","dig","era","cat","fox","bee","mod","day","apr","vie","nev","jam","pam","new","aye","ani","and","ibm","yap","can","pyx","tar","kin","fog","hum","pip","cup","dye","lyx","jog","nun","par","wan","fey","bus","oak","bad","ats","set","qom","vat","eat","pus","rev","axe","ion","six","ila","lao","mom","mas","pro","few","opt","poe","art","ash","oar","cap","lop","may","shy","rid","bat","sum","rim","fee","bmw","sky","maj","hue","thy","ava","rap","den","fla","auk","cox","ibo","hey","saw","vim","sec","ltd","you","its","tat","dew","eva","tog","ram","let","see","zit","maw","nix","ate","gig","rep","owe","ind","hog","eve","sam","zoo","any","dow","cod","bed","vet","ham","sis","hex","via","fir","nod","mao","aug","mum","hoe","bah","hal","keg","hew","zed","tow","gog","ass","dem","who","bet","gos","son","ear","spy","kit","boy","due","sen","oaf","mix","hep","fur","ada","bin","nil","mia","ewe","hit","fix","sad","rib","eye","hop","haw","wax","mid","tad","ken","wad","rye","pap","bog","gut","ito","woe","our","ado","sin","mad","ray","hon","roy","dip","hen","iva","lug","asp","hui","yak","bay","poi","yep","bun","try","lad","elm","nat","wyo","gym","dug","toe","dee","wig","sly","rip","geo","cog","pas","zen","odd","nan","lay","pod","fit","hem","joy","bum","rio","yon","dec","leg","put","sue","dim","pet","yaw","nub","bit","bur","sid","sun","oil","red","doc","moe","caw","eel","dix","cub","end","gem","off","yew","hug","pop","tub","sgt","lid","pun","ton","sol","din","yup","jab","pea","bug","gag","mil","jig","hub","low","did","tin","get","gte","sox","lei","mig","fig","lon","use","ban","flo","nov","jut","bag","mir","sty","lap","two","ins","con","ant","net","tux","ode","stu","mug","cad","nap","gun","fop","tot","sow","sal","sic","ted","wot","del","imp","cob","way","ann","tan","mci","job","wet","ism","err","him","all","pad","hah","hie","aim","ike","jed","ego","mac","baa","min","com","ill","was","cab","ago","ina","big","ilk","gal","tap","duh","ola","ran","lab","top","gob","hot","ora","tia","kip","han","met","hut","she","sac","fed","goo","tee","ell","not","act","gil","rut","ala","ape","rig","cid","god","duo","lin","aid","gel","awl","lag","elf","liz","ref","aha","fib","oho","tho","her","nor","ace","adz","fun","ned","coo","win","tao","coy","van","man","pit","guy","foe","hid","mai","sup","jay","hob","mow","jot","are","pol","arc","lax","aft","alb","len","air","pug","pox","vow","got","meg","zoe","amp","ale","bud","gee","pin","dun","pat","ten","mob"}; -// List wordList = new ArrayList<>(); -// wordList.addAll(Arrays.asList(words)); - System.out.println(solution.findLadders(beginWord, endWord, Arrays.asList(words))); - } - - @Test - public void test4() { - Solution solution = new Solution(); - String beginWord = "hit"; - String endWord = "cog"; - List wordList = new LinkedList<>(Arrays.asList("hot", "dot", "dog", "lot", "log")); - System.out.println(solution.findLadders(beginWord, endWord, wordList)); - } -} diff --git a/[126][Word Ladder II]/src/Solution.java b/[126][Word Ladder II]/src/Solution.java deleted file mode 100644 index bc6ce38..0000000 --- a/[126][Word Ladder II]/src/Solution.java +++ /dev/null @@ -1,130 +0,0 @@ -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Queue; -import java.util.Set; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-20 08:42 - **/ -public class Solution { - /** - *
-     * Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:
-     *
-     * Only one letter can be changed at a time
-     * Each transformed word must exist in the word list. Note that beginWord is not a transformed word.
-     * Note:
-     *
-     * Return an empty list if there is no such transformation sequence.
-     * All words have the same length.
-     * All words contain only lowercase alphabetic characters.
-     * You may assume no duplicates in the word list.
-     * You may assume beginWord and endWord are non-empty and are not the same.
-     * Example 1:
-     *
-     * Input:
-     * beginWord = "hit",
-     * endWord = "cog",
-     * wordList = ["hot","dot","dog","lot","log","cog"]
-     *
-     * Output:
-     * [
-     *   ["hit","hot","dot","dog","cog"],
-     *   ["hit","hot","lot","log","cog"]
-     * ]
-     * Example 2:
-     *
-     * Input:
-     * beginWord = "hit"
-     * endWord = "cog"
-     * wordList = ["hot","dot","dog","lot","log"]
-     *
-     * Output: []
-     *
-     * Explanation: The endWord "cog" is not in wordList, therefore no possible transformation.
-     *
-     * 使用了图的遍历
-     * https://www.cnblogs.com/splash/p/4102786.html
-     * 
- * - * @param beginWord - * @param endWord - * @param wordList - * @return - */ - HashMap> nodeSet = new HashMap<>(); - - public List> findLadders(String start, String end, List wordList) { - Set wordDict = new HashSet<>(wordList); - - List> result = new ArrayList>(); - - if (!wordDict.contains(end)) { - return result; - } - - Queue q = new LinkedList(); - HashSet hs = new HashSet(); - HashMap dist = new HashMap(); - q.add(start); - nodeSet.put(start, new ArrayList()); - nodeSet.put(end, new ArrayList()); - dist.put(start, 1); - - while (!q.isEmpty()) { - String temp = q.poll(); - int l = dist.get(temp); - hs.add(temp); - for (int i = 0; i < temp.length(); i++) { - for (char c = 'a'; c <= 'z'; c++) { - if (temp.charAt(i) == c) { - continue; - } - StringBuilder sb = new StringBuilder(temp); - sb.setCharAt(i, c); - String next = sb.toString(); - if (next.equals(end)) { - if (!dist.containsKey(end)) { - dist.put(end, l + 1); - nodeSet.get(end).add(temp); - } else if (dist.get(end) == l + 1) { - nodeSet.get(end).add(temp); - } - } else if (wordDict.contains(next) && !hs.contains(next)) { - if (!dist.containsKey(next)) { - q.add(next); - dist.put(next, l + 1); - ArrayList arr = new ArrayList(); - arr.add(temp); - nodeSet.put(next, arr); - } else if (dist.get(next) == l + 1) { - nodeSet.get(next).add(temp); - } - } - } - } - } - List path = new ArrayList(); - path.add(end); - - collect(start, result, path, nodeSet.get(end)); - return result; - } - - public void collect(String start, List> re, List path, ArrayList prevNodes) { - for (int i = 0; i < prevNodes.size(); i++) { - path.add(0, prevNodes.get(i)); - if (prevNodes.get(i).equals(start)) { - List pathCopy = new ArrayList(path); - re.add(pathCopy); - } else { - collect(start, re, path, nodeSet.get(prevNodes.get(i))); - } - path.remove(0); - } - } -} diff --git a/[126][Word Ladder II]/src/Solution2.java b/[126][Word Ladder II]/src/Solution2.java deleted file mode 100644 index 7315d8d..0000000 --- a/[126][Word Ladder II]/src/Solution2.java +++ /dev/null @@ -1,113 +0,0 @@ -import java.util.Deque; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-20 08:42 - **/ -public class Solution2 { - /** - *
-     * Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:
-     *
-     * Only one letter can be changed at a time
-     * Each transformed word must exist in the word list. Note that beginWord is not a transformed word.
-     * Note:
-     *
-     * Return an empty list if there is no such transformation sequence.
-     * All words have the same length.
-     * All words contain only lowercase alphabetic characters.
-     * You may assume no duplicates in the word list.
-     * You may assume beginWord and endWord are non-empty and are not the same.
-     * Example 1:
-     *
-     * Input:
-     * beginWord = "hit",
-     * endWord = "cog",
-     * wordList = ["hot","dot","dog","lot","log","cog"]
-     *
-     * Output:
-     * [
-     *   ["hit","hot","dot","dog","cog"],
-     *   ["hit","hot","lot","log","cog"]
-     * ]
-     * Example 2:
-     *
-     * Input:
-     * beginWord = "hit"
-     * endWord = "cog"
-     * wordList = ["hot","dot","dog","lot","log"]
-     *
-     * Output: []
-     *
-     * Explanation: The endWord "cog" is not in wordList, therefore no possible transformation.
-     *
-     * 使用了深度优化遍历方案,会超时
-     * 
- * - * @param beginWord - * @param endWord - * @param wordList - * @return - */ - public List> findLadders(String beginWord, String endWord, List wordList) { - Set wordDict = new HashSet<>(wordList); - List> result = new LinkedList<>(); - Deque current = new LinkedList<>(); - findLadders(beginWord, endWord, wordDict, current, result); - for(List r: result) { - r.add(0, beginWord); - } - return result; - } - - private void findLadders(String beginWord, String endWord, Set wordDict, Deque current, List> result) { - - if (beginWord.equals(endWord)) { - - // 还没有结果,或者有的最优解,就添加结果 - if (result.isEmpty() || result.get(0).size() == current.size()) { - result.add(new LinkedList<>(current)); - } - // 当前解不是最优解,记录最优化解 - else if (result.get(0).size() > current.size()) { - result.clear(); - result.add(new LinkedList<>(current)); - } - - return; - } - - // 已经找到至少一个可能的最优解,当前还没有找到最优化解,但是转换次数已经等于目前找到的最优化解的次数, - // 目前的方案一定不存在最优化解 - if (!result.isEmpty() && current.size() >= result.get(0).size()) { - return; - } - - char[] chars = beginWord.toCharArray(); - - for (int i = 0; i < chars.length; i++) { - for (char ch = 'a'; ch <= 'z'; ch++) { - char temp = chars[i]; - chars[i] = ch; - String s = new String(chars); - - if (wordDict.contains(s) ) { - wordDict.remove(s); - current.add(s); - - findLadders(s, endWord, wordDict, current, result); - // 还原 - wordDict.add(s); - current.remove(s); - } - - // 还原 - chars[i] = temp; - } - } - } -} diff --git a/[126][Word Ladder II]/src/Solution3.java b/[126][Word Ladder II]/src/Solution3.java deleted file mode 100644 index 906bc48..0000000 --- a/[126][Word Ladder II]/src/Solution3.java +++ /dev/null @@ -1,128 +0,0 @@ -import java.util.Deque; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-20 08:42 - **/ -public class Solution3 { - /** - *
-     * Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:
-     *
-     * Only one letter can be changed at a time
-     * Each transformed word must exist in the word list. Note that beginWord is not a transformed word.
-     * Note:
-     *
-     * Return an empty list if there is no such transformation sequence.
-     * All words have the same length.
-     * All words contain only lowercase alphabetic characters.
-     * You may assume no duplicates in the word list.
-     * You may assume beginWord and endWord are non-empty and are not the same.
-     * Example 1:
-     *
-     * Input:
-     * beginWord = "hit",
-     * endWord = "cog",
-     * wordList = ["hot","dot","dog","lot","log","cog"]
-     *
-     * Output:
-     * [
-     *   ["hit","hot","dot","dog","cog"],
-     *   ["hit","hot","lot","log","cog"]
-     * ]
-     * Example 2:
-     *
-     * Input:
-     * beginWord = "hit"
-     * endWord = "cog"
-     * wordList = ["hot","dot","dog","lot","log"]
-     *
-     * Output: []
-     *
-     * Explanation: The endWord "cog" is not in wordList, therefore no possible transformation.
-     *
-     * 使用了广度优化遍历方案,会超时
-     * 
- * - * @param beginWord - * @param endWord - * @param wordList - * @return - */ - public List> findLadders(String beginWord, String endWord, List wordList) { - - - Set wordDict = new HashSet<>(wordList); - List> result = new LinkedList<>(); - // 用于保存所有中间结果 - Deque> paths = new LinkedList<>(); - - - Deque deque = new LinkedList<>(); - deque.addLast(beginWord); - paths.addLast(deque); - - boolean find = false; - - while (!paths.isEmpty() && !find) { - // 先遍历看是否找到结果,如果找到了,一定是最优化解 - for (Deque path : paths) { - if (path.getLast().equals(endWord)) { - result.add(new LinkedList<>(path)); - find = true; - } - } - - // find表示已经找到了 - // paths.getFirst().size() >=beginWord.length()说明不可能找到结果,path最 - System.out.println(paths.getFirst().size()); - if (find || paths.getFirst().size() >= wordDict.size()) { - break; - } - - // TODO 什么时候判断找不到,path中可能形成环 - - - // 没有找到最优化解,构建下一层 - for (int k = paths.size(); k > 0; k--) { - - // 取路径的最后一个元素 - Deque path = paths.removeFirst(); - String s = path.getLast(); - - // 当前路径下,还可以使用的字词 - Set set = new HashSet<>(wordDict); - set.removeAll(path); - - System.out.println(set); - - // 找出当前层的每个元素经过一次变化后,是否在剩余的wordDict中找到, - // 如果找到就放到下一层的处理中 - char[] chars = s.toCharArray(); - for (int i = 0; i < beginWord.length(); i++) { - for (char j = 'a'; j <= 'z'; j++) { - char temp = chars[i]; - chars[i] = j; - String t = new String(chars); - - // 一次变换后可以找到单词,放到下一层处理中 - if (set.contains(t) && !t.equals(s)) { - path.addLast(t); - paths.addLast(new LinkedList<>(path)); - path.removeLast(); - } - // 还原 - chars[i] = temp; - } - } - - } - } - - return result; - } -} diff --git a/[127][Word Ladder]/src/Main.java b/[127][Word Ladder]/src/Main.java deleted file mode 100644 index 2a6d29a..0000000 --- a/[127][Word Ladder]/src/Main.java +++ /dev/null @@ -1,21 +0,0 @@ -import org.junit.Assert; -import org.junit.Test; - -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-20 08:17 - **/ -public class Main { - @Test - public void test1() { - Solution solution = new Solution(); - String beginWord = "hit"; - String endWord = "cog"; - List wordList = new LinkedList<>(Arrays.asList("hot", "dot", "dog", "lot", "log", "cog")); - Assert.assertEquals(5, solution.ladderLength(beginWord, endWord, wordList)); - } -} diff --git a/[127][Word Ladder]/src/Solution.java b/[127][Word Ladder]/src/Solution.java deleted file mode 100644 index 5366850..0000000 --- a/[127][Word Ladder]/src/Solution.java +++ /dev/null @@ -1,100 +0,0 @@ -import java.util.Deque; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -/** - * Author: - * Date: 2015-06-20 - * Time: 08:11 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Given two words (beginWord and endWord), and a dictionary, find the length
-     * of shortest transformation sequence from beginWord to endWord, such that:
-     *
-     *   - Only one letter can be changed at a time
-     *   - Each intermediate word must exist in the dictionary
-     *
-     * For example,
-     *
-     * Given:
-     * start = "hit"
-     * end = "cog"
-     * dict = ["hot","dot","dog","lot","log"]
-     * As one shortest transformation is "hit" -> "hot" -> "dot" -> "dog" -> "cog",
-     * return its length 5.
-     *
-     * Note:
-     *   - Return 0 if there is no such transformation sequence.
-     *   - All words have the same length.
-     *   - All words contain only lowercase alphabetic characters.
-     *
-     * Ŀ⣺
-     * ʣbeginWordendWordһֵ䣬ҴbeginWordת͵endWord̳ȣ
-     *   - һֻһĸԱı
-     *   - ÿмֱڴʵ
-     *
-     * ע⣺
-     *   - ı任У0
-     *   - еʾͬijȡ
-     *   - еֻСдĸַ
-     *
-     * ˼·
-     * Ż
-     * 
- * - * @param beginWord - * @param endWord - * @param wordList - * @return - */ - public int ladderLength(String beginWord, String endWord, List wordList) { - - Set wordDict = new HashSet<>(wordList); - - char[] chars; - Deque deque = new LinkedList<>(); - deque.addLast(beginWord); - int result = 0; - String s; - String t; - while (!deque.isEmpty()) { - - // ǰ - for (int k = deque.size(); k > 0; k--) { - s = deque.removeFirst(); - - if (s.equalsIgnoreCase(endWord)) { - return result + 1; - } - - // ҳǰÿԪؾһα仯ǷʣwordDictҵ - // ҵͷŵһĴ - chars = s.toCharArray(); - for (int i = 0; i < beginWord.length(); i++) { - for (char j = 'a'; j <= 'z'; j++) { - char temp = chars[i]; - chars[i] = j; - t = new String(chars); - // һα任ҵʣŵһ㴦УwordDictɾ¼ - if (wordDict.contains(t) && !t.equals(s)) { - deque.addLast(t); - wordDict.remove(t); - } - // ԭ - chars[i] = temp; - } - } - } - - - result++; - } - - return 0; - } -} diff --git a/[128][Longest Consecutive Sequence]/src/Main.java b/[128][Longest Consecutive Sequence]/src/Main.java deleted file mode 100644 index d6d2e5c..0000000 --- a/[128][Longest Consecutive Sequence]/src/Main.java +++ /dev/null @@ -1,17 +0,0 @@ -import org.junit.Assert; -import org.junit.Test; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-14 15:02 - **/ -public class Main { - @Test - public void test() { - int[] nums = {100, 4, 200, 1, 3, 2}; - - Solution solution = new Solution(); - - Assert.assertEquals(4, solution.longestConsecutive(nums)); - } -} diff --git a/[128][Longest Consecutive Sequence]/src/Solution.java b/[128][Longest Consecutive Sequence]/src/Solution.java deleted file mode 100644 index b41b5ec..0000000 --- a/[128][Longest Consecutive Sequence]/src/Solution.java +++ /dev/null @@ -1,59 +0,0 @@ -import java.util.HashSet; -import java.util.Set; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-14 14:48 - **/ -class Solution { - /** - *
-     * Given an unsorted array of integers, find the length of the longest consecutive elements sequence.
-     *
-     * Your algorithm should run in O(n) complexity.
-     *
-     * Example:
-     *
-     * Input: [100, 4, 200, 1, 3, 2]
-     * Output: 4
-     * Explanation: The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4.
-     *
-     * 这道题要求求最长连续序列,并给定了O(n)复杂度限制,我们的思路是,使用一个集合HashSet存入所有的数字,
-     * 然后遍历数组中的每个数字,如果其在集合中存在,那么将其移除,然后分别用两个变量pre和next算出其前一个
-     * 数跟后一个数,然后在集合中循环查找,如果pre在集合中,那么将pre移除集合,然后pre再自减1,直至pre不在
-     * 集合之中,对next采用同样的方法,那么next-pre-1就是当前数字的最长连续序列,更新res即可。这里再说下,
-     * 为啥当检测某数字在集合中存在当时候,都要移除数字。这是为了避免大量的重复计算,就拿题目中的例子来说吧,
-     * 我们在遍历到4的时候,会向下遍历3,2,1,如果都不移除数字的话,遍历到1的时候,还会遍历2,3,4。同样,
-     * 遍历到3的时候,向上遍历4,向下遍历2,1,等等等。如果数组中有大量的连续数字的话,那么就有大量的重复计算,
-     * 十分的不高效,所以我们要从HashSet中移除数字
-     * 
- * - * @param nums - * @return - */ - public int longestConsecutive(int[] nums) { - int res = 0; - Set set = new HashSet<>(); - - for (int i : nums) { - set.add(i); - } - - for (int i : nums) { - if (set.remove(i)) { - int prev = i - 1; - int next = i + 1; - while (set.remove(prev)) { - --prev; - } - while (set.remove(next)) { - ++next; - } - - res = Math.max(res, next - prev - 1); - } - } - - return res; - } -} diff --git a/[129][Sum Root To Leaf Numbers]/src/Solution.java b/[129][Sum Root To Leaf Numbers]/src/Solution.java deleted file mode 100644 index 5640b7f..0000000 --- a/[129][Sum Root To Leaf Numbers]/src/Solution.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 19:13 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - private int result = 0; // ¼ܵĽ - private int num = 0; // ǸҶӵ - - /** - *
-     * ԭ
-     * Given a binary tree containing digits from 0-9 only, each root-to-leaf path
-     * could represent a number.
-     * An example is the root-to-leaf path 1->2->3 which represents the number 123.
-     * Find the total sum of all root-to-leaf numbers.
-     * For example,
-     *
-     *   1
-     *  / \
-     * 2   3
-     *
-     * The root-to-leaf path 1->2 represents the number 12.
-     * The root-to-leaf path 1->3 represents the number 13.
-     * Return the sum = 12 + 13 = 25.
-     * Ŀ
-     * һÿֵ0-9Ҷһ֣еĸҶɵֵĺ͡
-     *
-     * ˼·
-     * ûݷ
-     * 
- * - * @param root - * @return - */ - public int sumNumbers(TreeNode root) { - sum(root); - return result; - } - - private void sum(TreeNode root) { - if (root != null) { - num = num * 10 + root.val; - - // Ѿ˸ - if (root.left == null && root.right == null) { - result += num; - } - - sum(root.left); - sum(root.right); - num /= 10; - } - } -} diff --git a/[129][Sum Root To Leaf Numbers]/src/TreeNode.java b/[129][Sum Root To Leaf Numbers]/src/TreeNode.java deleted file mode 100644 index 9f97f8f..0000000 --- a/[129][Sum Root To Leaf Numbers]/src/TreeNode.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 19:13 - * Declaration: All Rights Reserved !!! - */ -public class TreeNode { - int val; - TreeNode left; - TreeNode right; - - TreeNode(int x) { - val = x; - } -} diff --git a/[130][Surrounded Regions]/src/Main.java b/[130][Surrounded Regions]/src/Main.java deleted file mode 100644 index 6c22ca8..0000000 --- a/[130][Surrounded Regions]/src/Main.java +++ /dev/null @@ -1,81 +0,0 @@ -import org.junit.Test; - -/** - * Author: - * Date: 2015-06-22 - * Time: 10:02 - * Declaration: All Rights Reserved !!! - */ -public class Main { - - @Test - public void test01() { - Solution solution = new Solution(); - char[][] board = { - "XXXX".toCharArray(), - "XOOX".toCharArray(), - "XXOX".toCharArray(), - "XOXX".toCharArray() - }; - - solution.solve(board); - - for (char[] line : board) { - System.out.println(new String(line)); - } - System.out.println(); - } - - @Test - public void test02() { - Solution solution = new Solution(); - char[][] board = { - "XOXX".toCharArray(), - "OXOX".toCharArray(), - "XOXO".toCharArray(), - "OXOX".toCharArray(), - "XOXO".toCharArray(), - "OXOX".toCharArray() - }; - - solution.solve(board); - - for (char[] line : board) { - System.out.println(new String(line)); - } - System.out.println(); - } - - @Test - public void test03() { - Solution solution = new Solution(); - char[][] board = { - "OO".toCharArray(), - "OO".toCharArray() - }; - - solution.solve(board); - - for (char[] line : board) { - System.out.println(new String(line)); - } - System.out.println(); - } - - @Test - public void test04() { - Solution solution = new Solution(); - char[][] board = { - "OOO".toCharArray(), - "OOO".toCharArray(), - "OOO".toCharArray() - }; - - solution.solve(board); - - for (char[] line : board) { - System.out.println(new String(line)); - } - System.out.println(); - } -} diff --git a/[130][Surrounded Regions]/src/Solution.java b/[130][Surrounded Regions]/src/Solution.java deleted file mode 100644 index 636f0a0..0000000 --- a/[130][Surrounded Regions]/src/Solution.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * Author: - * Date: 2015-06-22 - * Time: 08:51 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.
-     * A region is captured by flipping all 'O's into 'X's in that surrounded region.
-     *
-     * For example,
-     * X X X X
-     * X O O X
-     * X X O X
-     * X O X X
-     *
-     * After running your function, the board should be:
-     * X X X X
-     * X X X X
-     * X X X X
-     * X O X X
-     *
-     * Ŀ⣺
-     * һά񣬰'X''O'ԱXΧOX
-     * ˼·
-     * ȶȱķʽҳXΧOΪ$
-     * 
- * - * @param board - */ - void solve(char[][] board) { - - // У - if (board == null || board.length < 1 || board[0].length < 1) { - return; - } - - // һк - for (int i = 0; i < board[0].length; i++) { - dfs(board, 0, i); - dfs(board, board.length - 1, i); - } - - // һкһ - for (int i = 1; i < board.length - 1; i++) { - dfs(board, i, 0); - dfs(board, i, board[0].length - 1); - } - - - - for (int i = 0; i < board.length; ++i) { - for (int j = 0; j < board[i].length; ++j) { - if (board[i][j] == 'O') { - board[i][j] = 'X'; - } - if (board[i][j] == '$') { - board[i][j] = 'O'; - } - } - } - } - - void dfs(char[][] board, int i, int j) { - if (board[i][j] == 'O') { - board[i][j] = '$'; - if (i > 0 && board[i - 1][j] == 'O') { - dfs(board, i - 1, j); - } - if (j < board[i].length - 1 && board[i][j + 1] == 'O') { - dfs(board, i, j + 1); - } - if (i < board.length - 1 && board[i + 1][j] == 'O') { - dfs(board, i + 1, j); - } - if (j > 1 && board[i][j - 1] == 'O') { - dfs(board, i, j - 1); - } - } - } -} diff --git a/[130][Surrounded Regions]/src/Solution2.java b/[130][Surrounded Regions]/src/Solution2.java deleted file mode 100644 index 3308a10..0000000 --- a/[130][Surrounded Regions]/src/Solution2.java +++ /dev/null @@ -1,258 +0,0 @@ -import java.util.LinkedList; -import java.util.List; - -/** - * Author: - * Date: 2015-06-22 - * Time: 08:51 - * Declaration: All Rights Reserved !!! - */ -public class Solution2 { - /** - *
-     * Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.
-     * A region is captured by flipping all 'O's into 'X's in that surrounded region.
-     *
-     * For example,
-     * X X X X
-     * X O O X
-     * X X O X
-     * X O X X
-     *
-     * After running your function, the board should be:
-     * X X X X
-     * X X X X
-     * X X X X
-     * X O X X
-     *
-     * Ŀ⣺
-     * һά񣬰'X''O'ԱXΧOX
-     * ˼·
-     * ùȱķʽҲԲóȵķʽջ,dzеıΧĵ㣬ʣµľDzΧĵ
-     * 
- * - * @param board - */ - //////////////////////////////////////////////////////////////////////////////////////////////// - // ùȶȱķʽҳеġΧĵ - //////////////////////////////////////////////////////////////////////////////////////////////// - public void solve(char[][] board) { - // У - if (board == null || board.length < 1 || board[0].length < 1) { - return; - } - - boolean[][] visited = new boolean[board.length][board[0].length]; - // ʱΧһȦԪ - List round = new LinkedList<>(); - // - for (int col = 0; col < board[0].length; col++) { - // УҵOҵδʹ - if (!visited[0][col] && board[0][col] == 'O') { - round.clear(); - round.add(new Coordinate(0, col)); - bfs(board, visited, round); - } - } - - // ײ - for (int col = 0; col < board[0].length; col++) { - // УҵOҵδʹ - if (!visited[board.length - 1][col] && board[board.length - 1][col] == 'O') { - round.clear(); - round.add(new Coordinate(board.length - 1, col)); - bfs(board, visited, round); - } - } - - // - for (int row = 1; row < board.length - 1; row++) { - // УҵOҵδʹ - if (!visited[row][0] && board[row][0] == 'O') { - round.clear(); - round.add(new Coordinate(row, 0)); - bfs(board, visited, round); - } - } - - // ұ - for (int row = 1; row < board.length - 1; row++) { - // УҵOҵδʹ - if (!visited[row][board[0].length - 1] && board[row][board[0].length - 1] == 'O') { - round.clear(); - round.add(new Coordinate(row, board[0].length - 1)); - bfs(board, visited, round); - } - } - - // - for (int i = 0; i < board.length; i++) { - for (int j = 0; j < board[0].length; j++) { - // δʹֿܣһX㣬ڶO㣬OһDZXΧ - // ʱδʹĵΪXȷ - if (!visited[i][j]) { - board[i][j] = 'X'; - } - } - } - } - - /** - * ȣҲΧĵ - * - * @param board ά - * @param visited ʱ - * @param round ʱΧһȦԪ - */ - public void bfs(char[][] board, boolean[][] visited, List round) { - Coordinate c; - while (round.size() > 0) { - c = round.remove(0); - if (c.x >= 0 && c.x < board.length && c.y >= 0 && c.y < board[0].length && board[c.x][c.y] == 'O' && !visited[c.x][c.y]) { - visited[c.x][c.y] = true; - round.add(new Coordinate(c.x - 1, c.y)); - round.add(new Coordinate(c.x, c.y + 1)); - round.add(new Coordinate(c.x + 1, c.y)); - round.add(new Coordinate(c.x, c.y - 1)); - } - } - } - - //////////////////////////////////////////////////////////////////////////////////////////////// - // ùȶȱķʽҳеıΧĵ㣬ұǻᳬʱ - //////////////////////////////////////////////////////////////////////////////////////////////// - public void solve2(char[][] board) { - // У - if (board == null || board.length < 1 || board[0].length < 1) { - return; - } - - boolean[][] visited = new boolean[board.length][board[0].length]; - - // ʱΧһȦԪ - List round = new LinkedList<>(); - // Ԫ - List all = new LinkedList<>(); - - for (int i = 0; i < board.length; i++) { - for (int j = 0; j < board[0].length; j++) { - if (!visited[i][j] && board[i][j] == 'O') { - // һȦԪ - round.add(new Coordinate(i, j)); - boolean result = bfs(board, visited, round, all); - // һOڣҲڱ߽ - if (result) { - // ñ - for (Coordinate c : all) { - board[c.x][c.y] = 'X'; - } - } - - // Ԫ - round.clear(); - all.clear(); - } - } - } - - } - - /** - * ȱ - * - * @param board ά - * @param visited ʱ - * @param round ʱΧһȦԪ - * @param all Ԫ - * @return trueOڣҲڱ߽ϣXܷtrue - */ - public boolean bfs(char[][] board, boolean[][] visited, List round, List all) { - boolean result = true; - int size = round.size(); - Coordinate c; - while (size > 0) { - size--; - - // ȡԪ - c = round.remove(0); - // ӵ¼Ԫؼ - all.add(c); - // Ѿʹ - visited[c.x][c.y] = true; - // жcǷOڵ - result &= isInner(board, c.x, c.y); - - // cһǷOûзʹӵround - if (isO(board, c.x - 1, c.y) && !visited[c.x - 1][c.y]) { - round.add(new Coordinate(c.x - 1, c.y)); - } - - // cһǷOûзʹӵround - if (isO(board, c.x, c.y + 1) && !visited[c.x][c.y + 1]) { - round.add(new Coordinate(c.x, c.y + 1)); - } - - // cһǷOûзʹӵround - if (isO(board, c.x + 1, c.y) && !visited[c.x + 1][c.y]) { - round.add(new Coordinate(c.x + 1, c.y)); - } - - // cһǷOûзʹӵround - if (isO(board, c.x, c.y - 1) && !visited[c.x][c.y - 1]) { - round.add(new Coordinate(c.x, c.y - 1)); - } - } - - if (round.size() > 0) { - return bfs(board, visited, round, all) && result; - } else { - return result; - } - - } - - /** - * жϵڶάڲҲڱ߽ - * - * @param board ά - * @param x - * @param y - * @return true - */ - public boolean isInner(char[][] board, int x, int y) { - return x > 0 && x < board.length - 1 && y > 0 && y < board[0].length - 1; - } - - /** - * жϵǷO - * - * @param board ά - * @param x - * @param y - * @return true - */ - public boolean isO(char[][] board, int x, int y) { - return x >= 0 && x < board.length && y >= 0 && y < board[0].length && board[x][y] == 'O'; - } - - /** - * - */ - public static class Coordinate { - private int x; - private int y; - - public Coordinate() { - } - - public Coordinate(int x, int y) { - this.x = x; - this.y = y; - } - - @Override - public String toString() { - return "(" + x + ", " + y + ")"; - } - } -} diff --git a/[131][Palindrome Partitioning]/src/Main.java b/[131][Palindrome Partitioning]/src/Main.java deleted file mode 100644 index 8266432..0000000 --- a/[131][Palindrome Partitioning]/src/Main.java +++ /dev/null @@ -1,15 +0,0 @@ -import org.junit.Test; - -import java.util.Arrays; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-21 18:36 - **/ -public class Main { - @Test - public void test1() { - Solution solution = new Solution(); - System.out.println(solution.partition("aab")); - } -} diff --git a/[131][Palindrome Partitioning]/src/Solution.java b/[131][Palindrome Partitioning]/src/Solution.java deleted file mode 100644 index e3efdab..0000000 --- a/[131][Palindrome Partitioning]/src/Solution.java +++ /dev/null @@ -1,70 +0,0 @@ -import java.util.Deque; -import java.util.LinkedList; -import java.util.List; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-21 18:29 - **/ -public class Solution { - /** - *
-     * Given a string s, partition s such that every substring of the partition is a palindrome.
-     *
-     * Return all possible palindrome partitioning of s.
-     *
-     * Example:
-     *
-     * Input: "aab"
-     * Output:
-     * [
-     *   ["aa","b"],
-     *   ["a","a","b"]
-     * ]
-     *
-     * 解决方案:可以使用回溯法
-     * TODO : 可以构建一个回文表,再进行判定
-     * 
- * - * @param s - * @return - */ - public List> partition(String s) { - List> result = new LinkedList<>(); - Deque current = new LinkedList<>(); - - partition(s, 0, current, result); - - return result; - } - - private void partition(String s, int index, Deque current, List> result) { - if (index == s.length()) { - result.add(new LinkedList<>(current)); - return; - } - - for (int i = index; i < s.length(); i++) { - String t = s.substring(index, i + 1); - if (isPalindrome(s, index, i)) { - current.addLast(t); - partition(s, i + 1, current, result); - // 还原 - current.removeLast(); - } - } - } - - private boolean isPalindrome(String s, int start, int end) { - while (start < end) { - - if (s.charAt(start) != s.charAt(end)) { - return false; - } else { - start++; - end--; - } - } - return true; - } -} diff --git a/[134][Gas Station]/src/Main.java b/[134][Gas Station]/src/Main.java deleted file mode 100644 index 250a219..0000000 --- a/[134][Gas Station]/src/Main.java +++ /dev/null @@ -1,17 +0,0 @@ -import org.junit.Assert; -import org.junit.Test; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-16 11:06 - **/ -public class Main { - @Test - public void test1() { - Solution solution = new Solution(); - int[] gas = {1, 2, 3, 4, 5}; - int[] cost = {3, 4, 5, 1, 2}; - int pos = solution.canCompleteCircuit(gas, cost); - Assert.assertEquals(3, pos); - } -} diff --git a/[134][Gas Station]/src/Solution.java b/[134][Gas Station]/src/Solution.java deleted file mode 100644 index 213926c..0000000 --- a/[134][Gas Station]/src/Solution.java +++ /dev/null @@ -1,146 +0,0 @@ -/** - * Author: - * Date: 2015-06-21 - * Time: 10:11 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * There are N gas stations along a circular route, where the amount
-     * of gas at station i is gas[i].
-     *
-     * You have a car with an unlimited gas tank and it costs cost[i] of gas
-     * to travel from station i to its next station (i+1). You begin the journey
-     * with an empty tank at one of the gas stations.
-     *
-     * Return the starting gas station's index if you can travel around the
-     * circuit once, otherwise return -1.
-     *
-     * Note:
-     *   - The solution is guaranteed to be unique.
-     *
-     * Ŀ⣺
-     * ػ·Nվڳվigas[i]
-     * гޣӼվiһվվi+1Ҫcost[i]塣
-     * 㿪ʼóʱǿյġصʼվָѡһ㿪ʼΣ
-     * ΧһΣͷؿʼļվ򷵻-1
-     *
-     * ע⣺
-     *   - 𰸱֤Ψһ
-     *
-     * ˼·
-     * վ i վ k ֮ǰȻܱ֤û׶k 󣬼׶ˡ
-     * ô˵ diff[i] + diff[i+1] + ... + diff[k] < 0diff[k]⣬diff[i]
-     * ʼۼӶ >= 0ġҲ˵diff[i] Ҳ >= 0ģʱǻбҪվ i + 1
-     * ϸһ֪ҪǴվ i+1վkûվkͼ
-     * ˣΪټվ i ͡
-     *
-     * ˣǷֵk վ׶i  k Щվ㶼Ϊˣ϶
-     * ֻҪk+1վ㳢Լɣ˽ⷨʱ临ӶȴO(n2) O(2n)֮
-     * O(2n)Ϊk+1վΪʼվȦk֤k+1Ƿ㡣
-     *
-     * ȵȣҪ
-     * ģһ¹̣
-     * a. ʼվ0ʼվ賵վpˣ
-     *      sum1 = diff[0] +diff[1] + ... + diff[p]֪sum1 < 0
-     *
-     * b. ǽp+1Ϊʼվqվֿˣ
-     *      sum2 = diff[p+1] +diff[p+2] + ... + diff[q]֪sum2 < 0
-     *
-     * c. q+1Ϊʼվһֱδѭĩվû׶
-     *      sum3 = diff[q+1] +diff[q+2] + ... + diff[size-1]֪sum3 >= 0
-     *
-     * Ҫ֪ܷ񿪻 q վʵsum3 Ļϣμ diff[0]  diff[q]
-     * sum3ǷС0֮ǰѾ֪ diff[0]  diff[p-1] ·
-     * һֱַǸֻҪsum3 + sum1Ƿ <0֪ܲܿ p+1վˡ
-     * ܴp+1վֻҪsum3 + sum1 + sum2 Ƿ < 0֪ܲܿqվˡ
-     *
-     * Ϊ sum1, sum2  < 0 sum3 + sum1 + sum2 >=0 ô
-     * sum3 + sum1 Ȼ >= 0Ҳ˵ֻҪsum3 + sum1 + sum2 >=0Ȼܿqվ
-     * sum3 + sum1 + sum2 ʵ diffܺ TotalԪѾˡ
-     *  Total ܷ >= 0Ƿվ ֱҪ
-     *
-     * ʱ临ӶȽһO(2n) O(n)
-     * 
- * - * @param gas - * @param cost - * @return - */ - public int canCompleteCircuit(int[] gas, int[] cost) { - // - if (gas == null || cost == null || gas.length == 0 || gas.length != cost.length) { - return -1; - } - - // ¼ʵʼ - int start = 0; - // ӵĵֵܲ - int total = 0; - // startλÿʼӵĵֵܲ - int sum = 0; - - for (int i = 0; i < gas.length; i++) { - total += (gas[i] - cost[i]); - - // û - if (sum < 0) { - // е - sum = gas[i] - cost[i]; - // ¼µλ - start = i; - } else { - // лͣе - sum += (gas[i] - cost[i]); - } - } - - return total >= 0 ? start : -1; - } - - - /** - * ķᳬʱO(N^2)ʱ临Ӷ - */ - public int canCompleteCircuit2(int[] gas, int[] cost) { - // - if (gas == null || cost == null || gas.length == 0 || gas.length != cost.length) { - return -1; - } - - // ʣµ壬ʼʱΪ0 - int leftGas = 0; - // ʼվ - int start = 0; - // վ - int end = 1; - - // δһ - while (start < gas.length) { - - // һվ - leftGas = gas[start] - cost[start]; - - // ߵһվ - if (leftGas > 0) { - // ¼һվ - end = (start + 1) % gas.length; - - // һֱԵһվͳв - while (start != end && (leftGas += (gas[end] - cost[end])) >= 0) { - end = (end + 1) % gas.length; - } - - // ˵Ѿһ - if (start == end) { - return start; - } - } - - start++; - } - - return -1; - } -} diff --git a/[135][Candy]/src/Main.java b/[135][Candy]/src/Main.java deleted file mode 100644 index 54ea1af..0000000 --- a/[135][Candy]/src/Main.java +++ /dev/null @@ -1,14 +0,0 @@ -import org.junit.Assert; -import org.junit.Test; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-16 11:37 - **/ -public class Main { - @Test - public void test1() { - Solution solution = new Solution(); - Assert.assertEquals(5, solution.candy(new int[]{1, 0, 2})); - } -} diff --git a/[135][Candy]/src/Solution.java b/[135][Candy]/src/Solution.java deleted file mode 100644 index ea602e0..0000000 --- a/[135][Candy]/src/Solution.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-16 11:27 - **/ -public class Solution { - /** - *
-     * There are N children standing in a line. Each child is assigned a rating value.
-     *
-     * You are giving candies to these children subjected to the following requirements:
-     *
-     * 1. Each child must have at least one candy.
-     * 2. Children with a higher rating get more candies than their neighbors.
-     * What is the minimum candies you must give?
-     *
-     * Example 1:
-     *
-     * Input: [1,0,2]
-     * Output: 5
-     * Explanation: You can allocate to the first, second and third child with 2, 1, 2 candies respectively.
-     * Example 2:
-     *
-     * Input: [1,2,2]
-     * Output: 4
-     * Explanation: You can allocate to the first, second and third child with 1, 2, 1 candies respectively.
-     *              The third child gets 1 candy because it satisfies the above two conditions.
-     * 
- * - * @param ratings - * @return - */ - public int candy(int[] ratings) { - if (ratings == null || ratings.length < 1) { - return 0; - } - - - int[] increment = new int[ratings.length]; - // 左右各扫描一遍 - for (int i = 1, inc = 1; i < ratings.length; i++) { - // 右边的孩子分数比左边的孩子分数高 - if (ratings[i] > ratings[i - 1]) { - // 右边的孩子比左边的孩子多发至少一个糖果 - increment[i] = increment[i - 1] + 1; - } -// // 右边的孩子分数与左边的孩子分数相等,相等可以少发 -// else if (ratings[i] == ratings[i - 1]) { -// // 右边和左边的孩子增同样多颗糖 -// increment[i] = increment[i - 1]; -// } - // 可以不处理 -// else{ -// increment[i] = 0; -// } - } - - // 从右到左进行处理 - for (int i = ratings.length - 2, inc = 1; i >= 0; i--) { - // 左边的孩子分数比右边高 - if (ratings[i] > ratings[i + 1]) { - increment[i] = Math.max(increment[i], increment[i + 1] + 1); - } - // -// else if (ratings[i] == ratings[i + 1]) { -// // 总是成立了 -// increment[i] = increment[i - 1]; -// } - // ratings[i] < ratings[i + 1] 不需要操作 - } - - int sum = ratings.length; - for (int n : increment) { - sum += n; - } - return sum; - } -} diff --git a/[136][Single Number]/src/Solution.java b/[136][Single Number]/src/Solution.java deleted file mode 100644 index 1ec5d37..0000000 --- a/[136][Single Number]/src/Solution.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Author: - * Date: 2015-06-18 - * Time: 10:29 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - * Given an array of integers, every element appears twice except for one. - * Find that single one. - * - * Note: Your algorithm should have a linear runtime complexity. - * Could you implement it without using extra memory? - * - * һ飬ÿԪض2γеһҳֻһε - * ע⣺㷨ʱ临ӶȣԲʹöռʵ - * - * ˼·ʹ - * - * @param nums - * @return - */ - public int singleNumber(int[] nums) { - - if (nums == null || nums.length < 1) { - throw new IllegalArgumentException("nums should contain at least one element"); - } - - - for (int i = 1; i< nums.length; i++) { - nums[0] ^= nums[i]; - } - return nums[0]; - } -} diff --git a/[137][Single Number II]/src/Solution.java b/[137][Single Number II]/src/Solution.java deleted file mode 100644 index 4b7d150..0000000 --- a/[137][Single Number II]/src/Solution.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Author: - * Date: 2015-06-21 - * Time: 20:35 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - - /** - *
-     * Given an array of integers, every element appears three times except for one.
-     * Find that single one.
-     *
-     * Note:
-     *   - Your algorithm should have a linear runtime complexity.
-     *          Could you implement it without using extra memory?
-     * Ŀ⣺
-     * һ飬ֻһһΣֶ3Σҳһε֣
-     * Ҫʱ临ӶΪO(n)ռ临ӶΪO(1)òĿռ
-     *
-     * ˼·
-     * һȫöƱʾǰ  i th   λֵĺͶ3ȡ࣬
-     * ôֻ 0  1 (⣬3031Ϊ0).  ȡĽ
-     * Ǹ Single Numberһֱӵʵ־ôСΪ 32¼
-     * λϵĺ͡
-     *
-     * ʹ
-     * ones    ithλֻһε
-     * twos    ithλֻδε
-     * threes  ithλֻε
-     * ithλ3ʱǾonestwosĵithλΪ0. յĴ𰸾 ones
-     * 
- * - * @param nums - * @return - */ - public int singleNumber(int[] nums) { - - int[] count = new int[32]; - int result = 0; - - for (int i = 0; i < 32; i++) { - for (int n : nums) { - // ͳƵiλ1ĸ - if (((n >> i) & 1) == 1) { - count[i]++; - } - } - - result |= (count[i] % 3) << i; - } - - return result; - } - - // TODO δȫ - public int singleNumber2(int[] nums) { - // ֻһε - int ones = 0; - // ֻδε - int twos = 0; - // ֻε - int threes; - - for (int n : nums) { - twos |= ones & n; - // 3 1εĽһ - ones ^= n; - // onestwosѳ3ελΪ0ȡ֮1λΪ0 - threes = ones & twos; - - ones &= ~threes; - twos &= ~threes; - } - - return ones; - } -} diff --git a/[138][Copy List With Random Pointer]/src/Main.java b/[138][Copy List With Random Pointer]/src/Main.java deleted file mode 100644 index 85972fb..0000000 --- a/[138][Copy List With Random Pointer]/src/Main.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Author: - * Date: 2015-06-24 - * Time: 09:18 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { - RandomListNode n1 = new RandomListNode(1); - RandomListNode n2 = new RandomListNode(2); - RandomListNode n3 = new RandomListNode(3); - RandomListNode n4 = new RandomListNode(4); - n1.next = n2; - n2.next = n3; - n3.next = n4; - - Solution solution = new Solution(); - RandomListNode copy = solution.copyRandomList(n1); - - print(copy); - - } - - public static void print(RandomListNode head) { - while (head != null) { - System.out.print(head.label + "->"); - head = head.next; - } - - System.out.println("null"); - } -} diff --git a/[138][Copy List With Random Pointer]/src/RandomListNode.java b/[138][Copy List With Random Pointer]/src/RandomListNode.java deleted file mode 100644 index 06bc0eb..0000000 --- a/[138][Copy List With Random Pointer]/src/RandomListNode.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Author: - * Date: 2015-06-24 - * Time: 08:49 - * Declaration: All Rights Reserved !!! - */ -public class RandomListNode { - int label; - RandomListNode next, random; - - RandomListNode(int x) { - this.label = x; - } -} diff --git a/[138][Copy List With Random Pointer]/src/Solution.java b/[138][Copy List With Random Pointer]/src/Solution.java deleted file mode 100644 index 5501ab5..0000000 --- a/[138][Copy List With Random Pointer]/src/Solution.java +++ /dev/null @@ -1,108 +0,0 @@ -/** - * Author: - * Date: 2015-06-24 - * Time: 08:48 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * A linked list is given such that each node contains an additional random
-     * pointer which could point to any node in the list or null.
-     *
-     * Return a deep copy of the list.
-     *
-     * Ŀ⣺
-     * һһָnullĽָ룬
-     *
-     * ˼·
-     * һƽ㣬ƵĽڴƵĽȻһ
-     * ڶָ
-     * ָƺ
-     * 
- * - * @param head - * @return - */ - public RandomListNode copyRandomList(RandomListNode head) { - if (head == null) { - return null; - } - - copyNode(head); - linkRandomPointer(head); - - return splitList(head); - } - - /** - * ƽ㣬ƵĽڴƵĽȻһ - * - * @param head ͷ - */ - public void copyNode(RandomListNode head) { - // ¼ǰҪƵ - RandomListNode node = head; - while (node != null) { - // һµĽ - RandomListNode copyNode = new RandomListNode(node.label); - // 㴮ӵƵĽ󣬲Ȼɵ - copyNode.next = node.next; - node.next = copyNode; - node = copyNode.next; - } - } - - /** - * ָ - * - * @param head ͷ - */ - public void linkRandomPointer(RandomListNode head) { - // ¼ǰҪƵ - RandomListNode node = head; - while (node != null) { - // ָָijĽ - if (node.random != null) { - // nodeƽָ - node.next.random = node.random.next; - } - - // ָһƵĽ - node = node.next.next; - } - } - - /** - * ֣ԭԭװ - * - * @param head ͷ - * @return ͷ - */ - public RandomListNode splitList(RandomListNode head) { - // ͷ - RandomListNode copyHead = head.next; - // ǰıƵĽ - RandomListNode node = head; - // ǰƵĽ - RandomListNode copy; - - while (node != null){ - // ָƽ - copy = node.next; - - // node.nextָһƵĽ - node.next = copy.next; - - // һƵĽ㲻Ϊnull - if (node.next != null) { - // copy.nextָһƵĽ - copy.next = node.next.next; - } - - // nodeָһҪıƽ - node = node.next; - } - return copyHead; - } -} diff --git a/[139][Word Break]/src/Main.java b/[139][Word Break]/src/Main.java deleted file mode 100644 index ad4016f..0000000 --- a/[139][Word Break]/src/Main.java +++ /dev/null @@ -1,50 +0,0 @@ -import java.util.HashSet; -import java.util.Set; - -/** - * Author: - * Date: 2015-06-21 - * Time: 08:48 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { -// test01(); -// test02(); - test03(); - } - - private static void test01() { - Solution solution = new Solution(); - Set set = new HashSet<>(); - set.add("leet"); - set.add("code"); - System.out.println(solution.wordBreak("leetcode", set)); - } - - private static void test02() { - Solution solution = new Solution(); - Set set = new HashSet<>(); - System.out.println(solution.wordBreak("a", set)); - } - - - private static void test03() { - Solution solution = new Solution(); - Set set = new HashSet<>(); -// set.add("b"); - set.add("a"); - set.add("aa"); - set.add("aaa"); - set.add("aaaa"); - set.add("aaaaa"); - set.add("aaaaaa"); - set.add("aaaaaaa"); - set.add("aaaaaaaa"); - set.add("aaaaaaaaa"); - set.add("aaaaaaaaaa"); - System.out.println(solution.wordBreak("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + - "aaaaaaaaaaaaaaaaaaaaaaaaab", set)); - } -} diff --git a/[139][Word Break]/src/Solution.java b/[139][Word Break]/src/Solution.java deleted file mode 100644 index 3bd11d4..0000000 --- a/[139][Word Break]/src/Solution.java +++ /dev/null @@ -1,121 +0,0 @@ -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -/** - * Author: - * Date: 2015-06-21 - * Time: 08:13 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     *
-     * Given a string s and a dictionary of words dict, determine if s can
-     * be segmented into a space-separated sequence of one or more dictionary words.
-     *
-     * For example, given
-     * s = "leetcode",
-     * dict = ["leet", "code"].
-     * Return true because "leetcode" can be segmented as "leet code".
-     *
-     * Ŀ⣺
-     * һַs͵ֵdictȷsǷԷָһʿոָС
-     *
-     * ˼·
-     * һַSijΪNSֵܹ伯ϡdictеĵƴӶɣôҪΪ
-     * F(0, N) = F(0, i) && F(i, j) && F(j, N);
-     * ӣ֪ijӴǷDictеļƴӶɾͿķʽõ
-     * ΪTrue, ΪFalse뵽һbooleanĶӦλϣӣboolean
-     * һλF(0, N)ֵΪTrueʾַSDictеĵƴӣУ
-     * 
- * - * @param s - * @param wordDict - * @return - */ - public boolean wordBreak(String s, Set wordDict) { - // У - if (s == null || s.length() < 1 || wordDict == null || wordDict.size() < 1) { - return false; - } - - // Ƿƥ䣬match[i][0, i-1]ƥ - int length = s.length(); - boolean[] match = new boolean[length + 1]; - match[0] = true; - - for (int i = 1; i < length + 1; i++) { - for (int j = 0; j < i; j++) { - if (match[j] && wordDict.contains(s.substring(j, i))) { - // f(0,n) = f(0,i) + f(i,j) + f(j,n) - match[i] = true; - break; - } - } - } - - - return match[length]; - } - - - // һֽⷨǻᳬʱ - public boolean wordBreak2(String s, Set wordDict) { - - // У - if (s == null || s.length() < 1 || wordDict == null || wordDict.size() < 1) { - return false; - } - - Map> wordMap = new HashMap<>(wordDict.size()); - // пʼַͬĵʷһSet - for (String word : wordDict) { - Set set = wordMap.get(word.charAt(0)); - if (set == null) { - // ´һsetMap - set = new HashSet<>(); - wordMap.put(word.charAt(0), set); - } - // ʴset - set.add(word); - } - - return wordBreak(s, 0, wordMap); - } - - /** - * ַǷԱָɵʴ - * - * @param s ַ - * @param idx Ŀʼλ - * @param wordMap ֵ䣬ʼַͬͬһset - * @return - */ - public boolean wordBreak(String s, int idx, Map> wordMap) { - - if (idx >= s.length()) { - return true; - } - - Set words = wordMap.get(s.charAt(idx)); - - if (words != null) { - for (String word : words) { - // idx֮ǰַѾƥ䣬ide֮ƥword - if (s.startsWith(word, idx)) { - // ݹ鴦 - boolean result = wordBreak(s, idx + word.length(), wordMap); - // true - if (result) { - return true; - } - } - } - } - - return false; - } -} diff --git a/[141][Linked List Cycle]/src/ListNode.java b/[141][Linked List Cycle]/src/ListNode.java deleted file mode 100644 index a9b5f6a..0000000 --- a/[141][Linked List Cycle]/src/ListNode.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 19:17 - * Declaration: All Rights Reserved !!! - */ -public class ListNode { - int val; - ListNode next; - ListNode(int x) { - val = x; - next = null; - } -} diff --git a/[141][Linked List Cycle]/src/Solution.java b/[141][Linked List Cycle]/src/Solution.java deleted file mode 100644 index 1bac274..0000000 --- a/[141][Linked List Cycle]/src/Solution.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 19:16 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Given a linked list, determine if it has a cycle in it.
-     * Follow up:
-     * Can you solve it without using extra space?
-     *
-     * Ŀ
-     * һжǷл
-     *
-     * ˼·
-     * ָ(fast, slow)ʼֵָͷslowÿǰһfastÿǰڻ
-     * fastضȽ뻷slow뻷ָض
-     * 
- * - * @param head - * @return - */ - public boolean hasCycle(ListNode head) { - - ListNode fast = head; - ListNode slow = head; - - while (fast != null && fast.next != null) { - fast = fast.next.next; - slow = slow.next; - if (slow == fast) { - return true; - } - } - - return false; - } - - public boolean hasCycle2(ListNode head) { - - ListNode fast = head; - ListNode slow = head; - - while (fast != null && fast.next != null) { - fast = fast.next.next; - slow = slow.next; - if (slow == fast) { - break; - } - } - - return !(fast == null || fast.next == null); - } -} diff --git a/[142][Linked List Cycle II]/src/ListNode.java b/[142][Linked List Cycle II]/src/ListNode.java deleted file mode 100644 index fba59f9..0000000 --- a/[142][Linked List Cycle II]/src/ListNode.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 19:19 - * Declaration: All Rights Reserved !!! - */ -public class ListNode { - int val; - ListNode next; - ListNode(int x) { - val = x; - next = null; - } -} diff --git a/[142][Linked List Cycle II]/src/Solution.java b/[142][Linked List Cycle II]/src/Solution.java deleted file mode 100644 index 1f0bccc..0000000 --- a/[142][Linked List Cycle II]/src/Solution.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 19:18 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Given a linked list, return the node where the cycle begins. If there is no cycle, return null.
-     * Follow up:
-     * Can you solve it without using extra space?
-     *
-     * Ŀ
-     * һлػڵĵһڵ㣬򷵻null
-     *
-     * ˼·
-     * жǷлʹÿ죨fastָ루slowⷨ141LinkedListCycle
-     * ûлͷnullлfast=slowslowָͷȻָÿͬʱƶһλã
-     * ֱǻڽ㡣
-     * 
- * - * @param head - * @return - */ - public ListNode detectCycle(ListNode head) { - - ListNode fast = head; - ListNode slow = head; - - while (fast != null && fast.next != null) { - fast = fast.next.next; - slow = slow.next; - - if (fast == slow) { - break; - } - } - - if (fast == null || fast.next == null) { - return null; - } - - slow = head; - while (fast != slow) { - fast = fast.next; - slow = slow.next; - } - - return slow; - } -} diff --git a/[143][Reorder List]/src/ListNode.java b/[143][Reorder List]/src/ListNode.java deleted file mode 100644 index 1f6cb21..0000000 --- a/[143][Reorder List]/src/ListNode.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Author: 王俊超 - * Date: 2015-08-21 - * Time: 19:22 - * Declaration: All Rights Reserved !!! - */ -public class ListNode { - int val; - ListNode next; - - ListNode(int x) { - val = x; - } -} diff --git a/[143][Reorder List]/src/Solution.java b/[143][Reorder List]/src/Solution.java deleted file mode 100644 index 8c489cf..0000000 --- a/[143][Reorder List]/src/Solution.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 19:21 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Given a singly linked list L: L0L1Ln-1Ln,
-     * reorder it to: L0LnL1Ln-1L2Ln-2
-     *
-     * You may not modify the values in the list's nodes, only nodes itself may be changed.
-     *
-     * Example 1:
-     *
-     * Given 1->2->3->4, reorder it to 1->4->2->3.
-     * Example 2:
-     *
-     * Given 1->2->3->4->5, reorder it to 1->5->2->4->3.
-     *
-     * ˼·
-     * 1ҵм
-     * 2㣬ͽм֮в֣
-     *
-     * 
- * @param head - */ - public void reorderList(ListNode head) { - if (head == null || head.next == null) { - return; - } - - ListNode root = new ListNode(-1); - root.next = head; - ListNode fast = head; - // мǰ - ListNode slow = root; - - while (fast != null && fast.next != null) { - fast = fast.next.next; - slow = slow.next; - } - - // ˵żڵ - if (fast == null) { - root.next = slow.next; - slow.next = null; - - } else { // - slow = slow.next; - root.next = slow.next; - slow.next = null; - } - - // һҪͷ巨 - fast = root.next; - ListNode tmp; - // 벿 - while (fast.next != null) { - tmp = fast.next; - fast.next = tmp.next; - tmp.next = root.next; - root.next = tmp; - } - - slow = head; - fast = root.next; - - while (fast != null) { - tmp = fast.next; - fast.next = slow.next; - slow.next = fast; - slow = slow.next.next; - fast = tmp; - } - } -} diff --git a/[144][Binary Tree Preorder Traversal]/src/Solution.java b/[144][Binary Tree Preorder Traversal]/src/Solution.java deleted file mode 100644 index ee6e425..0000000 --- a/[144][Binary Tree Preorder Traversal]/src/Solution.java +++ /dev/null @@ -1,34 +0,0 @@ -import java.util.Deque; -import java.util.LinkedList; -import java.util.List; - -/** - * Author: - * Date: 2015-08-19 - * Time: 06:44 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - public List preorderTraversal(TreeNode root) { - List result = new LinkedList<>(); - - if (root != null) { - Deque stack = new LinkedList<>(); - stack.add(root); - - while (!stack.isEmpty()) { - TreeNode node = stack.removeLast(); - result.add(node.val); - - if (node.right != null) { - stack.add(node.right); - } - if (node.left != null) { - stack.add(node.left); - } - } - } - - return result; - } -} diff --git a/[144][Binary Tree Preorder Traversal]/src/TreeNode.java b/[144][Binary Tree Preorder Traversal]/src/TreeNode.java deleted file mode 100644 index 9aec4dd..0000000 --- a/[144][Binary Tree Preorder Traversal]/src/TreeNode.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Author: - * Date: 2015-08-19 - * Time: 06:45 - * Declaration: All Rights Reserved !!! - */ -public class TreeNode { - int val; - TreeNode left; - TreeNode right; - - TreeNode(int x) { - val = x; - } -} diff --git a/[145][Binary Tree Postorder Traversal]/src/Solution.java b/[145][Binary Tree Postorder Traversal]/src/Solution.java deleted file mode 100644 index 2adec07..0000000 --- a/[145][Binary Tree Postorder Traversal]/src/Solution.java +++ /dev/null @@ -1,93 +0,0 @@ -import java.util.Deque; -import java.util.LinkedList; -import java.util.List; - -/** - * Author: - * Date: 2015-06-22 - * Time: 14:54 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Given a binary tree, return the postorder traversal of its nodes' values.
-     *
-     * For example:
-     * Given binary tree {1,#,2,3},
-     *      1
-     *       \
-     *        2
-     *       /
-     *      3
-     * return [3,2,1].
-     *
-     * Note: Recursive solution is trivial, could you do it iteratively?
-     *
-     * Ŀ⣺
-     * һŶĺĽֵ
-     *
-     * ע⣺
-     *   - ݹⷨף볢ʽ
-     *
-     * ˼·
-     * ǵݹ
-     * ݺ˳ȷٷʸڵ㣬ÿ˵
-     * ְͬķ˳бķǵݹʵ˵ҪһЩҪ֤
-     * ʺܷʣ˼·£
-     *
-     * һڵP
-     * 1ȽڵPջ
-     * 2PӺҺӣPӻҺӣҺѾ
-     *      ֱڵPջջڵPΪһĽڵ㣬ٽʱ
-     *      ջΪǰڵ㣻
-     * 32еPҺӺջǰڵΪջ㣬
-     *      ֮ظ2
-     * 4ֱջգ
-     * 
- * - * @param root - * @return - */ - public List postorderTraversal(TreeNode root) { - List list = new LinkedList<>(); - - if (root != null) { - // ˫˶Уջʹ - Deque deque = new LinkedList<>(); - // ָǰһĽ - TreeNode prev = null; - // ָǰĽ - TreeNode curr; - // ջ - deque.addLast(root); - // ջǿ - while (!deque.isEmpty()) { - // ȡջԪأɾ - curr = deque.getLast(); - if ((curr.left == null && curr.right == null) // ǰԪ - // prev != null && curr.left == prevǰֻѾ - // prev != null && curr.right == prevǰѾ - || (prev != null && (curr.left == prev || curr.right == prev))) { - // ɾջԪ - curr = deque.removeLast(); - // ֵջ - list.add(curr.val); - // һĽ - prev = curr; - } else { - - // δ꣬ǿջ - if (curr.right != null) { - deque.addLast(curr.right); - } - if (curr.left != null) { - deque.addLast(curr.left); - } - } - } - } - - return list; - } -} diff --git a/[145][Binary Tree Postorder Traversal]/src/TreeNode.java b/[145][Binary Tree Postorder Traversal]/src/TreeNode.java deleted file mode 100644 index 958278e..0000000 --- a/[145][Binary Tree Postorder Traversal]/src/TreeNode.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Author: - * Date: 2015-06-22 - * Time: 14:54 - * Declaration: All Rights Reserved !!! - */ -public class TreeNode { - int val; - TreeNode left; - TreeNode right; - - TreeNode(int x) { - val = x; - } -} diff --git a/[146][LRU Cache]/src/LRUCache.java b/[146][LRU Cache]/src/LRUCache.java deleted file mode 100644 index 3d26ca7..0000000 --- a/[146][LRU Cache]/src/LRUCache.java +++ /dev/null @@ -1,69 +0,0 @@ -import java.util.LinkedHashMap; -import java.util.Map; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-17 17:34 - **/ -public class LRUCache extends LinkedHashMap { - /** - *
-     * Design and implement a data structure for Least Recently Used (LRU) cache.
-     * It should support the following operations: get and put.
-     *
-     * get(key) - Get the value (will always be positive) of the key if the key exists
-     * in the cache, otherwise return -1.
-     * put(key, value) - Set or insert the value if the key is not already present. When
-     * the cache reached its capacity, it should invalidate the least recently used item
-     * before inserting a new item.
-     *
-     * The cache is initialized with a positive capacity.
-     *
-     * Follow up:
-     * Could you do both operations in O(1) time complexity?
-     *
-     * Example:
-     *
-     * LRUCache cache = new LRUCache( 2  );// capacity
-     *
-     * cache.put(1,1);
-     * cache.put(2,2);
-     * cache.get(1);       // returns 1
-     * cache.put(3,3);    // evicts key 2
-     * cache.get(2);       // returns -1 (not found)
-     * cache.put(4,4);    // evicts key 1
-     * cache.get(1);       // returns -1 (not found)
-     * cache.get(3);       // returns 3
-     * cache.get(4);       // returns 4
-     * 
- * - * @param capacity - */ - - private int capacity; - - - public LRUCache(int capacity) { - super(capacity, 0.75F, true); - this.capacity = capacity; - } - - public int get(int key) { - Integer value = super.get(key); - if (value == null) { - return -1; - } else { - return value; - } - } - - public void put(int key, int value) { - super.put(key, value); - } - - - @Override - protected boolean removeEldestEntry(Map.Entry eldest) { - return size() > capacity; - } -} diff --git a/[146][LRU Cache]/src/Main.java b/[146][LRU Cache]/src/Main.java deleted file mode 100644 index 61644cc..0000000 --- a/[146][LRU Cache]/src/Main.java +++ /dev/null @@ -1,26 +0,0 @@ -import org.junit.Assert; -import org.junit.Test; - -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-17 17:41 - **/ -public class Main { - - @Test - public void test1() { - LRUCache cache = new LRUCache(2); - - cache.put(1, 1); - cache.put(2, 2); - cache.get(1); // returns 1 - cache.put(3, 3); // evicts key 2 - cache.get(2); // returns -1 (not found) - Assert.assertEquals(-1, cache.get(2)); - cache.put(4, 4); // evicts key 1 - cache.get(1); // returns -1 (not found) - Assert.assertEquals(-1, cache.get(1)); - cache.get(3); // returns 3 - cache.get(4); // returns 4 - } -} diff --git a/[147][Insertion Sort List]/src/ListNode.java b/[147][Insertion Sort List]/src/ListNode.java deleted file mode 100644 index 0c7f1c1..0000000 --- a/[147][Insertion Sort List]/src/ListNode.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 19:24 - * Declaration: All Rights Reserved !!! - */ -public class ListNode { - int val; - ListNode next; - - ListNode(int v) { - val = v; - } -} diff --git a/[147][Insertion Sort List]/src/Solution.java b/[147][Insertion Sort List]/src/Solution.java deleted file mode 100644 index 14a4280..0000000 --- a/[147][Insertion Sort List]/src/Solution.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 19:23 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * ԭ
-     * Sort a linked list using insertion sort.
-     *
-     * Ŀ
-     * һв
-     *
-     * ˼·
-     * ʹһָpָδźĵһ㣬õIJҵҵһڵqǰ㣬
-     * pӦĽ뵽ȷλãpָδźĵһ㡣ֱá
-     * 
- * - * @param head - * @return - */ - public ListNode insertionSortList(ListNode head) { - - ListNode root = new ListNode(0); // ͷ - root.next = head; - ListNode p = head; - ListNode q; - ListNode r; - - while (p != null && p.next != null) { - if (p.val <= p.next.val) { - p = p.next; - } else { - q = p.next; - p.next = q.next; - - r = root; - // ҵһڵq.valǰ㣬Ϊroot.nextp֮ضĽ - while (r.next.val <= q.val) { - r = r.next; - } - - q.next = r.next; - r.next = q; - } - } - - return root.next; - } -} diff --git a/[148][Sort List]/src/ListNode.java b/[148][Sort List]/src/ListNode.java deleted file mode 100644 index 0c7f1c1..0000000 --- a/[148][Sort List]/src/ListNode.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 19:24 - * Declaration: All Rights Reserved !!! - */ -public class ListNode { - int val; - ListNode next; - - ListNode(int v) { - val = v; - } -} diff --git a/[148][Sort List]/src/Solution.java b/[148][Sort List]/src/Solution.java deleted file mode 100644 index 7cbd141..0000000 --- a/[148][Sort List]/src/Solution.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2019-06-19 14:28 - **/ -public class Solution { - /** - *
-     * Sort a linked list in O(n log n) time using constant space complexity.
-     *
-     * Example 1:
-     *
-     * Input: 4->2->1->3
-     * Output: 1->2->3->4
-     * Example 2:
-     *
-     * Input: -1->5->3->4->0
-     * Output: -1->0->3->4->5
-     *
-     * 使用链表的归并排序可以解决
-     * 
- * - * @param head - * @return - */ - public ListNode sortList(ListNode head) { - - if (head == null || head.next == null) { - return head; - } - return mergeSort(head); - } - - private ListNode mergeSort(ListNode head) { - - if (head == null || head.next == null) { - return head; - } - - ListNode p = head; - ListNode q = head; - // 记录前驱 - ListNode r = null; - - // 将链表分害割成两半 - while (p != null && p.next != null) { - p = p.next.next; - r = q; - q = q.next; - } - - r.next = null; - - // 两个链接分别进行排序 - ListNode h1 = mergeSort(head); - ListNode h2 = mergeSort(q); - - return merge(h1, h2); - } - - private ListNode merge(ListNode l1, ListNode l2) { - - ListNode head = new ListNode(0); - ListNode p = head; - while (l1 != null && l2 != null) { - if (l1.val <= l2.val) { - p.next = l1; - l1 = l1.next; - } else { - p.next = l2; - l2 = l2.next; - } - - p = p.next; - } - - if (l1 != null) { - p.next = l1; - } else { - p.next = l2; - } - - return head.next; - } -} diff --git a/[150][Evaluate Reverse Polish Notation]/src/Main.java b/[150][Evaluate Reverse Polish Notation]/src/Main.java deleted file mode 100644 index f6672ab..0000000 --- a/[150][Evaluate Reverse Polish Notation]/src/Main.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Author: - * Date: 2015-06-20 - * Time: 07:14 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { - Solution solution = new Solution(); - System.out.println(solution.evalRPN(new String[]{"0","3","/"})); - } -} diff --git a/[150][Evaluate Reverse Polish Notation]/src/Solution.java b/[150][Evaluate Reverse Polish Notation]/src/Solution.java deleted file mode 100644 index 499adc9..0000000 --- a/[150][Evaluate Reverse Polish Notation]/src/Solution.java +++ /dev/null @@ -1,75 +0,0 @@ -import java.util.Queue; -import java.util.Stack; - -/** - * Author: - * Date: 2015-06-20 - * Time: 06:58 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Evaluate the value of an arithmetic expression in Reverse Polish Notation.
-     * Valid operators are +, -, *, /. Each operand may be an integer or another expression.
-     *
-     * Some examples:
-     * ["2", "1", "+", "3", "*"] -> ((2 + 1) * 3) -> 9
-     * ["4", "13", "5", "/", "+"] -> (4 + (13 / 5)) -> 6
-     *
-     * Ŀ⣺
-     * 沨ʽֵЧǣ+-*/ÿҪôһҪôһʽ
-     *
-     * ˼·
-     * ʹջв
-     * 
- * - * @param tokens - * @return - */ - public int evalRPN(String[] tokens) { - // У - if (tokens == null || tokens.length < 1) { - throw new IllegalArgumentException(); - } - - int op1; - int op2; - // ջ - Stack stack = new Stack<>(); - - for (String token : tokens) { - // ˵ҪȡջԪؽ - if ("+".equals(token) || "-".equals(token) || "*".equals(token) || "/".equals(token)) { - // ȡջԪ - op2 = stack.pop(); - op1 = stack.pop(); - - // - switch (token.charAt(0)) { - case '+': - op1 += op2; - break; - case '-': - op1 -= op2; - break; - case '*': - op1 *= op2; - break; - case '/': - op1 /= op2; - break; - } - // ջ - stack.push(op1); - } - // ˵Dzջ - else { - stack.push(Integer.parseInt(token)); - } - } - - // ջֻʣһԪأǾĽ - return stack.pop(); - } -} diff --git a/[151][Reverse Words In A String]/src/Main.java b/[151][Reverse Words In A String]/src/Main.java deleted file mode 100644 index 8b507c4..0000000 --- a/[151][Reverse Words In A String]/src/Main.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Author: - * Date: 2015-06-20 - * Time: 09:50 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { - Solution solution = new Solution(); -// System.out.println("|" +solution.reverseWords(" ") + "|"); - -// char[] array = " a b ".toCharArray(); -// int len = solution.compressWhiteSpace(array); -// System.out.println("|" + new String(array, 0, len) + "|"); - -// System.out.println(solution.reverseWords("")); -// System.out.println(solution.reverseWords(" a ")); -// System.out.println(solution.reverseWords(" ")); -// System.out.println(solution.reverseWords(" a b ")); - System.out.println(solution.reverseWords(" a b c d e ")); - System.out.println(solution.reverseWords("a b c d e")); - System.out.println(solution.reverseWords("abcdef")); - - } - -} diff --git a/[151][Reverse Words In A String]/src/Solution.java b/[151][Reverse Words In A String]/src/Solution.java deleted file mode 100644 index e888c33..0000000 --- a/[151][Reverse Words In A String]/src/Solution.java +++ /dev/null @@ -1,141 +0,0 @@ -/** - * Author: - * Date: 2015-06-20 - * Time: 09:28 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Given an input string, reverse the string word by word.
-     *
-     * For example,
-     * Given s = "the sky is blue",
-     * return "blue is sky the".
-     *
-     * Ŀ⣺
-     * һַ䷴תִʲת
-     *
-     * ˼·
-     * ȶַתٽÿʽзת
-     * 
- * - * @param s - * @return - */ - public String reverseWords(String s) { - - if (s == null) { - return null; - } - - char[] chars = s.toCharArray(); - // ַѹ - int realLength = compressWhiteSpace(chars); - - // ַ - swapRange(chars, 0, realLength - 1); - - // ¼ʵ - int start = 0; - // ¼ʵյ - int end; - - while (start < realLength) { - // startλÿʼҵһǿհַ - while (start < realLength && chars[start] == ' ') { - start++; - } - - end = start + 1; - // ҵһհַ - while (end < realLength && chars[end] != ' ') { - end++; - } - - // תַ - swapRange(chars, start, end - 1); - // ¼µĿʼλ - start = end; - } - return new String(chars, 0, realLength); - } - - /** - * ַĵĿհַѹ - * - * @param chars ַ - * @return µij - */ - public int compressWhiteSpace(char[] chars) { - - if (chars == null || chars.length == 0) { - return 0; - } - - // ַλ - int pos = 0; - for (int i = 0; i < chars.length; i++) { - // iλÿʼҵһǿհַ - while (i < chars.length && chars[i] == ' ') { - i++; - } - - // Ѿ - if (i >= chars.length) { - break; - } - - // iλÿʼǿհֱַհַ - // Ǵһ - while (i < chars.length && chars[i] != ' ') { - chars[pos] = chars[i]; - pos++; - i++; - } - - // һҪһһʲжһA - if (pos < chars.length) { - // ո - chars[pos] = ' '; - } - - pos++; - } - - // ˵ַֻпհַ - if (pos == 0) { - return 0; - } else { - // һҪȥһո񣬼A - return pos - 1; - } - - } - - /** - * ת[x, y]λõַ - * - * @param chars ַ - * @param x xλ - * @param y yλ - */ - public void swapRange(char[] chars, int x, int y) { - for (; x < y; x++, y--) { - swap(chars, x, y); - } - } - - /** - * x,yλõĵ - * - * @param chars ַ - * @param x xλ - * @param y yλ - */ - public void swap(char[] chars, int x, int y) { - char z = chars[x]; - chars[x] = chars[y]; - chars[y] = z; - } -} diff --git a/[152][Maximum Product Subarray]/src/Main.java b/[152][Maximum Product Subarray]/src/Main.java deleted file mode 100644 index e1f42c9..0000000 --- a/[152][Maximum Product Subarray]/src/Main.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Author: - * Date: 2015-06-19 - * Time: 21:12 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { - Solution solution = new Solution(); - System.out.println(solution.maxProduct(new int[]{3, -1, 4})); - } -} diff --git a/[152][Maximum Product Subarray]/src/Solution.java b/[152][Maximum Product Subarray]/src/Solution.java deleted file mode 100644 index fb11c8f..0000000 --- a/[152][Maximum Product Subarray]/src/Solution.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Author: - * Date: 2015-06-19 - * Time: 20:52 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Find the contiguous subarray within an array (containing at least one number)
-     * which has the largest product.
-     *
-     * For example, given the array [2,3,-2,4],
-     *
-     * the contiguous subarray [2,3] has the largest product = 6.
-     *
-     * Ŀ⣺
-     * 飨ٰһ֣ҳһ飬ij˻
-     *
-     * ˼·
-     * 򵥶̬滮
-     *
-     * ƹʽ
-     * Product SubarrayҪǵһ͸ˣ
-     * ǰõһСĸͺһϴĸˣõķһϴ{2-3-7}
-     * ԣڴ˷ʱ򣬳ҪάһֲֵͬʱҪάһֲСֵ
-     *
-     * n<1˵дn0ʱ
-     * Fmax(0)=num[0]
-     * Fmin(0)=num[0]
-     *
-     * Fmax(n+1) = MAX(MAX(num[n+1]*Fmax(n), num[n+1]), num[n+1]*Fmin(n)) // ֵ
-     * Fmin(n+1) = MIN(MIN(num[n+1]*Fmax(n), num[n+1]), num[n+1]*Fmin(n)) // СֵΪһ¼׼
-     * 
- * - * @param nums - * @return - */ - public int maxProduct(int[] nums) { - - if (nums == null || nums.length < 1) { - throw new IllegalArgumentException(); - } - - if (nums.length == 1) { - return nums[0]; - } - - int result = nums[0]; - int fmax = nums[0]; - int fmin = nums[0]; - int prevMax; - - for (int i = 1; i < nums.length; i++) { - prevMax = fmax; - fmax = Math.max(Math.max(nums[i] * prevMax, nums[i]), nums[i] * fmin); - fmin = Math.min(Math.min(nums[i] * prevMax, nums[i]), nums[i] * fmin); - result = Math.max(result, fmax); - } - - return result; - } -} diff --git a/[153][Find Minimum In Rotated Sorted Array]/src/Main.java b/[153][Find Minimum In Rotated Sorted Array]/src/Main.java deleted file mode 100644 index 07cf2bf..0000000 --- a/[153][Find Minimum In Rotated Sorted Array]/src/Main.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Author: - * Date: 2015-06-19 - * Time: 20:30 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { - Solution solution = new Solution(); - System.out.println(solution.findMin(new int[]{9, 1, 2, 3, 4, 5, 6, 7, 8})); - System.out.println(solution.findMin(new int[]{2, 3, 1})); - System.out.println(solution.findMin(new int[]{3, 1, 2})); - } -} diff --git a/[153][Find Minimum In Rotated Sorted Array]/src/Solution.java b/[153][Find Minimum In Rotated Sorted Array]/src/Solution.java deleted file mode 100644 index 8a028d6..0000000 --- a/[153][Find Minimum In Rotated Sorted Array]/src/Solution.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Author: - * Date: 2015-06-19 - * Time: 20:12 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Suppose a sorted array is rotated at some pivot unknown to you beforehand.
-     * (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).
-     * Find the minimum element.
-     * You may assume no duplicate exists in the array.
-     *
-     * Ŀ⣺
-     * һδ֪ijת
-     * 0 1 2 4 5 6 7ܳΪ4 5 6 7 0 1 2
-     *
-     * ҵСԪء
-     * Լ費ظС
-     *
-     * Կ˼·
-     * ΪIJ֣ǰһֺͺһֲǰһ򲿷ԪضȺһԪش
-     * ֻҪҵһԪرǰһҪҵԪ
-     * 
- * - * @param nums - * @return - */ - public int findMin(int[] nums) { - // - if (nums == null || nums.length < 0) { - throw new IllegalArgumentException(); - } - - return binarySearch(nums, 0, nums.length - 1); - } - - public int binarySearch(int[] nums, int start, int end) { - - int mid = 0; - - while (start < end) { - mid = start + ((end - start) >> 1); -// System.out.println(mid + " " + nums[mid]); - // һǰСҵ - if (nums[mid] > nums[mid + 1]) { - return nums[mid + 1]; - } - // ˵мֵڵһ - else if (nums[mid] > nums[start]) { - // ȡmid+1пnum[mid]ǵһеһԪ - start = mid; - } - // ˵мֵڵڶ - else { - // ȡmid-1пnum[mid]ǵڶеĵһԪ - end = mid; - } - } - - // ˵ - return nums[0]; - } -} diff --git a/[154][Find Minimum In Rotated Sorted Array II]/src/Main.java b/[154][Find Minimum In Rotated Sorted Array II]/src/Main.java deleted file mode 100644 index bd05084..0000000 --- a/[154][Find Minimum In Rotated Sorted Array II]/src/Main.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Author: - * Date: 2015-06-21 - * Time: 16:08 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { - Solution solution = new Solution(); - System.out.println(solution.findMin(new int[]{1, 3, 3})); - } -} diff --git a/[154][Find Minimum In Rotated Sorted Array II]/src/Solution.java b/[154][Find Minimum In Rotated Sorted Array II]/src/Solution.java deleted file mode 100644 index 5efb112..0000000 --- a/[154][Find Minimum In Rotated Sorted Array II]/src/Solution.java +++ /dev/null @@ -1,92 +0,0 @@ -/** - * Author: - * Date: 2015-06-21 - * Time: 15:21 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - - - /** - *
-     * Follow up for "Find Minimum in Rotated Sorted Array":
-     * What if duplicates are allowed?
-     * Would this affect the run-time complexity? How and why?
-     * Suppose a sorted array is rotated at some pivot unknown to you beforehand.
-     *
-     *
-     * (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).
-     * Find the minimum element.
-     * The array may contain duplicates.
-     *
-     * Ŀ⣺
-     * תСֵĺظԪأȻֲ
-     *
-     * ˼·
-     * 㷨в
-     *
-     * 
- * - * @param nums - * @return - */ - public int findMin(int[] nums) { - // У - if (nums == null || nums.length < 1) { - throw new IllegalArgumentException(); - } - - int lo = 0; - int hi = nums.length - 1; - int mid = 0; - - // ųȫ - while (nums[lo] >= nums[hi]) { - - // ֻԪأغһ - if (hi - lo == 1) { - mid = hi; - break; - } - - mid = lo + ((hi - lo) >> 1); - - if (nums[mid] == nums[lo] && nums[mid] == nums[hi]) { - // ֻܲ˳ܲlo++hi--ķʽ - // Ϊloǰһһ - // hiҲǺһĵһ - return sequenceSearch(nums, lo, hi); - } - - // midǰһ - if (nums[mid] >= nums[lo]) { - lo = mid; - } - // midںһ - else if (nums[mid] <= nums[hi]) { - hi = mid; - } - - } - - - return nums[mid]; - } - - /** - * ˳еСֵnums鰴ijת - * - * @param nums - * @param start ʼλ - * @param end λ - * @return Сֵ - */ - public int sequenceSearch(int[] nums, int start, int end) { - for (int i = start; i < end; i++) { - if (nums[i] > nums[i + 1]) { - return nums[i + 1]; - } - } - return nums[start]; - } -} diff --git a/[155][Min Stack]/src/MinStack.java b/[155][Min Stack]/src/MinStack.java deleted file mode 100644 index 5587b2f..0000000 --- a/[155][Min Stack]/src/MinStack.java +++ /dev/null @@ -1,89 +0,0 @@ -/** - * Author: - * Date: 2015-08-21 - * Time: 19:25 - * Declaration: All Rights Reserved !!! - */ -public class MinStack { - private final static int DEFAULT_SIZE = 1000; - private int[] stack; - private int[] minIndex; // ڱǰnݵջСԪص± - private int min = Integer.MAX_VALUE; // ڼ¼еС - private int index = -1; // ¼СԪstackеλ - private int current = -1; - - /** - *
-     * ԭ
-     * Design a stack that supports push, pop, top, and retrieving
-     * the minimum element in constant time.
-     * push(x) C Push element x onto stack.
-     * pop() C Removes the element on top of the stack.
-     * top() C Get the top element.
-     * getMin() C Retrieve the minimum element in the stack.
-     *
-     * Ŀ
-     * һջ֧pushpoptopͲСԪزʱ䣩
-     *
-     * ˼·
-     * ʹһջջеСԪء
-     * 
- */ - public MinStack() { - stack = new int[DEFAULT_SIZE]; - minIndex = new int[DEFAULT_SIZE]; - } - - public MinStack(int size) { - stack = new int[size]; - minIndex = new int[size]; - } - - public void push(int x) { - current++; // ƶҪλ - - if (current >= stack.length) { // - int[] tmp = new int[current * 2]; - System.arraycopy(stack, 0, tmp, 0, stack.length); - stack = tmp; - - tmp = new int[current * 2]; - System.arraycopy(minIndex, 0, tmp, 0, minIndex.length); - minIndex = tmp; - } - - stack[current] = x; // - - if (x < min) { // Сֵ - min = x; - index = current; // ¼[0, current]СԪ±index - } - - minIndex[current] = index; - } - - public void pop() { - current--; - if (current >= 0) { - min = stack[minIndex[current]]; // ջеСֵ - index = minIndex[current]; // Сֵ - } - } - - public int top() { - - if (current < 0) { - throw new RuntimeException("No more data"); - } - - return stack[current]; - } - - public int getMin() { - if (current < 0) { - throw new RuntimeException("No more data"); - } - - return stack[minIndex[current]]; - } -} diff --git a/[162][Find Peak Element]/src/Solution.java b/[162][Find Peak Element]/src/Solution.java deleted file mode 100644 index ad5b5f3..0000000 --- a/[162][Find Peak Element]/src/Solution.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Author: - * Date: 2015-06-19 - * Time: 17:30 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * A peak element is an element that is greater than its neighbors.
-     *
-     * Given an input array where num[i]  num[i+1], find a peak element and return its index.
-     *
-     * The array may contain multiple peaks, in that case return the index to any one of the peaks is fine.
-     *
-     * You may imagine that num[-1] = num[n] = -.
-     *
-     * For example, in array [1, 2, 3, 1], 3 is a peak element and your function should return
-     * the index number 2.
-     *
-     * Note:
-     * Your solution should be in logarithmic complexity.
-     *
-     * Ŀ⣺
-     * ֵԪءֵָھӵԪ
-     *
-     * һnum[i]  num[i+1]ҵһֵԪز±ꡣ
-     *
-     * ֵܰ·һɡ
-     *
-     * Լnum[-1] = num[n] = -ޣʼԪصĩβԪصҲΪ
-     *
-     * 磬[1, 2, 3, 1]У3ǷֵԪأĺӦ÷±2
-     *
-     * ע⣺
-     * ΪӶȡ
-     * 
- * - * @param nums - * @return - */ - public int findPeakElement(int[] nums) { - return 0; - } - -} diff --git a/[167][Two Sum II - Input array is sorted]/src/Solution.java b/[167][Two Sum II - Input array is sorted]/src/Solution.java deleted file mode 100644 index 74f81cc..0000000 --- a/[167][Two Sum II - Input array is sorted]/src/Solution.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-09-28 16:17 - **/ -public class Solution { - /** - * 如果数组很大,target很小,可以考虑先用二分查找法找到不大于target元素的下标,再作处理 - * @param numbers - * @param target - * @return - */ - public int[] twoSum(int[] numbers, int target) { -// int idx = search(numbers, target); - int idx = numbers.length - 1; - return twoSum(numbers, target, idx); - } - - public int[] twoSum(int[] numbers, int target, int end) { - int[] result = {0, 0}; - - int lo = 0; - int hi = end; - - while (lo < hi) { - if (numbers[lo] + numbers[hi] == target) { - result[0] = lo; - result[1] = hi; - break; - } else if (numbers[lo] + numbers[hi] > target) { - hi--; - } else { - lo++; - } - } - - return result; - } - - public int search(int[] numbers, int target) { - - int lo = 0; - int hi = numbers.length - 1; - int mid; - - while (lo <= hi) { - mid = lo + (hi - lo) / 2; - if (numbers[mid] == target) { - return mid; - } else if (numbers[mid] > target) { - hi = mid - 1; - } else { - lo = mid + 1; - } - - } - return hi; - } -} diff --git a/[191][Number Of 1 Bits]/src/Main.java b/[191][Number Of 1 Bits]/src/Main.java deleted file mode 100644 index 4a645e8..0000000 --- a/[191][Number Of 1 Bits]/src/Main.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Author: - * Date: 2015-06-18 - * Time: 09:17 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { - Solution solution = new Solution(); - System.out.println(solution.hammingWeight(0B11111111_01010101)); - } -} diff --git a/[191][Number Of 1 Bits]/src/Solution.java b/[191][Number Of 1 Bits]/src/Solution.java deleted file mode 100644 index 5b782f6..0000000 --- a/[191][Number Of 1 Bits]/src/Solution.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Author: - * Date: 2015-06-17 - * Time: 21:51 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - * Write a function that takes an unsigned integer and returns the number of 1' bits it has - * (also known as the Hamming weight). - * - * For example, the 32-bit integer 11' has binary representation 00000000000000000000000000001011, - * so the function should return 3. - * - * еλ - * - * @param n - * @return - */ - // you need to treat n as an unsigned value - public int hammingWeight(int n) { - - int count = 0; - while (n != 0) { - count++; - n = (n - 1) & n; - } - return count; - } -} diff --git a/[198][House Robber]/src/Main.java b/[198][House Robber]/src/Main.java deleted file mode 100644 index 1904d36..0000000 --- a/[198][House Robber]/src/Main.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Author: - * Date: 2015-06-18 - * Time: 09:17 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { - Solution solution = new Solution(); - System.out.println(solution.rob(new int[]{1, 2, 3, 4, 5, 6, 6, 10, 7, 8, 9})); - } -} diff --git a/[198][House Robber]/src/Solution.java b/[198][House Robber]/src/Solution.java deleted file mode 100644 index 48d3efa..0000000 --- a/[198][House Robber]/src/Solution.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Author: - * Date: 2015-06-17 - * Time: 22:00 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - * You are a professional robber planning to rob houses along a street. Each house has a - * certain amount of money stashed, the only constraint stopping you from robbing each - * of them is that adjacent houses have security system connected and it will automatically - * contact the police if two adjacent houses were broken into on the same night. - *

- * Given a list of non-negative integers representing the amount of money of each house, - * determine the maximum amount of money you can rob tonight without alerting the police. - *

- * Ŀ⣺һרҵǿƻһִҽᡣÿ䷿ݶһĽǮΨһֹ - * ٵԼǣڷ֮аȫϵͳͬһڵķݱ룬Ǿͻ - * 羯죬˲Դڵķݡ - *

- * һзǸÿ䷿ݵĽǮڲǰһԴٵĽǮ - * ˼·̬滮Dynamic Programming - * ״̬תƷ̣dp[i] = max(dp[i - 2], dp[i - 3]) + num[i] A - * Уdp[i]ʾٵi䷿ʱۼȡõĽǮֵ - * ( i λõ max ֵ max(i-2, i-3) i λõֵԴ) - * - * @param nums - * @return - */ - public int rob(int[] nums) { - - if (nums == null || nums.length == 0) { - return 0; - } - - // еԪظ2ڡAʽi=2dp[2-3] - if (nums.length > 2) { - nums[2] += nums[0]; - } - - // ӵĸԪؿʼ - int i = 3; - for (; i < nums.length; i++) { - // iԪصֵ - nums[i] += Math.max(nums[i - 2], nums[i - 3]); - } - - // ֻһԪأԪֵ - if (nums.length == 1) { - return nums[0]; - } - // Ԫطнϴֵ - else if (nums.length == 2) { - return Math.max(nums[0], nums[1]); - } - // Ԫأֵĩβ֮䣬ķ - else { - return Math.max(nums[i - 1], nums[i - 2]); - } - } -} diff --git a/[199][Binary Tree Right Side View]/src/Solution.java b/[199][Binary Tree Right Side View]/src/Solution.java deleted file mode 100644 index c591727..0000000 --- a/[199][Binary Tree Right Side View]/src/Solution.java +++ /dev/null @@ -1,77 +0,0 @@ -import java.util.Deque; -import java.util.LinkedList; -import java.util.List; - -/** - * Author: - * Date: 2015-06-20 - * Time: 12:18 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *

-     * Given a binary tree, imagine yourself standing on the right side of it,
-     * return the values of the nodes you can see ordered from top to bottom.
-     *
-     * For example:
-     * Given the following binary tree,
-     *      1            <---
-     *    /   \
-     *   2     3         <---
-     *    \     \
-     *     5     4       <---
-     * You should return [1, 3, 4].
-     *
-     *  Ŀ⣺
-     *  һԼվұߣشµܿĽڵֵ
-     *
-     * ˼·
-     * IJαÿ㰴մҵ˳ηʽڵ㣬ÿһȡұߵĽ㣩
-     * 
- * - * @param root - * @return - */ - public List rightSideView(TreeNode root) { - List result = new LinkedList<>(); - - if (root != null) { - Deque deque = new LinkedList<>(); - // ǰĽ - int current = 1; - // һĽ - int next = 0; - TreeNode node; - deque.addLast(root); - while (deque.size() > 0) { - // ȡһ - node = deque.removeFirst(); - current--; - - // ӷǿյ - if (node.left != null) { - next++; - deque.addLast(node.left); - } - - // ӷǿյҽ - if (node.right != null) { - next++; - deque.addLast(node.right); - } - - // ǰѾ - if (current == 0) { - // ˲һֵ - result.add(node.val); - // һԪظ - current = next; - next = 0; - } - } - } - - return result; - } -} diff --git a/[199][Binary Tree Right Side View]/src/TreeNode.java b/[199][Binary Tree Right Side View]/src/TreeNode.java deleted file mode 100644 index 35a2b83..0000000 --- a/[199][Binary Tree Right Side View]/src/TreeNode.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Author: - * Date: 2015-06-20 - * Time: 12:18 - * Declaration: All Rights Reserved !!! - */ -public class TreeNode { - int val; - TreeNode left; - TreeNode right; - - TreeNode(int x) { - val = x; - } -} diff --git a/[200][Number Of Islands]/src/Solution.java b/[200][Number Of Islands]/src/Solution.java deleted file mode 100644 index 47991f4..0000000 --- a/[200][Number Of Islands]/src/Solution.java +++ /dev/null @@ -1,89 +0,0 @@ -/** - * Author: - * Date: 2015-06-20 - * Time: 11:00 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Given a 2d grid map of '1's (land) and '0's (water), count the number of islands.
-     * An island is surrounded by water and is formed by connecting adjacent lands horizontally
-     * or vertically. You may assume all four edges of the grid are all surrounded by water.
-     *
-     * Example 1:
-     *      11110
-     *      11010
-     *      11000
-     *      00000
-     * Answer: 1
-     *
-     * Example 2:
-     *      11000
-     *      11000
-     *      00100
-     *      00011
-     * Answer: 3
-     *
-     * Ŀ⣺
-     * һάĵͼ'1'½أ0ˮ滷ˮ
-     * ڵ½ˮƽֱӶγɵġԼĸ߶ˮΧ
-     *
-     * ˼·
-     * һһӦķʱǾ󣬶ÿԪʱйȱȱͳƵĿ
-     *
-     * 
- * - * @param grid - * @return - */ - public int numIslands(char[][] grid) { - // У - if (grid == null || grid.length == 0 || grid[0].length == 0) { - return 0; - } - - // ԪĬֵfalse - boolean[][] visited = new boolean[grid.length][grid[0].length]; - - int result = 0; - for (int i = 0; i < grid.length; i++) { - for (int j = 0; j < grid[0].length; j++) { - // λûбʹҴλǵ¹ȱ - if (!visited[i][j] && grid[i][j] == '1') { - result++; - bfs(grid, visited, i, j); - } - } - } - return result; - } - - /** - * - * @param grid - * @param visited ʱǾ - * @param row - * @param col - */ - private void bfs(char[][] grid, boolean[][] visited, int row, int col) { - - if (row >= 0 && row < grid.length // кϷ - && col >= 0 && col < grid[0].length // кϷ - && !visited[row][col] // ûзʹ - && grid[row][col] == '1') { // ǵ½ - - // ǴλѾʹ - visited[row][col] = true; - - // - bfs(grid, visited, row - 1, col); - // - bfs(grid, visited, row, col + 1); - // - bfs(grid, visited, row + 1, col); - // - bfs(grid, visited, row, col - 1); - } - } -} diff --git a/[201][Bitwise AND Of Numbers Range]/src/Solution.java b/[201][Bitwise AND Of Numbers Range]/src/Solution.java deleted file mode 100644 index 8e30521..0000000 --- a/[201][Bitwise AND Of Numbers Range]/src/Solution.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Author: - * Date: 2015-06-20 - * Time: 08:56 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND
-     * of all numbers in this range, inclusive.
-     *
-     * For example, given the range [5, 7], you should return 4.
-     *
-     * Ŀ⣺
-     * һΧΧеλĽ
-     *
-     * ˼·
-     * m!=nôĩλض0Ϊ[m, n]ضżĩλ0Խmnһλ
-     * Ϊmk nk൱ڽ[m, n]֮еƶһλmk=nkʱ˵֮ǰ
-     * [m, n]֮һλȵģƺANDm(=n)ԲͿֹͣ
-     * ¼ƵĴoffsetm>>offsetΪ
-     * 
- * - * @param m - * @param n - * @return - */ - public int rangeBitwiseAnd(int m, int n) { - int offset = 0; - - while (m != n) { - m >>= 1; - n >>= 1; - offset++; - } - - return m << offset; - } -} diff --git a/[202][Happy Number ]/src/Main.java b/[202][Happy Number ]/src/Main.java deleted file mode 100644 index 97bf463..0000000 --- a/[202][Happy Number ]/src/Main.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Author: - * Date: 2015-06-18 - * Time: 09:17 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { - Solution solution = new Solution(); - System.out.println(solution.isHappy(19)); - } -} diff --git a/[202][Happy Number ]/src/Solution.java b/[202][Happy Number ]/src/Solution.java deleted file mode 100644 index 5df793f..0000000 --- a/[202][Happy Number ]/src/Solution.java +++ /dev/null @@ -1,51 +0,0 @@ -import java.util.HashSet; - -/** - * Author: - * Date: 2015-06-17 - * Time: 21:36 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - * Write an algorithm to determine if a number is "happy". - * A happy number is a number defined by the following process: Starting with any positive integer, - * replace the number by the sum of the squares of its digits, and repeat the process until the number - * equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those - * numbers for which this process ends in 1 are happy numbers. - * - * ĿҪһϸλֵƽͣΪ1Ϊhappy number - * ܴijʼѭ - * - * @param n - * @return - */ - public boolean isHappy(int n) { - - if (n < 1) { - return false; - } - - // ڱмֵĽ - HashSet set = new HashSet<>(32); - - int tmp; - int newN; - - // nΪ1nֵظ֣ѭ - while (n != 1 && !set.contains(n)) { - set.add(n); - newN = 0; - while (n > 0) { - tmp = n % 10; - n /= 10; - newN += tmp * tmp; - } - - n = newN; - } - - return n == 1; - } - -} diff --git a/[203][Remove Linked List Elements]/src/ListNode.java b/[203][Remove Linked List Elements]/src/ListNode.java deleted file mode 100644 index 4f82c20..0000000 --- a/[203][Remove Linked List Elements]/src/ListNode.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Author: - * Date: 2015-06-19 - * Time: 13:57 - * Declaration: All Rights Reserved !!! - */ -public class ListNode { - int val; - ListNode next; - - ListNode(int x) { - val = x; - } -} diff --git a/[203][Remove Linked List Elements]/src/Solution.java b/[203][Remove Linked List Elements]/src/Solution.java deleted file mode 100644 index b58cbfd..0000000 --- a/[203][Remove Linked List Elements]/src/Solution.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Author: - * Date: 2015-06-19 - * Time: 13:57 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - * Remove all elements from a linked list of integers that have value val. - *

- * Example - * Given: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6 - * Return: 1 --> 2 --> 3 --> 4 --> 5 - *

- * һֵvalڵɾֵΪvalĽ - *

- * ˼· - * ͷһ㣬ɾ - * - * @param head - * @param val - * @return - */ - public ListNode removeElements(ListNode head, int val) { - ListNode root = new ListNode(1); - root.next = head; - // ڼ¼ҪԪصǰ - ListNode prev = root; - - // prev.nextʾҪĽ - while (prev.next != null) { - // ҪĽҪɾĽ - if (prev.next.val == val) { - // Խɾ - prev.next = prev.next.next; - } - // ǰĽڵ㲻Ҫɾprevƶһ - else { - prev = prev.next; - } - } - - // µĸ - return root.next; - } -} diff --git a/[204][Count Primes]/src/Solution.java b/[204][Count Primes]/src/Solution.java deleted file mode 100644 index 25b999a..0000000 --- a/[204][Count Primes]/src/Solution.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Author: - * Date: 2015-06-19 - * Time: 14:51 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /*** - * Description: - * Count the number of prime numbers less than a non-negative number, n. - *

- * Ŀ⣺ - * ͳСڷǸnĸ - *

- * ˼· - * ʹüɫɸ - * - * @param n - * @return - */ - public int countPrimes(int n) { - - if (n <= 1) { - return 0; - } - - // ĬеԪֵΪfalse - boolean[] notPrime = new boolean[n]; - notPrime[0] = true; - notPrime[1] = true; - - for (int i = 2; i * i < n; i++) { - // iһiiıΪ - // iһضѾΪtrueˣΪǴ2ʼ - if (!notPrime[i]) { - for (int j = 2 * i; j < n; j += i) { - notPrime[j] = true; - } - } - } - - // ͳĸ - int result = 0; - for (boolean b : notPrime) { - if (!b) { - result++; - } - } - - return result; - } -} diff --git a/[205][Isomorphic Strings]/src/Solution.java b/[205][Isomorphic Strings]/src/Solution.java deleted file mode 100644 index 23d9130..0000000 --- a/[205][Isomorphic Strings]/src/Solution.java +++ /dev/null @@ -1,109 +0,0 @@ -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -/** - * Author: - * Date: 2015-06-19 - * Time: 11:57 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - * Given two strings s and t, determine if they are isomorphic. - *

- * Two strings are isomorphic if the characters in s can be replaced to get t. - *

- * All occurrences of a character must be replaced with another character while - * preserving the order of characters. No two characters may map to the same character - * but a character may map to itself. - *

- * For example, - * Given "egg", "add", return true. - * Given "foo", "bar", return false. - * Given "paper", "title", return true. - *

- * Note: - * You may assume both s and t have the same length. - *

- * Ŀ⣺ - * ַstжǷͬġ - *

- * ַsַͨ滻ķʽõַtstͬġ - *

- * ַÿһγֶ뱻Ӧַ滻ͬʱҪ֤ԭʼ˳򲻷ı䡣 - * ַӳ䵽ͬһַַӳ䵽䱾 - *

- * Ŀ - * Լstȳ - *

- * ˼· - * ֻҪstһһӳͿˡ - * ʹһϣmapάַַӳϵͬʱһsetӳֵ - * (s[i], t[i])s[i]ûmapгֹt[i]ûsetгֹͼ뵽ӳϵУ - * t[i]ֵѾֹ˵Ƕһӳ䣬Ϸfalses[i]Ѿֹ - * Ϊs[k]ӦӳֵΪt[k]),s[i]==s[k],ҳs[k]ĶԶӦֵt[k] - * t[i]!=t[k],˵һͬһַͬӳ䣬ַͬģfalse - * һֱַ - *

- * ӳ䲻һµʱFalse򷵻True - * - * @param s - * @param t - * @return - */ - public boolean isIsomorphic(String s, String t) { - - // ַΪ - if (s == null && t == null) { - return true; - } - // ֻһΪ - else if (s == null || t == null) { - return false; - } - // ַijȶΪ0 - else if (s.length() == 0 && t.length() == 0) { - return true; - } - // ַijȲ - else if (s.length() != t.length()) { - return false; - } - - // ӳϵ - Map map = new HashMap<>(s.length()); - Set set = new HashSet<>(t.length()); - char sChar; - char tChar; - for (int i = 0; i < s.length(); i++) { - sChar = s.charAt(i); - tChar = t.charAt(i); - - // δֹͰӳϵ - if (!map.containsKey(sChar)) { - if (set.contains(tChar)) { - return false; - } else { - map.put(s.charAt(i), t.charAt(i)); - set.add(tChar); - } - } - // ǼѾֹ - else { - - // ԭȵļӳֵmap.get(sChar)ҪӳֵtChar - // ֵȣ˵ѾӳΣϣfalse - if (map.get(sChar) != tChar) { - return false; - } - } - - - } - - - return true; - } -} diff --git a/[206][Reverse Linked List]/src/ListNode.java b/[206][Reverse Linked List]/src/ListNode.java deleted file mode 100644 index 845bd94..0000000 --- a/[206][Reverse Linked List]/src/ListNode.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Author: - * Date: 2015-06-19 - * Time: 11:18 - * Declaration: All Rights Reserved !!! - */ -public class ListNode { - int val; - ListNode next; - - ListNode(int x) { - val = x; - } -} \ No newline at end of file diff --git a/[206][Reverse Linked List]/src/Main.java b/[206][Reverse Linked List]/src/Main.java deleted file mode 100644 index 449e76c..0000000 --- a/[206][Reverse Linked List]/src/Main.java +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Author: - * Date: 2015-06-19 - * Time: 11:17 - * Declaration: All Rights Reserved !!! - */ -public class Main { -} diff --git a/[206][Reverse Linked List]/src/Solution.java b/[206][Reverse Linked List]/src/Solution.java deleted file mode 100644 index 3799055..0000000 --- a/[206][Reverse Linked List]/src/Solution.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Author: - * Date: 2015-06-19 - * Time: 11:17 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - * Reverse a singly linked list. - * ת - * ʹͷ巨 - * - * @param head - * @return - */ - public ListNode reverseList(ListNode head) { - // ͷ - ListNode root = new ListNode(0); - ListNode nextNode; - while (head != null) { - nextNode = head.next; - head.next = root.next; - root.next = head; - head = nextNode; - } - - head = root.next; - root.next = null; - - return head; - } - - /** - * TODO ʹõݹⷨ - * @param head - * @return - */ - public ListNode reverseList2(ListNode head) { - if (head == null) { - return null; - } - - reverseList2(head.next).next = head; - - return null; - } -} diff --git a/[215][Kth Largest Element In An Array]/src/Main.java b/[215][Kth Largest Element In An Array]/src/Main.java deleted file mode 100644 index cd77742..0000000 --- a/[215][Kth Largest Element In An Array]/src/Main.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Author: - * Date: 2015-06-19 - * Time: 20:01 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { - Solution solution = new Solution(); - System.out.println(solution.findKthLargest(new int[]{2 , 1}, 2)); - } -} diff --git a/[215][Kth Largest Element In An Array]/src/Solution.java b/[215][Kth Largest Element In An Array]/src/Solution.java deleted file mode 100644 index 8119edf..0000000 --- a/[215][Kth Largest Element In An Array]/src/Solution.java +++ /dev/null @@ -1,81 +0,0 @@ -import java.util.Collections; - -/** - * Author: - * Date: 2015-06-19 - * Time: 19:36 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *

-     * Find the kth largest element in an unsorted array. Note that it is the kth
-     * largest element in the sorted order, not the kth distinct element.
-     *
-     * For example,
-     * Given [3,2,1,5,6,4] and k = 2, return 5.
-     *
-     * Note:
-     * You may assume k is always valid, 1  k  array's length.
-     *
-     * Ŀ⣺
-     * һδҳkԪءע֮ĵk󣬶ǵkظԪ
-     * ԼkһЧģ 1  k  鳤
-     *
-     * ˼·
-     * O(n)ⷨѡQuickSelect㷨
-     * 
- * - * @param nums - * @param k - * @return - */ - public int findKthLargest(int[] nums, int k) { - - if (k < 1 || nums == null || nums.length < k) { - throw new IllegalArgumentException(); - } - - return findKthLargest(nums, 0, nums.length - 1, k); - } - - public int findKthLargest(int[] nums, int start, int end, int k) { - - // ֵ - int pivot = nums[start]; - int lo = start; - int hi = end; - - while (lo < hi) { - // Сֵƶ - while (lo < hi && nums[hi] >= pivot) { - hi--; - } - nums[lo] = nums[hi]; - - // ֵƶұ - while (lo < hi && nums[lo] <= pivot) { - lo++; - } - nums[hi] = nums[lo]; - } - - nums[lo] = pivot; - - // Ѿҵ - if (end - lo + 1 == k) { - return pivot; - } - // kloλõұ - else if (end - lo + 1 > k){ - return findKthLargest(nums, lo + 1, end, k); - } - // kloλõ - else { - // k-(end-lo+1) - // (end-lo+1)ʾloλÿʼendλõԪظҰ벿 - // ԭĵkk-(end-lo+1) - return findKthLargest(nums, start, lo - 1, k - (end - lo + 1)); - } - } -} diff --git a/[216][Combination Sum III]/src/Main.java b/[216][Combination Sum III]/src/Main.java deleted file mode 100644 index 4378e2a..0000000 --- a/[216][Combination Sum III]/src/Main.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Author: - * Date: 2015-06-21 - * Time: 22:05 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { - Solution solution = new Solution(); -// System.out.println(solution.combinationSum3(3, 7)); -// System.out.println(solution.combinationSum3(3, 9)); -// System.out.println(solution.combinationSum3(4, 24)); - System.out.println(solution.combinationSum3(9, 45)); - } -} diff --git a/[216][Combination Sum III]/src/Solution.java b/[216][Combination Sum III]/src/Solution.java deleted file mode 100644 index e2c8e6f..0000000 --- a/[216][Combination Sum III]/src/Solution.java +++ /dev/null @@ -1,101 +0,0 @@ -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; - -/** - * Author: - * Date: 2015-06-21 - * Time: 21:31 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - /** - *
-     * Find all possible combinations of k numbers that add up to a number n,
-     * given that only numbers from 1 to 9 can be used and each combination
-     * should be a unique set of numbers.
-     *
-     * Ensure that numbers within the set are sorted in ascending order.
-     *
-     * Example 1:
-     * Input: k = 3, n = 7
-     * Output:
-     * [[1,2,4]]
-     *
-     * Example 2:
-     * Input: k = 3, n = 9
-     * Output:
-     * [[1,2,6], [1,3,5], [2,3,4]]
-     *
-     * Ŀ⣺
-     * Ѱk֮͵nϣֻʹ1-9ÿһеӦΨһġ
-     * ȷеԵ˳С
-     *
-     * ˼·
-     * ݷ
-     * 
- * - * @param k - * @param n - * @return - */ - public List> combinationSum3(int k, int n) { - // ڱн - List> result = new LinkedList<>(); - // ڱм - List list = new LinkedList<>(); - // ͽн - if (k > 0 && k <= 9) { - solve(k, 1, n, 0, list, result); - } - - // ؽ - return result; - } - - /** - * ⷽ - * - * @param k ÿԪظ - * @param cur ǰkԪ - * @param remainder k - cur + 1Ԫصĺ - * @param prevVal cur-1Ԫصȡֵ - * @param list Ԫصļ - * @param result н - */ - public void solve(int k, int cur, int remainder, int prevVal, List list, List> result) { - // һԪ - if (cur == k) { - // remainderΪһԪصֵǰһԪصֵҲܳ9 - if (remainder > prevVal && remainder <= 9) { - // Ԫֵ - list.add(remainder); - - // µĶ - List one = new LinkedList<>(); - for (Integer i : list) { - one.add(i); - } - - // - result.add(one); - // ɾһԪأֳԭ - list.remove(list.size() - 1); - } - } - // һԪ - else if (cur < k){ - for (int i = prevVal + 1; i <= 9 - (k - cur); i++) { - // Ԫ - list.add(i); - // ݹ - solve(k, cur + 1, remainder - i, i, list, result); - // ֳԭ - list.remove(list.size() - 1); - - } - } - - - } -} diff --git a/[217][Contains Duplicate ]/src/Main.java b/[217][Contains Duplicate ]/src/Main.java deleted file mode 100644 index b144561..0000000 --- a/[217][Contains Duplicate ]/src/Main.java +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Author: - * Date: 2015-06-18 - * Time: 09:59 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { - Solution solution = new Solution(); - System.out.println(solution.containsDuplicate(new int[]{1, 2, 8, 3, 4, 4, 7, 4, 5})); - System.out.println(solution.containsDuplicate(new int[]{1, 2, 3, 4, 7, 5})); - } -} diff --git a/[217][Contains Duplicate ]/src/Solution.java b/[217][Contains Duplicate ]/src/Solution.java deleted file mode 100644 index 67fdbb9..0000000 --- a/[217][Contains Duplicate ]/src/Solution.java +++ /dev/null @@ -1,46 +0,0 @@ -import java.util.HashSet; -import java.util.Set; - -/** - * Author: - * Date: 2015-06-18 - * Time: 09:40 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - - - /** - * Given an array of integers, find if the array contains any duplicates. - * Your function should return true if any value appears at least twice in the - * array, and it should return false if every element is distinct. - *

- * Ŀ⣺һ飬жǷظԪءһֳΣ - * ĺӦ÷trueÿһԪضΨһģfalse - * - * ˼·setݽṹ - * - * @param nums - * @return - */ - public boolean containsDuplicate(int[] nums) { - - // Ԫظ1ŽIJ - if (nums != null && nums.length > 1) { - //һhashSet - Set set = new HashSet<>(nums.length); - for(int i : nums) { - // ԪѾھͷtrue - if (set.contains(i)) { - return true; - } - // ûоӵԪؼ - else { - set.add(i); - } - } - } - - return false; - } -} diff --git a/[219][Contains Duplicate II]/src/Solution.java b/[219][Contains Duplicate II]/src/Solution.java deleted file mode 100644 index 2fa0545..0000000 --- a/[219][Contains Duplicate II]/src/Solution.java +++ /dev/null @@ -1,55 +0,0 @@ -import java.util.HashMap; -import java.util.Map; - -/** - * Author: - * Date: 2015-06-19 - * Time: 14:10 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - - /** - * Given an array of integers and an integer k, find out whether there there are - * two distinct indices i and j in the array such that nums[i] = nums[j] and the - * difference between i and j is at most k. - * - * Ŀ⣺ - * һnumsһkҽͬ±ijnums[i] = nums[j] - * |i-j|<=kʱtrue򷵻false - * - * ˼· - * nums[0...n-1]һmapУ(muns[i], i)nums[k]Ѿڣ - * Ƚ֮ǰ±ڵ±IJֵֵk˵ֵ - * ʹµ±Ϊֵ - * - * @param nums - * @param k - * @return - */ - public boolean containsNearbyDuplicate(int[] nums, int k) { - // ж - if (nums == null || nums.length < 2 || k < 1) { - return false; - } - - Map map = new HashMap<>(); - for (int i = 0; i < nums.length; i++) { - - // ûжӦkeyӽȥ - if (!map.containsKey(nums[i])) { - map.put(nums[i], i); - } - // ѾжӦkey-value - else { - // ԭֵӦ±꣬һСڵ± - int value = map.get(nums[i]); - if (i - value <= k) { - return true; - } - map.put(nums[i], i); - } - } - return false; - } -} diff --git a/[223][Rectangle Area]/src/Main.java b/[223][Rectangle Area]/src/Main.java deleted file mode 100644 index 7afa1b6..0000000 --- a/[223][Rectangle Area]/src/Main.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Author: - * Date: 2015-06-19 - * Time: 16:16 - * Declaration: All Rights Reserved !!! - */ -public class Main { - public static void main(String[] args) { - Solution solution = new Solution(); -// System.out.println(solution.computeArea(-2, -2, 2, 2, -2, -2, 2, 2)); -// System.out.println(solution.computeArea(-2, -2, 2, 2, -3, -3, 3, -1)); - System.out.println(solution.computeArea(-1500000001, 0, -1500000000, 1, 1500000000, 0, 1500000001, 1)); - } -} diff --git a/[223][Rectangle Area]/src/Solution.java b/[223][Rectangle Area]/src/Solution.java deleted file mode 100644 index f2ea311..0000000 --- a/[223][Rectangle Area]/src/Solution.java +++ /dev/null @@ -1,78 +0,0 @@ -import java.util.*; - -/** - * Author: - * Date: 2015-06-19 - * Time: 15:32 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - - /** - *

-     * Find the total area covered by two rectilinear rectangles in a 2D plane.
-     * Each rectangle is defined by its bottom left corner and top right
-     * corner as shown in the figure.
-     *
-     * Assume that the total area is never beyond the maximum possible value of int.
-     *
-     * *****************************(C,D):(3,4)
-     * *                           *
-     * *                           *
-     * *           *************************************(G,H):(9,2)
-     * *           *               *                   *
-     * *           *               *                   *
-     * *           *               *                   *
-     * *           *               *                   *
-     * *           *(0,0)          *                   *
-     * *****************************                   *
-     * (A,B):(-3,0)*                                   *
-     *             *                                   *
-     *             * (E,F):(0-1)                     *
-     *             *************************************
-     *
-     *   ***************************        ***************************
-     *   *            D            *        *            H            *
-     *   *                         *        *                         *
-     *   *A                       C*        *E                       G*
-     *   *                         *        *                         *
-     *   *                         *        *                         *
-     *   *            B            *        *            F            *
-     *   ***************************        ***************************
-     *
-     *
-     *
-     * 
- * Ŀ⣺ - * ܹǵ - *

- * ˼· - * 㷽Ϊ1+2-ιͬĸ - * - * @param A - * @param B - * @param C - * @param D - * @param E - * @param F - * @param G - * @param H - * @return - */ - public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { - long area = (long) (C - A) * (D - B) + (long)(G - E) * (H - F); - // Math.min(C, G) ʾұ߱ߵСı - // Math.max(A, E) ʾ߱ߵı - // ļԽ飬ҪݷΧ - long width = Math.max((long)Math.min(C, G) - (long)Math.max(A, E), 0); - // Math.min(D, H) ʾ߱ߵСı - // Math.max(B, F) ʾױ߱ߵı - long height = Math.max((long)Math.min(D, H) - (long)Math.max(B, F), 0); - - System.out.println(width +":" + height + "=" + width*height); - - return (int)(area - width * height); - } - - -} diff --git a/[225][Implement Stack Using Queues]/src/MyStack.java b/[225][Implement Stack Using Queues]/src/MyStack.java deleted file mode 100644 index 25e0c68..0000000 --- a/[225][Implement Stack Using Queues]/src/MyStack.java +++ /dev/null @@ -1,102 +0,0 @@ -import java.util.LinkedList; -import java.util.List; - -/** - *

- * Implement the following operations of a stack using queues.
- *   - push(x)  -- Push element x onto stack.
- *   - pop()    -- Removes the element on top of the stack.
- *   - top()    -- Get the top element.
- *   - empty()  -- Return whether the stack is empty.
- *
- * Notes:
- *   - You must use only standard operations of a queue -- which means only push
- *          to back, peek/pop from front, size, and is empty operations are valid.
- *   - Depending on your language, queue may not be supported natively. You may
- *          simulate a queue by using a list or deque (double-ended queue), as
- *          long as you use only standard operations of a queue.
- *   - You may assume that all operations are valid (for example, no pop or top
- *          operations will be called on an empty stack).
- *
- *  Ŀ⣺
- *  ʹöʵջ
- *   - push(x)  -- Ԫջ
- *   - pop()    -- Ԫسջ
- *   - top()    -- ȡջԪֵ
- *   - empty()  -- жջǷΪ
- *  ע⣺
- *   - ֻʹöеı׼ȽȳԪж϶ǷΪ
- *   - ڱԭЩԲ֧ĦУʹ˫棬ʹñ׼Ķв
- *   - ԼеIJǺϷģΪʱԪسջջԪصIJ
- *
- * ˼·
- * ģһջ
- * 
- *

- * Author: - * Date: 2015-06-22 - * Time: 20:45 - * Declaration: All Rights Reserved !!! - */ -public class MyStack { - - // άУһΪգΪpoptop׼ - private List aList = new LinkedList<>(); - private List bList = new LinkedList<>(); - - - // Push element x onto stack. - public void push(int x) { - // aListǿգͽxӵaList - if (!aList.isEmpty()) { - aList.add(x); - } - // ӵbList - else { - bList.add(x); - } - } - - // Removes the element on top of the stack. - public void pop() { - - // һΪգaList÷ǿ - if (aList.isEmpty()) { - List tmp = bList; - bList = aList; - aList = tmp; - } - - // һԪⶼתƵbList - while (aList.size() > 1) { - bList.add(aList.remove(0)); - } - - // ɾһԪأӦջջԪأ - aList.clear(); - } - - // Get the top element. - public int top() { - - // һΪգaList÷ǿ - if (aList.isEmpty()) { - List tmp = bList; - bList = aList; - aList = tmp; - } - - // һԪⶼתƵbList - while (aList.size() > 1) { - bList.add(aList.remove(0)); - } - - bList.add(aList.get(0)); - return aList.remove(0); - } - - // Return whether the stack is empty. - public boolean empty() { - return aList.isEmpty() && bList.isEmpty(); - } -} diff --git a/[226][Invert Binary Tree]/src/Solution.java b/[226][Invert Binary Tree]/src/Solution.java deleted file mode 100644 index f02e962..0000000 --- a/[226][Invert Binary Tree]/src/Solution.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Author: - * Date: 2015-06-18 - * Time: 10:01 - * Declaration: All Rights Reserved !!! - */ -public class Solution { - public TreeNode invertTree(TreeNode root) { - - if (root != null) { - invertTreeNode(root); - } - return root; - } - - public void invertTreeNode(TreeNode root) { - - if (root != null) { - TreeNode tmp = root.left; - root.left = root.right; - root.right = tmp; - - invertTree(root.left); - invertTree(root.right); - } - } -} diff --git a/[226][Invert Binary Tree]/src/TreeNode.java b/[226][Invert Binary Tree]/src/TreeNode.java deleted file mode 100644 index 73c7ed9..0000000 --- a/[226][Invert Binary Tree]/src/TreeNode.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Author: - * Date: 2015-06-18 - * Time: 10:02 - * Declaration: All Rights Reserved !!! - */ -public class TreeNode { - int val; - TreeNode left; - TreeNode right; - - TreeNode(int x) { - val = x; - } -} diff --git a/[231][Power of Two]/src/Solution.java b/[231][Power of Two]/src/Solution.java deleted file mode 100644 index dee3309..0000000 --- a/[231][Power of Two]/src/Solution.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-10-09 09:24 - **/ -public class Solution { - public boolean isPowerOfTwo(int n) { - if (n < 1) { - return false; - } - - int remainder; - boolean result = false; - while (n > 0) { - // 求余数 - remainder = n % 2; - n >>>= 1; - - if (n == 0 && remainder == 1) { - result = true; - break; - } else if (n > 0 && remainder == 1) { - break; - } - } - - return result; - } -} diff --git a/[231][Power of Two]/src/Test.java b/[231][Power of Two]/src/Test.java deleted file mode 100644 index 0b8841a..0000000 --- a/[231][Power of Two]/src/Test.java +++ /dev/null @@ -1,16 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-10-09 09:28 - **/ -public class Test { - public static void main(String[] args) { - Solution solution = new Solution(); - - System.out.println(solution.isPowerOfTwo(-1)); - System.out.println(solution.isPowerOfTwo(0)); - System.out.println(solution.isPowerOfTwo(1)); - System.out.println(solution.isPowerOfTwo(2)); - System.out.println(solution.isPowerOfTwo(16)); - System.out.println(solution.isPowerOfTwo(218)); - } -} diff --git a/[232][Implement Queue using Stacks]/src/MyQueue.java b/[232][Implement Queue using Stacks]/src/MyQueue.java deleted file mode 100644 index a4cdc0c..0000000 --- a/[232][Implement Queue using Stacks]/src/MyQueue.java +++ /dev/null @@ -1,56 +0,0 @@ -import java.util.LinkedList; -import java.util.List; -import java.util.Queue; - -/** - * @author: wangjunchao(王俊超) - * @time: 2018-10-09 09:37 - **/ -class MyQueue { - - private List list; - - /** - * Initialize your data structure here. - */ - public MyQueue() { - list = new LinkedList<>(); - } - - /** - * Push element x to the back of queue. - */ - public void push(int x) { - list.add(x); - } - - /** - * Removes the element from in front of queue and returns that element. - */ - public int pop() { - return list.remove(0); - } - - /** - * Get the front element. - */ - public int peek() { - return list.get(0); - } - - /** - * Returns whether the queue is empty. - */ - public boolean empty() { - return list.isEmpty(); - } -} - -/** - * Your MyQueue object will be instantiated and called as such: - * MyQueue obj = new MyQueue(); - * obj.push(x); - * int param_2 = obj.pop(); - * int param_3 = obj.peek(); - * boolean param_4 = obj.empty(); - */ diff --git a/[232][Implement Queue using Stacks]/src/Test.java b/[232][Implement Queue using Stacks]/src/Test.java deleted file mode 100644 index 4adabf6..0000000 --- a/[232][Implement Queue using Stacks]/src/Test.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-10-09 10:58 - **/ -public class Test { - public static void main(String[] args) { - MyQueue queue = new MyQueue(); - queue.push(1); - queue.push(2); - - System.out.println(queue.peek()); - System.out.println(queue.pop()); - System.out.println(queue.empty()); - } -} diff --git a/[234][Palindrome Linked List]/src/ListNode.java b/[234][Palindrome Linked List]/src/ListNode.java deleted file mode 100644 index 0304f36..0000000 --- a/[234][Palindrome Linked List]/src/ListNode.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-10-09 11:03 - **/ -public class ListNode { - int val; - ListNode next; - - ListNode(int x) { - val = x; - } -} diff --git a/[234][Palindrome Linked List]/src/Solution.java b/[234][Palindrome Linked List]/src/Solution.java deleted file mode 100644 index 9ace1e4..0000000 --- a/[234][Palindrome Linked List]/src/Solution.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * O(n) time and O(1) space - *

- * 1->2->2->1
- * 1->2->3->2->1
- * 先找到第二个2的位置,将2及后面的链逆转,形成新的链A,再按A与原来的链,从头开开始比较
- * 
- * - * @author: wangjunchao(王俊超) - * @time: 2018-10-09 11:02 - **/ -public class Solution { - public boolean isPalindrome(ListNode head) { - - // 没有节点或者只有一个结点 - if (head == null || head.next == null) { - return true; - } - - int count = 0; - ListNode node = head; - while (node != null) { - count++; - node = node.next; - } - - // 找反向链的起始位置 - count = (count + 1) / 2; - node = head; - while (count >0) { - count--; - node = node.next; - } - - - ListNode reverseHead = new ListNode(0); - ListNode temp; - while (node != null) { - temp = node.next; - node.next = reverseHead.next; - reverseHead.next = node; - node = temp; - } - - reverseHead = reverseHead.next; - - while (reverseHead != null) { - if (head.val != reverseHead.val) { - return false; - } - - reverseHead = reverseHead.next; - head = head.next; - } - - return true; - } -} diff --git a/[234][Palindrome Linked List]/src/Solution2.java b/[234][Palindrome Linked List]/src/Solution2.java deleted file mode 100644 index f6138f7..0000000 --- a/[234][Palindrome Linked List]/src/Solution2.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * O(n) time and O(n) space - * - * @author: wangjunchao(王俊超) - * @time: 2018-10-09 11:02 - **/ -public class Solution2 { - public boolean isPalindrome(ListNode head) { - - if (head == null) { - return true; - } - - // 反向链的头 - ListNode reverseHead = new ListNode(-1); - - ListNode temp = head; - ListNode node; - // 头插法构建反向链 - while (temp != null) { - node = new ListNode(temp.val); - node.next = reverseHead.next; - reverseHead.next = node; - temp = temp.next; - } - - reverseHead = reverseHead.next; - while (head != null) { - if (head.val != reverseHead.val) { - return false; - } - - head = head.next; - reverseHead = reverseHead.next; - } - return true; - } -} diff --git a/[234][Palindrome Linked List]/src/Test.java b/[234][Palindrome Linked List]/src/Test.java deleted file mode 100644 index 97b7f35..0000000 --- a/[234][Palindrome Linked List]/src/Test.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-10-09 11:10 - **/ -public class Test { - public static void main(String[] args) { - test1(); - test2(); - test3(); - } - - public static void test1() { - Solution solution = new Solution(); - ListNode head = new ListNode(1); - head.next = new ListNode(2); - System.out.println(solution.isPalindrome(head)); - } - - public static void test2() { - Solution solution = new Solution(); - - ListNode head = new ListNode(1); - head.next = new ListNode(2); - head.next.next= new ListNode(2); - head.next.next.next= new ListNode(1); - head.next.next.next.next= new ListNode(2); - head.next.next.next.next.next= new ListNode(2); - head.next.next.next.next.next.next= new ListNode(1); - System.out.println(solution.isPalindrome(head)); - } - - public static void test3() { - Solution solution = new Solution(); - - ListNode head = new ListNode(1); - head.next = new ListNode(2); - head.next.next= new ListNode(2); - head.next.next.next= new ListNode(1); - - System.out.println(solution.isPalindrome(head)); - } -} diff --git a/[235][Lowest Common Ancestor of a Binary Search Tree]/src/Solution.java b/[235][Lowest Common Ancestor of a Binary Search Tree]/src/Solution.java deleted file mode 100644 index 632cf2f..0000000 --- a/[235][Lowest Common Ancestor of a Binary Search Tree]/src/Solution.java +++ /dev/null @@ -1,56 +0,0 @@ -import java.util.ArrayList; -import java.util.List; - -/** - * Definition for a binary tree node. - *
- * public class TreeNode {
- *      int val;
- *      TreeNode left;
- *      TreeNode right;
- *      TreeNode(int x) { val = x; }
- * }
- * 
- * - * @author: wangjunchao(王俊超) - * @time: 2018-10-09 11:32 - */ -class Solution { - public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { - - List pPath = new ArrayList<>(); - List qPath = new ArrayList<>(); - - search(pPath, root, p); - search(qPath, root, q); - - TreeNode ancestor = pPath.get(0); - - int idx = 1; - while (idx < pPath.size() && idx < qPath.size()) { - p = pPath.get(idx); - q = qPath.get(idx); - if (p != null && q != null && p.val == q.val) { - ancestor = pPath.get(idx); - idx++; - } else { - break; - } - } - - return ancestor; - } - - public void search(List path, TreeNode root, TreeNode node) { - path.add(root); - - if (root != null) { - if (root.val > node.val) { - search(path, root.left, node); - } - if (root.val < node.val) { - search(path, root.right, node); - } - } - } -} diff --git a/[235][Lowest Common Ancestor of a Binary Search Tree]/src/TreeNode.java b/[235][Lowest Common Ancestor of a Binary Search Tree]/src/TreeNode.java deleted file mode 100644 index cb9448f..0000000 --- a/[235][Lowest Common Ancestor of a Binary Search Tree]/src/TreeNode.java +++ /dev/null @@ -1,13 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-10-09 11:33 - **/ -public class TreeNode { - int val; - TreeNode left; - TreeNode right; - - TreeNode(int x) { - val = x; - } -} diff --git a/[237][Delete Node in a Linked List]/src/ListNode.java b/[237][Delete Node in a Linked List]/src/ListNode.java deleted file mode 100644 index 50f6a11..0000000 --- a/[237][Delete Node in a Linked List]/src/ListNode.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-10-10 09:58 - **/ -public class ListNode { - int val; - ListNode next; - - ListNode(int x) { - val = x; - } -} diff --git a/[237][Delete Node in a Linked List]/src/Solution.java b/[237][Delete Node in a Linked List]/src/Solution.java deleted file mode 100644 index b440a61..0000000 --- a/[237][Delete Node in a Linked List]/src/Solution.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - *
- * Definition for singly-linked list.
- * public class ListNode {
- *     int val;
- *     ListNode next;
- *     ListNode(int x) { val = x; }
- * }
- * 
- * @author: wangjunchao(王俊超) - * @time: 2018-10-10 09:57 - **/ -class Solution { - public void deleteNode(ListNode node) { - - if (node == null || node.next == null) { - return; - } - - ListNode prev = node; - while (node.next != null) { - node.val = node.next.val; - prev = node; - node = node.next; - - - } - - prev.next = null; - } -} \ No newline at end of file diff --git a/[237][Delete Node in a Linked List]/src/Test.java b/[237][Delete Node in a Linked List]/src/Test.java deleted file mode 100644 index 8863287..0000000 --- a/[237][Delete Node in a Linked List]/src/Test.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-10-10 10:01 - **/ -public class Test { - public static void main(String[] args) { - ListNode node = new ListNode(4); - node.next = new ListNode(5); - node.next.next = new ListNode(1); - node.next.next.next = new ListNode(9); - - Solution solution = new Solution(); - solution.deleteNode(node.next); - - print(node); - } - - private static void print(ListNode node) { - do { - if (node == null) { - System.out.println("null"); - } else if (node.next != null){ - System.out.print(node.val + "->"); - node = node.next; - } else { - System.out.println(node.val + "->null"); - node = node.next; - } - - }while (node != null); - } -} diff --git a/[242][Valid Anagram]/src/Solution.java b/[242][Valid Anagram]/src/Solution.java deleted file mode 100644 index ace39c8..0000000 --- a/[242][Valid Anagram]/src/Solution.java +++ /dev/null @@ -1,48 +0,0 @@ -import java.util.HashMap; -import java.util.Map; - -/** - * @author: wangjunchao(王俊超) - * @time: 2018-10-10 10:28 - **/ -public class Solution { - public boolean isAnagram(String s, String t) { - - if (s == null && t == null) { - return true; - } else if (s == null || t == null) { - return false; - } - - Map map = new HashMap<>(); - - for (int i = 0; i < s.length(); i++) { - Character c = s.charAt(i); - if (map.containsKey(c)) { - map.put(c, map.get(c) + 1); - } else { - map.put(c, 1); - } - } - - for (int i = 0; i < t.length(); i++) { - Character c = t.charAt(i); - Integer count = map.get(c); - // t有s中不包含的字符串 - if (count == null) { - return false; - } else { - map.put(c, count - 1); - } - } - - // map中的值有非0的说明不合法 - for (Integer i : map.values()) { - if (i != 0) { - return false; - } - } - - return true; - } -} diff --git a/[242][Valid Anagram]/src/Test.java b/[242][Valid Anagram]/src/Test.java deleted file mode 100644 index 5282683..0000000 --- a/[242][Valid Anagram]/src/Test.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-10-10 10:35 - **/ -public class Test { - public static void main(String[] args) { - Solution solution = new Solution(); - - System.out.println(solution.isAnagram("anagram", "nagaram")); - System.out.println(solution.isAnagram("rat", "car")); - } -} diff --git a/[257][Binary Tree Paths]/src/Solution.java b/[257][Binary Tree Paths]/src/Solution.java deleted file mode 100644 index 6480a96..0000000 --- a/[257][Binary Tree Paths]/src/Solution.java +++ /dev/null @@ -1,56 +0,0 @@ -import java.util.LinkedList; -import java.util.List; - -/** - *
- * Definition for a binary tree node.
- * public class TreeNode {
- *     int val;
- *     TreeNode left;
- *     TreeNode right;
- *     TreeNode(int x) { val = x; }
- * }
- * 
- * - * @author: wangjunchao(王俊超) - * @time: 2018-10-10 11:16 - **/ -public class Solution { - public List binaryTreePaths(TreeNode root) { - List result = new LinkedList<>(); - binaryTreePaths(root, new LinkedList<>(), result); - - return result; - } - - private void binaryTreePaths(TreeNode root, LinkedList path, List result) { - - if (root == null) { - return; - } - - path.add(root); - - if (root.left == null && root.right == null) { - addResult(path, result); - } else { - binaryTreePaths(root.left, path, result); - binaryTreePaths(root.right, path, result); - } - - path.remove(path.size() - 1); - } - - private void addResult(LinkedList path, List result) { - StringBuilder builder = new StringBuilder(); - if (path != null) { - for (TreeNode node : path) { - builder.append("->").append(node.val); - } - } - - if (builder.length() > 0) { - result.add(builder.substring(2)); - } - } -} diff --git a/[257][Binary Tree Paths]/src/Test.java b/[257][Binary Tree Paths]/src/Test.java deleted file mode 100644 index 318a15c..0000000 --- a/[257][Binary Tree Paths]/src/Test.java +++ /dev/null @@ -1,16 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-10-10 11:25 - **/ -public class Test { - public static void main(String[] args) { - Solution solution = new Solution(); - - TreeNode root = new TreeNode(1); - root.left = new TreeNode(2); - root.right = new TreeNode(3); - root.left.right = new TreeNode(5); - - System.out.println(solution.binaryTreePaths(root)); - } -} diff --git a/[257][Binary Tree Paths]/src/TreeNode.java b/[257][Binary Tree Paths]/src/TreeNode.java deleted file mode 100644 index 2e248fe..0000000 --- a/[257][Binary Tree Paths]/src/TreeNode.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Author: 王俊超 - * Date: 2015-06-18 - * Time: 10:02 - * Declaration: All Rights Reserved !!! - */ -public class TreeNode { - int val; - TreeNode left; - TreeNode right; - - TreeNode(int x) { - val = x; - } -} diff --git a/[258][Add Digits]/src/Solution.java b/[258][Add Digits]/src/Solution.java deleted file mode 100644 index ff595f5..0000000 --- a/[258][Add Digits]/src/Solution.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-10-10 13:28 - **/ -public class Solution { - public int addDigits(int num) { - - if (num < 0) { - throw new IllegalArgumentException("input num :" + num + ", must not be negative"); - } - - int result = 0; - - while (num > 0) { - result += num % 10; - num /= 10; - - // 需要重新进行位相加 - if (num == 0 && result > 9) { - num = result; - result = 0; - } - } - - return result; - } -} diff --git a/[258][Add Digits]/src/Test.java b/[258][Add Digits]/src/Test.java deleted file mode 100644 index d3afaa3..0000000 --- a/[258][Add Digits]/src/Test.java +++ /dev/null @@ -1,13 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-10-10 13:35 - **/ -public class Test { - public static void main(String[] args) { - Solution solution = new Solution(); - - System.out.println(solution.addDigits(38)); - System.out.println(solution.addDigits(999999999)); - System.out.println(solution.addDigits(100000000)); - } -} diff --git a/[263][Ugly Number]/src/Solution.java b/[263][Ugly Number]/src/Solution.java deleted file mode 100644 index a05b03c..0000000 --- a/[263][Ugly Number]/src/Solution.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-10-10 13:45 - **/ -public class Solution { - public boolean isUgly(int num) { - - if (num < 1) { - return false; - } else if (num == 1) { - return true; - } - - while ((num % 2) == 0) { - num /= 2; - } - - while ((num % 3) == 0) { - num /= 3; - } - - while ((num % 5) == 0) { - num /= 5; - } - - return num == 1; - } -} diff --git a/[263][Ugly Number]/src/Test.java b/[263][Ugly Number]/src/Test.java deleted file mode 100644 index dccb247..0000000 --- a/[263][Ugly Number]/src/Test.java +++ /dev/null @@ -1,16 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-10-10 13:50 - **/ -public class Test { - public static void main(String[] args) { - Solution solution = new Solution(); - - System.out.println(solution.isUgly(-1)); - System.out.println(solution.isUgly(0)); - System.out.println(solution.isUgly(1)); - System.out.println(solution.isUgly(6)); - System.out.println(solution.isUgly(8)); - System.out.println(solution.isUgly(14)); - } -} diff --git a/[268][Missing Number]/src/Solution.java b/[268][Missing Number]/src/Solution.java deleted file mode 100644 index 0ad6903..0000000 --- a/[268][Missing Number]/src/Solution.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-10-10 14:02 - **/ -public class Solution { - public int missingNumber(int[] nums) { - - if (nums == null || nums.length < 1) { - throw new IllegalArgumentException("array should contain at least one element"); - } - - for (int i = 0; i < nums.length; i++) { - // 只会存在一个大于nums.length的数,将其放在数组最后一个位置 - if (nums[i] > nums.length) { - swap(nums, i, nums.length - 1); - } - - // 交换位置,直到nums[i] = i - while (nums[i] != i && nums[i] < nums.length) { - swap(nums, i, nums[i]); - } - } - - // 找出丢失的元素 - for (int i = 0; i < nums.length; i++) { - if (nums[i] != i) { - return i; - } - } - - return nums.length; - } - - private void swap(int[] nums, int x, int y) { - int temp = nums[x]; - nums[x] = nums[y]; - nums[y] = temp; - } -} diff --git a/[268][Missing Number]/src/Test.java b/[268][Missing Number]/src/Test.java deleted file mode 100644 index a4452e8..0000000 --- a/[268][Missing Number]/src/Test.java +++ /dev/null @@ -1,21 +0,0 @@ -import java.util.Arrays; - -/** - * @author: wangjunchao(王俊超) - * @time: 2018-10-10 14:14 - **/ -public class Test { - public static void main(String[] args) { - Solution solution = new Solution(); - - missingNumber(solution, new int[]{0}); - missingNumber(solution, new int[]{3, 0, 1}); - missingNumber(solution, new int[]{9, 6, 4, 2, 3, 5, 7, 0, 1}); - missingNumber(solution, new int[]{8, 6, 4, 2, 3, 5, 7, 0, 1}); - } - - private static void missingNumber(Solution solution, int[] array) { - System.out.println(solution.missingNumber(array)); - System.out.println(Arrays.toString(array)); - } -} diff --git a/[278][First Bad Version]/src/Solution.java b/[278][First Bad Version]/src/Solution.java deleted file mode 100644 index 2f344d1..0000000 --- a/[278][First Bad Version]/src/Solution.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - *
- * The isBadVersion API is defined in the parent class VersionControl.
- *       boolean isBadVersion(int version);
- * 
- * - * @author: wangjunchao(王俊超) - * @time: 2018-10-10 14:26 - **/ -public class Solution extends VersionControl { - public int firstBadVersion(int n) { - - if (!isBadVersion(n)) { - return 0; - } - - int hi = n; - int lo = 1; - int mid; - - while (hi >= lo) { - mid = lo + (hi - lo) / 2; - if (isBadVersion(mid)) { - // 当前是1号版本,或者前一个是合法版本,那么当前版本就是第一个非法的版本 - if (mid == 1 || (mid > 1 && !isBadVersion(mid - 1))) { - return mid; - } else { - // 非法的版本在[lo, mid-1]间 - hi = mid - 1; - } - } else { - // 非法版本在[mid + 1, hi]间 - lo = mid + 1; - } - } - - return 0; - } -} diff --git a/[278][First Bad Version]/src/Test.java b/[278][First Bad Version]/src/Test.java deleted file mode 100644 index 3a57cd6..0000000 --- a/[278][First Bad Version]/src/Test.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-10-10 16:55 - **/ -public class Test { - public static void main(String[] args) { - Solution solution = new Solution(); - - solution.setBadVersion(new boolean[]{false, false, false, true, true}); - System.out.println(solution.firstBadVersion(5)); - } -} diff --git a/[278][First Bad Version]/src/VersionControl.java b/[278][First Bad Version]/src/VersionControl.java deleted file mode 100644 index d124b97..0000000 --- a/[278][First Bad Version]/src/VersionControl.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-10-10 14:27 - **/ -public class VersionControl { - - private boolean[] badVersion; - - public boolean isBadVersion(int version){ - return badVersion[version - 1]; - } - - public boolean[] getBadVersion() { - return badVersion; - } - - public void setBadVersion(boolean[] badVersion) { - this.badVersion = badVersion; - } -} diff --git a/[283][Move Zeroes]/src/Solution.java b/[283][Move Zeroes]/src/Solution.java deleted file mode 100644 index 4afeb4a..0000000 --- a/[283][Move Zeroes]/src/Solution.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-10-10 17:04 - **/ -public class Solution { - public void moveZeroes(int[] nums) { - - if (nums == null || nums.length < 1) { - return; - } - - int idx = 0; - // 找第一个0的位置 - while (idx < nums.length && nums[idx] != 0) { - idx++; - } - - // 数组的值都非0 - if (idx >= nums.length) { - return; - } - - int temp = idx + 1; - - while (temp < nums.length) { - // 找temp开始第一个非0的位置 - while (temp < nums.length && nums[temp] == 0) { - temp++; - } - - // 找到非0值,移动到idx位置 - if (temp < nums.length) { - nums[idx] = nums[temp]; - idx++; - temp++; - } - } - - // 从[idx, nums.length-1]的长度都设置为0 - for (int i = idx; i < nums.length; i++) { - nums[i] = 0; - } - } -} diff --git a/[283][Move Zeroes]/src/Test.java b/[283][Move Zeroes]/src/Test.java deleted file mode 100644 index 1c5d20c..0000000 --- a/[283][Move Zeroes]/src/Test.java +++ /dev/null @@ -1,20 +0,0 @@ -import java.util.Arrays; - -/** - * @author: wangjunchao(王俊超) - * @time: 2018-10-10 17:11 - **/ -public class Test { - public static void main(String[] args) { - moveZeros(new int[]{0, 1, 0, 3, 12}); - moveZeros(new int[]{2, 1, 6, 3, 12}); - moveZeros(new int[]{2}); - moveZeros(new int[]{0}); - } - - private static void moveZeros(int[] a1) { - Solution solution = new Solution(); - solution.moveZeroes(a1); - System.out.println(Arrays.toString(a1)); - } -} diff --git a/[290][Word Pattern]/src/Solution.java b/[290][Word Pattern]/src/Solution.java deleted file mode 100644 index 580d1c2..0000000 --- a/[290][Word Pattern]/src/Solution.java +++ /dev/null @@ -1,48 +0,0 @@ -import java.util.HashMap; -import java.util.Map; - -/** - * @author: wangjunchao(王俊超) - * @time: 2018-10-10 17:24 - **/ -public class Solution { - public boolean wordPattern(String pattern, String str) { - - if (pattern == null && str == null) { - return true; - } else if (pattern == null || str == null) { - return false; - } - - String[] parts = str.split("\\s+"); - - if (pattern.length() != parts.length) { - return false; - } - - Map map = new HashMap<>(); - Map rmap = new HashMap<>(); - - Character c; - for (int i = 0; i < pattern.length(); i++) { - c = pattern.charAt(i); - if (!map.containsKey(c)) { - map.put(c, parts[i]); - } else { - if (!parts[i].equals(map.get(c))) { - return false; - } - } - // 双射,两边都要验证 - if (!rmap.containsKey(parts[i])) { - rmap.put(parts[i], c); - } else { - if (!c.equals(rmap.get(parts[i]))) { - return false; - } - } - } - - return true; - } -} diff --git a/[290][Word Pattern]/src/Test.java b/[290][Word Pattern]/src/Test.java deleted file mode 100644 index 6c75500..0000000 --- a/[290][Word Pattern]/src/Test.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-10-10 17:29 - **/ -public class Test { - public static void main(String[] args) { - Solution solution = new Solution(); - - System.out.println(solution.wordPattern("abba", "dog cat cat dog")); - System.out.println(solution.wordPattern("abba", "dog cat cat fish")); - System.out.println(solution.wordPattern("aaaa", "dog cat cat dog")); - System.out.println(solution.wordPattern("abba", "dog dog dog dog")); - } -} diff --git a/[303][Range Sum Query - Immutable]/src/NumArray.java b/[303][Range Sum Query - Immutable]/src/NumArray.java deleted file mode 100644 index fb70aae..0000000 --- a/[303][Range Sum Query - Immutable]/src/NumArray.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-10-12 13:53 - **/ -public class NumArray { - private int[] nums; - - public NumArray(int[] nums) { - this.nums = nums; - } - - public int sumRange(int i, int j) { - - if (i > j) { - throw new IllegalArgumentException("i = " + i + ", j = " + j +", i must not greater than j"); - } - - if (j < 0) { - throw new IllegalArgumentException("i = " + i + ", j = " + j +", i must not less than 0"); - } - - i = i < 0 ? 0 : i; - j = j >= nums.length ? nums.length - 1 : j; - - int sum = 0; - - - for (int k = i; k <= j; k++) { - sum += nums[k]; - } - - return sum; - } -} diff --git a/[303][Range Sum Query - Immutable]/src/Test.java b/[303][Range Sum Query - Immutable]/src/Test.java deleted file mode 100644 index 470204f..0000000 --- a/[303][Range Sum Query - Immutable]/src/Test.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-10-12 14:17 - **/ -public class Test { - public static void main(String[] args) { - NumArray array = new NumArray(new int[]{-2, 0, 3, -5, 2, -1}); - System.out.println(array.sumRange(0, 2)); - System.out.println(array.sumRange(2, 5)); - System.out.println(array.sumRange(0, 5)); - } -} diff --git a/[326][Power of Three]/src/Solution.java b/[326][Power of Three]/src/Solution.java deleted file mode 100644 index 8ab7b8d..0000000 --- a/[326][Power of Three]/src/Solution.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-11-16 15:21 - **/ -public class Solution { - - public boolean isPowerOfThree(int n) { - double rst = (Math.log10(n) / Math.log10(3)); - return n > 0 &&Double.doubleToLongBits((int)rst) == Double.doubleToLongBits(rst); - } - - public boolean isPowerOfThree2(int n) { - return (n > 0 && 1162261467 % n == 0); - } - - public boolean isPowerOfThree1(int n) { - while (n > 1 && n % 3 == 0) { - n /= 3; - } - - return n == 1; - } - - -} diff --git a/[326][Power of Three]/src/Test.java b/[326][Power of Three]/src/Test.java deleted file mode 100644 index c99e19b..0000000 --- a/[326][Power of Three]/src/Test.java +++ /dev/null @@ -1,13 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-11-16 15:31 - **/ -public class Test { - public static void main(String[] args) { - System.out.println(Double.doubleToLongBits((int)1.00000000001) - == Double.doubleToLongBits(1.00000000001)); - - System.out.println(Double.doubleToLongBits((int)1.00000000000) - == Double.doubleToLongBits(1.00000000000)); - } -} diff --git a/[342][Power of Four]/src/Solution.java b/[342][Power of Four]/src/Solution.java deleted file mode 100644 index 1466de8..0000000 --- a/[342][Power of Four]/src/Solution.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-11-16 15:43 - **/ -public class Solution { - - public boolean isPowerOfFour(int num) { - return num > 0 && (num & (num - 1)) == 0 && (num - 1) % 3 == 0; - } - - - public boolean isPowerOfFour3(int num) { - int n = 0b1010101_01010101_01010101_01010101; -// int n = 0x55555555; - return num > 0 && (num & (num - 1)) == 0 && (num & n) == num; - } - - public boolean isPowerOfFour2(int num) { - double rst = (Math.log10(num) / Math.log10(4)); - return num > 0 && Double.doubleToLongBits((int) rst) == Double.doubleToLongBits(rst); - } - - public boolean isPowerOfFour1(int num) { - while (num > 1 && (num % 4 == 0)) { - num /= 4; - } - return num == 1; - } -} diff --git a/[344][Reverse String]/src/Solution.java b/[344][Reverse String]/src/Solution.java deleted file mode 100644 index 955ed6b..0000000 --- a/[344][Reverse String]/src/Solution.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * @author: wangjunchao(王俊超) - * @time: 2018-11-16 16:04 - **/ -public class Solution { - public String reverseString(String s) { - if (s == null || s.length() < 1) { - return s; - } - - char[] chars = s.toCharArray(); - - for (int i = 0, j = chars.length - 1; i Date: Sun, 23 Jun 2019 15:42:03 +0800 Subject: [PATCH 052/108] commit --- .idea/compiler.xml | 16 + .idea/encodings.xml | 106 ++ .idea/inspectionProfiles/Project_Default.xml | 36 + .idea/leetcode.iml | 17 + .idea/libraries/R_User_Library.xml | 7 + .idea/misc.xml | 13 + .idea/modules.xml | 185 +++ .idea/vcs.xml | 6 + .idea/workspace.xml | 1318 ++++++++++++++++++ 9 files changed, 1704 insertions(+) create mode 100644 .idea/compiler.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/leetcode.iml create mode 100644 .idea/libraries/R_User_Library.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..ab52643 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..33c6539 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..6560a98 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,36 @@ + + + + \ No newline at end of file diff --git a/.idea/leetcode.iml b/.idea/leetcode.iml new file mode 100644 index 0000000..c05462b --- /dev/null +++ b/.idea/leetcode.iml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/R_User_Library.xml b/.idea/libraries/R_User_Library.xml new file mode 100644 index 0000000..2778a36 --- /dev/null +++ b/.idea/libraries/R_User_Library.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..9a339fb --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..2a2afb5 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,185 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..ca0b801 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,1318 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + excludeEnd2 + 28 + *c + 83794 + gray code + gas stat + vec + atoi + /[ + + + ] + nums1.length + nums2.length + nums[a] + nums[b] + nums[c] + array + /[0 + + + $PROJECT_DIR$/[128][Longest Consecutive Sequence]/src + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1560476240942 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1.7 + + + + + + + + \ No newline at end of file diff --git a/[0006][Zig Zag Conversion]/[0006][Zig Zag Conversion].iml b/[0006][Zig Zag Conversion]/[0006][Zig Zag Conversion].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0006][Zig Zag Conversion]/[0006][Zig Zag Conversion].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0006][Zig Zag Conversion]/[0006][ZigZagConversion].iml b/[0006][Zig Zag Conversion]/[0006][ZigZagConversion].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0006][Zig Zag Conversion]/[0006][ZigZagConversion].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0006][Zig Zag Conversion]/src/Solution.java b/[0006][Zig Zag Conversion]/src/Solution.java new file mode 100644 index 0000000..3de4a90 --- /dev/null +++ b/[0006][Zig Zag Conversion]/src/Solution.java @@ -0,0 +1,94 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 16:08 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     *     ԭ
+     * The string PAYPALISHIRING is written in a zigzag pattern on a given number
+     * of rows like this: (you may want to display this pattern in a fixed font for
+     * better legibility)
+     * P A H N
+     * APLSIIG
+     * Y I R
+     * And then read line by line: PAHNAPLSIIGYIR
+     * Write the code that will take a string and make this conversion given a number of rows:
+     * string convert(string text, int nRows);
+     * convert(PAYPALISHIRING,3) should return PAHNAPLSIIGYIR.
+     * Ŀ
+     * һַַָZ
+     *
+     * ˼·
+     * ַһһά飬ټÿַһάеλã
+     * ٶһάеַнղؽ
+     * 
+ * + * @param s + * @param nRows + * @return + */ + public String convert(String s, int nRows) { + + if (s == null || s.length() <= nRows || nRows == 1) { + return s; + } + + int index = s.length(); + int rowLength = 0; // еijȣַ + + int slash = nRows - 2; // һб߳ȥβռõ + + while (index > 0) { + // εһ + index -= nRows; + rowLength++; + + // бŵ + for (int i = 0; i < slash && index > 0; i++) { + rowLength++; + index--; + } + } + + char[] result = new char[nRows * rowLength]; // 飬һڱ滻з + for (int i = 0; i < result.length; i++) { // ʼΪո + result[i] = ' '; + } + + int curColumn = 0; // ǰ + index = 0; + while (index < s.length()) { + // + for (int i = 0; i < nRows && index < s.length(); i++) { + result[rowLength * i + curColumn] = s.charAt(index); + index++; + } + curColumn++; + // б + for (int i = nRows - 2; i > 0 && index < s.length(); i--) { + result[rowLength * i + curColumn] = s.charAt(index); + curColumn++; + index++; + } + } + + // ַнղ + index = 0; + while (index < s.length() && result[index] != ' ') { // ҵһǿոַλ + index++; + } + int next = index + 1; + while (index < s.length()) { + while (next < result.length && result[next] == ' ') { // ҲǿոԪ + next++; + } + result[index] = result[next]; + index++; + next++; + } + return new String(result, 0, index); + } +} diff --git a/[0007][Reverse Integer]/[0007][Reverse Integer].iml b/[0007][Reverse Integer]/[0007][Reverse Integer].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0007][Reverse Integer]/[0007][Reverse Integer].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0007][Reverse Integer]/[0007][ReverseInteger].iml b/[0007][Reverse Integer]/[0007][ReverseInteger].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0007][Reverse Integer]/[0007][ReverseInteger].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0007][Reverse Integer]/src/Solution.java b/[0007][Reverse Integer]/src/Solution.java new file mode 100644 index 0000000..00d3d95 --- /dev/null +++ b/[0007][Reverse Integer]/src/Solution.java @@ -0,0 +1,42 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 16:10 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Reverse digits of an integer.
+     * Example1: x = 123, return 321
+     * Example2: x = -123, return -321
+     *
+     * Ŀ
+     * һзת
+     *
+     * ˼·
+     * ̷ͨв
+     * 
+ * + * @param x + * @return + */ + public int reverse(int x) { + long tmp = x; + // ֹ + long result = 0; + + while (tmp != 0) { + result = result * 10 + tmp % 10; + tmp = tmp / 10; + } + + // ж + if (result < Integer.MIN_VALUE || result > Integer.MAX_VALUE) { + result = 0; + } + + return (int) result; + } +} diff --git a/[0008][String To Integer (atoi)]/[0008][String To Integer (atoi)].iml b/[0008][String To Integer (atoi)]/[0008][String To Integer (atoi)].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0008][String To Integer (atoi)]/[0008][String To Integer (atoi)].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0008][String To Integer (atoi)]/[0008][StringToInteger (atoi)].iml b/[0008][String To Integer (atoi)]/[0008][StringToInteger (atoi)].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0008][String To Integer (atoi)]/[0008][StringToInteger (atoi)].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0008][String To Integer (atoi)]/src/Solution.java b/[0008][String To Integer (atoi)]/src/Solution.java new file mode 100644 index 0000000..6010b26 --- /dev/null +++ b/[0008][String To Integer (atoi)]/src/Solution.java @@ -0,0 +1,104 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 16:13 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Implement atoi to convert a string to an integer.
+     * Hint: Carefully consider all possible input cases. If you want a challenge,
+     * please do not see below and ask yourself what are the possible input cases.
+     * Notes: It is intended for this problem to be specified vaguely (ie, no given
+     * input specs). You are responsible to gather all the input requirements up front.
+     *
+     * Ŀ
+     * ʵһatoiַת
+     * Ҫ㣺е
+     *
+     * ˼·
+     * ǰַ+-ûУֲ֣ܱʾС
+     * ͷضӦССֵ
+     * 
+ * + * @param str + * @return + */ + public int atoi(String str) { + + if (str == null || str.length() == 0) { +// throw new NumberFormatException("Invalid input string: " + str); + return 0; + } + + // ַԿոʼ + int start = 0; //ӿʼҵһǿո + boolean positive = true; // ǷΪĬΪtrue + + if (str.charAt(start) == ' ') { + while (str.charAt(start) == ' ') { + start++; + if (start >= str.length()) { // ȫǿո +// throw new NumberFormatException("Invalid input string: " + str); + return 0; + } + } + } + + if (str.charAt(start) == '-') { // һǿհַ- + positive = false; + start++; + } else if (str.charAt(start) == '+') {// һǿհַ+ + start++; + } else if (str.charAt(start) >= '0' && str.charAt(start) <= '9') { // һǿհַ + return cal(str, start, true); + } else { // ׳쳣 +// throw new NumberFormatException("Invalid input string: " + str); + return 0; + } + + + if (start >= str.length()) { // һǿհַ+-Ҳһַ +// throw new NumberFormatException("Invalid input string: " + str); + return 0; + } + + if (str.charAt(start) > '9' || str.charAt(start) < '0') { // +-ӵIJ +// throw new NumberFormatException("Invalid input string: " + str); + return 0; + } else { + return cal(str, start, positive); + } + } + + private int cal(String str, int start, boolean positive) { + + long result = 0; + while (start < str.length() && str.charAt(start) >= '0' && str.charAt(start) <= '9') { + result = result * 10 + (str.charAt(start) - '0'); + + if (positive) { // + if (result > Integer.MAX_VALUE) { +// throw new NumberFormatException("Invalid input string: " + str); + return Integer.MAX_VALUE; + } + + } else { + if (-result < Integer.MIN_VALUE) { +// throw new NumberFormatException("Invalid input string: " + str); + return Integer.MIN_VALUE; + } + } + + start++; + } + + if (positive) { + return (int) result; + } else { + return (int) -result; + } + } +} diff --git a/[0009][Palindrome Number]/[0009][Palindrome Number].iml b/[0009][Palindrome Number]/[0009][Palindrome Number].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0009][Palindrome Number]/[0009][Palindrome Number].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0009][Palindrome Number]/[0009][PalindromeNumber].iml b/[0009][Palindrome Number]/[0009][PalindromeNumber].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0009][Palindrome Number]/[0009][PalindromeNumber].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0009][Palindrome Number]/src/Main.java b/[0009][Palindrome Number]/src/Main.java new file mode 100644 index 0000000..e04c77b --- /dev/null +++ b/[0009][Palindrome Number]/src/Main.java @@ -0,0 +1,13 @@ +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-16 11:06 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + System.out.println(solution.isPalindrome(123321)); + } +} diff --git a/[0009][Palindrome Number]/src/Solution.java b/[0009][Palindrome Number]/src/Solution.java new file mode 100644 index 0000000..318a64d --- /dev/null +++ b/[0009][Palindrome Number]/src/Solution.java @@ -0,0 +1,46 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 16:52 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Determine whether an integer is a palindrome. Do this without extra space.
+     *
+     * Ŀ
+     * жһǷǻطҪʹöĿռ䡣
+     *
+     * ˼·
+     * Ϊ˲ʹöĿռ䣬οĽЩⷨisPalindromeûʹö
+     * ȴʹ˷ãһĵĿռ ûдﵽĿҪǼٵʵ֣
+     * ԱȻһĿռʵ֡
+     *  ȣǻ֣ζֽת123321任˵ǻ֡
+     * 
+ * + * @param x + * @return + */ + public boolean isPalindrome(int x) { + + // ǻط + if (x < 0) { + return false; + } + + // תֵΪ˲ʹlong + long reverse = 0; + int tmp = x; + + // תֵ + while (tmp != 0) { + reverse = reverse * 10 + tmp % 10; + tmp /= 10; + } + + // жǷǻ + return x == reverse; + } +} diff --git a/[0010][Regular Expression Matching]/[0010][Regular Expression Matching].iml b/[0010][Regular Expression Matching]/[0010][Regular Expression Matching].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0010][Regular Expression Matching]/[0010][Regular Expression Matching].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0010][Regular Expression Matching]/src/Main.java b/[0010][Regular Expression Matching]/src/Main.java new file mode 100644 index 0000000..8d9da5d --- /dev/null +++ b/[0010][Regular Expression Matching]/src/Main.java @@ -0,0 +1,12 @@ +/** + * Author: + * Date: 2015-06-24 + * Time: 21:34 + * Declaration: All Rights Reserved !!! + */ +public class Main { + public static void main(String[] args) { + Solution solution = new Solution(); + System.out.println(solution.isMatch("aa", "a*")); + } +} diff --git a/[0010][Regular Expression Matching]/src/Solution.java b/[0010][Regular Expression Matching]/src/Solution.java new file mode 100644 index 0000000..b462e2f --- /dev/null +++ b/[0010][Regular Expression Matching]/src/Solution.java @@ -0,0 +1,120 @@ +import java.util.Arrays; + +/** + * Author: + * Date: 2015-06-24 + * Time: 20:42 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Implement regular expression matching with support for '.' and '*'.
+     * '.' Matches any single character.
+     * '*' Matches zero or more of the preceding element.
+     *
+     * The matching should cover the entire input string (not partial).
+     *
+     * The function prototype should be:
+     * bool isMatch(const char *s, const char *p)
+     * Some examples:
+     * isMatch("aa","a")  false
+     * isMatch("aa","aa")  true
+     * isMatch("aaa","aa")  false
+     * isMatch("aa", "a*")  true
+     * isMatch("aa", ".*")  true
+     * isMatch("ab", ".*")  true
+     * isMatch("aab", "c*a*b")  true
+     *
+     * Ŀ⣺
+     * ʵһʽƥ㷨.ƥһַ*ƥ0߶ǰַ
+     *
+     * Կ˼·
+     * ע
+     *
+     * 
+ * + * @param s + * @param p + * @return + */ + public boolean isMatch(String s, String p) { + boolean[] match = new boolean[s.length() + 1]; + Arrays.fill(match, false); + match[s.length()] = true; + for (int i = p.length() - 1; i >= 0; i--) { + if (p.charAt(i) == '*') { + for (int j = s.length() - 1; j >= 0; j--) { + match[j] = match[j] || match[j + 1] + && (p.charAt(i - 1) == '.' || s.charAt(j) == p.charAt(i - 1)); + } + i--; + } else { + for (int j = 0; j < s.length(); j++) { + match[j] = match[j + 1] + && (p.charAt(i) == '.' || p.charAt(i) == s.charAt(j)); + } + + match[s.length()] = false; + } + } + return match[0]; + } + + // ĴʱȽϳ + public boolean isMatch2(String s, String p) { + // 붼Ϊnull + if (s == null && p == null) { + return true; + } + // һΪnull + else if (s == null || p == null) { + return false; + } + + return isMatch(s, 0, p, 0); + } + + /** + * ʽƥ + * + * @param s ƥ䴮 + * @param sIdx ǰƥλ + * @param p ģʽ + * @param pIdx ģʽƥλ + * @return ƥ + */ + public boolean isMatch(String s, int sIdx, String p, int pIdx) { + // ͬʱԵĩβ + if (s.length() == sIdx && p.length() == pIdx) { + return true; + } + // ƥ䴮ûеĩβģʽѾĩβ + else if (s.length() != sIdx && p.length() == pIdx) { + return false; + } + // + else { + // ǰƥһַ* + if (pIdx < p.length() - 1 && p.charAt(pIdx + 1) == '*') { + // ƥ䴮δҵǰַƥ䣨ַȻ.ţ + if (sIdx < s.length() && (s.charAt(sIdx) == p.charAt(pIdx) || p.charAt(pIdx) == '.')) { + return isMatch(s, sIdx + 1, p, pIdx + 2) // ƥ䴮ǰƶһַֻƥһΣ + || isMatch(s, sIdx + 1, p, pIdx) // ƥ䴮ǰƶһַһƥͬģģʽ + || isMatch(s, sIdx, p, pIdx + 2); // ƥģʽ + } else { + // * + return isMatch(s, sIdx, p, pIdx + 2); + } + } + + // ƥһַ + if (sIdx < s.length() && (s.charAt(sIdx) == p.charAt(pIdx) || p.charAt(pIdx) == '.')) { + return isMatch(s, sIdx + 1, p, pIdx + 1); + } + } + + return false; + } + +} diff --git a/[0011][Container With Most Water]/[0011][Container With Most Water].iml b/[0011][Container With Most Water]/[0011][Container With Most Water].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0011][Container With Most Water]/[0011][Container With Most Water].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0011][Container With Most Water]/[0011][ContainerWithMost Water].iml b/[0011][Container With Most Water]/[0011][ContainerWithMost Water].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0011][Container With Most Water]/[0011][ContainerWithMost Water].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0011][Container With Most Water]/src/Solution.java b/[0011][Container With Most Water]/src/Solution.java new file mode 100644 index 0000000..7a40cf8 --- /dev/null +++ b/[0011][Container With Most Water]/src/Solution.java @@ -0,0 +1,88 @@ +/** + * Author: + * Date: 2015-06-30 + * Time: 07:25 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Given n non-negative integers a1, a2, ..., an, where each represents
+     * a point at coordinate (i, ai). n vertical lines are drawn such that
+     * the two endpoints of line i is at (i, ai) and (i, 0). Find two lines,
+     * which together with x-axis forms a container, such that the container
+     * contains the most water.
+     *
+     * Note: You may not slant the container.
+     *
+     * Ŀ⣺
+     * ȻԼXṹɵˮ
+     *
+     * ˼·
+     * ʹ̰㷨
+     *      1.ȼҵȡݻΪ i, j (ٶi aj) 
+     *          ô   ak > aj min(ai, aj, ak) =min(ai, aj) 
+     *          i, kɵݻC' = min(ai, aj) * (k - i) > C
+     *          CֵìܣԵ֤jĺ߲бߵߣ
+     *
+     *          :ͬiҲбߵߣ˵ʲôأ
+     *          Ŀǰõĺѡ Ϊ x, yߣx< y)ôܹõ
+     *          ݻµ߱Ȼ[x, y]ڲ ax' >= ax , ay' >= ay;
+     *
+     *      3.Ǵͷм俿£ͬʱºѡֵʱȴ
+     *      x, yнСı߿ʼ
+     * 
+ * + * @param height + * @return + */ + public int maxArea(int[] height) { + + // У + if (height == null || height.length < 2) { + return 0; + } + + + // ¼Ľ + int result = 0; + + // ߵ + int left = 0; + // ұߵ + int right = height.length - 1; + + while (left < right) { + // 㵱ǰֵ + result = Math.max(result, Math.min(height[left], height[right]) * (right - left)); + // ұ߸ + if (height[left] < height[right]) { + int k = left; + // [left, right - 1]Уңҵһ߶ȱheight[left]ߵλ + while (k < right && height[k] <= height[left]) { + k++; + } + + // [left, right - 1]У¼һԭheight[left]ߵλ + left = k; + } + // ߵ߸ + else { + int k = right; + // [left + 1, right]Уңҵһ߶ȱheight[right]ߵλ + while (k > left && height[k] <= height[right]) { + k--; + } + + // [left, right - 1]У¼һԭheight[right]ߵλ + right = k; + } + } + + return result; + } +} diff --git a/[0012][Integer To Roman]/[0012][Integer To Roman].iml b/[0012][Integer To Roman]/[0012][Integer To Roman].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0012][Integer To Roman]/[0012][Integer To Roman].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0012][Integer To Roman]/src/Main.java b/[0012][Integer To Roman]/src/Main.java new file mode 100644 index 0000000..395df1b --- /dev/null +++ b/[0012][Integer To Roman]/src/Main.java @@ -0,0 +1,39 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-17 14:03 + **/ +public class Main { + + @Test + public void test1() { + Solution2 solution = new Solution2(); + Assert.assertEquals("III", solution.intToRoman(3)); + } + + @Test + public void test2() { + Solution2 solution = new Solution2(); + Assert.assertEquals("IV", solution.intToRoman(4)); + } + + @Test + public void test3() { + Solution2 solution = new Solution2(); + Assert.assertEquals("IX", solution.intToRoman(9)); + } + + @Test + public void test4() { + Solution2 solution = new Solution2(); + Assert.assertEquals("LVIII", solution.intToRoman(58)); + } + + @Test + public void test5() { + Solution2 solution = new Solution2(); + Assert.assertEquals("MCMXCIV", solution.intToRoman(1994)); + } +} diff --git a/[0012][Integer To Roman]/src/Solution.java b/[0012][Integer To Roman]/src/Solution.java new file mode 100644 index 0000000..2224976 --- /dev/null +++ b/[0012][Integer To Roman]/src/Solution.java @@ -0,0 +1,65 @@ +/** + * Author: + * Date: 2015-06-30 + * Time: 14:28 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Given an integer, convert it to a roman numeral.
+     *
+     * Input is guaranteed to be within the range from 1 to 3999.
+     *
+     * ֵıʾ
+     * λ
+     * (I, 1)  (II, 2)  (III, 3)  (IV, 4)  (V, 5)  (VI, 6)  (VII, 7)  (VIII, 8)  (IX, 9)
+     *
+     * ʮλ
+     * (X, 10)  (XI, 11)  (XII, 12)  (XIII, 13)  (XIV, 14)  (XV, 15)  (XVI, 16)
+     * (XVII, 17)  (XVIII, 18)  (XIX, 19)  (XX, 20)  (XXI, 21)  (XXII, 22)
+     * (XXIX, 29)  (XXX, 30)  (XXXIV, 34)  (XXXV, 35)  (XXXIX, 39)  (XL, 40)
+     * (L, 50)  (LI, 51)  (LV, 55)  (LX, 60)  (LXV, 65)  (LXXX, 80)  (XC, 90)
+     * (XCIII, 93)  (XCV, 95)  (XCVIII, 98)  (XCIX, 99)
+     *
+     * λ
+     * (C, 100)  (CC, 200)  (CCC, 300)  (CD, 400)  (D, 500)  (DC, 600)  (DCC, 700)
+     * (DCCC, 800)  (CM, 900)  (CMXCIX, 999)
+     *
+     * ǧλ
+     * (M, 1000)  (MC, 1100)  (MCD, 1400)  (MD, 1500)  (MDC, 1600)  (MDCLXVI, 1666)
+     * (MDCCCLXXXVIII, 1888)  (MDCCCXCIX, 1899)  (MCM, 1900)  (MCMLXXVI, 1976)
+     * (MCMLXXXIV, 1984)  (MCMXC, 1990)  (MM, 2000)  (MMMCMXCIX, 3999)
+     *
+     * Ŀ⣺
+     * һ֣תһ֣[1, 3999]֮
+     *
+     * 
+ * + * @param num + * @return + */ + public String intToRoman(int num) { + + String[][] base = new String[][]{ + {"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"}, // λıʾ + {"X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"}, // ʮλıʾ + {"C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"}, // ٱıʾ + {"M", "MM", "MMM", "", "", "", "", "", ""}}; // ǧλıʾ + + + String result = ""; + + // ÿһξʾһλС + // i¼ǰǵڼλ + for (int i = 0; num != 0; num /= 10, i++) { + // Ϊ0˵λֵҪӲ + if (num % 10 != 0) { + // ƴӽ + result = base[i][num % 10 - 1] + result; + } + } + + return result; + } +} diff --git a/[0012][Integer To Roman]/src/Solution2.java b/[0012][Integer To Roman]/src/Solution2.java new file mode 100644 index 0000000..f13fad7 --- /dev/null +++ b/[0012][Integer To Roman]/src/Solution2.java @@ -0,0 +1,56 @@ +/** + * Author: + * Date: 2015-06-30 + * Time: 14:28 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + /** + *
+     * Given an integer, convert it to a roman numeral.
+     *
+     * Input is guaranteed to be within the range from 1 to 3999.
+     *
+     * ֵıʾ
+     * λ
+     * (I, 1)  (II, 2)  (III, 3)  (IV, 4)  (V, 5)  (VI, 6)  (VII, 7)  (VIII, 8)  (IX, 9)
+     *
+     * ʮλ
+     * (X, 10)  (XI, 11)  (XII, 12)  (XIII, 13)  (XIV, 14)  (XV, 15)  (XVI, 16)
+     * (XVII, 17)  (XVIII, 18)  (XIX, 19)  (XX, 20)  (XXI, 21)  (XXII, 22)
+     * (XXIX, 29)  (XXX, 30)  (XXXIV, 34)  (XXXV, 35)  (XXXIX, 39)  (XL, 40)
+     * (L, 50)  (LI, 51)  (LV, 55)  (LX, 60)  (LXV, 65)  (LXXX, 80)  (XC, 90)
+     * (XCIII, 93)  (XCV, 95)  (XCVIII, 98)  (XCIX, 99)
+     *
+     * λ
+     * (C, 100)  (CC, 200)  (CCC, 300)  (CD, 400)  (D, 500)  (DC, 600)  (DCC, 700)
+     * (DCCC, 800)  (CM, 900)  (CMXCIX, 999)
+     *
+     * ǧλ
+     * (M, 1000)  (MC, 1100)  (MCD, 1400)  (MD, 1500)  (MDC, 1600)  (MDCLXVI, 1666)
+     * (MDCCCLXXXVIII, 1888)  (MDCCCXCIX, 1899)  (MCM, 1900)  (MCMLXXVI, 1976)
+     * (MCMLXXXIV, 1984)  (MCMXC, 1990)  (MM, 2000)  (MMMCMXCIX, 3999)
+     *
+     * Ŀ⣺
+     * һ֣תһ֣[1, 3999]֮
+     *
+     * 
+ * + * @param num + * @return + */ + public String intToRoman(int num) { + + final int[] radix = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}; + final String[] symbol = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"}; + String roman = ""; + for (int i = 0; num > 0; ++i) { + int count = num / radix[i]; + num %= radix[i]; + for (; count > 0; --count) { + roman += symbol[i]; + } + } + return roman; + } +} diff --git a/[0013][Romar To Integer]/[0013][Romar To Integer].iml b/[0013][Romar To Integer]/[0013][Romar To Integer].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0013][Romar To Integer]/[0013][Romar To Integer].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0013][Romar To Integer]/src/Main.java b/[0013][Romar To Integer]/src/Main.java new file mode 100644 index 0000000..5d7ae8a --- /dev/null +++ b/[0013][Romar To Integer]/src/Main.java @@ -0,0 +1,37 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * Author: 王俊超 + * Date: 2015-03-01 + * Time: 16:35 + * Declaration: All Rights Reserved !!! + */ +public class Main { + public static void main(String[] args) { + Solution solution = new Solution(); + + System.out.println(solution.romanToInt("I")); + System.out.println(solution.romanToInt("II")); + System.out.println(solution.romanToInt("III")); + System.out.println(solution.romanToInt("IV")); + System.out.println(solution.romanToInt("V")); + System.out.println(solution.romanToInt("VI")); + + System.out.println(solution.romanToInt("XCVIII")); + System.out.println(solution.romanToInt("XCIX")); + + System.out.println(solution.romanToInt("CM")); + System.out.println(solution.romanToInt("CMXCIX")); + + System.out.println(solution.romanToInt("MDCLXVI")); + System.out.println(solution.romanToInt("MCMLXXVI")); + System.out.println(solution.romanToInt("MMMCMXCIX")); + } + + @Test + public void test1() { + Solution solution = new Solution(); + Assert.assertEquals(1994, solution.romanToInt("MCMXCIV")); + } +} diff --git a/[0013][Romar To Integer]/src/Solution.java b/[0013][Romar To Integer]/src/Solution.java new file mode 100644 index 0000000..f47e222 --- /dev/null +++ b/[0013][Romar To Integer]/src/Solution.java @@ -0,0 +1,55 @@ +/** + * Author: 王俊超 + * Date: 2015-03-01 + * Time: 16:09 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * 原题
+     * Given a roman numeral, convert it to an integer.
+     * Input is guaranteed to be within the range from 1 to 3999.
+     *
+     * 题目大意
+     * 给定一个罗马数字,将其转换成对应的整数。
+     * 输入的数字在1-3999之间。
+     *
+     * 解题思路
+     * 从前往后扫描,用一个临时变量记录分段数字。
+     * 如果当前比前一个大,说明这一段的值应该是当前这个值减去上一个值。比如IV = 5 – 1;否
+     * 则,将当前值加入到结果中,然后开始下一段记录。比如VI = 5 + 1, II=1+1
+     * 
+ * + * @param s + * @return + */ + public int romanToInt(String s) { + + int result = 0; + + for (int i = 0; i < s.length(); i++) { + // 当前的值比前一个值大,说明[i-1, i]组成一个值,并且值是s[i-1]-s[i] + if (i > 0 && charToInt(s.charAt(i)) > charToInt(s.charAt(i - 1))) { + // 要减去两倍之前前值才能回到真实值 + result += charToInt(s.charAt(i)) - 2 * charToInt(s.charAt(i - 1)); + } else { + result += charToInt(s.charAt(i)); + } + } + + return result; + } + private int charToInt(char c) { + switch (c) { + case 'I': return 1; + case 'V': return 5; + case 'X': return 10; + case 'L': return 50; + case 'C': return 100; + case 'D': return 500; + case 'M': return 1000; + default: return 0; + } + } +} diff --git a/[0013][Romar To Integer]/src/Solution2.java b/[0013][Romar To Integer]/src/Solution2.java new file mode 100644 index 0000000..9d08f55 --- /dev/null +++ b/[0013][Romar To Integer]/src/Solution2.java @@ -0,0 +1,98 @@ +/** + * Author: 王俊超 + * Date: 2015-03-01 + * Time: 16:09 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + /** + *
+     * 原题
+     * Given a roman numeral, convert it to an integer.
+     * Input is guaranteed to be within the range from 1 to 3999.
+     *
+     * 题目大意
+     * 给定一个罗马数字,将其转换成对应的整数。
+     * 输入的数字在1-3999之间。
+     *
+     * 解题思路
+     * 根据罗马数字与整数数字对应关系进行加法操作,如果前一个数字比后一个大就相减,否则进行相加。
+     * 
+ * + * @param s + * @return + */ + public int romanToInt(String s) { + + int result = 0; + int prev = 0; // 记录前一个数字的值 + + for (int i = s.length() - 1; i > -1; i--) { + switch (s.charAt(i)) { + case 'I': // 1 + if (1 < prev) { + result -= 1; + } else { + result += 1; + + } + prev = 1; + break; + + case 'V': // 5 + + if (5 < prev) { + result -= 5; + } else { + result += 5; + } + + prev = 5; + + break; + case 'X': // 10 + if (10 < prev) { + result -= 10; + } else { + result += 10; + } + + prev = 10; + break; + case 'L': // 50 + if (50 < prev) { + result -= 50; + } else { + result += 50; + } + + prev = 50; + break; + case 'C': // 100 + if (100 < prev) { + result -= 100; + } else { + result += 100; + } + + prev = 100; + break; + case 'D': // 500 + if (500 < prev) { + result -= 500; + } else { + result += 500; + } + + prev = 500; + break; + case 'M': // 1000 + result += 1000; + prev = 1000; + break; + } + } + + return result; + } +} diff --git a/[0014][Longest Common Prefix]/[0014][Longest Common Prefix].iml b/[0014][Longest Common Prefix]/[0014][Longest Common Prefix].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0014][Longest Common Prefix]/[0014][Longest Common Prefix].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0014][Longest Common Prefix]/src/Main.java b/[0014][Longest Common Prefix]/src/Main.java new file mode 100644 index 0000000..5a40b00 --- /dev/null +++ b/[0014][Longest Common Prefix]/src/Main.java @@ -0,0 +1,20 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-17 13:05 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + Assert.assertEquals("fl", solution.longestCommonPrefix(new String[]{"flower", "flow", "flight"})); + } + + @Test + public void test2() { + Solution solution = new Solution(); + Assert.assertEquals("", solution.longestCommonPrefix(new String[]{"dog","racecar","car"})); + } +} diff --git a/[0014][Longest Common Prefix]/src/Solution.java b/[0014][Longest Common Prefix]/src/Solution.java new file mode 100644 index 0000000..c7fd1ef --- /dev/null +++ b/[0014][Longest Common Prefix]/src/Solution.java @@ -0,0 +1,59 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 16:19 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Write a function to find the longest common prefix string amongst an array of strings.
+     *
+     * Ŀ
+     * дһҳһִеĹǰ׺
+     *
+     * ˼·
+     * һҳСַȻַַҳ̵ǰ׺
+     * 
+ * + * @param strs + * @return + */ + public String longestCommonPrefix(String[] strs) { + if (strs == null) { + return null; + } + + if (strs.length == 0) { + return ""; + } + + // ¼̵ַij + int min = Integer.MAX_VALUE; + + // Ҷַij + String result = ""; + for (String str : strs) { + + if (str == null || str.length() == 0) { + return ""; + } + + if (min > str.length()) { + min = str.length(); + result = str; + } + } + + for (String s: strs) { + for (int i = 0; i < result.length(); i++) { + if (result.charAt(i) != s.charAt(i)) { + result = result.substring(0, i); + } + } + } + + return result; + } +} diff --git a/[0014][Longest Common Prefix]/src/Solution2.java b/[0014][Longest Common Prefix]/src/Solution2.java new file mode 100644 index 0000000..17eb282 --- /dev/null +++ b/[0014][Longest Common Prefix]/src/Solution2.java @@ -0,0 +1,65 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 16:19 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + /** + *
+     * ԭ
+     * Write a function to find the longest common prefix string amongst an array of strings.
+     *
+     * Ŀ
+     * дһҳһִеĹǰ׺
+     *
+     * ˼·
+     * һҳСַȻַַҳ̵ǰ׺
+     * 
+ * + * @param strs + * @return + */ + public String longestCommonPrefix(String[] strs) { + if (strs == null) { + return null; + } + + if (strs.length == 0) { + return ""; + } + + // ¼̵ַij + int min = Integer.MAX_VALUE; + + // Ҷַij + for (String str : strs) { + + if (str == null) { + return null; + } + + if (min > str.length()) { + min = str.length(); + } + } + + int i; // ¼ǰ׺ַ + boolean flag; + for (i = 0; i < min; i++) { + flag = true; + for (int j = 1; j < strs.length; j++) { + if (strs[0].charAt(i) != strs[j].charAt(i)) { + flag = false; + break; + } + } + + if (!flag) { + break; + } + } + + return strs[0].substring(0, i); + } +} diff --git a/[0015][3 Sum]/[0015][3 Sum].iml b/[0015][3 Sum]/[0015][3 Sum].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0015][3 Sum]/[0015][3 Sum].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0015][3 Sum]/src/Main.java b/[0015][3 Sum]/src/Main.java new file mode 100644 index 0000000..fc64650 --- /dev/null +++ b/[0015][3 Sum]/src/Main.java @@ -0,0 +1,53 @@ +import org.junit.Test; + +/** + * Author: + * Date: 2015-06-20 + * Time: 22:56 + * Declaration: All Rights Reserved !!! + */ +public class Main { + + @Test + public void test0() { + Solution solution = new Solution(); + System.out.println(solution.threeSum(new int[]{0, 0, 0})); + } + + @Test + public void test1() { + Solution solution = new Solution(); + System.out.println(solution.threeSum(new int[]{0, 0, 0, 0})); + } + + @Test + public void test2() { + Solution solution = new Solution(); + System.out.println(solution.threeSum(new int[]{1, -1, -1, 0})); + } + + @Test + public void test3() { + Solution solution = new Solution(); + System.out.println(solution.threeSum(new int[]{-2, 0, 1, 1, 2})); + } + + @Test + public void test4() { + Solution solution = new Solution(); + System.out.println(solution.threeSum(new int[]{-1, 0, 1, 2, -1, -4})); + } + + @Test + public void test5() { + Solution solution = new Solution(); + System.out.println(solution.threeSum(new int[]{82597,-9243,62390,83030,-97960,-26521,-61011,83390,-38677,12333,75987,46091,83794,19355,-71037,-6242,-28801,324,1202,-90885,-2989,-95597,-34333,35528,5680,89093,-90606,50360,-29393,-27012,53313,65213,99818,-82405,-41661,-3333,-51952,72135,-1523,26377,74685,96992,92263,15929,5467,-99555,-43348,-41689,-60383,-3990,32165,65265,-72973,-58372,12741,-48568,-46596,72419,-1859,34153,62937,81310,-61823,-96770,-54944,8845,-91184,24208,-29078,31495,65258,14198,85395,70506,-40908,56740,-12228,-40072,32429,93001,68445,-73927,25731,-91859,-24150,10093,-60271,-81683,-18126,51055,48189,-6468,25057,81194,-58628,74042,66158,-14452,-49851,-43667,11092,39189,-17025,-79173,13606,83172,92647,-59741,19343,-26644,-57607,82908,-20655,1637,80060,98994,39331,-31274,-61523,91225,-72953,13211,-75116,-98421,-41571,-69074,99587,39345,42151,-2460,98236,15690,-52507,-95803,-48935,-46492,-45606,-79254,-99851,52533,73486,39948,-7240,71815,-585,-96252,90990,-93815,93340,-71848,58733,-14859,-83082,-75794,-82082,-24871,-15206,91207,-56469,-93618,67131,-8682,75719,87429,-98757,-7535,-24890,-94160,85003,33928,75538,97456,-66424,-60074,-8527,-28697,-22308,2246,-70134,-82319,-10184,87081,-34949,-28645,-47352,-83966,-60418,-15293,-53067,-25921,55172,75064,95859,48049,34311,-86931,-38586,33686,-36714,96922,76713,-22165,-80585,-34503,-44516,39217,-28457,47227,-94036,43457,24626,-87359,26898,-70819,30528,-32397,-69486,84912,-1187,-98986,-32958,4280,-79129,-65604,9344,58964,50584,71128,-55480,24986,15086,-62360,-42977,-49482,-77256,-36895,-74818,20,3063,-49426,28152,-97329,6086,86035,-88743,35241,44249,19927,-10660,89404,24179,-26621,-6511,57745,-28750,96340,-97160,-97822,-49979,52307,79462,94273,-24808,77104,9255,-83057,77655,21361,55956,-9096,48599,-40490,-55107,2689,29608,20497,66834,-34678,23553,-81400,-66630,-96321,-34499,-12957,-20564,25610,-4322,-58462,20801,53700,71527,24669,-54534,57879,-3221,33636,3900,97832,-27688,-98715,5992,24520,-55401,-57613,-69926,57377,-77610,20123,52174,860,60429,-91994,-62403,-6218,-90610,-37263,-15052,62069,-96465,44254,89892,-3406,19121,-41842,-87783,-64125,-56120,73904,-22797,-58118,-4866,5356,75318,46119,21276,-19246,-9241,-97425,57333,-15802,93149,25689,-5532,95716,39209,-87672,-29470,-16324,-15331,27632,-39454,56530,-16000,29853,46475,78242,-46602,83192,-73440,-15816,50964,-36601,89758,38375,-40007,-36675,-94030,67576,46811,-64919,45595,76530,40398,35845,41791,67697,-30439,-82944,63115,33447,-36046,-50122,-34789,43003,-78947,-38763,-89210,32756,-20389,-31358,-90526,-81607,88741,86643,98422,47389,-75189,13091,95993,-15501,94260,-25584,-1483,-67261,-70753,25160,89614,-90620,-48542,83889,-12388,-9642,-37043,-67663,28794,-8801,13621,12241,55379,84290,21692,-95906,-85617,-17341,-63767,80183,-4942,-51478,30997,-13658,8838,17452,-82869,-39897,68449,31964,98158,-49489,62283,-62209,-92792,-59342,55146,-38533,20496,62667,62593,36095,-12470,5453,-50451,74716,-17902,3302,-16760,-71642,-34819,96459,-72860,21638,47342,-69897,-40180,44466,76496,84659,13848,-91600,-90887,-63742,-2156,-84981,-99280,94326,-33854,92029,-50811,98711,-36459,-75555,79110,-88164,-97397,-84217,97457,64387,30513,-53190,-83215,252,2344,-27177,-92945,-89010,82662,-11670,86069,53417,42702,97082,3695,-14530,-46334,17910,77999,28009,-12374,15498,-46941,97088,-35030,95040,92095,-59469,-24761,46491,67357,-66658,37446,-65130,-50416,99197,30925,27308,54122,-44719,12582,-99525,-38446,-69050,-22352,94757,-56062,33684,-40199,-46399,96842,-50881,-22380,-65021,40582,53623,-76034,77018,-97074,-84838,-22953,-74205,79715,-33920,-35794,-91369,73421,-82492,63680,-14915,-33295,37145,76852,-69442,60125,-74166,74308,-1900,-30195,-16267,-60781,-27760,5852,38917,25742,-3765,49097,-63541,98612,-92865,-30248,9612,-8798,53262,95781,-42278,-36529,7252,-27394,-5021,59178,80934,-48480,-75131,-54439,-19145,-48140,98457,-6601,-51616,-89730,78028,32083,-48904,16822,-81153,-8832,48720,-80728,-45133,-86647,-4259,-40453,2590,28613,50523,-4105,-27790,-74579,-17223,63721,33489,-47921,97628,-97691,-14782,-65644,18008,-93651,-71266,80990,-76732,-47104,35368,28632,59818,-86269,-89753,34557,-92230,-5933,-3487,-73557,-13174,-43981,-43630,-55171,30254,-83710,-99583,-13500,71787,5017,-25117,-78586,86941,-3251,-23867,-36315,75973,86272,-45575,77462,-98836,-10859,70168,-32971,-38739,-12761,93410,14014,-30706,-77356,-85965,-62316,63918,-59914,-64088,1591,-10957,38004,15129,-83602,-51791,34381,-89382,-26056,8942,5465,71458,-73805,-87445,-19921,-80784,69150,-34168,28301,-68955,18041,6059,82342,9947,39795,44047,-57313,48569,81936,-2863,-80932,32976,-86454,-84207,33033,32867,9104,-16580,-25727,80157,-70169,53741,86522,84651,68480,84018,61932,7332,-61322,-69663,76370,41206,12326,-34689,17016,82975,-23386,39417,72793,44774,-96259,3213,79952,29265,-61492,-49337,14162,65886,3342,-41622,-62659,-90402,-24751,88511,54739,-21383,-40161,-96610,-24944,-602,-76842,-21856,69964,43994,-15121,-85530,12718,13170,-13547,69222,62417,-75305,-81446,-38786,-52075,-23110,97681,-82800,-53178,11474,35857,94197,-58148,-23689,32506,92154,-64536,-73930,-77138,97446,-83459,70963,22452,68472,-3728,-25059,-49405,95129,-6167,12808,99918,30113,-12641,-26665,86362,-33505,50661,26714,33701,89012,-91540,40517,-12716,-57185,-87230,29914,-59560,13200,-72723,58272,23913,-45586,-96593,-26265,-2141,31087,81399,92511,-34049,20577,2803,26003,8940,42117,40887,-82715,38269,40969,-50022,72088,21291,-67280,-16523,90535,18669,94342,-39568,-88080,-99486,-20716,23108,-28037,63342,36863,-29420,-44016,75135,73415,16059,-4899,86893,43136,-7041,33483,-67612,25327,40830,6184,61805,4247,81119,-22854,-26104,-63466,63093,-63685,60369,51023,51644,-16350,74438,-83514,99083,10079,-58451,-79621,48471,67131,-86940,99093,11855,-22272,-67683,-44371,9541,18123,37766,-70922,80385,-57513,-76021,-47890,36154,72935,84387,-92681,-88303,-7810,59902,-90,-64704,-28396,-66403,8860,13343,33882,85680,7228,28160,-14003,54369,-58893,92606,-63492,-10101,64714,58486,29948,-44679,-22763,10151,-56695,4031,-18242,-36232,86168,-14263,9883,47124,47271,92761,-24958,-73263,-79661,-69147,-18874,29546,-92588,-85771,26451,-86650,-43306,-59094,-47492,-34821,-91763,-47670,33537,22843,67417,-759,92159,63075,94065,-26988,55276,65903,30414,-67129,-99508,-83092,-91493,-50426,14349,-83216,-76090,32742,-5306,-93310,-60750,-60620,-45484,-21108,-58341,-28048,-52803,69735,78906,81649,32565,-86804,-83202,-65688,-1760,89707,93322,-72750,84134,71900,-37720,19450,-78018,22001,-23604,26276,-21498,65892,-72117,-89834,-23867,55817,-77963,42518,93123,-83916,63260,-2243,-97108,85442,-36775,17984,-58810,99664,-19082,93075,-69329,87061,79713,16296,70996,13483,-74582,49900,-27669,-40562,1209,-20572,34660,83193,75579,7344,64925,88361,60969,3114,44611,-27445,53049,-16085,-92851,-53306,13859,-33532,86622,-75666,-18159,-98256,51875,-42251,-27977,-18080,23772,38160,41779,9147,94175,99905,-85755,62535,-88412,-52038,-68171,93255,-44684,-11242,-104,31796,62346,-54931,-55790,-70032,46221,56541,-91947,90592,93503,4071,20646,4856,-63598,15396,-50708,32138,-85164,38528,-89959,53852,57915,-42421,-88916,-75072,67030,-29066,49542,-71591,61708,-53985,-43051,28483,46991,-83216,80991,-46254,-48716,39356,-8270,-47763,-34410,874,-1186,-7049,28846,11276,21960,-13304,-11433,-4913,55754,79616,70423,-27523,64803,49277,14906,-97401,-92390,91075,70736,21971,-3303,55333,-93996,76538,54603,-75899,98801,46887,35041,48302,-52318,55439,24574,14079,-24889,83440,14961,34312,-89260,-22293,-81271,-2586,-71059,-10640,-93095,-5453,-70041,66543,74012,-11662,-52477,-37597,-70919,92971,-17452,-67306,-80418,7225,-89296,24296,86547,37154,-10696,74436,-63959,58860,33590,-88925,-97814,-83664,85484,-8385,-50879,57729,-74728,-87852,-15524,-91120,22062,28134,80917,32026,49707,-54252,-44319,-35139,13777,44660,85274,25043,58781,-89035,-76274,6364,-63625,72855,43242,-35033,12820,-27460,77372,-47578,-61162,-70758,-1343,-4159,64935,56024,-2151,43770,19758,-30186,-86040,24666,-62332,-67542,73180,-25821,-27826,-45504,-36858,-12041,20017,-24066,-56625,-52097,-47239,-90694,8959,7712,-14258,-5860,55349,61808,-4423,-93703,64681,-98641,-25222,46999,-83831,-54714,19997,-68477,66073,51801,-66491,52061,-52866,79907,-39736,-68331,68937,91464,98892,910,93501,31295,-85873,27036,-57340,50412,21,-2445,29471,71317,82093,-94823,-54458,-97410,39560,-7628,66452,39701,54029,37906,46773,58296,60370,-61090,85501,-86874,71443,-72702,-72047,14848,34102,77975,-66294,-36576,31349,52493,-70833,-80287,94435,39745,-98291,84524,-18942,10236,93448,50846,94023,-6939,47999,14740,30165,81048,84935,-19177,-13594,32289,62628,-90612,-542,-66627,64255,71199,-83841,-82943,-73885,8623,-67214,-9474,-35249,62254,-14087,-90969,21515,-83303,94377,-91619,19956,-98810,96727,-91939,29119,-85473,-82153,-69008,44850,74299,-76459,-86464,8315,-49912,-28665,59052,-69708,76024,-92738,50098,18683,-91438,18096,-19335,35659,91826,15779,-73070,67873,-12458,-71440,-46721,54856,97212,-81875,35805,36952,68498,81627,-34231,81712,27100,-9741,-82612,18766,-36392,2759,41728,69743,26825,48355,-17790,17165,56558,3295,-24375,55669,-16109,24079,73414,48990,-11931,-78214,90745,19878,35673,-15317,-89086,94675,-92513,88410,-93248,-19475,-74041,-19165,32329,-26266,-46828,-18747,45328,8990,-78219,-25874,-74801,-44956,-54577,-29756,-99822,-35731,-18348,-68915,-83518,-53451,95471,-2954,-13706,-8763,-21642,-37210,16814,-60070,-42743,27697,-36333,-42362,11576,85742,-82536,68767,-56103,-63012,71396,-78464,-68101,-15917,-11113,-3596,77626,-60191,-30585,-73584,6214,-84303,18403,23618,-15619,-89755,-59515,-59103,-74308,-63725,-29364,-52376,-96130,70894,-12609,50845,-2314,42264,-70825,64481,55752,4460,-68603,-88701,4713,-50441,-51333,-77907,97412,-66616,-49430,60489,-85262,-97621,-18980,44727,-69321,-57730,66287,-92566,-64427,-14270,11515,-92612,-87645,61557,24197,-81923,-39831,-10301,-23640,-76219,-68025,92761,-76493,68554,-77734,-95620,-11753,-51700,98234,-68544,-61838,29467,46603,-18221,-35441,74537,40327,-58293,75755,-57301,-7532,-94163,18179,-14388,-22258,-46417,-48285,18242,-77551,82620,250,-20060,-79568,-77259,82052,-98897,-75464,48773,-79040,-11293,45941,-67876,-69204,-46477,-46107,792,60546,-34573,-12879,-94562,20356,-48004,-62429,96242,40594,2099,99494,25724,-39394,-2388,-18563,-56510,-83570,-29214,3015,74454,74197,76678,-46597,60630,-76093,37578,-82045,-24077,62082,-87787,-74936,58687,12200,-98952,70155,-77370,21710,-84625,-60556,-84128,925,65474,-15741,-94619,88377,89334,44749,22002,-45750,-93081,-14600,-83447,46691,85040,-66447,-80085,56308,44310,24979,-29694,57991,4675,-71273,-44508,13615,-54710,23552,-78253,-34637,50497,68706,81543,-88408,-21405,6001,-33834,-21570,-46692,-25344,20310,71258,-97680,11721,59977,59247,-48949,98955,-50276,-80844,-27935,-76102,55858,-33492,40680,66691,-33188,8284,64893,-7528,6019,-85523,8434,-64366,-56663,26862,30008,-7611,-12179,-70076,21426,-11261,-36864,-61937,-59677,929,-21052,3848,-20888,-16065,98995,-32293,-86121,-54564,77831,68602,74977,31658,40699,29755,98424,80358,-69337,26339,13213,-46016,-18331,64713,-46883,-58451,-70024,-92393,-4088,70628,-51185,71164,-75791,-1636,-29102,-16929,-87650,-84589,-24229,-42137,-15653,94825,13042,88499,-47100,-90358,-7180,29754,-65727,-42659,-85560,-9037,-52459,20997,-47425,17318,21122,20472,-23037,65216,-63625,-7877,-91907,24100,-72516,22903,-85247,-8938,73878,54953,87480,-31466,-99524,35369,-78376,89984,-15982,94045,-7269,23319,-80456,-37653,-76756,2909,81936,54958,-12393,60560,-84664,-82413,66941,-26573,-97532,64460,18593,-85789,-38820,-92575,-43663,-89435,83272,-50585,13616,-71541,-53156,727,-27644,16538,34049,57745,34348,35009,16634,-18791,23271,-63844,95817,21781,16590,59669,15966,-6864,48050,-36143,97427,-59390,96931,78939,-1958,50777,43338,-51149,39235,-27054,-43492,67457,-83616,37179,10390,85818,2391,73635,87579,-49127,-81264,-79023,-81590,53554,-74972,-83940,-13726,-39095,29174,78072,76104,47778,25797,-29515,-6493,-92793,22481,-36197,-65560,42342,15750,97556,99634,-56048,-35688,13501,63969,-74291,50911,39225,93702,-3490,-59461,-30105,-46761,-80113,92906,-68487,50742,36152,-90240,-83631,24597,-50566,-15477,18470,77038,40223,-80364,-98676,70957,-63647,99537,13041,31679,86631,37633,-16866,13686,-71565,21652,-46053,-80578,-61382,68487,-6417,4656,20811,67013,-30868,-11219,46,74944,14627,56965,42275,-52480,52162,-84883,-52579,-90331,92792,42184,-73422,-58440,65308,-25069,5475,-57996,59557,-17561,2826,-56939,14996,-94855,-53707,99159,43645,-67719,-1331,21412,41704,31612,32622,1919,-69333,-69828,22422,-78842,57896,-17363,27979,-76897,35008,46482,-75289,65799,20057,7170,41326,-76069,90840,-81253,-50749,3649,-42315,45238,-33924,62101,96906,58884,-7617,-28689,-66578,62458,50876,-57553,6739,41014,-64040,-34916,37940,13048,-97478,-11318,-89440,-31933,-40357,-59737,-76718,-14104,-31774,28001,4103,41702,-25120,-31654,63085,-3642,84870,-83896,-76422,-61520,12900,88678,85547,33132,-88627,52820,63915,-27472,78867,-51439,33005,-23447,-3271,-39308,39726,-74260,-31874,-36893,93656,910,-98362,60450,-88048,99308,13947,83996,-90415,-35117,70858,-55332,-31721,97528,82982,-86218,6822,25227,36946,97077,-4257,-41526,56795,89870,75860,-70802,21779,14184,-16511,-89156,-31422,71470,69600,-78498,74079,-19410,40311,28501,26397,-67574,-32518,68510,38615,19355,-6088,-97159,-29255,-92523,3023,-42536,-88681,64255,41206,44119,52208,39522,-52108,91276,-70514,83436,63289,-79741,9623,99559,12642,85950,83735,-21156,-67208,98088,-7341,-27763,-30048,-44099,-14866,-45504,-91704,19369,13700,10481,-49344,-85686,33994,19672,36028,60842,66564,-24919,33950,-93616,-47430,-35391,-28279,56806,74690,39284,-96683,-7642,-75232,37657,-14531,-86870,-9274,-26173,98640,88652,64257,46457,37814,-19370,9337,-22556,-41525,39105,-28719,51611,-93252,98044,-90996,21710,-47605,-64259,-32727,53611,-31918,-3555,33316,-66472,21274,-37731,-2919,15016,48779,-88868,1897,41728,46344,-89667,37848,68092,-44011,85354,-43776,38739,-31423,-66330,65167,-22016,59405,34328,-60042,87660,-67698,-59174,-1408,-46809,-43485,-88807,-60489,13974,22319,55836,-62995,-37375,-4185,32687,-36551,-75237,58280,26942,-73756,71756,78775,-40573,14367,-71622,-77338,24112,23414,-7679,-51721,87492,85066,-21612,57045,10673,-96836,52461,-62218,-9310,65862,-22748,89906,-96987,-98698,26956,-43428,46141,47456,28095,55952,67323,-36455,-60202,-43302,-82932,42020,77036,10142,60406,70331,63836,58850,-66752,52109,21395,-10238,-98647,-41962,27778,69060,98535,-28680,-52263,-56679,66103,-42426,27203,80021,10153,58678,36398,63112,34911,20515,62082,-15659,-40785,27054,43767,-20289,65838,-6954,-60228,-72226,52236,-35464,25209,-15462,-79617,-41668,-84083,62404,-69062,18913,46545,20757,13805,24717,-18461,-47009,-25779,68834,64824,34473,39576,31570,14861,-15114,-41233,95509,68232,67846,84902,-83060,17642,-18422,73688,77671,-26930,64484,-99637,73875,6428,21034,-73471,19664,-68031,15922,-27028,48137,54955,-82793,-41144,-10218,-24921,-28299,-2288,68518,-54452,15686,-41814,66165,-72207,-61986,80020,50544,-99500,16244,78998,40989,14525,-56061,-24692,-94790,21111,37296,-90794,72100,70550,-31757,17708,-74290,61910,78039,-78629,-25033,73172,-91953,10052,64502,99585,-1741,90324,-73723,68942,28149,30218,24422,16659,10710,-62594,94249,96588,46192,34251,73500,-65995,-81168,41412,-98724,-63710,-54696,-52407,19746,45869,27821,-94866,-76705,-13417,-61995,-71560,43450,67384,-8838,-80293,-28937,23330,-89694,-40586,46918,80429,-5475,78013,25309,-34162,37236,-77577,86744,26281,-29033,-91813,35347,13033,-13631,-24459,3325,-71078,-75359,81311,19700,47678,-74680,-84113,45192,35502,37675,19553,76522,-51098,-18211,89717,4508,-82946,27749,85995,89912,-53678,-64727,-14778,32075,-63412,-40524,86440,-2707,-36821,63850,-30883,67294,-99468,-23708,34932,34386,98899,29239,-23385,5897,54882,98660,49098,70275,17718,88533,52161,63340,50061,-89457,19491,-99156,24873,-17008,64610,-55543,50495,17056,-10400,-56678,-29073,-42960,-76418,98562,-88104,-96255,10159,-90724,54011,12052,45871,-90933,-69420,67039,37202,78051,-52197,-40278,-58425,65414,-23394,-1415,6912,-53447,7352,17307,-78147,63727,98905,55412,-57658,-32884,-44878,22755,39730,3638,35111,39777,74193,38736,-11829,-61188,-92757,55946,-71232,-63032,-83947,39147,-96684,-99233,25131,-32197,24406,-55428,-61941,25874,-69453,64483,-19644,-68441,12783,87338,-48676,66451,-447,-61590,50932,-11270,29035,65698,-63544,10029,80499,-9461,86368,91365,-81810,-71914,-52056,-13782,44240,-30093,-2437,24007,67581,-17365,-69164,-8420,-69289,-29370,48010,90439,13141,69243,50668,39328,61731,78266,-81313,17921,-38196,55261,9948,-24970,75712,-72106,28696,7461,31621,61047,51476,56512,11839,-96916,-82739,28924,-99927,58449,37280,69357,11219,-32119,-62050,-48745,-83486,-52376,42668,82659,68882,38773,46269,-96005,97630,25009,-2951,-67811,99801,81587,-79793,-18547,-83086,69512,33127,-92145,-88497,47703,59527,1909,88785,-88882,69188,-46131,-5589,-15086,36255,-53238,-33009,82664,53901,35939,-42946,-25571,33298,69291,53199,74746,-40127,-39050,91033,51717,-98048,87240,36172,65453,-94425,-63694,-30027,59004,88660,3649,-20267,-52565,-67321,34037,4320,91515,-56753,60115,27134,68617,-61395,-26503,-98929,-8849,-63318,10709,-16151,61905,-95785,5262,23670,-25277,90206,-19391,45735,37208,-31992,-92450,18516,-90452,-58870,-58602,93383,14333,17994,82411,-54126,-32576,35440,-60526,-78764,-25069,-9022,-394,92186,-38057,55328,-61569,67780,77169,19546,-92664,-94948,44484,-13439,83529,27518,-48333,72998,38342,-90553,-98578,-76906,81515,-16464,78439,92529,35225,-39968,-10130,-7845,-32245,-74955,-74996,67731,-13897,-82493,33407,93619,59560,-24404,-57553,19486,-45341,34098,-24978,-33612,79058,71847,76713,-95422,6421,-96075,-59130,-28976,-16922,-62203,69970,68331,21874,40551,89650,51908,58181,66480,-68177,34323,-3046,-49656,-59758,43564,-10960,-30796,15473,-20216,46085,-85355,41515,-30669,-87498,57711,56067,63199,-83805,62042,91213,-14606,4394,-562,74913,10406,96810,-61595,32564,31640,-9732,42058,98052,-7908,-72330,1558,-80301,34878,32900,3939,-8824,88316,20937,21566,-3218,-66080,-31620,86859,54289,90476,-42889,-15016,-18838,75456,30159,-67101,42328,-92703,85850,-5475,23470,-80806,68206,17764,88235,46421,-41578,74005,-81142,80545,20868,-1560,64017,83784,68863,-97516,-13016,-72223,79630,-55692,82255,88467,28007,-34686,-69049,-41677,88535,-8217,68060,-51280,28971,49088,49235,26905,-81117,-44888,40623,74337,-24662,97476,79542,-72082,-35093,98175,-61761,-68169,59697,-62542,-72965,59883,-64026,-37656,-92392,-12113,-73495,98258,68379,-21545,64607,-70957,-92254,-97460,-63436,-8853,-19357,-51965,-76582,12687,-49712,45413,-60043,33496,31539,-57347,41837,67280,-68813,52088,-13155,-86430,-15239,-45030,96041,18749,-23992,46048,35243,-79450,85425,-58524,88781,-39454,53073,-48864,-82289,39086,82540,-11555,25014,-5431,-39585,-89526,2705,31953,-81611,36985,-56022,68684,-27101,11422,64655,-26965,-63081,-13840,-91003,-78147,-8966,41488,1988,99021,-61575,-47060,65260,-23844,-21781,-91865,-19607,44808,2890,63692,-88663,-58272,15970,-65195,-45416,-48444,-78226,-65332,-24568,42833,-1806,-71595,80002,-52250,30952,48452,-90106,31015,-22073,62339,63318,78391,28699,77900,-4026,-76870,-45943,33665,9174,-84360,-22684,-16832,-67949,-38077,-38987,-32847,51443,-53580,-13505,9344,-92337,26585,70458,-52764,-67471,-68411,-1119,-2072,-93476,67981,40887,-89304,-12235,41488,1454,5355,-34855,-72080,24514,-58305,3340,34331,8731,77451,-64983,-57876,82874,62481,-32754,-39902,22451,-79095,-23904,78409,-7418,77916})); + } + + + @Test + public void test6() { + Solution solution = new Solution(); + System.out.println(solution.threeSum(new int[]{-1, 0, 1, 2, -1, -4})); + } +} diff --git a/[0015][3 Sum]/src/Solution.java b/[0015][3 Sum]/src/Solution.java new file mode 100644 index 0000000..514b228 --- /dev/null +++ b/[0015][3 Sum]/src/Solution.java @@ -0,0 +1,80 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-06-20 + * Time: 21:46 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0?
+     * Find all unique triplets in the array which gives the sum of zero.
+     *
+     * Note:
+     * Elements in a triplet (a,b,c) must be in non-descending order. (ie, a  b  c)
+     * The solution set must not contain duplicate triplets.
+     *
+     * For example, given array S = {-1 0 1 2 -1 -4},
+     * A solution set is:
+     * (-1, 0, 1)
+     * (-1, -1, 2)
+     *
+     * Ŀ⣺
+     *
+     * 
+ * + * @param nums + * @return + */ + public List> threeSum(int[] nums) { + List> result = new LinkedList<>(); + + if (nums == null || nums.length < 3) { + return result; + } + + Arrays.sort(nums); + int target = 0; + + int a = 0; + while (a < nums.length - 2) { + int b = a + 1; + int c = nums.length - 1; + while (b < c) { + if (nums[a] + nums[b] + nums[c] < target) { + do { + ++b; + } while (b < c && nums[b] == nums[b - 1]); + } else if (nums[a] + nums[b] + nums[c] > target) { + do { + --c; + } while (b < c && nums[c] == nums[c + 1]); + } else { + List idxs = new ArrayList<>(); + idxs.add(nums[a]); + idxs.add(nums[b]); + idxs.add(nums[c]); + result.add(idxs); + + do { + ++b; + } while (b < c && nums[b] == nums[b - 1]); + do { + --c; + } while (b < c && nums[c] == nums[c + 1]); + } + } + + do { + ++a; + }while (a < nums.length - 2 && nums[a - 1] == nums[a]); + } + return result; + } + +} diff --git a/[0015][3 Sum]/src/Solution2.java b/[0015][3 Sum]/src/Solution2.java new file mode 100644 index 0000000..f840265 --- /dev/null +++ b/[0015][3 Sum]/src/Solution2.java @@ -0,0 +1,119 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-06-20 + * Time: 21:46 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + /** + *
+     * Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0?
+     * Find all unique triplets in the array which gives the sum of zero.
+     *
+     * Note:
+     * Elements in a triplet (a,b,c) must be in non-descending order. (ie, a  b  c)
+     * The solution set must not contain duplicate triplets.
+     *
+     * For example, given array S = {-1 0 1 2 -1 -4},
+     * A solution set is:
+     * (-1, 0, 1)
+     * (-1, -1, 2)
+     *
+     * Ŀ⣺
+     * һnԪص飬ǷabcԪأʹõa+b+c=0ҳзԪ
+     *
+     * ע⣺
+     *   - ԪеԪرǷǵݼ
+     *   - ܰظԪ
+     *
+     * ˼·
+     *  2sum Ļ3sum⣬3sumĿtargetÿδѡһk
+     * ʣµĿtarget-k2sum⡣ҪעиСtrickǴѡ
+     * iʱֻҪֵдӵi+1һΧ2sum⡣
+     *
+     * ѡһ͵ڶΪA[],ܹnԪA1A2....AnȻѡA1ʱ
+     * [A2~An]Ŀλtarget-A12sum⣬Ҫ֤ǵѡA2ʱֻҪ
+     * [A3~An]мĿλtarget-A22sum⣬[A1,A3~An]У֤£
+     * [A1,A3~An]Ŀλtarget-A22sumУA1 + m = target-A2mΪA3~An
+     * ijA2 + m = target-A1պǡ[A3~An],Ŀλtarget-A12sum⡱
+     * һ⡣൱ڶ3sumA1+A2+m = targetظˡΪ˱ظ㣬
+     * [A1A3~An]У԰A1ȥĿtarget-A22sum⡣
+     *
+     * ڱҪӽ⣬ֻҪ浱ǰԼǰĿľ룬µĽӽ½⡣
+     * 㷨ӶΪOn^2;
+     * 
+ * + * @param nums + * @return + */ + public List> threeSum(int[] nums) { + List> result = new LinkedList<>(); + + if (nums != null && nums.length > 2) { + // ȶ + Arrays.sort(nums); + // iʾȡiΪ + for (int i = 0; i < nums.length - 2; ) { + // ڶܵʼλ + int j = i + 1; + // ǽλ + int k = nums.length - 1; + + while (j < k) { + // ҵĽ + if (nums[j] + nums[k] == -nums[i]) { + // ӵ + List list = new ArrayList<>(3); + list.add(nums[i]); + list.add(nums[j]); + list.add(nums[k]); + result.add(list); + + // ƶһλãһ + k--; + j++; + + // ҵһ֮ǰͬ± + while (j < k && nums[j] == nums[j - 1]) { + j++; + } + // ҵһ֮ǰͬ± + while (j < k && nums[k] == nums[k + 1]) { + k--; + } + } + // ʹ0 + else if (nums[j] + nums[k] > -nums[i]) { + k--; + // ҵһ֮ǰͬ± + while (j < k && nums[k] == nums[k + 1]) { + k--; + } + } + // С0 + else { + j++; + // ҵһ֮ǰͬ± + while (j < k && nums[j] == nums[j - 1]) { + j++; + } + } + } + + // ָһҪ + i++; + // ҵһ֮ǰͬ± + while (i < nums.length - 2 && nums[i] == nums[i - 1]) { + i++; + } + } + } + + return result; + } +} diff --git a/[0015][3 Sum]/src/Solution3.java b/[0015][3 Sum]/src/Solution3.java new file mode 100644 index 0000000..b0419b1 --- /dev/null +++ b/[0015][3 Sum]/src/Solution3.java @@ -0,0 +1,68 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +/** + * Author: 王俊超 + * Date: 2015-06-20 + * Time: 21:46 + * Declaration: All Rights Reserved !!! + */ +public class Solution3 { + /** + *
+     * Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0?
+     * Find all unique triplets in the array which gives the sum of zero.
+     *
+     * Note:
+     * Elements in a triplet (a,b,c) must be in non-descending order. (ie, a ≤ b ≤ c)
+     * The solution set must not contain duplicate triplets.
+     *
+     * For example, given array S = {-1 0 1 2 -1 -4},
+     * A solution set is:
+     * (-1, 0, 1)
+     * (-1, -1, 2)
+     *
+     * 题目大意:
+     *
+     * 
+ * + * @param nums + * @return + */ + public List> threeSum(int[] nums) { + List> result = new LinkedList<>(); + + if (nums == null || nums.length < 3) { + return result; + } + + Arrays.sort(nums); + int target = 0; + for (int a = 0; a < nums.length - 2; ++a) { + + int b = a + 1; + int c = nums.length - 1; + while (b < c) { + if (nums[a] + nums[b] + nums[c] < target) { + ++b; + } else if (nums[a] + nums[b] + nums[c] > target) { + --c; + } else { + List idxs = new ArrayList<>(); + idxs.add(nums[a]); + idxs.add(nums[b]); + idxs.add(nums[c]); + if (!result.contains(idxs)) { + result.add(idxs); + } + ++b; + --c; + } + } + } + return result; + } + +} \ No newline at end of file diff --git a/[0016][3 Sum Closest]/[0016][3 Sum Closest].iml b/[0016][3 Sum Closest]/[0016][3 Sum Closest].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0016][3 Sum Closest]/[0016][3 Sum Closest].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0016][3 Sum Closest]/[0016][3SumClosest].iml b/[0016][3 Sum Closest]/[0016][3SumClosest].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0016][3 Sum Closest]/[0016][3SumClosest].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0016][3 Sum Closest]/src/Main.java b/[0016][3 Sum Closest]/src/Main.java new file mode 100644 index 0000000..ecb9b20 --- /dev/null +++ b/[0016][3 Sum Closest]/src/Main.java @@ -0,0 +1,12 @@ +/** + * Author: + * Date: 2015-06-21 + * Time: 09:58 + * Declaration: All Rights Reserved !!! + */ +public class Main { + public static void main(String[] args) { + Solution solution = new Solution(); + System.out.println(solution.threeSumClosest(new int[]{0, 1 , 2}, 3)); + } +} diff --git a/[0016][3 Sum Closest]/src/Solution.java b/[0016][3 Sum Closest]/src/Solution.java new file mode 100644 index 0000000..136d648 --- /dev/null +++ b/[0016][3 Sum Closest]/src/Solution.java @@ -0,0 +1,99 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * Author: + * Date: 2015-06-21 + * Time: 09:29 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Given an array S of n integers, find three integers in S such that the sum is
+     * closest to a given number, target. Return the sum of the three integers. You
+     * may assume that each input would have exactly one solution.
+     *
+     * For example,
+     * given array S = {-1 2 1 -4}, and target = 1.
+     * The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).
+     *
+     * Ŀ⣺
+     * nSҵSеӶʹ֮ӽ
+     * ܺ͡Լÿ뽫һȷеĽ
+     *
+     * ˼·
+     * 3sum
+     * 
+ * + * @param nums + * @param target + * @return + */ + public int threeSumClosest(int[] nums, int target) { + + // ¼СIJֵ + long minDiff = Long.MAX_VALUE; + // ¼СֵӦͺ + long result = 0; + // ÿõIJֵ + long diff; + // ÿõĺ + long sum; + + // ȶ + Arrays.sort(nums); + + + // iʾȡiΪ + for (int i = 0; i < nums.length - 2;) { + // ڶܵʼλ + int j = i + 1; + // ǽλ + int k = nums.length - 1; + + while (j < k) { + // ǰĺ + sum = nums[j] + nums[k] + nums[i]; + // ǰĿ֮IJֵ + diff = Math.abs(target - sum); + + // ֵΪ0ֱӷ + if (diff == 0) { + return (int) sum; + } + + // ǰIJֵ֮ǰ¼IJֵС + if (diff < minDiff) { + // СIJֵ + minDiff = diff; + // СֵӦĺ + result = sum; + + // ϵһԪشʱЧ + } + + + // ʹtarget + if (sum > target) { + do { + k--; // ҵֵͬ + }while (j < k && nums[k]==nums[k + 1]); + } + // Сtarget + else { + do { + j++; + }while (j < k && nums[j - 1] == nums[j]); + } + } + + do { + i++; + }while (i < nums.length - 2 && nums[i - 1] == nums[i]); + } + + return (int) result; + } +} diff --git a/[0016][3 Sum Closest]/src/Solution2.java b/[0016][3 Sum Closest]/src/Solution2.java new file mode 100644 index 0000000..1ed9f61 --- /dev/null +++ b/[0016][3 Sum Closest]/src/Solution2.java @@ -0,0 +1,89 @@ +import java.util.Arrays; + +/** + * Author: + * Date: 2015-06-21 + * Time: 09:29 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + /** + *
+     * Given an array S of n integers, find three integers in S such that the sum is
+     * closest to a given number, target. Return the sum of the three integers. You
+     * may assume that each input would have exactly one solution.
+     *
+     * For example,
+     * given array S = {-1 2 1 -4}, and target = 1.
+     * The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).
+     *
+     * Ŀ⣺
+     * nSҵSеӶʹ֮ӽ
+     * ܺ͡Լÿ뽫һȷеĽ
+     *
+     * ˼·
+     * 3sum
+     * 
+ * + * @param nums + * @param target + * @return + */ + public int threeSumClosest(int[] nums, int target) { + + // ¼СIJֵ + long minDiff = Long.MAX_VALUE; + // ¼СֵӦͺ + long result = 0; + // ÿõIJֵ + long diff; + // ÿõĺ + long sum; + + // ȶ + Arrays.sort(nums); + + + // iʾȡiΪ + for (int i = 0; i < nums.length - 2; i++) { + // ڶܵʼλ + int j = i + 1; + // ǽλ + int k = nums.length - 1; + + while (j < k) { + // ǰĺ + sum = nums[j] + nums[k] + nums[i]; + // ǰĿ֮IJֵ + diff = Math.abs(target - sum); + + // ֵΪ0ֱӷ + if (diff == 0) { + return (int) sum; + } + + // ǰIJֵ֮ǰ¼IJֵС + if (diff < minDiff) { + // СIJֵ + minDiff = diff; + // СֵӦĺ + result = sum; + + // ϵһԪشʱЧ + } + + + // ʹtarget + if (sum > target) { + k--; + } + // Сtarget + else { + j++; + } + } + } + + return (int) result; + } +} diff --git a/[0017][Letter Combinations Of A Phon Number/[0017][Letter Combinations Of A Phon Number.iml b/[0017][Letter Combinations Of A Phon Number/[0017][Letter Combinations Of A Phon Number.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0017][Letter Combinations Of A Phon Number/[0017][Letter Combinations Of A Phon Number.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0017][Letter Combinations Of A Phon Number/[0017][LetterCombinationsOfAPhonNumber ].iml b/[0017][Letter Combinations Of A Phon Number/[0017][LetterCombinationsOfAPhonNumber ].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0017][Letter Combinations Of A Phon Number/[0017][LetterCombinationsOfAPhonNumber ].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0017][Letter Combinations Of A Phon Number/src/Main.java b/[0017][Letter Combinations Of A Phon Number/src/Main.java new file mode 100644 index 0000000..d120486 --- /dev/null +++ b/[0017][Letter Combinations Of A Phon Number/src/Main.java @@ -0,0 +1,14 @@ +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-19 19:26 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + + System.out.println(solution.letterCombinations("23")); + } +} diff --git a/[0017][Letter Combinations Of A Phon Number/src/Solution.java b/[0017][Letter Combinations Of A Phon Number/src/Solution.java new file mode 100644 index 0000000..d9ec4a0 --- /dev/null +++ b/[0017][Letter Combinations Of A Phon Number/src/Solution.java @@ -0,0 +1,74 @@ +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-08-21 + * Time: 16:23 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + + private final static String[] S = { + "abc", + "def", + "ghi", + "jkl", + "mno", + "pqrs", + "tuv", + "wxyz", + }; + + + /** + *
+     * ԭ
+     * Given a digit string, return all possible letter combinations that the number could represent.
+     * A mapping of digit to letters (just like on the telephone buttons) is given below.
+     *
+     * Input:Digit string "23"
+     * Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].
+     *
+     * Note: Although the above answer is in lexicographical order, your answer
+     * could be in any order you want.
+     *
+     * Ŀ
+     * һִַϣֵַӳͼʾ
+     * ע⣺ Ľַ˳еģκ˳򷵻ؽ
+     *
+     * ˼·
+     * һ鱣ֵֺӳϵִ룬ҵӦַϽ
+     * 
+ * + * @param digits + * @return + */ + public List letterCombinations(String digits) { + List result = new LinkedList<>(); + + if (digits == null || digits.length() < 1) { + return result; + } + + StringBuilder builder = new StringBuilder(); + letterCombinations(digits, 0, builder, result); + + return result; + } + + private void letterCombinations(String digits, int index, StringBuilder builder, List result) { + if (index == digits.length()) { + result.add(builder.toString()); + return; + } + + String t = S[digits.charAt(index) - '2']; + + for (int i = 0; i < t.length(); i++) { + builder.append(t.charAt(i)); + letterCombinations(digits, index + 1, builder, result); + builder.deleteCharAt(builder.length() - 1); + } + } +} diff --git a/[0017][Letter Combinations Of A Phon Number/src/Solution2.java b/[0017][Letter Combinations Of A Phon Number/src/Solution2.java new file mode 100644 index 0000000..4dc400d --- /dev/null +++ b/[0017][Letter Combinations Of A Phon Number/src/Solution2.java @@ -0,0 +1,95 @@ +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-08-21 + * Time: 16:23 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + + private String[] map = { + "abc", + "def", + "ghi", + "jkl", + "mno", + "pqrs", + "tuv", + "wxyz", + }; + private List result; // 洢ս + private char[] chars; // ȥ01ַĽ + private char[] curResult; // 洢м + private int end = 0; // ַеĵһδʹõλ + private int handle = 0; // ǰǵڼַ + + /** + *
+     * ԭ
+     * Given a digit string, return all possible letter combinations that the number could represent.
+     * A mapping of digit to letters (just like on the telephone buttons) is given below.
+     *
+     * Input:Digit string "23"
+     * Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].
+     *
+     * Note: Although the above answer is in lexicographical order, your answer
+     * could be in any order you want.
+     *
+     * Ŀ
+     * һִַϣֵַӳͼʾ
+     * ע⣺ Ľַ˳еģκ˳򷵻ؽ
+     *
+     * ˼·
+     * һ鱣ֵֺӳϵִ룬ҵӦַϽ
+     * 
+ * + * @param digits + * @return + */ + public List letterCombinations(String digits) { + result = new LinkedList<>(); + + if (digits != null && digits.length() > 0) { + + chars = digits.toCharArray(); + + // ַдȥ01 + // ҵһ01λ + while (end < digits.length() && chars[end] != '0' && chars[end] != '1') { + end++; + } + + handle = end + 1; + while (handle < chars.length) { + if (chars[handle] != '0' && chars[handle] != '1') { + chars[end] = chars[handle]; + end++; + } + handle++; + } + + curResult = new char[end]; + // whileendΪЧַij + handle = 0; // ָһЧַλ + + letterCombinations(); + } + return result; + } + + private void letterCombinations() { + if (handle >= end) { + result.add(new String(curResult)); + } else { + int num = chars[handle] - '2'; + for (int i = 0; i < map[num].length(); i++) { + curResult[handle] = map[num].charAt(i); + handle++; + letterCombinations(); + handle--; + } + } + } +} diff --git a/[0017][Letter Combinations Of A Phon Number/src/phone-number.png b/[0017][Letter Combinations Of A Phon Number/src/phone-number.png new file mode 100644 index 0000000000000000000000000000000000000000..f740b9f24cfc17ed67eee7c9a88fb15fde735338 GIT binary patch literal 25417 zcmbT7hc}$x7w%I;h+d+%=%V*dM2qMI8NH4gz4z!{^iGWEq7BhW^kLMA-oh}5ZlbsQ zet+xUf8Z`_%vj#>j&t_ed!NtqoLDUlWxN+uFCIO5gs1XOK?isq1|ASBOyE0)Xcz=| z!n9OXR(SOA-`Cf!^0Y^f7#^u8$bIn5-|zAXG&aa-eOMMzNBqv?Hc&b28f-xJ?|Q%B zASA|m_3AUmNB`(j?s}XB7B1>S`qqDLxxX4c&AXamOax(_K7r@<$A5gDVvs8BK$LWP1# zgkyxuUEkbL($HAj*~PqJ2(7A0>nT>`J&%X035AB>zQ z^RdCnL*YY6@jZBNfzPVnpi)fj9xg8KY4VV~sVQA#WTaTZxL~A6)i=S5fBy&*m7v|4h^9@Z zf(0;?1V0)Zmw*Hpb5aOTC6!R|+d4W z`Q8{AQL85=dU|?JB4$*SZ6)uzRzSjWL&)OR*6gsbCkop64scx5`MI}*q@8o zSHV?AMtXX>mX7gTke|2*3jXV8f;LT@kfN-st6(q+6S#8s@bA}ZXm~e&w(9%$!xIy- zNMIhA7bdLuvobSvj6bMdB~Zc(r2~xNw6wHBzvq(U7xvC{jEw`8vLhuATdhVg-w9Eb zHaBM!7Sc_ti<->2iRFLL<2C;k<}h1lG|_p5KKAe0+1bf0Hu<0@PrD^vOEr<3c?r^u zRYd+fKhrVt$S;Y;cW-P<89z^>G*s3mjf;=xc>Ox}6jSP@hnJV|3=Ua+@Es;Rl%nX-;_WLCae3;!_2L(0_xlv%?THRcB9ibro3yYDxOE z#AAKFzc5ewOq-NY;ql|AT611PCYmDIU>Qe4!*EJ)w%5;()WQ_FS_T36CX!~wyZvsS z+|HC--W>&}r|y9=YrBjkdlJBifpTzO#D9c>X_t69zkr}%^_T^JbV7354-`d*Pq&(G z&;g~bh%GDy9;rA`V+zguv{V)&ezI7Zok#63sVtVe?=2|^hX33PJdS$`H$FdHOhv!ScMMmJ-i)zPx?vW9(x{mA_7j zU6qEh;Oy&@)`j6g$EsY19be-uYY(OXpRV`vD?}J8i=n|iMU9P(Dvmj>Vrm{9(1F0; zUbJ;{Lv6M(;sq{Ts1@MftUSaDGe4NEG?(!^wN{e7xeXR6@_C#m>helfcFjCfLBT=* z{keghxPtSX|77b-MB!7`vTkBgS|*J@OZGnf8~irqlWJ7?<5gxznf^KEDYC z*3+nCDi`#s^Ha^5FONtbo(ge_!mEXksSFG;QA$8MGeP+MBj_1A@b*|&B&SZyn&jKX zE3@}ElxL+oA8ah~1)|bC8 z&DXmjvf*7_(zkam$sUkH3l1Ymzn{3UKnyndA`4@2&6aDx-1Wog3&VdJUPO$2=O2W``p3FNrt+fTbeFf zeXyc7J1;N2C^XXR>U7I2XD1pm#cpC^f@Qz>R^KV#=a)^*$2LsQNuil~S`v|OxqIRT*kOna~^aFp!M=2$) zGS*;nCOU)IK}*<#vQ?D2=|_q1`+K>!pM$MI8V>)3nTE!AYtCaF^cA_u`02}P4Ok#r z{fJpqG?_&;bK}JKYAc-Jc#!(}g6nu285n6Re3rXF2FkW-_&6&fn1k~k%*V&)xd>;v zxw^&SwOxqQ`?_bB8wa)!E?hD+y1ELw(CIRNH8X=lgz@?2@Q!0Bncn7Z&|{ns`c4jp zi}^en4;4}Uan6e|1jIw1J;VN#I>{Vs zD<>qBz(A4Q)nT^%e61%s%=TT9&A%9#PFRjT&jc(DUwbj+pw=4;ApzN4ORtqK|%9z}6x@23pVomLy zrmsvNm+;UuAU|o1 z;}w;KJ|5s`$Ckd-gF31`b zQ7TdAzi!!m(?y?BWcH4W%4QHA*9268%vz7zd7|Lk@PO8%ReHCFiKEi$YRQGKJ70GR z69@fH>q0iy&6bDy2vvx<~wg!*>W=R3?h&C*$3lYeKdRfQe#st~WcQt0UoSG=zArNBjz6IbZ#%r? zFAVzYf)Vx@2ih>K!arfu8rSM(b|4qiy)fUqrgL8G~||Qera1$*iub&PXhk_zDW5IxloC$DN~uBQZ?G$nj(ZSMmk+YklxI@!`fW_EPTO#EER#cx)f3@xPX##DHr4 z>ir-iXiivx*1x^O-ofclS4#*(v7&INDSgZ8yG8@dTSC zC7)8hOtU1zuyb)lZeQGIPXwJ*ziUjWpyruG&9dHKU(##qB~l7<&U;VUh?^N$)D zIyhPP6eoH{r1E|N62`zhOIs!@H5JM%6#r-_iEe$dW$nvkl0-WXWY5+7K}N)BF@b9o z_84L>0bv%j9S@X{T;kx)`}Ok;J9O*c=j1ZCg~$!m`_T^pw!$ zb(ZW9OO}bsT`bk?r}_TBUerKXGw@132wgo>w96gDI|?ouh-a#xf>f~N=xHne#s!-> z)1_|I*JEM3O#5a_)A8b$GktPllZ0l^Ul8)u9*nq6X~~8nb~jIH4c5^&+;Hgv+Ro!; zMBpY#5gQPupO>61hxF!7m!j#chn8xYL|Z~-rLQFy4fEQLQ#mPUXg1ra*CctsA*M1A zOL}s&oxnP!^=4T-JM3L*{*R9&M9*HeeH0XhF_`3ql{x&LrLkIvl*XiH^U;&wMJGY# z2^A={C-Is&DKJ}WDC(n3xL&~oDyZ7OQnF@zWhwI`Qqg&%Mf8DI@16R9NZy$51Xku0 z_=_5tNG0`qJi?97$IJ7$GC3q>%xHXjFmKJ#X4b3F?^?wniC#HXA?(*92s6KwP=A!V z(WDS<5pUKzX866dq~FnvEYSU{fb|e>CP`SMf93m|$ZI>rK&&l@Ff5kgsa%@bSJMXu z%sx{g4;|50Ep>sP&F;?manSJ-vZIPwrWXA+*iSNMa89n>#s3WkJ9&4kGwj;go-}3% z2^X3l-o9p5p(BTKaj1|Se}I?3BEW=lgaU!E20P|YuWZ#?Qti~*!pvJ0o)J%|sLFr+ zfx_Z3z~2&l4R=;?$kcP3J;{>2|6Dq%PZckut;vO{M@6kse^<5l=yCGU=;R*;nUGrk zF;=nwFXdJ9^Un9Aib}ux`}ZyEsMQgZzr|9&zETkxRZscO4Il7p@3-Pdg86Ne-T3Ba zX|_FzuGx<|ccqOz?j!}X31}tW1ews%U;a_vJvdljr4J#HBiubaRLFcOq>el;e#&Ls zlu$d4|A=%U)0#|3H_d?(4zc6IdCRIQf~vWbq62#js_oelKegWb5r1`mamY%D`{%?r zEshUp+O@P|xL}?aUawRI+=K@kUsktm1^KWPNavQJJEG~#@5HxXjmBAU=ZAsjJ}Agh z|1WT!>N1tDYPrUI{`@#DF7EpxbFoQ(#5pNRZI1$hmd7o7d?uIT`)u(jlDEpwM@GP@ zd07)_no{GXStdF2G;ybUX1Dn`Jngu7V@Xx^#y)*OeH>cbit_0p2r+#ODbqGH=o_7Q z2+wnQz>;8op2Xk~le&Jtzw6Xzq05D58?~GqElxvWZs!^r)(eRc5&m?v53lPwC0@I| z&bs`!{gC0&l3#Q#stcE?E2=%zI6qh!^O%r=?Te%B#k5tW=(ZzmA3oRi#kM1jy$70G z-It|~q4f1Oh=bb2wj*!B?}8HpImvI zT%idc(OTg(-sg|qu7`y5m5ptqliBEO$2;G5n#!(geVH@$BQi*$j_!jkU(I+nHEWsj zQ+rx5RFs<^I=Bq()+gtQ=V8qmdyGXae{AG3qSDmU1H)@kkkMMTJcmeYd2D+`edPxX zjP9#uUL8aI!S5|=8NXTI^k&%mLQVay{0f7vRoXiwc6SfU8vP%e7RicB@3m_Pks&Wr zL}Lal;e|#jDhp~ntHFuuyHj{`4ZH5Yg%Vwv;W(PNpK0=5N>U{z`9Z%44k6uMqqsME zRlW05uQZcodLM50l>_$ zMRIhoZ&%)38+Dokg>kZLDAHP6;Ya(e!vsg2PVw>ZEL#@b#AsE}f13?VH>)46LCz09 zquZ_*TWtS%$jj3neEI~hHVl2V>DyUxB6b6WC2^vTUKdvRsJf9O&ND@poD{MWKG}zh zhk=87rQ4)|eD#Rxx^DlsPZbC;jCrzbp0ZNuwf+0+!{<0_496O`?qfk2A$WwzYFv?L zl9!XpGGpS~&MKyCZN7-Jh=SbHki25-D9z=+@&sb9}n4xx#6^$iRAf*pY9o1d^9OB@YVm^ju?t_2G0GS1uvJ=?}N(a~vET zeFx{0)6)sEqFGCamkdih?OawX!aOJ;LB|hZVPUNgddM?_LU08%_$?f?v|d$Rn|rL$ zzT!M_%;FdZXE89=3=WoipJv$f8ush)6WUMQo8+X$?C%Y6%L+x_O=CvYvP=+v+h`V` z=9YHmv?|d-R7wVCmsxeVb?jI6RP5p6;UzklCJxr@Nw}G8oK~;#zxFWqjVb>1i`k={ z$3v`O6Sbv@?IBTT6KW?RtPJo7Fz+Ev^i~G}K7OH28rW*~S)^)Rdm+$6CoJ^sZ)@=l z!_w3vbE$^VdUM$dDtK{mk!-I4 zPMf;+b3W4{<2CV%$`+1a5SBri5YqM+Sl!j8S%@gkcL&{kdyYjxHF$JkWJ*nk&#>tJ zvE7|^fW-#(teub1SN+X9?hhoEcIm&H937|-BEmvdNwuZ+)T4|2cCEm^(^2>70b4S1 zqQPb!A}uYAoP{tAz}ZuIKARJ2^JmA$sjiWt?6{Ov(by7sjwc-x#L%&^#*94f^wKjX z6x2qQQfp17@1}PXZ5*p?8xnR?pIB#BRN@1aa)-%#0!* zMgD8!pJKE2)>aLNmAC}YV|Izf3ytGO!C&&SLNK!>clQnylB13TXvAo|M@yMfuz<}n zi3rmWu^eIQU4FNG!TA2kmi7lrKGg;M67^JZ3f$=>#IHA+Y=%M#wR3)hIg#vD|67R+*e$i|ekG^?qPKr7t54XlX|mWB$X1DkIs6UD1u#5CgBCOvPN zOCHS#@5=~hOimUD&@L`Mzm(V;F5)+2p36KoA5e#f&Qa0PYadXq#>)CMy8Sc?WWvki zYT$Qcsk&oa#-3A(x)N`u2LR4|aRYE>P_pEpB|v2Prdr<%fm?SJELg)6z{L_7ez$>_;6u-Ez7*wBl zEBdPn?08L4Y8a5 z`|8gWGg&+l76t_sm8GleaTA%1E{C|dI84`xCySHm(Xl6UfuEh7-Lz?LW#+$NnKZa< zbx|Y^PwSr=T*6WMml!no%8XqVw9$RXG5|RG{f4Oz1Xt!FW1>nV20(UnA3)nj8zx(- z^5guhL;t)(y<>jMOw2!>iuoiH+2f)|gz>6v;c{Yx%W0+ktcKtVpd5sdi9=yVZaun&fyKesz8#*H~V^T&r3XQ*&#{1pB$=tGjk^6w-{u+$_R@V0Qu7}~l z32wX6A2(nb@wWII`3P5sNU=w6V*-R7VDlw}@rYQ&Zr~_>zC9|$6uh3Q$|GK4%4IT# zjqwE7S(9L440^&?nWRZ9o`0dFl*rZRU#a+S97rFW;>##4h-}mRtUq2aWL8?!Iikdt z;JQ@t89c>W|21;J)C)F6`AO8*)Fc4d_Py#T`)i)TJ@mR~yQ^3}j7DW}aFQWhULGSV zYIpabw4^H$*c>h{8De8T0g2MSRQv_Nk~9Aa!zO1Y)U44BpANkAmGhn9zVJ5x zlJAjk%zfd(=U0KY-<;Re70_j>41{0n>Ugbe4G==N_r_$rrv0gYzHIQ^5i`NBLKfAkxX6L4seV?dH-oX3%`u?4rC60A^ zQc{aL0nmc9XCj&zmIiiqs@eW?9|Q;ku8j@rHT*^AeuTP=Deq?I1Jn_qb|=cbmi(c1 zuRRWKZpD<+rpn*`_rBI=#lD8_s1NqF{h=xWn(U-y-K`cAV4J(GlPQJGM2S2ozaQ)EbDp+sSsB*#4&%+3I1opO_o5#PTJ$;(g#G!ryM{4}#Y+ZDs9wD*;KEQ9N z19lFaptz*kq_ELZ$%E#dZxi3bi6jLDQgskQr>8h=fkPQiQf%7hEIEn18G@W%!3)Fs z_)N(OucAoJC*8XK+H+Bc{n6ATayjGgu z%}awui;|25wOa2V+0ju^es?q5V%~NHhRf|*g$}6OUPf+wALKm3d z{lGI&QcnYcdb845uJ9Jyope zKyPhCR+3xR;5k6Wvlh$(wDu(e7X<&HwimU(2Z*C1m_cB4CVCtTy~isn@9XeP@%#5M{llqfr)kLRiBL(M&iBq~6b@&x;$UVu!T9B;G z`M!82Vu6LFH1HHrq`tWA&`T!!(qqJ1l=Ej&?`vybbB0=JFLR^XQ7nwUI1sPnovO+lG2@9-gZ%b9LhFLJRQn;?beCK5m4Th@8e%ju(qO#-uEjLizV%fu_kPeBhn8;P?{~~$E6zpr z(T=@OfpS({RW-1^f3gkS8m%SFG^!xb)?m#u`_9@}vovzbE72wJfV0M^hp1ykN$>0l z;}koXHQ8DTM_rjVMg1spyAV7G2c@SQFuSC>vcqvEWMC*XuZqS*RT(Jm%_5Bk>O%4X44&=brl z^81VZ*TL~}N;4$M(u28`1RnN=nONFJ*7hSd(=59czX9A#sc))aKK=IvLF8Md0U>$B z|MLQXAF!9vB>2LyL&!{}cqJ+N+iUHI)=Y?RZ4fUh9XW91ahR>dbHYzN!t38Wpv8Rfp_LLu`v#e z=$0xLobN#E3Mnb2leTQu)zhQZ>#(*mZFG9+3~U~rM`P~%Jp^P!3kX?Uv5MkU;JCGS z+cJ=b@#F}xBEyuTe5Qu&R##>c8JALPVBf|{1SZN#O4pmRktbpRQKS?_Gxgly9d+FC z7}utQJYJ)$WpM@_!^&84#)9<~KN-Wf1h*%r79VLlO21b}ur|d?6jS!&;=FSa%Uc=f ztojS5dbOL#_D#o~5$pDR-E4Yc>epQN34IJ?c&a4YZ^=uPAujbq)N}ILXFD!9GUT2~ zTH3^E(f#qkckY@MSDxImlMS>cVr6C^6V1yiS{GV|REF_#DP@vQJ1Tso!sE%FfV^3# zxe}sXu!qH1c*1u+rHniIwC5PKnJ>eY3Frr%q3ENvORCR5`CdX%u4lq?+J+)ef8n;g z<73+S8vmP4_MOTCuAzpAHoqf&BNzG>s;Ld?%0`v>qsHqrW?>W{awckzUAUhReL&DM zyuCKreB8ox>+-s-vf=aiI6jTWbNYv2lix)ZOrpF+Ktk!q6J1H*f{~%J%!2U&fN~!c zFyFc>1<($$z#TjQ<-Q%*Z=;d+1q>A8p02WfSI?ZpE&?(1%FnE&Z!WqqC2C|Z-qL6o zV0x&I@x*h8XX*^ITE4c~tfUVuWrr}U_yz_`(U~z)w}zz;zu*}iYpmBe`t!)2ET!o9O6g6+5U$-)x zR9(Au(GvvdDSmg&^(x zh4Nh8PYylugcz!KF+l-7=${X_2?4>bymWQ+a-k*4_<}CMFTJA$xp|56ouuTnwXyYP zaHfO`#L-pR;vQsde;rykPpjEExY>X#$Sz_%pd>`a!nV#RQf>w{Phxl zE)4R~#}L{aS-VFG$B%YghKDiKd*4M_|8@d@m4Bp)xI` z&P0~DG2*6c;E@1)kdxIV*_b7yppD-2^Yr&R)G|G<%p0Ni8x9W%#*xMtyZzE;~UkgT_9*{i7^LoDf9Boiw*?b+&kB zm#d)y65kVbX05dsGXaF3UO;6y3VP^y^h8{o&dFPn_jZ@a+5hNy%1g;e5wf-e+*`?fI;J_vyfdEBd>SYhzn1U?+G~7;tWX z+tvnXDe*wkTOWbR5q|9`kEVozDM8l?cFt9{ODs!QqgKiF!ALS@6-aS+Qrv<^>;Rmpq1J#}Ba5w8V)+QAs;bJ(h^|q5tsKvo!3;|!B4nV7XN2jD;FC8B;$UUlz%T?G zg5Fk<^8l^sOMbT?xku{cM9&Je#1ar0;mj&_?MX|>;+{H!B3S|xw#t=fav0oW>BLRi zIl?CLq(ehe0y$4YsgjfPK+0CT(=U}Irkfn$g_1?CV*Rdsp>uokgkOu-F@Rux^`4lP z_B%Y!ERsP51M~Ut*r>9uUSRj~=GYoQUF`jywd2>)w5+eh4W({Ja^2N9#z16vP*c|b zsDuPIx}OSiT8H8ua>3pkYWH2J!&zzuvh#7DEC+p0+R z*vOh=;I)le^!)qvP7BKWQ ztu(lt5w^+wxPoGn@$xBy15UY&X*N7O999qAT`JKLfPzoUA}UG{;vC#K@?or@1P}o* zK>A|ZM)GH2io=a+pT_vfxQu&YC?yoUz{QD+HFb31llLjk3-N`Inks(JLazGyoECo2 zg7j$$IW(SllE{|=420NI5H3-#-!=t3VZIfX?KiL$?q8&tFh}urfj?mX9@J6x>4)4>_fpIX2}lg zPayTm-ke;tp{{)(!|zl5lm=?P`P9`{WamJ^OrrwNo+)nfvRi)bNygiDR@5hjOkt55 zchZ7V+D@eD|G0!)0j1|~Gat=ktu)Yy5fImQXT9=G^M(9n^0D-h$d(S^xeE&VPksH!H6ktBncNxn_MO$NSAm_-$hs)L>w)BI zBtsl2S;kifDi#|-b{_7Qe*RZG4Eecj-RJD7WD1$z;pOl5rBbgh*YCItJ8{hzovegV z5QvU*`;~}{>rzLX(~#b9BOLK?DG78wo0%6YIYOLXwEA@mp&)ICg^?LpV&Aj)EI@_z zdlsnz?l7?iwj+Q~Fj{wW#L-y|$9#rR=&_t&)qP=wblA5@HhBKjh3Hx!IznDusSw9N z?`1h#(I_AZck~r{-jsGe{&w)STmV_*rmIbUb8AGC!XD6TJRCPhc@bxsk#us&{eqvtYoSWo?mjEo@W zSKz6&Ah3h|R^9)~t26dXNVre$|BqBGfSw%mO zejMgj$MPk{3UmZ18aE=T0J1dQN%g%bnMUI0;hY&utwW7*bJWY~S!){+@w0w_q6qkS z{eT{Au??RYJ|FVE_WOo)=T@r(9 z9}Ug;qE&OIQTNgz$5PS7;U}D^LkCSCw&;t_H-&Q+SF0z!fyR_K7;?k&k%>wrt$~sG zEeG5q%QNG}(!8lh9vYM$Tx5M)oR*`{vN~CEI)KKib2}0jENFyOQ1m?tSd*-L%!u{& zZTvSOH6bcRMT@QWG19DbM%J?Uf73tT_71=9? zZg}MWO`4i=&+j$X9845QxvdRj_~R)dh^ayoDNOxC>*I&hGX6Y0Q*~6-B9mwHEa2p0 zkDEU@hX<26)foElC=Te(O~5|$W1~K*l@=dTNOKF5Zu$veo>`|E;k2y!?|qvH&kko^ zQT=L9b@#N7G;_>yH%@ro$y;@%_}^WqCx3J76+Jh1_5>HXlh8-Qm6)d8xvEbIgETZd z<>$kX^K~$a=BT=;Vii~opgjEVlx9~CX(_&a3*=GFtScl%567vd+0gAAm7gEWr#j)m!bv&R%yEyt+RFsnH!G)Bx^aQ17!F4CQZ5C}SCQ&r#&jeH=n{CoSD1G$$wZ z#-f(3#47yPAA6R!WEih<;#ku_Y<2Ys;^=DEHurHV4>L{C?_*wACk)SQLn+^}ex-xa zB)v6tql9kj7s^00yICpo+FDxjW}^%hxZhb6^2*ykd-55ZcSJeP_2!^O6PDwtk_tFx zC?)IHU9&$I6MAQ5K^k*5x5zDZ8;5$o3B~UoHuG#uBAR3M`Y@jK{qy#jUPDAJ@q8)D z1Em3uAHagl+NnjYuAt4##>U2p{^N>~hfsH0P;*zdnAKGp+RToQ-rd`Uv~)a6Her_K zOZlYi*a_35KU^HJPo9efS3?jm^ zs@L*;kHgj}+8K}&-2DeC$GIh@M`C`OgXgVWCN7X0gyd){TqJ zFKNg|J6`my93O>L=^RRp|M^>O!k4#gk(<6jt;XVMmiQP^*qBjxs7VHV#h*toScOW( zUORtY#9wJ;!yhJ+fSOqJr)F)UmkO=nCcaQ{zxL7osTaz!1x@JUdj08_d z0>Yv%qoRdhXWB7FE#q7&18_0-ty83llO_=+^~VnC5i-AdL&(Au>Vg5KN~T;h(Ir}i zz{~$`zhQVIM$AH-ND^C`Jr+!+h^?I-GlYloqCvPmXMkt*w4mV-p9gHcf>b(@5CMuA27b!z+ zY^8GTLj`kUwJpSj`mKEA%4|3})3+9B(=0DqQ$vZebOijMrqX#u%k*?4)ii;>X&^7i zBmez42K4Hxr79cFr0NnM+o%743wOymeO`7eNDu}ad2ob3sEs(c_x=X(IK^pZo?MxY z;p%$<={Lah;1|(>en8rT*Vlyww#|?`>__0H3t(D4@$|`j7`9&3QOE z`?k>q+?&iE0RfUhK|xjm6WRP}w_#zi{1;~oZ}h==V@ehl>y$QRGIzV0n!AsHBL+gk z!c(iOh5V6&NVh;4SsZenuT|~2RU@wfA-ex)Vjv?eycQ?>nN{OVxRzexJLdOhA+pjd zCPJdZ)ARFhbmgT#ajVx6v{+Q6E1C4X^2LYU- zE4Xc$bto`GR#r^kzkes=hU`fIrf-|kEU5n(RVKHQlA8*DBQqNTB0D7yEap))@+IY$ zq)~I}zrdPx*NE9!vLw3T@b=u2CXqQNm08TDr2}}5U^D~*sr=c@*V5GVQ4Jfg>r0qm zqH~40OxhDRHX!^t$SVJlD#KlPv1|7E50NAqiFcpIEEaRACti3+(Un(LayZIL7Vu=& zeS}rbRD;?*cXKS9KWz=Cgac6I{S7QC;j_RDyw_ItW&uIR0LZU^Q6EhD5%7t>Ciqt>m7C*F7-HUTgeDNda@0Q8<-lUUFS2C7j9CgR*fR>L%=GjC#@8%7B-VQ2 zWtgkM@Iqe-2v|M68G8fegM)+8vNG22g`&J6z%@MYe}4t9$_CtOl^Bk?Bl%TTFJqM| ztEC6KP3op*r$b{h7PisaAduf8yyVQo)bugnUf$^ZZd92K;>QQ?y{b!Sr-v!vS_uLG zVeoU8r2Quui+l%~U&eZRUL)D{y0OP?6G6_?PZj38sHmy!U0ho1wA2wFyWR1YTFg}B zEaVuayJOf(iIcEnjkQr%p_}&nXeAXPbN?VhuO{2kiP#*rTKC4v&n9(UZ_Erh8=b}` z`CV3}PESu+$CiQ7@iReq>em>LZAsQbzA`+hTRA&8m|s*+Al6nyO5u2Tcug%WwgPpg zqvr<(sYOM$78)!K6tW&wo4-EBF%CG9-8wnd*aFuJ&My_F#M<27UTvaK8rch^>o{hY zz27in%Itwj_)q-^RG;(eyf+^2_`{gV4ayvzaR3{Wrg3lr62Ub7WtvocjiUrl7LEy_ zPV|YU9+RcD-m*1SAd_&g7!4{hsKc&CI)d3y+jgQ*-OcSJBHPiyVdvw>>5oNjGFG}6aZKZGVMRaI3PRY1R5bE2c80f$d1QsrhbDFC=DNTX&5%PJCmA1{M+8#GvQj54J*Pi;>E99#2o5hR^i8c$!hzJ7 zeJtVBE4d4tKN7deg*en(AoLZqS!t3ON?(5D=fr1G^~ib3e2_aKeSv$%_V;q0O-7!b zRK;I%n!I7REtzYThdU3Y}D2z!2VJ;ELPL1)c^VMlv=K%Q_= z0~FdrT+|HpI4wCkNcILBa4W9Vm~^~?1>Q+IZ|;Uj!A5y|;8in@6AT`&R(oIc290Iv z#&C0U182OF+~1yE znE`>X?P5rFQ=a}_td_>-^ddF=+)qV7U|6*>msIC;TY(lIq@+*m#Yv1EZ=<4=sk^3^ z`4R;;ieYV^Hcd;5Ze#70ax@i=9AJSR*$Pk#%hkXEQ-v5ceJpdEmx=9Kch?7f?qT!Q zyX$cdn?h+9qN<&GKIM|Bgo3{f*}w(ooenQ>;x%D3FCr_ezppQk8KrevZWs!3f~OXz zQ%j4sDi5}=;>TrJQIOkF?q~zj5@Ok~w^Yeq^jt&wP5smW5K8y3C1w~Cw@|6`6 z2CRQ)-Xt$DE5*IBRMIP|#ozbEA{jy<^V4)MM54pP8edp8WJi|N)wz5)1eVQcz%y;| zI>ZK)Q%Y380ec|`)^}alGB~DRyOjV=7BWQ>oLo%=64wolcDS^0&%~zoPW44!E+IoU zhu6a^a+SidIn%W(s(_3Ajaq_`-`4>us3}>g zUi#n%YU4uy`pxj}?C*R9_DRo=ddORb`aCpce*vd2qWcd2OeEhW**=_zHP#%@GZ8Sp zc;XEtj>OOc!4)Y4};&2 z0%Xl@PkSs{B-4(FSYo^HWsr*^lEOntZu>hH){1iJ%=hQzYl47~+C66m5G24m;fwr9 zSJIeTW3Gyu>jaM+u;~{LGKT*$=W~=z&RRG)X>^^kq`RKsC7$C?6};WJzX2wsZ+ldo zT|RP6_LLfshF$Hx1RUOznV1v++=ZUb536Gob`*kUU^vcu9-@&1oVN-Ig0tU!t(Lmj zG}9ur`Z@s7F1$n^rT$7{^-!DPq5*&1^rb&lNR1t^Y)JSN*s=1Ni*q*8aGFfr##eNu z9efpT&hYc%es3x8lBuYFdqQzeuJi*^klE{pD$4ZeI5v78c9#;4r`Qpi#JmN&4` z%NBRU|Bt18v58zSmUHewBX?r<{qAg}OaUbr#r8=Lx|q&D5&6obmIh-g*F%5qtR{8_ zGPPsRugpYre^70vK#FmAe@FnE;Qce#;~(15bEn>YR&bLrkc!TcKmQN3T_yBMnv1B(D=>QcwpUi17Q0IPt50-!=s$$YpW*d=@cxF-WC%Aw)R-X64IAhmL6h2 z8-LMx)OUL|wFU?TpFLVk!?H!*DX7TDIAYs=7A{mK9jL(*r9=I*6ky5;`F9rpV1>(R zgKmp`_NP9}XBL(x6teffe6CO}JE~`bcXW)>fAw{aVa`GV+$s=5T61Dh3 z^C=im@|jz1g3*1Ch4i4=6e>%B80bP1$+qK-(S*p-bOCw&I?zOH`yw;6ZQjYnu{03; zER_p57_IH}qN?h&rAJCh4|1K#uF`ou4b2ak+Om(7!t0*O4*z9go#F;C3f1p$CF1sf zkb)Bayt{qRwvS!j(&Q%Y0Q3Q5-r#fHA7)n~@=&(yPa=}Z4_ExPzDsB6nPYz@sh=NT z2X1b?JO*@M9r-iAZ9~(Pj0M(sq-7y7 z$!I5NI{Y_d3L#q_HK^Vd8@!&MaB3WuvugxMLZ?9ScujvfImFJxql(ZBt!3JAy`8t< z>E3@4e7p9bC`Pl9xpdUK?(TMnceFnA5F~oPZ0sMH*A(~N{&wM34#(v>wKv%?vLr*m+3@4$rLRw zOMOr;uV_sN$TKi|zav04q*Fv%B#PEb0zUadzyuo+Co4FX?LE9u|t!yVkMxL@u7 zNn<=oAHVaOSti*_(6dIm-U*(%GBz`}=J_5K9egG`e}In~t7ay|J-!%v=>L2d(0Wry zuM28sSePKONveMR5Ogu;w`M}GtnXwc;M3IXetZ`4$HPceo~`{zbe$4IAYMvIKD_gC zS=ZQgYD=kG50|@gkJ(Yd?&svsN3^sDf#>mN%7hBjOJ%p5hqDJpMdKuje5iMf$GCEO$sL`V{N)WvZMs$LZC>cbF-WiM#oe;f-7`-Ok z^R4^m{<*)-nzhcE^RE5AXP^B(&$FMCl{DP$H5IsY+1>XSgJE4?1QxY_Tk=R{wA|m@ zE(24e2fOi&^zjB*3pwZZ-9
0V-(K*p{oj=eyYBQ3XtsuJz!4y3n`;5{A9slP^1 zr=DJR-8}@F!$*u=uYnAcgxc5ss)K0x^eyA%%DrKeO`}3d49va)$VnfKRJ7@|O+B!wGlzI$6`x*PAd|C{+B=}GoeaAQ? zq-3@J8?RXW2^52*?bYkGsPA)s@-6s&goNfj=At5f@6v6AooUqP;M~ygBf7KGiVX7x zuSQ8tLu=UM<}Ydy(BS{4MYcgc>nvJZ!=8OTpY-chSR%M9X|Bgv{L^JUdTXf*R#i}Z0IJSK$k!^>q8bt(Y4$>Q|A>33PRP?4zK{(=q+uR2R z>Bh0?;vD>>8I?kr=CSrw^7gZFVp3hBK0&JiTb1UhOHzHpRaa`5!@ zTxU{w4@j07=ZH{v&#RZ!uSd;1WKQFAmCgbr(lOs;H~~uz92^|OLASG0)mQBcqZ15% zk7IW+ZY9>Zr}no1eDJ%fM*a(RbUJrhUY=`C0wj}wgBcHhTn&Pf8mYEy=`Z{y5{KjCI`HF0BcF$X>Y!KeH{C#kr;3^n6( zgA>50LEcA;y5I}n(LA2FcQx^e_@Eq3_m-e_=uG;Pc)$+geb5q_=Z@+AM<8k`j2@D# zl>P_vU>?WGr>x`vY{}@qvg%0z^%k?ckV{BF56V4omZY)fR~jVzlWujSKht0z3H0Mk zF3gU4hS6JnLg<_FvXD(pO^H{?yx~%zz?EYq5AAvu83?i#%Nm!F9ewmg8~3K|xS3nd zgYMMx=-vZ^j@*zM3l94w9&Dp)flGKqh0)^VNh??W{o%}BKS^5yVY?7yU^e@P+yCUC zvb`UfZ!BHVKddF-MJ0>u*ZF%uzd!s{SlU2nF`g`eMl_y6^zG$a=EROyuN;G9!p?lh zM<3uqAFx+c{xc>GXuNKwy;0IUwbuz$|5~^BO@`{N^kT zOW4Crryom7mQ++Y8_9ez73%fIszm)*`k7L`&FG|FZX9I1Eh?22%!y50TCK%SIwW2B zKHAm>R|)5-*a%*~M2as&(go~pMhD=)dO~!fKW9?->JKK2@&rWa5>}17~ zA+UOqF*hfg!qEz_11lqA51{@>=%gRpk8OE7xwtSHzUukx(DzD2!OzK@hO|QBOdUX+ zlsRp3a&S<{-nvJos*Eva_}Ms`(p36?@-G8r9C(?Zyw3N=d&tR}%9VxY$otM|M$M(^ zIcA($CKo#@-EBc;NnZd4mHm*=Hg-wDoAc8L(Yzbq0Ye}W=z(Slvz$mZlV>o<6G=(V zjA2;YXcCwvaX^bxyyZ{RV!1Ii0$_aie3?i|Bci}*>hPI-`sE+VV0`pfJ&`OM27Jx3 zNuIh~`ULYFKtKoV3O+g@jRZiMnxHK7)X^6{0)8Jzjxr?YuO1rqy6fMCRyn&}D7MFx z{-p1)z=E}#pl}NNH<|*?L0i|G+SL#U+P}biXRgWJ^u2M`HDop6!?Sna6GU-MdM^t} zenWIgvR-TpDnfsM-q2LB1P*pA)6zuy{~ewV@kGIV%-=`5G!hM;i_m}SA${tXKj$jR zekEa>;M$R*71rQ=;xnjV zmBlj~2i>4oVPwrj3$$&On189o=RN#=DQJ$ov7!a<%NOw|KW*++DOf|31SyTG zs$K;GEH_^xWGHM+KlQ=4#Qf=5>m%^0zNHY@vUP$Ck1Up#m+PaVKN02o zY@P=GmtdWz8SKiq3o!f%C*{mq=1iiP*i)%DH#EQ_c_KiCFyPM6*z}hE zZw^X?HV@k{ogay88Sqc8lI9swD?T8s&c1`)D+*oZ6w5QK^{_$g(|3<*o zXLJ3Kqf*sHfX@_|7+u|Q(1539iUZojdTo86+5f!Jv>pBs$WUp+A1M-5jR|NDz2`@v zEk-@+#o-yBbc%0}Yz|iL<;mFOlkC*mW-bZ(TLpo%kTGmwFs^>svQwy4!v0nDB`_`0 zfOX1jwOJ(dYl~Flsu~p^A3-cm#9Odb3h^*Ex5&0bX!{OQ5E1jRjFFYKx6pEN;`~tO ztl%lOu$aEDrCM8;W4znC@#W&Zxl(N=`6Up&FpuT4aO zG$D?@Pi}q0g|EknqaXNp)stEV2Xuqz6^SU5RVOAVAv~(Ka5w|7K#J!8Lh89yJySr4 zFEz6B6>a)3{x0iQA=23j%xV1n6zht0x{ce}wZ(RIexelah+3R)bLC56-G6?WP7wj) zjRaPQm+SM<)HCwY1uAL`o19-puR!GXdGT;}{gKmzaw}_S( zE?&YtF7vFLUj9@dgsP#gVgtuwffB>^#RDwMRO??id0undsayp*6~iBz^%WhPR4&P| zN_B?#%ibjussy}hj=4B(-$YIO;IV}-H8 zmrFpLO%lxob-}p%hgQ_O__wyo#iY&=CCT!% zfq;p$Mq6YygCXYa-Cd~PGwB`ES~#Qpad%%rq5&up|JT0LXIC1aiDWP#Q&3g7HS(8c zghljPW0oVuBLV`l1Jt-xFy5z>Hy_$#&yuES{nKtSU11}%Q9daEE^7RKl;OWYdSPa7 zYkh|eY&0H>eroIo^#)&!P_Tf?gdQhQ-*s6WwMxytA#7U?dEBoHN=>#R6haeuQ9n@N zrbBgHJ_XPS$J=5AoxMeRVWjQ&VZqgR(SI_mfoEO-08S>`g4|pC5I+BX-^Hxod?S2OZ)KpUX(bf63AcwaD4ZD zE2IY67+yl*wsOI{yioUOz?QP>j`^jc+*)+Ag%r*fG*F>DoW%PV52nW1xXy8BasGHV zti;85n(=CIaL}hvDTkziR`B`X6x~G0YpsTS#^-^-Sj~IeFOG)^*i^N&s!phy{&f4Z z96K!*qbl9|{QEIdO{9x;GZ>SO6~`@S8x&%%JA}PW_-QA>m+cg z#aY~7PvX6hWy0lhF#R>4L3l56x*32FYU2C0G5>j_Xn|EX@umewt;0&Td_7QdE+I`3 zyUEOmXL~XMz5I&01vVAsoU0kC2zuRiYUflifj=xdWJ!-iuR`#*A#TB^q`rQC`lxlE z0%BOY^_u(NqIEYv_p#%Cv@tc;tc0xvhTOiqW88n;{;+9dRh<0I13{!&v@$1SdOVn3 z_=|hCbTI2pP>^*Ft;$xnv`Mgyp`Z4ieB6HP(9Y>~{C|pj!JR9_e19vQvp}NR9qVXiYDJPLa&pfXnvCrkwf*`xzewj+MTQ1tz9p zWaHKQzh$Rvz~I81nU(@_J1q6v-%)?@BAT>GidPnN&DACX->qJU-G*h$ddR zYu(Nt=x*-)g7?Pj5@Jh~m!b`<$r=Br?5jSAF!Z+Cxi=9WA8*;#RC;^FA$PW?W|Pb7 zoveMec^|?McEcAI_4011hLb5VRwf&GY*l&lB5lk;G^#)5<`Q8|8lKtHaMf7wM+38^ zlL=w??fIP8bO5A3H*?sYmwQTC;gjYR7D%uv&~m|J-c#`T%WwEGX3;j;%MRUQFr#*~ z7>s4Ui>>Ik%<&!DSf9keVPKtUFMZgbu(cmO|7wM7I;tzn{O8?YOhe3OD&fC^tAn1= zKh|AO7^M2KPRhYaJ9ZuAV3!nqM;Eo8>pBNlhLp&*eWW6uh<9d^BDA_b*1DQUVdxMJ zZxc2AO||pYF8TL2gW;A_v>iE@xgw!z6DcYWa3#}QVSX>?Cf;e5R=AUei&4JYkfLVA zG3#JoOp}xxS7>zUX@Gg;3ul+(^)W?%m?(F~s}yJ-KefUsHf{9BNnc>plw540#r{FN z1-0Likv^)b>B4?ey|P+%WnY;QlbeWLf*$BqN%Z=a+X%l4UKvm-3MF9|2|Zf>R%gHG z4NxmINr4vhqXSR6j^}nU`zmD?s&%H_!_=s5Y1FK4DE@+lILnAaHvaEscEnpLCXhp% z3iS`y1Z+M|*&UWfX47F9llz~7I8Z0a1F9i&ygV7U<&|iIia5U~uaBIDLe4HOtY@pG z0rQpoR`&eJ*3d=fmP7VsA4N+&(LNOmdXcRNZj>Lif*5F0O@Zrdxh}7KKgf@be1oD) zjPB}F#)Nt5W2DF?bMjFfrg;@qTU_Mwe;G+gFYM;V9+jZwi%n~-DS;IE5Yri4m`;51 zp|gic>A&F+@D=0S?JLI&Ok z!?el5bnk#YWEt^m=l$;Q-~XPXlK)<9sM_zq1SEZz@Q z=b1C2hKjXQ6|>Uk^G%yj6LP8Gf^&ooIs02I-N6EAB^CV?X>aT^3I~&;Gf#`^M8srjI z#t7xo!zK?e-?JmBX@DI1I>P-+K*?$5=FQG1xd)9tgYl_ zuN>uTARSl3Z2-mX%fPR6Wj~r+#um*Tb~ye;Z>9LsgN^n64CiV#;3aMu)7`r6J%zZe zj2A{!{xifMxgSA+uPDuZ8Qg(_^axr-f}SKl-W$g=6J}AKK}Jwi+E?>rqNN^| zoOE_--M!~N#)#fiFuz`obF<4}P#c4OUY(tiAXSP~k_y_ynaFr9{K`S4zRP2BZV^W@ z-UDO-mQV85o1X=cGFqz?WDt9l8}s%7!D-B5T+~ zaaszO>z&*S-kJ)L&28=O|LO5_^$0KD4>#~NVT{&aqbp`t?)$4EczicDN0A(4HS)qy z2j6fVYERfJt>)?~yMCF zkFIDSk#{ful09zgx^{*C-P@`4z1D0r)7&y`WvN11Mpl`;WOG`Tqa#(wW>Y%srEXEU z^j~}EXOpW!6C3nSJEo1z%1I-Ln@XQK8W7K{-nP}*Uu)V!7Q%OqFacVw%$-+@VHD;* z_{a4{?Gg9zEeC-32scRRx*1{Xt8-7=KMk~7EniDFzs>55L%GhyDhp9qwDA;FZxWRExEnt2R7NeQwMuPeT>hrO4~1e ztNyRGhuhkwf!}{CNXJXy7W!QfI#}JNW*ujW-eaqt^bI|hT&w#O`tb7CeFatyiOKgo z2cTWb9KT}7C_dyfH;-PfL8+MclYhxYog@a2$at9Thy20sF7v@L_Wt;xYlXV(OvzC+ z%F7-OG&nh09Cf0%9&e6`O#{ze06IZQD&z?3?sBJSAixT4{3i^rf-FM9)o!NZ-vMex zN%2zJLnJtk7MA6b8>1L%y19?DPtNGArz`IAEKP5<=vq+O+QCIp&2b$U9E1 z`6n!Y8NEVSCY!T~9e_t5#RY4z{B0mM0?m%`cBTM!C$z~qaHmKQNOFE8wNTkUP>mG< zBeXeeuaYC@d;*Q6#%cEIQ(b~jsbgIjB7sbvpWBKy&I-=*=QkU&9N7W~tZN+|sCT7Ch&wHeq9SC{-#`&t)zlJE4 z)LaTB3~;U=&+n>KwYw|>4flrdwQJ0J-pZXkY$^gR%^G^fFLzQATo;Ibvzz}^&1}#b zPALGm3uFRx+Ck9%V+lNj(%IXNE0w&4=ALSGk|#Q2$4!xj zHA7FNaVIS)lK-Qv=d@m$*I}m5(L3*`_@@JQjpizIh3>1{Vv~EG$>|Pe8BNs?UyU*Y zhJ&YXv%-#^F8QNG+38ZNyx!R~*3dT=@!QM2`OR&<_|rO)%;VI%nCXGq4TCK#k2}QsE`oUFX3s zRVC8GZJ0bQ73NB>CNX#5$vq)hA1<+Wgn|>Lkhd>GN{A=ce-=Vob~1>=yo98f>P8|# z4JymF<^E$Xw$+!lf?{M}sZjJRSb74q zb?^nEP4DkwFlu%h^mAl{jcMn%O>B`~{pHE3O@B9*-#_EG-L9;&tLd6e-|-c~Z6{~i zkKuBgDkss9S!CCvM+Nmpt>O&+Sa(dyLC;pwgE;Ubz*o}iueVVj2htw2F8?A+&P@CM z5&Nn?*>FOGo6vGj?QvYK5V1;WLLl*byTf+8IOWoj7gXoEr0{S)92@cynn*jCz*lz5 zulWiCw%B|rEV$ya6F+InVHr=8KLrUzSk5!rfe_lhqh@imCNFo~Ph!L!-V$mJ3$aDV z(s;ygTVz3;R3JAFs!HW}e>3Pdov$dwdy+_z|B>HeFz97}$=00h z^55vSTBWi;oK-tgM3*(GPK3G13nap8)0%$d+Nwd~8U=oY(x)w)!q%+#t;43=V)0hr zVMy|u-Jx-!(Zh?D>g>Ov@{VjY8|f@KEpQW7uB#Erqdt!k@z%vv!= zzDy`XikY&HNLk9HOiHOao+Xibiz`|mHr1~_f#rmoVsNDZI}Sw+=Ide(67q`=E{L?(KPC|9B-`MxLc}pPu$DO~diz^ee!F7R2ph0OlfU)F z5}rD4GpF%p_^|`ommY)~R^)iw9thRPneaR!+20HVhy-K{2-;5!&Q|iFYIH6Yoxb=Sb8rnGz6AOH-j_Hvm)? zR!UN8gllK)y zoFeF6yNKnBc2~<_C9`KbE6b%R1F!sPK@*DQo)|Rt)aUNc2z`Efn-{!<0qW2T=k@wo!#`qO%BBtBHeW) z{k|W-i{XP7l4pVWJ~Pa2np& z^Myd)?W9OKf+#F^7VmDJb5{-SIIOsL4;WE|b6 zT(0@*;7H(VuzC zb5q3=yBzQ_hof64B*><~_*2V4MnS}TH~h55wZ+syNA%k#L>E3^1~TOs#|Rbz;E=0Y zwCF7nPN;jn1XCm5O+LiuOFw=u9ZRCJV)iq;YT13Ol!wEzGB literal 0 HcmV?d00001 diff --git a/[0018][4 Sum]/[0018][4 Sum].iml b/[0018][4 Sum]/[0018][4 Sum].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0018][4 Sum]/[0018][4 Sum].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0018][4 Sum]/[0018][4Sum].iml b/[0018][4 Sum]/[0018][4Sum].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0018][4 Sum]/[0018][4Sum].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0018][4 Sum]/src/Solution.java b/[0018][4 Sum]/src/Solution.java new file mode 100644 index 0000000..96be97f --- /dev/null +++ b/[0018][4 Sum]/src/Solution.java @@ -0,0 +1,105 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-08-21 + * Time: 16:28 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Given an array S of n integers, are there elements a, b, c, and d in S
+     * such that a + b + c + d = target? Find all unique quadruplets in the array
+     * which gives the sum of target.
+     * Note:
+     * Elements in a quadruplet (a,b,c,d) must be in non-descending order. (ie, a  b  c  d)
+     * The solution set must not contain duplicate quadruplets.
+     *
+     * For example, given array S = {1 0 -1 0 -2 2}, and target = 0.
+     *
+     * A solution set is:
+     * (-1,  0, 0, 1)
+     * (-2, -1, 1, 2)
+     * (-2,  0, 0, 2)
+     *
+     * Ŀ
+     * һ飬ҳa + b + c + d = targetΨһ⡣
+     *
+     * ˼·
+     * ȷadadͬʱظʹáȻȷbcͬҲ
+     * ͬʱظʹáҳĽ⣬ͬʱԱ֤ⲻظ
+     * 
+ * + * @param num + * @param target + * @return + */ + public List> fourSum(int[] num, int target) { + List> result = new LinkedList<>(); + if (num == null || num.length < 4) { + return result; + } + + // + Arrays.sort(num); + + // һ + for (int i = 0; i < num.length - 3; i++) { + // һʹòظ + if (i > 0 && num[i] == num[i - 1]) { + continue; + } + + // ĸ + for (int j = num.length - 1; j > i + 2; j--) { + // ĸʹòظ + if (j < num.length - 1 && num[j] == num[j + 1]) { + continue; + } + + // ڶ + int start = i + 1; + // + int end = j - 1; + int n = target - num[i] - num[j]; + + while (start < end) { + if (num[start] + num[end] == n) { + List four = new ArrayList<>(4); + four.add(num[i]); + four.add(num[start]); + four.add(num[end]); + four.add(num[j]); + + result.add(four); + + do { + start++; + // ֤ٴʹõڶظ + } while (start < end && num[start] == num[start - 1]); + do { + end--; + // ֤ٴʹõظ + } while (start < end && num[end] == num[end + 1]); + } else if (num[start] + num[end] < n) { + do { + start++; + // ֤ٴʹõڶظ + } while (start < end && num[start] == num[start - 1]); + } else { + do { + end--; + // ֤ٴʹõظ + } while (start < end && num[end] == num[end + 1]); + } + } + } + } + return result; + } +} diff --git a/[0019][Remove Nth Node From End Of List]/[0019][Remove Nth Node From End Of List].iml b/[0019][Remove Nth Node From End Of List]/[0019][Remove Nth Node From End Of List].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0019][Remove Nth Node From End Of List]/[0019][Remove Nth Node From End Of List].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0019][Remove Nth Node From End Of List]/src/ListNode.java b/[0019][Remove Nth Node From End Of List]/src/ListNode.java new file mode 100644 index 0000000..d011c54 --- /dev/null +++ b/[0019][Remove Nth Node From End Of List]/src/ListNode.java @@ -0,0 +1,15 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 16:30 + * Declaration: All Rights Reserved !!! + */ +public class ListNode { + int val; + ListNode next; + + ListNode(int x) { + val = x; + next = null; + } +} diff --git a/[0019][Remove Nth Node From End Of List]/src/Solution.java b/[0019][Remove Nth Node From End Of List]/src/Solution.java new file mode 100644 index 0000000..fb5db12 --- /dev/null +++ b/[0019][Remove Nth Node From End Of List]/src/Solution.java @@ -0,0 +1,59 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 16:30 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Given a linked list, remove the nth node from the end of list and return its head.
+     * For example,
+     *
+     * Given linked list: 1->2->3->4->5, and n = 2.
+     * After removing the second node from the end, the linked list becomes 1->2->3->5.
+     *
+     * Note:
+     * Given n will always be valid.
+     * Try to do this in one pass.
+     *
+     * Ŀ
+     * ɾĵڣθ㣬ע⣺ģζǺϷһαɲ
+     *
+     * ˼·
+     * һָҵNڵ㣬Ȼһָָͷ㣬Ȼָһߣ
+     * ֱǰһֱָĩβһָǵN+1㣬ɾNͿˡ
+     * 
+ * + * @param head + * @param n + * @return + */ + public ListNode removeNthFromEnd(ListNode head, int n) { + ListNode pa = head; + ListNode pb = head; + + // ҵn + for (int i = 0; i < n && pa != null; i++) { + pa = pa.next; + } + + + if (pa == null) { + head = head.next; + return head; + } + + // pbpan-1 + // pa.nextΪnullpbڵn+1λ + while (pa.next != null) { + pa = pa.next; + pb = pb.next; + } + + pb.next = pb.next.next; + + return head; + } +} diff --git a/[0020][Valid Parentheses]/[0020][Valid Parentheses].iml b/[0020][Valid Parentheses]/[0020][Valid Parentheses].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0020][Valid Parentheses]/[0020][Valid Parentheses].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0020][Valid Parentheses]/src/Main.java b/[0020][Valid Parentheses]/src/Main.java new file mode 100644 index 0000000..4fda8c6 --- /dev/null +++ b/[0020][Valid Parentheses]/src/Main.java @@ -0,0 +1,22 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-17 14:46 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + + Assert.assertEquals(true, solution.isValid("()")); + } + + @Test + public void test2() { + Solution solution = new Solution(); + + Assert.assertEquals(false, solution.isValid("(]")); + } +} diff --git a/[0020][Valid Parentheses]/src/Solution.java b/[0020][Valid Parentheses]/src/Solution.java new file mode 100644 index 0000000..f248985 --- /dev/null +++ b/[0020][Valid Parentheses]/src/Solution.java @@ -0,0 +1,52 @@ +import java.util.Deque; +import java.util.LinkedList; + +/** + * Author: + * Date: 2015-08-21 + * Time: 16:32 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Given a string containing just the characters (, ), {, }, [ and ],
+     * determine if the input string is valid.
+     * The brackets must close in the correct order, () and ()[]{} are all valid
+     * but (] and ([)] are not.
+     *
+     * Ŀ
+     * һֻ(, ), {, }, [ ͡]ַ֤ǷЧġ
+     * űԣҪȷ˳
+     *
+     * ˼·
+     * һջŴдžջžջԪؿǷһţ
+     * ɾ͵Ҵһţƥֱӷؽ
+     * 
+ * + * @param s + * @return + */ + public boolean isValid(String s) { + Deque stack = new LinkedList<>(); + final String left = "([{"; + final String right = ")]}"; + + for (int index = 0; index < s.length(); index++) { + char c = s.charAt(index); + + if (left.indexOf(c) > -1) { + stack.push(c); + } else { + if (stack.isEmpty() || right.indexOf(c) != left.indexOf(stack.peek())) { + return false; + } else { + stack.pop(); + } + } + } + + return stack.isEmpty(); + } +} diff --git a/[0020][Valid Parentheses]/src/Solution2.java b/[0020][Valid Parentheses]/src/Solution2.java new file mode 100644 index 0000000..84aaaa5 --- /dev/null +++ b/[0020][Valid Parentheses]/src/Solution2.java @@ -0,0 +1,97 @@ +import java.util.Deque; +import java.util.LinkedList; + +/** + * Author: + * Date: 2015-08-21 + * Time: 16:32 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + /** + *
+     * ԭ
+     * Given a string containing just the characters (, ), {, }, [ and ],
+     * determine if the input string is valid.
+     * The brackets must close in the correct order, () and ()[]{} are all valid
+     * but (] and ([)] are not.
+     *
+     * Ŀ
+     * һֻ(, ), {, }, [ ͡]ַ֤ǷЧġ
+     * űԣҪȷ˳
+     *
+     * ˼·
+     * һջŴдžջžջԪؿǷһţ
+     * ɾ͵Ҵһţƥֱӷؽ
+     * 
+ * + * @param s + * @return + */ + public boolean isValid(String s) { + Deque stack = new LinkedList<>(); + int index = 0; + Character top; + while (index < s.length()) { + Character c = s.charAt(index); + switch (c) { + case '(': + case '[': + case '{': + stack.addFirst(c); + break; + case ')': + + if (stack.isEmpty()) { + return false; + } + + top = stack.getFirst(); + if (top == '(') { + stack.removeFirst(); + } else if (top == '[' || top == '{') { + return false; + } else { + stack.addFirst(c); + } + break; + case ']': + + if (stack.isEmpty()) { + return false; + } + + top = stack.getFirst(); + if (top == '[') { + stack.removeFirst(); + } else if (top == '(' || top == '{') { + return false; + } else { + stack.addFirst(c); + } + break; + case '}': + + if (stack.isEmpty()) { + return false; + } + + top = stack.getFirst(); + if (top == '{') { + stack.removeFirst(); + } else if (top == '[' || top == '(') { + return false; + } else { + stack.addFirst(c); + } + break; + default: + return false; + } + + index++; + } + + return stack.isEmpty(); + } +} diff --git a/[0021][Merge Two Sorted Lists]/[0021][Merge Two Sorted Lists].iml b/[0021][Merge Two Sorted Lists]/[0021][Merge Two Sorted Lists].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0021][Merge Two Sorted Lists]/[0021][Merge Two Sorted Lists].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0021][Merge Two Sorted Lists]/src/ListNode.java b/[0021][Merge Two Sorted Lists]/src/ListNode.java new file mode 100644 index 0000000..165ba3b --- /dev/null +++ b/[0021][Merge Two Sorted Lists]/src/ListNode.java @@ -0,0 +1,15 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 16:35 + * Declaration: All Rights Reserved !!! + */ +public class ListNode { + int val; + ListNode next; + + ListNode(int x) { + val = x; + next = null; + } +} diff --git a/[0021][Merge Two Sorted Lists]/src/Solution.java b/[0021][Merge Two Sorted Lists]/src/Solution.java new file mode 100644 index 0000000..c3281f8 --- /dev/null +++ b/[0021][Merge Two Sorted Lists]/src/Solution.java @@ -0,0 +1,52 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 16:35 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Merge two sorted linked lists and return it as a new list.
+     * The new list should be made by splicing together the nodes of the first two lists.
+     *
+     * Ŀ
+     * ϲһµбµĽԭȵɣ
+     * ҲDzܺϲܰ´Ľ㡣
+     *
+     * ˼·
+     * ʹͷrootиһͷ㣬ʹָͷ㣬
+     * СĽֵĽժӵrootĩβͬʱժͷƶһ㣬
+     * һֱԭһΪգٽʣµĽӵrootĩβ
+     * 󷵻rootһ㣬Ϊµͷ
+     * 
+ * + * @param l1 + * @param l2 + * @return + */ + public ListNode mergeTwoLists(ListNode l1, ListNode l2) { + + ListNode head = new ListNode(0); // һͷ㣬Ҫɾ + ListNode tail = head; + + while (l1 != null && l2 != null) { + if (l1.val <= l2.val) { + tail.next = l1; + l1 = l1.next; + } else { + tail.next = l2; + l2 = l2.next; + } + + // ƶµβ + tail = tail.next; + } + + tail.next = (l1 != null ? l1 : l2); + + // headһڵǵһݽ + return head.next; + } +} diff --git a/[0022][Generate Parentheses]/[0022][Generate Parentheses].iml b/[0022][Generate Parentheses]/[0022][Generate Parentheses].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0022][Generate Parentheses]/[0022][Generate Parentheses].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0022][Generate Parentheses]/src/Main.java b/[0022][Generate Parentheses]/src/Main.java new file mode 100644 index 0000000..41be2f7 --- /dev/null +++ b/[0022][Generate Parentheses]/src/Main.java @@ -0,0 +1,17 @@ +/** + * Author: + * Date: 2015-06-22 + * Time: 12:00 + * Declaration: All Rights Reserved !!! + */ +public class Main { + public static void main(String[] args) { + Solution solution = new Solution(); + System.out.println(solution.generateParenthesis(0)); + System.out.println(solution.generateParenthesis(1)); + System.out.println(solution.generateParenthesis(2)); + System.out.println(solution.generateParenthesis(3)); + System.out.println(solution.generateParenthesis(4)); + System.out.println(solution.generateParenthesis(5)); + } +} diff --git a/[0022][Generate Parentheses]/src/Solution.java b/[0022][Generate Parentheses]/src/Solution.java new file mode 100644 index 0000000..75a6eb1 --- /dev/null +++ b/[0022][Generate Parentheses]/src/Solution.java @@ -0,0 +1,73 @@ +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-06-22 + * Time: 11:13 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Given n pairs of parentheses, write a function to generate all combinations
+     * of well-formed parentheses.
+     *
+     * For example, given n = 3, a solution set is:
+     * "((()))", "(()())", "(())()", "()(())", "()()()"
+     *
+     * Ŀ⣺
+     * nţȷ
+     *
+     * ˼·
+     * õݹ
+     * 
+ * + * @param n + * @return + */ + public List generateParenthesis(int n) { + // Ķ + List result = new ArrayList<>(); + // 0 + if (n > 0) { + // + char[] parentheses = new char[2 * n]; + // + solve(n, n, parentheses, result); + } + return result; + } + + /** + * @param left ʣõ + * @param right ʣõ + * @param parentheses һΪֹʹõ + * @param result Žļ + */ + public void solve(int left, int right, char[] parentheses, List result) { + + // ʣµС0ÿʣµС + if (left < 0 || right < 0 || right < left) { + // ʲô + return; + } + // Ŷʹ + else if (left == 0 && right == 0) { + result.add(new String(parentheses)); + } + // ʹ + else { + // ǰʹõλ + int idx = parentheses.length - left - right; + // ʹ + parentheses[idx] = '('; + // ݹ + solve(left - 1, right, parentheses, result); + // ʹ + parentheses[idx] = ')'; + solve(left, right - 1, parentheses, result); + } + } +} diff --git a/[0023][Merge K Sorted Lists]/[0023][Merge K Sorted Lists].iml b/[0023][Merge K Sorted Lists]/[0023][Merge K Sorted Lists].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0023][Merge K Sorted Lists]/[0023][Merge K Sorted Lists].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0023][Merge K Sorted Lists]/src/ListNode.java b/[0023][Merge K Sorted Lists]/src/ListNode.java new file mode 100644 index 0000000..0782835 --- /dev/null +++ b/[0023][Merge K Sorted Lists]/src/ListNode.java @@ -0,0 +1,14 @@ +/** + * Author: + * Date: 2015-06-30 + * Time: 17:12 + * Declaration: All Rights Reserved !!! + */ +public class ListNode { + int val; + ListNode next; + + ListNode(int x) { + val = x; + } +} diff --git a/[0023][Merge K Sorted Lists]/src/Solution.java b/[0023][Merge K Sorted Lists]/src/Solution.java new file mode 100644 index 0000000..243ebc1 --- /dev/null +++ b/[0023][Merge K Sorted Lists]/src/Solution.java @@ -0,0 +1,214 @@ +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +/** + * Author: + * Date: 2015-06-30 + * Time: 19:21 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Merge k sorted linked lists and return it as one sorted list.
+     * Analyze and describe its complexity.
+     *
+     * Ŀ⣺
+     * ϲkźõĵĵ
+     *
+     * ˼·
+     * ʹһСвȽkĵһѣȡеСأΪСԪأ
+     * ԪصһѣȡСģβֱΪ
+     * 
+ * + * @param lists + * @return + */ + public ListNode mergeKLists(ListNode[] lists) { + + // ΪջûԪ + if (lists == null || lists.length < 1) { + return null; + } + + // ֻһԪ + if (lists.length == 1) { + return lists[0]; + } + + // һСѣʹһڲΪȽ + MinHeap minHeap = new MinHeap(new Comparator() { + @Override + public int compare(ListNode o1, ListNode o2) { + if (o1 == null) { + return -1; + } + + if (o2 == null) { + return 1; + } + + return o1.val - o2.val; + } + }); + + + // ĵһ + for (ListNode node : lists) { + if (node != null) { + minHeap.add(node); + } + } + + // ͷ㣬ʹ + ListNode head = new ListNode(0); + // ǰĽ + ListNode curr = head; + + while (!minHeap.isEmpty()) { + ListNode node = minHeap.deleteTop(); + + // һ㲻Ϊվͽһ + if (node.next != null) { + minHeap.add(node.next); + } + + curr.next = node; + curr = node; + } + + return head.next; + } + + /** + * С + * + * @param + */ + private static class MinHeap { + // Ԫشŵļ + private List items; + + private Comparator comp; + + /** + * һ׵ʼС32 + */ + public MinHeap(Comparator comp) { + this(32, comp); + } + + /** + * һָʼСĶ + * + * @param size ʼС + */ + public MinHeap(int size, Comparator comp) { + items = new ArrayList<>(size); + this.comp = comp; + } + + /** + * ϵ + * + * @param index Ԫصʼλ + */ + public void siftUp(int index) { + T intent = items.get(index); // ȡʼԪض + + while (index > 0) { // ǸԪ + int parentIndex = (index - 1) / 2; // ҸԪضλ + T parent = items.get(parentIndex); // ȡԪض + if (comp.compare(intent, parent) < 0) { //ƵӽڵȸڵС + items.set(index, parent); // ڵ· + index = parentIndex; // ¼ڵ·ŵλ + } else { // ӽڵ㲻ȸڵС˵·ѾСź˳ˣҪ + break; + } + } + + // indexʱ¼ǵһ·ŵĸڵλãҲ + // ԽʼĵԪֵindexλü + items.set(index, intent); + } + + /** + * µ + * + * @param index ƵԪصʼλ + */ + public void siftDown(int index) { + T intent = items.get(index); // ȡʼԪض + int leftIndex = 2 * index + 1; // // ȡʼԪضӽԪλ + + while (leftIndex < items.size()) { // ӽ + T minChild = items.get(leftIndex); // ȡӽԪض󣬲ҼٶΪӽС + int minIndex = leftIndex; // ӽڵСڵԪصλãٶʼʱΪӽλ + + int rightIndex = leftIndex + 1; // ȡӽλ + if (rightIndex < items.size()) { // ӽ + T rightChild = items.get(rightIndex); // ȡӽԪض + if (comp.compare(rightChild, minChild) < 0) { // ҳӽڵеСӽ + minChild = rightChild; + minIndex = rightIndex; + } + } + + // СӽڵȸڵСҪµ + if (comp.compare(minChild, intent) < 0) { + items.set(index, minChild); // ӽڵ + index = minIndex; // ¼ƽڵλ + leftIndex = index * 2 + 1; // ҵƽڵӽڵλ + } else { // Сӽڵ㲻ȸڵС˵·ѾСź˳ˣҪ + break; + } + } + + // indexʱ¼ǵһƵӽڵλãҲ + // ԽʼĵԪֵindexλü + items.set(index, intent); + } + + /** + * һԪ + * + * @param item ȴӵԪ + */ + public void add(T item) { + items.add(item); // Ԫӵ + siftUp(items.size() - 1); // ѭƣع + } + + /** + * ɾѶԪ + * + * @return ѶԪ + */ + public T deleteTop() { + if (items.isEmpty()) { // ѾΪգͱ쳣 + throw new RuntimeException("The heap is empty."); + } + + T maxItem = items.get(0); // ȡѶԪ + T lastItem = items.remove(items.size() - 1); // ɾһԪ + if (items.isEmpty()) { // ɾԪغΪյ˵ɾԪҲǶѶԪ + return lastItem; + } + + items.set(0, lastItem); // ɾԪطѶ + siftDown(0); // µ + return maxItem; // ضѶԪ + } + + /** + * ж϶ǷΪ + * + * @return trueǿգfalse + */ + public boolean isEmpty() { + return items.isEmpty(); + } + } + +} diff --git a/[0024][Swap Nodes In Pairs]/[0024][Swap Nodes In Pairs].iml b/[0024][Swap Nodes In Pairs]/[0024][Swap Nodes In Pairs].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0024][Swap Nodes In Pairs]/[0024][Swap Nodes In Pairs].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0024][Swap Nodes In Pairs]/[0024][SwapNodesInPairs].iml b/[0024][Swap Nodes In Pairs]/[0024][SwapNodesInPairs].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0024][Swap Nodes In Pairs]/[0024][SwapNodesInPairs].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0024][Swap Nodes In Pairs]/src/ListNode.java b/[0024][Swap Nodes In Pairs]/src/ListNode.java new file mode 100644 index 0000000..71c954d --- /dev/null +++ b/[0024][Swap Nodes In Pairs]/src/ListNode.java @@ -0,0 +1,15 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 16:37 + * Declaration: All Rights Reserved !!! + */ +public class ListNode { + int val; + ListNode next; + + ListNode(int x) { + val = x; + next = null; + } +} diff --git a/[0024][Swap Nodes In Pairs]/src/Solution.java b/[0024][Swap Nodes In Pairs]/src/Solution.java new file mode 100644 index 0000000..780c049 --- /dev/null +++ b/[0024][Swap Nodes In Pairs]/src/Solution.java @@ -0,0 +1,53 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 16:37 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Given a linked list, swap every two adjacent nodes and return its head.
+     * For example,
+     * Given 1->2->3->4, you should return the list as 2->1->4->3.
+     * Your algorithm should use only constant space. You may not modify the values in the list, only nodes itself can be changed.
+     *
+     * Ŀ
+     * һɶԽڵĽ㡣㷨Ӧռ䣬ܸĽֵֻܽ㡣
+     *
+     * ˼·
+     * ʹһͷrootҪнÿλýн
+     * ҰѽĽӵrootϣֱеĽ㶼ꡣ
+     * 
+ * + * @param head + * @return + */ + public ListNode swapPairs(ListNode head) { + // ͷ + ListNode node = new ListNode(0); + node.next = head; + + // pָµβ㣬pָõĽ㣬ӵͷΪѾ + ListNode p = node; + ListNode tmp; + + // ÿв + while (p.next != null && p.next.next != null) { + // ¼һҪдλ + tmp = p.next.next; + // 㽻 + p.next.next = tmp.next; + tmp.next = p.next; + p.next = tmp; + // ָ򷵻µβ + p = tmp.next; + } + + head = node.next; + node.next = null; + + return head; + } +} diff --git a/[0025][Reverse Nodes In K-Group]/[0025][Reverse Nodes In K-Group].iml b/[0025][Reverse Nodes In K-Group]/[0025][Reverse Nodes In K-Group].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0025][Reverse Nodes In K-Group]/[0025][Reverse Nodes In K-Group].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0025][Reverse Nodes In K-Group]/src/ListNode.java b/[0025][Reverse Nodes In K-Group]/src/ListNode.java new file mode 100644 index 0000000..a590f24 --- /dev/null +++ b/[0025][Reverse Nodes In K-Group]/src/ListNode.java @@ -0,0 +1,14 @@ +/** + * Author: + * Date: 2015-06-30 + * Time: 21:20 + * Declaration: All Rights Reserved !!! + */ +public class ListNode { + int val; + ListNode next; + + ListNode(int x) { + val = x; + } +} diff --git a/[0025][Reverse Nodes In K-Group]/src/Main.java b/[0025][Reverse Nodes In K-Group]/src/Main.java new file mode 100644 index 0000000..120f95b --- /dev/null +++ b/[0025][Reverse Nodes In K-Group]/src/Main.java @@ -0,0 +1,42 @@ +/** + * Author: + * Date: 2015-06-30 + * Time: 21:40 + * Declaration: All Rights Reserved !!! + */ +public class Main { + public static void main(String[] args) { + test01(1); + test01(2); + test01(3); + test01(4); + test01(5); + test01(6); + } + + private static void test01(int k) { + ListNode n1 = new ListNode(1); + ListNode n2 = new ListNode(2); + ListNode n3 = new ListNode(3); + ListNode n4 = new ListNode(4); + ListNode n5 = new ListNode(5); + n1.next = n2; + n2.next = n3; + n3.next = n4; + n4.next = n5; + + Solution solution = new Solution(); + ListNode head = solution.reverseKGroup(n1, k); + + print(head); + } + + private static void print(ListNode head) { + while (head != null) { + System.out.print(head.val + "->"); + head = head.next; + } + + System.out.println("null"); + } +} diff --git a/[0025][Reverse Nodes In K-Group]/src/Solution.java b/[0025][Reverse Nodes In K-Group]/src/Solution.java new file mode 100644 index 0000000..0e4cfb0 --- /dev/null +++ b/[0025][Reverse Nodes In K-Group]/src/Solution.java @@ -0,0 +1,106 @@ +/** + * Author: + * Date: 2015-06-30 + * Time: 21:20 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Given a linked list, reverse the nodes of a linked list k at a time
+     * and return its modified list.
+     *
+     * If the number of nodes is not a multiple of k then left-out nodes
+     * in the end should remain as it is.
+     *
+     * You may not alter the values in the nodes, only nodes itself may
+     * be changed.
+     *
+     * Only constant memory is allowed.
+     *
+     * For example,
+     * Given this linked list: 1->2->3->4->5
+     * For k = 2, you should return: 2->1->4->3->5
+     * For k = 3, you should return: 3->2->1->4->5
+     *
+     * Ŀ⣺
+     * һһKÿKзתĽK
+     * ԭ˳򲻱䡣
+     *
+     * ˼·
+     *
+     * һָ¼Ӻõһ㣨tail
+     * һָ¼һӺõIJֵһ㣨head
+     * δĽheadβ巨kԪأٽheadƶtail
+     * tail¼¼β㣬ֱеԪض˲
+     * һԪزkΪйβ巨ԻҪлԭ
+     * headԪؽβ巨Ϳ
+     *
+     * 
+ * + * @param head + * @param k + * @return + */ + public ListNode reverseKGroup(ListNode head, int k) { + + if (k <= 1) { + return head; + } + + ListNode root = new ListNode(0); + // ͷһԪصǰ + ListNode groupHead = root; + // ǰҪĽ + ListNode curr = head; + // õβ + ListNode groupTail = head; + // ǰҪĽĺ + ListNode next; + + // ÿ飬˶ٸ + int count = 0; + + + while (curr != null) { + + // ǷĵһԪؾͼ¼ + if (count == 0) { + groupTail = curr; + } + + // ¼Ԫظ + count++; + // ¼һ + next = curr.next; + // β巨 + curr.next = groupHead.next; + groupHead.next = curr; + curr = next; + + // Ѿk㣬ͷǰƶһӺõĽ + if (count == k) { + groupHead = groupTail; + // + count = 0; + } + } + + + // ˵kĸԪصĽ㣬 + // ٴʹβ巨лԭ + if (count != 0) { + curr = groupHead.next; + groupHead.next = null; + + while (curr != null) { + next = curr.next; + curr.next = groupHead.next; + groupHead.next = curr; + curr = next; + } + } + + return root.next; + } +} diff --git a/[0026][Remove Duplicates from Sorted Array]/[0026][Remove Duplicates from Sorted Array].iml b/[0026][Remove Duplicates from Sorted Array]/[0026][Remove Duplicates from Sorted Array].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0026][Remove Duplicates from Sorted Array]/[0026][Remove Duplicates from Sorted Array].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0026][Remove Duplicates from Sorted Array]/[0026][RemoveDuplicatesfromSortedArray].iml b/[0026][Remove Duplicates from Sorted Array]/[0026][RemoveDuplicatesfromSortedArray].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0026][Remove Duplicates from Sorted Array]/[0026][RemoveDuplicatesfromSortedArray].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0026][Remove Duplicates from Sorted Array]/src/Solution.java b/[0026][Remove Duplicates from Sorted Array]/src/Solution.java new file mode 100644 index 0000000..9131cb0 --- /dev/null +++ b/[0026][Remove Duplicates from Sorted Array]/src/Solution.java @@ -0,0 +1,54 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 16:40 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Given a sorted array, remove the duplicates in place such that each element
+     * appear only once and return the new length.
+     * Do not allocate extra space for another array, you must do this in place
+     * with constant memory.
+     * For example,
+     * Given input array nums = [1,1,2],
+     * Your function should return length = 2, with the first two elements of nums
+     * being 1 and 2 respectively. It doesnt matter what you leave beyond the new length.
+     *
+     * Ŀ
+     * һ飬еظԪȥֻͬһҷµԪظ
+     * Ҫһµڳʱڽ
+     *
+     * ˼·
+     * ӵڶԪؿʼΪǰԪأǰԪǰһԪͬɾԪأ
+     * ͬͽƶȷλãԪ˸
+     * 
+ * + * @param A + * @return + */ + public int removeDuplicates(int[] A) { + + if (A == null) { + return 0; + } + + if (A.length < 2) { + return A.length; + } + + // ָһλ + int index = 1; + for (int i = 1; i < A.length; i++) { + // index - 1ʾǰһźõλ + if (A[index - 1] < A[i]) { + A[index] = A[i]; + index++; + } + } + + return index; + } +} diff --git a/[0026][Remove Duplicates from Sorted Array]/src/Solution2.java b/[0026][Remove Duplicates from Sorted Array]/src/Solution2.java new file mode 100644 index 0000000..fc801b2 --- /dev/null +++ b/[0026][Remove Duplicates from Sorted Array]/src/Solution2.java @@ -0,0 +1,57 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 16:40 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + /** + *
+     * ԭ
+     * Given a sorted array, remove the duplicates in place such that each element
+     * appear only once and return the new length.
+     * Do not allocate extra space for another array, you must do this in place
+     * with constant memory.
+     * For example,
+     * Given input array nums = [1,1,2],
+     * Your function should return length = 2, with the first two elements of nums
+     * being 1 and 2 respectively. It doesnt matter what you leave beyond the new length.
+     *
+     * Ŀ
+     * һ飬еظԪȥֻͬһҷµԪظ
+     * Ҫһµڳʱڽ
+     *
+     * ˼·
+     * ӵڶԪؿʼΪǰԪأǰԪǰһԪͬɾԪأ
+     * ͬͽƶȷλãԪ˸
+     * 
+ * + * @param A + * @return + */ + public int removeDuplicates(int[] A) { + + if (A.length == 0) { + return 0; + } + + int index = 0;//[0,index]ֻ¼гֵİСΨһһѾź + int next = 1; + + // 㷨˼룺index֮ıA[index]ҵƶA[index+1] + // indexƶһλãnextƶһλãұA[index] + + while (next < A.length) { + while (next < A.length && A[index] == A[next]) { // Ҳ + next++; + } + + if (next < A.length) { + index++; + A[index] = A[next]; + next++; + } + } + return index + 1; + } +} diff --git a/[0027][Remove Element]/[0027][Remove Element].iml b/[0027][Remove Element]/[0027][Remove Element].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0027][Remove Element]/[0027][Remove Element].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0027][Remove Element]/src/Solution.java b/[0027][Remove Element]/src/Solution.java new file mode 100644 index 0000000..bfdcaf6 --- /dev/null +++ b/[0027][Remove Element]/src/Solution.java @@ -0,0 +1,52 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 16:43 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Given an array and a value, remove all instances of that value in place and return the new length.
+     *  The order of elements can be changed. It doesnt matter what you leave beyond the new length.
+     *
+     * Ŀ
+     * һһֵɾֵȵԪأҷµijȡ
+     *
+     * ˼·
+     * ֵΪelemԪصλãjұֵΪelemԪصλãȻjλõֵƶiλá
+     * 
+ * + * @param nums + * @param val + * @return + */ + public int removeElement(int[] nums, int val) { + int exchange = 0; // ¼ĴҲͳelemԪֵȵĸ + + // 㷨˼룺iֵΪelemԪصλãjұֵΪelemԪصλã + // ȡȺóΪ1Խ + for (int i = 0, j = nums.length - 1; i <= j; i++) { + // ҵҪԪ + if (nums[i] == val) { + exchange++; + + // 濪ʼǰҵһelemԪ + while (j > i && nums[j] == val) { + // ֵΪelemԪ˵Ҫǽ̿ʡȥ + exchange++; + j--; + } + + // 1ΪelemԪصλãjλõԪطŵiλ + // 2ûҵelemԪصλãiԪֵeʱj=i + // jеֵiûйϵ + nums[i] = nums[j]; + j--; // jѾʹԻҪǰƶһµλ + } + } + + return nums.length - exchange; + } +} diff --git a/[0027][Remove Element]/src/Solution2.java b/[0027][Remove Element]/src/Solution2.java new file mode 100644 index 0000000..e87040c --- /dev/null +++ b/[0027][Remove Element]/src/Solution2.java @@ -0,0 +1,40 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 16:43 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + /** + *
+     * ԭ
+     * Given an array and a value, remove all instances of that value in place and return the new length.
+     *  The order of elements can be changed. It doesnt matter what you leave beyond the new length.
+     *
+     * Ŀ
+     * һһֵɾֵȵԪأҷµijȡ
+     *
+     * ˼·
+     *
+     * 
+ * + * @param nums + * @param val + * @return + */ + public int removeElement(int[] nums, int val) { + + // [0, ..., index - 1]ʾѾųvalֵ飬indexʾ֮ԷԪصλã + // Ҳʾij + int index = 0; + for (int i = 0; i < nums.length; i++) { + // Ⱦƶ + if (nums[i] != val) { + nums[index] = nums[i]; + ++index; + } + } + + return index; + } +} diff --git a/[0028][Implement-strStr()]/[0028][Implement-strStr()].iml b/[0028][Implement-strStr()]/[0028][Implement-strStr()].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0028][Implement-strStr()]/[0028][Implement-strStr()].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0028][Implement-strStr()]/src/Solution.java b/[0028][Implement-strStr()]/src/Solution.java new file mode 100644 index 0000000..2f84bbe --- /dev/null +++ b/[0028][Implement-strStr()]/src/Solution.java @@ -0,0 +1,97 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 16:45 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Implement strStr().
+     * Returns the index of the first occurrence of needle in haystack, or -1
+     * if needle is not part of haystack.
+     *
+     * Ŀ
+     * ʵʵstrStr()жһַһַгֵλáƥͷ-1
+     *
+     * ˼·
+     * ʹKMP㷨ʵ
+     * 
+ * + * @param haystack + * @param needle + * @return + */ + public int strStr(String haystack, String needle) { + + if (haystack == null || needle == null) { + return -1; + } + + if (needle.length() > haystack.length()) { + return -1; + } + + if ("".equals(haystack)) { + if ("".equals(needle)) { + return 0; + } else { + return -1; + } + } else { + if ("".equals(needle)) { + return 0; + } + } + + + return kmpIndex(haystack, needle); + } + + private int kmpIndex(String haystack, String needle) { + + + int i = 0; + int j = 0; + int[] next = next(needle); + while (i < haystack.length() && j < needle.length()) { + if (j == -1 || haystack.charAt(i) == needle.charAt(j)) { + ++i; + ++j; + } else { + j = next[j]; + } + } + + if (j == needle.length()) { + return i - j; + } else { + return -1; + } + } + + private int[] next(String needle) { + int[] next = new int[needle.length()]; + next[0] = -1; + int i = 0; + int j = -1; + int k = needle.length() - 1; + while (i < k) { + if (j == -1 || needle.charAt(i) == needle.charAt(j)) { + ++i; + ++j; + if (needle.charAt(i) != needle.charAt(j)) { + next[i] = j; + } else { + next[i] = next[j]; + } + + } else { + j = next[j]; + } + } + + return next; + } +} diff --git a/[0029][Divide Two Integers]/[0029][Divide Two Integers].iml b/[0029][Divide Two Integers]/[0029][Divide Two Integers].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0029][Divide Two Integers]/[0029][Divide Two Integers].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0029][Divide Two Integers]/[0029][DivideTwoIntegers].iml b/[0029][Divide Two Integers]/[0029][DivideTwoIntegers].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0029][Divide Two Integers]/[0029][DivideTwoIntegers].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0029][Divide Two Integers]/src/Main.java b/[0029][Divide Two Integers]/src/Main.java new file mode 100644 index 0000000..ac26ef0 --- /dev/null +++ b/[0029][Divide Two Integers]/src/Main.java @@ -0,0 +1,13 @@ +/** + * Author: + * Date: 2015-06-30 + * Time: 21:05 + * Declaration: All Rights Reserved !!! + */ +public class Main { + public static void main(String[] args) { + Solution solution = new Solution(); + + System.out.println(solution.divide(-1010369383, -2147483648)); + } +} diff --git a/[0029][Divide Two Integers]/src/Solution.java b/[0029][Divide Two Integers]/src/Solution.java new file mode 100644 index 0000000..7a9e147 --- /dev/null +++ b/[0029][Divide Two Integers]/src/Solution.java @@ -0,0 +1,68 @@ +/** + * Author: + * Date: 2015-06-30 + * Time: 20:46 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Divide two integers without using multiplication, division and mod operator.
+     * If it is overflow, return MAX_INT.
+     *
+     * Ŀ⣺
+     * ʹó˷ȡ࣬Ľͷ
+     *
+     * ˼·
+     * κһԱʾ2Ϊ׵һϣ
+     * num=a_0*2^0+a_1*2^1+a_2*2^2+...+a_n*2^n
+     * ʽԼһλ൱ڳ2ó
+     * ֱڱ֮ǰõһĻȻ
+     * ÿγԼȥӼ2^k,Ȼ
+     * ƵֱΪ0ΪֹΪĵǰ2֪
+     * ʱ临ӶΪO(log(n))
+     *
+     * 
+ * + * @param dividend + * @param divisor + * @return + */ + public int divide(int dividend, int divisor) { + // ʱ + if (divisor == 0 || dividend == Integer.MIN_VALUE && divisor == -1) { + return Integer.MAX_VALUE; + } + + // λ + int sign = ((dividend < 0) ^ (divisor < 0)) ? -1 : 1; + + // ֵΪֹʹlong + long dvd = Math.abs((long) dividend); + long dvs = Math.abs((long) divisor); + + // ¼ + int result = 0; + + // ڳ + while (dvd >= dvs) { + // ¼ + long tmp = dvs; + // ¼̵ĴС + long mul = 1; + + while (dvd >= (tmp << 1)) { + tmp <<= 1; + mul <<= 1; + } + + // ȥӽdvddvsֵֵָΪtmp + dvd -= tmp; + + // + result += mul; + } + + return result * sign; + } +} diff --git a/[0030][Substring With Concatenation Of All Words]/[0030][Substring With Concatenation Of All Words].iml b/[0030][Substring With Concatenation Of All Words]/[0030][Substring With Concatenation Of All Words].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0030][Substring With Concatenation Of All Words]/[0030][Substring With Concatenation Of All Words].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0030][Substring With Concatenation Of All Words]/[0030][SubstringWithConcatenationOfAllWords].iml b/[0030][Substring With Concatenation Of All Words]/[0030][SubstringWithConcatenationOfAllWords].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0030][Substring With Concatenation Of All Words]/[0030][SubstringWithConcatenationOfAllWords].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0030][Substring With Concatenation Of All Words]/src/Solution.java b/[0030][Substring With Concatenation Of All Words]/src/Solution.java new file mode 100644 index 0000000..b6d432d --- /dev/null +++ b/[0030][Substring With Concatenation Of All Words]/src/Solution.java @@ -0,0 +1,33 @@ +import java.util.List; + +/** + * Author: + * Date: 2015-07-01 + * Time: 08:23 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * You are given a string, s, and a list of words, words,
+     * that are all of the same length. Find all starting indices
+     * of substring(s) in s that is a concatenation of each word
+     * in words exactly once and without any intervening characters.
+     *
+     * For example, given:
+     * s: "barfoothefoobarman"
+     * words: ["foo", "bar"]
+     * You should return the indices: [0,9].
+     * (order does not matter).
+     * 
+ * + * @param s + * @param words + * @return + */ + public List findSubstring(String s, String[] words) { + + + return null; + } +} diff --git a/[0031][Next Permutation]/[0031][Next Permutation].iml b/[0031][Next Permutation]/[0031][Next Permutation].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0031][Next Permutation]/[0031][Next Permutation].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0031][Next Permutation]/src/Main.java b/[0031][Next Permutation]/src/Main.java new file mode 100644 index 0000000..1f5a159 --- /dev/null +++ b/[0031][Next Permutation]/src/Main.java @@ -0,0 +1,42 @@ +import org.junit.Test; + +import java.util.Arrays; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-14 21:30 + **/ +public class Main { + + @Test + public void test1() { + Solution solution = new Solution(); + int[] nums = {1, 2, 3}; + solution.nextPermutation(nums); + System.out.println(Arrays.toString(nums)); + } + + @Test + public void test2() { + Solution solution = new Solution(); + int[] nums = {3, 2, 1}; + solution.nextPermutation(nums); + System.out.println(Arrays.toString(nums)); + } + + @Test + public void test3() { + Solution solution = new Solution(); + int[] nums = {1, 1, 5}; + solution.nextPermutation(nums); + System.out.println(Arrays.toString(nums)); + } + + @Test + public void test4() { + Solution solution = new Solution(); + int[] nums = {1, 3, 2}; + solution.nextPermutation(nums); + System.out.println(Arrays.toString(nums)); + } +} diff --git a/[0031][Next Permutation]/src/Solution.java b/[0031][Next Permutation]/src/Solution.java new file mode 100644 index 0000000..90a5a19 --- /dev/null +++ b/[0031][Next Permutation]/src/Solution.java @@ -0,0 +1,82 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-14 21:17 + **/ +public class Solution { + /** + *
+     * Implement next permutation, which rearranges numbers into the lexicographically next
+     * greater permutation of numbers.
+     *
+     * If such arrangement is not possible, it must rearrange it as the lowest possible order
+     * (ie, sorted in ascending order).
+     *
+     * The replacement must be in-place and use only constant extra memory.
+     *
+     * Here are some examples. Inputs are in the left-hand column and its corresponding outputs
+     * are in the right-hand column.
+     *
+     * 1,2,3 → 1,3,2
+     * 3,2,1 → 1,2,3
+     * 1,1,5 → 1,5,1
+     *
+     * 1.首先从最尾端开始往前寻找一个元素,满足nums[i] < nums[i+1]。
+     * 如果没有找到即i < 0, 说明整个数组是递增的,已经到了最大值,此时只要反转数组即可
+     * 如果i >= 0
+     *
+     * 2.再从最尾端开始往前检验,找出第一个大于nums[i]的元素nums[j] 并且,j >= i
+     * 将nums[i],nums[j]元素对调(swap)。
+     *
+     * 3.再将i位置之后的所有元素颠倒(reverse)排序。
+     * 
+ * + * @param nums + */ + public void nextPermutation(int[] nums) { + int i = nums.length - 2; + // 从后向前查找第一个元素i,并且使用nums[i] >= nums[i+1]不成立。 + while (i >= 0 && nums[i] >= nums[i + 1]) { + i--; + } + + // 此时nums[i+1, ..., last]是递增的 + + + if (i >= 0) { + int j = nums.length - 1; + // 从右开始向左找,找第一个大于等num[i]的元素 + // 如果找到i==j,说明没有找到 + while (j > i && nums[j] <= nums[i]) { + j--; + } + + // 交换两者之间的值,当j == i时,交换也没有问题 + swap(nums, i, j); + + // 将nums[i+1, last]进行反转 + reverse(nums, i + 1); + } else { + // 说明整个序列是非递增的 + // 对子数组进行翻转 + reverse(nums, 0); + } + + + } + + private void reverse(int[] nums, int start) { + int i = start; + int j = nums.length - 1; + while (i < j) { + swap(nums, i, j); + i++; + j--; + } + } + + private void swap(int[] nums, int i, int j) { + int temp = nums[i]; + nums[i] = nums[j]; + nums[j] = temp; + } +} diff --git a/[0032][Longest Valid Parentheses]/[0032][Longest Valid Parentheses].iml b/[0032][Longest Valid Parentheses]/[0032][Longest Valid Parentheses].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0032][Longest Valid Parentheses]/[0032][Longest Valid Parentheses].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0032][Longest Valid Parentheses]/src/Main.java b/[0032][Longest Valid Parentheses]/src/Main.java new file mode 100644 index 0000000..aafc2f1 --- /dev/null +++ b/[0032][Longest Valid Parentheses]/src/Main.java @@ -0,0 +1,15 @@ +/** + * Author: + * Date: 2015-06-25 + * Time: 09:22 + * Declaration: All Rights Reserved !!! + */ +public class Main { + public static void main(String[] args) { + Solution solution = new Solution(); + System.out.println(solution.longestValidParentheses("(()")); + System.out.println(solution.longestValidParentheses(")()())")); + System.out.println(solution.longestValidParentheses(")()())()")); + System.out.println(solution.longestValidParentheses(")()(()()))()()()")); + } +} diff --git a/[0032][Longest Valid Parentheses]/src/Solution.java b/[0032][Longest Valid Parentheses]/src/Solution.java new file mode 100644 index 0000000..2e4f5d1 --- /dev/null +++ b/[0032][Longest Valid Parentheses]/src/Solution.java @@ -0,0 +1,54 @@ +import java.util.Deque; +import java.util.LinkedList; +import java.util.Stack; + +/** + * Author: + * Date: 2015-06-25 + * Time: 09:12 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Given a string containing just the characters '(' and ')',
+     * find the length of the longest valid (well-formed) parentheses substring.
+     *
+     * For "(()", the longest valid parentheses substring is "()", which has length = 2.
+     * Another example is ")()())", where the longest valid parentheses substring is "()()",
+     * which has length = 4.
+     *
+     * Ŀ⣺
+     * һַֻСźţĺϷСŵĿ
+     *
+     * ˼·
+     * ʹջʵ
+     * 
+ * + * @param s + * @return + */ + public int longestValidParentheses(String s) { + // ڼ¼ƥźŵλ + Stack st = new Stack<>(); + int max = 0; + for (int i = 0; i < s.length(); i++) { + + // ǵǰַţҼ¼ջǿգǰһַ + if (s.charAt(i) == ')' && !st.isEmpty() && s.charAt(st.peek()) == '(') { + // ųջ + st.pop(); + // ֵ + // ʱ(ƥ)ѾջջҪôΪգҪô뵱ǰ)) + // Ҫô뵱ǰ)ڶ( + max = Math.max(max, i - ((st.isEmpty()) ? -1 : st.peek())); + } + // ͽַջ + else { + st.push(i); + } + } + + return max; + } +} diff --git a/[0032][Longest Valid Parentheses]/src/Solution2.java b/[0032][Longest Valid Parentheses]/src/Solution2.java new file mode 100644 index 0000000..fb9b995 --- /dev/null +++ b/[0032][Longest Valid Parentheses]/src/Solution2.java @@ -0,0 +1,59 @@ +import java.util.Deque; +import java.util.LinkedList; + +/** + * Author: + * Date: 2015-06-25 + * Time: 09:12 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + /** + *
+     * Given a string containing just the characters '(' and ')',
+     * find the length of the longest valid (well-formed) parentheses substring.
+     *
+     * For "(()", the longest valid parentheses substring is "()", which has length = 2.
+     * Another example is ")()())", where the longest valid parentheses substring is "()()",
+     * which has length = 4.
+     *
+     * Ŀ⣺
+     * һַֻСźţĺϷСŵĿ
+     *
+     * ˼·
+     * ʹջʵ
+     * 
+ * + * @param s + * @return + */ + public int longestValidParentheses(String s) { + int result = 0; + int start = 0; + // ¼ŵλ + Deque m = new LinkedList<>(); + for (int i = 0; i < s.length(); ++i) { + // žͼ¼λ + if (s.charAt(i) == '(') { + m.push(i); + } + // + else if (s.charAt(i) == ')') { + // ֮ǰŶѾԣߴû + if (m.isEmpty()) { + // ǰλѾЧˣ¼һλǿʼԵλ + start = i + 1; + } else { + // ջӦ + m.pop(); + // ջΪգ˵startʼһֱƥ䣬ûֶţ + // ǣMath.max(result, i - start + 1) + // ջǿգ˵жţһŵλþm.peek() + // ƥž: Math.max(result, i - m.peek()) + result = m.isEmpty() ? Math.max(result, i - start + 1) : Math.max(result, i - m.peek()); + } + } + } + return result; + } +} diff --git a/[0033][Search In Rotated Sorted Array]/[0033][Search In Rotated Sorted Array].iml b/[0033][Search In Rotated Sorted Array]/[0033][Search In Rotated Sorted Array].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0033][Search In Rotated Sorted Array]/[0033][Search In Rotated Sorted Array].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0033][Search In Rotated Sorted Array]/[0033][SearchInRotatedSortedArray].iml b/[0033][Search In Rotated Sorted Array]/[0033][SearchInRotatedSortedArray].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0033][Search In Rotated Sorted Array]/[0033][SearchInRotatedSortedArray].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0033][Search In Rotated Sorted Array]/src/Main.java b/[0033][Search In Rotated Sorted Array]/src/Main.java new file mode 100644 index 0000000..7665c43 --- /dev/null +++ b/[0033][Search In Rotated Sorted Array]/src/Main.java @@ -0,0 +1,14 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-12 23:22 + **/ +public class Main { + public static void main(String[] args) { + int[] nums = {4,5,6,7,0,1,2} + ; + Solution2 solution = new Solution2(); + + System.out.println(solution.search(nums, 4)); + System.out.println(solution.search(nums, 3)); + } +} diff --git a/[0033][Search In Rotated Sorted Array]/src/Solution.java b/[0033][Search In Rotated Sorted Array]/src/Solution.java new file mode 100644 index 0000000..4f3e4eb --- /dev/null +++ b/[0033][Search In Rotated Sorted Array]/src/Solution.java @@ -0,0 +1,120 @@ +/** + * Author: 王俊超 + * Date: 2015-06-21 + * Time: 14:48 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Suppose a sorted array is rotated at some pivot unknown to you beforehand.
+     * (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).
+     * You are given a target value to search. If found in the array return its
+     * index, otherwise return -1.
+     *
+     * You may assume no duplicate exists in the array.
+     *
+     * 题目大意:
+     * 假设一个排序的数组以一个未知的的枢轴旋转。(即,0 1 2 4 5 6 7可能成为4 5 6 7 0 1 2)。
+     * 给定一个目标值,在数组中搜寻。如果存在就返回其对应的下标,否则返回-1。
+     * 假设数组中不存在重复值。
+     *
+     * 解题思路:
+     * 找旋转数组最小值的位置minIndex(见LeetCode第153题 ),如果minIndex不为,说明其在分隔成
+     * 两个有序数组,并且前一个中的第一个元素都大于后一个数组的每一个元素,判断target中哪一个数组区
+     * 间中使用二叉搜索算法查找,如果minIndex=0,说明全局有序,对整个数组进行二叉查找,返回查找结果
+     * 
+ * + * @param nums + * @param target + * @return + */ + public int search(int[] nums, int target) { + + if (nums != null && nums.length > 0) { + + // 找最小元素对应的下标 + int minIndex = searchMinIndex(nums, 0, nums.length - 1); + + // 整个数组全局有序 + if (minIndex == 0) { + return binarySearch(nums, 0, nums.length - 1, target); + } + // 有两个局部有序区间, 如 4 5 6 7 8 9 0 1 2 3 + else { + // 恬好和后一个有序区间的最后一个元素相等,返回对应的下标 + if (nums[nums.length - 1] == target) { + return nums.length - 1; + } + // target可能在后一个有序区间中 + else if (nums[nums.length - 1] > target) { + return binarySearch(nums, minIndex, nums.length - 1, target); + } + // target可能是前一个有序区间中 + else { + return binarySearch(nums, 0, minIndex - 1, target); + } + } + } + + return -1; + } + + /** + * 二分搜索 + * + * @param nums 数组 + * @param start 起始位置 + * @param end 结束位置 + * @param target 搜索目标 + * @return 匹配元素的下标 + */ + public int binarySearch(int[] nums, int start, int end, int target) { + + int mid; + while (start <= end) { + mid = start + ((end - start) >> 1); + + if (nums[mid] == target) { + return mid; + } else if (nums[mid] > target) { + end = mid - 1; + } else { + start = mid + 1; + } + } + + return -1; + } + + /** + * 找最小元素的下标 + * + * @param nums 数组 + * @param start 起始位置 + * @param end 结束位置 + * @return 最小元素的下标 + */ + public int searchMinIndex(int[] nums, int start, int end) { + + int mid; + while (start < end) { + mid = start + ((end - start) >> 1); + // 后一个数比前个数小就找到了 + if (nums[mid] > nums[mid + 1]) { + return mid + 1; + } + // 说明中间值在第一个有序的数组中 + else if (nums[mid] > nums[start]) { + start = mid; + } + // 说明中间值在第二个有序的数组中 + else { + end = mid; + } + } + + // 说明整个数组是有序的 + return 0; + } +} diff --git a/[0033][Search In Rotated Sorted Array]/src/Solution2.java b/[0033][Search In Rotated Sorted Array]/src/Solution2.java new file mode 100644 index 0000000..59a71a5 --- /dev/null +++ b/[0033][Search In Rotated Sorted Array]/src/Solution2.java @@ -0,0 +1,65 @@ +/** + * Author: 王俊超 + * Date: 2015-06-21 + * Time: 14:48 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + /** + *
+     * Suppose a sorted array is rotated at some pivot unknown to you beforehand.
+     * (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).
+     * You are given a target value to search. If found in the array return its
+     * index, otherwise return -1.
+     *
+     * You may assume no duplicate exists in the array.
+     *
+     * 题目大意:
+     * 假设一个排序的数组以一个未知的的枢轴旋转。(即,0 1 2 4 5 6 7可能成为4 5 6 7 0 1 2)。
+     * 给定一个目标值,在数组中搜寻。如果存在就返回其对应的下标,否则返回-1。
+     * 假设数组中不存在重复值。
+     *
+     * 解题思路:
+     * 找旋转数组最小值的位置minIndex(见LeetCode第153题 ),如果minIndex不为,说明其在分隔成
+     * 两个有序数组,并且前一个中的第一个元素都大于后一个数组的每一个元素,判断target中哪一个数组区
+     * 间中使用二叉搜索算法查找,如果minIndex=0,说明全局有序,对整个数组进行二叉查找,返回查找结果
+     * 
+ * + * @param nums + * @param target + * @return + */ + public int search(int[] nums, int target) { + if (nums == null || nums.length == 0) { + return -1; + } + + int left = 0; + int right = nums.length - 1; + int mid; + while (left <= right) { + mid = left + (right - left) / 2; + if (nums[mid] == target) { + return mid; + } + + // 说明first,mid都在同一个递增子序列中 + if (nums[left] <= nums[mid]) { + if (nums[left] <= target && target < nums[mid]) { + right = mid - 1; + } else { + left = mid + 1; + } + } else { + if (nums[mid] < target && target <= nums[right]) { + left = mid + 1; + } else { + right = mid - 1; + } + } + } + + return -1; + } + +} diff --git a/[0034][Search For A Range]/[0034][Search For A Range].iml b/[0034][Search For A Range]/[0034][Search For A Range].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0034][Search For A Range]/[0034][Search For A Range].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0034][Search For A Range]/[0034][SearchForARange].iml b/[0034][Search For A Range]/[0034][SearchForARange].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0034][Search For A Range]/[0034][SearchForARange].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0034][Search For A Range]/src/Solution.java b/[0034][Search For A Range]/src/Solution.java new file mode 100644 index 0000000..9314e1b --- /dev/null +++ b/[0034][Search For A Range]/src/Solution.java @@ -0,0 +1,124 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 16:55 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Given a sorted array of integers, find the starting and ending position of a given target value.
+     * Your algorithms runtime complexity must be in the order of O(log n).
+     * If the target is not found in the array, return [-1, -1].
+     * For example,
+     * Given [5, 7, 7, 8, 8, 10] and target value 8,
+     * return [3, 4].
+     *
+     * Ŀ
+     * һź飬ͬʱһҪҵֵ ҳеijʼͽλá
+     * 㷨ʱ临ӶҪΪlog(N)
+     * ûҵͷ[-1, -1]
+     *
+     * ˼·
+     * ٶǵģöֲ㷨Ƿھͷ[-1,-1]
+     * ھͷֱһγֵλúʼֵλáֵλʱȴ
+     * һλÿʼңڴҵֵǰһλãھǰ22ָӣ
+     * Сھ˻صԭλõĺһвң°124ӵķʽУֱҵΪֹ
+     * ȵԪҲһġ
+     * 
+ * + * @param A + * @param target + * @return + */ + public int[] searchRange(int[] A, int target) { + + if (A == null || A.length == 0) { + return new int[]{-1, -1}; + } + + int lo = 0; + int hi = A.length - 1; + int mi = 0; + // ǷֵΪtargetԪ + while (lo <= hi) { + mi = lo + (hi - lo) / 2; + if (target < A[mi]) { + hi = mi - 1; + } else if (target > A[mi]) { + lo = mi + 1; + } else { + break; + } + + } + + if (A[mi] != target) { + return new int[]{-1, -1}; + } + + lo = searchFirst(A, 0, mi, target); + hi = searchLast(A, mi, A.length - 1, target); + + return new int[]{lo, hi}; + } + + /** + * targetȳֵλãҵķΧ[lo, hi]A[hi]targetAΪ + * + * @param A ҵ + * @param lo ҵʼλ + * @param hi ҵĽλ + * @param target ҵֵ + * @return targetȳֵλ + */ + private int searchFirst(int[] A, int lo, int hi, int target) { + + int gap = 1; + do { + hi -= gap; + if (hi < lo || A[hi] != target) { + hi += gap; + + if (hi <= lo || A[hi - 1] != target) { + return hi; + } else { + gap = 1; + hi--; + } + } else {// һελúgapȻ + gap *= 2; + } + } while (true); + + } + + /** + * targetֵλãҵķΧ[lo, hi]A[lo]targetAΪ + * + * @param A ҵ + * @param lo ҵʼλ + * @param hi ҵĽλ + * @param target ҵֵ + * @return targetֵλ + */ + private int searchLast(int[] A, int lo, int hi, int target) { + int gap = 1; + do { + lo += gap; + if (lo > hi || A[lo] != target) { + lo -= gap; + + if (lo >= hi || A[lo + 1] != target) { + return lo; + } else { + gap = 1; + lo++; + } + } else {// һελǰgapȻ + gap *= 2; + } + } while (true); + } +} diff --git a/[0035][Search Insert Position]/[0035][Search Insert Position].iml b/[0035][Search Insert Position]/[0035][Search Insert Position].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0035][Search Insert Position]/[0035][Search Insert Position].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0035][Search Insert Position]/[0035][SearchInsertPosition].iml b/[0035][Search Insert Position]/[0035][SearchInsertPosition].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0035][Search Insert Position]/[0035][SearchInsertPosition].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0035][Search Insert Position]/src/Solution.java b/[0035][Search Insert Position]/src/Solution.java new file mode 100644 index 0000000..90057f0 --- /dev/null +++ b/[0035][Search Insert Position]/src/Solution.java @@ -0,0 +1,70 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 16:57 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Given a sorted array and a target value, return the index if the target is found.
+     * If not, return the index where it would be if it were inserted in order.
+     * You may assume no duplicates in the array.
+     * Here are few examples.
+     *
+     * [1,3,5,6], 5  2
+     * [1,3,5,6], 2  1
+     * [1,3,5,6], 7  4
+     * [1,3,5,6], 0  0
+     *
+     * Ŀ
+     * һ飬һֵָҵֵֵλãûҵֵеIJλá
+     * ûظԪء
+     *
+     * ˼·
+     * һֱӵIJ㷨
+     * ʹöֲ㷨
+     * 
+ * + * @param A + * @param target + * @return + */ + public int searchInsert(int[] A, int target) { + + int mid; + int lo = 0; + int hi = A.length - 1; + + while (lo <= hi) { + mid = lo + (hi - lo) / 2; + + if (A[mid] == target) { + return mid; + } else if (A[mid] < target) { + lo = mid + 1; + } else { + hi = mid - 1; + } + } + + return lo; + } + + public int searchInsert2(int[] A, int target) { + + if (A == null) { + return -1; + } + + int i; + for (i = 0; i < A.length; i++) { + if (A[i] >= target) { + return i; + } + } + + return i; + } +} diff --git a/[0036][Valid Sudoku]/[0036][Valid Sudoku].iml b/[0036][Valid Sudoku]/[0036][Valid Sudoku].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0036][Valid Sudoku]/[0036][Valid Sudoku].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0036][Valid Sudoku]/src/Solution.java b/[0036][Valid Sudoku]/src/Solution.java new file mode 100644 index 0000000..80b5bcd --- /dev/null +++ b/[0036][Valid Sudoku]/src/Solution.java @@ -0,0 +1,108 @@ +import java.util.Arrays; + +/** + * Author: + * Date: 2015-08-21 + * Time: 16:59 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.
+     * The Sudoku board could be partially filled, where empty cells are filled
+     * with the character '.'.
+     *
+     * A partially filled sudoku which is valid.
+     * Note:
+     * A valid Sudoku board (partially filled) is not necessarily solvable.
+     * Only the filled cells need to be validated.
+     *
+     * Ŀ
+     * ֤һǷϷ̵֤ӶӦҳ档
+     * Dzģյλʹõ档
+     * ע⣺Ϸ̲һҪĿɽģֻҪҪͿԡ
+     *
+     * ˼·
+     * ȶнм飬ٶнм飬飳*ķ
+     * 
+ * + * @param board + * @return + */ + public boolean isValidSudoku(char[][] board) { + // .ASCIIֵ460ASCIIֵ48/ASCIIֵ47 + int number = board[0].length; + int[] record = new int[10 + 2]; //.9ֵݵλ[2, 10] + boolean isValid; + reset(record); + + // нм + for (int i = 0; i < number; i++) { + for (int j = 0; j < number; j++) { + record[board[i][j] - '.']++; + } + + // Ǽʧ + if (!check(record)) { + return false; + } + // ɹ + else { + reset(record); + } + } + + // нм + for (int i = 0; i < number; i++) { + for (int j = 0; j < number; j++) { + record[board[j][i] - '.']++; + } + + if (!check(record)) { // Ǽʧ + return false; + } else { // ɹ + reset(record); + } + } + + // 3*3 + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + + for (int k = i * 3; k < (i + 1) * 3; k++) { + for (int l = j * 3; l < (j + 1) * 3; l++) { + record[board[k][l] - '.']++; + } + } + + if (!check(record)) { // Ǽʧ + return false; + } else { // ɹ + reset(record); + } + } + } + return true; + } + + private void reset(int[] a) { + Arrays.fill(a, 0); + } + + /** + * һУһУ3*3ķǷϷ1-9еָ1ͲϷ + * + * @param a ֤ + * @return ؽ + */ + private boolean check(int[] a) { + for (int i = 2; i < a.length; i++) { + if (a[i] > 1) { + return false; + } + } + return true; + } +} diff --git a/[0036][Valid Sudoku]/src/sodoku.png b/[0036][Valid Sudoku]/src/sodoku.png new file mode 100644 index 0000000000000000000000000000000000000000..e37925927203736ee9bf73ce716e3e8a54191f46 GIT binary patch literal 14593 zcmZvD2RPRK|1XsWnq+15$Ow^9*`l&Tk(rS_LK%?}ky2Jxl2MB6kR-cdtL%~N5y{S; z=kd()m7#9k~5H#kdW+ER5*Vb|6L{i*}W704w%rB z#D8|0D9fKG*&_aWQJNA#Lc&U-cwR=+EpD>MRY$X9ab|W}o$Ndr*$!oD9&Q@yQ(6<9 z^@k4yF|3`+tvnxm$+SZ!np{JOSl`m5Tu zD$>!fL0>l|LL0V^_UqcxwSSFqTI^Nc$#rl?qNY%j>o#9jg$9)c|NQ(@)1^xZNuTEC z<^mo)dZ`q}9m%7u+N?veXV0Fbq$KqMdxKij3-a=8(e}3I~16+?R$#qPTO^j4d-6CaN#)VNLBC=_Rzxz4!qcuEGjNmW_B3; z9C-@e0?!C-8*`))!;yo50|sd$!#wi$v*84kfq(h zX1w@|r8YVu;#{_2sbR7AV8z4v={_SKMbh=9@~x5O*`e-|+Yy{<2_*gF<4O$)k}(pu z-wtc%D+eCt(Yk@3_Fj+SFI(Q`;NZYyer(LI%Kwcz*Y17$s=B(K)kX2pc0GUgEWNGb zw0*aNg2L|LBWGTl*FWK+Cg(FKs)!SH>dZCWHQMkz#ia6)Ua&5Mq{m{=+R`*_;dIk0 z`Qed~+#3V3OqT3p&+xK?BO@1#jbBg~Qs+31D2=ygDgStD-u6>aNN9F;_UOrzkGIxG zrFnJVo}ZKGb;;1mGHFY{;{U#{&}rA1GiMmi*neG{F3*1Ob%%jqXTumXGc(yE#*cM% zk79%@x82xSb@58NVspK(jLGL9o7~u`{W51L-!~d@vaxNiVe#UKR8dvk_p`vEy16-g z;LC$Q;!HBT9vO^9^BcX^%F@%!)CuFb_-v+@^Z5ZLrV|(J$;>P*ou;})U#rGH%E~&S z@meKJ!ou2RqEq0|p+jRo3$j0azjh42fBN)kVXHl(|vJmTWwcJJBq>D#x9;civNf7-K1f*4LIHN@;LdO2Gu;^gG?#-La( zg5zTA&$oGbx^K<)1k#)s{IXwqc&ev3^0_4 zeJ+)?u$KGWd$Vx$Ph1>h+43Mo+192cXFVhI+b*?!t)f?yL9rvxGdX6?c6o z$8|JIqGj@D!LG;ac}0bVq8ZxRRaI5@4T^6iYCbw8^yplg=3AFPS}H0k71qUJO-hLw zJL`3HbgYJMY}IskGkSP*(q#GG_~4GPrj{(*0e6&_U;mL$XF#o<7gNd(YT+ zv$C=IwYF;BS(`jl$?e&d~+`POYqpj6wV%=1R0&gx&_l>4Jzhly#sq4S!@~1sG zUfk8@L|RFS#Nxz{FW3``N#MxH-v;T?K>o5uJqgns@2xw6f`W8Xo*&w$gLdCn!{;n@ zKgDuq`6wcYzH8SmMN`uCxqAL%?Cb(}*4=7N z?S8%wwrofs&899&PG;Y?Z(sO6W^L}MimIx*x+f=;{mBm>V@XYji{q{T{=KTUR&h=T zsPGo&kc3++Gd0q^)lgQ}_iIJP4h;>BT9(+$X^|tt!^So?+_y`xFSs`5kEOeH$493| z>Z9LAMpEDfs!^5NeTAi!4?@uPXhK0rJL+Yx}gz;8N z$@cn!_@UqL*jrLBy^361Tok)~T}DO*Xbc#rHT_-0uA!sz^pHBU$c?ka&s)_V+wFVr zzt)$!h?VZH$(b8I>pZW(8^5qpHD-e2Z5i@E-`ib?O){zb_Kp3Ye|+!V+rh}h#9kT| z`SfYc@0OI?pb{{X^JG_)UcQaB`xIyC*WIC zQ{%f!P>79(hXTux#jdS4*;^Wm6M7Q>2p}b;6Sg|AYaip|W4%C><>3f51vNEo2O$B0 zYgIw?yaq+oF)FX~bpmPmEw(l{E=<|Br5~o{yV|J7E8|qjJ#X9bhB#U(7cc6Td5Yo~ zR03adUvWk9S9fVV+gKTWe(%A9q2IqBMnq6;Zf=HGt`3Dt(}_AB!|9#q%=LS3_j7Lk zw}#Z#y3>;r`f?+6QS7>G-T*xR?=usVlljc@jX|ISO>X*AHq&IqA?;cE8B17v z>--2C>jDr4uASe*hkF3dPu?{~^BE}F+wHGhuK$xC1$CjiCr(4hkIVImiHT32Jrgwk=p!rYJk_nc@xy?t zNBEBXesc0{bK)t-I60~4=oIASc4Ft9$6FOk+>fNr&pThge*KYWwU(r%_vQ*G&U=SV zcc1rGJlGyeHC?_{rXz0{D$F+zcG=pz+h=Jxx@}F9R+B~2J!#=XSy>rbnL}sJQSfH8=U}9|aIld{L`1~h^^Ek% zu6#BLiMZuuH>~bmtO+1)v^iNhoSi#T1s9Zrd?9@Qo;?F!V}w3#xumw;hfbKAEa;o7 zX7N5iPhXpO?!g!kabRG;`FHaL$ylYvER%e*Z8vV-9Edi$^QpP{kk7R*_rsn&s{_vH z=2`6ZSeyvs&`3Q0>wA1X7+kmfj$~6)(|E=d!JTbwQDb9PS%v{?;~ClHo<PgZAvwTs$K%XDZ)O^V`JAuB4!)f7Pk&$PxpGfBM-u{@JXa-ij|vmnc34WDXj_xQYfCtPc~$KU$uSiG3aHZI|RrrPWXk@%$f zP|}l_n1|)%(m0YW?z_5QUM=&a_rdj4W>)4>8IpDAE0ZK3nU&Q?zra4NfG0}n37-M^ z3+Bg1=|Vu?vePde3*%;os;OvctApr;a&mKlrA$DvM)55>keVFWLP1gSsEEi@`A}wo8~tZ3zCKNi5+QM&>P}RS<`Z`4 zjf0-OlxuQfs=M%&vse`tMcd=ebF3ZEY24v+*ZhN%whHE-rdfotdT0Hm&}kIP8u}?PEsdSfKA%5-c0N?! z-mX=eZlk0`4t*V7%G!~BCD3bak#t2P20)gkp6JVEzg_+1$`}a^4UOLO-A5HNJXhw# z0?h&NE8!i!zbg7o|A*>*u^E&Q6;(tj*wc0*F5}d_y}h8OZAXqAvG^XBwxI8XdjfNiWBh5Gqm$F@-@jiv zI--G?uhpJ^|9E$M<%SKZ&%&RMmiKo0zP`Rzy(I+EBwKuY#whA|Z)WC(SIUwedqOEk za%LuPRS1(Z!2jscqwlO+cGgTwjSmfd0kh4_&L$d_-_d*M+W(Q1&#*+H_|_!xSu8A8 z%AdfW4E+9Gi=!*z^otUQU+*DjN$mIM(hbA45yW$R`t(UNL+fHGKjb6cMABlZfpU&X z^4PI^xXZgLfJIV?Q z0q$!!Zp*(@o?A61?ZIVjRN@`z0kpH@gG^0LEw8P$ytCFIw(Dx4px@5DgHR!>s z*3^tR!jRNq+gc|R4dWSB-$O)*dM=;5lCGHugms?ojfZ1TE1;;l=#qE>Bq!?h>i{)% zMf#Nt5$CZ3M^0a7J#iwqHiGkyXnluJjqEOhV@~M3GsdOROuI~`tgMW!y7>3kx7%AA zOLwY;K_^3`dk>+s;n{MR2af;;moz=AVkc{zNw?F~1Yns{v7mP%Q zehm+w#}##(8{X5AZN#6$&%tpY0`HoorF>73%R=OUv{0vPUx5RQ^yV^KSXda8`pt#$ zE1sU7GfPV;I1_qylR`GFTqGQ7312_??NU@z<3uI`D83ILHKp%T-y%sef(Wg`&iSfHp|%iHO3TPxHb5p z5RhM3LPE%^S8SyoORovDQV}ce$_J1dKU<&;&#LMq3;p#(eLcPASMvMgLliO$icdp_wCYL>^k}}43wC|ul=JD1 z9PJJnkN?8fp0vuYF1!O**ipWFHSTjlUKS5LU`b|;^ zx0$n&a^EFNO&&i42PcJ>fP5s!7xdeXR|bp{ii^&_dJdeP6$Rb)M_g{JR-@%2p2e!5*BvdW4iq z`%T<%=rnFR$vdki**RJP5^-_yLsV2Qn`e%z_WYlii5_i;x z4<8y!JzQ(2v&kL!ffvMm$Nu{JlOa6%QePhkjQK5oDsi`3g2cf3%HN9W>WHW)f4G;u zM^0C?wB&VGb896|_mw|~g*~iy|3`cK6XXX2qodjrJ9hLek3<_iJ$cR7J>LDWrKRNp zxw!8DaVV)cRAA8X{67jDjBXq@<*j^nyDO4H7{D48_BspkrKI0nq8=;*yEGfiUJc-fS~EwSX+kn-}0>uHI=`@C+X?wgIJ^! z-kR4t&JEXYTY3axu3TW>GygPxMhq8>r&T{kHD2u9^&f}uNI>NuWnRVZzyF?TT4pk6 zyZ8<(=D(Qs{$a?g`=j9NW50>O4ygAW)h%%oKq@9GWcj@Ut{1=><-N7m=ZRGBYWbZWxzyvztM@Jd@tEUe*Qv6VUq=x3{)@qz z>$h`#DVjA-J-FWTdM}c@B;=(!`ucyH>TecM@bJ1-%R+R(Bt@;FzNQi8Pi zcbLnN*w`b)VY_9tJ($9)^3h?~?>ty!$fXM{uP<6d1{mF0VJGr17=q(7b!>Dy+qTiA zhw5dI_Y|M;S)EWhc@;r#5_XGG(w!PSO?)OZv!tpmqaoRH*fEk)_XX~EYWb7M7#McZ zIKR5Hu}X5m&{?B&cdFLWgOty4nc${m(==%^IE$#bRB_%>-ax{%F{ zHKbghp^4i950I3=;%$^z=aojiV5$ybViOX|Yg|N>d;^CIVkR*Ev`>|GPl{@M9sC|4 zBA^4*vky2S&m@A=V1`r6gMs|Q`*_FhqZNof<6!a8ht$p8UC?dD7?Nfgju;JrN#hF{ zN(NztK5KGsA@e$FWT|pc0myrH{`m0&n;Z|5YieOph2(;qmv@$fq5KsQxPhO9a09|4 zB6N#yodEQ*3kZa%Nv+(YpydPb8@=4cu8;w|Cp;GP0+5uMNK{cv=)Av9U%oyUxLjlI z14pe4?^Ni$B~|P?Z86qA{r^JXf5rc){8j9noKC;K(kuFM-&qJwQd}7aSZ6yf-ZK zJYN6pTNHQ*7dNAvrnIB?nqZ6y@8VIb^BW<(Ns3e;EOzUYg;!PaH1r}jjB_pfA}b(* zly2QR4UHEi(H?M+Eg(3U%=nWp8Kj_Gvl}kQFW@jEVzg!vlHA-}BGy7COE^VE)1ERf z{hs@2jw5v{@nTn+-S#s}^dsZ`*w7G)WCK3S7}5m_`6RS=t*O`AWC0n?rsg&!et!Ps zR^V-vk7IL^VtDms?kFWlj^xc%{;^A4?)kvQ?0N=l_Qit=!4FR4Qp#xgDvc*?fDe^yj=)ZgNQUCBN43u@#OER2H zq|)c~Md|&)MNO|S9>D<)t2Gl56(yoI*>mR>;=A+-3<79XefmU7MMZ@he-279M$r7x zYC`^u1x_Q<`kY&ndiVDpk*j}l0xx_a%&GO%r3sEeZX6<0um{SOM0Kv3`g)$Xg#`zj zT#&lj;0M=fX6VNXSb*%ZRiy^{vQpFs;o;$KtMkVJ9hMMcs1DQnevtKWw_DDG%nvd% ztK!Xb8A|q$VMjt>ZUm8rb8Ej*!CpX7rzl2nV6Pj~ukd)KEVoNYN=9I=%e+w{Pa3@9nwXTM~02kY@JVnZ7Xr zp`oNE%Xy%i+Q$2At&IV`b0hUQQj8LA>V3cI*n@kUzJ2?4)5V3IhbIsRmbNpc$k7w*N|a3> zW6lJGhVF8+`>Efyh>R4g`#P^A$->;+KPHAASp*YIu@Y0CivoYVI1{uF?2Gya>`Y&#BgK7lJqBr_Uw(q1g zhD5&p^L^IG%@8K>Ippl)$BPSKhv=aYHHQ5wfH;3!)TEn|m1!l-7VV#jx!5Fzia|MP zdG{1LS@s-W1-2eF3q+Jl-X*`T#Mz3VvfIlb?Dq2<9XrrV%=!1}^Qt5y zbm_z_z}Sm~L`}WU&dx@B1eXGX#Nl^^I>|b2vj1;!{ldO>xWAuuC7lB(fen8w<}yB( z#3P54lz@$~rgL*Tgc^{PWby&Np<(^Ux+Ev( zD+b+@3l{=GbC4WoD36ek#_QEpAV8gVij~q)NlAkz5fQHI+QRo^wbWv*rE7X$eL2^@bQZbr{QC9Fy+)<60?CF>iQCP@ z(T0|m28wDYFW|6c*uAOL{QS*V_{`jPHZkLaA791|vG_yD-@eA^DbcajLc zhlkDJ84S|fMR-nN{Ne(Bnd17N&RjNdMH1919H{|y5vlw9*g?cWub@hH?Ak?37dAFL ztZ8+v>CEjvfj1#X$c%Bf9Xz;Xwt4eAMxkB?396xZRZ1TAdw0*I>%H9(Ft5sUDFdD_ zA$>Lj4{>^&X8L6ioc{hN^%E?G@YYOM72u6GZo%hvV@ z2??1A(j#2{8Ydb7I&I3g)ea6_(n^_1zd&g;S$CAK3_c^*X;fA3{q@=;#fbU%5OoAY znh076^$25u6vrR!Cm}#Vcc=p&7s>l@C|w=XesgsI_(i}N9zAOQq;Ck(9Rkb;r>0a9 z8;DQ|spGT2d)(j0L28%8t8b zszX?$zoVzSi8cxZAf~%~mP-^V843DeeXHj-cPX!k3tx;(ZS>w)&?X*6!tF-b!`=5s zYQoqs;=)2pON$C6)v&avOyf}R3ozo@JH>P58g?1Fd9U#~FC_+gj82Dq{CIZfe&!(5 zZ@BM#?aNj&-h`~eAtL1beikWB2X7EK)^5kg>T3C+p~Gv7UEo&{uT^1td;3b}c($=# zLg>_wzzdh$iZ6pTukEm)dPEGp5LD7h9gkLKKl(5;bMvOuOKcpfaRJ%c z4!I#$CS<4K;3(1 z+=w#F1pGPD!NkAiiZ03=G6$6SZ;li51YYCzrluO1M_t$hNKIh?L=rG%d}|Zi^H2kEQ*T z$78~P#u&>Q8XiuH80f}tplq7!^_W&<<^ifrOk7`B68ls71f|Z7NbGo&#FNWunus&5 zSlilWL~NS5jJF=oFYQ2d66xcJjcA{+*chZC zS`1i15o{$&k?eRsqeHN;CO8x#A|fZ9eyOBurpY1#f$O9I;}3NgI=Q*IS)E8YjgV7b zUjFZFHH${F(qUX2@_Y~UKaCm|zKLTU*(}6R5Av{&i`nIy&#-?&P?t#X)1!0{C=u*{ zmXPo22cL`#9ug!HAHRI@0}JEL8IU@sMY(lZ1vq?AYU|s0+lv(|_t=pKZ!g^bCHy^MKF)%;RYAyT*ov$=KMW zCkRpXk^z{Yo{X)n)ACKVkpAPtKo6*MQIjoJ5=k$r=&Z_?(|CoN8U=8;b>jjyy;lTSo56Zr2D+p`|Cem zPA!X~F2*cKrM8h*Wn<#GN=p}+6HpounBfTt-+N0v(k{KauN4Z^vIe5d!)&8G{POA3 zT?kvJxnV`QQ08xterWqTY*g$7YFy{F16?5+$+}kE-P{_{1>)d~cyE?SHB(WlU%q?@ z+H?p)C)23BtTQ92tQHXlQ3D~*Lm!99gHPzm_w3te0d_?++5AGhg~2Q_!|)-bd0^ak zZ8X)a-U1#n=&2J?QeQ1~kAfjlzI+3=k}&Iz!!@$;_UQ5gk(&W(cu$^aeN1PTSp4CG zI&24S+@q4_gr`q;v#xYoeVQqCo81OO4A7py34%8p=;m?8jD>Wh`I&|ByM0oboOB;nc!~BReZ&> zrRf*&L3bexENN`;+*}#e`%T)HXQ>7UQU$)GJ7doXp^l#MF5)5qSm9wuQIrZ5t*!G} zri!18DSDck!usy41%np;0tEC+d(iM8g3iT#lC!C+V=YPi7l7`&!Ua${Cz zrilAI7p%qgA8-9n=)X^0ih269MyjNmW;;zo!!s&{^C{!=fv$#V`7@1 z;l*61GN(0nY}aUI+?|H@1{O7t(bS=aa?vD?b$8c)Vd}plsi_{>q9P*wBP0I?L*Ic_ zFd6x(d`U#URvpUHg224ilu7)SN~y>-q5~+e2K>o+dP<;>2@~FT*4(0XSj5PHs#reqe9SXA3+@CQ%6MtZ8jNAS05d{LT{kWz zs?T5)Nf$(q>ljs1Xo|E;B~iV9VuJTJF}V?A?;6gUy}HPN$M zfKMXbJ8#1NH$0b)mf5`e0ESC>bs5Li3@j^b*QL3#6lI!pfR2vK>Bfy0Xj8+b9kA!b z^x48v@_Y7(2M-=JW9F07F0i}1+qo+|?SBsd!vZ)ccASV|WMrg9U)7|@+Z3*NASmen zp6s15?Fp8FS%K~r!exXkvdJ$FP{Kzdh9BW%fnku}#9Fiukw7`jVhH61IO~5;C$V_W zkP?%26+FQ}OA*{d+ok;s!U1?{Yfp(wV>^w}$?;zOaKH!N*CxNwsKiYMeh+MZ>+a4d zY*J)WBgDr8bf1_4!hyJEZ?B4Xr=a0wMY#%7W+Q1~O?~+A6=V0szEcjpB|83msyz$5 z_-LR3jq*EQiXqSA<1b=+aT(1KTVY)GY`6#sQmFYq9ibQ}qCr9B?q1}cgP9Cw@+QnDuCK2@#q?&osff5ZQQB^9Vjv0^SO3pV z5@HhcpMU;A0VaR_EGegko0wDb@V9qM%FUWR+c#U8n#xFq`#2h&Nq3nPm#!7{9>%G+w1 zRzeXPT0I}{k%Cu+k@Pb-(bl+LI{6obL?>Xf14(w(SCzkWUP}$MeKNM~nMYCE!3)~t z52ci0CWiu*J=hlj72xgxO26AM@v>kew(!G;oSQ>(KsZd|5VbB$41rA8uU1!UVRobp zSfr;ymiy3(rl4lQr^(>Hl3sy%Bj}-IL^ShwacOC3VyqOsrMu1BvFIfWXsc`381UOJ zgah1~sUH!Ntn_VdK0rkPpu4if)q0Q1nMuRo<`i;AT!nFONXN5x&NTM-8#7CJrdIPR z+gAh}jFa?u0)nCfOd%Dc6Exe6viBcRQF_d0`q`ad=DXqQnu2;VDLFZ9%R>05)T=+8 zNa1TS8CqSPQnLXwXAaMZdB#X0iL3r$O$=F5>Yuaw3PHBi; z4*mlw`AbX-lG|bAZxAqUR`d8MCEdvv=e4!={s8&iU7zBXtz~CtKS)D!AMs+PF4sBg zq7ck{=hjT7bKF680pQKna}?mkA|vm5cO|pI{nmyV8%iDNZOl01-KF-wtAY1m7bF zMHWJ|A6f6@1$W}Q8KZS_1(jk@Tr6($IwcVD5?){|a@ zts=%EjEaq7DGuL3Rfviu92q4Q3ri?Sm?$do?uWI1243qexxHiO&O^-1-;t=2SarN% zLLp=VwNhzVa~Ur@)|oqGtM;d_9a@rI)cz8@-R$Bb1afm-M+YtDQ?i)Ux(Rvx|EnjC z9m|1>SM|;I)iO7tNd=QMr<0nrz{>61n@w&`)BGV+@y?1X^ ziCq(>3R;cu%*va~Q@y1W!&?{AH>HvzV`6HNo;%N#V7vYu*gDiJ$-%*afX6H4D7Bvo z$GNmtuiCV}CVi+V)I1mwd-hBTT6KBxr-Mr~V-9AA&}r~^11@4(bHOXBm|P*jw8Tps z_8Ay}qZ*Ku3;Jmb{HGm?xzY2wT`}?v;Fcv00g+kZ z`zHwr33bRRYH>8!ZfBz0IB@VFY02d=EiJ7|266pENDzoQRwZVNxg+x2)a3CM?k+Vc z7zP*?u(Puh5D;jpHLb6&-#(X;sKnHOS?G;?e}8|>tEChaxqT-AxF6SlpZR@r^Ge14 z(?;|Jz`$b#Z*Q&_mT4S(bQHo7gQXGAp6Lym2FRY-hV=dgt_Ko2LVJOM2$7317>9*w zQx(jF2bGp?NN@gWP7c&E#nFhsVID$?i7~{SygZ^&$K^Y`rem_GcRc#(Q-!s~$%nzg z=E!<5Hv15Kgzy=@S3e*qXc$0|{POO-Nbu%Tm;P&lv)~9bGPa@SiA7En@#IO>Qvp+A zmI>b36sMOkND$V9oDUA=BrlEpS?I(G6G+J<7Kt5CFHn1Wk`$rQ_XNp$oZ+L-SjuG3 zO?IOE4O^3tknmZTvhEVJ>k>v>fE#n}ZgMrTxx}|#q`bs12hqIjHfUZF8TjxaDVMN3 zu3Q|@opc6;W&G$BJwmx+SDTAmY_m?)Mb?i%?S`Wi5x|t)wly4l0{IGQ4{iGTH3*S>X`XHM5u%SLk`n=wds>zYy88M< z0|TFcH;4kv?q;l9x^!ur{!aGyr=C>A!(8RF1iTY7x!9bRG!0JNN1|*^dUstmGc^Z)^J=QBJ z7XkSgwEo>r6lk4YT{M4GWJ_K}JA!w&_v33%7?PlIX>8vxGQBxivB$*31QTGdaahEH zOR*%lg7ngNJj3{Vv)Ou^lnbHY9r0sQE5lTqtAF?xDnD%BwJ!&1ALD5B_;L%%niPfG z2USN1AEuM*i+QGj{(hv#JJC(9enjMy^Fy-@$@VLYFB#2+e&7(f8w$)ThmLEicr zb(D#qvH;SdgJ24%v?Q-ym;_?z`UAcQf{XM8ksv-}^ztiTE@!q&s3VB3dRn;mHmpWv zQP#p~V%-`O{j@^Z4Zr`7=^dXUjlirdyIieIu7@!CM0HOL$Q2Ys3)7rEe|`rfE+`G( z(tv!#1R3j=%`M_Ai2T?GH~ii^hre=e1}y8yZHrMH(mTvhv9bO;PqZ%mF;PRAl%a4I-)SUKyr6pi JjjXZn{{pe9VGsZS literal 0 HcmV?d00001 diff --git a/[0037][Sudoku Solver]/[0037][Sudoku Solver].iml b/[0037][Sudoku Solver]/[0037][Sudoku Solver].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0037][Sudoku Solver]/[0037][Sudoku Solver].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0037][Sudoku Solver]/src/Solution.java b/[0037][Sudoku Solver]/src/Solution.java new file mode 100644 index 0000000..299431d --- /dev/null +++ b/[0037][Sudoku Solver]/src/Solution.java @@ -0,0 +1,56 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-09-28 15:06 + **/ +public class Solution { + public void solveSudoku(char[][] board) { + if(board == null || board.length == 0) { + return; + } + solve(board); + } + + public boolean solve(char[][] board){ + for(int i = 0; i < board.length; i++){ + for(int j = 0; j < board[0].length; j++){ + if(board[i][j] == '.'){ + // 尝试1到9的数字 + for(char c = '1'; c <= '9'; c++){ + if(isValid(board, i, j, c)){ + // 将字符放入单元格 + board[i][j] = c; + + // 如果字符可以放入单元格返回true + if(solve(board)){ + return true; + }else { // 如果字符不能放入单元格就是还原成点号 + board[i][j] = '.'; + } + } + } + return false; + } + } + } + return true; + } + + private boolean isValid(char[][] board, int row, int col, char c){ + for(int i = 0; i < 9; i++) { + // 检查行 + if(board[i][col] != '.' && board[i][col] == c) { + return false; + } + // 检查列 + if(board[row][i] != '.' && board[row][i] == c) { + return false; + } + // 检查3*3的单元格 + if(board[3 * (row / 3) + i / 3][ 3 * (col / 3) + i % 3] != '.' + && board[3 * (row / 3) + i / 3][3 * (col / 3) + i % 3] == c) { + return false; + } + } + return true; + } +} diff --git a/[0038][Count And Say]/[0038][Count And Say].iml b/[0038][Count And Say]/[0038][Count And Say].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0038][Count And Say]/[0038][Count And Say].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0038][Count And Say]/src/Solution.java b/[0038][Count And Say]/src/Solution.java new file mode 100644 index 0000000..59b80b5 --- /dev/null +++ b/[0038][Count And Say]/src/Solution.java @@ -0,0 +1,67 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 16:47 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * The count-and-say sequence is the sequence of integers beginning as follows:
+     * 1, 11, 21, 1211, 111221, ...
+     * 1 is read off as "one 1" or 11.
+     * 11 is read off as "two 1s" or 21.
+     * 21 is read off as "one 2, then one 1" or 1211.
+     * Given an integer n, generate the nth sequence.
+     * Note: The sequence of integers will be represented as a string.
+     *
+     * Ŀ
+     * n=1ʱַ1n=2ʱϴַеֵΪϴַ11
+     * 11n=3ʱϴַ112121n=4ʱϴַ21
+     * 12111211ƣдcountAndSay(n)ַ
+     *
+     * ˼·
+     * һn<0ʱnull
+     * ڶn=1ʱ1
+     * n>1ʱn-1صַssĴдԲͬ
+     * з112365477899ֳ112365477899о21
+     * 12131615һ4271829211213161614271829ش˽
+     * 
+ * + * @param n + * @return + */ + public String countAndSay(int n) { + + if (n < 1) { + return null; + } + + String result = "1"; + for (int i = 2; i <= n; i++) { + result = countAndSay(result); + } + + return result; + } + + public String countAndSay(String str) { + StringBuilder builder = new StringBuilder(128); + + int count = 1; + for (int i = 1; i < str.length(); i++) { + if (str.charAt(i) == str.charAt(i - 1)) { + count++; + } else { + builder.append(count); + builder.append(str.charAt(i - 1)); + count = 1; + } + } + + builder.append(count); + builder.append(str.charAt(str.length() - 1)); + return builder.toString(); + } +} diff --git a/[0039][Combination Sum]/[0039][Combination Sum].iml b/[0039][Combination Sum]/[0039][Combination Sum].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0039][Combination Sum]/[0039][Combination Sum].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0039][Combination Sum]/src/Solution.java b/[0039][Combination Sum]/src/Solution.java new file mode 100644 index 0000000..05d51b7 --- /dev/null +++ b/[0039][Combination Sum]/src/Solution.java @@ -0,0 +1,43 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +/** + * @author: wangjunchao(王俊超) + * @time: 2018-09-28 15:11 + **/ +public class Solution { + public List> combinationSum(int[] nums, int target) { + // 用于保存结果 + List> list = new LinkedList<>(); + Arrays.sort(nums); + backtrack(list, new ArrayList<>(), nums, target, 0); + return list; + } + + // 回溯法 + // list:保存总的结果 + // tempList:保存临时结果 + // nums:输入的数组 + // remain:剩下的值 + // start:可用的值在数组中的起始位置 + private void backtrack(List> list, List tempList, int [] nums, int remain, int start){ + // 不够减 + if(remain < 0) { + return; + } else if(remain == 0) { // 刚好够减 + list.add(new LinkedList<>(tempList)); + } else { + // 从剩下的数中一个一个尝试 + for(int i = start; i < nums.length; i++){ + // 假设这个值是临时结果中的一个值 + tempList.add(nums[i]); + // 处理下一步 + backtrack(list, tempList, nums, remain - nums[i], i); + // 现场还原 + tempList.remove(tempList.size() - 1); + } + } + } +} diff --git a/[0040][Combination Sum II]/[0040][Combination Sum II].iml b/[0040][Combination Sum II]/[0040][Combination Sum II].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0040][Combination Sum II]/[0040][Combination Sum II].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0040][Combination Sum II]/src/Solution.java b/[0040][Combination Sum II]/src/Solution.java new file mode 100644 index 0000000..c766df0 --- /dev/null +++ b/[0040][Combination Sum II]/src/Solution.java @@ -0,0 +1,44 @@ +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +/** + * @author: wangjunchao(王俊超) + * @time: 2018-09-28 15:15 + **/ +public class Solution { + public List> combinationSum2(int[] nums, int target) { + List> list = new LinkedList<>(); + Arrays.sort(nums); + backtrack(list, new LinkedList<>(), nums, target, 0); + return list; + + } + + /** + * @param list 结果集 + * @param tempList 临时结果集 + * @param nums 可选值数组 + * @param remain 剩余值 + * @param start 可选值的起始下标 + */ + private void backtrack(List> list, List tempList, int[] nums, int remain, int start) { + if (remain < 0) { + return; + } else if (remain == 0) { + list.add(new LinkedList<>(tempList)); + } else { + for (int i = start; i < nums.length; i++) { + // 如果上一轮循环没有选nums[i],则本次循环就不能再选nums[i], + // 确保nums[i] 最多只用一次 + if (i > start && nums[i] == nums[i - 1]) { + continue; + } + tempList.add(nums[i]); + // 数值不可以被重用 + backtrack(list, tempList, nums, remain - nums[i], i + 1); + tempList.remove(tempList.size() - 1); + } + } + } +} diff --git a/[0041][First Missing Positive]/[0041][First Missing Positive].iml b/[0041][First Missing Positive]/[0041][First Missing Positive].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0041][First Missing Positive]/[0041][First Missing Positive].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0041][First Missing Positive]/src/Main.java b/[0041][First Missing Positive]/src/Main.java new file mode 100644 index 0000000..3a25e0e --- /dev/null +++ b/[0041][First Missing Positive]/src/Main.java @@ -0,0 +1,20 @@ +import org.junit.Assert; +import org.junit.Test; + +import java.util.Arrays; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-19 14:38 + **/ +public class Main { + + @Test + public void test1() { + Solution solution = new Solution(); + int[] arr = {1, 4, 3, 3, 2}; + int result = solution.firstMissingPositive(arr); + System.out.println(Arrays.toString(arr)); + Assert.assertEquals(5, result); + } +} diff --git a/[0041][First Missing Positive]/src/Solution.java b/[0041][First Missing Positive]/src/Solution.java new file mode 100644 index 0000000..b551643 --- /dev/null +++ b/[0041][First Missing Positive]/src/Solution.java @@ -0,0 +1,51 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-09-28 15:18 + **/ +public class Solution { + /** + *
+     * Given an unsorted integer array, find the smallest missing positive integer.
+     *
+     * Example 1:
+     *
+     * Input: [1,2,0]
+     * Output: 3
+     * Example 2:
+     *
+     * Input: [3,4,-1,1]
+     * Output: 2
+     * Example 3:
+     *
+     * Input: [7,8,9,11,12]
+     * Output: 1
+     *
+     * 本质上是桶排序(bucket sort),每当A[i]!= i+1 的时候,将A[i] 与A[A[i]-1] 交换,
+     * 直到无法交换为止,终止条件是A[i]== A[A[i]-1]。
+     * 
+ * @param nums + * @return + */ + public int firstMissingPositive(int[] nums) { + int n = nums.length; + for (int i = 0; i < n; i++) { + // nums[i] == nums[nums[i] - 1] 说明出现了两个同样的元素或者两个是同一个元素 + while (nums[i] > 0 && nums[i] <= n && nums[i] != nums[nums[i] - 1]) { + swap(nums, i, nums[i] - 1); + } + } + for (int i = 0; i < n; i++) { + if (nums[i] != i + 1) { + return i + 1; + } + } + + return n + 1; + } + + private void swap(int[] nums, int i, int j) { + int temp = nums[i]; + nums[i] = nums[j]; + nums[j] = temp; + } +} diff --git a/[0042][Trapping Rain Water]/[0042][Trapping Rain Water].iml b/[0042][Trapping Rain Water]/[0042][Trapping Rain Water].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0042][Trapping Rain Water]/[0042][Trapping Rain Water].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0042][Trapping Rain Water]/src/Solution.java b/[0042][Trapping Rain Water]/src/Solution.java new file mode 100644 index 0000000..810a76c --- /dev/null +++ b/[0042][Trapping Rain Water]/src/Solution.java @@ -0,0 +1,149 @@ +import java.util.Deque; +import java.util.LinkedList; + +/** + * @author: wangjunchao(王俊超) + * @time: 2018-09-28 15:20 + **/ +class Solution { + + public int trap(int[] height) { + return trap4(height); + } + + /** + *
+     * 对于每个柱子,找到其左右两边最高的柱子,该柱子能容纳的面积就是min(max_left,max_right) - height。所以,
+     * 1. 从左往右扫描一遍,对于每个柱子,求取左边最大值;
+     * 2. 从右往左扫描一遍,对于每个柱子,求最大右值;
+     * 3. 再扫描一遍,把每个柱子的面积并累加。
+     * 
+ * + * @param height + * @return + */ + public int trap1(int[] height) { + int ans = 0; + int size = height.length; + for (int i = 1; i < size - 1; i++) { + int maxLeft = 0; + int maxRight = 0; + // 找此柱左边最高的柱子 + for (int j = i - 1; j >= 0; j--) { + maxLeft = Math.max(maxLeft, height[j]); + } + // 找此柱子右边最高的柱子 + for (int j = i + 2; j < size; j++) { + maxRight = Math.max(maxRight, height[j]); + } + + // Math.min(maxLeft, maxRight) - height[i] 此柱子可以容纳的水 + ans += Math.min(maxLeft, maxRight) - height[i]; + } + return ans; + } + + int trap2(int[] height) { + if (height == null || height.length == 0) { + return 0; + } + int ans = 0; + int size = height.length; + int[] leftMax = new int[size]; + int[] rightMax = new int[size]; + + + // 对于每个柱子求左右最大值,并保存起来 + for (int i = 1; i < size - 1; i++) { + leftMax[i] = Math.max(height[i], leftMax[i - 1]); + rightMax[size - i - 1] = Math.max(height[size - i], rightMax[size - i]); + } + + + for (int i = 1; i < size - 1; i++) { + ans += Math.min(leftMax[i], rightMax[i]) - height[i]; + } + return ans; + } + + /** + *
+     * 用一个栈辅助,小于栈顶的元素压入,大于等于栈顶就把栈里所有小于或
+     * 等于当前值的元素全部出栈处理掉,计算面积,最后把当前元素入栈
+     *
+     *
+     *
+     *         =
+     *    =   === =
+     *  = == =======
+     * =============
+     * 0123456789012
+     * 
+ * @param height + * @return + */ + int trap3(int[] height) { + int ans = 0, current = 0; + Deque st = new LinkedList<>(); + while (current < height.length) { + // 当前元素比栈顶元素大 + while (!st.isEmpty() && height[current] > height[st.getFirst()]) { + int top = st.pop(); + if (st.isEmpty()) { + break; + } + + // 求距离,如上图,比如current=7,此时top=4,top到current距离:current-top-1 + int distance = current - st.peek() - 1; + // top以下的水位已经计算过了,top以上的水位就 + // height[current] - height[top], height[st.peek()] - height[top] + // 较小的值,简化为以下面的表达式 + int boundedHeight = Math.min(height[current], height[st.peek()]) - height[top]; + ans += distance * boundedHeight; + } + + // 当前元素不大于栈顶元素 + st.push(current++); + } + return ans; + } + + /** + *
+     * 1. 扫描一遍,找到最高的柱子,这个柱子将数组分为两半;
+     * 2. 处理左边一半;
+     * 3. 处理右边一半。
+     * 
+ * + * @param height + * @return + */ + int trap4(int[] height) { + int left = 0; + int right = height.length - 1; + int ans = 0; + int leftMax = 0; + int rightMax = 0; + + while (left < right) { + if (height[left] < height[right]) { + if (height[left] >= leftMax) { + leftMax = height[left]; + } else { + ans += leftMax - height[left]; + } + + ++left; + } else { + if (height[right] >= rightMax) { + rightMax = height[right]; + } else { + ans += rightMax - height[right]; + } + + --right; + } + } + return ans; + } +} diff --git a/[0043][Multiply Strings]/[0043][Multiply Strings].iml b/[0043][Multiply Strings]/[0043][Multiply Strings].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0043][Multiply Strings]/[0043][Multiply Strings].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0043][Multiply Strings]/src/Solution.java b/[0043][Multiply Strings]/src/Solution.java new file mode 100644 index 0000000..1570a3f --- /dev/null +++ b/[0043][Multiply Strings]/src/Solution.java @@ -0,0 +1,42 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-09-28 15:23 + **/ +public class Solution { + public String multiply(String num1, String num2) { + int m = num1.length(), n = num2.length(); + int[] pos = new int[m + n]; + + int mul; + int index; + int temp; + for (int i = m - 1; i >= 0; i--) { + for (int j = n - 1; j >= 0; j--) { + // 求积 + mul = (num1.charAt(i) - '0') * (num2.charAt(j) - '0'); + // 积的最低位所在的位置 + index = i + j + 1; + + // 最低低求和 + pos[index] += mul; + + // 做进位处理 + while (pos[index] > 9) { + temp = pos[index]; + pos[index] = temp % 10; + --index; + pos[index] += temp / 10; + } + + } + } + + StringBuilder sb = new StringBuilder(); + for (int p : pos) { + if (!(sb.length() == 0 && p == 0)) { + sb.append(p); + } + } + return sb.length() == 0 ? "0" : sb.toString(); + } +} diff --git a/[0044][Wildcard Matching]/[0044][Wildcard Matching].iml b/[0044][Wildcard Matching]/[0044][Wildcard Matching].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0044][Wildcard Matching]/[0044][Wildcard Matching].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0044][Wildcard Matching]/src/Solution.java b/[0044][Wildcard Matching]/src/Solution.java new file mode 100644 index 0000000..2f5d7e2 --- /dev/null +++ b/[0044][Wildcard Matching]/src/Solution.java @@ -0,0 +1,54 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-09-28 15:25 + **/ +public class Solution { + public boolean isMatch(String str, String pattern) { + // 匹配串的索引 + int s = 0; + // 模式串的索引 + int p = 0; + // 记录匹配的匹配位置 + int match = 0; + // 星号的起始索引 + int starIdx = -1; + while (s < str.length()) { + // 两个指针都往前推进 + if (p < pattern.length() && (pattern.charAt(p) == '?' || str.charAt(s) == pattern.charAt(p))) { + s++; + p++; + } + // 发现一个*,只前进模式串索引 + else if (p < pattern.length() && pattern.charAt(p) == '*') { + // 记录最后一次发现*的位置 + starIdx = p; + // 记录在匹配串中匹配*时的位置 + match = s; + // 模式串索引向前推进 + p++; + } + // last pattern pointer was *, advancing string pointer + // 最后的模式串索引是*,匹配串索引向前推进。这个条件隐含p >= pattern.length(),再加上starIdx != -1 + // 说明存在*号匹配,在星号匹配的 + else if (starIdx != -1) { + // 记录模式串最后处理的*号的下一个位置 + p = starIdx + 1; + // 记录在匹配串中匹配*时的位置 + match++; + // 匹配串索引向前推进 + s = match; + } + // 当前的模式索引指向的不是*号,最后一个模式索引指向的也不是*号,说明不匹配 + else { + return false; + } + } + + // 检查余下的模式串,模式串必须全都是*号才行 + while (p < pattern.length() && pattern.charAt(p) == '*') { + p++; + } + + return p == pattern.length(); + } +} diff --git a/[0045][Jump Game II]/[0045][Jump Game II].iml b/[0045][Jump Game II]/[0045][Jump Game II].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0045][Jump Game II]/[0045][Jump Game II].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0045][Jump Game II]/src/Solution.java b/[0045][Jump Game II]/src/Solution.java new file mode 100644 index 0000000..3f11ba2 --- /dev/null +++ b/[0045][Jump Game II]/src/Solution.java @@ -0,0 +1,49 @@ +/** + * 使用贪心算法,每次都移动最远的距离 + * + * @author: wangjunchao(王俊超) + * @time: 2018-09-28 15:27 + **/ +public class Solution { + + public int jump(int[] nums) { + + if (nums == null || nums.length < 2) { + return 0; + } + + // 记录跳跃次数 + int jump = 0; + // 记录当前可以到达的最远的位置 + int currentMax = 0; + // 下一次可以到达的最远的位置 + int nextMax = 0; + // 记录处理的位置 + int i = 0; + + // 还没有到最未位置,还可以移动 + while (currentMax - i + 1 > 0) { + // 跳数增加 + jump++; + // 找下一次最远可以移动的位置 + for (; i <= currentMax; i++) { + nextMax = Math.max(nextMax, nums[i] + i); + // 如果下一次可以移动到最末的位置,则返回跳数 + if (nextMax >= nums.length - 1) { + return jump; + } + } + + // 本次处理不能使移动位增加,并且不能到达最末位置,说明永远到不了最后的位置 + if (currentMax == nextMax) { + return Integer.MAX_VALUE; + } + + // 更新当前可以移动的最远位置 + currentMax = nextMax; + } + + return 0; + } + +} diff --git a/[0046][Permutations]/[0046][Permutations].iml b/[0046][Permutations]/[0046][Permutations].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0046][Permutations]/[0046][Permutations].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0046][Permutations]/src/Solution.java b/[0046][Permutations]/src/Solution.java new file mode 100644 index 0000000..b08b4bb --- /dev/null +++ b/[0046][Permutations]/src/Solution.java @@ -0,0 +1,66 @@ +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-08-21 + * Time: 16:50 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + private List> result; + + /** + *
+     * ԭ
+     * Given a collection of numbers, return all possible permutations.
+     * For example,
+     * [1,2,3] have the following permutations:
+     * [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].
+     *
+     * Ŀ
+     * һ飬С
+     *
+     * ˼·
+     * ʹ÷η⡣
+     * 
+ * + * @param num + * @return + */ + public List> permute(int[] num) { + + result = new LinkedList<>(); + if (num != null) { + permute(0, num); + } + + return result; + } + + private void permute(int i, int[] nums) { + + if (i == nums.length) { + List l = new ArrayList<>(); + for (int n : nums) { + l.add(n); + } + result.add(l); + } else { + + for (int j = i; j < nums.length; j++) { + swap(nums, j, i); + permute(i + 1, nums); + swap(nums, j, i); + } + } + } + + private void swap(int[] nums, int x, int y) { + int tmp = nums[x]; + nums[x] = nums[y]; + nums[y] = tmp; + } +} diff --git a/[0047][Permutations II]/[0047][Permutations II].iml b/[0047][Permutations II]/[0047][Permutations II].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0047][Permutations II]/[0047][Permutations II].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0047][Permutations II]/src/Main.java b/[0047][Permutations II]/src/Main.java new file mode 100644 index 0000000..050363c --- /dev/null +++ b/[0047][Permutations II]/src/Main.java @@ -0,0 +1,14 @@ +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-19 18:01 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + int[] nums = {1, 1, 2}; + System.out.println(solution.permuteUnique(nums)); + } +} diff --git a/[0047][Permutations II]/src/Solution.java b/[0047][Permutations II]/src/Solution.java new file mode 100644 index 0000000..859454a --- /dev/null +++ b/[0047][Permutations II]/src/Solution.java @@ -0,0 +1,62 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * @author: wangjunchao(王俊超) + * @time: 2018-09-28 15:29 + **/ +public class Solution { + + public List> permuteUnique(int[] nums) { + List> res = new ArrayList<>(); + + if (nums == null || nums.length == 0){ + return res; + } + + boolean[] used = new boolean[nums.length]; + List list = new ArrayList<>(); + + Arrays.sort(nums); + + permuteUnique(nums, used, list, res); + return res; + } + + /** + * 时间复杂度:n! + * @param nums + * @param used + * @param list + * @param res + */ + private void permuteUnique(int[] nums, boolean[] used, List list, List> res) { + if (list.size() == nums.length) { + res.add(new ArrayList<>(list)); + return; + } + + for (int i = 0; i < nums.length; i++) { + // 第i个数值已经被使用过 + if (used[i]) { + continue; + } + + // 第i个字符与前一个字符相等,并且第i-1个字符没有使用,说明此次不应该交换 + if (i > 0 && nums[i - 1] == nums[i] && !used[i - 1]) { + continue; + } + + // 标记第i个字符已经被使用 + used[i] = true; + // 添加到临时结果中 + list.add(nums[i]); + // 下一次处理 + permuteUnique(nums, used, list, res); + // 现场还原 + used[i] = false; + list.remove(list.size() - 1); + } + } +} diff --git a/[0048][Rotate Image]/[0048][Rotate Image].iml b/[0048][Rotate Image]/[0048][Rotate Image].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0048][Rotate Image]/[0048][Rotate Image].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0048][Rotate Image]/src/Solution.java b/[0048][Rotate Image]/src/Solution.java new file mode 100644 index 0000000..bba7234 --- /dev/null +++ b/[0048][Rotate Image]/src/Solution.java @@ -0,0 +1,28 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-09-28 15:31 + **/ +public class Solution { + public void rotate(int[][] matrix) { + int temp; + + // 先做y=x对称转换 + for (int i = 0; i < matrix.length; i++) { + for (int j = i; j < matrix.length; j++) { + temp = matrix[i][j]; + matrix[i][j] = matrix[j][i]; + matrix[j][i] = temp; + } + } + + // 再对行进行垂直转换 + int half = matrix.length / 2; + for (int i = 0; i < matrix.length; i++) { + for (int j = 0; j < half; j++) { + temp = matrix[i][j]; + matrix[i][j] = matrix[i][matrix.length - 1 - j]; + matrix[i][matrix.length - 1 - j] = temp; + } + } + } +} diff --git a/[0049][Group Anagrams]/[0049][Group Anagrams].iml b/[0049][Group Anagrams]/[0049][Group Anagrams].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0049][Group Anagrams]/[0049][Group Anagrams].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0049][Group Anagrams]/src/Solution.java b/[0049][Group Anagrams]/src/Solution.java new file mode 100644 index 0000000..3ff45ad --- /dev/null +++ b/[0049][Group Anagrams]/src/Solution.java @@ -0,0 +1,80 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author: wangjunchao(王俊超) + * @time: 2018-09-28 15:33 + **/ +public class Solution { + + public List> groupAnagrams(String[] strs) { + return groupAnagrams2(strs); + } + + /** + * 算法原理:对字符串进行排序,相同类型的字符串排序后的字符串都是一样的 + * + * @param strs + * @return + */ + public List> groupAnagrams1(String[] strs) { + if (strs.length == 0) { + return new ArrayList(); + } + Map ans = new HashMap<>(); + // 处理每一个字符串 + for (String s : strs) { + char[] ca = s.toCharArray(); + // 对象字符串对应的字符数组进行排序,再转成排序后的字符串 + Arrays.sort(ca); + String key = String.valueOf(ca); + // 如果map中不包含已经排序后的字符串,那么就创建一个新容器要放入结果 + if (!ans.containsKey(key)) { + ans.put(key, new ArrayList()); + } + + // 结果放入对应的集合中 + ans.get(key).add(s); + } + return new ArrayList(ans.values()); + } + + /** + * 算法原理:统计每个字符出现的次数,然后使用#字符将每个字符出现的次数拼成一个字符串, + * 相同类型的字符串通过上面的方式拼出来的字符串都是一样的 + * + * @param strs + * @return + */ + public List> groupAnagrams2(String[] strs) { + if (strs.length == 0) { + return new ArrayList(); + } + Map ans = new HashMap<>(); + int[] count = new int[26]; + + for (String s : strs) { + // 清零操作 + Arrays.fill(count, 0); + for (char c : s.toCharArray()) { + count[c - 'a']++; + } + + // 字符串拼接 + StringBuilder sb = new StringBuilder(""); + for (int i = 0; i < 26; i++) { + sb.append('#'); + sb.append(count[i]); + } + String key = sb.toString(); + if (!ans.containsKey(key)) { + ans.put(key, new ArrayList()); + } + ans.get(key).add(s); + } + return new ArrayList(ans.values()); + } +} diff --git a/[0050][Pow(x,n)]/[0050][Pow(x,n)].iml b/[0050][Pow(x,n)]/[0050][Pow(x,n)].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0050][Pow(x,n)]/[0050][Pow(x,n)].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0050][Pow(x,n)]/src/Solution.java b/[0050][Pow(x,n)]/src/Solution.java new file mode 100644 index 0000000..43aafc9 --- /dev/null +++ b/[0050][Pow(x,n)]/src/Solution.java @@ -0,0 +1,59 @@ +/** + * Author: + * Date: 2015-06-23 + * Time: 10:56 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Implement pow(x, n).
+     *
+     * Ŀ⣺
+     * ʵxnη
+     *
+     * ⷽ
+     * ݹ
+     * 
+ * + * @param x + * @param n + * @return + */ + public double myPow(double x, int n) { + if (x == 0 && n == 0) { + throw new IllegalArgumentException(); + } + + // ָ + boolean isNegative = false; + + // nľֵ + if (n < 0) { + n = -n; + isNegative = true; + } + + double result = pow(x, n); + + if (isNegative) { + return 1.0 / result; + } else { + return result; + } + } + + public double pow(double x, int n) { + if (n == 0) { + return 1; + } else { + double result = pow(x, n / 2); + // n + if (n % 2 != 0) { + return x * result * result; + } else { + return result * result; + } + } + } +} diff --git a/[0051][N-Queens]/[0051][N-Queens].iml b/[0051][N-Queens]/[0051][N-Queens].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0051][N-Queens]/[0051][N-Queens].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0051][N-Queens]/src/Solution.java b/[0051][N-Queens]/src/Solution.java new file mode 100644 index 0000000..7d31661 --- /dev/null +++ b/[0051][N-Queens]/src/Solution.java @@ -0,0 +1,69 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * @author: wangjunchao(王俊超) + * @time: 2018-09-28 15:36 + **/ +public class Solution { + public List> solveNQueens(int n) { + List> result = new ArrayList<>(); + + if (n < 1) { + return result; + } + + char[][] board = new char[n][]; + for (int i = 0; i < n; i++) { + board[i] = new char[n]; + Arrays.fill(board[i], '.'); + } + + solveNQueens(board, 0, result); + return result; + } + + private void solveNQueens(char[][] board, int row, List> result) { + if (board.length == row) { + List list = new ArrayList<>(); + for (char[] chs : board) { + list.add(new String(chs)); + } + result.add(list); + } + + for (int col = 0; col < board.length; col++) { + if (canPlace(board, row, col)) { + board[row][col] = 'Q'; + solveNQueens(board, row + 1, result); + board[row][col] = '.'; + } + } + } + + private boolean canPlace(char[][] board, int row, int col) { + // 检测之前的列上是否已经放过皇后 + for (int i = 0; i < row; ++i) { + if (board[i][col] == 'Q') { + return false; + } + } + + // 45度角(左下角)上是否已经存在过皇后 + for (int i = row - 1, j = col - 1; i >= 0 && j >= 0; --i, --j) { + if (board[i][j] == 'Q') { + return false; + } + } + + // 135度角上(左上角)是否已经存在过皇后 + for (int i = row - 1, j = col + 1; i >= 0 && j < board.length; --i, ++j) { + if (board[i][j] == 'Q') { + return false; + } + } + + return true; + } +} diff --git a/[0052][N-Queens II]/[0052][N-Queens II].iml b/[0052][N-Queens II]/[0052][N-Queens II].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0052][N-Queens II]/[0052][N-Queens II].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0052][N-Queens II]/src/Solution.java b/[0052][N-Queens II]/src/Solution.java new file mode 100644 index 0000000..5638da5 --- /dev/null +++ b/[0052][N-Queens II]/src/Solution.java @@ -0,0 +1,63 @@ +import java.util.Arrays; + +/** + * @author: wangjunchao(王俊超) + * @time: 2018-09-28 15:38 + **/ +public class Solution { + public int totalNQueens(int n) { + int[] result = {0}; + + if (n < 1) { + return result[0]; + } + + char[][] board = new char[n][]; + for (int i = 0; i < n; i++) { + board[i] = new char[n]; + Arrays.fill(board[i], '.'); + } + + solveNQueens(board, 0, result); + return result[0]; + } + + private void solveNQueens(char[][] board, int row, int[] result) { + if (board.length == row) { + result[0]++; + } + + for (int col = 0; col < board.length; col++) { + if (canPlace(board, row, col)) { + board[row][col] = 'Q'; + solveNQueens(board, row + 1, result); + board[row][col] = '.'; + } + } + } + + private boolean canPlace(char[][] board, int row, int col) { + // 检测之前的列上是否已经放过皇后 + for (int i = 0; i < row; ++i) { + if (board[i][col] == 'Q') { + return false; + } + } + + // 45度角(左下角)上是否已经存在过皇后 + for (int i = row - 1, j = col - 1; i >= 0 && j >= 0; --i, --j) { + if (board[i][j] == 'Q') { + return false; + } + } + + // 135度角上(左上角)是否已经存在过皇后 + for (int i = row - 1, j = col + 1; i >= 0 && j < board.length; --i, ++j) { + if (board[i][j] == 'Q') { + return false; + } + } + + return true; + } +} \ No newline at end of file diff --git a/[0053][Maximum Subarray]/[0053][Maximum Subarray].iml b/[0053][Maximum Subarray]/[0053][Maximum Subarray].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0053][Maximum Subarray]/[0053][Maximum Subarray].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0053][Maximum Subarray]/[0053][MaximumSubarray].iml b/[0053][Maximum Subarray]/[0053][MaximumSubarray].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0053][Maximum Subarray]/[0053][MaximumSubarray].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0053][Maximum Subarray]/src/Solution.java b/[0053][Maximum Subarray]/src/Solution.java new file mode 100644 index 0000000..9c2d79b --- /dev/null +++ b/[0053][Maximum Subarray]/src/Solution.java @@ -0,0 +1,53 @@ +/** + * Author: + * Date: 2015-06-22 + * Time: 12:05 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Find the contiguous subarray within an array (containing at least one number)
+     * which has the largest sum.
+     *
+     * For example, given the array [?2,1,?3,4,?1,2,1,?5,4],
+     * the contiguous subarray [4,?1,2,1] has the largest sum = 6.
+     *
+     * Ŀ⣺
+     * ĺ
+     * ˼·
+     * ̬滮⣬֪ǰkԪصкΪmaxSubѾ¼ˣԼһʱsum
+     * ˵k+1Ԫأƣk+1Ԫ֮ǰĺС0ģ
+     * ôk+1ԪشӶȥûй׵ģԿ԰sum 0
+     *
+ * @param nums + * @return + */ + public int maxSubArray(int[] nums) { + // У + if (nums == null || nums.length < 1) { + throw new IllegalArgumentException(); + } + + int max = Integer.MIN_VALUE; + int curSum = 0; + + for (int i : nums) { + // ǰС0ͽǰֵcurSum + if (curSum <= 0){ + curSum = i; + } + // ۼ + else { + curSum += i; + } + + // ϴֵ + if (max < curSum) { + max = curSum; + } + } + + return max; + } +} diff --git a/[0054][Spiral Matrix]/[0054][Spiral Matrix].iml b/[0054][Spiral Matrix]/[0054][Spiral Matrix].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0054][Spiral Matrix]/[0054][Spiral Matrix].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0054][Spiral Matrix]/[0054][SpiralMatrix].iml b/[0054][Spiral Matrix]/[0054][SpiralMatrix].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0054][Spiral Matrix]/[0054][SpiralMatrix].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0054][Spiral Matrix]/src/Solution.java b/[0054][Spiral Matrix]/src/Solution.java new file mode 100644 index 0000000..1d632f7 --- /dev/null +++ b/[0054][Spiral Matrix]/src/Solution.java @@ -0,0 +1,111 @@ +import java.util.ArrayList; +import java.util.List; + +/** + * Author: + * Date: 2015-08-21 + * Time: 17:11 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Given a matrix of m x n elements (m rows, n columns), return all elements
+     * of the matrix in spiral order.
+     * For example,
+     * Given the following matrix:
+     *
+     * [
+     * [ 1, 2, 3 ],
+     * [ 4, 5, 6 ],
+     * [ 7, 8, 9 ]
+     * ]
+     *
+     * You should return [1,2,3,6,9,8,7,4,5].
+     * Ŀ
+     * һm*nľԪص˳
+     *
+     * ˼·
+     * ʹüķȴһУٴұһУٴһУٴһУ
+     * һֱֱеԪضꡣ
+     * 
+ * + * @param matrix + * @return + */ + public List spiralOrder(int[][] matrix) { + List result = new ArrayList<>(50); + + if (matrix == null || matrix.length == 0 || matrix[0].length == 0) { + return result; + } + + // ֻһе + if (matrix.length == 1) { + for (int i : matrix[0]) { + result.add(i); + } + + return result; + } + + // ֻһе + if (matrix[0].length == 1) { + for (int i = 0; i < matrix.length; i++) { + result.add(matrix[i][0]); + } + + return result; + } + + // жȦ + int row = matrix.length; + int col = matrix[0].length; + int cycle = row < col ? row : col; + cycle = (cycle + 1) / 2; + + int round = 0; // ¼ǰǵڼȦ + int left = 0; + int right = matrix[0].length - 1; + int top = 0; + int down = matrix.length - 1; + int total = col * row; + int count = 0; + while (round < cycle) { + + // һ + for (int i = left; i <= right && count < total; i++) { + count++; + result.add(matrix[round][i]); + } + top++; // + + // ұһ + for (int i = top; i <= down && count < total; i++) { + count++; + result.add(matrix[i][col - round - 1]); + } + right--; + + // һ + for (int i = right; i >= left && count < total; i--) { + count++; + result.add(matrix[row - round - 1][i]); + + } + down--; + + // һ + for (int i = down; i >= top && count < total; i--) { + count++; + result.add(matrix[i][round]); + } + left++; + + round++; + } + + return result; + } +} diff --git a/[0055][Jump Game]/[0055][Jump Game].iml b/[0055][Jump Game]/[0055][Jump Game].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0055][Jump Game]/[0055][Jump Game].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0055][Jump Game]/src/Solution.java b/[0055][Jump Game]/src/Solution.java new file mode 100644 index 0000000..2fabd87 --- /dev/null +++ b/[0055][Jump Game]/src/Solution.java @@ -0,0 +1,65 @@ +/** + * Author: 王俊超 + * Date: 2015-06-19 + * Time: 19:29 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Given an array of non-negative integers, you are initially positioned at the
+     * first index of the array.
+     *
+     * Each element in the array represents your maximum jump length at that position.
+     *
+     * Determine if you are able to reach the last index.
+     *
+     * For example:
+     * A = [2,3,1,1,4], return true.
+     * A = [3,2,1,0,4], return false.
+     *
+     * 题目大意:
+     * 给定的非负整数的数组,则最初定位在数组的第一个位置。数组中的每个元素都代表你的最大跳跃长度在那个位置。
+     * 决定你是否能到达最后一个索引。
+     *
+     * 
+ * + * @param nums + * @return + */ + public boolean canJump(int[] nums) { + return canJump2(nums); + } + public boolean canJump1(int[] nums) { + if (nums == null || nums.length < 2) { + return true; + } + + // 最后可以移动的位置 + int lastPos = 0; + + // 处理每一个位置 + for (int i = 0; i < nums.length; i++) { + // i不能比lastPos大,否则说明不能走到i,走不到i也就不能走到最后 + // 如果在i位置可以移动的距离比已经记录到的最大距离还要大,那么更新最大的移动距离 + if (i <= lastPos && i + nums[i] > lastPos ) { + lastPos = i + nums[i]; + } else if (i > lastPos) { + return false; + } + } + + // 最后的位置必然可以达到最后 + return lastPos >= nums.length - 1; + } + + public boolean canJump2(int[] nums) { + int lastPos = nums.length - 1; + for (int i = nums.length - 1; i >= 0; i--) { + if (i + nums[i] >= lastPos) { + lastPos = i; + } + } + return lastPos == 0; + } +} diff --git a/[0056][Merge Intervals]/[0056][Merge Intervals].iml b/[0056][Merge Intervals]/[0056][Merge Intervals].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0056][Merge Intervals]/[0056][Merge Intervals].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0056][Merge Intervals]/[0056][MergeIntervals].iml b/[0056][Merge Intervals]/[0056][MergeIntervals].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0056][Merge Intervals]/[0056][MergeIntervals].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0056][Merge Intervals]/src/Interval.java b/[0056][Merge Intervals]/src/Interval.java new file mode 100644 index 0000000..0905b1b --- /dev/null +++ b/[0056][Merge Intervals]/src/Interval.java @@ -0,0 +1,20 @@ +/** + * Author: + * Date: 2015-06-23 + * Time: 19:40 + * Declaration: All Rights Reserved !!! + */ +public class Interval { + int start; + int end; + + Interval() { + start = 0; + end = 0; + } + + Interval(int s, int e) { + start = s; + end = e; + } +} diff --git a/[0056][Merge Intervals]/src/Solution.java b/[0056][Merge Intervals]/src/Solution.java new file mode 100644 index 0000000..312eac5 --- /dev/null +++ b/[0056][Merge Intervals]/src/Solution.java @@ -0,0 +1,60 @@ +import java.util.*; + +/** + * Author: + * Date: 2015-06-23 + * Time: 19:39 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Given a collection of intervals, merge all overlapping intervals.
+     *
+     * For example,
+     * Given [1,3],[2,6],[8,10],[15,18],
+     * return [1,6],[8,10],[15,18].
+     *
+     * Ŀ⣬
+     * һ伯ϣϲص
+     *
+     * ˼·
+     * ȶ򣬰ʼһһкϲ
+     * 
+ * + * @param intervals + * @return + */ + public List merge(List intervals) { + List result = new LinkedList<>(); + + if (intervals == null || intervals.size() < 1) { + return result; + } + + // ȶʹһڲ + Collections.sort(intervals, new Comparator() { + @Override + public int compare(Interval o1, Interval o2) { + return o1.start - o2.start; + } + }); + + // 󣬺һԪأΪnextstartһDzСǰһΪprevstartģ + // ӵ䣬next.startprev.end˵ǷֿģҪ + // һµ䣬˵next.start[prev.start, prev.end]ڣֻҪ + // next.endǷǴprev.endھҪϲ䣨 + Interval prev = null; + for (Interval item : intervals) { + + if (prev == null || prev.end < item.start) { + result.add(item); + prev = item; + } else if (prev.end < item.end) { + prev.end = item.end; + } + } + + return result; + } +} diff --git a/[0057][Insert Interval]/[0057][Insert Interval].iml b/[0057][Insert Interval]/[0057][Insert Interval].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0057][Insert Interval]/[0057][Insert Interval].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0057][Insert Interval]/[0057][InsertInterval].iml b/[0057][Insert Interval]/[0057][InsertInterval].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0057][Insert Interval]/[0057][InsertInterval].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0057][Insert Interval]/src/Interval.java b/[0057][Insert Interval]/src/Interval.java new file mode 100644 index 0000000..196e728 --- /dev/null +++ b/[0057][Insert Interval]/src/Interval.java @@ -0,0 +1,20 @@ +/** + * Author: + * Date: 2015-06-24 + * Time: 19:34 + * Declaration: All Rights Reserved !!! + */ +public class Interval { + int start; + int end; + + Interval() { + start = 0; + end = 0; + } + + Interval(int s, int e) { + start = s; + end = e; + } +} diff --git a/[0057][Insert Interval]/src/Solution.java b/[0057][Insert Interval]/src/Solution.java new file mode 100644 index 0000000..d158b09 --- /dev/null +++ b/[0057][Insert Interval]/src/Solution.java @@ -0,0 +1,76 @@ +import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ; + +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-06-24 + * Time: 19:33 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Given a set of non-overlapping intervals, insert a new interval into the intervals
+     * (merge if necessary).
+     *
+     * You may assume that the intervals were initially sorted according to their start times.
+     *
+     * Example 1:
+     * Given intervals [1,3],[6,9], insert and merge [2,5] in as [1,5],[6,9].
+     *
+     * Example 2:
+     * Given [1,2],[3,5],[6,7],[8,10],[12,16], insert and merge [4,9] in as [1,2],[3,10],[12,16].
+     *
+     * This is because the new interval [4,9] overlaps with [3,5],[6,7],[8,10].
+     *
+     * Ŀ⣺
+     * һϵзǸǵ䣬һµ䣬бҪʱϲ
+     * 俪ʼʼʱкϲ
+     *
+     * ˼·
+     * ԭȲСͲص²䣬
+     * Сԭ䣬Ȳ䣬Ӵ
+     * 
+ * + * @param intervals + * @param newInterval + * @return + */ + public List insert(List intervals, Interval newInterval) { + + // ļ + List result = new LinkedList<>(); + + // 뼯ǿ + if (intervals != null) { + // Ԫ + for (Interval item : intervals) { + // newInterval == null ʾѾ + // ȲС + if (newInterval == null || item.end < newInterval.start) { + result.add(item); + } + // ȲУͬʱ + else if (item.start > newInterval.end) { + result.add(newInterval); + result.add(item); + newInterval = null; + } + // ص² + else { + newInterval.start = Math.min(newInterval.start, item.start); + newInterval.end = Math.max(newInterval.end, item.end); + } + } + } + + // ǿ˵仹δ + if (newInterval != null) { + result.add(newInterval); + } + + return result; + } +} diff --git a/[0058][Length Of Last Word]/[0058][Length Of Last Word].iml b/[0058][Length Of Last Word]/[0058][Length Of Last Word].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0058][Length Of Last Word]/[0058][Length Of Last Word].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0058][Length Of Last Word]/src/Solution.java b/[0058][Length Of Last Word]/src/Solution.java new file mode 100644 index 0000000..98d71cb --- /dev/null +++ b/[0058][Length Of Last Word]/src/Solution.java @@ -0,0 +1,54 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 19:27 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Given a string s consists of upper/lower-case alphabets and empty space characters ' ',
+     * return the length of last word in the string.
+     * If the last word does not exist, return 0.
+     * Note: A word is defined as a character sequence consists of non-space characters only.
+     * For example,
+     * Given s = "Hello World",
+     * return 5.
+     *
+     * Ŀ
+     * һɴСдĸͿոɵַַеһʳȡ
+     *
+     * ˼·
+     * ȴӺҵһĸλxûҵͷ0ҵҵһոλΪy(y-1
+     * Ϊûҵո)ؽx-y
+     * 
+ * + * @param s + * @return + */ + public int lengthOfLastWord(String s) { + + int index = s.length() - 1; + + // Ӻǰҵһ' 'ַ + while (index >= 0 && s.charAt(index) == ' ') { + index--; + } + + if (index < 0) { + return 0; + } + + int tmp = index; + + // ִе˵һ + + // Ӻǰҵһ' 'ַ + while (index >= 0 && s.charAt(index) != ' ') { + index--; + } + + return tmp - index; + } +} diff --git a/[0059][Spiral Matrix II]/[0059][Spiral Matrix II].iml b/[0059][Spiral Matrix II]/[0059][Spiral Matrix II].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0059][Spiral Matrix II]/[0059][Spiral Matrix II].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0059][Spiral Matrix II]/[0059][SpiralMatrixII].iml b/[0059][Spiral Matrix II]/[0059][SpiralMatrixII].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0059][Spiral Matrix II]/[0059][SpiralMatrixII].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0059][Spiral Matrix II]/src/Solution.java b/[0059][Spiral Matrix II]/src/Solution.java new file mode 100644 index 0000000..3470f7f --- /dev/null +++ b/[0059][Spiral Matrix II]/src/Solution.java @@ -0,0 +1,75 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 19:28 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.
+     * For example,
+     * Given n = 3,
+     * You should return the following matrix:
+     *
+     * [
+     *  [ 1, 2, 3 ],
+     *  [ 8, 9, 4 ],
+     *  [ 7, 6, 5 ]
+     * ]
+     *
+     * Ŀ
+     * һnһn*nľ1-n^2ֽ䡣
+     *
+     * ˼·
+     * üɷÿһλüӦ
+     * 
+ * + * @param n + * @return + */ + public int[][] generateMatrix(int n) { + int[][] result = new int[n][n]; + + int layer; + int k; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + layer = layer(i, j, n); // ǰм + // n * n - layer * layerΧʹõһ֣Ҳģ + // ڵĵǰʹõĵһ + k = n * n - (n - 2 * layer) * (n - 2 * layer) + 1; + result[i][j] = k; + + // (n - 2 * layer - 1)ĸ(n - 2 * layer - 1)ǣxyڲԪظ + if (i == layer) { // һϱ߽ + result[i][j] = k + j - layer; + } else if (j == n - layer - 1) { // ұ߽ + result[i][j] = k + (n - 2 * layer - 1) + i - layer; + } else if (i == n - layer - 1) { // ±߽ + result[i][j] = k + 3 * (n - 2 * layer - 1) - (j - layer); + } else { // ߽ + result[i][j] = k + 4 * (n - 2 * layer - 1) - (i - layer); + } + } + } + + return result; + } + + /** + * һn*nľУ㣨x,yжٲ㣬0ʼ + * + * @param x + * @param y + * @param n С + * @return IJ + */ + public int layer(int x, int y, int n) { + x = x < n - 1 - x ? x : n - 1 - x; // ±߽ + y = y < n - 1 - y ? y : n - 1 - y; // ұ߽ + + return x < y ? x : y; // СֵΪΧ + } +} diff --git a/[0060][Permutation Sequence]/[0060][Permutation Sequence].iml b/[0060][Permutation Sequence]/[0060][Permutation Sequence].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0060][Permutation Sequence]/[0060][Permutation Sequence].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0060][Permutation Sequence]/src/Solution.java b/[0060][Permutation Sequence]/src/Solution.java new file mode 100644 index 0000000..3bc2edf --- /dev/null +++ b/[0060][Permutation Sequence]/src/Solution.java @@ -0,0 +1,57 @@ +import java.util.ArrayList; +import java.util.List; + +/** + * @author: wangjunchao(王俊超) + * @time: 2018-09-28 15:45 + **/ +public class Solution { + /** + *
+     * 利用康托编码的思路,假设有n 个不重复的元素,第k 个排列是a1; a2; a3; :::; an,那么a1 是
+     * 哪一个位置呢?
+     * 我们把a1 去掉,那么剩下的排列为a2; a3; :::; an, 共计n-1 个元素,n-1 个元素共有(n-1)!
+     * 个排列,于是就可以知道a1 = k/(n - 1)!。
+     * 同理,a2; a3; :::; an 的值推导如下:
+     * k2 = k%(n - 1)!
+     * a2 = k2/(n - 2)!
+     * ...
+     * k(n-1) = k(n-2)%2!
+     * a(n-1) = k(n-1)/1!
+     * an = 0
+     * 
+ * + * @param n + * @param k + * @return + */ + public String getPermutation(int n, int k) { + + StringBuilder sb = new StringBuilder(); + List num = new ArrayList<>(); + // 用于计录最大的阶乘数 + int fact = 1; + for (int i = 1; i <= n; i++) { + fact *= i; + num.add(i); + } + + // l = k - 1;为了方便从0开始计数 + int index; + for (int i = 0, l = k - 1; i < n; i++) { + // 从最大的阶乘数开始减少 + // fact的值说明,如果从 __1____ -> _2____ 至少要经过fact次变换 + fact /= (n - i); + // 计算剩下的数据中的索引 + // 说明类似 __1____ -> _2____ 的变化可以做 index 次,0表示不用变 + index = (l / fact); + // 将索引值添加到结果中 + // 每做一次__1____ -> _2____ 的变化,表示在num中取后一个更大的值 + sb.append(num.remove(index)); + // 余下要处理的数 + l -= index * fact; + } + + return sb.toString(); + } +} diff --git a/[0061][Rotate List]/[0061][Rotate List].iml b/[0061][Rotate List]/[0061][Rotate List].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0061][Rotate List]/[0061][Rotate List].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0061][Rotate List]/src/ListNode.java b/[0061][Rotate List]/src/ListNode.java new file mode 100644 index 0000000..43e96df --- /dev/null +++ b/[0061][Rotate List]/src/ListNode.java @@ -0,0 +1,14 @@ +/** + * Author: + * Date: 2015-07-21 + * Time: 18:46 + * Declaration: All Rights Reserved !!! + */ +public class ListNode { + int val; + ListNode next; + + ListNode(int x) { + val = x; + } +} diff --git a/[0061][Rotate List]/src/Solution.java b/[0061][Rotate List]/src/Solution.java new file mode 100644 index 0000000..9f4e91d --- /dev/null +++ b/[0061][Rotate List]/src/Solution.java @@ -0,0 +1,34 @@ +/** + * Author: + * Date: 2015-07-21 + * Time: 18:46 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + public ListNode rotateRight(ListNode head, int n) { + + if (head == null || n < 1) { + return head; + } + + int length = 1; + ListNode p = head; + while (p.next != null) { + p = p.next; + length++; + } + + // ҪĽڵΪheadǰһڵ + n = length - n % length; + + // β + p.next = head; + for (int i = 0; i < n; i++) { + p = p.next; + } + + head = p.next; + p.next = null; + return head; + } +} diff --git a/[0061][Rotate List]/src/Solution2.java b/[0061][Rotate List]/src/Solution2.java new file mode 100644 index 0000000..00ca18f --- /dev/null +++ b/[0061][Rotate List]/src/Solution2.java @@ -0,0 +1,62 @@ +/** + * Author: + * Date: 2015-07-21 + * Time: 18:46 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + public ListNode rotateRight(ListNode head, int n) { + + if (head == null || n < 1) { + return head; + } + + ListNode root = new ListNode(0); + root.next = head; + ListNode p = root; + ListNode q = root; + + // תλÿܱ + int count = 0; + for (int i = 0; i <= n; i++) { + p = p.next; + count++; + if (p == null) { + // гͷݸ + count--; + // ʵҪλõλ + n = n % count; + // Ϊ¿ʼλ׼ + i = 0; + p = head; + } + } + + // ҵһҪĽǰ + // qΪһҪĽǰ + while (p != null) { + p = p.next; + q = q.next; + + } + + p = q; + q = root; + // ҪλƵĽ + if (p != null && p.next != null) { + ListNode node; + while (p.next != null) { + // ժ + node = p.next; + p.next = node.next; + // Ͻ + node.next = q.next; + q.next = node; + // һƶĽڵ + q = node; + } + } + + return root.next; + } +} diff --git a/[0062][Unique Paths]/[0062][Unique Paths].iml b/[0062][Unique Paths]/[0062][Unique Paths].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0062][Unique Paths]/[0062][Unique Paths].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0062][Unique Paths]/[0062][UniquePaths].iml b/[0062][Unique Paths]/[0062][UniquePaths].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0062][Unique Paths]/[0062][UniquePaths].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0062][Unique Paths]/src/Solution.java b/[0062][Unique Paths]/src/Solution.java new file mode 100644 index 0000000..43be774 --- /dev/null +++ b/[0062][Unique Paths]/src/Solution.java @@ -0,0 +1,63 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 19:30 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * A robot is located at the top-left corner of a m x n grid
+     * (marked Start in the diagram below).
+     * The robot can only move either down or right at any point in time.
+     * The robot is trying to reach the bottom-right corner of the grid
+     * (marked Finish in the diagram below).
+     * How many possible unique paths are there?
+     *
+     * Above is a 3 x 7 grid. How many possible unique paths are there?
+     * Note: m and n will be at most 100.
+     *
+     * Ŀ
+     * һһm*nķϽǡ
+     * ֻһһ񣬻Ҫ½ǵķ
+     * һжΨһ·
+     * ע⣺ͣ󲻳100
+     *
+     * ˼·
+     * ͵Ķ̬滮⣬ʹö̬滮ķ⡣
+     * һm*nA
+     * AеԪС
+     * 1x=0y=0ʱA[x][y] = 1
+     * 2x>=1y>=1ʱA[x][y] = A[x-1][y]+A[x][y-1]
+     * 3ĽA[m-1][n-1]
+     * 
+ * + * @param m + * @param n + * @return + */ + public int uniquePaths(int m, int n) { + int[][] result = new int[m][n]; + + // һеĽ + for (int i = 0; i < m; i++) { + result[i][0] = 1; + } + + // һеĽ + for (int i = 1; i < n; i++) { + result[0][i] = 1; + } + + // λõĽ + for (int i = 1; i < m; i++) { + for (int j = 1; j < n; j++) { + result[i][j] = result[i - 1][j] + result[i][j - 1]; + } + } + + // Ľ + return result[m - 1][n - 1]; + } +} diff --git a/[0063][Unique Paths II]/[0063][Unique Paths II].iml b/[0063][Unique Paths II]/[0063][Unique Paths II].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0063][Unique Paths II]/[0063][Unique Paths II].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0063][Unique Paths II]/[0063][UniquePathsII].iml b/[0063][Unique Paths II]/[0063][UniquePathsII].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0063][Unique Paths II]/[0063][UniquePathsII].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0063][Unique Paths II]/src/Solution.java b/[0063][Unique Paths II]/src/Solution.java new file mode 100644 index 0000000..66ce05d --- /dev/null +++ b/[0063][Unique Paths II]/src/Solution.java @@ -0,0 +1,99 @@ +/** + * Author: + * Date: 2015-06-22 + * Time: 21:38 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Follow up for "Unique Paths":
+     * Now consider if some obstacles are added to the grids. How many unique paths would there be?
+     * An obstacle and empty space is marked as 1 and 0 respectively in the grid.
+     *
+     * For example,
+     * There is one obstacle in the middle of a 3x3 grid as illustrated below.
+     * [
+     *      [0,0,0],
+     *      [0,1,0],
+     *      [0,0,0]
+     * ]
+     *
+     * The total number of unique paths is 2.
+     * Note: m and n will be at most 100.
+     *
+     * Ŀ⣺
+     * Ψһ··ϰܵ·
+     * ע⣺
+     * 100
+     *
+     * ˼·
+     * ÷ⷽ
+     *
+     * 
+ * + * @param obstacleGrid + * @return + */ + public int uniquePathsWithObstacles(int[][] obstacleGrid) { + // У + if (obstacleGrid == null || obstacleGrid.length < 1 || obstacleGrid[0].length < 1 + || obstacleGrid[0][0] == 1 + || obstacleGrid[obstacleGrid.length - 1][obstacleGrid[0].length - 1] == 1) { + return 0; + } + + int rows = obstacleGrid.length; + int cols = obstacleGrid[0].length; + int[][] result = new int[rows][cols]; + + // һλжַϰ1֣ϰ0 + result[0][0] = obstacleGrid[0][0] == 0 ? 1 : 0; + + // һж߷ϰ0 + for (int i = 1; i < cols; i++) { + result[0][i] = obstacleGrid[0][i] == 0 ? result[0][i - 1] : 0; + } + + // һж߷ϰ0 + for (int i = 1; i < rows; i++) { + result[i][0] = obstacleGrid[i][0] == 0 ? result[i - 1][0] : 0; + } + + // λõĽⷨϰ0 + for (int i = 1; i < rows; i++) { + for (int j = 1; j < cols; j++) { + result[i][j] = obstacleGrid[i][j] == 0 ? result[i - 1][j] + result[i][j - 1] : 0; + } + } + + return result[rows - 1][cols - 1]; + } + + + // ʹõݹ鷽ᳬʱ + public int uniquePathsWithObstacles2(int[][] obstacleGrid) { + // У + if (obstacleGrid == null || obstacleGrid.length < 1 || obstacleGrid[0].length < 1 + || obstacleGrid[obstacleGrid.length - 1][obstacleGrid[0].length - 1] == 1) { + return 0; + } + int[] result = {0}; + solve(obstacleGrid, 0, 0, result); + return result[0]; + } + + public void solve(int[][] grid, int row, int col, int[] sum) { + // յ + if (row == grid.length - 1 && col == grid[0].length - 1) { + sum[0]++; + } + // ûеյ㣬ڣҵǰλò + else if (row >= 0 && row < grid.length && col >= 0 && col < grid[0].length && grid[row][col] == 0) { + // + solve(grid, row, col + 1, sum); + // + solve(grid, row + 1, col, sum); + } + } +} diff --git a/[0064][Minimum Path Sum]/[0064][Minimum Path Sum].iml b/[0064][Minimum Path Sum]/[0064][Minimum Path Sum].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0064][Minimum Path Sum]/[0064][Minimum Path Sum].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0064][Minimum Path Sum]/[0064][MinimumPathSum].iml b/[0064][Minimum Path Sum]/[0064][MinimumPathSum].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0064][Minimum Path Sum]/[0064][MinimumPathSum].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0064][Minimum Path Sum]/src/Main.java b/[0064][Minimum Path Sum]/src/Main.java new file mode 100644 index 0000000..8709016 --- /dev/null +++ b/[0064][Minimum Path Sum]/src/Main.java @@ -0,0 +1,24 @@ +/** + * Author: + * Date: 2015-06-22 + * Time: 16:29 + * Declaration: All Rights Reserved !!! + */ +public class Main { + public static void main(String[] args) { + Solution solution = new Solution(); + + int[][] grid = {{5, 0, 1, 1, 2, 1, 0, 1, 3, 6, 3, 0, 7, 3, 3, 3, 1}, {1, 4, 1, 8, 5, 5, 5, 6, 8, 7, 0, 4, 3, 9, 9, 6, 0}, {2, 8, 3, 3, 1, 6, 1, 4, 9, 0, 9, 2, 3, 3, 3, 8, 4}, {3, 5, 1, 9, 3, 0, 8, 3, 4, 3, 4, 6, 9, 6, 8, 9, 9}, {3, 0, 7, 4, 6, 6, 4, 6, 8, 8, 9, 3, 8, 3, 9, 3, 4}, {8, 8, 6, 8, 3, 3, 1, 7, 9, 3, 3, 9, 2, 4, 3, 5, 1}, {7, 1, 0, 4, 7, 8, 4, 6, 4, 2, 1, 3, 7, 8, 3, 5, 4}, {3, 0, 9, 6, 7, 8, 9, 2, 0, 4, 6, 3, 9, 7, 2, 0, 7}, {8, 0, 8, 2, 6, 4, 4, 0, 9, 3, 8, 4, 0, 4, 7, 0, 4}, {3, 7, 4, 5, 9, 4, 9, 7, 9, 8, 7, 4, 0, 4, 2, 0, 4}, {5, 9, 0, 1, 9, 1, 5, 9, 5, 5, 3, 4, 6, 9, 8, 5, 6}, {5, 7, 2, 4, 4, 4, 2, 1, 8, 4, 8, 0, 5, 4, 7, 4, 7}, {9, 5, 8, 6, 4, 4, 3, 9, 8, 1, 1, 8, 7, 7, 3, 6, 9}, {7, 2, 3, 1, 6, 3, 6, 6, 6, 3, 2, 3, 9, 9, 4, 4, 8}}; + +// System.out.println(solution.minPathSum(grid)); + + int[][] grid2 = {{4, 1, 7, 8, 4, 9, 2, 9, 9, 0, 2, 9, 4, 0, 2}, {2, 2, 7, 7, 3, 9, 0, 8, 4, 7, 8, 2, 5, 5, 5}, {2, 9, 8, 1, 7, 2, 0, 2, 1, 9, 4, 5, 0, 1, 5}, {4, 3, 0, 1, 1, 5, 2, 3, 5, 8, 3, 3, 0, 0, 8}, {7, 2, 9, 5, 3, 7, 7, 6, 1, 1, 7, 5, 6, 8, 6}, {4, 4, 2, 6, 6, 3, 1, 0, 8, 7, 9, 1, 0, 1, 3}, {1, 9, 5, 0, 4, 1, 9, 4, 7, 0, 5, 6, 8, 3, 6}, {4, 7, 1, 6, 3, 7, 1, 7, 9, 0, 6, 8, 3, 8, 0}, {7, 9, 1, 4, 2, 5, 7, 1, 1, 6, 4, 6, 3, 2, 2}, {9, 8, 9, 0, 7, 5, 9, 8, 4, 9, 0, 0, 9, 4, 8}, {1, 3, 0, 2, 7, 2, 0, 5, 5, 1, 1, 9, 0, 4, 3}, {2, 4, 4, 3, 6, 1, 0, 6, 1, 4, 5, 2, 4, 4, 8}, {5, 8, 1, 5, 0, 0, 9, 0, 5, 4, 4, 9, 6, 4, 5}}; + +// System.out.println(solution.minPathSum(grid2)); + + + int[][] grid3 = {{0, 7, 7, 8, 1, 2, 4, 3, 0, 0, 5, 9, 8, 3, 6, 5, 1, 0}, {2, 1, 1, 0, 8, 1, 3, 3, 9, 9, 5, 8, 7, 5, 7, 5, 5, 8}, {9, 2, 3, 1, 2, 8, 1, 2, 3, 7, 9, 7, 9, 3, 0, 0, 3, 8}, {3, 9, 3, 4, 8, 1, 2, 6, 8, 9, 3, 4, 9, 4, 8, 3, 6, 2}, {3, 7, 4, 7, 6, 5, 6, 5, 8, 6, 7, 3, 6, 2, 2, 9, 9, 3}, {2, 3, 1, 1, 5, 4, 7, 4, 0, 7, 7, 6, 9, 1, 5, 5, 0, 3}, {0, 8, 8, 8, 4, 7, 1, 0, 2, 6, 1, 1, 1, 6, 4, 2, 7, 9}, {8, 6, 6, 8, 3, 3, 5, 4, 6, 2, 9, 8, 6, 9, 6, 6, 9, 2}, {6, 2, 2, 8, 0, 6, 1, 1, 4, 5, 3, 1, 7, 3, 9, 3, 2, 2}, {8, 9, 8, 5, 3, 7, 5, 9, 8, 2, 8, 7, 4, 4, 1, 9, 2, 2}, {7, 3, 3, 1, 0, 9, 4, 7, 2, 3, 2, 6, 7, 1, 7, 7, 8, 1}, {4, 3, 2, 2, 7, 0, 1, 4, 4, 4, 3, 8, 6, 2, 1, 2, 5, 4}, {1, 9, 3, 5, 4, 6, 4, 3, 7, 1, 0, 7, 2, 4, 0, 7, 8, 0}, {7, 1, 4, 2, 5, 9, 0, 4, 1, 4, 6, 6, 8, 9, 7, 1, 4, 3}, {9, 8, 6, 8, 2, 6, 5, 6, 2, 8, 3, 2, 8, 1, 5, 4, 5, 2}, {3, 7, 8, 6, 3, 4, 2, 3, 5, 1, 7, 2, 4, 6, 0, 2, 5, 4}, {8, 2, 1, 2, 2, 6, 6, 0, 7, 3, 6, 4, 5, 9, 4, 4, 5, 7}}; + System.out.println(solution.minPathSum(grid3)); + + } +} diff --git a/[0064][Minimum Path Sum]/src/Solution.java b/[0064][Minimum Path Sum]/src/Solution.java new file mode 100644 index 0000000..295e70c --- /dev/null +++ b/[0064][Minimum Path Sum]/src/Solution.java @@ -0,0 +1,110 @@ +/** + * Author: + * Date: 2015-06-22 + * Time: 15:59 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + + /** + *
+     * Given a m x n grid filled with non-negative numbers, find a path from top
+     * left to bottom right which minimizes the sum of all numbers along its path.
+     *
+     * Note: You can only move either down or right at any point in time.
+     *
+     * Ŀ⣺
+     * һm x nķÿԪصֵǷǸģҳϽǶ㣬½Ƕ͵ֵС·
+     * ҵС
+     *
+     * ע⣺
+     *   - ÿֻ»ȡƶһ
+     *
+     * Կ˼·
+     * η
+     * һ  S[0][0] = grid[0][0]
+     * һУ  S[0][j] = S[0][j - 1] + grid[0][j]
+     * һУ  S[i][0] = S[i - 1][0] + grid[i][0]
+     * S[i][j] = min(S[i - 1][j], S[i][j - 1]) + grid[i][j]
+     * 
+ * + * @param grid + * @return + */ + + public int minPathSum(int[][] grid) { + // + if (grid == null || grid.length < 1 || grid[0].length < 1) { + return 0; + } + + + int[][] result = new int[grid.length][grid[0].length]; + // һ + result[0][0] = grid[0][0]; + + // һ + for (int i = 1; i < result[0].length; i++) { + result[0][i] = result[0][i - 1] + grid[0][i]; + } + + // һ + for (int i = 1; i < result.length; i++) { + result[i][0] = result[i - 1][0] + grid[i][0]; + } + + // + for (int i = 1; i < result.length; i++) { + for (int j = 1; j < result[0].length; j++) { + result[i][j] = Math.min(result[i - 1][j], result[i][j - 1]) + grid[i][j]; + } + } + + return result[result.length - 1][result[0].length - 1]; + } + + //////////////////////////////////////////////////////////////////////////////////////////////// + // ̬黮ͷ֦޽磬ķᳬʱ + //////////////////////////////////////////////////////////////////////////////////////////////// + public int minPathSum2(int[][] grid) { + // + if (grid == null || grid.length < 1 || grid[0].length < 1) { + return 0; + } + + // ڼ¼С· + int[] minSum = {Integer.MAX_VALUE}; + int[] curSum = {0}; + // + solve(grid, 0, 0, curSum, minSum); + + // ؽ + return minSum[0]; + } + + public void solve(int[][] grid, int row, int col, int[] curSum, int[] minSum) { + // Ѿյ + if (row == grid.length - 1 && col == grid[0].length - 1) { + curSum[0] += grid[row][col]; + + // Сĺ + if (curSum[0] < minSum[0]) { + minSum[0] = curSum[0]; + } + + curSum[0] -= grid[row][col]; + } + // δյ㣬 + else if (row >= 0 && row < grid.length && col >= 0 && col < grid[0].length) { + curSum[0] += grid[row][col]; + // ǰĺֻвСڼ¼С·ֵܽһ + if (curSum[0] <= minSum[0]) { + // + solve(grid, row, col + 1, curSum, minSum); + // + solve(grid, row + 1, col, curSum, minSum); + } + curSum[0] -= grid[row][col]; + } + } +} diff --git a/[0065][Valid Number]/[0065][Valid Number].iml b/[0065][Valid Number]/[0065][Valid Number].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0065][Valid Number]/[0065][Valid Number].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0065][Valid Number]/src/Main.java b/[0065][Valid Number]/src/Main.java new file mode 100644 index 0000000..c039e9e --- /dev/null +++ b/[0065][Valid Number]/src/Main.java @@ -0,0 +1,95 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-17 13:32 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + Assert.assertEquals(true, solution.isNumber("0")); + } + + @Test + public void test2() { + Solution solution = new Solution(); + Assert.assertEquals(true, solution.isNumber(" 0.1 ")); + } + + @Test + public void test3() { + Solution solution = new Solution(); + Assert.assertEquals(false, solution.isNumber("abc")); + } + + @Test + public void test4() { + Solution solution = new Solution(); + Assert.assertEquals(false, solution.isNumber("1 a")); + } + + @Test + public void test41() { + Solution solution = new Solution(); + Assert.assertEquals(true, solution.isNumber("2e10")); + } + + @Test + public void test42() { + Solution solution = new Solution(); + Assert.assertEquals(true, solution.isNumber(" -90e3 ")); + } + + @Test + public void test5() { + Solution solution = new Solution(); + Assert.assertEquals(false, solution.isNumber(" 1e")); + } + + @Test + public void test6() { + Solution solution = new Solution(); + Assert.assertEquals(false, solution.isNumber("e3")); + } + + + @Test + public void test7() { + Solution solution = new Solution(); + Assert.assertEquals(true, solution.isNumber(" 6e-1")); + } + + @Test + public void test8() { + Solution solution = new Solution(); + Assert.assertEquals(false, solution.isNumber(" 99e2.5 ")); + } + + + @Test + public void test9() { + Solution solution = new Solution(); + Assert.assertEquals(true, solution.isNumber("53.5e93")); + } + + @Test + public void test10() { + Solution solution = new Solution(); + Assert.assertEquals(false, solution.isNumber(" --6 ")); + } + + @Test + public void test11() { + Solution solution = new Solution(); + Assert.assertEquals(false, solution.isNumber("-+3")); + } + + @Test + public void test12() { + Solution solution = new Solution(); + Assert.assertEquals(false, solution.isNumber("95a54e53")); + } + +} diff --git a/[0065][Valid Number]/src/Solution.java b/[0065][Valid Number]/src/Solution.java new file mode 100644 index 0000000..3f6d642 --- /dev/null +++ b/[0065][Valid Number]/src/Solution.java @@ -0,0 +1,100 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-17 13:20 + **/ +public class Solution { + + /** + * 序数就分别为0, 1, 2, 3, 4, 5, 6 + */ + private enum InputType { + INVALID, + SPACE, + SIGN, + DIGIT, + DOT, + EXPONENT + } + + // 状态转表 TODO 每个状态是什么意思? + private final static int[][] TRANSITION_TABLE = { + {-1, 0, 3, 1, 2, -1}, // next states for state 0 + {-1, 8, -1, 1, 4, 5}, // next states for state 1 + {-1, -1, -1, 4, -1, -1},// next states for state 2 + {-1, -1, -1, 1, 2, -1,},// next states for state 3 + {-1, 8, -1, 4, -1, 5},// next states for state 4 + {-1, -1, 6, 7, -1, -1},// next states for state 5 + {-1, -1, -1, 7, -1, -1},// next states for state 6 + {-1, 8, -1, 7, -1, -1},// next states for state 7 + {-1, 8, -1, -1, -1, -1},// next states for state 8 + }; + + /** + *
+     * Validate if a given string can be interpreted as a decimal number.
+     *
+     * Some examples:
+     * "0" => true
+     * " 0.1 " => true
+     * "abc" => false
+     * "1 a" => false
+     * "2e10" => true
+     * " -90e3   " => true
+     * " 1e" => false
+     * "e3" => false
+     * " 6e-1" => true
+     * " 99e2.5 " => false
+     * "53.5e93" => true
+     * " --6 " => false
+     * "-+3" => false
+     * "95a54e53" => false
+     *
+     * Note: It is intended for the problem statement to be ambiguous. You should gather all requirements
+     * up front before implementing one. However, here is a list of characters that can be in a valid decimal number:
+     *
+     * Numbers 0-9
+     * Exponent - "e"
+     * Positive/negative sign - "+"/"-"
+     * Decimal point - "."
+     * Of course, the context of these characters also matters in the input.
+     * 
+ * + * @param s + * @return + */ + public boolean isNumber(String s) { + int state = 0; + for (int i = 0; i < s.length(); i++) { + InputType inputType = InputType.INVALID; + if (Character.isSpaceChar(s.charAt(i))) { + inputType = InputType.SPACE; + } else if (s.charAt(i) == '+' || s.charAt(i) == '-') { + inputType = InputType.SIGN; + } else if (Character.isDigit(s.charAt(i))) { + inputType = InputType.DIGIT; + } else if (s.charAt(i) == '.') { + inputType = InputType.DOT; + } else if (s.charAt(i) == 'e' || s.charAt(i) == 'E') { + inputType = InputType.EXPONENT; + } + // Get next state from current state and input symbol + state = TRANSITION_TABLE[state][inputType.ordinal()]; + + // Invalid input + if (state == -1) { + return false; + } + } + // If the current state belongs to one of the accepting (final) states, + // then the number is valid + return state == 1 || state == 4 || state == 7 || state == 8; + } + + private boolean isDigit(char charAt) { + return charAt >= '0' && charAt <= '9'; + } + + private boolean isSpace(char charAt) { + return charAt == ' '; + } +} diff --git a/[0066][Plus One]/[0066][Plus One].iml b/[0066][Plus One]/[0066][Plus One].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0066][Plus One]/[0066][Plus One].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0066][Plus One]/src/Solution.java b/[0066][Plus One]/src/Solution.java new file mode 100644 index 0000000..efc7195 --- /dev/null +++ b/[0066][Plus One]/src/Solution.java @@ -0,0 +1,55 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 19:32 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Given a non-negative number represented as an array of digits, plus one to the number.
+     * The digits are stored such that the most significant digit is at the head of the list.
+     *
+     * Ŀ
+     * һʾһмһ
+     * ÿһλ洢һλϡ±ӴСʾλӵλλ
+     *
+     * ˼·
+     * ֱ⣬һλ־carryֵΪ1ʾ1λʼtmp = a[x] + carry
+     * a[x] = tmp%10carry = tmp/10carryΪ0һλٽвֱеλcarray
+     * Ϊ0˳carrayΪ0˵Ҫչһλ
+     * 
+ * + * @param digits + * @return + */ + public int[] plusOne(int[] digits) { + + // λ־һλĽλ־ + int carry = 1; + int tmp; + for (int i = digits.length - 1; i >= 0; i--) { + tmp = digits[i]; + // 㵱ǰλֵ + digits[i] = (tmp + carry) % 10; + // µĽλ + carry = (tmp + carry) / 10; + + // ûнλ˾Ϳ˳ + if (carry == 0) { + break; + } + } + + // һλ + if (carry == 1) { + int[] result = new int[digits.length + 1]; + System.arraycopy(digits, 0, result, 1, digits.length); + result[0] = carry; + return result; + } else { + return digits; + } + } +} diff --git a/[0067][Add Binary]/[0067][Add Binary].iml b/[0067][Add Binary]/[0067][Add Binary].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0067][Add Binary]/[0067][Add Binary].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0067][Add Binary]/src/Solution.java b/[0067][Add Binary]/src/Solution.java new file mode 100644 index 0000000..a79aab6 --- /dev/null +++ b/[0067][Add Binary]/src/Solution.java @@ -0,0 +1,105 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 19:34 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Given two binary strings, return their sum (also a binary string).
+     * For example,
+     * a = "11"
+     * b = "1"
+     * Return "100"
+     *
+     * Ŀ
+     * ƵַǵĺͣҲǶַ
+     *
+     * ˼·
+     * ȽӦַתɶӦ飬ӵλλӣͬʱҪǵ
+     * ӻҪչһλʵ֡
+     * 
+ * + * @param a + * @param b + * @return + */ + public String addBinary(String a, String b) { + + int[] ca = new int[a.length()]; + int[] cb = new int[b.length()]; + + // ַеֵתֵ01 + for (int i = 0; i < a.length(); i++) { + ca[i] = a.charAt(i) - '0'; + } + + // ַеֵתֵ01 + for (int i = 0; i < b.length(); i++) { + cb[i] = b.charAt(i) - '0'; + } + + // ʹcaijȳ + if (ca.length < cb.length) { + int[] tmp = ca; + ca = cb; + cb = tmp; + } + + + int ai = ca.length - 1; // ַcaһ± + int bi = cb.length - 1; // ַcbһ± + int carry = 0; // λĽλʶ + int result; // صĽ + + // 磺1010101101 + 10100 + while (ai >= 0 && bi >= 0) { + result = ca[ai] + cb[bi] + carry; + ca[ai] = result % 2; + carry = result / 2; + + ai--; + bi--; + } + + // µ + while (ai >= 0) { + result = ca[ai] + carry; + ca[ai] = result % 2; + carry = result / 2; + + if (carry == 0) { + break; + } + + ai--; + } + + // ַеֵתַ01 + for (int i = 0; i < ca.length; i++) { + ca[i] += '0'; + } + + // Ҫչһλ + if (carry == 0) { + + char[] ch = new char[ca.length]; + for (int i = 0; i < ca.length; i++) { + ch[i] = (char) (ca[i]); + } + + return new String(ch); + } + // Ҫչһλ + else { + char[] ch = new char[ca.length + 1]; + ch[0] = '1'; + for (int i = 0; i < ca.length; i++) { + ch[i + 1] = (char) (ca[i]); + } + return new String(ch); + } + } +} diff --git a/[0069][Sqrt(x)]/[0069][Sqrt(x)].iml b/[0069][Sqrt(x)]/[0069][Sqrt(x)].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0069][Sqrt(x)]/[0069][Sqrt(x)].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0069][Sqrt(x)]/src/Solution.java b/[0069][Sqrt(x)]/src/Solution.java new file mode 100644 index 0000000..d1cc9c3 --- /dev/null +++ b/[0069][Sqrt(x)]/src/Solution.java @@ -0,0 +1,87 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-23 15:09 + **/ +public class Solution { + /** + *
+     * Implement int sqrt(int x).
+     *
+     * Compute and return the square root of x, where x is guaranteed to be a non-negative integer.
+     *
+     * Since the return type is an integer, the decimal digits are truncated and only the integer
+     * part of the result is returned.
+     *
+     * Example 1:
+     *
+     * Input: 4
+     * Output: 2
+     * Example 2:
+     *
+     * Input: 8
+     * Output: 2
+     * Explanation: The square root of 8 is 2.82842..., and since
+     *              the decimal part is truncated, 2 is returned.
+     * 
+ * + * @param x + * @return + */ + public int mySqrt(int x) { + return mySqrt2(x); + } + + /** + * 使用二分法 + *
+     * 思路:要实现一个sqrt函数,可以使用二分法,首先确定一个范围[begin, end],这个范围的中间数mid,
+     * 看mid的平方是否等于x,如果相等,则返回mid,如果不等则缩小[begin,end]的范围,为原来的一半。这
+     * 里的初始范围可以是[1, x],也可以是更精确一些的[1, (x/2) + 1]。(因 (x/2) + 1 的平方等于
+     * x+1+(x^2/4),它一定大于x,所以,x的平方根一定在[1, (x/2) + 1]范围内)
+     *
+     * 
+ * + * @param x + * @return + */ + public int mySqrt1(int x) { + if (x == 0) { + return 0; + } + int left = 1; + int right = x; + while (true) { + int mid = left + (right - left) / 2; + if (mid > x / mid) { + right = mid - 1; + } else { + if (mid + 1 > x / (mid + 1)) { + return mid; + } + left = mid + 1; + } + } + } + + /** + * 使用牛顿法 + *
+     * x^2 = a的解,也就是函数f(x) = x^2 – a与x轴的交点。可以在x轴上先任选一点x0,则点(x0, f(x0))
+     * 在f(x)上的切线,与x轴的交点为x1,它们满足切线的方程:f(x0)=(x0-x1)f’(x0),可得x1更接近最终的
+     * 结果,解方程得到:
+     * 切线方程:y = 2x0(x - x0) + x0^2 - a,令y=0 -> x = (x0 + (a/x0))/2,即为x1的值
+     *
+     * x1 = (x0 + (a/x0))/2。以x1为新的x0,按照切线的方法依次迭代下去,最终求得符合精确度要求的结果值。
+     * 
+ * + * @param x + * @return + */ + public int mySqrt2(int x) { + long r = x; + while (r * r > x) { + r = (r + x / r) / 2; + } + return (int) r; + } +} diff --git a/[0070][Climbing Stairs]/[0070][Climbing Stairs].iml b/[0070][Climbing Stairs]/[0070][Climbing Stairs].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0070][Climbing Stairs]/[0070][Climbing Stairs].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0070][Climbing Stairs]/src/Solution.java b/[0070][Climbing Stairs]/src/Solution.java new file mode 100644 index 0000000..570efe8 --- /dev/null +++ b/[0070][Climbing Stairs]/src/Solution.java @@ -0,0 +1,47 @@ +/** + * Author: + * Date: 2015-07-25 + * Time: 09:10 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * f(n) ʾn ¥ݵIJͬΪn ¥ݣѡ
+     * - ӵn - 1 ǰ1 
+     * - ӵn - 1 ǰ2 
+     * ˣf(n) = f(n - 1) + f(n - 2)
+     * 
+ * @param n + * @return + */ + public int climbStairs(int n) { + + int result = 0; + + // ֻһ + if (n == 1) { + result = 1; + } + // ֻ + else if (n == 2) { + result = 2; + } + // ¥ݽ2 + else if (n > 2) { + // еĽⷨ + int[] ways = new int[n]; + + ways[0] = 1; + ways[1] = 2; + + for (int i = 2; i < ways.length; i++) { + ways[i] = ways[i - 1] + ways[i - 2]; + } + + result = ways[ways.length - 1]; + } + + return result; + } +} diff --git a/[0071][Simplify Path]/[0071][Simplify Path].iml b/[0071][Simplify Path]/[0071][Simplify Path].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0071][Simplify Path]/[0071][Simplify Path].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0071][Simplify Path]/src/Solution.java b/[0071][Simplify Path]/src/Solution.java new file mode 100644 index 0000000..c17fc59 --- /dev/null +++ b/[0071][Simplify Path]/src/Solution.java @@ -0,0 +1,32 @@ +import java.util.LinkedList; +import java.util.List; + +/** + * @author: wangjunchao(王俊超) + * @time: 2018-09-28 15:50 + **/ +public class Solution { + public String simplifyPath(String path) { + String[] ss = path.split("/"); + List result = new LinkedList<>(); + + for (String part : ss) { + if (".".equals(part)) { + continue; + } else if ("..".equals(part)) { + if (result.size() > 0) { + result.remove(result.size() - 1); + } + } else if (!"".equals(part.trim())) { + result.add(part); + } + } + + StringBuilder builder = new StringBuilder(); + for (String part : result) { + builder.append("/").append(part); + } + + return builder.length() == 0 ? "/" : builder.toString(); + } +} diff --git a/[0073][Set Matrix Zeroes]/[0073][Set Matrix Zeroes].iml b/[0073][Set Matrix Zeroes]/[0073][Set Matrix Zeroes].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0073][Set Matrix Zeroes]/[0073][Set Matrix Zeroes].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0073][Set Matrix Zeroes]/[0073][SetMatrixZeroes].iml b/[0073][Set Matrix Zeroes]/[0073][SetMatrixZeroes].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0073][Set Matrix Zeroes]/[0073][SetMatrixZeroes].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0073][Set Matrix Zeroes]/src/Solution.java b/[0073][Set Matrix Zeroes]/src/Solution.java new file mode 100644 index 0000000..1d25618 --- /dev/null +++ b/[0073][Set Matrix Zeroes]/src/Solution.java @@ -0,0 +1,58 @@ +/** + * Author: + * Date: 2015-07-25 + * Time: 09:27 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + public void setZeroes(int[][] matrix) { + // һбõı־ + boolean rowFlag = false; + // һбõı־ + boolean colFlag = false; + + for (int i = 0; i < matrix.length; i++) { + for (int j = 0; j < matrix[0].length; j++) { + if (matrix[i][j] == 0) { + // ǵһҪ + if (i == 0) { + rowFlag = true; + } + + // ǵһҪ + if (j == 0){ + colFlag = true; + } + + // ڱҪΪ0к + matrix[0][j] = 0; + matrix[i][0] = 0; + } + } + } + + // ԵڶеڶпʼԪ0 + for (int i = 1; i < matrix.length; i++) { + for (int j = 1; j < matrix[0].length; j++) { + if (matrix[i][0] == 0 || matrix[0][j] == 0) { + matrix[i][j] = 0; + } + } + } + + // õһΪ0 + if (rowFlag) { + for (int j = 0; j < matrix[0].length; j++) { + matrix[0][j] = 0; + } + } + + // õһΪ0 + if (colFlag) { + for (int i = 0; i < matrix.length; i++) { + matrix[i][0] = 0; + } + } + + } +} diff --git a/[0074][Search A 2D Matrix]/[0074][Search A 2D Matrix].iml b/[0074][Search A 2D Matrix]/[0074][Search A 2D Matrix].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0074][Search A 2D Matrix]/[0074][Search A 2D Matrix].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0074][Search A 2D Matrix]/[0074][SearchA2DMatrix].iml b/[0074][Search A 2D Matrix]/[0074][SearchA2DMatrix].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0074][Search A 2D Matrix]/[0074][SearchA2DMatrix].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0074][Search A 2D Matrix]/src/Main.java b/[0074][Search A 2D Matrix]/src/Main.java new file mode 100644 index 0000000..4206b6b --- /dev/null +++ b/[0074][Search A 2D Matrix]/src/Main.java @@ -0,0 +1,16 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-19 16:11 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + + int[][] matrix = {{1, 3}}; + Assert.assertEquals(true, solution.searchMatrix(matrix, 3)); + } +} diff --git a/[0074][Search A 2D Matrix]/src/Solution.java b/[0074][Search A 2D Matrix]/src/Solution.java new file mode 100644 index 0000000..4942ee4 --- /dev/null +++ b/[0074][Search A 2D Matrix]/src/Solution.java @@ -0,0 +1,62 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 19:36 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:
+     * Integers in each row are sorted from left to right.
+     * The first integer of each row is greater than the last integer of the previous row.
+     * For example,
+     * Consider the following matrix:Given target = 3, return true.
+     *
+     * [
+     *  [1,   3,  5,  7],
+     *  [10, 11, 16, 20],
+     *  [23, 30, 34, 50]
+     * ]
+     *
+     * Ŀ
+     * һάʵһ㷨ھʵֿkھk
+     * ʣÿһÿһжźģÿһеĵһһеһ
+     *
+     * ˼·
+     * ⷨһö鿴㷨ҵڵУö㷨ڵСҵͷtrue򷵻false
+     * 
+ * + * @param matrix + * @param target + * @return + */ + public boolean searchMatrix(int[][] matrix, int target) { + + if (matrix == null || matrix.length == 0 || matrix[0].length == 0) { + return false; + } + + int row = matrix.length; + int column = matrix[0].length; + int low = 0; + int high = row * column - 1; + int mid; + + // ҽڵ + while (low <= high) { + mid = low + (high - low) / 2; + int value = matrix[mid / column][mid % column]; + if (value == target) { + return true; + } else if (value < target) { + low = mid + 1; + } else { + high = mid - 1; + } + } + + return false; + } +} diff --git a/[0074][Search A 2D Matrix]/src/Solution2.java b/[0074][Search A 2D Matrix]/src/Solution2.java new file mode 100644 index 0000000..0a5ed46 --- /dev/null +++ b/[0074][Search A 2D Matrix]/src/Solution2.java @@ -0,0 +1,88 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 19:36 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + /** + *
+     * ԭ
+     * Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:
+     * Integers in each row are sorted from left to right.
+     * The first integer of each row is greater than the last integer of the previous row.
+     * For example,
+     * Consider the following matrix:Given target = 3, return true.
+     *
+     * [
+     *  [1,   3,  5,  7],
+     *  [10, 11, 16, 20],
+     *  [23, 30, 34, 50]
+     * ]
+     *
+     * Ŀ
+     * һάʵһ㷨ھʵֿkھk
+     * ʣÿһÿһжźģÿһеĵһһеһ
+     *
+     * ˼·
+     * ⷨһö鿴㷨ҵڵУö㷨ڵСҵͷtrue򷵻false
+     * 
+ * + * @param matrix + * @param target + * @return + */ + public boolean searchMatrix(int[][] matrix, int target) { + + if (matrix == null || matrix.length == 0 || matrix[0].length == 0) { + return false; + } + + int row = matrix.length; + int column = matrix[0].length; + int low = 0; + int high = row - 1; + int mid = 0; + + // ҽڵ + while (low <= high) { + mid = low + (high - low) / 2; + + if (target < matrix[mid][column - 1]) { + high = mid - 1; + } else if (target > matrix[mid][column - 1]) { + low = mid + 1; + } else { + return true; + } + } + + // ڵλ + int targetRow = mid; + if (matrix[mid][column - 1] < target) { + targetRow++; + } + + // Ŀг޽ + if (targetRow >= row) { + return false; + } + + low = 0; + high = column - 1; + // ڵУҵtrueûзfalse + while (low <= high) { + mid = low + (high - low) / 2; + + if (target < matrix[targetRow][mid]) { + high = mid - 1; + } else if (target > matrix[targetRow][mid]) { + low = mid + 1; + } else { + return true; + } + } + + return false; + } +} diff --git a/[0075][Sort Colors]/[0075][Sort Colors].iml b/[0075][Sort Colors]/[0075][Sort Colors].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0075][Sort Colors]/[0075][Sort Colors].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0075][Sort Colors]/[0075][SortColors].iml b/[0075][Sort Colors]/[0075][SortColors].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0075][Sort Colors]/[0075][SortColors].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0075][Sort Colors]/src/Main.java b/[0075][Sort Colors]/src/Main.java new file mode 100644 index 0000000..a29defe --- /dev/null +++ b/[0075][Sort Colors]/src/Main.java @@ -0,0 +1,33 @@ +import org.junit.Test; + +import java.util.Arrays; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-19 14:52 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + int[] colors = {2, 0, 2, 1, 1, 0}; + solution.sortColors(colors); + System.out.println(Arrays.toString(colors)); + } + + @Test + public void test2() { + Solution solution = new Solution(); + int[] colors = {2, 0, 1}; + solution.sortColors(colors); + System.out.println(Arrays.toString(colors)); + } + + @Test + public void test3() { + Solution solution = new Solution(); + int[] colors = {0}; + solution.sortColors(colors); + System.out.println(Arrays.toString(colors)); + } +} diff --git a/[0075][Sort Colors]/src/Solution.java b/[0075][Sort Colors]/src/Solution.java new file mode 100644 index 0000000..2f930cc --- /dev/null +++ b/[0075][Sort Colors]/src/Solution.java @@ -0,0 +1,68 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 19:37 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Given an array with n objects colored red, white or blue, sort them so that objects
+     * of the same color are adjacent, with the colors in the order red, white and blue.
+     * Here, we will use the integers 0, 1, and 2 to represent the color red, white,
+     * and blue respectively.
+     * Note:
+     * You are not suppose to use the librarys sort function for this problem.
+     *
+     * Ŀ
+     * һ飬Ǻɫɫɫɫ򣬺죬ף
+     * ʹ012ֱ죬ף
+     * ע⣺ʹÿ⺯
+     *
+     * ˼·
+     * һֱ012ֵĴٽ鸳ֵ
+     * 
+ * + * @param nums + */ + public void sortColors(int[] nums) { + + if (nums == null) { + return; + } + + int[] count = new int[3]; + + for (int n : nums) { + count[n]++; + } + + int start = 0; + int end = 0; + for (int i = 0; i < count.length; i++) { + if (i == 0) { + start = 0; + } else { + start += count[i - 1]; + } + end += count[i]; + for (int j = start; j < end; j++) { + nums[j] = i; + } + } + + // ϶ĸĽ +// for (int i = 0; i < count[0]; i++) { +// nums[i] = 0; +// } +// +// for (int i = count[0]; i < count[0] + count[1]; i++) { +// nums[i] = 1; +// } +// +// for (int i = count[0] + count[1]; i < nums.length; i++) { +// nums[i] = 2; +// } + } +} diff --git a/[0075][Sort Colors]/src/Solution2.java b/[0075][Sort Colors]/src/Solution2.java new file mode 100644 index 0000000..ac7b270 --- /dev/null +++ b/[0075][Sort Colors]/src/Solution2.java @@ -0,0 +1,71 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 19:37 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + /** + *
+     * ԭ
+     * Given an array with n objects colored red, white or blue, sort them so that objects
+     * of the same color are adjacent, with the colors in the order red, white and blue.
+     * Here, we will use the integers 0, 1, and 2 to represent the color red, white,
+     * and blue respectively.
+     * Note:
+     * You are not suppose to use the librarys sort function for this problem.
+     *
+     * Ŀ
+     * һ飬Ǻɫɫɫɫ򣬺죬ף
+     * ʹ012ֱ죬ף
+     * ע⣺ʹÿ⺯
+     *
+     * ˼·
+     * ɨ裬¼1ĸĺ͡ɨԵó1Ŀt2Ŀ(sum-t)/2
+     * Եó0ĿӸ012Ŀٶֵ
+     * 
+ * + * @param A + */ + public void sortColors(int[] A) { + + if (A == null) { + return; + } + + // ͳ1ĸ + int count = 0; + + // ͳĺ + int sum = 0; + + for (int i : A) { + if (i == 1) { + count++; + } + + sum += i; + } + + // 2Ŀ + sum = (sum - count) / 2; + + // 1ʼֵλ + count = A.length - count - sum; + + // 2ʼֵλ + sum = A.length - sum; + + for (int i = 0; i < count; i++) { + A[i] = 0; + } + + for (int i = count; i < sum; i++) { + A[i] = 1; + } + + for (int i = sum; i < A.length; i++) { + A[i] = 2; + } + } +} diff --git a/[0077][Combinations]/[0077][Combinations].iml b/[0077][Combinations]/[0077][Combinations].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0077][Combinations]/[0077][Combinations].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0077][Combinations]/src/Main.java b/[0077][Combinations]/src/Main.java new file mode 100644 index 0000000..e4021a1 --- /dev/null +++ b/[0077][Combinations]/src/Main.java @@ -0,0 +1,15 @@ +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-19 19:04 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + + System.out.println(solution.combine(4, 2)); + } + +} diff --git a/[0077][Combinations]/src/Solution.java b/[0077][Combinations]/src/Solution.java new file mode 100644 index 0000000..7d055e8 --- /dev/null +++ b/[0077][Combinations]/src/Solution.java @@ -0,0 +1,62 @@ +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-08-21 + * Time: 19:39 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + + /** + *
+     * ԭ
+     * Given two integers n and k, return all possible combinations of k numbers out of 1  n.
+     * For example,
+     * If n = 4 and k = 2, a solution is:
+     *
+     * [
+     *  [2,4],
+     *  [3,4],
+     *  [2,3],
+     *  [1,2],
+     *  [1,3],
+     *  [1,4],
+     * ]
+     *
+     * Ŀ
+     * nk1-nkϡ
+     *
+     * ˼·
+     * ʹùŻ㷨
+     * 
+ * + * @param n + * @param k + * @return + */ + public List> combine(int n, int k) { + List> result = new LinkedList<>(); + List current = new LinkedList<>(); + + dfs(1, n, k, current, result); + + return result; + } + + private void dfs(int start, int end, int k, List current, List> result) { + if (k == current.size()) { + result.add(new LinkedList<>(current)); + return; + } + + for (int i = start; i <= end; i++) { + current.add(i); + dfs(i + 1, end, k, current, result); + current.remove((Integer) i); + } + } + + +} diff --git a/[0077][Combinations]/src/Solution2.java b/[0077][Combinations]/src/Solution2.java new file mode 100644 index 0000000..8e1fb2f --- /dev/null +++ b/[0077][Combinations]/src/Solution2.java @@ -0,0 +1,80 @@ +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-08-21 + * Time: 19:39 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + private List> result; + private List l; + + /** + *
+     * ԭ
+     * Given two integers n and k, return all possible combinations of k numbers out of 1  n.
+     * For example,
+     * If n = 4 and k = 2, a solution is:
+     *
+     * [
+     *  [2,4],
+     *  [3,4],
+     *  [2,3],
+     *  [1,2],
+     *  [1,3],
+     *  [1,4],
+     * ]
+     *
+     * Ŀ
+     * nk1-nkϡ
+     *
+     * ˼·
+     * õݹη⣬롣
+     * 
+ * + * @param n + * @param k + * @return + */ + public List> combine(int n, int k) { + result = new LinkedList<>(); + + if (n > 0 && k > 0 && n >= k) { + l = new LinkedList<>(); + combine(1, n, k); + } + + return result; + } + + /** + * + * + * @param start ѡʼλ + * @param end ѡĽλ + * @param num [start, end]ѡĿ + */ + private void combine(int start, int end, int num) { + + if (num == 0) { + List tmp = new ArrayList<>(); + for (Integer i : l) { + tmp.add(i); + } + + result.add(tmp); + return; + } + + // һѡֵ + int endFirst = end - num + 1; + for (int i = start; i <= endFirst; i++) { + l.add(i); + combine(i + 1, end, num - 1); + l.remove(new Integer(i)); + } + } +} diff --git a/[0078][Subsets]/[0078][Subsets].iml b/[0078][Subsets]/[0078][Subsets].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0078][Subsets]/[0078][Subsets].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0078][Subsets]/src/Main.java b/[0078][Subsets]/src/Main.java new file mode 100644 index 0000000..9295524 --- /dev/null +++ b/[0078][Subsets]/src/Main.java @@ -0,0 +1,16 @@ +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-19 16:27 + **/ +public class Main { + @Test + public void test1() { + int[] nums = {1, 2, 3}; + + Solution solution = new Solution(); + + System.out.println(solution.subsets(nums)); + } +} diff --git a/[0078][Subsets]/src/Solution.java b/[0078][Subsets]/src/Solution.java new file mode 100644 index 0000000..9db75ec --- /dev/null +++ b/[0078][Subsets]/src/Solution.java @@ -0,0 +1,71 @@ +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-08-21 + * Time: 19:41 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + + /** + *
+     * ԭ
+     * Given a set of distinct integers, nums, return all possible subsets.
+     * Note:
+     * Elements in a subset must be in non-descending order.
+     * The solution set must not contain duplicate subsets.
+     * For example,
+     * If nums = [1,2,3], a solution is:
+     *
+     * [
+     *  [3],
+     *  [1],
+     *  [2],
+     *  [1,2,3],
+     *  [1,3],
+     *  [2,3],
+     *  [1,2],
+     *  []
+     * ]
+     *
+     * Ŀ
+     * һֵͬ飬Ӽ
+     *
+     * ˼·
+     * ȶеԪؽȻʹùŻ
+     * 
+ * + * @param nums + * @return + */ + public List> subsets(int[] nums) { + List> result = new LinkedList<>(); + List curr = new LinkedList<>(); + if (nums != null) { + // S + Arrays.sort(nums); + dfs(nums, 0, result, curr); + } + + return result; + } + + private void dfs(int[] nums, int index, List> result, List curr) { + + + // ӵУ˵һµĽ + result.add(new LinkedList<>(curr)); + + + for (int j = index; j < nums.length; j++) { + // Ԫ + curr.add(nums[j]); + dfs(nums, j + 1, result, curr); + // ԭ + curr.remove((Integer) nums[j]); + } + } +} diff --git a/[0078][Subsets]/src/Solution2.java b/[0078][Subsets]/src/Solution2.java new file mode 100644 index 0000000..ce86399 --- /dev/null +++ b/[0078][Subsets]/src/Solution2.java @@ -0,0 +1,123 @@ +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-08-21 + * Time: 19:41 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + private List> result; + private List l; + private int[] set; + private int num; // setлҪѡԪظ + + /** + *
+     * ԭ
+     * Given a set of distinct integers, nums, return all possible subsets.
+     * Note:
+     * Elements in a subset must be in non-descending order.
+     * The solution set must not contain duplicate subsets.
+     * For example,
+     * If nums = [1,2,3], a solution is:
+     *
+     * [
+     *  [3],
+     *  [1],
+     *  [2],
+     *  [1,2,3],
+     *  [1,3],
+     *  [2,3],
+     *  [1,2],
+     *  []
+     * ]
+     *
+     * Ŀ
+     * һֵͬ飬Ӽ
+     *
+     * ˼·
+     * ȶеԪؽȻõݹη⡣
+     * 
+ * + * @param S + * @return + */ + public List> subsets(int[] S) { + result = new LinkedList<>(); + + if (S != null) { + l = new ArrayList<>(); + + // S + quickSort(S, 0, S.length - 1); + + set = S; + for (int i = 0; i <= S.length; i++) { + num = i; + subset(0); + } + } + + // գӿ + set = null; + l = null; + + return result; + } + + /** + * ԪظnumӼ + * + * @param start ʣҪѡnumԪУһС± + */ + public void subset(int start) { + if (num == 0) { + List tmp = new ArrayList<>(); + for (Integer i : l) { + tmp.add(i); + } + + result.add(tmp); + return; + } + + int endFirst = set.length - num; // ʣҪѡnumԪУһ± + for (int i = start; i <= endFirst; i++) { + l.add(set[i]); + num--; + subset(i + 1); + num++; + l.remove(new Integer(set[i])); + } + } + + private void quickSort(int[] arr, int lo, int hi) { + if (lo < hi) { + int mid = getMid(arr, lo, hi); + quickSort(arr, lo, mid - 1); + quickSort(arr, mid + 1, hi); + } + } + + private int getMid(int[] arr, int lo, int hi) { + int tmp = arr[lo]; + while (lo < hi) { + while (lo < hi && arr[hi] > tmp) { + hi--; + } + arr[lo] = arr[hi]; + + while (lo < hi && arr[lo] < tmp) { + lo++; + } + + arr[hi] = arr[lo]; + } + + arr[lo] = tmp; + return lo; + } +} diff --git a/[0078][Subsets]/src/Solution3.java b/[0078][Subsets]/src/Solution3.java new file mode 100644 index 0000000..4ad1f20 --- /dev/null +++ b/[0078][Subsets]/src/Solution3.java @@ -0,0 +1,86 @@ +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-08-21 + * Time: 19:41 + * Declaration: All Rights Reserved !!! + */ +public class Solution3 { + + /** + *
+     * ԭ
+     * Given a set of distinct integers, nums, return all possible subsets.
+     * Note:
+     * Elements in a subset must be in non-descending order.
+     * The solution set must not contain duplicate subsets.
+     * For example,
+     * If nums = [1,2,3], a solution is:
+     *
+     * [
+     *  [3],
+     *  [1],
+     *  [2],
+     *  [1,2,3],
+     *  [1,3],
+     *  [2,3],
+     *  [1,2],
+     *  []
+     * ]
+     *
+     * Ŀ
+     * һֵͬ飬Ӽ
+     *
+     * ˼·
+     * ȶеԪؽȻõݹη⡣
+     * 
+ * + * @param nums + * @return + */ + public List> subsets(int[] nums) { + List> result = new LinkedList<>(); + List curr = new LinkedList<>(); + if (nums != null) { + + // S + Arrays.sort(nums); + // iʾӼԪظ + for (int i = 0; i <= nums.length; i++) { + subset(nums, 0, i, result, curr); + } + } + + return result; + } + + /** + * ԪnӼ + * + * @param nums Ԫؼ + * @param idx ȡԪصʼλ + * @param n Ԫظ + * @param result + * @param curr ʱ + */ + private void subset(int[] nums, int idx, int n, List> result, List curr) { + + // Ѿĩβˣ˵һ + if (n == 0) { + result.add(new LinkedList<>(curr)); + return; + } + + // ûд꣬ݹ鴦һԪ + for (int i = idx; i < nums.length - n + 1; i++) { + curr.add(nums[i]); + subset(nums, i + 1, n - 1, result, curr); + curr.remove((Integer) nums[i]); + } + } + + +} diff --git a/[0079][Word Search]/[0079][Word Search].iml b/[0079][Word Search]/[0079][Word Search].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0079][Word Search]/[0079][Word Search].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0079][Word Search]/[0079][WordSearch].iml b/[0079][Word Search]/[0079][WordSearch].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0079][Word Search]/[0079][WordSearch].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0079][Word Search]/src/Main.java b/[0079][Word Search]/src/Main.java new file mode 100644 index 0000000..2491d90 --- /dev/null +++ b/[0079][Word Search]/src/Main.java @@ -0,0 +1,14 @@ +/** + * Author: + * Date: 2015-06-20 + * Time: 08:02 + * Declaration: All Rights Reserved !!! + */ +public class Main { + public static void main(String[] args) { + Solution solution = new Solution(); + System.out.println(solution.exist(new char[][]{ + "abc".toCharArray(),"aed".toCharArray(),"afg".toCharArray() + }, "abcdefg")); + } +} diff --git a/[0079][Word Search]/src/Solution.java b/[0079][Word Search]/src/Solution.java new file mode 100644 index 0000000..e510517 --- /dev/null +++ b/[0079][Word Search]/src/Solution.java @@ -0,0 +1,113 @@ +/** + * Author: + * Date: 2015-06-20 + * Time: 07:19 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Given a 2D board and a word, find if the word exists in the grid.
+     *
+     * The word can be constructed from letters of sequentially adjacent cell,
+     * where "adjacent" cells are those horizontally or vertically neighboring.
+     * The same letter cell may not be used more than once.
+     *
+     * For example,
+     * Given board =
+     * [
+     *      ["ABCE"],
+     *      ["SFCS"],
+     *      ["ADEE"]
+     * ]
+     * word = "ABCCED", -> returns true,
+     * word = "SEE", -> returns true,
+     * word = "ABCB", -> returns false.
+     *
+     * Ŀ⣺
+     * һboardַ󣬿Դһ㿪ʼҵķʽߣÿֻһΣ
+     * һ·߹ַڸַôtrue
+     *
+     * ˼·
+     * ÿһΪ㣬ʹûݷ
+     * 
+ * + * @param board + * @param word + * @return + */ + public boolean exist(char[][] board, String word) { + // עǼٶIJǺϷ + + // ʱǾ󣬳ʼֵĬϻΪfalse + boolean[][] visited = new boolean[board.length][board[0].length]; + + // ÿһλΪҵһ·ֹͣ + for (int i = 0; i < board.length; i++) { + for (int j = 0; j < board[0].length; j++) { + if (search(board, visited, i, j, word, new int[]{0})) { + return true; + } + } + } + + return false; + } + + /** + * @param board ַ + * @param visited ʱǾ + * @param row ʵк + * @param col ʵк + * @param word ƥַ + * @param idx ƥλãȡǸºֵԱ + * @return + */ + private boolean search(char[][] board, boolean[][] visited, int row, int col, String word, int[] idx) { + // λõִijȣ˵Ѿҵҵƥ + if (idx[0] == word.length()) { + return true; + } + + boolean hasPath = false; + // ǰλúϷ + if (check(board, visited, row, col, word, idx[0])) { + // λñʹ + visited[row][col] = true; + idx[0]++; + // ϣң£ĸ + hasPath = search(board, visited, row - 1, col, word, idx ) // + || search(board, visited, row, col + 1, word, idx) // + || search(board, visited, row + 1, col, word, idx) // + || search(board, visited, row, col - 1, word, idx); // + + + // ûҵ·ͻ + if (!hasPath) { + visited[row][col] = false; + idx[0]--; + } + } + + return hasPath; + } + + /** + * жʵλǷϷ + * + * @param board ַ + * @param visited ʱǾ + * @param row ʵк + * @param col ʵк + * @param word ƥַ + * @param idx ƥλ + * @return + */ + + public boolean check(char[][] board, boolean[][] visited, int row, int col, String word, int idx) { + return row >= 0 && row < board.length // кźϷ + && col >= 0 && col < board[0].length // кźϷ + && !visited[row][col] // ûбʹ + && board[row][col] == word.charAt(idx); // ַ + } +} diff --git a/[0080][Remove Duplicates from Sorted Array II]/[0080][Remove Duplicates from Sorted Array II].iml b/[0080][Remove Duplicates from Sorted Array II]/[0080][Remove Duplicates from Sorted Array II].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0080][Remove Duplicates from Sorted Array II]/[0080][Remove Duplicates from Sorted Array II].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0080][Remove Duplicates from Sorted Array II]/src/Main.java b/[0080][Remove Duplicates from Sorted Array II]/src/Main.java new file mode 100644 index 0000000..83f9e74 --- /dev/null +++ b/[0080][Remove Duplicates from Sorted Array II]/src/Main.java @@ -0,0 +1,15 @@ +import java.util.Arrays; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-12 22:29 + **/ +public class Main { + public static void main(String[] args) { + Solution solution = new Solution(); + int[] nums = {1, 1, 1, 2, 2, 3}; + int i = solution.removeDuplicates(nums); + System.out.println(i + ": "+ Arrays.toString(nums)); + + } +} diff --git a/[0080][Remove Duplicates from Sorted Array II]/src/Solution.java b/[0080][Remove Duplicates from Sorted Array II]/src/Solution.java new file mode 100644 index 0000000..9109816 --- /dev/null +++ b/[0080][Remove Duplicates from Sorted Array II]/src/Solution.java @@ -0,0 +1,24 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-12 22:29 + **/ +public class Solution { + public int removeDuplicates(int[] nums) { + if (nums == null) { + return 0; + } + if (nums.length < 3) { + return nums.length; + } + + int index = 2; + for (int i = 2; i < nums.length; i++) { + if (nums[index - 2] < nums[i] ) { + nums[index] = nums[i]; + index++; + } + } + + return index; + } +} diff --git a/[0080][Remove Duplicates from Sorted Array II]/src/Solution2.java b/[0080][Remove Duplicates from Sorted Array II]/src/Solution2.java new file mode 100644 index 0000000..c3e4f83 --- /dev/null +++ b/[0080][Remove Duplicates from Sorted Array II]/src/Solution2.java @@ -0,0 +1,24 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-12 22:53 + **/ +/** + * 删除重复出现的数字,使之最多出现两次 + */ +public class Solution2 { + public int removeDuplicates(int[] nums) { + int i = 0; + + // 处理每一个数字 + for (int n : nums) { + // i < 2 处理前两个数字 + // n > nums[i - 2]说明n不与nums[i - 2]重复,并且因为数组有序,那么必然n > nums[i - 2] + if (i < 2 || n > nums[i - 2]) { + nums[i++] = n; + } + } + + return i; + } +} + diff --git a/[0081][Search In Rotated Sorted Array II]/[0081][Search In Rotated Sorted Array II].iml b/[0081][Search In Rotated Sorted Array II]/[0081][Search In Rotated Sorted Array II].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0081][Search In Rotated Sorted Array II]/[0081][Search In Rotated Sorted Array II].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0081][Search In Rotated Sorted Array II]/src/Main.java b/[0081][Search In Rotated Sorted Array II]/src/Main.java new file mode 100644 index 0000000..be94e08 --- /dev/null +++ b/[0081][Search In Rotated Sorted Array II]/src/Main.java @@ -0,0 +1,13 @@ +/** + * Author: 王俊超 + * Date: 2015-06-21 + * Time: 16:38 + * Declaration: All Rights Reserved !!! + */ +public class Main { + public static void main(String[] args) { + Solution2 solution = new Solution2(); + System.out.println(solution.search(new int[]{1, 1, 3, 1}, 3)); + System.out.println(solution.search(new int[]{5, 1, 3}, 3)); + } +} diff --git a/[0081][Search In Rotated Sorted Array II]/src/Solution.java b/[0081][Search In Rotated Sorted Array II]/src/Solution.java new file mode 100644 index 0000000..3a86418 --- /dev/null +++ b/[0081][Search In Rotated Sorted Array II]/src/Solution.java @@ -0,0 +1,136 @@ +/** + * Author: + * Date: 2015-06-21 + * Time: 14:46 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Follow up for "Search in Rotated Sorted Array":
+     * What if duplicates are allowed?
+     * Would this affect the run-time complexity? How and why?
+     * Write a function to determine if a given target is in the array
+     *
+     * Ŀ⣺
+     * "תֵ"ĺеֵظ
+     * дһȷһֵǷ
+     * 
+ * @param nums + * @param target + * @return + */ + public boolean search(int[] nums, int target) { + if (nums != null && nums.length > 0) { + // СԪضӦ± + int minIndex = findMinIndex(nums); + + // ȫ + if (minIndex == 0) { + return binarySearch(nums, 0, nums.length - 1, target); + } + // ֲ, 4 5 6 7 8 9 0 1 2 3 + else { + // úͺһһԪȣضӦ± + if (nums[nums.length - 1] == target) { + return true; + } + // targetںһ + else if (nums[nums.length - 1] > target) { + return binarySearch(nums, minIndex, nums.length - 1, target); + } + // targetǰһ + else { + return binarySearch(nums, 0, minIndex - 1, target); + } + } + } + + return false; + } + + /** + * + * + * @param nums + * @param start ʼλ + * @param end λ + * @param target Ŀ + * @return trueҵfalseûҵ + */ + public boolean binarySearch(int[] nums, int start, int end, int target) { + + int mid; + while (start <= end) { + mid = start + ((end - start) >> 1); + + if (nums[mid] == target) { + return true; + } else if (nums[mid] > target) { + end = mid - 1; + } else { + start = mid + 1; + } + } + + return false; + } + + + public int findMinIndex(int[] nums) { + // У + if (nums == null || nums.length < 1) { + throw new IllegalArgumentException(); + } + + int lo = 0; + int hi = nums.length - 1; + int mid = 0; + + // ųȫ + while (nums[lo] >= nums[hi]) { + // ֻԪأغһ + if (hi - lo == 1) { + mid = hi; + break; + } + + mid = lo + ((hi - lo) >> 1); + + if (nums[mid] == nums[lo] && nums[mid] == nums[hi]) { + // ֻܲ˳ܲlo++hi--ķʽ + // Ϊloǰһһ + // hiҲǺһĵһ + return sequenceSearchMinIndex(nums, lo, hi); + } + + // midǰһ + if (nums[mid] >= nums[lo]) { + lo = mid; + } + // midںһ + else if (nums[mid] <= nums[hi]) { + hi = mid; + } + } + + return mid; + } + + /** + * ˳еСֵ±꣬nums鰴ijת + * + * @param nums + * @param start ʼλ + * @param end λ + * @return Сֵ± + */ + public int sequenceSearchMinIndex(int[] nums, int start, int end) { + for (int i = start; i < end; i++) { + if (nums[i] > nums[i + 1]) { + return i + 1; + } + } + return start; + } +} diff --git a/[0081][Search In Rotated Sorted Array II]/src/Solution2.java b/[0081][Search In Rotated Sorted Array II]/src/Solution2.java new file mode 100644 index 0000000..9e48b6c --- /dev/null +++ b/[0081][Search In Rotated Sorted Array II]/src/Solution2.java @@ -0,0 +1,56 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-13 06:19 + **/ +public class Solution2 { + /** + * 分析 + * 允许重复元素,则上一题中如果A[mid]>=A[left], 那么[left,mid] 为递增序列的假设就不能成立了,比 + * 如[1,3,1,1,1]。 + * 如果A[mid]>=A[left] 不能确定递增,那就把它拆分成两个条件: + * • 若A[mid]>A[left],则区间[left,mid] 一定递增 + * • 若A[mid]==A[left] 确定不了,那就l++,往下看一步即可。 + * + * @param nums + * @param target + * @return + */ + public boolean search(int[] nums, int target) { + if (nums == null || nums.length < 1) { + return false; + } + + int left = 0; + int right = nums.length - 1; + int mid; + while (left <= right) { + mid = left + (right - left) / 2; + if (nums[mid] == target) { + return true; + } + + // [left, mid]区间递增 + if (nums[left] < nums[mid]) { + // target在[nums[left], nums[mid]]之间 + if (nums[left] <= target && target < nums[mid]) { + right = mid - 1; + } else { + left = mid + 1; + } + } else if (nums[left] > nums[mid]) { // [mid, right]区间递增 + // target在[nums[mid], nums[right]]之间 + if (nums[mid] < target && target <= nums[right]) { + left = mid + 1; + } else { + right = mid - 1; + } + } else { + // 无法区分递增区间,向右移动一个位置 + left++; + } + } + + + return false; + } +} diff --git a/[0082][Remove Duplicates From Sorted List II]/[0082][Remove Duplicates From Sorted List II].iml b/[0082][Remove Duplicates From Sorted List II]/[0082][Remove Duplicates From Sorted List II].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0082][Remove Duplicates From Sorted List II]/[0082][Remove Duplicates From Sorted List II].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0082][Remove Duplicates From Sorted List II]/[0082][RemoveDuplicatesFromSortedListII].iml b/[0082][Remove Duplicates From Sorted List II]/[0082][RemoveDuplicatesFromSortedListII].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0082][Remove Duplicates From Sorted List II]/[0082][RemoveDuplicatesFromSortedListII].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0082][Remove Duplicates From Sorted List II]/src/ListNode.java b/[0082][Remove Duplicates From Sorted List II]/src/ListNode.java new file mode 100644 index 0000000..2afe199 --- /dev/null +++ b/[0082][Remove Duplicates From Sorted List II]/src/ListNode.java @@ -0,0 +1,14 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 19:43 + * Declaration: All Rights Reserved !!! + */ +public class ListNode { + int val; + ListNode next; + + ListNode(int v) { + val = v; + } +} diff --git a/[0082][Remove Duplicates From Sorted List II]/src/Solution.java b/[0082][Remove Duplicates From Sorted List II]/src/Solution.java new file mode 100644 index 0000000..8e69cf6 --- /dev/null +++ b/[0082][Remove Duplicates From Sorted List II]/src/Solution.java @@ -0,0 +1,80 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 19:43 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Given a sorted linked list, delete all nodes that have duplicate numbers,
+     * leaving only distinct numbers from the original list.
+     * For example,
+     * Given 1->2->3->3->4->4->5, return 1->2->5.
+     * Given 1->1->1->2->3, return 2->3.
+     *
+     * Ŀ
+     * һźĵɾظԪءֻֻһֵԪء
+     *
+     * ˼·
+     * һrootrootӵԭͷͷ͸ָ룬صԪؽɾ
+     * 
+ * + * @param head + * @return + */ + public ListNode deleteDuplicates(ListNode head) { + + // ͷ + ListNode root = new ListNode(0); + root.next = head; + ListNode p = head; + // ¼һûظԪأʼָͷ + ListNode q = root; + + // Ԫظ + int delta = 0; + + while (p != null && p.next != null) { + // ͬ + if (p.val == p.next.val) { + delta++; + // ƶһ + p = p.next; + } + // 㲻ͬ + else { + // ֵΪp.valĽûظ + if (delta == 0) { + // ӵûиԪ + q.next = p; + // ָһδظԪ + q = p; + // ƶһ + p = p.next; + } + // ֵΪp.valĽظ + else { + // ƶһԪ + p = p.next; + // ȥظԪ + q.next = p.next; + // ԪظΪ0 + delta = 0; + } + } + } + + // һԪǸľȥ + if (delta != 0) { + q.next = null; + } + // ûظͿӵβ + else { + q.next = p; + } + + return root.next; + } +} diff --git a/[0083][Remove Duplicates From Sorted List]/[0083][Remove Duplicates From Sorted List].iml b/[0083][Remove Duplicates From Sorted List]/[0083][Remove Duplicates From Sorted List].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0083][Remove Duplicates From Sorted List]/[0083][Remove Duplicates From Sorted List].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0083][Remove Duplicates From Sorted List]/src/ListNode.java b/[0083][Remove Duplicates From Sorted List]/src/ListNode.java new file mode 100644 index 0000000..a9499a6 --- /dev/null +++ b/[0083][Remove Duplicates From Sorted List]/src/ListNode.java @@ -0,0 +1,15 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 19:46 + * Declaration: All Rights Reserved !!! + */ +public class ListNode { + int val; + ListNode next; + + ListNode(int x) { + val = x; + next = null; + } +} diff --git a/[0083][Remove Duplicates From Sorted List]/src/Solution.java b/[0083][Remove Duplicates From Sorted List]/src/Solution.java new file mode 100644 index 0000000..97b28f2 --- /dev/null +++ b/[0083][Remove Duplicates From Sorted List]/src/Solution.java @@ -0,0 +1,55 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 19:45 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Given a sorted linked list, delete all duplicates such that each element appear only once.
+     * For example,
+     * Given 1->1->2, return 1->2.
+     * Given 1->1->2->3->3, return 1->2->3.
+     *
+     * Ŀ
+     * һɾظԪأֻͬһ
+     *
+     * ˼·
+     * ʹһָָͷһ뵱ǰĽɾֱһͬģָָ
+     * µĽ㣬ظֱеĽ㶼ꡣ
+     * 
+ * + * @param head + * @return + */ + public ListNode deleteDuplicates(ListNode head) { + ListNode point; + // ָ½βʼʱֻһԪأͷ + ListNode tail = head; + + if (head != null) { + // ָͷһԪ + point = head.next; + // δĩβ + while (point != null) { + + // βڵ㲻ͬͽͬĽڵӵtailһλ + if (tail.val != point.val) { + tail.next = point; + // ָβ + tail = tail.next; + } + + // ƶһλ + point = point.next; + } + + // βָ + tail.next = null; + } + + return head; + } +} diff --git a/[0084][Largest Rectangle in Histogram]/[0084][Largest Rectangle in Histogram].iml b/[0084][Largest Rectangle in Histogram]/[0084][Largest Rectangle in Histogram].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0084][Largest Rectangle in Histogram]/[0084][Largest Rectangle in Histogram].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0084][Largest Rectangle in Histogram]/src/Solution.java b/[0084][Largest Rectangle in Histogram]/src/Solution.java new file mode 100644 index 0000000..72f516d --- /dev/null +++ b/[0084][Largest Rectangle in Histogram]/src/Solution.java @@ -0,0 +1,71 @@ +import java.util.Arrays; +import java.util.Deque; +import java.util.LinkedList; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-17 15:29 + **/ +public class Solution { + /** + *
+     * Given n non-negative integers representing the histogram's bar height where the width
+     * of each bar is 1, find the area of largest rectangle in the histogram.
+     *
+     *
+     *    -
+     *   --
+     *   --
+     *   -- -
+     * - ----
+     * ------
+     * Above is a histogram where width of each bar is 1, given height = [2,1,5,6,2,3].
+     * The largest rectangle is shown in the shaded area, which has area = 10 unit.
+     *    -
+     *   ==
+     *   ==
+     *   == -
+     * - ==--
+     * --==--
+     * Example:
+     * Input: [2,1,5,6,2,3]
+     * Output: 10
+     *
+     * https://leetcode.com/problems/largest-rectangle-in-histogram/
+     * 
+ */ + public int largestRectangleArea(int[] heights) { + if (heights == null || heights.length < 1) { + return 0; + } + // 记录位置 + Deque stack = new LinkedList<>(); + + int i = 0; + int result = 0; + + // 复制数组,最后位置补0,方便计算 + int[] h = Arrays.copyOf(heights, heights.length + 1); + + while (i < h.length) { + // 之前的元素小于等于当前元素 + if (stack.isEmpty() || h[stack.peek()] <= h[i]) { + // 当前元素入栈 + stack.push(i); + i++; + } else { + // 栈顶元素位置出栈 + int t = stack.pop(); + // 高度是height[t] + // stack.isEmpty(): 说明栈里的所有元素都比height[i]大,i位置之前有i个元素,序列就是[0 ,1, ..., i-1] + // 所求的长度就是i + // stack不为空,说明计算的位置是[stack.peek(), ..., i-1] 长度 + result = Math.max(result, h[t] * (stack.isEmpty() ? i : i - stack.peek() - 1)); + } + } + + + return result; + + } +} diff --git a/[0086][Partition List]/[0086][Partition List].iml b/[0086][Partition List]/[0086][Partition List].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0086][Partition List]/[0086][Partition List].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0086][Partition List]/[0086][PartitionList].iml b/[0086][Partition List]/[0086][PartitionList].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0086][Partition List]/[0086][PartitionList].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0086][Partition List]/src/ListNode.java b/[0086][Partition List]/src/ListNode.java new file mode 100644 index 0000000..b0946e7 --- /dev/null +++ b/[0086][Partition List]/src/ListNode.java @@ -0,0 +1,11 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 17:18 + * Declaration: All Rights Reserved !!! + */ +public class ListNode { + int val; + ListNode next; + ListNode(int x) { val = x; } +} diff --git a/[0086][Partition List]/src/Solution.java b/[0086][Partition List]/src/Solution.java new file mode 100644 index 0000000..c241a4b --- /dev/null +++ b/[0086][Partition List]/src/Solution.java @@ -0,0 +1,64 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 17:18 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Given a linked list and a value x, partition it such that all nodes less
+     * than x come before nodes greater than or equal to x.
+     * You should preserve the original relative order of the nodes in each of
+     * the two partitions.
+     *
+     * For example,
+     * Given 1->4->3->2->5->2 and x = 3,
+     * return 1->2->2->4->3->5.
+     *
+     * Ŀ
+     * һһֵxֳСڵxIJֺʹxIJ֡ͬʱԭ˳
+     *
+     * ˼·
+     * abԭеÿ㣬СڵxĽaĩβǴھͷb
+     * ĩβbͷӵaĩβ
+     * 
+ * + * @param head + * @param x + * @return + */ + public ListNode partition(ListNode head, int x) { + + ListNode le = new ListNode(0); // Сx + ListNode ge = new ListNode(0); // ڵx + ListNode t1 = le; + ListNode t2 = ge; + ListNode p = head; + + while (p != null) { + if (p.val < x) { + t1.next = p; + t1 = p; + } else { + t2.next = p; + t2 = p; + } + p = p.next; + } + + t2.next = null; + + // пt1û + // t1ƶ˵Сڵ + if (t1 != le) { + t1.next = ge.next; + head = le.next; + } else { + head = ge.next; + } + + return head; + } +} diff --git a/[0088][Merge Sorted Array]/[0088][Merge Sorted Array].iml b/[0088][Merge Sorted Array]/[0088][Merge Sorted Array].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0088][Merge Sorted Array]/[0088][Merge Sorted Array].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0088][Merge Sorted Array]/src/Solution.java b/[0088][Merge Sorted Array]/src/Solution.java new file mode 100644 index 0000000..d25ea04 --- /dev/null +++ b/[0088][Merge Sorted Array]/src/Solution.java @@ -0,0 +1,51 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 17:20 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.
+     * Note:
+     * You may assume that nums1 has enough space (size that is greater or equal to m + n) to
+     * hold additional elements from nums2. The number of elements initialized in nums1 and
+     * nums2 are m and n respectively.
+     *
+     * Ŀ
+     * 飬кϲϲҲģϲnums1С
+     * nums1㹻Ŀռnums2
+     *
+     * ˼·
+     * еһλÿʼкϲнϴƶλãǸ
+     * λֵǰƶһλãٽͬIJֱеԪشꡣ
+     * 
+ * + * @param arr + * @param m + * @param brr + * @param n + */ + public void merge(int arr[], int m, int brr[], int n) { + int pa = m - 1; + int pb = n - 1; + int index = m + n - 1; + + while (pa >= 0 && pb >= 0) { + if (arr[pa] >= brr[pb]) { + arr[index--] = arr[pa--]; + } else { + arr[index--] = brr[pb--]; + } + } + + // ˵paһΪ0 + while (pb >= 0) { + arr[index--] = brr[pb--]; + } + + // pa >= 0˵[0, pa]ûнжϣΪ[0, pa]arrУԲҪƶ + } +} diff --git a/[0089][Gray Code]/[0089][Gray Code].iml b/[0089][Gray Code]/[0089][Gray Code].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0089][Gray Code]/[0089][Gray Code].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0089][Gray Code]/src/Main.java b/[0089][Gray Code]/src/Main.java new file mode 100644 index 0000000..ba43581 --- /dev/null +++ b/[0089][Gray Code]/src/Main.java @@ -0,0 +1,18 @@ +import java.util.List; + +/** + * Author: + * Date: 2015-06-22 + * Time: 13:27 + * Declaration: All Rights Reserved !!! + */ +public class Main { + public static void main(String[] args) { + Solution solution = new Solution(); + List result = solution.grayCode(2); + + for (Integer i: result) { + System.out.printf("%s\n", Integer.toBinaryString(i)); + } + } +} diff --git a/[0089][Gray Code]/src/Solution.java b/[0089][Gray Code]/src/Solution.java new file mode 100644 index 0000000..4af4a3c --- /dev/null +++ b/[0089][Gray Code]/src/Solution.java @@ -0,0 +1,82 @@ +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-06-22 + * Time: 13:16 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * The nums[c] is a binary numeral system where two successive values differ in only one bit.
+     * Given a non-negative integer n representing the total number of bits in the code, print the
+     * sequence of gray code. A gray code sequence must begin with 0.
+     *
+     * For example, given n = 2, return [0,1,3,2]. Its gray code sequence is:
+     * 00 - 0
+     * 01 - 1
+     * 11 - 3
+     * 10 - 2
+     *
+     * Note:
+     *   - For a given n, a gray code sequence is not uniquely defined.
+     *   - For example, [0,2,3,1] is also a valid gray code sequence according to the above
+     *          definition.
+     *   - For now, the judge is able to judge based on one instance of gray code sequence.
+     *          Sorry about that.
+     *
+     * Ŀ⣺
+     * nΪnĸ
+     *
+     * (Gray Code) Ķοhttp://en.wikipedia.org/wiki/Gray_code
+     * ȻתΪ룺g0 = b0; gi = bi^b(i-1)
+     * ȻλΪλθλΪĸλθλ
+     * λθλơ磬Ȼ1001תΪĹǣ
+     * λȻ󽫵1 λ1 ͵2 λ0 򣬵õ1Ϊĵ2 λ2 λ0 ͵3 λ
+     * 0 򣬵õ0Ϊĵ3 λ3 λ0 ͵4 λ1 򣬵õ1Ϊ
+     * 4 λգΪ1101
+     * תΪȻ룺b0 = g0; bi = gi^b(i-1)
+     * λΪȻλθλΪȻƸλθλ
+     * λθλơ磬1000 תΪȻĹǣ
+     * λ1ΪȻλȻȻĵ1 λ1 ͸ĵ2 λ0 򣬵
+     * 1ΪȻĵ2 λȻĵ2 λ1 ͸ĵ3 λ0 򣬵õ1
+     * ΪȻĵ3 λȻĵ3 λ1 ͸ĵ4 λ0 򣬵õ1Ϊ
+     * Ȼĵ4 λգȻΪ1111
+     * ѧʽn ĸn^(n/2)
+     * Ҫn صи롣
+     * 1򵥵ķѧʽԴ0 ~2^n-1 תΪ롣
+     * 2nصĸ룬Եݹشn - 1 صĸɡ
+     *
+     * ˼·
+     * ݹ
+     *  ַڸǷʵõݹ¹죺
+     *  1λ
+     *  (n+1)λеǰ2^nֵnλ֣˳дǰ׺0
+     *  (n+1)λеĺ2^nֵnλ֣дǰ׺1
+     * 
+ * + * @param n + * @return + */ + public List grayCode(int n) { + List result = new LinkedList<>(); + if (n >= 0) { + // ǰ벿 + result.add(0); + // λֵ0ʱ + int t = 1; + // ÿһѭλi+1λĸ൱ڳΪi+1λĸǰ벿 + for (int i = 0; i < n; i++) { + // ijΪi+1λĺ벿֣ǰ벿ɳΪiλĸ + for (int j = result.size() - 1; j >= 0; j--) { + result.add(result.get(j) ^ t); + } + // λ + t <<= 1; + } + } + return result; + } +} diff --git a/[0090][Subsets II]/[0090][Subsets II].iml b/[0090][Subsets II]/[0090][Subsets II].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0090][Subsets II]/[0090][Subsets II].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0090][Subsets II]/src/Main.java b/[0090][Subsets II]/src/Main.java new file mode 100644 index 0000000..c656a4c --- /dev/null +++ b/[0090][Subsets II]/src/Main.java @@ -0,0 +1,23 @@ +import org.junit.Test; + +import java.util.Arrays; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-19 17:33 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + int[] nums = {1, 2, 2}; + System.out.println(solution.subsetsWithDup(nums)); + } + + @Test + public void test2() { + Solution solution = new Solution(); + int[] nums = {1, 2, 2}; + System.out.println(solution.subsetsWithDup(nums)); + } +} diff --git a/[0090][Subsets II]/src/Solution.java b/[0090][Subsets II]/src/Solution.java new file mode 100644 index 0000000..7593613 --- /dev/null +++ b/[0090][Subsets II]/src/Solution.java @@ -0,0 +1,66 @@ +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-19 16:43 + **/ +public class Solution { + + /** + *
+     * Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set).
+     *
+     * Note: The solution set must not contain duplicate subsets.
+     *
+     * Example:
+     *
+     * Input: [1,2,2]
+     * Output:
+     * [
+     *   [2],
+     *   [1],
+     *   [1,2,2],
+     *   [2,2],
+     *   [1,2],
+     *   []
+     * ]
+     * 
+ * + * @param nums + * @return + */ + public List> subsetsWithDup(int[] nums) { + List> result = new LinkedList<>(); + List curr = new LinkedList<>(); + if (nums != null) { + // 对S进行排序处理 + Arrays.sort(nums); + dfs(nums, 0, result, curr); + } + + return result; + } + + private void dfs(int[] nums, int index, List> result, List curr) { + + + // 添加到结果中,说明有一种新的结产生 + result.add(new LinkedList<>(curr)); + + + for (int j = index; j < nums.length; j++) { + // 在当前可选择的范围内,相同的只能选择一次 + if (j > index && nums[j] == nums[j - 1]) { + continue; + } + + // 添加元素 + curr.add(nums[j]); + dfs(nums, j + 1, result, curr); + // 还原 + curr.remove((Integer) nums[j]); + } + } +} diff --git a/[0092][Reverse Linked List II]/[0092][Reverse Linked List II].iml b/[0092][Reverse Linked List II]/[0092][Reverse Linked List II].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0092][Reverse Linked List II]/[0092][Reverse Linked List II].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0092][Reverse Linked List II]/src/ListNode.java b/[0092][Reverse Linked List II]/src/ListNode.java new file mode 100644 index 0000000..69ec703 --- /dev/null +++ b/[0092][Reverse Linked List II]/src/ListNode.java @@ -0,0 +1,11 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 17:23 + * Declaration: All Rights Reserved !!! + */ +public class ListNode { + int val; + ListNode next; + ListNode(int x) { val = x; } +} diff --git a/[0092][Reverse Linked List II]/src/Solution.java b/[0092][Reverse Linked List II]/src/Solution.java new file mode 100644 index 0000000..e1a7587 --- /dev/null +++ b/[0092][Reverse Linked List II]/src/Solution.java @@ -0,0 +1,70 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 17:23 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Reverse a linked list from position m to n. Do it in-place and in one-pass.
+     * For example:
+     * Given 1->2->3->4->5->NULL, m = 2 and n = 4,
+     * return 1->4->3->2->5->NULL.
+     * Note:
+     * Given m, n satisfy the following condition:
+     * 1  m  n  length of list.
+     *
+     * Ŀ
+     * һmn֮Ԫؽת
+     * nmǺϷģʹԭطнʹóռ䣩
+     *
+     * ˼·
+     * ҵһҪתԪصǰprevټҪзתԪظԪؽͷ巨
+     * prev棬ͬʱϿ
+     * 
+ * + * @param head + * @param m + * @param n + * @return + */ + public ListNode reverseBetween(ListNode head, int m, int n) { + + ListNode root = new ListNode(0); + ListNode p = root; + root.next = head; + + for (int i = 1; i < m && p != null; i++) { + p = p.next; + } + + if (p != null) { + ListNode q = p.next; + ListNode r; + + // mΪΪǴӵһʼ + if (m < 1) { + m = 1; + } + + // nΪҪĽĿ + n = n - m + 1; + // ʱҪʹβ巨βĸΪn-1 + for (int i = 1; i < n && q.next != null; i++) { + // ΪҪβĽ + r = q.next; + + // qĺβ + q.next = r.next; + r.next = p.next; + p.next = r; + } + + head = root.next; + } + + return head; + } +} diff --git a/[0093][Restore IP Addresses]/[0093][Restore IP Addresses].iml b/[0093][Restore IP Addresses]/[0093][Restore IP Addresses].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0093][Restore IP Addresses]/[0093][Restore IP Addresses].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0093][Restore IP Addresses]/src/Solution.java b/[0093][Restore IP Addresses]/src/Solution.java new file mode 100644 index 0000000..ad998bc --- /dev/null +++ b/[0093][Restore IP Addresses]/src/Solution.java @@ -0,0 +1,32 @@ +import java.util.ArrayList; +import java.util.List; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-23 06:48 + **/ +public class Solution { + public List restoreIpAddresses(String s) { + List result = new ArrayList<>(); + doRestore(result, "", s, 0); + return result; + } + + private void doRestore(List result, String path, String s, int k) { + if (s.isEmpty() || k == 4) { + if (s.isEmpty() && k == 4) { + result.add(path.substring(1)); + } + return; + } + + int length = (s.charAt(0) == '0' ? 1 : 3); // 避免前导0 + length = length < s.length() ? length : s.length(); + for (int i = 1; i <= length; i++) { + String part = s.substring(0, i); + if (Integer.valueOf(part) <= 255) { + doRestore(result, path + "." + part, s.substring(i), k + 1); + } + } + } +} diff --git a/[0094][Binary Tree Inorder Traversal]/[0094][Binary Tree Inorder Traversal].iml b/[0094][Binary Tree Inorder Traversal]/[0094][Binary Tree Inorder Traversal].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0094][Binary Tree Inorder Traversal]/[0094][Binary Tree Inorder Traversal].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0094][Binary Tree Inorder Traversal]/[0094][BinaryTree InorderTraversal].iml b/[0094][Binary Tree Inorder Traversal]/[0094][BinaryTree InorderTraversal].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0094][Binary Tree Inorder Traversal]/[0094][BinaryTree InorderTraversal].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0094][Binary Tree Inorder Traversal]/src/Main.java b/[0094][Binary Tree Inorder Traversal]/src/Main.java new file mode 100644 index 0000000..c5cc83f --- /dev/null +++ b/[0094][Binary Tree Inorder Traversal]/src/Main.java @@ -0,0 +1,22 @@ +import java.util.List; + +/** + * Author: + * Date: 2015-07-25 + * Time: 18:33 + * Declaration: All Rights Reserved !!! + */ +public class Main { + public static void main(String[] args) { + TreeNode n1 = new TreeNode(1); + TreeNode n2 = new TreeNode(2); + TreeNode n3 = new TreeNode(3); + + n1.left = n2; + n1.right = n3; + + Solution solution = new Solution(); + List result = solution.inorderTraversal(n1); + System.out.println(result); + } +} diff --git a/[0094][Binary Tree Inorder Traversal]/src/Solution.java b/[0094][Binary Tree Inorder Traversal]/src/Solution.java new file mode 100644 index 0000000..c1cffb9 --- /dev/null +++ b/[0094][Binary Tree Inorder Traversal]/src/Solution.java @@ -0,0 +1,37 @@ +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-07-25 + * Time: 18:19 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + public List inorderTraversal(TreeNode root) { + + List result = new LinkedList<>(); + LinkedList stack = new LinkedList<>(); + TreeNode node = root; + + + // node1root㣬2Һ + while (node != null || !stack.isEmpty()) { + // ջ + while (node != null) { + stack.addLast(node); + node = node.left; + } + + // ʱջеջԪһûӵ + if (!stack.isEmpty()) { + // ɾջԪ + node = stack.removeLast(); + result.add(node.val); + // ָҺ + node = node.right; + } + } + return result; + } +} diff --git a/[0094][Binary Tree Inorder Traversal]/src/TreeNode.java b/[0094][Binary Tree Inorder Traversal]/src/TreeNode.java new file mode 100644 index 0000000..bb8c0d2 --- /dev/null +++ b/[0094][Binary Tree Inorder Traversal]/src/TreeNode.java @@ -0,0 +1,15 @@ +/** + * Author: + * Date: 2015-07-25 + * Time: 18:19 + * Declaration: All Rights Reserved !!! + */ +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} \ No newline at end of file diff --git a/[0096][Unique Binary Search Trees]/[0096][Unique Binary Search Trees].iml b/[0096][Unique Binary Search Trees]/[0096][Unique Binary Search Trees].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0096][Unique Binary Search Trees]/[0096][Unique Binary Search Trees].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0096][Unique Binary Search Trees]/src/Main.java b/[0096][Unique Binary Search Trees]/src/Main.java new file mode 100644 index 0000000..71f13cf --- /dev/null +++ b/[0096][Unique Binary Search Trees]/src/Main.java @@ -0,0 +1,16 @@ +/** + * Author: + * Date: 2015-06-18 + * Time: 17:40 + * Declaration: All Rights Reserved !!! + */ +public class Main { + public static void main(String[] args) { + Solution solution = new Solution(); + System.out.println(solution.numTrees(0)); + System.out.println(solution.numTrees(1)); + System.out.println(solution.numTrees(2)); + System.out.println(solution.numTrees(3)); + System.out.println(solution.numTrees(4)); + } +} diff --git a/[0096][Unique Binary Search Trees]/src/Solution.java b/[0096][Unique Binary Search Trees]/src/Solution.java new file mode 100644 index 0000000..ab0f547 --- /dev/null +++ b/[0096][Unique Binary Search Trees]/src/Solution.java @@ -0,0 +1,49 @@ +/** + * Author: + * Date: 2015-06-18 + * Time: 17:36 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + * Given n, how many structurally unique BST's (binary search trees) that store values 1...n? + *

+ * For example, + * Given n = 3, there are a total of 5 unique BST's. + * 1 3 3 2 1 + * \ / / / \ \ + * 3 2 1 1 3 2 + * / / \ \ + * 2 1 2 3 + *

+ * ƹʽ + * f(0) = 1 + * f(1) = 1 + * f(i) = f(0)f(i-1) + f(1)f(i-1) + ... + f(i-1)f(0) + * + * @param n + * @return + */ + public int numTrees(int n) { + + if (n <= 0) { + return 1; + } else if (n == 1) { + return 1; + } + + int[] result = new int[n + 1]; + result[0] = 1; + result[1] = 1; + + + // f(2)...f(n) + for (int i = 2; i <= n; i++) { + for (int j = 1; j <= i; j++) { + result[i] += result[j - 1] * result[i - j]; + } + + } + return result[n]; + } +} diff --git a/[0096][Unique Binary Search Trees]/src/Solution2.java b/[0096][Unique Binary Search Trees]/src/Solution2.java new file mode 100644 index 0000000..753d48c --- /dev/null +++ b/[0096][Unique Binary Search Trees]/src/Solution2.java @@ -0,0 +1,51 @@ +/** + * Author: + * Date: 2015-06-18 + * Time: 17:36 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + /** + * Given n, how many structurally unique BST's (binary search trees) that store values 1...n? + * + * For example, + * Given n = 3, there are a total of 5 unique BST's. + * 1 3 3 2 1 + * \ / / / \ \ + * 3 2 1 1 3 2 + * / / \ \ + * 2 1 2 3 + * + * ƹʽ + * f(k)*f(n-1-k)f(k)ʾk㣬е״f(k)f(n-1-k)ʾn-1-k + * + * f(n) = 2*f(n-1) + f(1)*f(n-2) + f(2)f(n-3) + f(3)f(n-4) + ... +f(n-2)*f(1) + * + * @param n + * @return + */ + public int numTrees(int n) { + + if (n <= 0) { + return 1; + } else if (n == 1) { + return 1; + } + + int[] result = new int[n + 1]; + result[0] = 0; + result[1] = 1; + + + // f(2)...f(n) + for (int i = 2; i <= n; i++) { + // f(i) + result[i] = 2 * result[i - 1]; + for (int j = 1; j <= i - 1 ; j++) { + result[i] += result[j]*result[i - 1 -j]; + } + + } + return result[n]; + } +} diff --git a/[0098][Validate Binary Search Tree]/[0098][Validate Binary Search Tree].iml b/[0098][Validate Binary Search Tree]/[0098][Validate Binary Search Tree].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0098][Validate Binary Search Tree]/[0098][Validate Binary Search Tree].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0098][Validate Binary Search Tree]/[0098][ValidateBinarySearchTree].iml b/[0098][Validate Binary Search Tree]/[0098][ValidateBinarySearchTree].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0098][Validate Binary Search Tree]/[0098][ValidateBinarySearchTree].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0098][Validate Binary Search Tree]/src/Solution.java b/[0098][Validate Binary Search Tree]/src/Solution.java new file mode 100644 index 0000000..26ed700 --- /dev/null +++ b/[0098][Validate Binary Search Tree]/src/Solution.java @@ -0,0 +1,67 @@ +import java.util.Stack; + +/** + * Author: + * Date: 2015-08-21 + * Time: 18:37 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + private Stack stack; + + /** + *

+     * ԭ
+     * Given a binary tree, determine if it is a valid binary search tree (BST).
+     * Assume a BST is defined as follows:
+     * The left subtree of a node contains only nodes with keys less than the nodes key.
+     * The right subtree of a node contains only nodes with keys greater than the nodes key.
+     * Both the left and right subtrees must also be binary search trees.
+     *
+     * Ŀ
+     * ֤
+     *
+     * ˼·
+     * Զ˳򱣴ڶ
+     * һСеУûԪأɴ˿жһǷǶ
+     * 
+ * + * @param root + * @return + */ + public boolean isValidBST(TreeNode root) { + + if (root == null) { + return true; + } + + stack = new Stack<>(); + inOrder(root); + + int i = stack.pop(); + int j; + while (!stack.isEmpty()) { + j = stack.pop(); + if (i <= j) { + return false; + } + + i = j; + } + + return true; + } + + /** + * һöر + * + * @param root + */ + public void inOrder(TreeNode root) { + if (root != null) { + inOrder(root.left); + stack.push(root.val); + inOrder(root.right); + } + } +} diff --git a/[0098][Validate Binary Search Tree]/src/TreeNode.java b/[0098][Validate Binary Search Tree]/src/TreeNode.java new file mode 100644 index 0000000..c9e75e7 --- /dev/null +++ b/[0098][Validate Binary Search Tree]/src/TreeNode.java @@ -0,0 +1,15 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 18:38 + * Declaration: All Rights Reserved !!! + */ +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} diff --git a/[0100][Same Tree]/[0100][Same Tree].iml b/[0100][Same Tree]/[0100][Same Tree].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0100][Same Tree]/[0100][Same Tree].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0100][Same Tree]/[0100][SameTree].iml b/[0100][Same Tree]/[0100][SameTree].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0100][Same Tree]/[0100][SameTree].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0100][Same Tree]/src/Solution.java b/[0100][Same Tree]/src/Solution.java new file mode 100644 index 0000000..06cf0a2 --- /dev/null +++ b/[0100][Same Tree]/src/Solution.java @@ -0,0 +1,45 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 18:40 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Given two binary trees, write a function to check if they are equal or not.
+     * Two binary trees are considered equal if they are structurally identical and
+     * the nodes have the same value.
+     *
+     * Ŀ
+     * жǷȡ
+     * Ľṹֵͬʱȡ
+     *
+     * ˼·
+     * ʹõݹ⣬жϵǰֵǷȣȾٱȽ
+     * ֻееĽ㶼Ȳȡ
+     * 
+ * + * @param p + * @param q + * @return + */ + public boolean isSameTree(TreeNode p, TreeNode q) { + + if (p == null && q == null) { + return true; + } + + if (p != null && q == null) { + return false; + } + + if (p == null && q != null) { + return false; + } + + + return p.val == q.val && isSameTree(p.left, q.left) && isSameTree(p.right, q.right); + } +} diff --git a/[0100][Same Tree]/src/TreeNode.java b/[0100][Same Tree]/src/TreeNode.java new file mode 100644 index 0000000..58ea6f4 --- /dev/null +++ b/[0100][Same Tree]/src/TreeNode.java @@ -0,0 +1,12 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 18:40 + * Declaration: All Rights Reserved !!! + */ +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + TreeNode(int x) { val = x; } +} diff --git a/[0101][Symmetric Tree]/[0101][Symmetric Tree].iml b/[0101][Symmetric Tree]/[0101][Symmetric Tree].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0101][Symmetric Tree]/[0101][Symmetric Tree].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0101][Symmetric Tree]/[0101][SymmetricTree].iml b/[0101][Symmetric Tree]/[0101][SymmetricTree].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0101][Symmetric Tree]/[0101][SymmetricTree].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0101][Symmetric Tree]/src/Solution.java b/[0101][Symmetric Tree]/src/Solution.java new file mode 100644 index 0000000..d1be230 --- /dev/null +++ b/[0101][Symmetric Tree]/src/Solution.java @@ -0,0 +1,62 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 18:42 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
+     * For example, this binary tree is symmetric:
+     *
+     *     1
+     *    / \
+     *   2   2
+     *  / \ / \
+     * 3  4 4  3
+     *
+     * But the following is not:
+     *
+     *   1
+     *  / \
+     * 2   2
+     * \   \
+     * 3    3
+     *
+     * Note:
+     * Bonus points if you could solve it both recursively and iteratively.
+     * Ŀ
+     * һжǷǶԳƵġǷľ
+     *
+     * ˼·
+     * ʹõݹ⣬жӽǷȣȾͷfalseȾͽӽ
+     * ӽӽбȽϲͬʱӽӽбȽϣֻ
+     * ͬʱΪDzŷtrue򷵻false
+     * 
+ * + * @param root + * @return + */ + public boolean isSymmetric(TreeNode root) { + + if (root == null) { + return true; + } else { + return isSame(root.left, root.right); + } + } + + private boolean isSame(TreeNode left, TreeNode right) { + if (left == null && right == null) { + return true; + } + if (left != null && right == null || left == null && right != null) { + return false; + } else { + return left.val == right.val && isSame(left.left, right.right) + && isSame(left.right, right.left); + } + } +} diff --git a/[0101][Symmetric Tree]/src/TreeNode.java b/[0101][Symmetric Tree]/src/TreeNode.java new file mode 100644 index 0000000..6834d90 --- /dev/null +++ b/[0101][Symmetric Tree]/src/TreeNode.java @@ -0,0 +1,15 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 18:42 + * Declaration: All Rights Reserved !!! + */ +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} diff --git a/[0102][Binary Tree Level Order Traversal]/[0102][Binary Tree Level Order Traversal].iml b/[0102][Binary Tree Level Order Traversal]/[0102][Binary Tree Level Order Traversal].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0102][Binary Tree Level Order Traversal]/[0102][Binary Tree Level Order Traversal].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0102][Binary Tree Level Order Traversal]/[0102][BinaryTreeLevelOrderTraversal].iml b/[0102][Binary Tree Level Order Traversal]/[0102][BinaryTreeLevelOrderTraversal].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0102][Binary Tree Level Order Traversal]/[0102][BinaryTreeLevelOrderTraversal].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0102][Binary Tree Level Order Traversal]/src/Solution.java b/[0102][Binary Tree Level Order Traversal]/src/Solution.java new file mode 100644 index 0000000..0f940e9 --- /dev/null +++ b/[0102][Binary Tree Level Order Traversal]/src/Solution.java @@ -0,0 +1,83 @@ +import java.util.ArrayList; +import java.util.Deque; +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-08-21 + * Time: 18:44 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * 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,#,#,15,7},
+     *
+     *    3
+     *   / \
+     *  9  20
+     *    /  \
+     *   15   7
+     *
+     * return its level order traversal as:
+     *
+     * [
+     *  [3],
+     *  [9,20],
+     *  [15,7]
+     * ]
+     * Ŀ
+     * һÿһĽ㡣
+     *
+     * ˼·
+     * ʹУһ浱ǰIJ㣬һһҪIJ㡣ֻÿһ㶼ꡣ
+     * 
+ * + * @param root + * @return + */ + public List> levelOrder(TreeNode root) { + + List> result = new ArrayList<>(); + + if (root == null) { + return result; + } + + Deque cur = new LinkedList<>(); + Deque sub = new LinkedList<>(); + Deque exc; + + TreeNode node; + cur.addLast(root); + + while (!cur.isEmpty()) { + List layout = new LinkedList<>(); + while (!cur.isEmpty()) { + node = cur.removeFirst(); + layout.add(node.val); + + if (node.left != null) { + sub.addLast(node.left); + } + + if (node.right != null) { + sub.addLast(node.right); + } + } + + exc = cur; + cur = sub; + sub = exc; + + result.add(layout); + } + + return result; + } +} diff --git a/[0102][Binary Tree Level Order Traversal]/src/TreeNode.java b/[0102][Binary Tree Level Order Traversal]/src/TreeNode.java new file mode 100644 index 0000000..fa1fe26 --- /dev/null +++ b/[0102][Binary Tree Level Order Traversal]/src/TreeNode.java @@ -0,0 +1,15 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 18:45 + * Declaration: All Rights Reserved !!! + */ +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} diff --git a/[0103][Binary Tree Zigzag LevelOrder Traversal]/[0103][Binary Tree Zigzag LevelOrder Traversal].iml b/[0103][Binary Tree Zigzag LevelOrder Traversal]/[0103][Binary Tree Zigzag LevelOrder Traversal].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0103][Binary Tree Zigzag LevelOrder Traversal]/[0103][Binary Tree Zigzag LevelOrder Traversal].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0103][Binary Tree Zigzag LevelOrder Traversal]/[0103][BinaryTreeZigzagLevelOrderTraversal].iml b/[0103][Binary Tree Zigzag LevelOrder Traversal]/[0103][BinaryTreeZigzagLevelOrderTraversal].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0103][Binary Tree Zigzag LevelOrder Traversal]/[0103][BinaryTreeZigzagLevelOrderTraversal].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0103][Binary Tree Zigzag LevelOrder Traversal]/src/Main.java b/[0103][Binary Tree Zigzag LevelOrder Traversal]/src/Main.java new file mode 100644 index 0000000..a33d650 --- /dev/null +++ b/[0103][Binary Tree Zigzag LevelOrder Traversal]/src/Main.java @@ -0,0 +1,27 @@ +/** + * Author: + * Date: 2015-06-23 + * Time: 13:43 + * Declaration: All Rights Reserved !!! + */ +public class Main { + public static void main(String[] args) { + Solution solution = new Solution(); + TreeNode n1 = new TreeNode(1); + TreeNode n2 = new TreeNode(2); + TreeNode n3 = new TreeNode(3); + TreeNode n4 = new TreeNode(4); + TreeNode n5 = new TreeNode(5); + TreeNode n6 = new TreeNode(6); + TreeNode n7 = new TreeNode(7); + + n1.left = n2; + n1.right = n3; + n2.left = n4; + n3.right = n5; + n4.left = n6; + n5.right = n7; + + solution.zigzagLevelOrder(n1); + } +} diff --git a/[0103][Binary Tree Zigzag LevelOrder Traversal]/src/Solution.java b/[0103][Binary Tree Zigzag LevelOrder Traversal]/src/Solution.java new file mode 100644 index 0000000..9c60b4e --- /dev/null +++ b/[0103][Binary Tree Zigzag LevelOrder Traversal]/src/Solution.java @@ -0,0 +1,104 @@ +import java.util.Deque; +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-06-23 + * Time: 13:24 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Given a binary tree, return the zigzag level order traversal of its nodes' values.
+     * (ie, from left to right, then right to left for the next level and alternate between).
+     *
+     * For example:
+     * Given binary tree {3,9,20,#,#,15,7},
+     * 3
+     * / \
+     * 9  20
+     * /  \
+     * 15   7
+     * return its zigzag level order traversal as:
+     * [
+     *      [3],
+     *      [20,9],
+     *      [15,7]
+     * ]
+     *
+     * Ŀ⣺
+     * һöӶ£ZηֲǴҵģ²Ǵ
+     *
+     * ˼·
+     * ֲиĽʹջ
+     * 
+ * + * @param root + * @return + */ + public List> zigzagLevelOrder(TreeNode root) { + List> result = new LinkedList<>(); + + if (root == null) { + return result; + } + // ־0ʾң1ʾҵ + int flag = 0; + TreeNode node; + // ¼ÿһԪ + List lay = new LinkedList<>(); + // ˫Уջʹã¼ǰ + Deque stack = new LinkedList<>(); + // ¼һ + Deque nextStack = new LinkedList<>(); + + stack.add(root); + + while (!stack.isEmpty()) { + // ɾջԪ + node = stack.removeLast(); + + // + lay.add(node.val); + + // ǰǴұ˳ + if (flag == 0) { + if (node.left != null) { + nextStack.addLast(node.left); + } + + if (node.right != null) { + nextStack.addLast(node.right); + } + } + // ǰǴҵ˳ + else { + if (node.right != null) { + nextStack.addLast(node.right); + } + + if (node.left != null) { + nextStack.addLast(node.left); + } + } + + // ǰѾ + if (stack.isEmpty()) { + Deque temp = nextStack; + nextStack = stack; + stack = temp; + + // һ㴦ķ + flag = 1 - flag; + // 汾 + result.add(lay); + // µһĽ + lay = new LinkedList<>(); + } + } + + return result; + } +} diff --git a/[0103][Binary Tree Zigzag LevelOrder Traversal]/src/TreeNode.java b/[0103][Binary Tree Zigzag LevelOrder Traversal]/src/TreeNode.java new file mode 100644 index 0000000..efc9fd5 --- /dev/null +++ b/[0103][Binary Tree Zigzag LevelOrder Traversal]/src/TreeNode.java @@ -0,0 +1,15 @@ +/** + * Author: + * Date: 2015-06-23 + * Time: 13:25 + * Declaration: All Rights Reserved !!! + */ +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} diff --git a/[0104][Maximum Depth Of Binary Tree]/[0104][Maximum Depth Of Binary Tree].iml b/[0104][Maximum Depth Of Binary Tree]/[0104][Maximum Depth Of Binary Tree].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0104][Maximum Depth Of Binary Tree]/[0104][Maximum Depth Of Binary Tree].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0104][Maximum Depth Of Binary Tree]/src/Solution.java b/[0104][Maximum Depth Of Binary Tree]/src/Solution.java new file mode 100644 index 0000000..95106ad --- /dev/null +++ b/[0104][Maximum Depth Of Binary Tree]/src/Solution.java @@ -0,0 +1,38 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 18:47 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Given a binary tree, find its maximum depth.
+     * The maximum depth is the number of nodes along the longest path
+     * from the root node down to the farthest leaf node.
+     *
+     * Ŀ
+     * һȡ
+     *
+     * ˼·
+     * ݹ⣬ݹ鹫ʽ
+     * f(n) = 0; n=null,
+     * f(n) = 1+ max(f(n) f(n))
+     * 
+ * + * @param root + * @return + */ + public int maxDepth(TreeNode root) { + if (root == null) { + return 0; + } else if (root.left == null && root.right == null) { + return 1; + } else { + int left = maxDepth(root.left); + int right = maxDepth(root.right); + return 1 + (left > right ? left : right); + } + } +} diff --git a/[0104][Maximum Depth Of Binary Tree]/src/TreeNode.java b/[0104][Maximum Depth Of Binary Tree]/src/TreeNode.java new file mode 100644 index 0000000..9ab5aa7 --- /dev/null +++ b/[0104][Maximum Depth Of Binary Tree]/src/TreeNode.java @@ -0,0 +1,15 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 18:47 + * Declaration: All Rights Reserved !!! + */ +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} diff --git a/[0105][Construct Binary Tree From Preorder And Inorder Traversal]/[0105][Construct Binary Tree From Preorder And Inorder Traversal].iml b/[0105][Construct Binary Tree From Preorder And Inorder Traversal]/[0105][Construct Binary Tree From Preorder And Inorder Traversal].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0105][Construct Binary Tree From Preorder And Inorder Traversal]/[0105][Construct Binary Tree From Preorder And Inorder Traversal].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0105][Construct Binary Tree From Preorder And Inorder Traversal]/src/Solution.java b/[0105][Construct Binary Tree From Preorder And Inorder Traversal]/src/Solution.java new file mode 100644 index 0000000..5922420 --- /dev/null +++ b/[0105][Construct Binary Tree From Preorder And Inorder Traversal]/src/Solution.java @@ -0,0 +1,89 @@ +/** + * Author: + * Date: 2015-06-23 + * Time: 14:04 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Given preorder and inorder traversal of a tree, construct the binary tree.
+     *
+     * Note:
+     * You may assume that duplicates do not exist in the tree.
+     *
+     * Ŀ⣺
+     * һǰУһ
+     * ע⣺
+     *   - ԪظԪ
+     *
+     * ˼·
+     * ǰһԪǸ㣨kֵΪk±idx
+     * idxзֳǰҲһɽеݹ
+     * 
+ * + * @param preorder + * @param inorder + * @return + */ + public TreeNode buildTree(int[] preorder, int[] inorder) { + + // У + if (preorder == null || inorder == null || preorder.length == 0 || preorder.length != inorder.length) { + return null; + } + return solve(preorder, 0, preorder.length - 1, inorder, 0, inorder.length - 1); + } + + /** + * ȷԼ֤ + * + * @param preorder Ľ + * @param x Ŀʼλ + * @param y Ľλ + * @param inorder Ľ + * @param i Ŀʼλ + * @param j Ľλ + * @return ĸ + */ + public TreeNode solve(int[] preorder, int x, int y, int[] inorder, int i, int j) { + + if (x >= 0 && x <= y && i >= 0 && i <= j) { + // ֻһԪ + if (x == y) { + return new TreeNode(preorder[x]); + } + // xܴy + else if (x < y) { + // ¼ + int idx = i; + while (idx <= j && inorder[idx] != preorder[x]) { + idx++; + } + + // + TreeNode root = new TreeNode(inorder[idx]); + + // Ľ + //[i, i+1, ..., idx - 1] -> ܼidx - i + int leftLength = idx - i; + // + if (leftLength > 0) { + // x + 1, x + leftLengthʼͽλ + root.left = solve(preorder, x + 1, x + leftLength, inorder, i, idx - 1); + } + + // Ľ + // [idx+1, idx+2, ..., j] -> ܼƣj - idx + int rightLength = j - idx; + if (rightLength > 0) { + // x + leftLength + 1, yʼͽλ + root.right = solve(preorder, x + leftLength + 1, y, inorder, idx + 1, j); + } + return root; + } + } + + return null; + } +} diff --git a/[0105][Construct Binary Tree From Preorder And Inorder Traversal]/src/TreeNode.java b/[0105][Construct Binary Tree From Preorder And Inorder Traversal]/src/TreeNode.java new file mode 100644 index 0000000..c4a28e9 --- /dev/null +++ b/[0105][Construct Binary Tree From Preorder And Inorder Traversal]/src/TreeNode.java @@ -0,0 +1,15 @@ +/** + * Author: + * Date: 2015-06-23 + * Time: 14:04 + * Declaration: All Rights Reserved !!! + */ +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} diff --git a/[0106][Construct Binary Tree From Inorder And Postorder Traversal]/[0106][Construct Binary Tree From Inorder And Postorder Traversal].iml b/[0106][Construct Binary Tree From Inorder And Postorder Traversal]/[0106][Construct Binary Tree From Inorder And Postorder Traversal].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0106][Construct Binary Tree From Inorder And Postorder Traversal]/[0106][Construct Binary Tree From Inorder And Postorder Traversal].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0106][Construct Binary Tree From Inorder And Postorder Traversal]/src/Main.java b/[0106][Construct Binary Tree From Inorder And Postorder Traversal]/src/Main.java new file mode 100644 index 0000000..232e3c8 --- /dev/null +++ b/[0106][Construct Binary Tree From Inorder And Postorder Traversal]/src/Main.java @@ -0,0 +1,24 @@ +/** + * Author: + * Date: 2015-06-23 + * Time: 10:32 + * Declaration: All Rights Reserved !!! + */ +public class Main { + public static void main(String[] args) { + Solution solution = new Solution(); + int[] inorder = {1,2,3,4}; + int[] postorder = {3,2,4,1}; + + TreeNode root = solution.buildTree(inorder, postorder); + print(root); + } + + public static void print(TreeNode root) { + if (root != null) { + print(root.left); + System.out.print(root.val + " "); + print(root.right); + } + } +} diff --git a/[0106][Construct Binary Tree From Inorder And Postorder Traversal]/src/Solution.java b/[0106][Construct Binary Tree From Inorder And Postorder Traversal]/src/Solution.java new file mode 100644 index 0000000..83cccad --- /dev/null +++ b/[0106][Construct Binary Tree From Inorder And Postorder Traversal]/src/Solution.java @@ -0,0 +1,93 @@ + +/** + * Author: + * Date: 2015-06-23 + * Time: 10:05 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Given inorder and postorder traversal of a tree, construct the binary tree.
+     *
+     * Note:
+     * You may assume that duplicates do not exist in the tree.
+     *
+     * Ŀ⣺
+     * һͺУһö
+     * ע⣺
+     * ûظԪ
+     *
+     * ˼·
+     * һԪؾĸ(ֵΪr)
+     * ֵΪrλidxidxзΪ
+     * ӦԽзݹ
+     * 
+ * + * @param inorder + * @param postorder + * @return + */ + public TreeNode buildTree(int[] inorder, int[] postorder) { + + // + if (inorder == null || postorder == null || inorder.length == 0 || inorder.length != postorder.length) { + return null; + } + + // + return solve(inorder, 0, inorder.length - 1, postorder, 0, postorder.length - 1); + } + + /** + * + * + * @param inorder Ľ + * @param x Ŀʼλ + * @param y Ľλ + * @param postorder Ľ + * @param i Ŀʼλ + * @param j Ľλ + * @return + */ + public TreeNode solve(int[] inorder, int x, int y, int[] postorder, int i, int j) { + + if (x >= 0 && x <= y && i >= 0 && i <= j) { + // ֻһԪأʱҲi=jɣ + if (x == y) { + return new TreeNode(postorder[j]); + } + // һԪأʱҲi ܼ idx-x + int leftLength = idx - x; + if (leftLength > 0) { + // i, i + leftLength - 1ǰʼλ + root.left = solve(inorder, x, idx - 1, postorder, i, i + leftLength - 1); + } + + // ǿգ + // [idx+1, idx+2, ..., y] -> ܼ y-idx + int rightLength = y - idx; + if (rightLength > 0) { + // i + leftLength, j - 1ǰʼλ + root.right = solve(inorder, idx + 1, y, postorder, i + leftLength, j - 1); + } + + return root; + } + } + + return null; + } +} diff --git a/[0106][Construct Binary Tree From Inorder And Postorder Traversal]/src/TreeNode.java b/[0106][Construct Binary Tree From Inorder And Postorder Traversal]/src/TreeNode.java new file mode 100644 index 0000000..b25eb0f --- /dev/null +++ b/[0106][Construct Binary Tree From Inorder And Postorder Traversal]/src/TreeNode.java @@ -0,0 +1,15 @@ +/** + * Author: + * Date: 2015-06-23 + * Time: 10:05 + * Declaration: All Rights Reserved !!! + */ +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} diff --git a/[0107][Binary Tree Level Order Traversa lII]/[0107][Binary Tree Level Order Traversa lII].iml b/[0107][Binary Tree Level Order Traversa lII]/[0107][Binary Tree Level Order Traversa lII].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0107][Binary Tree Level Order Traversa lII]/[0107][Binary Tree Level Order Traversa lII].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0107][Binary Tree Level Order Traversa lII]/[0107][BinaryTreeLevelOrderTraversalII].iml b/[0107][Binary Tree Level Order Traversa lII]/[0107][BinaryTreeLevelOrderTraversalII].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0107][Binary Tree Level Order Traversa lII]/[0107][BinaryTreeLevelOrderTraversalII].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0107][Binary Tree Level Order Traversa lII]/src/Solution.java b/[0107][Binary Tree Level Order Traversa lII]/src/Solution.java new file mode 100644 index 0000000..02173b2 --- /dev/null +++ b/[0107][Binary Tree Level Order Traversa lII]/src/Solution.java @@ -0,0 +1,83 @@ +import java.util.ArrayList; +import java.util.Deque; +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-08-21 + * Time: 18:49 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Given a binary tree, return the bottom-up level order traversal of its nodes values.
+     * (ie, from left to right, level by level from leaf to root).
+     * For example:
+     * Given binary tree {3,9,20,#,#,15,7},
+     *
+     *     3
+     *    / \
+     *   9  20
+     *     /  \
+     *    15   7
+     * return its bottom-up level order traversal as:
+     *
+     * [
+     *  [15,7],
+     *  [9,20],
+     *  [3]
+     * ]
+     *
+     * Ŀ
+     * һöԵ½в
+     *
+     * ˼·
+     * вÿĽڽͷ
+     * 
+ * + * @param root + * @return + */ + public List> levelOrderBottom(TreeNode root) { + + List> list = new LinkedList<>(); + if (root == null) { + return list; + } + + Deque cur = new LinkedList<>(); + Deque nxt = new LinkedList<>(); + Deque exc = new LinkedList<>(); + + TreeNode tmp; + + cur.add(root); + while (!cur.isEmpty()) { + List layout = new ArrayList<>(); + + while (!cur.isEmpty()) { + tmp = cur.remove(); + + if (tmp.left != null) { + nxt.add(tmp.left); + } + + if (tmp.right != null) { + nxt.add(tmp.right); + } + + layout.add(tmp.val); + } + + exc = cur; + cur = nxt; + nxt = exc; + + list.add(0, layout); + } + + return list; + } +} diff --git a/[0107][Binary Tree Level Order Traversa lII]/src/TreeNode.java b/[0107][Binary Tree Level Order Traversa lII]/src/TreeNode.java new file mode 100644 index 0000000..ea4ddea --- /dev/null +++ b/[0107][Binary Tree Level Order Traversa lII]/src/TreeNode.java @@ -0,0 +1,15 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 18:49 + * Declaration: All Rights Reserved !!! + */ +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} diff --git a/[0108][Convert Sorted Array To Binary Search Tree]/[0108][Convert Sorted Array To Binary Search Tree].iml b/[0108][Convert Sorted Array To Binary Search Tree]/[0108][Convert Sorted Array To Binary Search Tree].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0108][Convert Sorted Array To Binary Search Tree]/[0108][Convert Sorted Array To Binary Search Tree].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0108][Convert Sorted Array To Binary Search Tree]/[0108][ConvertSortedArrayToBinarySearchTree].iml b/[0108][Convert Sorted Array To Binary Search Tree]/[0108][ConvertSortedArrayToBinarySearchTree].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0108][Convert Sorted Array To Binary Search Tree]/[0108][ConvertSortedArrayToBinarySearchTree].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0108][Convert Sorted Array To Binary Search Tree]/src/Solution.java b/[0108][Convert Sorted Array To Binary Search Tree]/src/Solution.java new file mode 100644 index 0000000..a123565 --- /dev/null +++ b/[0108][Convert Sorted Array To Binary Search Tree]/src/Solution.java @@ -0,0 +1,58 @@ +/** + * Author: + * Date: 2015-06-22 + * Time: 12:56 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Given an array where elements are sorted in ascending order,
+     * convert it to a height balanced BST.
+     *
+     * Ŀ⣺
+     * һ飬תһ߶ƽ
+     *
+     * ˼·
+     * õݹη
+     * 
+ * + * @param nums + * @return + */ + public TreeNode sortedArrayToBST(int[] nums) { + // + if (nums == null || nums.length < 1) { + return null; + } + + // ݹη + return solve(nums, 0, nums.length - 1); + } + + /** + * ݹⷽ + * + * @param nums + * @param start ʼλ + * @param end λ + * @return + */ + public TreeNode solve(int[] nums, int start, int end) { + // δ + if (start <= end) { + // Ҳλ + int mid = start + ((end - start) >> 1); + // + TreeNode root = new TreeNode(nums[mid]); + // + root.left = solve(nums, start, mid - 1); + // + root.right = solve(nums, mid + 1, end); + // ؽ + return root; + } + + return null; + } +} diff --git a/[0108][Convert Sorted Array To Binary Search Tree]/src/TreeNode.java b/[0108][Convert Sorted Array To Binary Search Tree]/src/TreeNode.java new file mode 100644 index 0000000..3784d5f --- /dev/null +++ b/[0108][Convert Sorted Array To Binary Search Tree]/src/TreeNode.java @@ -0,0 +1,15 @@ +/** + * Author: + * Date: 2015-06-22 + * Time: 12:57 + * Declaration: All Rights Reserved !!! + */ +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} diff --git a/[0109][Convert Sorted List To Binary Search Tree]/[0109][Convert Sorted List To Binary Search Tree].iml b/[0109][Convert Sorted List To Binary Search Tree]/[0109][Convert Sorted List To Binary Search Tree].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0109][Convert Sorted List To Binary Search Tree]/[0109][Convert Sorted List To Binary Search Tree].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0109][Convert Sorted List To Binary Search Tree]/[0109][ConvertSortedListToBinarySearchTree].iml b/[0109][Convert Sorted List To Binary Search Tree]/[0109][ConvertSortedListToBinarySearchTree].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0109][Convert Sorted List To Binary Search Tree]/[0109][ConvertSortedListToBinarySearchTree].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0109][Convert Sorted List To Binary Search Tree]/src/ListNode.java b/[0109][Convert Sorted List To Binary Search Tree]/src/ListNode.java new file mode 100644 index 0000000..22946ff --- /dev/null +++ b/[0109][Convert Sorted List To Binary Search Tree]/src/ListNode.java @@ -0,0 +1,14 @@ +/** + * Author: + * Date: 2015-06-23 + * Time: 07:17 + * Declaration: All Rights Reserved !!! + */ +public class ListNode { + int val; + ListNode next; + + ListNode(int x) { + val = x; + } +} diff --git a/[0109][Convert Sorted List To Binary Search Tree]/src/Main.java b/[0109][Convert Sorted List To Binary Search Tree]/src/Main.java new file mode 100644 index 0000000..3f5d483 --- /dev/null +++ b/[0109][Convert Sorted List To Binary Search Tree]/src/Main.java @@ -0,0 +1,63 @@ +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-06-23 + * Time: 08:08 + * Declaration: All Rights Reserved !!! + */ +public class Main { + public static void main(String[] args) { + Solution solution = new Solution(); + ListNode n1 = new ListNode(-1); + ListNode n2 = new ListNode(0); + ListNode n3 = new ListNode(1); + ListNode n4 = new ListNode(2); + n1.next = n2; + n2.next = n3; + n3.next = n4; + + TreeNode root = solution.sortedListToBST(n1); + print2(root); + } + + public static void print(TreeNode root) { + if (root != null) { + print(root.left); + System.out.print(root.val + ", "); + print(root.right); + } + } + + public static void print2(TreeNode root) { + if (root != null) { + List list = new LinkedList<>(); + list.add(root); + TreeNode node; + int curr = 1; + int next = 0; + while (!list.isEmpty()) { + node = list.remove(0); + curr--; + System.out.print(node.val + ", "); + + if (node.left != null) { + list.add(node.left); + next++; + } + + if (node.right != null) { + list.add(node.right); + next++; + } + + if (curr == 0) { + System.out.println(); + curr = next; + next = 0; + } + } + } + } +} diff --git a/[0109][Convert Sorted List To Binary Search Tree]/src/Solution.java b/[0109][Convert Sorted List To Binary Search Tree]/src/Solution.java new file mode 100644 index 0000000..087b4bb --- /dev/null +++ b/[0109][Convert Sorted List To Binary Search Tree]/src/Solution.java @@ -0,0 +1,64 @@ +/** + * Author: + * Date: 2015-06-23 + * Time: 07:16 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Given a singly linked list where elements are sorted in ascending order,
+     * convert it to a height balanced BST.
+     *
+     * Ŀ⣺
+     * һĵתһŸ߶ƽĶ
+     *
+     * ˼·
+     * ⷨһеֵһУͨ㷨ʱ临ӶǣO(n)ռ临ӶǣO(n)
+     * ⷨõݹķʽ
+     *      һм㣬㣬
+     *      м벿ֹ
+     *      мҲֹ
+     * õڶֽⷨ
+     * 
+ * + * @param head + * @return + */ + public TreeNode sortedListToBST(ListNode head) { + // Ϊվֱӷnull + if (head == null) { + return null; + } + + // ֻһ + if (head.next == null) { + return new TreeNode(head.val); + } + + // ƶ㣬ÿƶλ + ListNode fast = head.next.next; + // ¼м + ListNode mid = head; + // м + while (fast != null && fast.next != null) { + mid = mid.next; + fast = fast.next.next; + } + + // мһΪ + TreeNode root = new TreeNode(mid.next.val); + // + root.right = sortedListToBST(mid.next.next); + // ¼ҪϿĵ + ListNode midNext = mid.next; + // ϿƻԭĽṹ + mid.next = null; + // + root.left = sortedListToBST(head); + // ½Ӻ + mid.next = midNext; + // ؽ + return root; + } +} diff --git a/[0109][Convert Sorted List To Binary Search Tree]/src/TreeNode.java b/[0109][Convert Sorted List To Binary Search Tree]/src/TreeNode.java new file mode 100644 index 0000000..b19643b --- /dev/null +++ b/[0109][Convert Sorted List To Binary Search Tree]/src/TreeNode.java @@ -0,0 +1,15 @@ +/** + * Author: + * Date: 2015-06-23 + * Time: 07:17 + * Declaration: All Rights Reserved !!! + */ +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} diff --git a/[0110][Balanced Binary Tree]/[0110][Balanced Binary Tree].iml b/[0110][Balanced Binary Tree]/[0110][Balanced Binary Tree].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0110][Balanced Binary Tree]/[0110][Balanced Binary Tree].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0110][Balanced Binary Tree]/[0110][BalancedBinaryTree].iml b/[0110][Balanced Binary Tree]/[0110][BalancedBinaryTree].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0110][Balanced Binary Tree]/[0110][BalancedBinaryTree].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0110][Balanced Binary Tree]/src/Solution.java b/[0110][Balanced Binary Tree]/src/Solution.java new file mode 100644 index 0000000..51147b9 --- /dev/null +++ b/[0110][Balanced Binary Tree]/src/Solution.java @@ -0,0 +1,61 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 18:53 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + + /** + *
+     * ԭ
+     * Given a binary tree, determine if it is height-balanced.
+     * For this problem, a height-balanced binary tree is defined as a binary tree
+     * in which the depth of the two subtrees of every node never differ by more than 1.
+     *
+     * Ŀ
+     * һƽжǷǸ߶ƽġһø߶ƽĶĸ߶1
+     * Ҳˡ
+     *
+     * ˼·
+     * ݹη⡣
+     * 
+ * + * @param root + * @return + */ + public boolean isBalanced(TreeNode root) { + + if (root == null) { + return true; + } + + int left = depth(root.left); + int right = depth(root.right); + if (left - right > 1 || left - right < -1) { + return false; + } else { + return isBalanced(root.left) && isBalanced(root.right); + } + } + + /** + * ĸ߶ + * + * @param n ĸ + * @return ĸ߶ + */ + private int depth(TreeNode n) { + if (n == null) { + return 0; + } + if (n.left == null && n.right == null) { + return 1; + } else { + int left = depth(n.left); + int right = depth(n.right); + return 1 + (left > right ? left : right); + } + } + +} diff --git a/[0110][Balanced Binary Tree]/src/TreeNode.java b/[0110][Balanced Binary Tree]/src/TreeNode.java new file mode 100644 index 0000000..b36baee --- /dev/null +++ b/[0110][Balanced Binary Tree]/src/TreeNode.java @@ -0,0 +1,15 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 18:54 + * Declaration: All Rights Reserved !!! + */ +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} diff --git a/[0111][Minimum Depth Of Binary Tree]/[0111][Minimum Depth Of Binary Tree].iml b/[0111][Minimum Depth Of Binary Tree]/[0111][Minimum Depth Of Binary Tree].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0111][Minimum Depth Of Binary Tree]/[0111][Minimum Depth Of Binary Tree].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0111][Minimum Depth Of Binary Tree]/src/Solution.java b/[0111][Minimum Depth Of Binary Tree]/src/Solution.java new file mode 100644 index 0000000..836fb49 --- /dev/null +++ b/[0111][Minimum Depth Of Binary Tree]/src/Solution.java @@ -0,0 +1,40 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 18:51 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Given a binary tree, find its minimum depth.
+     * The minimum depth is the number of nodes along the shortest path from
+     * the root node down to the nearest leaf node.
+     *
+     * Ŀ
+     * һСȡ
+     *
+     * ˼·
+     * бҳСȡ
+     * 
+ * + * @param root + * @return + */ + public int minDepth(TreeNode root) { + return minDepth(root, false); + } + + public int minDepth(TreeNode root, boolean hasBrother) { + if (root == null) { + // ԼΪnullֵܲΪnullϲӽ㣬˵ǰûҵС + // ûֵܣ˵ǰʱֲСѾҵ + return hasBrother ? Integer.MAX_VALUE : 0; + } + + return 1 + Math.min(minDepth(root.left, root.right != null), + minDepth(root.right, root.left != null)); + } + +} diff --git a/[0111][Minimum Depth Of Binary Tree]/src/Solution2.java b/[0111][Minimum Depth Of Binary Tree]/src/Solution2.java new file mode 100644 index 0000000..6dfcd46 --- /dev/null +++ b/[0111][Minimum Depth Of Binary Tree]/src/Solution2.java @@ -0,0 +1,64 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 18:51 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + private int min = Integer.MAX_VALUE; // ¼С + private int cur = 0; // iǰij + + /** + *
+     * ԭ
+     * Given a binary tree, find its minimum depth.
+     * The minimum depth is the number of nodes along the shortest path from
+     * the root node down to the nearest leaf node.
+     *
+     * Ŀ
+     * һСȡ
+     *
+     * ˼·
+     * бҳСȡ
+     * 
+ * + * @param root + * @return + */ + public int minDepth(TreeNode root) { + + depth(root); + return min; + } + + /** + * + * + * @param node ǰ + */ + private void depth(TreeNode node) { + + if (node == null) { + min = cur; + return; + } + + cur++; // ǰIJμ1 + // Ҷڵ㣬·ȼ¼СС + if (node.left == null && node.right == null && cur < min) { + min = cur; // Сֵ + } + // + if (node.left != null) { + depth(node.left); + } + + // + if (node.right != null) { + depth(node.right); + } + + cur--; // ԭ + + } +} diff --git a/[0111][Minimum Depth Of Binary Tree]/src/TreeNode.java b/[0111][Minimum Depth Of Binary Tree]/src/TreeNode.java new file mode 100644 index 0000000..d4f5960 --- /dev/null +++ b/[0111][Minimum Depth Of Binary Tree]/src/TreeNode.java @@ -0,0 +1,15 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 18:52 + * Declaration: All Rights Reserved !!! + */ +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} diff --git a/[0112][Path Sum]/[0112][Path Sum].iml b/[0112][Path Sum]/[0112][Path Sum].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0112][Path Sum]/[0112][Path Sum].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0112][Path Sum]/[0112][PathSum].iml b/[0112][Path Sum]/[0112][PathSum].iml new file mode 100644 index 0000000..86622ab --- /dev/null +++ b/[0112][Path Sum]/[0112][PathSum].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0112][Path Sum]/src/Solution.java b/[0112][Path Sum]/src/Solution.java new file mode 100644 index 0000000..6f66723 --- /dev/null +++ b/[0112][Path Sum]/src/Solution.java @@ -0,0 +1,70 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 18:56 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + private boolean stop = false; // жǷѾҵ + + /** + *
+     * ԭ
+     * Given a binary tree and a sum, determine if the tree has a root-to-leaf path
+     * such that adding up all the values along the path equals the given sum.
+     * For example:
+     * Given the below binary tree and sum = 22,
+     *
+     *       5
+     *      / \
+     *     4   8
+     *    /   / \
+     *   11  13  4
+     *  /  \      \
+     * 7    2      1
+     *
+     * return true, as there exist a root-to-leaf path 5->4->11->2 which sum is 22.
+     *
+     * Ŀ
+     * һöһͣжϴĸ㵽ҶӽнĺǷڸĺͣڣ
+     * ͷtrue򷵻false
+     *
+     * ˼·
+     * бʹûݷ⡣
+     * 
+ * + * @param root + * @param sum + * @return + */ + public boolean hasPathSum(TreeNode root, int sum) { + calculate(root, 0, sum); + return stop; + } + + /** + * Ҷӽĺ + * + * @param node ǰĽڵ + * @param cur Ӹڵ㵽ǰ֮ǰнڵ + * @param sum Ҫĺ + */ + private void calculate(TreeNode node, int cur, int sum) { + if (!stop && node != null) { // ûҵ𰸣ҪĽڵ㲻Ϊ + + // Ҷڵ㣬ͼӸǰҶڵĺǷΪsumǾ˵Ѿҵıstop + if (node.left == null && node.right == null && (node.val + cur == sum)) { + stop = true; + } + + // ǷҶڵ㣬 + if (node.left != null) { + calculate(node.left, cur + node.val, sum); + } + + if (node.right != null) { + calculate(node.right, cur + node.val, sum); + } + } + } +} diff --git a/[0112][Path Sum]/src/TreeNode.java b/[0112][Path Sum]/src/TreeNode.java new file mode 100644 index 0000000..0076620 --- /dev/null +++ b/[0112][Path Sum]/src/TreeNode.java @@ -0,0 +1,15 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 18:56 + * Declaration: All Rights Reserved !!! + */ +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} diff --git a/[0113][Path Sum II]/[0113][Path Sum II].iml b/[0113][Path Sum II]/[0113][Path Sum II].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0113][Path Sum II]/[0113][Path Sum II].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0113][Path Sum II]/[0113][PathSumII].iml b/[0113][Path Sum II]/[0113][PathSumII].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0113][Path Sum II]/[0113][PathSumII].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0113][Path Sum II]/src/Solution.java b/[0113][Path Sum II]/src/Solution.java new file mode 100644 index 0000000..230a216 --- /dev/null +++ b/[0113][Path Sum II]/src/Solution.java @@ -0,0 +1,90 @@ +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-08-21 + * Time: 18:59 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + private List> result; + private List l; + private int sum; + private int curSum = 0; + + /** + *
+     * ԭ
+     * Given a binary tree and a sum, find all root-to-leaf paths where each paths
+     * sum equals the given sum.
+     * For example:
+     * Given the below binary tree and sum = 22,
+     *
+     *       5
+     *      / \
+     *     4   8
+     *    /   / \
+     *   11  13  4
+     *  /  \    / \
+     * 7    2  5   1
+     *
+     *  return
+     *
+     * [
+     *  [5,4,11,2],
+     *  [5,8,4,5]
+     * ]
+     *
+     * Ŀ
+     * һöһͣжϴĸ㵽ҶӽнĺǷڸĺͣھͼ¼·
+     *
+     * ˼·
+     * бʹûݷ⡣
+     * 
+ * + * @param root + * @param sum + * @return + */ + public List> pathSum(TreeNode root, int sum) { + + result = new LinkedList<>(); + + if (root != null) { + this.sum = sum; + l = new LinkedList<>(); + pathSum(root); + } + + return result; + } + + private void pathSum(TreeNode root) { + if (root != null) { + + l.add(root.val); + curSum += root.val; + + if (root.left == null && root.right == null && curSum == sum) { + List list = new LinkedList<>(); + for (Integer i : l) { + list.add(i); + } + + result.add(list); + } + + if (root.left != null) { + pathSum(root.left); + } + + if (root.right != null) { + pathSum(root.right); + } + + curSum -= root.val; + l.remove(l.size() - 1); // ɾһ + } + } +} diff --git a/[0113][Path Sum II]/src/TreeNode.java b/[0113][Path Sum II]/src/TreeNode.java new file mode 100644 index 0000000..8bf40e8 --- /dev/null +++ b/[0113][Path Sum II]/src/TreeNode.java @@ -0,0 +1,15 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 18:59 + * Declaration: All Rights Reserved !!! + */ +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} diff --git a/[0114][Flatten Binary Tree To Linked List]/[0114][Flatten Binary Tree To Linked List].iml b/[0114][Flatten Binary Tree To Linked List]/[0114][Flatten Binary Tree To Linked List].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0114][Flatten Binary Tree To Linked List]/[0114][Flatten Binary Tree To Linked List].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0114][Flatten Binary Tree To Linked List]/[0114][FlattenBinaryTreeToLinkedList].iml b/[0114][Flatten Binary Tree To Linked List]/[0114][FlattenBinaryTreeToLinkedList].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0114][Flatten Binary Tree To Linked List]/[0114][FlattenBinaryTreeToLinkedList].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0114][Flatten Binary Tree To Linked List]/src/Solution.java b/[0114][Flatten Binary Tree To Linked List]/src/Solution.java new file mode 100644 index 0000000..fad9b71 --- /dev/null +++ b/[0114][Flatten Binary Tree To Linked List]/src/Solution.java @@ -0,0 +1,68 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 19:02 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Given a binary tree, flatten it to a linked list in-place.
+     * For example,
+     * Given
+     *
+     *      1
+     *     / \
+     *    2   5
+     *   / \   \
+     *  3   4   6
+     *
+     * The flattened tree should look like:
+     *
+     * 1
+     *  \
+     *   2
+     *    \
+     *     3
+     *      \
+     *       4
+     *        \
+     *         5
+     *          \
+     *           6
+     *
+     * Ŀ
+     * һöתɵʹԭ㷨
+     *
+     * ˼·
+     * Ӹ㣨rootlӽ㣨xrootrӵxϣxΪգ
+     * rootΪrootա
+     * 
+ * + * @param root + */ + public void flatten(TreeNode root) { + TreeNode head = new TreeNode(-1); + head.right = root; + TreeNode node = head; + + while (node.right != null) { + node = node.right; + if (node.left != null) { + TreeNode end = node.left; + while (end.right != null) { + end = end.right; + } + + TreeNode tmp = node.right; + + node.right = node.left; + node.left = null; + end.right = tmp; + } + } + + head.right = null; // ȥ÷ + } +} diff --git a/[0114][Flatten Binary Tree To Linked List]/src/TreeNode.java b/[0114][Flatten Binary Tree To Linked List]/src/TreeNode.java new file mode 100644 index 0000000..c988e88 --- /dev/null +++ b/[0114][Flatten Binary Tree To Linked List]/src/TreeNode.java @@ -0,0 +1,12 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 19:02 + * Declaration: All Rights Reserved !!! + */ +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + TreeNode(int x) { val = x; } +} diff --git a/[0116][Populating Next Right Pointersin Each Node]/[0116][Populating Next Right Pointersin Each Node].iml b/[0116][Populating Next Right Pointersin Each Node]/[0116][Populating Next Right Pointersin Each Node].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0116][Populating Next Right Pointersin Each Node]/[0116][Populating Next Right Pointersin Each Node].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0116][Populating Next Right Pointersin Each Node]/[0116][PopulatingNextRightPointersinEachNode ].iml b/[0116][Populating Next Right Pointersin Each Node]/[0116][PopulatingNextRightPointersinEachNode ].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0116][Populating Next Right Pointersin Each Node]/[0116][PopulatingNextRightPointersinEachNode ].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0116][Populating Next Right Pointersin Each Node]/src/Solution.java b/[0116][Populating Next Right Pointersin Each Node]/src/Solution.java new file mode 100644 index 0000000..7765517 --- /dev/null +++ b/[0116][Populating Next Right Pointersin Each Node]/src/Solution.java @@ -0,0 +1,84 @@ +/** + * Author: + * Date: 2015-06-18 + * Time: 10:43 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + + /** + *
+     * Given a binary tree
+     *      struct TreeLinkNode {
+     *          TreeLinkNode *left;
+     *          TreeLinkNode *right;
+     *          TreeLinkNode *next;
+     *      }
+     * Populate each next pointer to point to its next right node. If there is no next right node,
+     * the next pointer should be set to NULL.
+     *
+     * Initially, all next pointers are set to NULL.
+     *
+     * Note:
+     *      - You may only use constant extra space.
+     *      - You may assume that it is a perfect binary tree (ie, all leaves are at the same level,
+     *        and every parent has two children).
+     *
+     * For example,
+     * Given the following perfect binary tree,
+     *      1
+     *    /  \
+     *   2    3
+     *  / \  / \
+     * 4  5  6  7
+     *
+     * After calling your function, the tree should look like:
+     *
+     *      1 -> NULL
+     *    /  \
+     *   2 -> 3 -> NULL
+     *  / \  / \
+     * 4->5->6->7 -> NULL
+     *
+     * ˼·
+     * ÿһڵnextÿһҲγһ
+     * ÿͷǣӣӣӡ
+     * ˫ѭѭŸӣһֱ¡
+     * ڲѭһĽڵ㴮
+     *
+     * ԼҺӷŵӵnextϣҺӣͨԼnextָ룬ҵھӡ
+     * 
+ * + * @param root + */ + public void connect(TreeLinkNode root) { + + TreeLinkNode node; + // мһȫ + // һѭ + // root.left != nullãһûĽ + while (root != null && root.left != null) { + // ÿrootʾһĵһ + // node¼ÿһĵһ + node = root; + + // ÿ + while (node != null) { + // ʾӵͬһµӽ + node.left.next = node.right; + // nodeijһ + if (node.next != null) { + // ӽӵͬڽӽ + node.right.next = node.next.left; + } + + // ƶͬһ + node = node.next; + } + + // ƶһĵһ + root = root.left; + } + + } +} diff --git a/[0116][Populating Next Right Pointersin Each Node]/src/TreeLinkNode.java b/[0116][Populating Next Right Pointersin Each Node]/src/TreeLinkNode.java new file mode 100644 index 0000000..47a84b5 --- /dev/null +++ b/[0116][Populating Next Right Pointersin Each Node]/src/TreeLinkNode.java @@ -0,0 +1,14 @@ +/** + * Author: + * Date: 2015-06-18 + * Time: 10:43 + * Declaration: All Rights Reserved !!! + */ +public class TreeLinkNode { + int val; + TreeLinkNode left, right, next; + + TreeLinkNode(int x) { + val = x; + } +} diff --git a/[0117][Populating Next Right Pointers In Each Node II]/[0117][Populating Next Right Pointers In Each Node II].iml b/[0117][Populating Next Right Pointers In Each Node II]/[0117][Populating Next Right Pointers In Each Node II].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0117][Populating Next Right Pointers In Each Node II]/[0117][Populating Next Right Pointers In Each Node II].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0117][Populating Next Right Pointers In Each Node II]/[0117][PopulatingNextRightPointersInEachNodeII].iml b/[0117][Populating Next Right Pointers In Each Node II]/[0117][PopulatingNextRightPointersInEachNodeII].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0117][Populating Next Right Pointers In Each Node II]/[0117][PopulatingNextRightPointersInEachNodeII].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0117][Populating Next Right Pointers In Each Node II]/src/Main.java b/[0117][Populating Next Right Pointers In Each Node II]/src/Main.java new file mode 100644 index 0000000..4945afa --- /dev/null +++ b/[0117][Populating Next Right Pointers In Each Node II]/src/Main.java @@ -0,0 +1,46 @@ +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-06-22 + * Time: 19:49 + * Declaration: All Rights Reserved !!! + */ +public class Main { + public static void main(String[] args) { + TreeLinkNode n1 = new TreeLinkNode(1); + TreeLinkNode n2 = new TreeLinkNode(2); + TreeLinkNode n3 = new TreeLinkNode(3); + TreeLinkNode n4 = new TreeLinkNode(4); + TreeLinkNode n5 = new TreeLinkNode(5); + TreeLinkNode n6 = new TreeLinkNode(6); + TreeLinkNode n7 = new TreeLinkNode(7); + + n1.left = n2; + n1.right = n3; + + n2.left = n4; + n2.right = n5; + + n3.left = n7; + + Solution solution = new Solution(); + solution.connect(n1); +// print(n1); + + + } + + public static void print(TreeLinkNode root) { + if (root != null) { + TreeLinkNode curr; + List list = new LinkedList<>(); + list.add(root); + + while (list.size() > 0) { + curr = list.get(0); + } + } + } +} diff --git a/[0117][Populating Next Right Pointers In Each Node II]/src/Solution.java b/[0117][Populating Next Right Pointers In Each Node II]/src/Solution.java new file mode 100644 index 0000000..0aa6600 --- /dev/null +++ b/[0117][Populating Next Right Pointers In Each Node II]/src/Solution.java @@ -0,0 +1,100 @@ +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-06-22 + * Time: 19:27 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Follow up for problem "Populating Next Right Pointers in Each Node".
+     *
+     * What if the given tree could be any binary tree? Would your previous solution still work?
+     * Note:
+     *
+     * You may only use constant extra space.
+     * For example,
+     * Given the following binary tree,
+     *      1
+     *    /  \
+     *   2    3
+     *  / \    \
+     * 4   5    7
+     * After calling your function, the tree should look like:
+     *      1 -> NULL
+     *    /  \
+     *   2 -> 3 -> NULL
+     *  / \    \
+     * 4-> 5 -> 7 -> NULL
+     *
+     * Ŀ⣺
+     * һöÿڵһnextָ룬ָͬһڵұߵĽڵ㡣ͬĽ㶼
+     *
+     * ˼·
+     * вαÿһ㴮
+     * 
+ * + * @param root + */ + public void connect(TreeLinkNode root) { + if (root != null) { + // + List list = new LinkedList<>(); + // ǰĽǰһ + TreeLinkNode prev = null; + // ǰĽ + TreeLinkNode node; + // ǰʣĽ + int curr = 1; + // ¼һԪظ + int next = 0; + + // + list.add(root); + + // зǿ + while (list.size() > 0) { + // ɾԪ + node = list.remove(0); + // ǰʣ + curr--; + + // ǿգӽ + if (node.left != null) { + list.add(node.left); + next++; + } + + // ǿգӽ + if (node.right != null) { + list.add(node.right); + next++; + } + + // ǰ㴦 + if (curr == 0) { + + // һԪؽд + Iterator iterable = list.iterator(); + if (iterable.hasNext()) { + prev = iterable.next(); + while (iterable.hasNext()) { + node = iterable.next(); + prev.next = node; + prev = node; + } + } + + // µǰʣĽ + curr = next; + // ͳ² + next = 0; + } + } + } + } +} diff --git a/[0117][Populating Next Right Pointers In Each Node II]/src/TreeLinkNode.java b/[0117][Populating Next Right Pointers In Each Node II]/src/TreeLinkNode.java new file mode 100644 index 0000000..253335a --- /dev/null +++ b/[0117][Populating Next Right Pointers In Each Node II]/src/TreeLinkNode.java @@ -0,0 +1,14 @@ +/** + * Author: + * Date: 2015-06-22 + * Time: 19:28 + * Declaration: All Rights Reserved !!! + */ +public class TreeLinkNode { + int val; + TreeLinkNode left, right, next; + + TreeLinkNode(int x) { + val = x; + } +} diff --git a/[0118][Pascal's Triangle]/[0118][Pascal's Triangle].iml b/[0118][Pascal's Triangle]/[0118][Pascal's Triangle].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0118][Pascal's Triangle]/[0118][Pascal's Triangle].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0118][Pascal's Triangle]/[0118][Pascal'sTriangle].iml b/[0118][Pascal's Triangle]/[0118][Pascal'sTriangle].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0118][Pascal's Triangle]/[0118][Pascal'sTriangle].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0118][Pascal's Triangle]/src/Solution.java b/[0118][Pascal's Triangle]/src/Solution.java new file mode 100644 index 0000000..4eb8ab8 --- /dev/null +++ b/[0118][Pascal's Triangle]/src/Solution.java @@ -0,0 +1,76 @@ +import java.util.ArrayList; +import java.util.List; + +/** + * Author: + * Date: 2015-08-21 + * Time: 19:05 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Given numRows, generate the first numRows of Pascals triangle.
+     * For example, given numRows = 5,
+     * Return
+     *
+     * [
+     * [1],
+     * [1,1],
+     * [1,2,1],
+     * [1,3,3,1],
+     * [1,4,6,4,1]
+     * ]
+     *
+     * Ŀ
+     * һnn˹Ρ
+     *
+     * ˼·
+     * n>0
+     * f(1, n)=1(n>0)
+     * f(1, 2)=1(n=2)
+     * f(i,j) = f(i-1, j-1)+f(i, j-1)i>2,j>2
+     * 
+ * + * @param numRows + * @return + */ + public List> generate(int numRows) { + + if (numRows < 0) { + return null; + } + + List> list = new ArrayList<>(); + + if (numRows >= 1) { + List data = new ArrayList<>(); + data.add(1); + list.add(data); + } + + if (numRows >= 2) { + List data = new ArrayList<>(); + data.add(1); + data.add(1); + list.add(data); + } + + if (numRows >= 3) { + for (int i = 3; i <= numRows; i++) { + List data = new ArrayList<>(); + List prev = list.get(i - 2); + data.add(1); + for (int j = 2; j <= i - 1; j++) { + data.add(prev.get(j - 2) + prev.get(j - 1)); + } + data.add(1); + + list.add(data); + } + } + + return list; + } +} diff --git a/[0119][Pascal's Triangle II]/[0119][Pascal's Triangle II].iml b/[0119][Pascal's Triangle II]/[0119][Pascal's Triangle II].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0119][Pascal's Triangle II]/[0119][Pascal's Triangle II].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0119][Pascal's Triangle II]/[0119][Pascal'sTriangleII].iml b/[0119][Pascal's Triangle II]/[0119][Pascal'sTriangleII].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0119][Pascal's Triangle II]/[0119][Pascal'sTriangleII].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0119][Pascal's Triangle II]/src/Solution.java b/[0119][Pascal's Triangle II]/src/Solution.java new file mode 100644 index 0000000..ef8b077 --- /dev/null +++ b/[0119][Pascal's Triangle II]/src/Solution.java @@ -0,0 +1,83 @@ +import java.util.ArrayList; +import java.util.List; + +/** + * Author: + * Date: 2015-08-21 + * Time: 19:09 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Given an index k, return the kth row of the Pascals triangle.
+     * For example, given k = 3,
+     * Return [1,3,3,1].
+     * Note:
+     * Could you optimize your algorithm to use only O(k) extra space?
+     *
+     * Ŀ
+     * һk˹ĵkС
+     *
+     * ˼·
+     * n>0
+     * f(1, n)=1(n>0)
+     * f(n, n)=1(n>2)
+     * f(i,j) = f(i-1, j-1)+f(i, j-1)i>2,j>2
+     * kС
+     * 
+ * + * @param rowIndex + * @return + */ + public List getRow(int rowIndex) { + + rowIndex++; // rowIndexʵĿ + + if (rowIndex < 0) { + return null; + } + + List result = new ArrayList<>(rowIndex); + + if (rowIndex >= 1) { + result.add(1); + } + + if (rowIndex >= 2) { + result.add(1); + } + + int line = 0; // ¼ǰʹһ + int prev; // һһ + if (rowIndex >= 3) { + + int[][] data = new int[2][rowIndex]; + // 1 + data[0][0] = 1; + data[1][0] = 1; + data[1][1] = 1; + + for (int i = 2; i < rowIndex; i++) { + line = i % 2; // ¼ݱڵ0ߵ1 + prev = (i - 1 + 2) % 2; +// data[line][0] = 1; // õһ֣Բã1Ѿˣdata[x][0]Ϊ1 + for (int j = 1; j < i; j++) { + data[line][j] = data[prev][j - 1] + data[prev][j]; + } + + data[line][i] = 1; // һ + } + + // + result.clear(); + for (int i = 0; i < rowIndex; i++) { + result.add(data[line][i]); + } + + } + + return result; + } +} diff --git a/[0120][Triangle]/[0120][Triangle].iml b/[0120][Triangle]/[0120][Triangle].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0120][Triangle]/[0120][Triangle].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0120][Triangle]/src/Main.java b/[0120][Triangle]/src/Main.java new file mode 100644 index 0000000..419cba9 --- /dev/null +++ b/[0120][Triangle]/src/Main.java @@ -0,0 +1,33 @@ +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-06-23 + * Time: 09:24 + * Declaration: All Rights Reserved !!! + */ +public class Main { + public static void main(String[] args) { + Solution solution = new Solution(); + int[][] t = { + {2}, + {3, 4}, + {6, 5, 7}, + {4, 1, 8, 3} + }; + + List> tri = new LinkedList<>(); + for (int i = 0; i < t.length; i++) { + List line = new LinkedList<>(); + for (int j = 0; j < t[i].length; j++) { + line.add(t[i][j]); + } + + tri.add(line); + } + + System.out.println(tri); + System.out.println(solution.minimumTotal(tri)); + } +} diff --git a/[0120][Triangle]/src/Solution.java b/[0120][Triangle]/src/Solution.java new file mode 100644 index 0000000..d3e6b5c --- /dev/null +++ b/[0120][Triangle]/src/Solution.java @@ -0,0 +1,80 @@ +import java.util.List; + +/** + * Author: + * Date: 2015-06-23 + * Time: 08:51 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Given a triangle, find the minimum path sum from top to bottom.
+     * Each step you may move to adjacent numbers on the row below.
+     *
+     * For example, given the following triangle
+     * [
+     *      [2],
+     *     [3,4],
+     *    [6,5,7],
+     *   [4,1,8,3]
+     * ]
+     *
+     * The minimum path sum from top to bottom is 11 (i.e., 2 + 3 + 5 + 1 = 11).
+     * Note:
+     * Bonus point if you are able to do this using only O(n) extra space,
+     * where n is the total number of rows in the triangle.
+     *
+     * Ŀ⣺
+     * һΣҳӶ׵С·ͣÿһԴһƶһڵ
+     *
+     * ˼·
+     * Ʒ̣
+     * f(0,0)=a[0][0]
+     * f(i,0)=a[i][0]+f(i-1,0) (i>0)
+     * f(i,i)=a[i][i]+f(i-1,i-1)(i>0)
+     * f(i,j)=a[i][j]+MIN(f(i-1,j),f(i-1,j-1))(0
+     *
+     * @param triangle
+     * @return
+     */
+    public int minimumTotal(List> triangle) {
+
+        if (triangle == null || triangle.size() < 1) {
+            return 0;
+        }
+        // ĵڶά
+        int[][] minSum = new int[triangle.size()][];
+
+        // ĵһά
+        for (int i = 0; i < minSum.length; i++) {
+            minSum[i] = new int[i + 1];
+        }
+        // õһ
+        minSum[0][0] = triangle.get(0).get(0);
+        // 
+        for (int i = 1; i < minSum.length; i++) {
+            List line = triangle.get(i);
+            for (int j = 0; j < minSum[i].length; j++) {
+                if (j == 0) {
+                    minSum[i][0] = line.get(0) + minSum[i - 1][0];
+                } else if (i == j) {
+                    minSum[i][j] = line.get(j) + minSum[i - 1][j - 1];
+                } else if (j < i) {
+                    minSum[i][j] = line.get(j) + Math.min(minSum[i - 1][j], minSum[i - 1][j - 1]);
+                }
+            }
+        }
+        //һеСֵĽ
+        int min = minSum[minSum.length - 1][0];
+        int length = minSum[minSum.length - 1].length;
+        for (int i = 1; i < length; i++) {
+            if (min > minSum[length - 1][i]) {
+                min = minSum[length - 1][i];
+            }
+        }
+
+        return min;
+    }
+}
diff --git a/[0121][Best Time To Buy And Sell Stock]/[0121][Best Time To Buy And Sell Stock].iml b/[0121][Best Time To Buy And Sell Stock]/[0121][Best Time To Buy And Sell Stock].iml
new file mode 100644
index 0000000..c90834f
--- /dev/null
+++ b/[0121][Best Time To Buy And Sell Stock]/[0121][Best Time To Buy And Sell Stock].iml	
@@ -0,0 +1,11 @@
+
+
+  
+    
+    
+      
+    
+    
+    
+  
+
\ No newline at end of file
diff --git a/[0121][Best Time To Buy And Sell Stock]/[0121][BestTimeToBuyAndSellStock].iml b/[0121][Best Time To Buy And Sell Stock]/[0121][BestTimeToBuyAndSellStock].iml
new file mode 100644
index 0000000..f080bef
--- /dev/null
+++ b/[0121][Best Time To Buy And Sell Stock]/[0121][BestTimeToBuyAndSellStock].iml	
@@ -0,0 +1,13 @@
+
+
+  
+    
+    
+      
+    
+    
+    
+    
+    
+  
+
\ No newline at end of file
diff --git a/[0121][Best Time To Buy And Sell Stock]/src/Solution.java b/[0121][Best Time To Buy And Sell Stock]/src/Solution.java
new file mode 100644
index 0000000..f779c93
--- /dev/null
+++ b/[0121][Best Time To Buy And Sell Stock]/src/Solution.java	
@@ -0,0 +1,54 @@
+/**
+ * Author: 
+ * Date: 2015-06-22
+ * Time: 15:42
+ * Declaration: All Rights Reserved !!!
+ */
+public class Solution {
+    /**
+     * 
+     * Say you have an array for which the ith element is the price of a given stock on day i.
+     *
+     * If you were only permitted to complete at most one transaction (ie, buy one and sell
+     * one share of the stock), design an algorithm to find the maximum profit.
+     *
+     * Ŀ⣺
+     * һprices[]prices[i]Ʊڵiۼֻۣһν(һ)ܵõ档
+     *
+     * ˼·
+     * ֻҪҳIJֵɣ max(prices[j] C prices[i]) i < jһαɣڱʱñ
+     * low¼ prices[o....i] еСֵǵǰΪֹۼۣʱ临ӶΪ O(n)
+     * 
+ * + * @param prices + * @return + */ + public int maxProfit(int[] prices) { + + if (prices == null || prices.length < 1) { + return 0; + } + + int min = prices[0]; + int profit = 0; + + // iļ۸ԿҲԿ + for (int i = 1; i < prices.length; i++) { + // ҵ͵ + if (min > prices[i]) { + // + min = prices[i]; + } + // ļ۸񲻵 + else { + // ļ۸֮ǰļ۸ + if (profit < prices[i] - min) { + // + profit = prices[i] - min; + } + } + } + + return profit; + } +} diff --git a/[0122][Best Time to Buy and Sell Stock II]/[0122][Best Time to Buy and Sell Stock II].iml b/[0122][Best Time to Buy and Sell Stock II]/[0122][Best Time to Buy and Sell Stock II].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0122][Best Time to Buy and Sell Stock II]/[0122][Best Time to Buy and Sell Stock II].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0122][Best Time to Buy and Sell Stock II]/src/Solution.java b/[0122][Best Time to Buy and Sell Stock II]/src/Solution.java new file mode 100644 index 0000000..bef6708 --- /dev/null +++ b/[0122][Best Time to Buy and Sell Stock II]/src/Solution.java @@ -0,0 +1,37 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-09 08:46 + **/ +public class Solution { + public int maxProfit(int[] prices) { + + if (prices == null || prices.length < 2) { + return 0; + } + + int buy = 0; + int sell = 1; + + int sum = 0; + while (sell < prices.length) { + // 从buy的位置开始找降序子序列中最小的值 + while (buy + 1 < prices.length && prices[buy] >= prices[buy + 1]) { + buy++; + } + // 从buy的位置开始找升序子序列中最大的值 + sell = buy + 1; + while (sell + 1 < prices.length && prices[sell] <= prices[sell + 1]) { + sell++; + } + + if (sell < prices.length) { + sum += prices[sell] - prices[buy]; + } + + buy = sell + 1; + + } + + return sum; + } +} diff --git a/[0122][Best Time to Buy and Sell Stock II]/src/Test.java b/[0122][Best Time to Buy and Sell Stock II]/src/Test.java new file mode 100644 index 0000000..2b9341e --- /dev/null +++ b/[0122][Best Time to Buy and Sell Stock II]/src/Test.java @@ -0,0 +1,18 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-09 09:13 + **/ +public class Test { + public static void main(String[] args) { + Solution solution = new Solution(); + + int[] prices = {7, 1, 5, 3, 6, 4}; + System.out.println(solution.maxProfit(prices) == 7); + + int[] prices2 = {1, 2, 3, 4, 5}; + System.out.println(solution.maxProfit(prices2) == 4); + + int[] prices3 = {7, 6, 4, 3, 1}; + System.out.println(solution.maxProfit(prices3) == 0); + } +} diff --git a/[0124][Binary Tree Maximum Path Sum]/[0124][Binary Tree Maximum Path Sum].iml b/[0124][Binary Tree Maximum Path Sum]/[0124][Binary Tree Maximum Path Sum].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0124][Binary Tree Maximum Path Sum]/[0124][Binary Tree Maximum Path Sum].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0124][Binary Tree Maximum Path Sum]/[0124][BinaryTreeMaximumPathSum].iml b/[0124][Binary Tree Maximum Path Sum]/[0124][BinaryTreeMaximumPathSum].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0124][Binary Tree Maximum Path Sum]/[0124][BinaryTreeMaximumPathSum].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0124][Binary Tree Maximum Path Sum]/src/Solution.java b/[0124][Binary Tree Maximum Path Sum]/src/Solution.java new file mode 100644 index 0000000..0322f49 --- /dev/null +++ b/[0124][Binary Tree Maximum Path Sum]/src/Solution.java @@ -0,0 +1,59 @@ +/** + * Author: + * Date: 2015-06-25 + * Time: 09:00 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + // ¼· + private int max; + // ¼ǰ· + private int cur; + + /** + *
+     * Given a binary tree, find the maximum path sum.
+     * The path may start and end at any node in the tree.
+     * For example:
+     * Given the below binary tree,
+     *   1
+     *  / \
+     * 2   3
+     * Return 6.
+     *
+     * Ŀ⣺
+     * ·ͣ·ʼյ
+     *
+     *
+     * 
+ * + * @param root + * @return + */ + public int maxPathSum(TreeNode root) { + + + if (root == null) { + throw new IllegalArgumentException(); + } + + max = Integer.MIN_VALUE; + cur = 0; + maxPathSumHelper(root); + return max; + } + + public void maxPathSumHelper(TreeNode root) { + if (root != null) { + cur += root.val; + + if (max < cur) { + max = cur; + } + + maxPathSumHelper(root.left); + maxPathSumHelper(root.right); + } + } + +} diff --git a/[0124][Binary Tree Maximum Path Sum]/src/TreeNode.java b/[0124][Binary Tree Maximum Path Sum]/src/TreeNode.java new file mode 100644 index 0000000..25c6a36 --- /dev/null +++ b/[0124][Binary Tree Maximum Path Sum]/src/TreeNode.java @@ -0,0 +1,15 @@ +/** + * Author: + * Date: 2015-06-25 + * Time: 09:01 + * Declaration: All Rights Reserved !!! + */ +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} diff --git a/[0125][Valid Palindrome]/[0125][Valid Palindrome].iml b/[0125][Valid Palindrome]/[0125][Valid Palindrome].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0125][Valid Palindrome]/[0125][Valid Palindrome].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0125][Valid Palindrome]/[0125][ValidPalindrome].iml b/[0125][Valid Palindrome]/[0125][ValidPalindrome].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0125][Valid Palindrome]/[0125][ValidPalindrome].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0125][Valid Palindrome]/src/Solution.java b/[0125][Valid Palindrome]/src/Solution.java new file mode 100644 index 0000000..853e8cf --- /dev/null +++ b/[0125][Valid Palindrome]/src/Solution.java @@ -0,0 +1,78 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 19:10 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Given a string, determine if it is a palindrome, considering only
+     * alphanumeric characters and ignoring cases.
+     * For example,
+     * "A man, a plan, a canal: Panama" is a palindrome.
+     * "race a car" is not a palindrome.
+     * Note:
+     * Have you consider that the string might be empty? This is a good
+     * question to ask during an interview.
+     * For the purpose of this problem, we define empty string as valid palindrome.
+     *
+     * Ŀ
+     * һַжǷǻַĸҺԴСд
+     *
+     * ˼·
+     * ʹβָ룬ֱҵһλãбȽϣȾͽһȽϣ
+     * Ⱦͷfalseֱеĸꡣ
+     * 
+ * + * @param s + * @return + */ + public boolean isPalindrome(String s) { + + if (s == null) { + return false; + } + + int left = 0; + int right = s.length() - 1; + + int delta = 'A' - 'a'; + char l; + char r; + + while (left < right) { + while (left < s.length() && !isAlphanumericCharacters(s.charAt(left))) { // ĸ + left++; + } + + while (right >= 0 && !isAlphanumericCharacters(s.charAt(right))) { // ĸ + right--; + } + + if (left < right) { + l = s.charAt(left); + r = s.charAt(right); + if (l == r || l - r == delta || r - l == delta) { + left++; + right--; + } else { + return false; + } + } + } + + return true; + } + + /** + * жǷĸ + * + * @param c жϵ + * @return жϽ + */ + private boolean isAlphanumericCharacters(char c) { + return c >= '0' && c <= '9' || c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z'; + } +} diff --git a/[0126][Word Ladder II]/[0126][Word Ladder II].iml b/[0126][Word Ladder II]/[0126][Word Ladder II].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0126][Word Ladder II]/[0126][Word Ladder II].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0126][Word Ladder II]/src/Main.java b/[0126][Word Ladder II]/src/Main.java new file mode 100644 index 0000000..356b93f --- /dev/null +++ b/[0126][Word Ladder II]/src/Main.java @@ -0,0 +1,51 @@ +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-20 08:17 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + String beginWord = "hit"; + String endWord = "cog"; + List wordList = new LinkedList<>(Arrays.asList("hot", "dot", "dog", "lot", "log", "cog")); + System.out.println(solution.findLadders(beginWord, endWord, wordList)); + } + + @Test + public void test2() { + Solution solution = new Solution(); + String beginWord = "hot"; + String endWord = "dog"; + List wordList = new LinkedList<>(Arrays.asList("hot","dog","dot")); + System.out.println(solution.findLadders(beginWord, endWord, wordList)); + } + + @Test + public void test3() { + Solution solution = new Solution(); + String beginWord = "cet"; + String endWord = "ism"; + String[] words = {"kid","tag","pup","ail","tun","woo","erg","luz","brr","gay","sip","kay","per","val","mes","ohs","now","boa","cet","pal","bar","die","war","hay","eco","pub","lob","rue","fry","lit","rex","jan","cot","bid","ali","pay","col","gum","ger","row","won","dan","rum","fad","tut","sag","yip","sui","ark","has","zip","fez","own","ump","dis","ads","max","jaw","out","btu","ana","gap","cry","led","abe","box","ore","pig","fie","toy","fat","cal","lie","noh","sew","ono","tam","flu","mgm","ply","awe","pry","tit","tie","yet","too","tax","jim","san","pan","map","ski","ova","wed","non","wac","nut","why","bye","lye","oct","old","fin","feb","chi","sap","owl","log","tod","dot","bow","fob","for","joe","ivy","fan","age","fax","hip","jib","mel","hus","sob","ifs","tab","ara","dab","jag","jar","arm","lot","tom","sax","tex","yum","pei","wen","wry","ire","irk","far","mew","wit","doe","gas","rte","ian","pot","ask","wag","hag","amy","nag","ron","soy","gin","don","tug","fay","vic","boo","nam","ave","buy","sop","but","orb","fen","paw","his","sub","bob","yea","oft","inn","rod","yam","pew","web","hod","hun","gyp","wei","wis","rob","gad","pie","mon","dog","bib","rub","ere","dig","era","cat","fox","bee","mod","day","apr","vie","nev","jam","pam","new","aye","ani","and","ibm","yap","can","pyx","tar","kin","fog","hum","pip","cup","dye","lyx","jog","nun","par","wan","fey","bus","oak","bad","ats","set","qom","vat","eat","pus","rev","axe","ion","six","ila","lao","mom","mas","pro","few","opt","poe","art","ash","oar","cap","lop","may","shy","rid","bat","sum","rim","fee","bmw","sky","maj","hue","thy","ava","rap","den","fla","auk","cox","ibo","hey","saw","vim","sec","ltd","you","its","tat","dew","eva","tog","ram","let","see","zit","maw","nix","ate","gig","rep","owe","ind","hog","eve","sam","zoo","any","dow","cod","bed","vet","ham","sis","hex","via","fir","nod","mao","aug","mum","hoe","bah","hal","keg","hew","zed","tow","gog","ass","dem","who","bet","gos","son","ear","spy","kit","boy","due","sen","oaf","mix","hep","fur","ada","bin","nil","mia","ewe","hit","fix","sad","rib","eye","hop","haw","wax","mid","tad","ken","wad","rye","pap","bog","gut","ito","woe","our","ado","sin","mad","ray","hon","roy","dip","hen","iva","lug","asp","hui","yak","bay","poi","yep","bun","try","lad","elm","nat","wyo","gym","dug","toe","dee","wig","sly","rip","geo","cog","pas","zen","odd","nan","lay","pod","fit","hem","joy","bum","rio","yon","dec","leg","put","sue","dim","pet","yaw","nub","bit","bur","sid","sun","oil","red","doc","moe","caw","eel","dix","cub","end","gem","off","yew","hug","pop","tub","sgt","lid","pun","ton","sol","din","yup","jab","pea","bug","gag","mil","jig","hub","low","did","tin","get","gte","sox","lei","mig","fig","lon","use","ban","flo","nov","jut","bag","mir","sty","lap","two","ins","con","ant","net","tux","ode","stu","mug","cad","nap","gun","fop","tot","sow","sal","sic","ted","wot","del","imp","cob","way","ann","tan","mci","job","wet","ism","err","him","all","pad","hah","hie","aim","ike","jed","ego","mac","baa","min","com","ill","was","cab","ago","ina","big","ilk","gal","tap","duh","ola","ran","lab","top","gob","hot","ora","tia","kip","han","met","hut","she","sac","fed","goo","tee","ell","not","act","gil","rut","ala","ape","rig","cid","god","duo","lin","aid","gel","awl","lag","elf","liz","ref","aha","fib","oho","tho","her","nor","ace","adz","fun","ned","coo","win","tao","coy","van","man","pit","guy","foe","hid","mai","sup","jay","hob","mow","jot","are","pol","arc","lax","aft","alb","len","air","pug","pox","vow","got","meg","zoe","amp","ale","bud","gee","pin","dun","pat","ten","mob"}; +// List wordList = new ArrayList<>(); +// wordList.addAll(Arrays.asList(words)); + System.out.println(solution.findLadders(beginWord, endWord, Arrays.asList(words))); + } + + @Test + public void test4() { + Solution solution = new Solution(); + String beginWord = "hit"; + String endWord = "cog"; + List wordList = new LinkedList<>(Arrays.asList("hot", "dot", "dog", "lot", "log")); + System.out.println(solution.findLadders(beginWord, endWord, wordList)); + } +} diff --git a/[0126][Word Ladder II]/src/Solution.java b/[0126][Word Ladder II]/src/Solution.java new file mode 100644 index 0000000..bc6ce38 --- /dev/null +++ b/[0126][Word Ladder II]/src/Solution.java @@ -0,0 +1,130 @@ +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; +import java.util.Set; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-20 08:42 + **/ +public class Solution { + /** + *
+     * Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:
+     *
+     * Only one letter can be changed at a time
+     * Each transformed word must exist in the word list. Note that beginWord is not a transformed word.
+     * Note:
+     *
+     * Return an empty list if there is no such transformation sequence.
+     * All words have the same length.
+     * All words contain only lowercase alphabetic characters.
+     * You may assume no duplicates in the word list.
+     * You may assume beginWord and endWord are non-empty and are not the same.
+     * Example 1:
+     *
+     * Input:
+     * beginWord = "hit",
+     * endWord = "cog",
+     * wordList = ["hot","dot","dog","lot","log","cog"]
+     *
+     * Output:
+     * [
+     *   ["hit","hot","dot","dog","cog"],
+     *   ["hit","hot","lot","log","cog"]
+     * ]
+     * Example 2:
+     *
+     * Input:
+     * beginWord = "hit"
+     * endWord = "cog"
+     * wordList = ["hot","dot","dog","lot","log"]
+     *
+     * Output: []
+     *
+     * Explanation: The endWord "cog" is not in wordList, therefore no possible transformation.
+     *
+     * 使用了图的遍历
+     * https://www.cnblogs.com/splash/p/4102786.html
+     * 
+ * + * @param beginWord + * @param endWord + * @param wordList + * @return + */ + HashMap> nodeSet = new HashMap<>(); + + public List> findLadders(String start, String end, List wordList) { + Set wordDict = new HashSet<>(wordList); + + List> result = new ArrayList>(); + + if (!wordDict.contains(end)) { + return result; + } + + Queue q = new LinkedList(); + HashSet hs = new HashSet(); + HashMap dist = new HashMap(); + q.add(start); + nodeSet.put(start, new ArrayList()); + nodeSet.put(end, new ArrayList()); + dist.put(start, 1); + + while (!q.isEmpty()) { + String temp = q.poll(); + int l = dist.get(temp); + hs.add(temp); + for (int i = 0; i < temp.length(); i++) { + for (char c = 'a'; c <= 'z'; c++) { + if (temp.charAt(i) == c) { + continue; + } + StringBuilder sb = new StringBuilder(temp); + sb.setCharAt(i, c); + String next = sb.toString(); + if (next.equals(end)) { + if (!dist.containsKey(end)) { + dist.put(end, l + 1); + nodeSet.get(end).add(temp); + } else if (dist.get(end) == l + 1) { + nodeSet.get(end).add(temp); + } + } else if (wordDict.contains(next) && !hs.contains(next)) { + if (!dist.containsKey(next)) { + q.add(next); + dist.put(next, l + 1); + ArrayList arr = new ArrayList(); + arr.add(temp); + nodeSet.put(next, arr); + } else if (dist.get(next) == l + 1) { + nodeSet.get(next).add(temp); + } + } + } + } + } + List path = new ArrayList(); + path.add(end); + + collect(start, result, path, nodeSet.get(end)); + return result; + } + + public void collect(String start, List> re, List path, ArrayList prevNodes) { + for (int i = 0; i < prevNodes.size(); i++) { + path.add(0, prevNodes.get(i)); + if (prevNodes.get(i).equals(start)) { + List pathCopy = new ArrayList(path); + re.add(pathCopy); + } else { + collect(start, re, path, nodeSet.get(prevNodes.get(i))); + } + path.remove(0); + } + } +} diff --git a/[0126][Word Ladder II]/src/Solution2.java b/[0126][Word Ladder II]/src/Solution2.java new file mode 100644 index 0000000..7315d8d --- /dev/null +++ b/[0126][Word Ladder II]/src/Solution2.java @@ -0,0 +1,113 @@ +import java.util.Deque; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-20 08:42 + **/ +public class Solution2 { + /** + *
+     * Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:
+     *
+     * Only one letter can be changed at a time
+     * Each transformed word must exist in the word list. Note that beginWord is not a transformed word.
+     * Note:
+     *
+     * Return an empty list if there is no such transformation sequence.
+     * All words have the same length.
+     * All words contain only lowercase alphabetic characters.
+     * You may assume no duplicates in the word list.
+     * You may assume beginWord and endWord are non-empty and are not the same.
+     * Example 1:
+     *
+     * Input:
+     * beginWord = "hit",
+     * endWord = "cog",
+     * wordList = ["hot","dot","dog","lot","log","cog"]
+     *
+     * Output:
+     * [
+     *   ["hit","hot","dot","dog","cog"],
+     *   ["hit","hot","lot","log","cog"]
+     * ]
+     * Example 2:
+     *
+     * Input:
+     * beginWord = "hit"
+     * endWord = "cog"
+     * wordList = ["hot","dot","dog","lot","log"]
+     *
+     * Output: []
+     *
+     * Explanation: The endWord "cog" is not in wordList, therefore no possible transformation.
+     *
+     * 使用了深度优化遍历方案,会超时
+     * 
+ * + * @param beginWord + * @param endWord + * @param wordList + * @return + */ + public List> findLadders(String beginWord, String endWord, List wordList) { + Set wordDict = new HashSet<>(wordList); + List> result = new LinkedList<>(); + Deque current = new LinkedList<>(); + findLadders(beginWord, endWord, wordDict, current, result); + for(List r: result) { + r.add(0, beginWord); + } + return result; + } + + private void findLadders(String beginWord, String endWord, Set wordDict, Deque current, List> result) { + + if (beginWord.equals(endWord)) { + + // 还没有结果,或者有的最优解,就添加结果 + if (result.isEmpty() || result.get(0).size() == current.size()) { + result.add(new LinkedList<>(current)); + } + // 当前解不是最优解,记录最优化解 + else if (result.get(0).size() > current.size()) { + result.clear(); + result.add(new LinkedList<>(current)); + } + + return; + } + + // 已经找到至少一个可能的最优解,当前还没有找到最优化解,但是转换次数已经等于目前找到的最优化解的次数, + // 目前的方案一定不存在最优化解 + if (!result.isEmpty() && current.size() >= result.get(0).size()) { + return; + } + + char[] chars = beginWord.toCharArray(); + + for (int i = 0; i < chars.length; i++) { + for (char ch = 'a'; ch <= 'z'; ch++) { + char temp = chars[i]; + chars[i] = ch; + String s = new String(chars); + + if (wordDict.contains(s) ) { + wordDict.remove(s); + current.add(s); + + findLadders(s, endWord, wordDict, current, result); + // 还原 + wordDict.add(s); + current.remove(s); + } + + // 还原 + chars[i] = temp; + } + } + } +} diff --git a/[0126][Word Ladder II]/src/Solution3.java b/[0126][Word Ladder II]/src/Solution3.java new file mode 100644 index 0000000..906bc48 --- /dev/null +++ b/[0126][Word Ladder II]/src/Solution3.java @@ -0,0 +1,128 @@ +import java.util.Deque; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-20 08:42 + **/ +public class Solution3 { + /** + *
+     * Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:
+     *
+     * Only one letter can be changed at a time
+     * Each transformed word must exist in the word list. Note that beginWord is not a transformed word.
+     * Note:
+     *
+     * Return an empty list if there is no such transformation sequence.
+     * All words have the same length.
+     * All words contain only lowercase alphabetic characters.
+     * You may assume no duplicates in the word list.
+     * You may assume beginWord and endWord are non-empty and are not the same.
+     * Example 1:
+     *
+     * Input:
+     * beginWord = "hit",
+     * endWord = "cog",
+     * wordList = ["hot","dot","dog","lot","log","cog"]
+     *
+     * Output:
+     * [
+     *   ["hit","hot","dot","dog","cog"],
+     *   ["hit","hot","lot","log","cog"]
+     * ]
+     * Example 2:
+     *
+     * Input:
+     * beginWord = "hit"
+     * endWord = "cog"
+     * wordList = ["hot","dot","dog","lot","log"]
+     *
+     * Output: []
+     *
+     * Explanation: The endWord "cog" is not in wordList, therefore no possible transformation.
+     *
+     * 使用了广度优化遍历方案,会超时
+     * 
+ * + * @param beginWord + * @param endWord + * @param wordList + * @return + */ + public List> findLadders(String beginWord, String endWord, List wordList) { + + + Set wordDict = new HashSet<>(wordList); + List> result = new LinkedList<>(); + // 用于保存所有中间结果 + Deque> paths = new LinkedList<>(); + + + Deque deque = new LinkedList<>(); + deque.addLast(beginWord); + paths.addLast(deque); + + boolean find = false; + + while (!paths.isEmpty() && !find) { + // 先遍历看是否找到结果,如果找到了,一定是最优化解 + for (Deque path : paths) { + if (path.getLast().equals(endWord)) { + result.add(new LinkedList<>(path)); + find = true; + } + } + + // find表示已经找到了 + // paths.getFirst().size() >=beginWord.length()说明不可能找到结果,path最 + System.out.println(paths.getFirst().size()); + if (find || paths.getFirst().size() >= wordDict.size()) { + break; + } + + // TODO 什么时候判断找不到,path中可能形成环 + + + // 没有找到最优化解,构建下一层 + for (int k = paths.size(); k > 0; k--) { + + // 取路径的最后一个元素 + Deque path = paths.removeFirst(); + String s = path.getLast(); + + // 当前路径下,还可以使用的字词 + Set set = new HashSet<>(wordDict); + set.removeAll(path); + + System.out.println(set); + + // 找出当前层的每个元素经过一次变化后,是否在剩余的wordDict中找到, + // 如果找到就放到下一层的处理中 + char[] chars = s.toCharArray(); + for (int i = 0; i < beginWord.length(); i++) { + for (char j = 'a'; j <= 'z'; j++) { + char temp = chars[i]; + chars[i] = j; + String t = new String(chars); + + // 一次变换后可以找到单词,放到下一层处理中 + if (set.contains(t) && !t.equals(s)) { + path.addLast(t); + paths.addLast(new LinkedList<>(path)); + path.removeLast(); + } + // 还原 + chars[i] = temp; + } + } + + } + } + + return result; + } +} diff --git a/[0127][Word Ladder]/[0127][Word Ladder].iml b/[0127][Word Ladder]/[0127][Word Ladder].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0127][Word Ladder]/[0127][Word Ladder].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0127][Word Ladder]/[0127][WordLadder].iml b/[0127][Word Ladder]/[0127][WordLadder].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0127][Word Ladder]/[0127][WordLadder].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0127][Word Ladder]/src/Main.java b/[0127][Word Ladder]/src/Main.java new file mode 100644 index 0000000..2a6d29a --- /dev/null +++ b/[0127][Word Ladder]/src/Main.java @@ -0,0 +1,21 @@ +import org.junit.Assert; +import org.junit.Test; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-20 08:17 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + String beginWord = "hit"; + String endWord = "cog"; + List wordList = new LinkedList<>(Arrays.asList("hot", "dot", "dog", "lot", "log", "cog")); + Assert.assertEquals(5, solution.ladderLength(beginWord, endWord, wordList)); + } +} diff --git a/[0127][Word Ladder]/src/Solution.java b/[0127][Word Ladder]/src/Solution.java new file mode 100644 index 0000000..5366850 --- /dev/null +++ b/[0127][Word Ladder]/src/Solution.java @@ -0,0 +1,100 @@ +import java.util.Deque; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +/** + * Author: + * Date: 2015-06-20 + * Time: 08:11 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Given two words (beginWord and endWord), and a dictionary, find the length
+     * of shortest transformation sequence from beginWord to endWord, such that:
+     *
+     *   - Only one letter can be changed at a time
+     *   - Each intermediate word must exist in the dictionary
+     *
+     * For example,
+     *
+     * Given:
+     * start = "hit"
+     * end = "cog"
+     * dict = ["hot","dot","dog","lot","log"]
+     * As one shortest transformation is "hit" -> "hot" -> "dot" -> "dog" -> "cog",
+     * return its length 5.
+     *
+     * Note:
+     *   - Return 0 if there is no such transformation sequence.
+     *   - All words have the same length.
+     *   - All words contain only lowercase alphabetic characters.
+     *
+     * Ŀ⣺
+     * ʣbeginWordendWordһֵ䣬ҴbeginWordת͵endWord̳ȣ
+     *   - һֻһĸԱı
+     *   - ÿмֱڴʵ
+     *
+     * ע⣺
+     *   - ı任У0
+     *   - еʾͬijȡ
+     *   - еֻСдĸַ
+     *
+     * ˼·
+     * Ż
+     * 
+ * + * @param beginWord + * @param endWord + * @param wordList + * @return + */ + public int ladderLength(String beginWord, String endWord, List wordList) { + + Set wordDict = new HashSet<>(wordList); + + char[] chars; + Deque deque = new LinkedList<>(); + deque.addLast(beginWord); + int result = 0; + String s; + String t; + while (!deque.isEmpty()) { + + // ǰ + for (int k = deque.size(); k > 0; k--) { + s = deque.removeFirst(); + + if (s.equalsIgnoreCase(endWord)) { + return result + 1; + } + + // ҳǰÿԪؾһα仯ǷʣwordDictҵ + // ҵͷŵһĴ + chars = s.toCharArray(); + for (int i = 0; i < beginWord.length(); i++) { + for (char j = 'a'; j <= 'z'; j++) { + char temp = chars[i]; + chars[i] = j; + t = new String(chars); + // һα任ҵʣŵһ㴦УwordDictɾ¼ + if (wordDict.contains(t) && !t.equals(s)) { + deque.addLast(t); + wordDict.remove(t); + } + // ԭ + chars[i] = temp; + } + } + } + + + result++; + } + + return 0; + } +} diff --git a/[0128][Longest Consecutive Sequence]/[0128][Longest Consecutive Sequence].iml b/[0128][Longest Consecutive Sequence]/[0128][Longest Consecutive Sequence].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0128][Longest Consecutive Sequence]/[0128][Longest Consecutive Sequence].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0128][Longest Consecutive Sequence]/src/Main.java b/[0128][Longest Consecutive Sequence]/src/Main.java new file mode 100644 index 0000000..d6d2e5c --- /dev/null +++ b/[0128][Longest Consecutive Sequence]/src/Main.java @@ -0,0 +1,17 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-14 15:02 + **/ +public class Main { + @Test + public void test() { + int[] nums = {100, 4, 200, 1, 3, 2}; + + Solution solution = new Solution(); + + Assert.assertEquals(4, solution.longestConsecutive(nums)); + } +} diff --git a/[0128][Longest Consecutive Sequence]/src/Solution.java b/[0128][Longest Consecutive Sequence]/src/Solution.java new file mode 100644 index 0000000..b41b5ec --- /dev/null +++ b/[0128][Longest Consecutive Sequence]/src/Solution.java @@ -0,0 +1,59 @@ +import java.util.HashSet; +import java.util.Set; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-14 14:48 + **/ +class Solution { + /** + *
+     * Given an unsorted array of integers, find the length of the longest consecutive elements sequence.
+     *
+     * Your algorithm should run in O(n) complexity.
+     *
+     * Example:
+     *
+     * Input: [100, 4, 200, 1, 3, 2]
+     * Output: 4
+     * Explanation: The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4.
+     *
+     * 这道题要求求最长连续序列,并给定了O(n)复杂度限制,我们的思路是,使用一个集合HashSet存入所有的数字,
+     * 然后遍历数组中的每个数字,如果其在集合中存在,那么将其移除,然后分别用两个变量pre和next算出其前一个
+     * 数跟后一个数,然后在集合中循环查找,如果pre在集合中,那么将pre移除集合,然后pre再自减1,直至pre不在
+     * 集合之中,对next采用同样的方法,那么next-pre-1就是当前数字的最长连续序列,更新res即可。这里再说下,
+     * 为啥当检测某数字在集合中存在当时候,都要移除数字。这是为了避免大量的重复计算,就拿题目中的例子来说吧,
+     * 我们在遍历到4的时候,会向下遍历3,2,1,如果都不移除数字的话,遍历到1的时候,还会遍历2,3,4。同样,
+     * 遍历到3的时候,向上遍历4,向下遍历2,1,等等等。如果数组中有大量的连续数字的话,那么就有大量的重复计算,
+     * 十分的不高效,所以我们要从HashSet中移除数字
+     * 
+ * + * @param nums + * @return + */ + public int longestConsecutive(int[] nums) { + int res = 0; + Set set = new HashSet<>(); + + for (int i : nums) { + set.add(i); + } + + for (int i : nums) { + if (set.remove(i)) { + int prev = i - 1; + int next = i + 1; + while (set.remove(prev)) { + --prev; + } + while (set.remove(next)) { + ++next; + } + + res = Math.max(res, next - prev - 1); + } + } + + return res; + } +} diff --git a/[0129][Sum Root To Leaf Numbers]/[0129][Sum Root To Leaf Numbers].iml b/[0129][Sum Root To Leaf Numbers]/[0129][Sum Root To Leaf Numbers].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0129][Sum Root To Leaf Numbers]/[0129][Sum Root To Leaf Numbers].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0129][Sum Root To Leaf Numbers]/[0129][SumRootToLeafNumbers].iml b/[0129][Sum Root To Leaf Numbers]/[0129][SumRootToLeafNumbers].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0129][Sum Root To Leaf Numbers]/[0129][SumRootToLeafNumbers].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0129][Sum Root To Leaf Numbers]/src/Solution.java b/[0129][Sum Root To Leaf Numbers]/src/Solution.java new file mode 100644 index 0000000..5640b7f --- /dev/null +++ b/[0129][Sum Root To Leaf Numbers]/src/Solution.java @@ -0,0 +1,56 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 19:13 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + private int result = 0; // ¼ܵĽ + private int num = 0; // ǸҶӵ + + /** + *
+     * ԭ
+     * Given a binary tree containing digits from 0-9 only, each root-to-leaf path
+     * could represent a number.
+     * An example is the root-to-leaf path 1->2->3 which represents the number 123.
+     * Find the total sum of all root-to-leaf numbers.
+     * For example,
+     *
+     *   1
+     *  / \
+     * 2   3
+     *
+     * The root-to-leaf path 1->2 represents the number 12.
+     * The root-to-leaf path 1->3 represents the number 13.
+     * Return the sum = 12 + 13 = 25.
+     * Ŀ
+     * һÿֵ0-9Ҷһ֣еĸҶɵֵĺ͡
+     *
+     * ˼·
+     * ûݷ
+     * 
+ * + * @param root + * @return + */ + public int sumNumbers(TreeNode root) { + sum(root); + return result; + } + + private void sum(TreeNode root) { + if (root != null) { + num = num * 10 + root.val; + + // Ѿ˸ + if (root.left == null && root.right == null) { + result += num; + } + + sum(root.left); + sum(root.right); + num /= 10; + } + } +} diff --git a/[0129][Sum Root To Leaf Numbers]/src/TreeNode.java b/[0129][Sum Root To Leaf Numbers]/src/TreeNode.java new file mode 100644 index 0000000..9f97f8f --- /dev/null +++ b/[0129][Sum Root To Leaf Numbers]/src/TreeNode.java @@ -0,0 +1,15 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 19:13 + * Declaration: All Rights Reserved !!! + */ +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} diff --git a/[0130][Surrounded Regions]/[0130][Surrounded Regions].iml b/[0130][Surrounded Regions]/[0130][Surrounded Regions].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0130][Surrounded Regions]/[0130][Surrounded Regions].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0130][Surrounded Regions]/[0130][SurroundedRegions].iml b/[0130][Surrounded Regions]/[0130][SurroundedRegions].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0130][Surrounded Regions]/[0130][SurroundedRegions].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0130][Surrounded Regions]/src/Main.java b/[0130][Surrounded Regions]/src/Main.java new file mode 100644 index 0000000..6c22ca8 --- /dev/null +++ b/[0130][Surrounded Regions]/src/Main.java @@ -0,0 +1,81 @@ +import org.junit.Test; + +/** + * Author: + * Date: 2015-06-22 + * Time: 10:02 + * Declaration: All Rights Reserved !!! + */ +public class Main { + + @Test + public void test01() { + Solution solution = new Solution(); + char[][] board = { + "XXXX".toCharArray(), + "XOOX".toCharArray(), + "XXOX".toCharArray(), + "XOXX".toCharArray() + }; + + solution.solve(board); + + for (char[] line : board) { + System.out.println(new String(line)); + } + System.out.println(); + } + + @Test + public void test02() { + Solution solution = new Solution(); + char[][] board = { + "XOXX".toCharArray(), + "OXOX".toCharArray(), + "XOXO".toCharArray(), + "OXOX".toCharArray(), + "XOXO".toCharArray(), + "OXOX".toCharArray() + }; + + solution.solve(board); + + for (char[] line : board) { + System.out.println(new String(line)); + } + System.out.println(); + } + + @Test + public void test03() { + Solution solution = new Solution(); + char[][] board = { + "OO".toCharArray(), + "OO".toCharArray() + }; + + solution.solve(board); + + for (char[] line : board) { + System.out.println(new String(line)); + } + System.out.println(); + } + + @Test + public void test04() { + Solution solution = new Solution(); + char[][] board = { + "OOO".toCharArray(), + "OOO".toCharArray(), + "OOO".toCharArray() + }; + + solution.solve(board); + + for (char[] line : board) { + System.out.println(new String(line)); + } + System.out.println(); + } +} diff --git a/[0130][Surrounded Regions]/src/Solution.java b/[0130][Surrounded Regions]/src/Solution.java new file mode 100644 index 0000000..636f0a0 --- /dev/null +++ b/[0130][Surrounded Regions]/src/Solution.java @@ -0,0 +1,83 @@ +/** + * Author: + * Date: 2015-06-22 + * Time: 08:51 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.
+     * A region is captured by flipping all 'O's into 'X's in that surrounded region.
+     *
+     * For example,
+     * X X X X
+     * X O O X
+     * X X O X
+     * X O X X
+     *
+     * After running your function, the board should be:
+     * X X X X
+     * X X X X
+     * X X X X
+     * X O X X
+     *
+     * Ŀ⣺
+     * һά񣬰'X''O'ԱXΧOX
+     * ˼·
+     * ȶȱķʽҳXΧOΪ$
+     * 
+ * + * @param board + */ + void solve(char[][] board) { + + // У + if (board == null || board.length < 1 || board[0].length < 1) { + return; + } + + // һк + for (int i = 0; i < board[0].length; i++) { + dfs(board, 0, i); + dfs(board, board.length - 1, i); + } + + // һкһ + for (int i = 1; i < board.length - 1; i++) { + dfs(board, i, 0); + dfs(board, i, board[0].length - 1); + } + + + + for (int i = 0; i < board.length; ++i) { + for (int j = 0; j < board[i].length; ++j) { + if (board[i][j] == 'O') { + board[i][j] = 'X'; + } + if (board[i][j] == '$') { + board[i][j] = 'O'; + } + } + } + } + + void dfs(char[][] board, int i, int j) { + if (board[i][j] == 'O') { + board[i][j] = '$'; + if (i > 0 && board[i - 1][j] == 'O') { + dfs(board, i - 1, j); + } + if (j < board[i].length - 1 && board[i][j + 1] == 'O') { + dfs(board, i, j + 1); + } + if (i < board.length - 1 && board[i + 1][j] == 'O') { + dfs(board, i + 1, j); + } + if (j > 1 && board[i][j - 1] == 'O') { + dfs(board, i, j - 1); + } + } + } +} diff --git a/[0130][Surrounded Regions]/src/Solution2.java b/[0130][Surrounded Regions]/src/Solution2.java new file mode 100644 index 0000000..3308a10 --- /dev/null +++ b/[0130][Surrounded Regions]/src/Solution2.java @@ -0,0 +1,258 @@ +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-06-22 + * Time: 08:51 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + /** + *
+     * Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.
+     * A region is captured by flipping all 'O's into 'X's in that surrounded region.
+     *
+     * For example,
+     * X X X X
+     * X O O X
+     * X X O X
+     * X O X X
+     *
+     * After running your function, the board should be:
+     * X X X X
+     * X X X X
+     * X X X X
+     * X O X X
+     *
+     * Ŀ⣺
+     * һά񣬰'X''O'ԱXΧOX
+     * ˼·
+     * ùȱķʽҲԲóȵķʽջ,dzеıΧĵ㣬ʣµľDzΧĵ
+     * 
+ * + * @param board + */ + //////////////////////////////////////////////////////////////////////////////////////////////// + // ùȶȱķʽҳеġΧĵ + //////////////////////////////////////////////////////////////////////////////////////////////// + public void solve(char[][] board) { + // У + if (board == null || board.length < 1 || board[0].length < 1) { + return; + } + + boolean[][] visited = new boolean[board.length][board[0].length]; + // ʱΧһȦԪ + List round = new LinkedList<>(); + // + for (int col = 0; col < board[0].length; col++) { + // УҵOҵδʹ + if (!visited[0][col] && board[0][col] == 'O') { + round.clear(); + round.add(new Coordinate(0, col)); + bfs(board, visited, round); + } + } + + // ײ + for (int col = 0; col < board[0].length; col++) { + // УҵOҵδʹ + if (!visited[board.length - 1][col] && board[board.length - 1][col] == 'O') { + round.clear(); + round.add(new Coordinate(board.length - 1, col)); + bfs(board, visited, round); + } + } + + // + for (int row = 1; row < board.length - 1; row++) { + // УҵOҵδʹ + if (!visited[row][0] && board[row][0] == 'O') { + round.clear(); + round.add(new Coordinate(row, 0)); + bfs(board, visited, round); + } + } + + // ұ + for (int row = 1; row < board.length - 1; row++) { + // УҵOҵδʹ + if (!visited[row][board[0].length - 1] && board[row][board[0].length - 1] == 'O') { + round.clear(); + round.add(new Coordinate(row, board[0].length - 1)); + bfs(board, visited, round); + } + } + + // + for (int i = 0; i < board.length; i++) { + for (int j = 0; j < board[0].length; j++) { + // δʹֿܣһX㣬ڶO㣬OһDZXΧ + // ʱδʹĵΪXȷ + if (!visited[i][j]) { + board[i][j] = 'X'; + } + } + } + } + + /** + * ȣҲΧĵ + * + * @param board ά + * @param visited ʱ + * @param round ʱΧһȦԪ + */ + public void bfs(char[][] board, boolean[][] visited, List round) { + Coordinate c; + while (round.size() > 0) { + c = round.remove(0); + if (c.x >= 0 && c.x < board.length && c.y >= 0 && c.y < board[0].length && board[c.x][c.y] == 'O' && !visited[c.x][c.y]) { + visited[c.x][c.y] = true; + round.add(new Coordinate(c.x - 1, c.y)); + round.add(new Coordinate(c.x, c.y + 1)); + round.add(new Coordinate(c.x + 1, c.y)); + round.add(new Coordinate(c.x, c.y - 1)); + } + } + } + + //////////////////////////////////////////////////////////////////////////////////////////////// + // ùȶȱķʽҳеıΧĵ㣬ұǻᳬʱ + //////////////////////////////////////////////////////////////////////////////////////////////// + public void solve2(char[][] board) { + // У + if (board == null || board.length < 1 || board[0].length < 1) { + return; + } + + boolean[][] visited = new boolean[board.length][board[0].length]; + + // ʱΧһȦԪ + List round = new LinkedList<>(); + // Ԫ + List all = new LinkedList<>(); + + for (int i = 0; i < board.length; i++) { + for (int j = 0; j < board[0].length; j++) { + if (!visited[i][j] && board[i][j] == 'O') { + // һȦԪ + round.add(new Coordinate(i, j)); + boolean result = bfs(board, visited, round, all); + // һOڣҲڱ߽ + if (result) { + // ñ + for (Coordinate c : all) { + board[c.x][c.y] = 'X'; + } + } + + // Ԫ + round.clear(); + all.clear(); + } + } + } + + } + + /** + * ȱ + * + * @param board ά + * @param visited ʱ + * @param round ʱΧһȦԪ + * @param all Ԫ + * @return trueOڣҲڱ߽ϣXܷtrue + */ + public boolean bfs(char[][] board, boolean[][] visited, List round, List all) { + boolean result = true; + int size = round.size(); + Coordinate c; + while (size > 0) { + size--; + + // ȡԪ + c = round.remove(0); + // ӵ¼Ԫؼ + all.add(c); + // Ѿʹ + visited[c.x][c.y] = true; + // жcǷOڵ + result &= isInner(board, c.x, c.y); + + // cһǷOûзʹӵround + if (isO(board, c.x - 1, c.y) && !visited[c.x - 1][c.y]) { + round.add(new Coordinate(c.x - 1, c.y)); + } + + // cһǷOûзʹӵround + if (isO(board, c.x, c.y + 1) && !visited[c.x][c.y + 1]) { + round.add(new Coordinate(c.x, c.y + 1)); + } + + // cһǷOûзʹӵround + if (isO(board, c.x + 1, c.y) && !visited[c.x + 1][c.y]) { + round.add(new Coordinate(c.x + 1, c.y)); + } + + // cһǷOûзʹӵround + if (isO(board, c.x, c.y - 1) && !visited[c.x][c.y - 1]) { + round.add(new Coordinate(c.x, c.y - 1)); + } + } + + if (round.size() > 0) { + return bfs(board, visited, round, all) && result; + } else { + return result; + } + + } + + /** + * жϵڶάڲҲڱ߽ + * + * @param board ά + * @param x + * @param y + * @return true + */ + public boolean isInner(char[][] board, int x, int y) { + return x > 0 && x < board.length - 1 && y > 0 && y < board[0].length - 1; + } + + /** + * жϵǷO + * + * @param board ά + * @param x + * @param y + * @return true + */ + public boolean isO(char[][] board, int x, int y) { + return x >= 0 && x < board.length && y >= 0 && y < board[0].length && board[x][y] == 'O'; + } + + /** + * + */ + public static class Coordinate { + private int x; + private int y; + + public Coordinate() { + } + + public Coordinate(int x, int y) { + this.x = x; + this.y = y; + } + + @Override + public String toString() { + return "(" + x + ", " + y + ")"; + } + } +} diff --git a/[0131][Palindrome Partitioning]/[0131][Palindrome Partitioning].iml b/[0131][Palindrome Partitioning]/[0131][Palindrome Partitioning].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0131][Palindrome Partitioning]/[0131][Palindrome Partitioning].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0131][Palindrome Partitioning]/src/Main.java b/[0131][Palindrome Partitioning]/src/Main.java new file mode 100644 index 0000000..8266432 --- /dev/null +++ b/[0131][Palindrome Partitioning]/src/Main.java @@ -0,0 +1,15 @@ +import org.junit.Test; + +import java.util.Arrays; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-21 18:36 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + System.out.println(solution.partition("aab")); + } +} diff --git a/[0131][Palindrome Partitioning]/src/Solution.java b/[0131][Palindrome Partitioning]/src/Solution.java new file mode 100644 index 0000000..e3efdab --- /dev/null +++ b/[0131][Palindrome Partitioning]/src/Solution.java @@ -0,0 +1,70 @@ +import java.util.Deque; +import java.util.LinkedList; +import java.util.List; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-21 18:29 + **/ +public class Solution { + /** + *
+     * Given a string s, partition s such that every substring of the partition is a palindrome.
+     *
+     * Return all possible palindrome partitioning of s.
+     *
+     * Example:
+     *
+     * Input: "aab"
+     * Output:
+     * [
+     *   ["aa","b"],
+     *   ["a","a","b"]
+     * ]
+     *
+     * 解决方案:可以使用回溯法
+     * TODO : 可以构建一个回文表,再进行判定
+     * 
+ * + * @param s + * @return + */ + public List> partition(String s) { + List> result = new LinkedList<>(); + Deque current = new LinkedList<>(); + + partition(s, 0, current, result); + + return result; + } + + private void partition(String s, int index, Deque current, List> result) { + if (index == s.length()) { + result.add(new LinkedList<>(current)); + return; + } + + for (int i = index; i < s.length(); i++) { + String t = s.substring(index, i + 1); + if (isPalindrome(s, index, i)) { + current.addLast(t); + partition(s, i + 1, current, result); + // 还原 + current.removeLast(); + } + } + } + + private boolean isPalindrome(String s, int start, int end) { + while (start < end) { + + if (s.charAt(start) != s.charAt(end)) { + return false; + } else { + start++; + end--; + } + } + return true; + } +} diff --git a/[0134][Gas Station]/[0134][Gas Station].iml b/[0134][Gas Station]/[0134][Gas Station].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0134][Gas Station]/[0134][Gas Station].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0134][Gas Station]/[0134][GasStation].iml b/[0134][Gas Station]/[0134][GasStation].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0134][Gas Station]/[0134][GasStation].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0134][Gas Station]/src/Main.java b/[0134][Gas Station]/src/Main.java new file mode 100644 index 0000000..250a219 --- /dev/null +++ b/[0134][Gas Station]/src/Main.java @@ -0,0 +1,17 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-16 11:06 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + int[] gas = {1, 2, 3, 4, 5}; + int[] cost = {3, 4, 5, 1, 2}; + int pos = solution.canCompleteCircuit(gas, cost); + Assert.assertEquals(3, pos); + } +} diff --git a/[0134][Gas Station]/src/Solution.java b/[0134][Gas Station]/src/Solution.java new file mode 100644 index 0000000..213926c --- /dev/null +++ b/[0134][Gas Station]/src/Solution.java @@ -0,0 +1,146 @@ +/** + * Author: + * Date: 2015-06-21 + * Time: 10:11 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * There are N gas stations along a circular route, where the amount
+     * of gas at station i is gas[i].
+     *
+     * You have a car with an unlimited gas tank and it costs cost[i] of gas
+     * to travel from station i to its next station (i+1). You begin the journey
+     * with an empty tank at one of the gas stations.
+     *
+     * Return the starting gas station's index if you can travel around the
+     * circuit once, otherwise return -1.
+     *
+     * Note:
+     *   - The solution is guaranteed to be unique.
+     *
+     * Ŀ⣺
+     * ػ·Nվڳվigas[i]
+     * гޣӼվiһվվi+1Ҫcost[i]塣
+     * 㿪ʼóʱǿյġصʼվָѡһ㿪ʼΣ
+     * ΧһΣͷؿʼļվ򷵻-1
+     *
+     * ע⣺
+     *   - 𰸱֤Ψһ
+     *
+     * ˼·
+     * վ i վ k ֮ǰȻܱ֤û׶k 󣬼׶ˡ
+     * ô˵ diff[i] + diff[i+1] + ... + diff[k] < 0diff[k]⣬diff[i]
+     * ʼۼӶ >= 0ġҲ˵diff[i] Ҳ >= 0ģʱǻбҪվ i + 1
+     * ϸһ֪ҪǴվ i+1վkûվkͼ
+     * ˣΪټվ i ͡
+     *
+     * ˣǷֵk վ׶i  k Щվ㶼Ϊˣ϶
+     * ֻҪk+1վ㳢Լɣ˽ⷨʱ临ӶȴO(n2) O(2n)֮
+     * O(2n)Ϊk+1վΪʼվȦk֤k+1Ƿ㡣
+     *
+     * ȵȣҪ
+     * ģһ¹̣
+     * a. ʼվ0ʼվ賵վpˣ
+     *      sum1 = diff[0] +diff[1] + ... + diff[p]֪sum1 < 0
+     *
+     * b. ǽp+1Ϊʼվqվֿˣ
+     *      sum2 = diff[p+1] +diff[p+2] + ... + diff[q]֪sum2 < 0
+     *
+     * c. q+1Ϊʼվһֱδѭĩվû׶
+     *      sum3 = diff[q+1] +diff[q+2] + ... + diff[size-1]֪sum3 >= 0
+     *
+     * Ҫ֪ܷ񿪻 q վʵsum3 Ļϣμ diff[0]  diff[q]
+     * sum3ǷС0֮ǰѾ֪ diff[0]  diff[p-1] ·
+     * һֱַǸֻҪsum3 + sum1Ƿ <0֪ܲܿ p+1վˡ
+     * ܴp+1վֻҪsum3 + sum1 + sum2 Ƿ < 0֪ܲܿqվˡ
+     *
+     * Ϊ sum1, sum2  < 0 sum3 + sum1 + sum2 >=0 ô
+     * sum3 + sum1 Ȼ >= 0Ҳ˵ֻҪsum3 + sum1 + sum2 >=0Ȼܿqվ
+     * sum3 + sum1 + sum2 ʵ diffܺ TotalԪѾˡ
+     *  Total ܷ >= 0Ƿվ ֱҪ
+     *
+     * ʱ临ӶȽһO(2n) O(n)
+     * 
+ * + * @param gas + * @param cost + * @return + */ + public int canCompleteCircuit(int[] gas, int[] cost) { + // + if (gas == null || cost == null || gas.length == 0 || gas.length != cost.length) { + return -1; + } + + // ¼ʵʼ + int start = 0; + // ӵĵֵܲ + int total = 0; + // startλÿʼӵĵֵܲ + int sum = 0; + + for (int i = 0; i < gas.length; i++) { + total += (gas[i] - cost[i]); + + // û + if (sum < 0) { + // е + sum = gas[i] - cost[i]; + // ¼µλ + start = i; + } else { + // лͣе + sum += (gas[i] - cost[i]); + } + } + + return total >= 0 ? start : -1; + } + + + /** + * ķᳬʱO(N^2)ʱ临Ӷ + */ + public int canCompleteCircuit2(int[] gas, int[] cost) { + // + if (gas == null || cost == null || gas.length == 0 || gas.length != cost.length) { + return -1; + } + + // ʣµ壬ʼʱΪ0 + int leftGas = 0; + // ʼվ + int start = 0; + // վ + int end = 1; + + // δһ + while (start < gas.length) { + + // һվ + leftGas = gas[start] - cost[start]; + + // ߵһվ + if (leftGas > 0) { + // ¼һվ + end = (start + 1) % gas.length; + + // һֱԵһվͳв + while (start != end && (leftGas += (gas[end] - cost[end])) >= 0) { + end = (end + 1) % gas.length; + } + + // ˵Ѿһ + if (start == end) { + return start; + } + } + + start++; + } + + return -1; + } +} diff --git a/[0135][Candy]/[0135][Candy].iml b/[0135][Candy]/[0135][Candy].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0135][Candy]/[0135][Candy].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0135][Candy]/src/Main.java b/[0135][Candy]/src/Main.java new file mode 100644 index 0000000..54ea1af --- /dev/null +++ b/[0135][Candy]/src/Main.java @@ -0,0 +1,14 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-16 11:37 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + Assert.assertEquals(5, solution.candy(new int[]{1, 0, 2})); + } +} diff --git a/[0135][Candy]/src/Solution.java b/[0135][Candy]/src/Solution.java new file mode 100644 index 0000000..ea602e0 --- /dev/null +++ b/[0135][Candy]/src/Solution.java @@ -0,0 +1,77 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-16 11:27 + **/ +public class Solution { + /** + *
+     * There are N children standing in a line. Each child is assigned a rating value.
+     *
+     * You are giving candies to these children subjected to the following requirements:
+     *
+     * 1. Each child must have at least one candy.
+     * 2. Children with a higher rating get more candies than their neighbors.
+     * What is the minimum candies you must give?
+     *
+     * Example 1:
+     *
+     * Input: [1,0,2]
+     * Output: 5
+     * Explanation: You can allocate to the first, second and third child with 2, 1, 2 candies respectively.
+     * Example 2:
+     *
+     * Input: [1,2,2]
+     * Output: 4
+     * Explanation: You can allocate to the first, second and third child with 1, 2, 1 candies respectively.
+     *              The third child gets 1 candy because it satisfies the above two conditions.
+     * 
+ * + * @param ratings + * @return + */ + public int candy(int[] ratings) { + if (ratings == null || ratings.length < 1) { + return 0; + } + + + int[] increment = new int[ratings.length]; + // 左右各扫描一遍 + for (int i = 1, inc = 1; i < ratings.length; i++) { + // 右边的孩子分数比左边的孩子分数高 + if (ratings[i] > ratings[i - 1]) { + // 右边的孩子比左边的孩子多发至少一个糖果 + increment[i] = increment[i - 1] + 1; + } +// // 右边的孩子分数与左边的孩子分数相等,相等可以少发 +// else if (ratings[i] == ratings[i - 1]) { +// // 右边和左边的孩子增同样多颗糖 +// increment[i] = increment[i - 1]; +// } + // 可以不处理 +// else{ +// increment[i] = 0; +// } + } + + // 从右到左进行处理 + for (int i = ratings.length - 2, inc = 1; i >= 0; i--) { + // 左边的孩子分数比右边高 + if (ratings[i] > ratings[i + 1]) { + increment[i] = Math.max(increment[i], increment[i + 1] + 1); + } + // +// else if (ratings[i] == ratings[i + 1]) { +// // 总是成立了 +// increment[i] = increment[i - 1]; +// } + // ratings[i] < ratings[i + 1] 不需要操作 + } + + int sum = ratings.length; + for (int n : increment) { + sum += n; + } + return sum; + } +} diff --git a/[0136][Single Number]/[0136][Single Number].iml b/[0136][Single Number]/[0136][Single Number].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0136][Single Number]/[0136][Single Number].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0136][Single Number]/src/Solution.java b/[0136][Single Number]/src/Solution.java new file mode 100644 index 0000000..1ec5d37 --- /dev/null +++ b/[0136][Single Number]/src/Solution.java @@ -0,0 +1,35 @@ +/** + * Author: + * Date: 2015-06-18 + * Time: 10:29 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + * Given an array of integers, every element appears twice except for one. + * Find that single one. + * + * Note: Your algorithm should have a linear runtime complexity. + * Could you implement it without using extra memory? + * + * һ飬ÿԪض2γеһҳֻһε + * ע⣺㷨ʱ临ӶȣԲʹöռʵ + * + * ˼·ʹ + * + * @param nums + * @return + */ + public int singleNumber(int[] nums) { + + if (nums == null || nums.length < 1) { + throw new IllegalArgumentException("nums should contain at least one element"); + } + + + for (int i = 1; i< nums.length; i++) { + nums[0] ^= nums[i]; + } + return nums[0]; + } +} diff --git a/[0137][Single Number II]/[0137][Single Number II].iml b/[0137][Single Number II]/[0137][Single Number II].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0137][Single Number II]/[0137][Single Number II].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0137][Single Number II]/src/Solution.java b/[0137][Single Number II]/src/Solution.java new file mode 100644 index 0000000..4b7d150 --- /dev/null +++ b/[0137][Single Number II]/src/Solution.java @@ -0,0 +1,78 @@ +/** + * Author: + * Date: 2015-06-21 + * Time: 20:35 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + + /** + *
+     * Given an array of integers, every element appears three times except for one.
+     * Find that single one.
+     *
+     * Note:
+     *   - Your algorithm should have a linear runtime complexity.
+     *          Could you implement it without using extra memory?
+     * Ŀ⣺
+     * һ飬ֻһһΣֶ3Σҳһε֣
+     * Ҫʱ临ӶΪO(n)ռ临ӶΪO(1)òĿռ
+     *
+     * ˼·
+     * һȫöƱʾǰ  i th   λֵĺͶ3ȡ࣬
+     * ôֻ 0  1 (⣬3031Ϊ0).  ȡĽ
+     * Ǹ Single Numberһֱӵʵ־ôСΪ 32¼
+     * λϵĺ͡
+     *
+     * ʹ
+     * ones    ithλֻһε
+     * twos    ithλֻδε
+     * threes  ithλֻε
+     * ithλ3ʱǾonestwosĵithλΪ0. յĴ𰸾 ones
+     * 
+ * + * @param nums + * @return + */ + public int singleNumber(int[] nums) { + + int[] count = new int[32]; + int result = 0; + + for (int i = 0; i < 32; i++) { + for (int n : nums) { + // ͳƵiλ1ĸ + if (((n >> i) & 1) == 1) { + count[i]++; + } + } + + result |= (count[i] % 3) << i; + } + + return result; + } + + // TODO δȫ + public int singleNumber2(int[] nums) { + // ֻһε + int ones = 0; + // ֻδε + int twos = 0; + // ֻε + int threes; + + for (int n : nums) { + twos |= ones & n; + // 3 1εĽһ + ones ^= n; + // onestwosѳ3ελΪ0ȡ֮1λΪ0 + threes = ones & twos; + + ones &= ~threes; + twos &= ~threes; + } + + return ones; + } +} diff --git a/[0138][Copy List With Random Pointer]/[0138][Copy List With Random Pointer].iml b/[0138][Copy List With Random Pointer]/[0138][Copy List With Random Pointer].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0138][Copy List With Random Pointer]/[0138][Copy List With Random Pointer].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0138][Copy List With Random Pointer]/src/Main.java b/[0138][Copy List With Random Pointer]/src/Main.java new file mode 100644 index 0000000..85972fb --- /dev/null +++ b/[0138][Copy List With Random Pointer]/src/Main.java @@ -0,0 +1,32 @@ +/** + * Author: + * Date: 2015-06-24 + * Time: 09:18 + * Declaration: All Rights Reserved !!! + */ +public class Main { + public static void main(String[] args) { + RandomListNode n1 = new RandomListNode(1); + RandomListNode n2 = new RandomListNode(2); + RandomListNode n3 = new RandomListNode(3); + RandomListNode n4 = new RandomListNode(4); + n1.next = n2; + n2.next = n3; + n3.next = n4; + + Solution solution = new Solution(); + RandomListNode copy = solution.copyRandomList(n1); + + print(copy); + + } + + public static void print(RandomListNode head) { + while (head != null) { + System.out.print(head.label + "->"); + head = head.next; + } + + System.out.println("null"); + } +} diff --git a/[0138][Copy List With Random Pointer]/src/RandomListNode.java b/[0138][Copy List With Random Pointer]/src/RandomListNode.java new file mode 100644 index 0000000..06bc0eb --- /dev/null +++ b/[0138][Copy List With Random Pointer]/src/RandomListNode.java @@ -0,0 +1,14 @@ +/** + * Author: + * Date: 2015-06-24 + * Time: 08:49 + * Declaration: All Rights Reserved !!! + */ +public class RandomListNode { + int label; + RandomListNode next, random; + + RandomListNode(int x) { + this.label = x; + } +} diff --git a/[0138][Copy List With Random Pointer]/src/Solution.java b/[0138][Copy List With Random Pointer]/src/Solution.java new file mode 100644 index 0000000..5501ab5 --- /dev/null +++ b/[0138][Copy List With Random Pointer]/src/Solution.java @@ -0,0 +1,108 @@ +/** + * Author: + * Date: 2015-06-24 + * Time: 08:48 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * A linked list is given such that each node contains an additional random
+     * pointer which could point to any node in the list or null.
+     *
+     * Return a deep copy of the list.
+     *
+     * Ŀ⣺
+     * һһָnullĽָ룬
+     *
+     * ˼·
+     * һƽ㣬ƵĽڴƵĽȻһ
+     * ڶָ
+     * ָƺ
+     * 
+ * + * @param head + * @return + */ + public RandomListNode copyRandomList(RandomListNode head) { + if (head == null) { + return null; + } + + copyNode(head); + linkRandomPointer(head); + + return splitList(head); + } + + /** + * ƽ㣬ƵĽڴƵĽȻһ + * + * @param head ͷ + */ + public void copyNode(RandomListNode head) { + // ¼ǰҪƵ + RandomListNode node = head; + while (node != null) { + // һµĽ + RandomListNode copyNode = new RandomListNode(node.label); + // 㴮ӵƵĽ󣬲Ȼɵ + copyNode.next = node.next; + node.next = copyNode; + node = copyNode.next; + } + } + + /** + * ָ + * + * @param head ͷ + */ + public void linkRandomPointer(RandomListNode head) { + // ¼ǰҪƵ + RandomListNode node = head; + while (node != null) { + // ָָijĽ + if (node.random != null) { + // nodeƽָ + node.next.random = node.random.next; + } + + // ָһƵĽ + node = node.next.next; + } + } + + /** + * ֣ԭԭװ + * + * @param head ͷ + * @return ͷ + */ + public RandomListNode splitList(RandomListNode head) { + // ͷ + RandomListNode copyHead = head.next; + // ǰıƵĽ + RandomListNode node = head; + // ǰƵĽ + RandomListNode copy; + + while (node != null){ + // ָƽ + copy = node.next; + + // node.nextָһƵĽ + node.next = copy.next; + + // һƵĽ㲻Ϊnull + if (node.next != null) { + // copy.nextָһƵĽ + copy.next = node.next.next; + } + + // nodeָһҪıƽ + node = node.next; + } + return copyHead; + } +} diff --git a/[0139][Word Break]/[0139][Word Break].iml b/[0139][Word Break]/[0139][Word Break].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0139][Word Break]/[0139][Word Break].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0139][Word Break]/[0139][WordBreak].iml b/[0139][Word Break]/[0139][WordBreak].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0139][Word Break]/[0139][WordBreak].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0139][Word Break]/src/Main.java b/[0139][Word Break]/src/Main.java new file mode 100644 index 0000000..ad4016f --- /dev/null +++ b/[0139][Word Break]/src/Main.java @@ -0,0 +1,50 @@ +import java.util.HashSet; +import java.util.Set; + +/** + * Author: + * Date: 2015-06-21 + * Time: 08:48 + * Declaration: All Rights Reserved !!! + */ +public class Main { + public static void main(String[] args) { +// test01(); +// test02(); + test03(); + } + + private static void test01() { + Solution solution = new Solution(); + Set set = new HashSet<>(); + set.add("leet"); + set.add("code"); + System.out.println(solution.wordBreak("leetcode", set)); + } + + private static void test02() { + Solution solution = new Solution(); + Set set = new HashSet<>(); + System.out.println(solution.wordBreak("a", set)); + } + + + private static void test03() { + Solution solution = new Solution(); + Set set = new HashSet<>(); +// set.add("b"); + set.add("a"); + set.add("aa"); + set.add("aaa"); + set.add("aaaa"); + set.add("aaaaa"); + set.add("aaaaaa"); + set.add("aaaaaaa"); + set.add("aaaaaaaa"); + set.add("aaaaaaaaa"); + set.add("aaaaaaaaaa"); + System.out.println(solution.wordBreak("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + + "aaaaaaaaaaaaaaaaaaaaaaaaab", set)); + } +} diff --git a/[0139][Word Break]/src/Solution.java b/[0139][Word Break]/src/Solution.java new file mode 100644 index 0000000..3bd11d4 --- /dev/null +++ b/[0139][Word Break]/src/Solution.java @@ -0,0 +1,121 @@ +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * Author: + * Date: 2015-06-21 + * Time: 08:13 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     *
+     * Given a string s and a dictionary of words dict, determine if s can
+     * be segmented into a space-separated sequence of one or more dictionary words.
+     *
+     * For example, given
+     * s = "leetcode",
+     * dict = ["leet", "code"].
+     * Return true because "leetcode" can be segmented as "leet code".
+     *
+     * Ŀ⣺
+     * һַs͵ֵdictȷsǷԷָһʿոָС
+     *
+     * ˼·
+     * һַSijΪNSֵܹ伯ϡdictеĵƴӶɣôҪΪ
+     * F(0, N) = F(0, i) && F(i, j) && F(j, N);
+     * ӣ֪ijӴǷDictеļƴӶɾͿķʽõ
+     * ΪTrue, ΪFalse뵽һbooleanĶӦλϣӣboolean
+     * һλF(0, N)ֵΪTrueʾַSDictеĵƴӣУ
+     * 
+ * + * @param s + * @param wordDict + * @return + */ + public boolean wordBreak(String s, Set wordDict) { + // У + if (s == null || s.length() < 1 || wordDict == null || wordDict.size() < 1) { + return false; + } + + // Ƿƥ䣬match[i][0, i-1]ƥ + int length = s.length(); + boolean[] match = new boolean[length + 1]; + match[0] = true; + + for (int i = 1; i < length + 1; i++) { + for (int j = 0; j < i; j++) { + if (match[j] && wordDict.contains(s.substring(j, i))) { + // f(0,n) = f(0,i) + f(i,j) + f(j,n) + match[i] = true; + break; + } + } + } + + + return match[length]; + } + + + // һֽⷨǻᳬʱ + public boolean wordBreak2(String s, Set wordDict) { + + // У + if (s == null || s.length() < 1 || wordDict == null || wordDict.size() < 1) { + return false; + } + + Map> wordMap = new HashMap<>(wordDict.size()); + // пʼַͬĵʷһSet + for (String word : wordDict) { + Set set = wordMap.get(word.charAt(0)); + if (set == null) { + // ´һsetMap + set = new HashSet<>(); + wordMap.put(word.charAt(0), set); + } + // ʴset + set.add(word); + } + + return wordBreak(s, 0, wordMap); + } + + /** + * ַǷԱָɵʴ + * + * @param s ַ + * @param idx Ŀʼλ + * @param wordMap ֵ䣬ʼַͬͬһset + * @return + */ + public boolean wordBreak(String s, int idx, Map> wordMap) { + + if (idx >= s.length()) { + return true; + } + + Set words = wordMap.get(s.charAt(idx)); + + if (words != null) { + for (String word : words) { + // idx֮ǰַѾƥ䣬ide֮ƥword + if (s.startsWith(word, idx)) { + // ݹ鴦 + boolean result = wordBreak(s, idx + word.length(), wordMap); + // true + if (result) { + return true; + } + } + } + } + + return false; + } +} diff --git a/[0141][Linked List Cycle]/[0141][Linked List Cycle].iml b/[0141][Linked List Cycle]/[0141][Linked List Cycle].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0141][Linked List Cycle]/[0141][Linked List Cycle].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0141][Linked List Cycle]/src/ListNode.java b/[0141][Linked List Cycle]/src/ListNode.java new file mode 100644 index 0000000..a9b5f6a --- /dev/null +++ b/[0141][Linked List Cycle]/src/ListNode.java @@ -0,0 +1,14 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 19:17 + * Declaration: All Rights Reserved !!! + */ +public class ListNode { + int val; + ListNode next; + ListNode(int x) { + val = x; + next = null; + } +} diff --git a/[0141][Linked List Cycle]/src/Solution.java b/[0141][Linked List Cycle]/src/Solution.java new file mode 100644 index 0000000..1bac274 --- /dev/null +++ b/[0141][Linked List Cycle]/src/Solution.java @@ -0,0 +1,57 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 19:16 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Given a linked list, determine if it has a cycle in it.
+     * Follow up:
+     * Can you solve it without using extra space?
+     *
+     * Ŀ
+     * һжǷл
+     *
+     * ˼·
+     * ָ(fast, slow)ʼֵָͷslowÿǰһfastÿǰڻ
+     * fastضȽ뻷slow뻷ָض
+     * 
+ * + * @param head + * @return + */ + public boolean hasCycle(ListNode head) { + + ListNode fast = head; + ListNode slow = head; + + while (fast != null && fast.next != null) { + fast = fast.next.next; + slow = slow.next; + if (slow == fast) { + return true; + } + } + + return false; + } + + public boolean hasCycle2(ListNode head) { + + ListNode fast = head; + ListNode slow = head; + + while (fast != null && fast.next != null) { + fast = fast.next.next; + slow = slow.next; + if (slow == fast) { + break; + } + } + + return !(fast == null || fast.next == null); + } +} diff --git a/[0142][Linked List Cycle II]/[0142][Linked List Cycle II].iml b/[0142][Linked List Cycle II]/[0142][Linked List Cycle II].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0142][Linked List Cycle II]/[0142][Linked List Cycle II].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0142][Linked List Cycle II]/[0142][LinkedListCycleII].iml b/[0142][Linked List Cycle II]/[0142][LinkedListCycleII].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0142][Linked List Cycle II]/[0142][LinkedListCycleII].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0142][Linked List Cycle II]/src/ListNode.java b/[0142][Linked List Cycle II]/src/ListNode.java new file mode 100644 index 0000000..fba59f9 --- /dev/null +++ b/[0142][Linked List Cycle II]/src/ListNode.java @@ -0,0 +1,14 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 19:19 + * Declaration: All Rights Reserved !!! + */ +public class ListNode { + int val; + ListNode next; + ListNode(int x) { + val = x; + next = null; + } +} diff --git a/[0142][Linked List Cycle II]/src/Solution.java b/[0142][Linked List Cycle II]/src/Solution.java new file mode 100644 index 0000000..1f0bccc --- /dev/null +++ b/[0142][Linked List Cycle II]/src/Solution.java @@ -0,0 +1,53 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 19:18 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Given a linked list, return the node where the cycle begins. If there is no cycle, return null.
+     * Follow up:
+     * Can you solve it without using extra space?
+     *
+     * Ŀ
+     * һлػڵĵһڵ㣬򷵻null
+     *
+     * ˼·
+     * жǷлʹÿ죨fastָ루slowⷨ141LinkedListCycle
+     * ûлͷnullлfast=slowslowָͷȻָÿͬʱƶһλã
+     * ֱǻڽ㡣
+     * 
+ * + * @param head + * @return + */ + public ListNode detectCycle(ListNode head) { + + ListNode fast = head; + ListNode slow = head; + + while (fast != null && fast.next != null) { + fast = fast.next.next; + slow = slow.next; + + if (fast == slow) { + break; + } + } + + if (fast == null || fast.next == null) { + return null; + } + + slow = head; + while (fast != slow) { + fast = fast.next; + slow = slow.next; + } + + return slow; + } +} diff --git a/[0143][Reorder List]/[0143][CopyListWithRandomPointer].iml b/[0143][Reorder List]/[0143][CopyListWithRandomPointer].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0143][Reorder List]/[0143][CopyListWithRandomPointer].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0143][Reorder List]/[0143][Reorder List].iml b/[0143][Reorder List]/[0143][Reorder List].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0143][Reorder List]/[0143][Reorder List].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0143][Reorder List]/src/ListNode.java b/[0143][Reorder List]/src/ListNode.java new file mode 100644 index 0000000..1f6cb21 --- /dev/null +++ b/[0143][Reorder List]/src/ListNode.java @@ -0,0 +1,14 @@ +/** + * Author: 王俊超 + * Date: 2015-08-21 + * Time: 19:22 + * Declaration: All Rights Reserved !!! + */ +public class ListNode { + int val; + ListNode next; + + ListNode(int x) { + val = x; + } +} diff --git a/[0143][Reorder List]/src/Solution.java b/[0143][Reorder List]/src/Solution.java new file mode 100644 index 0000000..8c489cf --- /dev/null +++ b/[0143][Reorder List]/src/Solution.java @@ -0,0 +1,78 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 19:21 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Given a singly linked list L: L0L1Ln-1Ln,
+     * reorder it to: L0LnL1Ln-1L2Ln-2
+     *
+     * You may not modify the values in the list's nodes, only nodes itself may be changed.
+     *
+     * Example 1:
+     *
+     * Given 1->2->3->4, reorder it to 1->4->2->3.
+     * Example 2:
+     *
+     * Given 1->2->3->4->5, reorder it to 1->5->2->4->3.
+     *
+     * ˼·
+     * 1ҵм
+     * 2㣬ͽм֮в֣
+     *
+     * 
+ * @param head + */ + public void reorderList(ListNode head) { + if (head == null || head.next == null) { + return; + } + + ListNode root = new ListNode(-1); + root.next = head; + ListNode fast = head; + // мǰ + ListNode slow = root; + + while (fast != null && fast.next != null) { + fast = fast.next.next; + slow = slow.next; + } + + // ˵żڵ + if (fast == null) { + root.next = slow.next; + slow.next = null; + + } else { // + slow = slow.next; + root.next = slow.next; + slow.next = null; + } + + // һҪͷ巨 + fast = root.next; + ListNode tmp; + // 벿 + while (fast.next != null) { + tmp = fast.next; + fast.next = tmp.next; + tmp.next = root.next; + root.next = tmp; + } + + slow = head; + fast = root.next; + + while (fast != null) { + tmp = fast.next; + fast.next = slow.next; + slow.next = fast; + slow = slow.next.next; + fast = tmp; + } + } +} diff --git a/[0144][Binary Tree Preorder Traversal]/[0144][Binary Tree Preorder Traversal].iml b/[0144][Binary Tree Preorder Traversal]/[0144][Binary Tree Preorder Traversal].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0144][Binary Tree Preorder Traversal]/[0144][Binary Tree Preorder Traversal].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0144][Binary Tree Preorder Traversal]/src/Solution.java b/[0144][Binary Tree Preorder Traversal]/src/Solution.java new file mode 100644 index 0000000..ee6e425 --- /dev/null +++ b/[0144][Binary Tree Preorder Traversal]/src/Solution.java @@ -0,0 +1,34 @@ +import java.util.Deque; +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-08-19 + * Time: 06:44 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + public List preorderTraversal(TreeNode root) { + List result = new LinkedList<>(); + + if (root != null) { + Deque stack = new LinkedList<>(); + stack.add(root); + + while (!stack.isEmpty()) { + TreeNode node = stack.removeLast(); + result.add(node.val); + + if (node.right != null) { + stack.add(node.right); + } + if (node.left != null) { + stack.add(node.left); + } + } + } + + return result; + } +} diff --git a/[0144][Binary Tree Preorder Traversal]/src/TreeNode.java b/[0144][Binary Tree Preorder Traversal]/src/TreeNode.java new file mode 100644 index 0000000..9aec4dd --- /dev/null +++ b/[0144][Binary Tree Preorder Traversal]/src/TreeNode.java @@ -0,0 +1,15 @@ +/** + * Author: + * Date: 2015-08-19 + * Time: 06:45 + * Declaration: All Rights Reserved !!! + */ +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} diff --git a/[0145][Binary Tree Postorder Traversal]/[0145][Binary Tree Postorder Traversal].iml b/[0145][Binary Tree Postorder Traversal]/[0145][Binary Tree Postorder Traversal].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0145][Binary Tree Postorder Traversal]/[0145][Binary Tree Postorder Traversal].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0145][Binary Tree Postorder Traversal]/[0145][BinaryTreePostorderTraversal].iml b/[0145][Binary Tree Postorder Traversal]/[0145][BinaryTreePostorderTraversal].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0145][Binary Tree Postorder Traversal]/[0145][BinaryTreePostorderTraversal].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0145][Binary Tree Postorder Traversal]/src/Solution.java b/[0145][Binary Tree Postorder Traversal]/src/Solution.java new file mode 100644 index 0000000..2adec07 --- /dev/null +++ b/[0145][Binary Tree Postorder Traversal]/src/Solution.java @@ -0,0 +1,93 @@ +import java.util.Deque; +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-06-22 + * Time: 14:54 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Given a binary tree, return the postorder traversal of its nodes' values.
+     *
+     * For example:
+     * Given binary tree {1,#,2,3},
+     *      1
+     *       \
+     *        2
+     *       /
+     *      3
+     * return [3,2,1].
+     *
+     * Note: Recursive solution is trivial, could you do it iteratively?
+     *
+     * Ŀ⣺
+     * һŶĺĽֵ
+     *
+     * ע⣺
+     *   - ݹⷨף볢ʽ
+     *
+     * ˼·
+     * ǵݹ
+     * ݺ˳ȷٷʸڵ㣬ÿ˵
+     * ְͬķ˳бķǵݹʵ˵ҪһЩҪ֤
+     * ʺܷʣ˼·£
+     *
+     * һڵP
+     * 1ȽڵPջ
+     * 2PӺҺӣPӻҺӣҺѾ
+     *      ֱڵPջջڵPΪһĽڵ㣬ٽʱ
+     *      ջΪǰڵ㣻
+     * 32еPҺӺջǰڵΪջ㣬
+     *      ֮ظ2
+     * 4ֱջգ
+     * 
+ * + * @param root + * @return + */ + public List postorderTraversal(TreeNode root) { + List list = new LinkedList<>(); + + if (root != null) { + // ˫˶Уջʹ + Deque deque = new LinkedList<>(); + // ָǰһĽ + TreeNode prev = null; + // ָǰĽ + TreeNode curr; + // ջ + deque.addLast(root); + // ջǿ + while (!deque.isEmpty()) { + // ȡջԪأɾ + curr = deque.getLast(); + if ((curr.left == null && curr.right == null) // ǰԪ + // prev != null && curr.left == prevǰֻѾ + // prev != null && curr.right == prevǰѾ + || (prev != null && (curr.left == prev || curr.right == prev))) { + // ɾջԪ + curr = deque.removeLast(); + // ֵջ + list.add(curr.val); + // һĽ + prev = curr; + } else { + + // δ꣬ǿջ + if (curr.right != null) { + deque.addLast(curr.right); + } + if (curr.left != null) { + deque.addLast(curr.left); + } + } + } + } + + return list; + } +} diff --git a/[0145][Binary Tree Postorder Traversal]/src/TreeNode.java b/[0145][Binary Tree Postorder Traversal]/src/TreeNode.java new file mode 100644 index 0000000..958278e --- /dev/null +++ b/[0145][Binary Tree Postorder Traversal]/src/TreeNode.java @@ -0,0 +1,15 @@ +/** + * Author: + * Date: 2015-06-22 + * Time: 14:54 + * Declaration: All Rights Reserved !!! + */ +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} diff --git a/[0146][LRU Cache]/[0146][LRU Cache].iml b/[0146][LRU Cache]/[0146][LRU Cache].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0146][LRU Cache]/[0146][LRU Cache].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0146][LRU Cache]/src/LRUCache.java b/[0146][LRU Cache]/src/LRUCache.java new file mode 100644 index 0000000..3d26ca7 --- /dev/null +++ b/[0146][LRU Cache]/src/LRUCache.java @@ -0,0 +1,69 @@ +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-17 17:34 + **/ +public class LRUCache extends LinkedHashMap { + /** + *
+     * Design and implement a data structure for Least Recently Used (LRU) cache.
+     * It should support the following operations: get and put.
+     *
+     * get(key) - Get the value (will always be positive) of the key if the key exists
+     * in the cache, otherwise return -1.
+     * put(key, value) - Set or insert the value if the key is not already present. When
+     * the cache reached its capacity, it should invalidate the least recently used item
+     * before inserting a new item.
+     *
+     * The cache is initialized with a positive capacity.
+     *
+     * Follow up:
+     * Could you do both operations in O(1) time complexity?
+     *
+     * Example:
+     *
+     * LRUCache cache = new LRUCache( 2  );// capacity
+     *
+     * cache.put(1,1);
+     * cache.put(2,2);
+     * cache.get(1);       // returns 1
+     * cache.put(3,3);    // evicts key 2
+     * cache.get(2);       // returns -1 (not found)
+     * cache.put(4,4);    // evicts key 1
+     * cache.get(1);       // returns -1 (not found)
+     * cache.get(3);       // returns 3
+     * cache.get(4);       // returns 4
+     * 
+ * + * @param capacity + */ + + private int capacity; + + + public LRUCache(int capacity) { + super(capacity, 0.75F, true); + this.capacity = capacity; + } + + public int get(int key) { + Integer value = super.get(key); + if (value == null) { + return -1; + } else { + return value; + } + } + + public void put(int key, int value) { + super.put(key, value); + } + + + @Override + protected boolean removeEldestEntry(Map.Entry eldest) { + return size() > capacity; + } +} diff --git a/[0146][LRU Cache]/src/Main.java b/[0146][LRU Cache]/src/Main.java new file mode 100644 index 0000000..61644cc --- /dev/null +++ b/[0146][LRU Cache]/src/Main.java @@ -0,0 +1,26 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-17 17:41 + **/ +public class Main { + + @Test + public void test1() { + LRUCache cache = new LRUCache(2); + + cache.put(1, 1); + cache.put(2, 2); + cache.get(1); // returns 1 + cache.put(3, 3); // evicts key 2 + cache.get(2); // returns -1 (not found) + Assert.assertEquals(-1, cache.get(2)); + cache.put(4, 4); // evicts key 1 + cache.get(1); // returns -1 (not found) + Assert.assertEquals(-1, cache.get(1)); + cache.get(3); // returns 3 + cache.get(4); // returns 4 + } +} diff --git a/[0147][Insertion Sort List]/[0147][Insertion Sort List].iml b/[0147][Insertion Sort List]/[0147][Insertion Sort List].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0147][Insertion Sort List]/[0147][Insertion Sort List].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0147][Insertion Sort List]/[0147][InsertionSortList].iml b/[0147][Insertion Sort List]/[0147][InsertionSortList].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0147][Insertion Sort List]/[0147][InsertionSortList].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0147][Insertion Sort List]/src/ListNode.java b/[0147][Insertion Sort List]/src/ListNode.java new file mode 100644 index 0000000..0c7f1c1 --- /dev/null +++ b/[0147][Insertion Sort List]/src/ListNode.java @@ -0,0 +1,14 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 19:24 + * Declaration: All Rights Reserved !!! + */ +public class ListNode { + int val; + ListNode next; + + ListNode(int v) { + val = v; + } +} diff --git a/[0147][Insertion Sort List]/src/Solution.java b/[0147][Insertion Sort List]/src/Solution.java new file mode 100644 index 0000000..14a4280 --- /dev/null +++ b/[0147][Insertion Sort List]/src/Solution.java @@ -0,0 +1,52 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 19:23 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * ԭ
+     * Sort a linked list using insertion sort.
+     *
+     * Ŀ
+     * һв
+     *
+     * ˼·
+     * ʹһָpָδźĵһ㣬õIJҵҵһڵqǰ㣬
+     * pӦĽ뵽ȷλãpָδźĵһ㡣ֱá
+     * 
+ * + * @param head + * @return + */ + public ListNode insertionSortList(ListNode head) { + + ListNode root = new ListNode(0); // ͷ + root.next = head; + ListNode p = head; + ListNode q; + ListNode r; + + while (p != null && p.next != null) { + if (p.val <= p.next.val) { + p = p.next; + } else { + q = p.next; + p.next = q.next; + + r = root; + // ҵһڵq.valǰ㣬Ϊroot.nextp֮ضĽ + while (r.next.val <= q.val) { + r = r.next; + } + + q.next = r.next; + r.next = q; + } + } + + return root.next; + } +} diff --git a/[0148][Sort List]/[0148][Sort List].iml b/[0148][Sort List]/[0148][Sort List].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0148][Sort List]/[0148][Sort List].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0148][Sort List]/src/ListNode.java b/[0148][Sort List]/src/ListNode.java new file mode 100644 index 0000000..0c7f1c1 --- /dev/null +++ b/[0148][Sort List]/src/ListNode.java @@ -0,0 +1,14 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 19:24 + * Declaration: All Rights Reserved !!! + */ +public class ListNode { + int val; + ListNode next; + + ListNode(int v) { + val = v; + } +} diff --git a/[0148][Sort List]/src/Solution.java b/[0148][Sort List]/src/Solution.java new file mode 100644 index 0000000..7cbd141 --- /dev/null +++ b/[0148][Sort List]/src/Solution.java @@ -0,0 +1,84 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-19 14:28 + **/ +public class Solution { + /** + *
+     * Sort a linked list in O(n log n) time using constant space complexity.
+     *
+     * Example 1:
+     *
+     * Input: 4->2->1->3
+     * Output: 1->2->3->4
+     * Example 2:
+     *
+     * Input: -1->5->3->4->0
+     * Output: -1->0->3->4->5
+     *
+     * 使用链表的归并排序可以解决
+     * 
+ * + * @param head + * @return + */ + public ListNode sortList(ListNode head) { + + if (head == null || head.next == null) { + return head; + } + return mergeSort(head); + } + + private ListNode mergeSort(ListNode head) { + + if (head == null || head.next == null) { + return head; + } + + ListNode p = head; + ListNode q = head; + // 记录前驱 + ListNode r = null; + + // 将链表分害割成两半 + while (p != null && p.next != null) { + p = p.next.next; + r = q; + q = q.next; + } + + r.next = null; + + // 两个链接分别进行排序 + ListNode h1 = mergeSort(head); + ListNode h2 = mergeSort(q); + + return merge(h1, h2); + } + + private ListNode merge(ListNode l1, ListNode l2) { + + ListNode head = new ListNode(0); + ListNode p = head; + while (l1 != null && l2 != null) { + if (l1.val <= l2.val) { + p.next = l1; + l1 = l1.next; + } else { + p.next = l2; + l2 = l2.next; + } + + p = p.next; + } + + if (l1 != null) { + p.next = l1; + } else { + p.next = l2; + } + + return head.next; + } +} diff --git a/[0150][Evaluate Reverse Polish Notation]/[0150][Evaluate Reverse Polish Notation].iml b/[0150][Evaluate Reverse Polish Notation]/[0150][Evaluate Reverse Polish Notation].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0150][Evaluate Reverse Polish Notation]/[0150][Evaluate Reverse Polish Notation].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0150][Evaluate Reverse Polish Notation]/src/Main.java b/[0150][Evaluate Reverse Polish Notation]/src/Main.java new file mode 100644 index 0000000..f6672ab --- /dev/null +++ b/[0150][Evaluate Reverse Polish Notation]/src/Main.java @@ -0,0 +1,12 @@ +/** + * Author: + * Date: 2015-06-20 + * Time: 07:14 + * Declaration: All Rights Reserved !!! + */ +public class Main { + public static void main(String[] args) { + Solution solution = new Solution(); + System.out.println(solution.evalRPN(new String[]{"0","3","/"})); + } +} diff --git a/[0150][Evaluate Reverse Polish Notation]/src/Solution.java b/[0150][Evaluate Reverse Polish Notation]/src/Solution.java new file mode 100644 index 0000000..499adc9 --- /dev/null +++ b/[0150][Evaluate Reverse Polish Notation]/src/Solution.java @@ -0,0 +1,75 @@ +import java.util.Queue; +import java.util.Stack; + +/** + * Author: + * Date: 2015-06-20 + * Time: 06:58 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Evaluate the value of an arithmetic expression in Reverse Polish Notation.
+     * Valid operators are +, -, *, /. Each operand may be an integer or another expression.
+     *
+     * Some examples:
+     * ["2", "1", "+", "3", "*"] -> ((2 + 1) * 3) -> 9
+     * ["4", "13", "5", "/", "+"] -> (4 + (13 / 5)) -> 6
+     *
+     * Ŀ⣺
+     * 沨ʽֵЧǣ+-*/ÿҪôһҪôһʽ
+     *
+     * ˼·
+     * ʹջв
+     * 
+ * + * @param tokens + * @return + */ + public int evalRPN(String[] tokens) { + // У + if (tokens == null || tokens.length < 1) { + throw new IllegalArgumentException(); + } + + int op1; + int op2; + // ջ + Stack stack = new Stack<>(); + + for (String token : tokens) { + // ˵ҪȡջԪؽ + if ("+".equals(token) || "-".equals(token) || "*".equals(token) || "/".equals(token)) { + // ȡջԪ + op2 = stack.pop(); + op1 = stack.pop(); + + // + switch (token.charAt(0)) { + case '+': + op1 += op2; + break; + case '-': + op1 -= op2; + break; + case '*': + op1 *= op2; + break; + case '/': + op1 /= op2; + break; + } + // ջ + stack.push(op1); + } + // ˵Dzջ + else { + stack.push(Integer.parseInt(token)); + } + } + + // ջֻʣһԪأǾĽ + return stack.pop(); + } +} diff --git a/[0151][Reverse Words In A String]/[0151][Reverse Words In A String].iml b/[0151][Reverse Words In A String]/[0151][Reverse Words In A String].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0151][Reverse Words In A String]/[0151][Reverse Words In A String].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0151][Reverse Words In A String]/[0151][ReverseWordsInAString].iml b/[0151][Reverse Words In A String]/[0151][ReverseWordsInAString].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0151][Reverse Words In A String]/[0151][ReverseWordsInAString].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0151][Reverse Words In A String]/src/Main.java b/[0151][Reverse Words In A String]/src/Main.java new file mode 100644 index 0000000..8b507c4 --- /dev/null +++ b/[0151][Reverse Words In A String]/src/Main.java @@ -0,0 +1,26 @@ +/** + * Author: + * Date: 2015-06-20 + * Time: 09:50 + * Declaration: All Rights Reserved !!! + */ +public class Main { + public static void main(String[] args) { + Solution solution = new Solution(); +// System.out.println("|" +solution.reverseWords(" ") + "|"); + +// char[] array = " a b ".toCharArray(); +// int len = solution.compressWhiteSpace(array); +// System.out.println("|" + new String(array, 0, len) + "|"); + +// System.out.println(solution.reverseWords("")); +// System.out.println(solution.reverseWords(" a ")); +// System.out.println(solution.reverseWords(" ")); +// System.out.println(solution.reverseWords(" a b ")); + System.out.println(solution.reverseWords(" a b c d e ")); + System.out.println(solution.reverseWords("a b c d e")); + System.out.println(solution.reverseWords("abcdef")); + + } + +} diff --git a/[0151][Reverse Words In A String]/src/Solution.java b/[0151][Reverse Words In A String]/src/Solution.java new file mode 100644 index 0000000..e888c33 --- /dev/null +++ b/[0151][Reverse Words In A String]/src/Solution.java @@ -0,0 +1,141 @@ +/** + * Author: + * Date: 2015-06-20 + * Time: 09:28 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Given an input string, reverse the string word by word.
+     *
+     * For example,
+     * Given s = "the sky is blue",
+     * return "blue is sky the".
+     *
+     * Ŀ⣺
+     * һַ䷴תִʲת
+     *
+     * ˼·
+     * ȶַתٽÿʽзת
+     * 
+ * + * @param s + * @return + */ + public String reverseWords(String s) { + + if (s == null) { + return null; + } + + char[] chars = s.toCharArray(); + // ַѹ + int realLength = compressWhiteSpace(chars); + + // ַ + swapRange(chars, 0, realLength - 1); + + // ¼ʵ + int start = 0; + // ¼ʵյ + int end; + + while (start < realLength) { + // startλÿʼҵһǿհַ + while (start < realLength && chars[start] == ' ') { + start++; + } + + end = start + 1; + // ҵһհַ + while (end < realLength && chars[end] != ' ') { + end++; + } + + // תַ + swapRange(chars, start, end - 1); + // ¼µĿʼλ + start = end; + } + return new String(chars, 0, realLength); + } + + /** + * ַĵĿհַѹ + * + * @param chars ַ + * @return µij + */ + public int compressWhiteSpace(char[] chars) { + + if (chars == null || chars.length == 0) { + return 0; + } + + // ַλ + int pos = 0; + for (int i = 0; i < chars.length; i++) { + // iλÿʼҵһǿհַ + while (i < chars.length && chars[i] == ' ') { + i++; + } + + // Ѿ + if (i >= chars.length) { + break; + } + + // iλÿʼǿհֱַհַ + // Ǵһ + while (i < chars.length && chars[i] != ' ') { + chars[pos] = chars[i]; + pos++; + i++; + } + + // һҪһһʲжһA + if (pos < chars.length) { + // ո + chars[pos] = ' '; + } + + pos++; + } + + // ˵ַֻпհַ + if (pos == 0) { + return 0; + } else { + // һҪȥһո񣬼A + return pos - 1; + } + + } + + /** + * ת[x, y]λõַ + * + * @param chars ַ + * @param x xλ + * @param y yλ + */ + public void swapRange(char[] chars, int x, int y) { + for (; x < y; x++, y--) { + swap(chars, x, y); + } + } + + /** + * x,yλõĵ + * + * @param chars ַ + * @param x xλ + * @param y yλ + */ + public void swap(char[] chars, int x, int y) { + char z = chars[x]; + chars[x] = chars[y]; + chars[y] = z; + } +} diff --git a/[0152][Maximum Product Subarray]/[0152][Maximum Product Subarray].iml b/[0152][Maximum Product Subarray]/[0152][Maximum Product Subarray].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0152][Maximum Product Subarray]/[0152][Maximum Product Subarray].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0152][Maximum Product Subarray]/[0152][MaximumProductSubarray].iml b/[0152][Maximum Product Subarray]/[0152][MaximumProductSubarray].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0152][Maximum Product Subarray]/[0152][MaximumProductSubarray].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0152][Maximum Product Subarray]/src/Main.java b/[0152][Maximum Product Subarray]/src/Main.java new file mode 100644 index 0000000..e1f42c9 --- /dev/null +++ b/[0152][Maximum Product Subarray]/src/Main.java @@ -0,0 +1,12 @@ +/** + * Author: + * Date: 2015-06-19 + * Time: 21:12 + * Declaration: All Rights Reserved !!! + */ +public class Main { + public static void main(String[] args) { + Solution solution = new Solution(); + System.out.println(solution.maxProduct(new int[]{3, -1, 4})); + } +} diff --git a/[0152][Maximum Product Subarray]/src/Solution.java b/[0152][Maximum Product Subarray]/src/Solution.java new file mode 100644 index 0000000..fb11c8f --- /dev/null +++ b/[0152][Maximum Product Subarray]/src/Solution.java @@ -0,0 +1,63 @@ +/** + * Author: + * Date: 2015-06-19 + * Time: 20:52 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Find the contiguous subarray within an array (containing at least one number)
+     * which has the largest product.
+     *
+     * For example, given the array [2,3,-2,4],
+     *
+     * the contiguous subarray [2,3] has the largest product = 6.
+     *
+     * Ŀ⣺
+     * 飨ٰһ֣ҳһ飬ij˻
+     *
+     * ˼·
+     * 򵥶̬滮
+     *
+     * ƹʽ
+     * Product SubarrayҪǵһ͸ˣ
+     * ǰõһСĸͺһϴĸˣõķһϴ{2-3-7}
+     * ԣڴ˷ʱ򣬳ҪάһֲֵͬʱҪάһֲСֵ
+     *
+     * n<1˵дn0ʱ
+     * Fmax(0)=num[0]
+     * Fmin(0)=num[0]
+     *
+     * Fmax(n+1) = MAX(MAX(num[n+1]*Fmax(n), num[n+1]), num[n+1]*Fmin(n)) // ֵ
+     * Fmin(n+1) = MIN(MIN(num[n+1]*Fmax(n), num[n+1]), num[n+1]*Fmin(n)) // СֵΪһ¼׼
+     * 
+ * + * @param nums + * @return + */ + public int maxProduct(int[] nums) { + + if (nums == null || nums.length < 1) { + throw new IllegalArgumentException(); + } + + if (nums.length == 1) { + return nums[0]; + } + + int result = nums[0]; + int fmax = nums[0]; + int fmin = nums[0]; + int prevMax; + + for (int i = 1; i < nums.length; i++) { + prevMax = fmax; + fmax = Math.max(Math.max(nums[i] * prevMax, nums[i]), nums[i] * fmin); + fmin = Math.min(Math.min(nums[i] * prevMax, nums[i]), nums[i] * fmin); + result = Math.max(result, fmax); + } + + return result; + } +} diff --git a/[0153][Find Minimum In Rotated Sorted Array]/[0153][Find Minimum In Rotated Sorted Array].iml b/[0153][Find Minimum In Rotated Sorted Array]/[0153][Find Minimum In Rotated Sorted Array].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0153][Find Minimum In Rotated Sorted Array]/[0153][Find Minimum In Rotated Sorted Array].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0153][Find Minimum In Rotated Sorted Array]/[0153][FindMinimumInRotatedSortedArray].iml b/[0153][Find Minimum In Rotated Sorted Array]/[0153][FindMinimumInRotatedSortedArray].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0153][Find Minimum In Rotated Sorted Array]/[0153][FindMinimumInRotatedSortedArray].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0153][Find Minimum In Rotated Sorted Array]/src/Main.java b/[0153][Find Minimum In Rotated Sorted Array]/src/Main.java new file mode 100644 index 0000000..07cf2bf --- /dev/null +++ b/[0153][Find Minimum In Rotated Sorted Array]/src/Main.java @@ -0,0 +1,14 @@ +/** + * Author: + * Date: 2015-06-19 + * Time: 20:30 + * Declaration: All Rights Reserved !!! + */ +public class Main { + public static void main(String[] args) { + Solution solution = new Solution(); + System.out.println(solution.findMin(new int[]{9, 1, 2, 3, 4, 5, 6, 7, 8})); + System.out.println(solution.findMin(new int[]{2, 3, 1})); + System.out.println(solution.findMin(new int[]{3, 1, 2})); + } +} diff --git a/[0153][Find Minimum In Rotated Sorted Array]/src/Solution.java b/[0153][Find Minimum In Rotated Sorted Array]/src/Solution.java new file mode 100644 index 0000000..8a028d6 --- /dev/null +++ b/[0153][Find Minimum In Rotated Sorted Array]/src/Solution.java @@ -0,0 +1,65 @@ +/** + * Author: + * Date: 2015-06-19 + * Time: 20:12 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Suppose a sorted array is rotated at some pivot unknown to you beforehand.
+     * (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).
+     * Find the minimum element.
+     * You may assume no duplicate exists in the array.
+     *
+     * Ŀ⣺
+     * һδ֪ijת
+     * 0 1 2 4 5 6 7ܳΪ4 5 6 7 0 1 2
+     *
+     * ҵСԪء
+     * Լ費ظС
+     *
+     * Կ˼·
+     * ΪIJ֣ǰһֺͺһֲǰһ򲿷ԪضȺһԪش
+     * ֻҪҵһԪرǰһҪҵԪ
+     * 
+ * + * @param nums + * @return + */ + public int findMin(int[] nums) { + // + if (nums == null || nums.length < 0) { + throw new IllegalArgumentException(); + } + + return binarySearch(nums, 0, nums.length - 1); + } + + public int binarySearch(int[] nums, int start, int end) { + + int mid = 0; + + while (start < end) { + mid = start + ((end - start) >> 1); +// System.out.println(mid + " " + nums[mid]); + // һǰСҵ + if (nums[mid] > nums[mid + 1]) { + return nums[mid + 1]; + } + // ˵мֵڵһ + else if (nums[mid] > nums[start]) { + // ȡmid+1пnum[mid]ǵһеһԪ + start = mid; + } + // ˵мֵڵڶ + else { + // ȡmid-1пnum[mid]ǵڶеĵһԪ + end = mid; + } + } + + // ˵ + return nums[0]; + } +} diff --git a/[0154][Find Minimum In Rotated Sorted Array II]/[0154][Find Minimum In Rotated Sorted Array II].iml b/[0154][Find Minimum In Rotated Sorted Array II]/[0154][Find Minimum In Rotated Sorted Array II].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0154][Find Minimum In Rotated Sorted Array II]/[0154][Find Minimum In Rotated Sorted Array II].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0154][Find Minimum In Rotated Sorted Array II]/[0154][FindMinimumInRotatedSortedArrayII].iml b/[0154][Find Minimum In Rotated Sorted Array II]/[0154][FindMinimumInRotatedSortedArrayII].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0154][Find Minimum In Rotated Sorted Array II]/[0154][FindMinimumInRotatedSortedArrayII].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0154][Find Minimum In Rotated Sorted Array II]/src/Main.java b/[0154][Find Minimum In Rotated Sorted Array II]/src/Main.java new file mode 100644 index 0000000..bd05084 --- /dev/null +++ b/[0154][Find Minimum In Rotated Sorted Array II]/src/Main.java @@ -0,0 +1,12 @@ +/** + * Author: + * Date: 2015-06-21 + * Time: 16:08 + * Declaration: All Rights Reserved !!! + */ +public class Main { + public static void main(String[] args) { + Solution solution = new Solution(); + System.out.println(solution.findMin(new int[]{1, 3, 3})); + } +} diff --git a/[0154][Find Minimum In Rotated Sorted Array II]/src/Solution.java b/[0154][Find Minimum In Rotated Sorted Array II]/src/Solution.java new file mode 100644 index 0000000..5efb112 --- /dev/null +++ b/[0154][Find Minimum In Rotated Sorted Array II]/src/Solution.java @@ -0,0 +1,92 @@ +/** + * Author: + * Date: 2015-06-21 + * Time: 15:21 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + + + /** + *
+     * Follow up for "Find Minimum in Rotated Sorted Array":
+     * What if duplicates are allowed?
+     * Would this affect the run-time complexity? How and why?
+     * Suppose a sorted array is rotated at some pivot unknown to you beforehand.
+     *
+     *
+     * (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).
+     * Find the minimum element.
+     * The array may contain duplicates.
+     *
+     * Ŀ⣺
+     * תСֵĺظԪأȻֲ
+     *
+     * ˼·
+     * 㷨в
+     *
+     * 
+ * + * @param nums + * @return + */ + public int findMin(int[] nums) { + // У + if (nums == null || nums.length < 1) { + throw new IllegalArgumentException(); + } + + int lo = 0; + int hi = nums.length - 1; + int mid = 0; + + // ųȫ + while (nums[lo] >= nums[hi]) { + + // ֻԪأغһ + if (hi - lo == 1) { + mid = hi; + break; + } + + mid = lo + ((hi - lo) >> 1); + + if (nums[mid] == nums[lo] && nums[mid] == nums[hi]) { + // ֻܲ˳ܲlo++hi--ķʽ + // Ϊloǰһһ + // hiҲǺһĵһ + return sequenceSearch(nums, lo, hi); + } + + // midǰһ + if (nums[mid] >= nums[lo]) { + lo = mid; + } + // midںһ + else if (nums[mid] <= nums[hi]) { + hi = mid; + } + + } + + + return nums[mid]; + } + + /** + * ˳еСֵnums鰴ijת + * + * @param nums + * @param start ʼλ + * @param end λ + * @return Сֵ + */ + public int sequenceSearch(int[] nums, int start, int end) { + for (int i = start; i < end; i++) { + if (nums[i] > nums[i + 1]) { + return nums[i + 1]; + } + } + return nums[start]; + } +} diff --git a/[0155][Min Stack]/[0155][Min Stack].iml b/[0155][Min Stack]/[0155][Min Stack].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0155][Min Stack]/[0155][Min Stack].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0155][Min Stack]/[0155][MinStack].iml b/[0155][Min Stack]/[0155][MinStack].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0155][Min Stack]/[0155][MinStack].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0155][Min Stack]/src/MinStack.java b/[0155][Min Stack]/src/MinStack.java new file mode 100644 index 0000000..5587b2f --- /dev/null +++ b/[0155][Min Stack]/src/MinStack.java @@ -0,0 +1,89 @@ +/** + * Author: + * Date: 2015-08-21 + * Time: 19:25 + * Declaration: All Rights Reserved !!! + */ +public class MinStack { + private final static int DEFAULT_SIZE = 1000; + private int[] stack; + private int[] minIndex; // ڱǰnݵջСԪص± + private int min = Integer.MAX_VALUE; // ڼ¼еС + private int index = -1; // ¼СԪstackеλ + private int current = -1; + + /** + *
+     * ԭ
+     * Design a stack that supports push, pop, top, and retrieving
+     * the minimum element in constant time.
+     * push(x) C Push element x onto stack.
+     * pop() C Removes the element on top of the stack.
+     * top() C Get the top element.
+     * getMin() C Retrieve the minimum element in the stack.
+     *
+     * Ŀ
+     * һջ֧pushpoptopͲСԪزʱ䣩
+     *
+     * ˼·
+     * ʹһջջеСԪء
+     * 
+ */ + public MinStack() { + stack = new int[DEFAULT_SIZE]; + minIndex = new int[DEFAULT_SIZE]; + } + + public MinStack(int size) { + stack = new int[size]; + minIndex = new int[size]; + } + + public void push(int x) { + current++; // ƶҪλ + + if (current >= stack.length) { // + int[] tmp = new int[current * 2]; + System.arraycopy(stack, 0, tmp, 0, stack.length); + stack = tmp; + + tmp = new int[current * 2]; + System.arraycopy(minIndex, 0, tmp, 0, minIndex.length); + minIndex = tmp; + } + + stack[current] = x; // + + if (x < min) { // Сֵ + min = x; + index = current; // ¼[0, current]СԪ±index + } + + minIndex[current] = index; + } + + public void pop() { + current--; + if (current >= 0) { + min = stack[minIndex[current]]; // ջеСֵ + index = minIndex[current]; // Сֵ + } + } + + public int top() { + + if (current < 0) { + throw new RuntimeException("No more data"); + } + + return stack[current]; + } + + public int getMin() { + if (current < 0) { + throw new RuntimeException("No more data"); + } + + return stack[minIndex[current]]; + } +} diff --git a/[0162][Find Peak Element]/[0162][Find Peak Element].iml b/[0162][Find Peak Element]/[0162][Find Peak Element].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0162][Find Peak Element]/[0162][Find Peak Element].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0162][Find Peak Element]/[0162][FindPeakElement].iml b/[0162][Find Peak Element]/[0162][FindPeakElement].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0162][Find Peak Element]/[0162][FindPeakElement].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0162][Find Peak Element]/src/Solution.java b/[0162][Find Peak Element]/src/Solution.java new file mode 100644 index 0000000..ad5b5f3 --- /dev/null +++ b/[0162][Find Peak Element]/src/Solution.java @@ -0,0 +1,46 @@ +/** + * Author: + * Date: 2015-06-19 + * Time: 17:30 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * A peak element is an element that is greater than its neighbors.
+     *
+     * Given an input array where num[i]  num[i+1], find a peak element and return its index.
+     *
+     * The array may contain multiple peaks, in that case return the index to any one of the peaks is fine.
+     *
+     * You may imagine that num[-1] = num[n] = -.
+     *
+     * For example, in array [1, 2, 3, 1], 3 is a peak element and your function should return
+     * the index number 2.
+     *
+     * Note:
+     * Your solution should be in logarithmic complexity.
+     *
+     * Ŀ⣺
+     * ֵԪءֵָھӵԪ
+     *
+     * һnum[i]  num[i+1]ҵһֵԪز±ꡣ
+     *
+     * ֵܰ·һɡ
+     *
+     * Լnum[-1] = num[n] = -ޣʼԪصĩβԪصҲΪ
+     *
+     * 磬[1, 2, 3, 1]У3ǷֵԪأĺӦ÷±2
+     *
+     * ע⣺
+     * ΪӶȡ
+     * 
+ * + * @param nums + * @return + */ + public int findPeakElement(int[] nums) { + return 0; + } + +} diff --git a/[0167][Two Sum II - Input array is sorted]/[0167][Two Sum II - Input array is sorted].iml b/[0167][Two Sum II - Input array is sorted]/[0167][Two Sum II - Input array is sorted].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0167][Two Sum II - Input array is sorted]/[0167][Two Sum II - Input array is sorted].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0167][Two Sum II - Input array is sorted]/src/Solution.java b/[0167][Two Sum II - Input array is sorted]/src/Solution.java new file mode 100644 index 0000000..74f81cc --- /dev/null +++ b/[0167][Two Sum II - Input array is sorted]/src/Solution.java @@ -0,0 +1,58 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-09-28 16:17 + **/ +public class Solution { + /** + * 如果数组很大,target很小,可以考虑先用二分查找法找到不大于target元素的下标,再作处理 + * @param numbers + * @param target + * @return + */ + public int[] twoSum(int[] numbers, int target) { +// int idx = search(numbers, target); + int idx = numbers.length - 1; + return twoSum(numbers, target, idx); + } + + public int[] twoSum(int[] numbers, int target, int end) { + int[] result = {0, 0}; + + int lo = 0; + int hi = end; + + while (lo < hi) { + if (numbers[lo] + numbers[hi] == target) { + result[0] = lo; + result[1] = hi; + break; + } else if (numbers[lo] + numbers[hi] > target) { + hi--; + } else { + lo++; + } + } + + return result; + } + + public int search(int[] numbers, int target) { + + int lo = 0; + int hi = numbers.length - 1; + int mid; + + while (lo <= hi) { + mid = lo + (hi - lo) / 2; + if (numbers[mid] == target) { + return mid; + } else if (numbers[mid] > target) { + hi = mid - 1; + } else { + lo = mid + 1; + } + + } + return hi; + } +} diff --git a/[0191][Number Of 1 Bits]/[0191][Number Of 1 Bits].iml b/[0191][Number Of 1 Bits]/[0191][Number Of 1 Bits].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0191][Number Of 1 Bits]/[0191][Number Of 1 Bits].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0191][Number Of 1 Bits]/[0191][NumberOf1Bits].iml b/[0191][Number Of 1 Bits]/[0191][NumberOf1Bits].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0191][Number Of 1 Bits]/[0191][NumberOf1Bits].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0191][Number Of 1 Bits]/src/Main.java b/[0191][Number Of 1 Bits]/src/Main.java new file mode 100644 index 0000000..4a645e8 --- /dev/null +++ b/[0191][Number Of 1 Bits]/src/Main.java @@ -0,0 +1,12 @@ +/** + * Author: + * Date: 2015-06-18 + * Time: 09:17 + * Declaration: All Rights Reserved !!! + */ +public class Main { + public static void main(String[] args) { + Solution solution = new Solution(); + System.out.println(solution.hammingWeight(0B11111111_01010101)); + } +} diff --git a/[0191][Number Of 1 Bits]/src/Solution.java b/[0191][Number Of 1 Bits]/src/Solution.java new file mode 100644 index 0000000..5b782f6 --- /dev/null +++ b/[0191][Number Of 1 Bits]/src/Solution.java @@ -0,0 +1,30 @@ +/** + * Author: + * Date: 2015-06-17 + * Time: 21:51 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + * Write a function that takes an unsigned integer and returns the number of 1' bits it has + * (also known as the Hamming weight). + * + * For example, the 32-bit integer 11' has binary representation 00000000000000000000000000001011, + * so the function should return 3. + * + * еλ + * + * @param n + * @return + */ + // you need to treat n as an unsigned value + public int hammingWeight(int n) { + + int count = 0; + while (n != 0) { + count++; + n = (n - 1) & n; + } + return count; + } +} diff --git a/[0198][House Robber]/[0198][House Robber].iml b/[0198][House Robber]/[0198][House Robber].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0198][House Robber]/[0198][House Robber].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0198][House Robber]/[0198][HouseRobber].iml b/[0198][House Robber]/[0198][HouseRobber].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0198][House Robber]/[0198][HouseRobber].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0198][House Robber]/src/Main.java b/[0198][House Robber]/src/Main.java new file mode 100644 index 0000000..1904d36 --- /dev/null +++ b/[0198][House Robber]/src/Main.java @@ -0,0 +1,12 @@ +/** + * Author: + * Date: 2015-06-18 + * Time: 09:17 + * Declaration: All Rights Reserved !!! + */ +public class Main { + public static void main(String[] args) { + Solution solution = new Solution(); + System.out.println(solution.rob(new int[]{1, 2, 3, 4, 5, 6, 6, 10, 7, 8, 9})); + } +} diff --git a/[0198][House Robber]/src/Solution.java b/[0198][House Robber]/src/Solution.java new file mode 100644 index 0000000..48d3efa --- /dev/null +++ b/[0198][House Robber]/src/Solution.java @@ -0,0 +1,61 @@ +/** + * Author: + * Date: 2015-06-17 + * Time: 22:00 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + * You are a professional robber planning to rob houses along a street. Each house has a + * certain amount of money stashed, the only constraint stopping you from robbing each + * of them is that adjacent houses have security system connected and it will automatically + * contact the police if two adjacent houses were broken into on the same night. + *

+ * Given a list of non-negative integers representing the amount of money of each house, + * determine the maximum amount of money you can rob tonight without alerting the police. + *

+ * Ŀ⣺һרҵǿƻһִҽᡣÿ䷿ݶһĽǮΨһֹ + * ٵԼǣڷ֮аȫϵͳͬһڵķݱ룬Ǿͻ + * 羯죬˲Դڵķݡ + *

+ * һзǸÿ䷿ݵĽǮڲǰһԴٵĽǮ + * ˼·̬滮Dynamic Programming + * ״̬תƷ̣dp[i] = max(dp[i - 2], dp[i - 3]) + num[i] A + * Уdp[i]ʾٵi䷿ʱۼȡõĽǮֵ + * ( i λõ max ֵ max(i-2, i-3) i λõֵԴ) + * + * @param nums + * @return + */ + public int rob(int[] nums) { + + if (nums == null || nums.length == 0) { + return 0; + } + + // еԪظ2ڡAʽi=2dp[2-3] + if (nums.length > 2) { + nums[2] += nums[0]; + } + + // ӵĸԪؿʼ + int i = 3; + for (; i < nums.length; i++) { + // iԪصֵ + nums[i] += Math.max(nums[i - 2], nums[i - 3]); + } + + // ֻһԪأԪֵ + if (nums.length == 1) { + return nums[0]; + } + // Ԫطнϴֵ + else if (nums.length == 2) { + return Math.max(nums[0], nums[1]); + } + // Ԫأֵĩβ֮䣬ķ + else { + return Math.max(nums[i - 1], nums[i - 2]); + } + } +} diff --git a/[0199][Binary Tree Right Side View]/[0199][Binary Tree Right Side View].iml b/[0199][Binary Tree Right Side View]/[0199][Binary Tree Right Side View].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0199][Binary Tree Right Side View]/[0199][Binary Tree Right Side View].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0199][Binary Tree Right Side View]/[0199][BinaryTreeRightSideView].iml b/[0199][Binary Tree Right Side View]/[0199][BinaryTreeRightSideView].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0199][Binary Tree Right Side View]/[0199][BinaryTreeRightSideView].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0199][Binary Tree Right Side View]/src/Solution.java b/[0199][Binary Tree Right Side View]/src/Solution.java new file mode 100644 index 0000000..c591727 --- /dev/null +++ b/[0199][Binary Tree Right Side View]/src/Solution.java @@ -0,0 +1,77 @@ +import java.util.Deque; +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-06-20 + * Time: 12:18 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *

+     * Given a binary tree, imagine yourself standing on the right side of it,
+     * return the values of the nodes you can see ordered from top to bottom.
+     *
+     * For example:
+     * Given the following binary tree,
+     *      1            <---
+     *    /   \
+     *   2     3         <---
+     *    \     \
+     *     5     4       <---
+     * You should return [1, 3, 4].
+     *
+     *  Ŀ⣺
+     *  һԼվұߣشµܿĽڵֵ
+     *
+     * ˼·
+     * IJαÿ㰴մҵ˳ηʽڵ㣬ÿһȡұߵĽ㣩
+     * 
+ * + * @param root + * @return + */ + public List rightSideView(TreeNode root) { + List result = new LinkedList<>(); + + if (root != null) { + Deque deque = new LinkedList<>(); + // ǰĽ + int current = 1; + // һĽ + int next = 0; + TreeNode node; + deque.addLast(root); + while (deque.size() > 0) { + // ȡһ + node = deque.removeFirst(); + current--; + + // ӷǿյ + if (node.left != null) { + next++; + deque.addLast(node.left); + } + + // ӷǿյҽ + if (node.right != null) { + next++; + deque.addLast(node.right); + } + + // ǰѾ + if (current == 0) { + // ˲һֵ + result.add(node.val); + // һԪظ + current = next; + next = 0; + } + } + } + + return result; + } +} diff --git a/[0199][Binary Tree Right Side View]/src/TreeNode.java b/[0199][Binary Tree Right Side View]/src/TreeNode.java new file mode 100644 index 0000000..35a2b83 --- /dev/null +++ b/[0199][Binary Tree Right Side View]/src/TreeNode.java @@ -0,0 +1,15 @@ +/** + * Author: + * Date: 2015-06-20 + * Time: 12:18 + * Declaration: All Rights Reserved !!! + */ +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} diff --git a/[0200][Number Of Islands]/[0200][Number Of Islands].iml b/[0200][Number Of Islands]/[0200][Number Of Islands].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0200][Number Of Islands]/[0200][Number Of Islands].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0200][Number Of Islands]/[0200][NumberOfIslands].iml b/[0200][Number Of Islands]/[0200][NumberOfIslands].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0200][Number Of Islands]/[0200][NumberOfIslands].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0200][Number Of Islands]/src/Solution.java b/[0200][Number Of Islands]/src/Solution.java new file mode 100644 index 0000000..47991f4 --- /dev/null +++ b/[0200][Number Of Islands]/src/Solution.java @@ -0,0 +1,89 @@ +/** + * Author: + * Date: 2015-06-20 + * Time: 11:00 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Given a 2d grid map of '1's (land) and '0's (water), count the number of islands.
+     * An island is surrounded by water and is formed by connecting adjacent lands horizontally
+     * or vertically. You may assume all four edges of the grid are all surrounded by water.
+     *
+     * Example 1:
+     *      11110
+     *      11010
+     *      11000
+     *      00000
+     * Answer: 1
+     *
+     * Example 2:
+     *      11000
+     *      11000
+     *      00100
+     *      00011
+     * Answer: 3
+     *
+     * Ŀ⣺
+     * һάĵͼ'1'½أ0ˮ滷ˮ
+     * ڵ½ˮƽֱӶγɵġԼĸ߶ˮΧ
+     *
+     * ˼·
+     * һһӦķʱǾ󣬶ÿԪʱйȱȱͳƵĿ
+     *
+     * 
+ * + * @param grid + * @return + */ + public int numIslands(char[][] grid) { + // У + if (grid == null || grid.length == 0 || grid[0].length == 0) { + return 0; + } + + // ԪĬֵfalse + boolean[][] visited = new boolean[grid.length][grid[0].length]; + + int result = 0; + for (int i = 0; i < grid.length; i++) { + for (int j = 0; j < grid[0].length; j++) { + // λûбʹҴλǵ¹ȱ + if (!visited[i][j] && grid[i][j] == '1') { + result++; + bfs(grid, visited, i, j); + } + } + } + return result; + } + + /** + * + * @param grid + * @param visited ʱǾ + * @param row + * @param col + */ + private void bfs(char[][] grid, boolean[][] visited, int row, int col) { + + if (row >= 0 && row < grid.length // кϷ + && col >= 0 && col < grid[0].length // кϷ + && !visited[row][col] // ûзʹ + && grid[row][col] == '1') { // ǵ½ + + // ǴλѾʹ + visited[row][col] = true; + + // + bfs(grid, visited, row - 1, col); + // + bfs(grid, visited, row, col + 1); + // + bfs(grid, visited, row + 1, col); + // + bfs(grid, visited, row, col - 1); + } + } +} diff --git a/[0201][Bitwise AND Of Numbers Range]/[0201][Bitwise AND Of Numbers Range].iml b/[0201][Bitwise AND Of Numbers Range]/[0201][Bitwise AND Of Numbers Range].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0201][Bitwise AND Of Numbers Range]/[0201][Bitwise AND Of Numbers Range].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0201][Bitwise AND Of Numbers Range]/[0201][BitwiseANDOfNumbersRange].iml b/[0201][Bitwise AND Of Numbers Range]/[0201][BitwiseANDOfNumbersRange].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0201][Bitwise AND Of Numbers Range]/[0201][BitwiseANDOfNumbersRange].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0201][Bitwise AND Of Numbers Range]/src/Solution.java b/[0201][Bitwise AND Of Numbers Range]/src/Solution.java new file mode 100644 index 0000000..8e30521 --- /dev/null +++ b/[0201][Bitwise AND Of Numbers Range]/src/Solution.java @@ -0,0 +1,40 @@ +/** + * Author: + * Date: 2015-06-20 + * Time: 08:56 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND
+     * of all numbers in this range, inclusive.
+     *
+     * For example, given the range [5, 7], you should return 4.
+     *
+     * Ŀ⣺
+     * һΧΧеλĽ
+     *
+     * ˼·
+     * m!=nôĩλض0Ϊ[m, n]ضżĩλ0Խmnһλ
+     * Ϊmk nk൱ڽ[m, n]֮еƶһλmk=nkʱ˵֮ǰ
+     * [m, n]֮һλȵģƺANDm(=n)ԲͿֹͣ
+     * ¼ƵĴoffsetm>>offsetΪ
+     * 
+ * + * @param m + * @param n + * @return + */ + public int rangeBitwiseAnd(int m, int n) { + int offset = 0; + + while (m != n) { + m >>= 1; + n >>= 1; + offset++; + } + + return m << offset; + } +} diff --git a/[0202][Happy Number ]/[0202][Happy Number ].iml b/[0202][Happy Number ]/[0202][Happy Number ].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0202][Happy Number ]/[0202][Happy Number ].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0202][Happy Number ]/[0202][HappyNumber ].iml b/[0202][Happy Number ]/[0202][HappyNumber ].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0202][Happy Number ]/[0202][HappyNumber ].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0202][Happy Number ]/src/Main.java b/[0202][Happy Number ]/src/Main.java new file mode 100644 index 0000000..97bf463 --- /dev/null +++ b/[0202][Happy Number ]/src/Main.java @@ -0,0 +1,12 @@ +/** + * Author: + * Date: 2015-06-18 + * Time: 09:17 + * Declaration: All Rights Reserved !!! + */ +public class Main { + public static void main(String[] args) { + Solution solution = new Solution(); + System.out.println(solution.isHappy(19)); + } +} diff --git a/[0202][Happy Number ]/src/Solution.java b/[0202][Happy Number ]/src/Solution.java new file mode 100644 index 0000000..5df793f --- /dev/null +++ b/[0202][Happy Number ]/src/Solution.java @@ -0,0 +1,51 @@ +import java.util.HashSet; + +/** + * Author: + * Date: 2015-06-17 + * Time: 21:36 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + * Write an algorithm to determine if a number is "happy". + * A happy number is a number defined by the following process: Starting with any positive integer, + * replace the number by the sum of the squares of its digits, and repeat the process until the number + * equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those + * numbers for which this process ends in 1 are happy numbers. + * + * ĿҪһϸλֵƽͣΪ1Ϊhappy number + * ܴijʼѭ + * + * @param n + * @return + */ + public boolean isHappy(int n) { + + if (n < 1) { + return false; + } + + // ڱмֵĽ + HashSet set = new HashSet<>(32); + + int tmp; + int newN; + + // nΪ1nֵظ֣ѭ + while (n != 1 && !set.contains(n)) { + set.add(n); + newN = 0; + while (n > 0) { + tmp = n % 10; + n /= 10; + newN += tmp * tmp; + } + + n = newN; + } + + return n == 1; + } + +} diff --git a/[0203][Remove Linked List Elements]/[0203][Remove Linked List Elements].iml b/[0203][Remove Linked List Elements]/[0203][Remove Linked List Elements].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0203][Remove Linked List Elements]/[0203][Remove Linked List Elements].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0203][Remove Linked List Elements]/[0203][RemoveLinkedList Elements].iml b/[0203][Remove Linked List Elements]/[0203][RemoveLinkedList Elements].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0203][Remove Linked List Elements]/[0203][RemoveLinkedList Elements].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0203][Remove Linked List Elements]/src/ListNode.java b/[0203][Remove Linked List Elements]/src/ListNode.java new file mode 100644 index 0000000..4f82c20 --- /dev/null +++ b/[0203][Remove Linked List Elements]/src/ListNode.java @@ -0,0 +1,14 @@ +/** + * Author: + * Date: 2015-06-19 + * Time: 13:57 + * Declaration: All Rights Reserved !!! + */ +public class ListNode { + int val; + ListNode next; + + ListNode(int x) { + val = x; + } +} diff --git a/[0203][Remove Linked List Elements]/src/Solution.java b/[0203][Remove Linked List Elements]/src/Solution.java new file mode 100644 index 0000000..b58cbfd --- /dev/null +++ b/[0203][Remove Linked List Elements]/src/Solution.java @@ -0,0 +1,46 @@ +/** + * Author: + * Date: 2015-06-19 + * Time: 13:57 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + * Remove all elements from a linked list of integers that have value val. + *

+ * Example + * Given: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6 + * Return: 1 --> 2 --> 3 --> 4 --> 5 + *

+ * һֵvalڵɾֵΪvalĽ + *

+ * ˼· + * ͷһ㣬ɾ + * + * @param head + * @param val + * @return + */ + public ListNode removeElements(ListNode head, int val) { + ListNode root = new ListNode(1); + root.next = head; + // ڼ¼ҪԪصǰ + ListNode prev = root; + + // prev.nextʾҪĽ + while (prev.next != null) { + // ҪĽҪɾĽ + if (prev.next.val == val) { + // Խɾ + prev.next = prev.next.next; + } + // ǰĽڵ㲻Ҫɾprevƶһ + else { + prev = prev.next; + } + } + + // µĸ + return root.next; + } +} diff --git a/[0204][Count Primes]/[0204][Count Primes].iml b/[0204][Count Primes]/[0204][Count Primes].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0204][Count Primes]/[0204][Count Primes].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0204][Count Primes]/[0204][CountPrimes].iml b/[0204][Count Primes]/[0204][CountPrimes].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0204][Count Primes]/[0204][CountPrimes].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0204][Count Primes]/src/Solution.java b/[0204][Count Primes]/src/Solution.java new file mode 100644 index 0000000..25b999a --- /dev/null +++ b/[0204][Count Primes]/src/Solution.java @@ -0,0 +1,52 @@ +/** + * Author: + * Date: 2015-06-19 + * Time: 14:51 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /*** + * Description: + * Count the number of prime numbers less than a non-negative number, n. + *

+ * Ŀ⣺ + * ͳСڷǸnĸ + *

+ * ˼· + * ʹüɫɸ + * + * @param n + * @return + */ + public int countPrimes(int n) { + + if (n <= 1) { + return 0; + } + + // ĬеԪֵΪfalse + boolean[] notPrime = new boolean[n]; + notPrime[0] = true; + notPrime[1] = true; + + for (int i = 2; i * i < n; i++) { + // iһiiıΪ + // iһضѾΪtrueˣΪǴ2ʼ + if (!notPrime[i]) { + for (int j = 2 * i; j < n; j += i) { + notPrime[j] = true; + } + } + } + + // ͳĸ + int result = 0; + for (boolean b : notPrime) { + if (!b) { + result++; + } + } + + return result; + } +} diff --git a/[0205][Isomorphic Strings]/[0205][Isomorphic Strings].iml b/[0205][Isomorphic Strings]/[0205][Isomorphic Strings].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0205][Isomorphic Strings]/[0205][Isomorphic Strings].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0205][Isomorphic Strings]/[0205][IsomorphicStrings].iml b/[0205][Isomorphic Strings]/[0205][IsomorphicStrings].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0205][Isomorphic Strings]/[0205][IsomorphicStrings].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0205][Isomorphic Strings]/src/Solution.java b/[0205][Isomorphic Strings]/src/Solution.java new file mode 100644 index 0000000..23d9130 --- /dev/null +++ b/[0205][Isomorphic Strings]/src/Solution.java @@ -0,0 +1,109 @@ +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * Author: + * Date: 2015-06-19 + * Time: 11:57 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + * Given two strings s and t, determine if they are isomorphic. + *

+ * Two strings are isomorphic if the characters in s can be replaced to get t. + *

+ * All occurrences of a character must be replaced with another character while + * preserving the order of characters. No two characters may map to the same character + * but a character may map to itself. + *

+ * For example, + * Given "egg", "add", return true. + * Given "foo", "bar", return false. + * Given "paper", "title", return true. + *

+ * Note: + * You may assume both s and t have the same length. + *

+ * Ŀ⣺ + * ַstжǷͬġ + *

+ * ַsַͨ滻ķʽõַtstͬġ + *

+ * ַÿһγֶ뱻Ӧַ滻ͬʱҪ֤ԭʼ˳򲻷ı䡣 + * ַӳ䵽ͬһַַӳ䵽䱾 + *

+ * Ŀ + * Լstȳ + *

+ * ˼· + * ֻҪstһһӳͿˡ + * ʹһϣmapάַַӳϵͬʱһsetӳֵ + * (s[i], t[i])s[i]ûmapгֹt[i]ûsetгֹͼ뵽ӳϵУ + * t[i]ֵѾֹ˵Ƕһӳ䣬Ϸfalses[i]Ѿֹ + * Ϊs[k]ӦӳֵΪt[k]),s[i]==s[k],ҳs[k]ĶԶӦֵt[k] + * t[i]!=t[k],˵һͬһַͬӳ䣬ַͬģfalse + * һֱַ + *

+ * ӳ䲻һµʱFalse򷵻True + * + * @param s + * @param t + * @return + */ + public boolean isIsomorphic(String s, String t) { + + // ַΪ + if (s == null && t == null) { + return true; + } + // ֻһΪ + else if (s == null || t == null) { + return false; + } + // ַijȶΪ0 + else if (s.length() == 0 && t.length() == 0) { + return true; + } + // ַijȲ + else if (s.length() != t.length()) { + return false; + } + + // ӳϵ + Map map = new HashMap<>(s.length()); + Set set = new HashSet<>(t.length()); + char sChar; + char tChar; + for (int i = 0; i < s.length(); i++) { + sChar = s.charAt(i); + tChar = t.charAt(i); + + // δֹͰӳϵ + if (!map.containsKey(sChar)) { + if (set.contains(tChar)) { + return false; + } else { + map.put(s.charAt(i), t.charAt(i)); + set.add(tChar); + } + } + // ǼѾֹ + else { + + // ԭȵļӳֵmap.get(sChar)ҪӳֵtChar + // ֵȣ˵ѾӳΣϣfalse + if (map.get(sChar) != tChar) { + return false; + } + } + + + } + + + return true; + } +} diff --git a/[0206][Reverse Linked List]/[0206][Reverse Linked List].iml b/[0206][Reverse Linked List]/[0206][Reverse Linked List].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0206][Reverse Linked List]/[0206][Reverse Linked List].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0206][Reverse Linked List]/src/ListNode.java b/[0206][Reverse Linked List]/src/ListNode.java new file mode 100644 index 0000000..845bd94 --- /dev/null +++ b/[0206][Reverse Linked List]/src/ListNode.java @@ -0,0 +1,14 @@ +/** + * Author: + * Date: 2015-06-19 + * Time: 11:18 + * Declaration: All Rights Reserved !!! + */ +public class ListNode { + int val; + ListNode next; + + ListNode(int x) { + val = x; + } +} \ No newline at end of file diff --git a/[0206][Reverse Linked List]/src/Main.java b/[0206][Reverse Linked List]/src/Main.java new file mode 100644 index 0000000..449e76c --- /dev/null +++ b/[0206][Reverse Linked List]/src/Main.java @@ -0,0 +1,8 @@ +/** + * Author: + * Date: 2015-06-19 + * Time: 11:17 + * Declaration: All Rights Reserved !!! + */ +public class Main { +} diff --git a/[0206][Reverse Linked List]/src/Solution.java b/[0206][Reverse Linked List]/src/Solution.java new file mode 100644 index 0000000..3799055 --- /dev/null +++ b/[0206][Reverse Linked List]/src/Solution.java @@ -0,0 +1,47 @@ +/** + * Author: + * Date: 2015-06-19 + * Time: 11:17 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + * Reverse a singly linked list. + * ת + * ʹͷ巨 + * + * @param head + * @return + */ + public ListNode reverseList(ListNode head) { + // ͷ + ListNode root = new ListNode(0); + ListNode nextNode; + while (head != null) { + nextNode = head.next; + head.next = root.next; + root.next = head; + head = nextNode; + } + + head = root.next; + root.next = null; + + return head; + } + + /** + * TODO ʹõݹⷨ + * @param head + * @return + */ + public ListNode reverseList2(ListNode head) { + if (head == null) { + return null; + } + + reverseList2(head.next).next = head; + + return null; + } +} diff --git a/[0215][Kth Largest Element In An Array]/[0215][Kth Largest Element In An Array].iml b/[0215][Kth Largest Element In An Array]/[0215][Kth Largest Element In An Array].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0215][Kth Largest Element In An Array]/[0215][Kth Largest Element In An Array].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0215][Kth Largest Element In An Array]/[0215][KthLargestElementInAnArray].iml b/[0215][Kth Largest Element In An Array]/[0215][KthLargestElementInAnArray].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0215][Kth Largest Element In An Array]/[0215][KthLargestElementInAnArray].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0215][Kth Largest Element In An Array]/src/Main.java b/[0215][Kth Largest Element In An Array]/src/Main.java new file mode 100644 index 0000000..cd77742 --- /dev/null +++ b/[0215][Kth Largest Element In An Array]/src/Main.java @@ -0,0 +1,12 @@ +/** + * Author: + * Date: 2015-06-19 + * Time: 20:01 + * Declaration: All Rights Reserved !!! + */ +public class Main { + public static void main(String[] args) { + Solution solution = new Solution(); + System.out.println(solution.findKthLargest(new int[]{2 , 1}, 2)); + } +} diff --git a/[0215][Kth Largest Element In An Array]/src/Solution.java b/[0215][Kth Largest Element In An Array]/src/Solution.java new file mode 100644 index 0000000..8119edf --- /dev/null +++ b/[0215][Kth Largest Element In An Array]/src/Solution.java @@ -0,0 +1,81 @@ +import java.util.Collections; + +/** + * Author: + * Date: 2015-06-19 + * Time: 19:36 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *

+     * Find the kth largest element in an unsorted array. Note that it is the kth
+     * largest element in the sorted order, not the kth distinct element.
+     *
+     * For example,
+     * Given [3,2,1,5,6,4] and k = 2, return 5.
+     *
+     * Note:
+     * You may assume k is always valid, 1  k  array's length.
+     *
+     * Ŀ⣺
+     * һδҳkԪءע֮ĵk󣬶ǵkظԪ
+     * ԼkһЧģ 1  k  鳤
+     *
+     * ˼·
+     * O(n)ⷨѡQuickSelect㷨
+     * 
+ * + * @param nums + * @param k + * @return + */ + public int findKthLargest(int[] nums, int k) { + + if (k < 1 || nums == null || nums.length < k) { + throw new IllegalArgumentException(); + } + + return findKthLargest(nums, 0, nums.length - 1, k); + } + + public int findKthLargest(int[] nums, int start, int end, int k) { + + // ֵ + int pivot = nums[start]; + int lo = start; + int hi = end; + + while (lo < hi) { + // Сֵƶ + while (lo < hi && nums[hi] >= pivot) { + hi--; + } + nums[lo] = nums[hi]; + + // ֵƶұ + while (lo < hi && nums[lo] <= pivot) { + lo++; + } + nums[hi] = nums[lo]; + } + + nums[lo] = pivot; + + // Ѿҵ + if (end - lo + 1 == k) { + return pivot; + } + // kloλõұ + else if (end - lo + 1 > k){ + return findKthLargest(nums, lo + 1, end, k); + } + // kloλõ + else { + // k-(end-lo+1) + // (end-lo+1)ʾloλÿʼendλõԪظҰ벿 + // ԭĵkk-(end-lo+1) + return findKthLargest(nums, start, lo - 1, k - (end - lo + 1)); + } + } +} diff --git a/[0216][Combination Sum III]/[0216][Combination Sum III].iml b/[0216][Combination Sum III]/[0216][Combination Sum III].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0216][Combination Sum III]/[0216][Combination Sum III].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0216][Combination Sum III]/[0216][CombinationSumIII].iml b/[0216][Combination Sum III]/[0216][CombinationSumIII].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0216][Combination Sum III]/[0216][CombinationSumIII].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0216][Combination Sum III]/src/Main.java b/[0216][Combination Sum III]/src/Main.java new file mode 100644 index 0000000..4378e2a --- /dev/null +++ b/[0216][Combination Sum III]/src/Main.java @@ -0,0 +1,15 @@ +/** + * Author: + * Date: 2015-06-21 + * Time: 22:05 + * Declaration: All Rights Reserved !!! + */ +public class Main { + public static void main(String[] args) { + Solution solution = new Solution(); +// System.out.println(solution.combinationSum3(3, 7)); +// System.out.println(solution.combinationSum3(3, 9)); +// System.out.println(solution.combinationSum3(4, 24)); + System.out.println(solution.combinationSum3(9, 45)); + } +} diff --git a/[0216][Combination Sum III]/src/Solution.java b/[0216][Combination Sum III]/src/Solution.java new file mode 100644 index 0000000..e2c8e6f --- /dev/null +++ b/[0216][Combination Sum III]/src/Solution.java @@ -0,0 +1,101 @@ +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +/** + * Author: + * Date: 2015-06-21 + * Time: 21:31 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + /** + *
+     * Find all possible combinations of k numbers that add up to a number n,
+     * given that only numbers from 1 to 9 can be used and each combination
+     * should be a unique set of numbers.
+     *
+     * Ensure that numbers within the set are sorted in ascending order.
+     *
+     * Example 1:
+     * Input: k = 3, n = 7
+     * Output:
+     * [[1,2,4]]
+     *
+     * Example 2:
+     * Input: k = 3, n = 9
+     * Output:
+     * [[1,2,6], [1,3,5], [2,3,4]]
+     *
+     * Ŀ⣺
+     * Ѱk֮͵nϣֻʹ1-9ÿһеӦΨһġ
+     * ȷеԵ˳С
+     *
+     * ˼·
+     * ݷ
+     * 
+ * + * @param k + * @param n + * @return + */ + public List> combinationSum3(int k, int n) { + // ڱн + List> result = new LinkedList<>(); + // ڱм + List list = new LinkedList<>(); + // ͽн + if (k > 0 && k <= 9) { + solve(k, 1, n, 0, list, result); + } + + // ؽ + return result; + } + + /** + * ⷽ + * + * @param k ÿԪظ + * @param cur ǰkԪ + * @param remainder k - cur + 1Ԫصĺ + * @param prevVal cur-1Ԫصȡֵ + * @param list Ԫصļ + * @param result н + */ + public void solve(int k, int cur, int remainder, int prevVal, List list, List> result) { + // һԪ + if (cur == k) { + // remainderΪһԪصֵǰһԪصֵҲܳ9 + if (remainder > prevVal && remainder <= 9) { + // Ԫֵ + list.add(remainder); + + // µĶ + List one = new LinkedList<>(); + for (Integer i : list) { + one.add(i); + } + + // + result.add(one); + // ɾһԪأֳԭ + list.remove(list.size() - 1); + } + } + // һԪ + else if (cur < k){ + for (int i = prevVal + 1; i <= 9 - (k - cur); i++) { + // Ԫ + list.add(i); + // ݹ + solve(k, cur + 1, remainder - i, i, list, result); + // ֳԭ + list.remove(list.size() - 1); + + } + } + + + } +} diff --git a/[0217][Contains Duplicate ]/[0217][Contains Duplicate ].iml b/[0217][Contains Duplicate ]/[0217][Contains Duplicate ].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0217][Contains Duplicate ]/[0217][Contains Duplicate ].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0217][Contains Duplicate ]/[0217][ContainsDuplicate ].iml b/[0217][Contains Duplicate ]/[0217][ContainsDuplicate ].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0217][Contains Duplicate ]/[0217][ContainsDuplicate ].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0217][Contains Duplicate ]/src/Main.java b/[0217][Contains Duplicate ]/src/Main.java new file mode 100644 index 0000000..b144561 --- /dev/null +++ b/[0217][Contains Duplicate ]/src/Main.java @@ -0,0 +1,13 @@ +/** + * Author: + * Date: 2015-06-18 + * Time: 09:59 + * Declaration: All Rights Reserved !!! + */ +public class Main { + public static void main(String[] args) { + Solution solution = new Solution(); + System.out.println(solution.containsDuplicate(new int[]{1, 2, 8, 3, 4, 4, 7, 4, 5})); + System.out.println(solution.containsDuplicate(new int[]{1, 2, 3, 4, 7, 5})); + } +} diff --git a/[0217][Contains Duplicate ]/src/Solution.java b/[0217][Contains Duplicate ]/src/Solution.java new file mode 100644 index 0000000..67fdbb9 --- /dev/null +++ b/[0217][Contains Duplicate ]/src/Solution.java @@ -0,0 +1,46 @@ +import java.util.HashSet; +import java.util.Set; + +/** + * Author: + * Date: 2015-06-18 + * Time: 09:40 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + + + /** + * Given an array of integers, find if the array contains any duplicates. + * Your function should return true if any value appears at least twice in the + * array, and it should return false if every element is distinct. + *

+ * Ŀ⣺һ飬жǷظԪءһֳΣ + * ĺӦ÷trueÿһԪضΨһģfalse + * + * ˼·setݽṹ + * + * @param nums + * @return + */ + public boolean containsDuplicate(int[] nums) { + + // Ԫظ1ŽIJ + if (nums != null && nums.length > 1) { + //һhashSet + Set set = new HashSet<>(nums.length); + for(int i : nums) { + // ԪѾھͷtrue + if (set.contains(i)) { + return true; + } + // ûоӵԪؼ + else { + set.add(i); + } + } + } + + return false; + } +} diff --git a/[0219][Contains Duplicate II]/[0219][Contains Duplicate II].iml b/[0219][Contains Duplicate II]/[0219][Contains Duplicate II].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0219][Contains Duplicate II]/[0219][Contains Duplicate II].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0219][Contains Duplicate II]/[0219][ContainsDuplicateII].iml b/[0219][Contains Duplicate II]/[0219][ContainsDuplicateII].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0219][Contains Duplicate II]/[0219][ContainsDuplicateII].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0219][Contains Duplicate II]/src/Solution.java b/[0219][Contains Duplicate II]/src/Solution.java new file mode 100644 index 0000000..2fa0545 --- /dev/null +++ b/[0219][Contains Duplicate II]/src/Solution.java @@ -0,0 +1,55 @@ +import java.util.HashMap; +import java.util.Map; + +/** + * Author: + * Date: 2015-06-19 + * Time: 14:10 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + + /** + * Given an array of integers and an integer k, find out whether there there are + * two distinct indices i and j in the array such that nums[i] = nums[j] and the + * difference between i and j is at most k. + * + * Ŀ⣺ + * һnumsһkҽͬ±ijnums[i] = nums[j] + * |i-j|<=kʱtrue򷵻false + * + * ˼· + * nums[0...n-1]һmapУ(muns[i], i)nums[k]Ѿڣ + * Ƚ֮ǰ±ڵ±IJֵֵk˵ֵ + * ʹµ±Ϊֵ + * + * @param nums + * @param k + * @return + */ + public boolean containsNearbyDuplicate(int[] nums, int k) { + // ж + if (nums == null || nums.length < 2 || k < 1) { + return false; + } + + Map map = new HashMap<>(); + for (int i = 0; i < nums.length; i++) { + + // ûжӦkeyӽȥ + if (!map.containsKey(nums[i])) { + map.put(nums[i], i); + } + // ѾжӦkey-value + else { + // ԭֵӦ±꣬һСڵ± + int value = map.get(nums[i]); + if (i - value <= k) { + return true; + } + map.put(nums[i], i); + } + } + return false; + } +} diff --git a/[0223][Rectangle Area]/[0223][Rectangle Area].iml b/[0223][Rectangle Area]/[0223][Rectangle Area].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0223][Rectangle Area]/[0223][Rectangle Area].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0223][Rectangle Area]/[0223][RectangleArea].iml b/[0223][Rectangle Area]/[0223][RectangleArea].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0223][Rectangle Area]/[0223][RectangleArea].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0223][Rectangle Area]/src/Main.java b/[0223][Rectangle Area]/src/Main.java new file mode 100644 index 0000000..7afa1b6 --- /dev/null +++ b/[0223][Rectangle Area]/src/Main.java @@ -0,0 +1,14 @@ +/** + * Author: + * Date: 2015-06-19 + * Time: 16:16 + * Declaration: All Rights Reserved !!! + */ +public class Main { + public static void main(String[] args) { + Solution solution = new Solution(); +// System.out.println(solution.computeArea(-2, -2, 2, 2, -2, -2, 2, 2)); +// System.out.println(solution.computeArea(-2, -2, 2, 2, -3, -3, 3, -1)); + System.out.println(solution.computeArea(-1500000001, 0, -1500000000, 1, 1500000000, 0, 1500000001, 1)); + } +} diff --git a/[0223][Rectangle Area]/src/Solution.java b/[0223][Rectangle Area]/src/Solution.java new file mode 100644 index 0000000..f2ea311 --- /dev/null +++ b/[0223][Rectangle Area]/src/Solution.java @@ -0,0 +1,78 @@ +import java.util.*; + +/** + * Author: + * Date: 2015-06-19 + * Time: 15:32 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + + /** + *

+     * Find the total area covered by two rectilinear rectangles in a 2D plane.
+     * Each rectangle is defined by its bottom left corner and top right
+     * corner as shown in the figure.
+     *
+     * Assume that the total area is never beyond the maximum possible value of int.
+     *
+     * *****************************(C,D):(3,4)
+     * *                           *
+     * *                           *
+     * *           *************************************(G,H):(9,2)
+     * *           *               *                   *
+     * *           *               *                   *
+     * *           *               *                   *
+     * *           *               *                   *
+     * *           *(0,0)          *                   *
+     * *****************************                   *
+     * (A,B):(-3,0)*                                   *
+     *             *                                   *
+     *             * (E,F):(0-1)                     *
+     *             *************************************
+     *
+     *   ***************************        ***************************
+     *   *            D            *        *            H            *
+     *   *                         *        *                         *
+     *   *A                       C*        *E                       G*
+     *   *                         *        *                         *
+     *   *                         *        *                         *
+     *   *            B            *        *            F            *
+     *   ***************************        ***************************
+     *
+     *
+     *
+     * 
+ * Ŀ⣺ + * ܹǵ + *

+ * ˼· + * 㷽Ϊ1+2-ιͬĸ + * + * @param A + * @param B + * @param C + * @param D + * @param E + * @param F + * @param G + * @param H + * @return + */ + public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { + long area = (long) (C - A) * (D - B) + (long)(G - E) * (H - F); + // Math.min(C, G) ʾұ߱ߵСı + // Math.max(A, E) ʾ߱ߵı + // ļԽ飬ҪݷΧ + long width = Math.max((long)Math.min(C, G) - (long)Math.max(A, E), 0); + // Math.min(D, H) ʾ߱ߵСı + // Math.max(B, F) ʾױ߱ߵı + long height = Math.max((long)Math.min(D, H) - (long)Math.max(B, F), 0); + + System.out.println(width +":" + height + "=" + width*height); + + return (int)(area - width * height); + } + + +} diff --git a/[0225][Implement Stack Using Queues]/[0225][Implement Stack Using Queues].iml b/[0225][Implement Stack Using Queues]/[0225][Implement Stack Using Queues].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0225][Implement Stack Using Queues]/[0225][Implement Stack Using Queues].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0225][Implement Stack Using Queues]/[0225][ImplementStackUsingQueues].iml b/[0225][Implement Stack Using Queues]/[0225][ImplementStackUsingQueues].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0225][Implement Stack Using Queues]/[0225][ImplementStackUsingQueues].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0225][Implement Stack Using Queues]/src/MyStack.java b/[0225][Implement Stack Using Queues]/src/MyStack.java new file mode 100644 index 0000000..25e0c68 --- /dev/null +++ b/[0225][Implement Stack Using Queues]/src/MyStack.java @@ -0,0 +1,102 @@ +import java.util.LinkedList; +import java.util.List; + +/** + *

+ * Implement the following operations of a stack using queues.
+ *   - push(x)  -- Push element x onto stack.
+ *   - pop()    -- Removes the element on top of the stack.
+ *   - top()    -- Get the top element.
+ *   - empty()  -- Return whether the stack is empty.
+ *
+ * Notes:
+ *   - You must use only standard operations of a queue -- which means only push
+ *          to back, peek/pop from front, size, and is empty operations are valid.
+ *   - Depending on your language, queue may not be supported natively. You may
+ *          simulate a queue by using a list or deque (double-ended queue), as
+ *          long as you use only standard operations of a queue.
+ *   - You may assume that all operations are valid (for example, no pop or top
+ *          operations will be called on an empty stack).
+ *
+ *  Ŀ⣺
+ *  ʹöʵջ
+ *   - push(x)  -- Ԫջ
+ *   - pop()    -- Ԫسջ
+ *   - top()    -- ȡջԪֵ
+ *   - empty()  -- жջǷΪ
+ *  ע⣺
+ *   - ֻʹöеı׼ȽȳԪж϶ǷΪ
+ *   - ڱԭЩԲ֧ĦУʹ˫棬ʹñ׼Ķв
+ *   - ԼеIJǺϷģΪʱԪسջջԪصIJ
+ *
+ * ˼·
+ * ģһջ
+ * 
+ *

+ * Author: + * Date: 2015-06-22 + * Time: 20:45 + * Declaration: All Rights Reserved !!! + */ +public class MyStack { + + // άУһΪգΪpoptop׼ + private List aList = new LinkedList<>(); + private List bList = new LinkedList<>(); + + + // Push element x onto stack. + public void push(int x) { + // aListǿգͽxӵaList + if (!aList.isEmpty()) { + aList.add(x); + } + // ӵbList + else { + bList.add(x); + } + } + + // Removes the element on top of the stack. + public void pop() { + + // һΪգaList÷ǿ + if (aList.isEmpty()) { + List tmp = bList; + bList = aList; + aList = tmp; + } + + // һԪⶼתƵbList + while (aList.size() > 1) { + bList.add(aList.remove(0)); + } + + // ɾһԪأӦջջԪأ + aList.clear(); + } + + // Get the top element. + public int top() { + + // һΪգaList÷ǿ + if (aList.isEmpty()) { + List tmp = bList; + bList = aList; + aList = tmp; + } + + // һԪⶼתƵbList + while (aList.size() > 1) { + bList.add(aList.remove(0)); + } + + bList.add(aList.get(0)); + return aList.remove(0); + } + + // Return whether the stack is empty. + public boolean empty() { + return aList.isEmpty() && bList.isEmpty(); + } +} diff --git a/[0226][Invert Binary Tree]/[0226][Invert Binary Tree].iml b/[0226][Invert Binary Tree]/[0226][Invert Binary Tree].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0226][Invert Binary Tree]/[0226][Invert Binary Tree].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0226][Invert Binary Tree]/[0226][InvertBinaryTree ].iml b/[0226][Invert Binary Tree]/[0226][InvertBinaryTree ].iml new file mode 100644 index 0000000..f080bef --- /dev/null +++ b/[0226][Invert Binary Tree]/[0226][InvertBinaryTree ].iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0226][Invert Binary Tree]/src/Solution.java b/[0226][Invert Binary Tree]/src/Solution.java new file mode 100644 index 0000000..f02e962 --- /dev/null +++ b/[0226][Invert Binary Tree]/src/Solution.java @@ -0,0 +1,27 @@ +/** + * Author: + * Date: 2015-06-18 + * Time: 10:01 + * Declaration: All Rights Reserved !!! + */ +public class Solution { + public TreeNode invertTree(TreeNode root) { + + if (root != null) { + invertTreeNode(root); + } + return root; + } + + public void invertTreeNode(TreeNode root) { + + if (root != null) { + TreeNode tmp = root.left; + root.left = root.right; + root.right = tmp; + + invertTree(root.left); + invertTree(root.right); + } + } +} diff --git a/[0226][Invert Binary Tree]/src/TreeNode.java b/[0226][Invert Binary Tree]/src/TreeNode.java new file mode 100644 index 0000000..73c7ed9 --- /dev/null +++ b/[0226][Invert Binary Tree]/src/TreeNode.java @@ -0,0 +1,15 @@ +/** + * Author: + * Date: 2015-06-18 + * Time: 10:02 + * Declaration: All Rights Reserved !!! + */ +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} diff --git a/[0231][Power of Two]/[0231][Power of Two].iml b/[0231][Power of Two]/[0231][Power of Two].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0231][Power of Two]/[0231][Power of Two].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0231][Power of Two]/src/Solution.java b/[0231][Power of Two]/src/Solution.java new file mode 100644 index 0000000..dee3309 --- /dev/null +++ b/[0231][Power of Two]/src/Solution.java @@ -0,0 +1,28 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-09 09:24 + **/ +public class Solution { + public boolean isPowerOfTwo(int n) { + if (n < 1) { + return false; + } + + int remainder; + boolean result = false; + while (n > 0) { + // 求余数 + remainder = n % 2; + n >>>= 1; + + if (n == 0 && remainder == 1) { + result = true; + break; + } else if (n > 0 && remainder == 1) { + break; + } + } + + return result; + } +} diff --git a/[0231][Power of Two]/src/Test.java b/[0231][Power of Two]/src/Test.java new file mode 100644 index 0000000..0b8841a --- /dev/null +++ b/[0231][Power of Two]/src/Test.java @@ -0,0 +1,16 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-09 09:28 + **/ +public class Test { + public static void main(String[] args) { + Solution solution = new Solution(); + + System.out.println(solution.isPowerOfTwo(-1)); + System.out.println(solution.isPowerOfTwo(0)); + System.out.println(solution.isPowerOfTwo(1)); + System.out.println(solution.isPowerOfTwo(2)); + System.out.println(solution.isPowerOfTwo(16)); + System.out.println(solution.isPowerOfTwo(218)); + } +} diff --git a/[0232][Implement Queue using Stacks]/[0232][Implement Queue using Stacks].iml b/[0232][Implement Queue using Stacks]/[0232][Implement Queue using Stacks].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0232][Implement Queue using Stacks]/[0232][Implement Queue using Stacks].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0232][Implement Queue using Stacks]/src/MyQueue.java b/[0232][Implement Queue using Stacks]/src/MyQueue.java new file mode 100644 index 0000000..a4cdc0c --- /dev/null +++ b/[0232][Implement Queue using Stacks]/src/MyQueue.java @@ -0,0 +1,56 @@ +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; + +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-09 09:37 + **/ +class MyQueue { + + private List list; + + /** + * Initialize your data structure here. + */ + public MyQueue() { + list = new LinkedList<>(); + } + + /** + * Push element x to the back of queue. + */ + public void push(int x) { + list.add(x); + } + + /** + * Removes the element from in front of queue and returns that element. + */ + public int pop() { + return list.remove(0); + } + + /** + * Get the front element. + */ + public int peek() { + return list.get(0); + } + + /** + * Returns whether the queue is empty. + */ + public boolean empty() { + return list.isEmpty(); + } +} + +/** + * Your MyQueue object will be instantiated and called as such: + * MyQueue obj = new MyQueue(); + * obj.push(x); + * int param_2 = obj.pop(); + * int param_3 = obj.peek(); + * boolean param_4 = obj.empty(); + */ diff --git a/[0232][Implement Queue using Stacks]/src/Test.java b/[0232][Implement Queue using Stacks]/src/Test.java new file mode 100644 index 0000000..4adabf6 --- /dev/null +++ b/[0232][Implement Queue using Stacks]/src/Test.java @@ -0,0 +1,15 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-09 10:58 + **/ +public class Test { + public static void main(String[] args) { + MyQueue queue = new MyQueue(); + queue.push(1); + queue.push(2); + + System.out.println(queue.peek()); + System.out.println(queue.pop()); + System.out.println(queue.empty()); + } +} diff --git a/[0234][Palindrome Linked List]/[0234][Palindrome Linked List].iml b/[0234][Palindrome Linked List]/[0234][Palindrome Linked List].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0234][Palindrome Linked List]/[0234][Palindrome Linked List].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0234][Palindrome Linked List]/src/ListNode.java b/[0234][Palindrome Linked List]/src/ListNode.java new file mode 100644 index 0000000..0304f36 --- /dev/null +++ b/[0234][Palindrome Linked List]/src/ListNode.java @@ -0,0 +1,12 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-09 11:03 + **/ +public class ListNode { + int val; + ListNode next; + + ListNode(int x) { + val = x; + } +} diff --git a/[0234][Palindrome Linked List]/src/Solution.java b/[0234][Palindrome Linked List]/src/Solution.java new file mode 100644 index 0000000..9ace1e4 --- /dev/null +++ b/[0234][Palindrome Linked List]/src/Solution.java @@ -0,0 +1,58 @@ +/** + * O(n) time and O(1) space + *

+ * 1->2->2->1
+ * 1->2->3->2->1
+ * 先找到第二个2的位置,将2及后面的链逆转,形成新的链A,再按A与原来的链,从头开开始比较
+ * 
+ * + * @author: wangjunchao(王俊超) + * @time: 2018-10-09 11:02 + **/ +public class Solution { + public boolean isPalindrome(ListNode head) { + + // 没有节点或者只有一个结点 + if (head == null || head.next == null) { + return true; + } + + int count = 0; + ListNode node = head; + while (node != null) { + count++; + node = node.next; + } + + // 找反向链的起始位置 + count = (count + 1) / 2; + node = head; + while (count >0) { + count--; + node = node.next; + } + + + ListNode reverseHead = new ListNode(0); + ListNode temp; + while (node != null) { + temp = node.next; + node.next = reverseHead.next; + reverseHead.next = node; + node = temp; + } + + reverseHead = reverseHead.next; + + while (reverseHead != null) { + if (head.val != reverseHead.val) { + return false; + } + + reverseHead = reverseHead.next; + head = head.next; + } + + return true; + } +} diff --git a/[0234][Palindrome Linked List]/src/Solution2.java b/[0234][Palindrome Linked List]/src/Solution2.java new file mode 100644 index 0000000..f6138f7 --- /dev/null +++ b/[0234][Palindrome Linked List]/src/Solution2.java @@ -0,0 +1,38 @@ +/** + * O(n) time and O(n) space + * + * @author: wangjunchao(王俊超) + * @time: 2018-10-09 11:02 + **/ +public class Solution2 { + public boolean isPalindrome(ListNode head) { + + if (head == null) { + return true; + } + + // 反向链的头 + ListNode reverseHead = new ListNode(-1); + + ListNode temp = head; + ListNode node; + // 头插法构建反向链 + while (temp != null) { + node = new ListNode(temp.val); + node.next = reverseHead.next; + reverseHead.next = node; + temp = temp.next; + } + + reverseHead = reverseHead.next; + while (head != null) { + if (head.val != reverseHead.val) { + return false; + } + + head = head.next; + reverseHead = reverseHead.next; + } + return true; + } +} diff --git a/[0234][Palindrome Linked List]/src/Test.java b/[0234][Palindrome Linked List]/src/Test.java new file mode 100644 index 0000000..97b7f35 --- /dev/null +++ b/[0234][Palindrome Linked List]/src/Test.java @@ -0,0 +1,42 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-09 11:10 + **/ +public class Test { + public static void main(String[] args) { + test1(); + test2(); + test3(); + } + + public static void test1() { + Solution solution = new Solution(); + ListNode head = new ListNode(1); + head.next = new ListNode(2); + System.out.println(solution.isPalindrome(head)); + } + + public static void test2() { + Solution solution = new Solution(); + + ListNode head = new ListNode(1); + head.next = new ListNode(2); + head.next.next= new ListNode(2); + head.next.next.next= new ListNode(1); + head.next.next.next.next= new ListNode(2); + head.next.next.next.next.next= new ListNode(2); + head.next.next.next.next.next.next= new ListNode(1); + System.out.println(solution.isPalindrome(head)); + } + + public static void test3() { + Solution solution = new Solution(); + + ListNode head = new ListNode(1); + head.next = new ListNode(2); + head.next.next= new ListNode(2); + head.next.next.next= new ListNode(1); + + System.out.println(solution.isPalindrome(head)); + } +} diff --git a/[0235][Lowest Common Ancestor of a Binary Search Tree]/[0235][Lowest Common Ancestor of a Binary Search Tree].iml b/[0235][Lowest Common Ancestor of a Binary Search Tree]/[0235][Lowest Common Ancestor of a Binary Search Tree].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0235][Lowest Common Ancestor of a Binary Search Tree]/[0235][Lowest Common Ancestor of a Binary Search Tree].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0235][Lowest Common Ancestor of a Binary Search Tree]/src/Solution.java b/[0235][Lowest Common Ancestor of a Binary Search Tree]/src/Solution.java new file mode 100644 index 0000000..632cf2f --- /dev/null +++ b/[0235][Lowest Common Ancestor of a Binary Search Tree]/src/Solution.java @@ -0,0 +1,56 @@ +import java.util.ArrayList; +import java.util.List; + +/** + * Definition for a binary tree node. + *
+ * public class TreeNode {
+ *      int val;
+ *      TreeNode left;
+ *      TreeNode right;
+ *      TreeNode(int x) { val = x; }
+ * }
+ * 
+ * + * @author: wangjunchao(王俊超) + * @time: 2018-10-09 11:32 + */ +class Solution { + public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { + + List pPath = new ArrayList<>(); + List qPath = new ArrayList<>(); + + search(pPath, root, p); + search(qPath, root, q); + + TreeNode ancestor = pPath.get(0); + + int idx = 1; + while (idx < pPath.size() && idx < qPath.size()) { + p = pPath.get(idx); + q = qPath.get(idx); + if (p != null && q != null && p.val == q.val) { + ancestor = pPath.get(idx); + idx++; + } else { + break; + } + } + + return ancestor; + } + + public void search(List path, TreeNode root, TreeNode node) { + path.add(root); + + if (root != null) { + if (root.val > node.val) { + search(path, root.left, node); + } + if (root.val < node.val) { + search(path, root.right, node); + } + } + } +} diff --git a/[0235][Lowest Common Ancestor of a Binary Search Tree]/src/TreeNode.java b/[0235][Lowest Common Ancestor of a Binary Search Tree]/src/TreeNode.java new file mode 100644 index 0000000..cb9448f --- /dev/null +++ b/[0235][Lowest Common Ancestor of a Binary Search Tree]/src/TreeNode.java @@ -0,0 +1,13 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-09 11:33 + **/ +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} diff --git a/[0237][Delete Node in a Linked List]/[0237][Delete Node in a Linked List].iml b/[0237][Delete Node in a Linked List]/[0237][Delete Node in a Linked List].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0237][Delete Node in a Linked List]/[0237][Delete Node in a Linked List].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0237][Delete Node in a Linked List]/src/ListNode.java b/[0237][Delete Node in a Linked List]/src/ListNode.java new file mode 100644 index 0000000..50f6a11 --- /dev/null +++ b/[0237][Delete Node in a Linked List]/src/ListNode.java @@ -0,0 +1,12 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 09:58 + **/ +public class ListNode { + int val; + ListNode next; + + ListNode(int x) { + val = x; + } +} diff --git a/[0237][Delete Node in a Linked List]/src/Solution.java b/[0237][Delete Node in a Linked List]/src/Solution.java new file mode 100644 index 0000000..b440a61 --- /dev/null +++ b/[0237][Delete Node in a Linked List]/src/Solution.java @@ -0,0 +1,31 @@ +/** + *
+ * Definition for singly-linked list.
+ * public class ListNode {
+ *     int val;
+ *     ListNode next;
+ *     ListNode(int x) { val = x; }
+ * }
+ * 
+ * @author: wangjunchao(王俊超) + * @time: 2018-10-10 09:57 + **/ +class Solution { + public void deleteNode(ListNode node) { + + if (node == null || node.next == null) { + return; + } + + ListNode prev = node; + while (node.next != null) { + node.val = node.next.val; + prev = node; + node = node.next; + + + } + + prev.next = null; + } +} \ No newline at end of file diff --git a/[0237][Delete Node in a Linked List]/src/Test.java b/[0237][Delete Node in a Linked List]/src/Test.java new file mode 100644 index 0000000..8863287 --- /dev/null +++ b/[0237][Delete Node in a Linked List]/src/Test.java @@ -0,0 +1,32 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 10:01 + **/ +public class Test { + public static void main(String[] args) { + ListNode node = new ListNode(4); + node.next = new ListNode(5); + node.next.next = new ListNode(1); + node.next.next.next = new ListNode(9); + + Solution solution = new Solution(); + solution.deleteNode(node.next); + + print(node); + } + + private static void print(ListNode node) { + do { + if (node == null) { + System.out.println("null"); + } else if (node.next != null){ + System.out.print(node.val + "->"); + node = node.next; + } else { + System.out.println(node.val + "->null"); + node = node.next; + } + + }while (node != null); + } +} diff --git a/[0242][Valid Anagram]/[0242][Valid Anagram].iml b/[0242][Valid Anagram]/[0242][Valid Anagram].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0242][Valid Anagram]/[0242][Valid Anagram].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0242][Valid Anagram]/src/Solution.java b/[0242][Valid Anagram]/src/Solution.java new file mode 100644 index 0000000..ace39c8 --- /dev/null +++ b/[0242][Valid Anagram]/src/Solution.java @@ -0,0 +1,48 @@ +import java.util.HashMap; +import java.util.Map; + +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 10:28 + **/ +public class Solution { + public boolean isAnagram(String s, String t) { + + if (s == null && t == null) { + return true; + } else if (s == null || t == null) { + return false; + } + + Map map = new HashMap<>(); + + for (int i = 0; i < s.length(); i++) { + Character c = s.charAt(i); + if (map.containsKey(c)) { + map.put(c, map.get(c) + 1); + } else { + map.put(c, 1); + } + } + + for (int i = 0; i < t.length(); i++) { + Character c = t.charAt(i); + Integer count = map.get(c); + // t有s中不包含的字符串 + if (count == null) { + return false; + } else { + map.put(c, count - 1); + } + } + + // map中的值有非0的说明不合法 + for (Integer i : map.values()) { + if (i != 0) { + return false; + } + } + + return true; + } +} diff --git a/[0242][Valid Anagram]/src/Test.java b/[0242][Valid Anagram]/src/Test.java new file mode 100644 index 0000000..5282683 --- /dev/null +++ b/[0242][Valid Anagram]/src/Test.java @@ -0,0 +1,12 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 10:35 + **/ +public class Test { + public static void main(String[] args) { + Solution solution = new Solution(); + + System.out.println(solution.isAnagram("anagram", "nagaram")); + System.out.println(solution.isAnagram("rat", "car")); + } +} diff --git a/[0257][Binary Tree Paths]/[0257][Binary Tree Paths].iml b/[0257][Binary Tree Paths]/[0257][Binary Tree Paths].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0257][Binary Tree Paths]/[0257][Binary Tree Paths].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0257][Binary Tree Paths]/src/Solution.java b/[0257][Binary Tree Paths]/src/Solution.java new file mode 100644 index 0000000..6480a96 --- /dev/null +++ b/[0257][Binary Tree Paths]/src/Solution.java @@ -0,0 +1,56 @@ +import java.util.LinkedList; +import java.util.List; + +/** + *
+ * Definition for a binary tree node.
+ * public class TreeNode {
+ *     int val;
+ *     TreeNode left;
+ *     TreeNode right;
+ *     TreeNode(int x) { val = x; }
+ * }
+ * 
+ * + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 11:16 + **/ +public class Solution { + public List binaryTreePaths(TreeNode root) { + List result = new LinkedList<>(); + binaryTreePaths(root, new LinkedList<>(), result); + + return result; + } + + private void binaryTreePaths(TreeNode root, LinkedList path, List result) { + + if (root == null) { + return; + } + + path.add(root); + + if (root.left == null && root.right == null) { + addResult(path, result); + } else { + binaryTreePaths(root.left, path, result); + binaryTreePaths(root.right, path, result); + } + + path.remove(path.size() - 1); + } + + private void addResult(LinkedList path, List result) { + StringBuilder builder = new StringBuilder(); + if (path != null) { + for (TreeNode node : path) { + builder.append("->").append(node.val); + } + } + + if (builder.length() > 0) { + result.add(builder.substring(2)); + } + } +} diff --git a/[0257][Binary Tree Paths]/src/Test.java b/[0257][Binary Tree Paths]/src/Test.java new file mode 100644 index 0000000..318a15c --- /dev/null +++ b/[0257][Binary Tree Paths]/src/Test.java @@ -0,0 +1,16 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 11:25 + **/ +public class Test { + public static void main(String[] args) { + Solution solution = new Solution(); + + TreeNode root = new TreeNode(1); + root.left = new TreeNode(2); + root.right = new TreeNode(3); + root.left.right = new TreeNode(5); + + System.out.println(solution.binaryTreePaths(root)); + } +} diff --git a/[0257][Binary Tree Paths]/src/TreeNode.java b/[0257][Binary Tree Paths]/src/TreeNode.java new file mode 100644 index 0000000..2e248fe --- /dev/null +++ b/[0257][Binary Tree Paths]/src/TreeNode.java @@ -0,0 +1,15 @@ +/** + * Author: 王俊超 + * Date: 2015-06-18 + * Time: 10:02 + * Declaration: All Rights Reserved !!! + */ +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} diff --git a/[0258][Add Digits]/[0258][Add Digits].iml b/[0258][Add Digits]/[0258][Add Digits].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0258][Add Digits]/[0258][Add Digits].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0258][Add Digits]/src/Solution.java b/[0258][Add Digits]/src/Solution.java new file mode 100644 index 0000000..ff595f5 --- /dev/null +++ b/[0258][Add Digits]/src/Solution.java @@ -0,0 +1,27 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 13:28 + **/ +public class Solution { + public int addDigits(int num) { + + if (num < 0) { + throw new IllegalArgumentException("input num :" + num + ", must not be negative"); + } + + int result = 0; + + while (num > 0) { + result += num % 10; + num /= 10; + + // 需要重新进行位相加 + if (num == 0 && result > 9) { + num = result; + result = 0; + } + } + + return result; + } +} diff --git a/[0258][Add Digits]/src/Test.java b/[0258][Add Digits]/src/Test.java new file mode 100644 index 0000000..d3afaa3 --- /dev/null +++ b/[0258][Add Digits]/src/Test.java @@ -0,0 +1,13 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 13:35 + **/ +public class Test { + public static void main(String[] args) { + Solution solution = new Solution(); + + System.out.println(solution.addDigits(38)); + System.out.println(solution.addDigits(999999999)); + System.out.println(solution.addDigits(100000000)); + } +} diff --git a/[0263][Ugly Number]/[0263][Ugly Number].iml b/[0263][Ugly Number]/[0263][Ugly Number].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0263][Ugly Number]/[0263][Ugly Number].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0263][Ugly Number]/src/Solution.java b/[0263][Ugly Number]/src/Solution.java new file mode 100644 index 0000000..a05b03c --- /dev/null +++ b/[0263][Ugly Number]/src/Solution.java @@ -0,0 +1,28 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 13:45 + **/ +public class Solution { + public boolean isUgly(int num) { + + if (num < 1) { + return false; + } else if (num == 1) { + return true; + } + + while ((num % 2) == 0) { + num /= 2; + } + + while ((num % 3) == 0) { + num /= 3; + } + + while ((num % 5) == 0) { + num /= 5; + } + + return num == 1; + } +} diff --git a/[0263][Ugly Number]/src/Test.java b/[0263][Ugly Number]/src/Test.java new file mode 100644 index 0000000..dccb247 --- /dev/null +++ b/[0263][Ugly Number]/src/Test.java @@ -0,0 +1,16 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 13:50 + **/ +public class Test { + public static void main(String[] args) { + Solution solution = new Solution(); + + System.out.println(solution.isUgly(-1)); + System.out.println(solution.isUgly(0)); + System.out.println(solution.isUgly(1)); + System.out.println(solution.isUgly(6)); + System.out.println(solution.isUgly(8)); + System.out.println(solution.isUgly(14)); + } +} diff --git a/[0268][Missing Number]/[0268][Missing Number].iml b/[0268][Missing Number]/[0268][Missing Number].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0268][Missing Number]/[0268][Missing Number].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0268][Missing Number]/src/Solution.java b/[0268][Missing Number]/src/Solution.java new file mode 100644 index 0000000..0ad6903 --- /dev/null +++ b/[0268][Missing Number]/src/Solution.java @@ -0,0 +1,39 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 14:02 + **/ +public class Solution { + public int missingNumber(int[] nums) { + + if (nums == null || nums.length < 1) { + throw new IllegalArgumentException("array should contain at least one element"); + } + + for (int i = 0; i < nums.length; i++) { + // 只会存在一个大于nums.length的数,将其放在数组最后一个位置 + if (nums[i] > nums.length) { + swap(nums, i, nums.length - 1); + } + + // 交换位置,直到nums[i] = i + while (nums[i] != i && nums[i] < nums.length) { + swap(nums, i, nums[i]); + } + } + + // 找出丢失的元素 + for (int i = 0; i < nums.length; i++) { + if (nums[i] != i) { + return i; + } + } + + return nums.length; + } + + private void swap(int[] nums, int x, int y) { + int temp = nums[x]; + nums[x] = nums[y]; + nums[y] = temp; + } +} diff --git a/[0268][Missing Number]/src/Test.java b/[0268][Missing Number]/src/Test.java new file mode 100644 index 0000000..a4452e8 --- /dev/null +++ b/[0268][Missing Number]/src/Test.java @@ -0,0 +1,21 @@ +import java.util.Arrays; + +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 14:14 + **/ +public class Test { + public static void main(String[] args) { + Solution solution = new Solution(); + + missingNumber(solution, new int[]{0}); + missingNumber(solution, new int[]{3, 0, 1}); + missingNumber(solution, new int[]{9, 6, 4, 2, 3, 5, 7, 0, 1}); + missingNumber(solution, new int[]{8, 6, 4, 2, 3, 5, 7, 0, 1}); + } + + private static void missingNumber(Solution solution, int[] array) { + System.out.println(solution.missingNumber(array)); + System.out.println(Arrays.toString(array)); + } +} diff --git a/[0278][First Bad Version]/[0278][First Bad Version].iml b/[0278][First Bad Version]/[0278][First Bad Version].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0278][First Bad Version]/[0278][First Bad Version].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0278][First Bad Version]/src/Solution.java b/[0278][First Bad Version]/src/Solution.java new file mode 100644 index 0000000..2f344d1 --- /dev/null +++ b/[0278][First Bad Version]/src/Solution.java @@ -0,0 +1,39 @@ +/** + *
+ * The isBadVersion API is defined in the parent class VersionControl.
+ *       boolean isBadVersion(int version);
+ * 
+ * + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 14:26 + **/ +public class Solution extends VersionControl { + public int firstBadVersion(int n) { + + if (!isBadVersion(n)) { + return 0; + } + + int hi = n; + int lo = 1; + int mid; + + while (hi >= lo) { + mid = lo + (hi - lo) / 2; + if (isBadVersion(mid)) { + // 当前是1号版本,或者前一个是合法版本,那么当前版本就是第一个非法的版本 + if (mid == 1 || (mid > 1 && !isBadVersion(mid - 1))) { + return mid; + } else { + // 非法的版本在[lo, mid-1]间 + hi = mid - 1; + } + } else { + // 非法版本在[mid + 1, hi]间 + lo = mid + 1; + } + } + + return 0; + } +} diff --git a/[0278][First Bad Version]/src/Test.java b/[0278][First Bad Version]/src/Test.java new file mode 100644 index 0000000..3a57cd6 --- /dev/null +++ b/[0278][First Bad Version]/src/Test.java @@ -0,0 +1,12 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 16:55 + **/ +public class Test { + public static void main(String[] args) { + Solution solution = new Solution(); + + solution.setBadVersion(new boolean[]{false, false, false, true, true}); + System.out.println(solution.firstBadVersion(5)); + } +} diff --git a/[0278][First Bad Version]/src/VersionControl.java b/[0278][First Bad Version]/src/VersionControl.java new file mode 100644 index 0000000..d124b97 --- /dev/null +++ b/[0278][First Bad Version]/src/VersionControl.java @@ -0,0 +1,20 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 14:27 + **/ +public class VersionControl { + + private boolean[] badVersion; + + public boolean isBadVersion(int version){ + return badVersion[version - 1]; + } + + public boolean[] getBadVersion() { + return badVersion; + } + + public void setBadVersion(boolean[] badVersion) { + this.badVersion = badVersion; + } +} diff --git a/[0283][Move Zeroes]/[0283][Move Zeroes].iml b/[0283][Move Zeroes]/[0283][Move Zeroes].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0283][Move Zeroes]/[0283][Move Zeroes].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0283][Move Zeroes]/src/Solution.java b/[0283][Move Zeroes]/src/Solution.java new file mode 100644 index 0000000..4afeb4a --- /dev/null +++ b/[0283][Move Zeroes]/src/Solution.java @@ -0,0 +1,44 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 17:04 + **/ +public class Solution { + public void moveZeroes(int[] nums) { + + if (nums == null || nums.length < 1) { + return; + } + + int idx = 0; + // 找第一个0的位置 + while (idx < nums.length && nums[idx] != 0) { + idx++; + } + + // 数组的值都非0 + if (idx >= nums.length) { + return; + } + + int temp = idx + 1; + + while (temp < nums.length) { + // 找temp开始第一个非0的位置 + while (temp < nums.length && nums[temp] == 0) { + temp++; + } + + // 找到非0值,移动到idx位置 + if (temp < nums.length) { + nums[idx] = nums[temp]; + idx++; + temp++; + } + } + + // 从[idx, nums.length-1]的长度都设置为0 + for (int i = idx; i < nums.length; i++) { + nums[i] = 0; + } + } +} diff --git a/[0283][Move Zeroes]/src/Test.java b/[0283][Move Zeroes]/src/Test.java new file mode 100644 index 0000000..1c5d20c --- /dev/null +++ b/[0283][Move Zeroes]/src/Test.java @@ -0,0 +1,20 @@ +import java.util.Arrays; + +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 17:11 + **/ +public class Test { + public static void main(String[] args) { + moveZeros(new int[]{0, 1, 0, 3, 12}); + moveZeros(new int[]{2, 1, 6, 3, 12}); + moveZeros(new int[]{2}); + moveZeros(new int[]{0}); + } + + private static void moveZeros(int[] a1) { + Solution solution = new Solution(); + solution.moveZeroes(a1); + System.out.println(Arrays.toString(a1)); + } +} diff --git a/[0290][Word Pattern]/[0290][Word Pattern].iml b/[0290][Word Pattern]/[0290][Word Pattern].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0290][Word Pattern]/[0290][Word Pattern].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0290][Word Pattern]/src/Solution.java b/[0290][Word Pattern]/src/Solution.java new file mode 100644 index 0000000..580d1c2 --- /dev/null +++ b/[0290][Word Pattern]/src/Solution.java @@ -0,0 +1,48 @@ +import java.util.HashMap; +import java.util.Map; + +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 17:24 + **/ +public class Solution { + public boolean wordPattern(String pattern, String str) { + + if (pattern == null && str == null) { + return true; + } else if (pattern == null || str == null) { + return false; + } + + String[] parts = str.split("\\s+"); + + if (pattern.length() != parts.length) { + return false; + } + + Map map = new HashMap<>(); + Map rmap = new HashMap<>(); + + Character c; + for (int i = 0; i < pattern.length(); i++) { + c = pattern.charAt(i); + if (!map.containsKey(c)) { + map.put(c, parts[i]); + } else { + if (!parts[i].equals(map.get(c))) { + return false; + } + } + // 双射,两边都要验证 + if (!rmap.containsKey(parts[i])) { + rmap.put(parts[i], c); + } else { + if (!c.equals(rmap.get(parts[i]))) { + return false; + } + } + } + + return true; + } +} diff --git a/[0290][Word Pattern]/src/Test.java b/[0290][Word Pattern]/src/Test.java new file mode 100644 index 0000000..6c75500 --- /dev/null +++ b/[0290][Word Pattern]/src/Test.java @@ -0,0 +1,14 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-10 17:29 + **/ +public class Test { + public static void main(String[] args) { + Solution solution = new Solution(); + + System.out.println(solution.wordPattern("abba", "dog cat cat dog")); + System.out.println(solution.wordPattern("abba", "dog cat cat fish")); + System.out.println(solution.wordPattern("aaaa", "dog cat cat dog")); + System.out.println(solution.wordPattern("abba", "dog dog dog dog")); + } +} diff --git a/[0303][Range Sum Query - Immutable]/[0303][Range Sum Query - Immutable].iml b/[0303][Range Sum Query - Immutable]/[0303][Range Sum Query - Immutable].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0303][Range Sum Query - Immutable]/[0303][Range Sum Query - Immutable].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0303][Range Sum Query - Immutable]/src/NumArray.java b/[0303][Range Sum Query - Immutable]/src/NumArray.java new file mode 100644 index 0000000..fb70aae --- /dev/null +++ b/[0303][Range Sum Query - Immutable]/src/NumArray.java @@ -0,0 +1,34 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-12 13:53 + **/ +public class NumArray { + private int[] nums; + + public NumArray(int[] nums) { + this.nums = nums; + } + + public int sumRange(int i, int j) { + + if (i > j) { + throw new IllegalArgumentException("i = " + i + ", j = " + j +", i must not greater than j"); + } + + if (j < 0) { + throw new IllegalArgumentException("i = " + i + ", j = " + j +", i must not less than 0"); + } + + i = i < 0 ? 0 : i; + j = j >= nums.length ? nums.length - 1 : j; + + int sum = 0; + + + for (int k = i; k <= j; k++) { + sum += nums[k]; + } + + return sum; + } +} diff --git a/[0303][Range Sum Query - Immutable]/src/Test.java b/[0303][Range Sum Query - Immutable]/src/Test.java new file mode 100644 index 0000000..470204f --- /dev/null +++ b/[0303][Range Sum Query - Immutable]/src/Test.java @@ -0,0 +1,12 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-10-12 14:17 + **/ +public class Test { + public static void main(String[] args) { + NumArray array = new NumArray(new int[]{-2, 0, 3, -5, 2, -1}); + System.out.println(array.sumRange(0, 2)); + System.out.println(array.sumRange(2, 5)); + System.out.println(array.sumRange(0, 5)); + } +} diff --git a/[0326][Power of Three]/[0326][Power of Three].iml b/[0326][Power of Three]/[0326][Power of Three].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0326][Power of Three]/[0326][Power of Three].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0326][Power of Three]/src/Solution.java b/[0326][Power of Three]/src/Solution.java new file mode 100644 index 0000000..8ab7b8d --- /dev/null +++ b/[0326][Power of Three]/src/Solution.java @@ -0,0 +1,25 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-11-16 15:21 + **/ +public class Solution { + + public boolean isPowerOfThree(int n) { + double rst = (Math.log10(n) / Math.log10(3)); + return n > 0 &&Double.doubleToLongBits((int)rst) == Double.doubleToLongBits(rst); + } + + public boolean isPowerOfThree2(int n) { + return (n > 0 && 1162261467 % n == 0); + } + + public boolean isPowerOfThree1(int n) { + while (n > 1 && n % 3 == 0) { + n /= 3; + } + + return n == 1; + } + + +} diff --git a/[0326][Power of Three]/src/Test.java b/[0326][Power of Three]/src/Test.java new file mode 100644 index 0000000..c99e19b --- /dev/null +++ b/[0326][Power of Three]/src/Test.java @@ -0,0 +1,13 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-11-16 15:31 + **/ +public class Test { + public static void main(String[] args) { + System.out.println(Double.doubleToLongBits((int)1.00000000001) + == Double.doubleToLongBits(1.00000000001)); + + System.out.println(Double.doubleToLongBits((int)1.00000000000) + == Double.doubleToLongBits(1.00000000000)); + } +} diff --git a/[0342][Power of Four]/[0342][Power of Four].iml b/[0342][Power of Four]/[0342][Power of Four].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0342][Power of Four]/[0342][Power of Four].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0342][Power of Four]/src/Solution.java b/[0342][Power of Four]/src/Solution.java new file mode 100644 index 0000000..1466de8 --- /dev/null +++ b/[0342][Power of Four]/src/Solution.java @@ -0,0 +1,29 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-11-16 15:43 + **/ +public class Solution { + + public boolean isPowerOfFour(int num) { + return num > 0 && (num & (num - 1)) == 0 && (num - 1) % 3 == 0; + } + + + public boolean isPowerOfFour3(int num) { + int n = 0b1010101_01010101_01010101_01010101; +// int n = 0x55555555; + return num > 0 && (num & (num - 1)) == 0 && (num & n) == num; + } + + public boolean isPowerOfFour2(int num) { + double rst = (Math.log10(num) / Math.log10(4)); + return num > 0 && Double.doubleToLongBits((int) rst) == Double.doubleToLongBits(rst); + } + + public boolean isPowerOfFour1(int num) { + while (num > 1 && (num % 4 == 0)) { + num /= 4; + } + return num == 1; + } +} diff --git a/[0344][Reverse String]/[0344][Reverse String].iml b/[0344][Reverse String]/[0344][Reverse String].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0344][Reverse String]/[0344][Reverse String].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0344][Reverse String]/src/Solution.java b/[0344][Reverse String]/src/Solution.java new file mode 100644 index 0000000..955ed6b --- /dev/null +++ b/[0344][Reverse String]/src/Solution.java @@ -0,0 +1,25 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2018-11-16 16:04 + **/ +public class Solution { + public String reverseString(String s) { + if (s == null || s.length() < 1) { + return s; + } + + char[] chars = s.toCharArray(); + + for (int i = 0, j = chars.length - 1; i + + + + + + + + + + + \ No newline at end of file From 181aeca800af30e6bb5aabefd9aadba2f647294a Mon Sep 17 00:00:00 2001 From: Wang-Jun-Chao Date: Mon, 24 Jun 2019 11:24:04 +0800 Subject: [PATCH 054/108] commit --- .idea/encodings.xml | 3 + .idea/misc.xml | 2 +- .idea/uiDesigner.xml | 124 +++++ .idea/workspace.xml | 518 ++++++++++++------ ...stSubstringWithoutRepeatingCharacters].iml | 13 - .../src/Solution.java | 7 +- .../[0011][ContainerWithMost Water].iml | 13 - [0055][Jump Game]/src/Solution.java | 5 + .../[0121][BestTimeToBuyAndSellStock].iml | 13 - .../src/Solution.java | 8 +- ...2][Best Time to Buy and Sell Stock II].iml | 10 + .../src/Main.java | 37 ++ .../src/Solution.java | 59 +- .../src/Solution2.java | 71 +++ .../src/Test.java | 18 - 15 files changed, 643 insertions(+), 258 deletions(-) create mode 100644 .idea/uiDesigner.xml delete mode 100644 [0003][Longest Substring Without Repeating Characters]/[0003][LongestSubstringWithoutRepeatingCharacters].iml delete mode 100644 [0011][Container With Most Water]/[0011][ContainerWithMost Water].iml delete mode 100644 [0121][Best Time To Buy And Sell Stock]/[0121][BestTimeToBuyAndSellStock].iml create mode 100644 [0122][Best Time to Buy and Sell Stock II]/src/Main.java create mode 100644 [0122][Best Time to Buy and Sell Stock II]/src/Solution2.java delete mode 100644 [0122][Best Time to Buy and Sell Stock II]/src/Test.java diff --git a/.idea/encodings.xml b/.idea/encodings.xml index 02f612a..110a15f 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -3,6 +3,7 @@ + @@ -10,6 +11,7 @@ + @@ -83,6 +85,7 @@ + diff --git a/.idea/misc.xml b/.idea/misc.xml index d97877f..5b2bcaf 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -7,7 +7,7 @@ - + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index ca0b801..b3a472a 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,7 +1,22 @@ - + + + + + + + + + + + + + + + + - @@ -157,7 +246,75 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - @@ -409,9 +542,9 @@ + - @@ -456,14 +589,8 @@ - - - - 1538119268262 - 1538119421634 @@ -801,7 +928,14 @@ - @@ -837,13 +971,13 @@ - - + - + @@ -852,7 +986,7 @@ - + @@ -1028,64 +1162,8 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -1100,44 +1178,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + @@ -1145,23 +1190,8 @@ - - - - - - - - - - - - - - - - - + + @@ -1173,93 +1203,17 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + @@ -1336,44 +1290,37 @@ - - - - - - - - + - + - - + + - - + + - + - + @@ -1381,24 +1328,58 @@ + + + + + + + + + + + + + + + + + + + + + - - + + - + - - + + - + + + + - - + + + + + + + + + + + + diff --git a/[0000][common]/[0000][common].iml b/[0000][common]/[0000][common].iml index c90834f..f080bef 100644 --- a/[0000][common]/[0000][common].iml +++ b/[0000][common]/[0000][common].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0001][Two Sum]/[0001][Two Sum].iml b/[0001][Two Sum]/[0001][Two Sum].iml index c90834f..f080bef 100644 --- a/[0001][Two Sum]/[0001][Two Sum].iml +++ b/[0001][Two Sum]/[0001][Two Sum].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0002][Add Two Numbers]/[0002][Add Two Numbers].iml b/[0002][Add Two Numbers]/[0002][Add Two Numbers].iml index c90834f..f080bef 100644 --- a/[0002][Add Two Numbers]/[0002][Add Two Numbers].iml +++ b/[0002][Add Two Numbers]/[0002][Add Two Numbers].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0003][Longest Substring Without Repeating Characters]/[0003][Longest Substring Without Repeating Characters].iml b/[0003][Longest Substring Without Repeating Characters]/[0003][Longest Substring Without Repeating Characters].iml index c90834f..f080bef 100644 --- a/[0003][Longest Substring Without Repeating Characters]/[0003][Longest Substring Without Repeating Characters].iml +++ b/[0003][Longest Substring Without Repeating Characters]/[0003][Longest Substring Without Repeating Characters].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0004][Median of Two Sorted Arrays]/[0004][Median of Two Sorted Arrays].iml b/[0004][Median of Two Sorted Arrays]/[0004][Median of Two Sorted Arrays].iml index c90834f..f080bef 100644 --- a/[0004][Median of Two Sorted Arrays]/[0004][Median of Two Sorted Arrays].iml +++ b/[0004][Median of Two Sorted Arrays]/[0004][Median of Two Sorted Arrays].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0005][Longest Palindromic Substring Total]/[0005][Longest Palindromic Substring Total].iml b/[0005][Longest Palindromic Substring Total]/[0005][Longest Palindromic Substring Total].iml index c90834f..f080bef 100644 --- a/[0005][Longest Palindromic Substring Total]/[0005][Longest Palindromic Substring Total].iml +++ b/[0005][Longest Palindromic Substring Total]/[0005][Longest Palindromic Substring Total].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0006][Zig Zag Conversion]/[0006][Zig Zag Conversion].iml b/[0006][Zig Zag Conversion]/[0006][Zig Zag Conversion].iml index c90834f..f080bef 100644 --- a/[0006][Zig Zag Conversion]/[0006][Zig Zag Conversion].iml +++ b/[0006][Zig Zag Conversion]/[0006][Zig Zag Conversion].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0007][Reverse Integer]/[0007][Reverse Integer].iml b/[0007][Reverse Integer]/[0007][Reverse Integer].iml index c90834f..f080bef 100644 --- a/[0007][Reverse Integer]/[0007][Reverse Integer].iml +++ b/[0007][Reverse Integer]/[0007][Reverse Integer].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0008][String To Integer (atoi)]/[0008][String To Integer (atoi)].iml b/[0008][String To Integer (atoi)]/[0008][String To Integer (atoi)].iml index c90834f..f080bef 100644 --- a/[0008][String To Integer (atoi)]/[0008][String To Integer (atoi)].iml +++ b/[0008][String To Integer (atoi)]/[0008][String To Integer (atoi)].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0009][Palindrome Number]/[0009][Palindrome Number].iml b/[0009][Palindrome Number]/[0009][Palindrome Number].iml index c90834f..f080bef 100644 --- a/[0009][Palindrome Number]/[0009][Palindrome Number].iml +++ b/[0009][Palindrome Number]/[0009][Palindrome Number].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0010][Regular Expression Matching]/[0010][Regular Expression Matching].iml b/[0010][Regular Expression Matching]/[0010][Regular Expression Matching].iml index c90834f..f080bef 100644 --- a/[0010][Regular Expression Matching]/[0010][Regular Expression Matching].iml +++ b/[0010][Regular Expression Matching]/[0010][Regular Expression Matching].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0011][Container With Most Water]/[0011][Container With Most Water].iml b/[0011][Container With Most Water]/[0011][Container With Most Water].iml index c90834f..f080bef 100644 --- a/[0011][Container With Most Water]/[0011][Container With Most Water].iml +++ b/[0011][Container With Most Water]/[0011][Container With Most Water].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0011][Container With Most Water]/src/Solution2.java b/[0011][Container With Most Water]/src/Solution2.java new file mode 100644 index 0000000..556a26a --- /dev/null +++ b/[0011][Container With Most Water]/src/Solution2.java @@ -0,0 +1,74 @@ +/** + * Author: + * Date: 2015-06-30 + * Time: 07:25 + * Declaration: All Rights Reserved !!! + */ +public class Solution2 { + /** + *
+     * Given n non-negative integers a1, a2, ..., an, where each represents
+     * a point at coordinate (i, ai). n vertical lines are drawn such that
+     * the two endpoints of line i is at (i, ai) and (i, 0). Find two lines,
+     * which together with x-axis forms a container, such that the container
+     * contains the most water.
+     *
+     * Note: You may not slant the container.
+     *
+     * Ŀ⣺
+     * ȻԼXṹɵˮ
+     *
+     * ˼·
+     * ʹ̰㷨
+     *      1.ȼҵȡݻΪ i, j (ٶi aj) 
+     *          ô   ak > aj min(ai, aj, ak) =min(ai, aj) 
+     *          i, kɵݻC' = min(ai, aj) * (k - i) > C
+     *          CֵìܣԵ֤jĺ߲бߵߣ
+     *
+     *          :ͬiҲбߵߣ˵ʲôأ
+     *          Ŀǰõĺѡ Ϊ x, yߣx< y)ôܹõ
+     *          ݻµ߱Ȼ[x, y]ڲ ax' >= ax , ay' >= ay;
+     *
+     *      3.Ǵͷм俿£ͬʱºѡֵʱȴ
+     *      x, yнСı߿ʼ
+     * 
+ * + * @param height + * @return + */ + public int maxArea(int[] height) { + + // У + if (height == null || height.length < 2) { + return 0; + } + + + // ¼Ľ + int result = 0; + + // ߵ + int left = 0; + // ұߵ + int right = height.length - 1; + + while (left < right) { + // 㵱ǰֵ + result = Math.max(result, Math.min(height[left], height[right]) * (right - left)); + // ұ߸ + if (height[left] < height[right]) { + left++; + } + // ߵ߸ + else { + right--; + } + } + + return result; + } +} diff --git a/[0012][Integer To Roman]/[0012][Integer To Roman].iml b/[0012][Integer To Roman]/[0012][Integer To Roman].iml index c90834f..f080bef 100644 --- a/[0012][Integer To Roman]/[0012][Integer To Roman].iml +++ b/[0012][Integer To Roman]/[0012][Integer To Roman].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0013][Romar To Integer]/[0013][Romar To Integer].iml b/[0013][Romar To Integer]/[0013][Romar To Integer].iml index c90834f..f080bef 100644 --- a/[0013][Romar To Integer]/[0013][Romar To Integer].iml +++ b/[0013][Romar To Integer]/[0013][Romar To Integer].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0014][Longest Common Prefix]/[0014][Longest Common Prefix].iml b/[0014][Longest Common Prefix]/[0014][Longest Common Prefix].iml index c90834f..f080bef 100644 --- a/[0014][Longest Common Prefix]/[0014][Longest Common Prefix].iml +++ b/[0014][Longest Common Prefix]/[0014][Longest Common Prefix].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0015][3 Sum]/[0015][3 Sum].iml b/[0015][3 Sum]/[0015][3 Sum].iml index c90834f..f080bef 100644 --- a/[0015][3 Sum]/[0015][3 Sum].iml +++ b/[0015][3 Sum]/[0015][3 Sum].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0016][3 Sum Closest]/[0016][3 Sum Closest].iml b/[0016][3 Sum Closest]/[0016][3 Sum Closest].iml index c90834f..f080bef 100644 --- a/[0016][3 Sum Closest]/[0016][3 Sum Closest].iml +++ b/[0016][3 Sum Closest]/[0016][3 Sum Closest].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0017][Letter Combinations Of A Phon Number/[0017][Letter Combinations Of A Phon Number.iml b/[0017][Letter Combinations Of A Phon Number/[0017][Letter Combinations Of A Phon Number.iml index c90834f..f080bef 100644 --- a/[0017][Letter Combinations Of A Phon Number/[0017][Letter Combinations Of A Phon Number.iml +++ b/[0017][Letter Combinations Of A Phon Number/[0017][Letter Combinations Of A Phon Number.iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0018][4 Sum]/[0018][4 Sum].iml b/[0018][4 Sum]/[0018][4 Sum].iml index c90834f..f080bef 100644 --- a/[0018][4 Sum]/[0018][4 Sum].iml +++ b/[0018][4 Sum]/[0018][4 Sum].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0019][Remove Nth Node From End Of List]/[0019][Remove Nth Node From End Of List].iml b/[0019][Remove Nth Node From End Of List]/[0019][Remove Nth Node From End Of List].iml index c90834f..f080bef 100644 --- a/[0019][Remove Nth Node From End Of List]/[0019][Remove Nth Node From End Of List].iml +++ b/[0019][Remove Nth Node From End Of List]/[0019][Remove Nth Node From End Of List].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0020][Valid Parentheses]/[0020][Valid Parentheses].iml b/[0020][Valid Parentheses]/[0020][Valid Parentheses].iml index c90834f..f080bef 100644 --- a/[0020][Valid Parentheses]/[0020][Valid Parentheses].iml +++ b/[0020][Valid Parentheses]/[0020][Valid Parentheses].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0021][Merge Two Sorted Lists]/[0021][Merge Two Sorted Lists].iml b/[0021][Merge Two Sorted Lists]/[0021][Merge Two Sorted Lists].iml index c90834f..f080bef 100644 --- a/[0021][Merge Two Sorted Lists]/[0021][Merge Two Sorted Lists].iml +++ b/[0021][Merge Two Sorted Lists]/[0021][Merge Two Sorted Lists].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0022][Generate Parentheses]/[0022][Generate Parentheses].iml b/[0022][Generate Parentheses]/[0022][Generate Parentheses].iml index c90834f..f080bef 100644 --- a/[0022][Generate Parentheses]/[0022][Generate Parentheses].iml +++ b/[0022][Generate Parentheses]/[0022][Generate Parentheses].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0023][Merge K Sorted Lists]/[0023][Merge K Sorted Lists].iml b/[0023][Merge K Sorted Lists]/[0023][Merge K Sorted Lists].iml index c90834f..f080bef 100644 --- a/[0023][Merge K Sorted Lists]/[0023][Merge K Sorted Lists].iml +++ b/[0023][Merge K Sorted Lists]/[0023][Merge K Sorted Lists].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0024][Swap Nodes In Pairs]/[0024][Swap Nodes In Pairs].iml b/[0024][Swap Nodes In Pairs]/[0024][Swap Nodes In Pairs].iml index c90834f..f080bef 100644 --- a/[0024][Swap Nodes In Pairs]/[0024][Swap Nodes In Pairs].iml +++ b/[0024][Swap Nodes In Pairs]/[0024][Swap Nodes In Pairs].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0025][Reverse Nodes In K-Group]/[0025][Reverse Nodes In K-Group].iml b/[0025][Reverse Nodes In K-Group]/[0025][Reverse Nodes In K-Group].iml index c90834f..f080bef 100644 --- a/[0025][Reverse Nodes In K-Group]/[0025][Reverse Nodes In K-Group].iml +++ b/[0025][Reverse Nodes In K-Group]/[0025][Reverse Nodes In K-Group].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0026][Remove Duplicates from Sorted Array]/[0026][Remove Duplicates from Sorted Array].iml b/[0026][Remove Duplicates from Sorted Array]/[0026][Remove Duplicates from Sorted Array].iml index c90834f..f080bef 100644 --- a/[0026][Remove Duplicates from Sorted Array]/[0026][Remove Duplicates from Sorted Array].iml +++ b/[0026][Remove Duplicates from Sorted Array]/[0026][Remove Duplicates from Sorted Array].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0027][Remove Element]/[0027][Remove Element].iml b/[0027][Remove Element]/[0027][Remove Element].iml index c90834f..f080bef 100644 --- a/[0027][Remove Element]/[0027][Remove Element].iml +++ b/[0027][Remove Element]/[0027][Remove Element].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0028][Implement-strStr()]/[0028][Implement-strStr()].iml b/[0028][Implement-strStr()]/[0028][Implement-strStr()].iml index c90834f..f080bef 100644 --- a/[0028][Implement-strStr()]/[0028][Implement-strStr()].iml +++ b/[0028][Implement-strStr()]/[0028][Implement-strStr()].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0029][Divide Two Integers]/[0029][Divide Two Integers].iml b/[0029][Divide Two Integers]/[0029][Divide Two Integers].iml index c90834f..f080bef 100644 --- a/[0029][Divide Two Integers]/[0029][Divide Two Integers].iml +++ b/[0029][Divide Two Integers]/[0029][Divide Two Integers].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0030][Substring With Concatenation Of All Words]/[0030][Substring With Concatenation Of All Words].iml b/[0030][Substring With Concatenation Of All Words]/[0030][Substring With Concatenation Of All Words].iml index c90834f..f080bef 100644 --- a/[0030][Substring With Concatenation Of All Words]/[0030][Substring With Concatenation Of All Words].iml +++ b/[0030][Substring With Concatenation Of All Words]/[0030][Substring With Concatenation Of All Words].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0031][Next Permutation]/[0031][Next Permutation].iml b/[0031][Next Permutation]/[0031][Next Permutation].iml index c90834f..f080bef 100644 --- a/[0031][Next Permutation]/[0031][Next Permutation].iml +++ b/[0031][Next Permutation]/[0031][Next Permutation].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0032][Longest Valid Parentheses]/[0032][Longest Valid Parentheses].iml b/[0032][Longest Valid Parentheses]/[0032][Longest Valid Parentheses].iml index c90834f..f080bef 100644 --- a/[0032][Longest Valid Parentheses]/[0032][Longest Valid Parentheses].iml +++ b/[0032][Longest Valid Parentheses]/[0032][Longest Valid Parentheses].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0033][Search In Rotated Sorted Array]/[0033][Search In Rotated Sorted Array].iml b/[0033][Search In Rotated Sorted Array]/[0033][Search In Rotated Sorted Array].iml index c90834f..f080bef 100644 --- a/[0033][Search In Rotated Sorted Array]/[0033][Search In Rotated Sorted Array].iml +++ b/[0033][Search In Rotated Sorted Array]/[0033][Search In Rotated Sorted Array].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0034][Search For A Range]/[0034][Search For A Range].iml b/[0034][Search For A Range]/[0034][Search For A Range].iml index c90834f..f080bef 100644 --- a/[0034][Search For A Range]/[0034][Search For A Range].iml +++ b/[0034][Search For A Range]/[0034][Search For A Range].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0035][Search Insert Position]/[0035][Search Insert Position].iml b/[0035][Search Insert Position]/[0035][Search Insert Position].iml index c90834f..f080bef 100644 --- a/[0035][Search Insert Position]/[0035][Search Insert Position].iml +++ b/[0035][Search Insert Position]/[0035][Search Insert Position].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0036][Valid Sudoku]/[0036][Valid Sudoku].iml b/[0036][Valid Sudoku]/[0036][Valid Sudoku].iml index c90834f..f080bef 100644 --- a/[0036][Valid Sudoku]/[0036][Valid Sudoku].iml +++ b/[0036][Valid Sudoku]/[0036][Valid Sudoku].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0037][Sudoku Solver]/[0037][Sudoku Solver].iml b/[0037][Sudoku Solver]/[0037][Sudoku Solver].iml index c90834f..f080bef 100644 --- a/[0037][Sudoku Solver]/[0037][Sudoku Solver].iml +++ b/[0037][Sudoku Solver]/[0037][Sudoku Solver].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0038][Count And Say]/[0038][Count And Say].iml b/[0038][Count And Say]/[0038][Count And Say].iml index c90834f..f080bef 100644 --- a/[0038][Count And Say]/[0038][Count And Say].iml +++ b/[0038][Count And Say]/[0038][Count And Say].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0039][Combination Sum]/[0039][Combination Sum].iml b/[0039][Combination Sum]/[0039][Combination Sum].iml index c90834f..f080bef 100644 --- a/[0039][Combination Sum]/[0039][Combination Sum].iml +++ b/[0039][Combination Sum]/[0039][Combination Sum].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0040][Combination Sum II]/[0040][Combination Sum II].iml b/[0040][Combination Sum II]/[0040][Combination Sum II].iml index c90834f..f080bef 100644 --- a/[0040][Combination Sum II]/[0040][Combination Sum II].iml +++ b/[0040][Combination Sum II]/[0040][Combination Sum II].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0041][First Missing Positive]/[0041][First Missing Positive].iml b/[0041][First Missing Positive]/[0041][First Missing Positive].iml index c90834f..f080bef 100644 --- a/[0041][First Missing Positive]/[0041][First Missing Positive].iml +++ b/[0041][First Missing Positive]/[0041][First Missing Positive].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0042][Trapping Rain Water]/[0042][Trapping Rain Water].iml b/[0042][Trapping Rain Water]/[0042][Trapping Rain Water].iml index c90834f..f080bef 100644 --- a/[0042][Trapping Rain Water]/[0042][Trapping Rain Water].iml +++ b/[0042][Trapping Rain Water]/[0042][Trapping Rain Water].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0043][Multiply Strings]/[0043][Multiply Strings].iml b/[0043][Multiply Strings]/[0043][Multiply Strings].iml index c90834f..f080bef 100644 --- a/[0043][Multiply Strings]/[0043][Multiply Strings].iml +++ b/[0043][Multiply Strings]/[0043][Multiply Strings].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0044][Wildcard Matching]/[0044][Wildcard Matching].iml b/[0044][Wildcard Matching]/[0044][Wildcard Matching].iml index c90834f..f080bef 100644 --- a/[0044][Wildcard Matching]/[0044][Wildcard Matching].iml +++ b/[0044][Wildcard Matching]/[0044][Wildcard Matching].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0045][Jump Game II]/[0045][Jump Game II].iml b/[0045][Jump Game II]/[0045][Jump Game II].iml index c90834f..f080bef 100644 --- a/[0045][Jump Game II]/[0045][Jump Game II].iml +++ b/[0045][Jump Game II]/[0045][Jump Game II].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0046][Permutations]/[0046][Permutations].iml b/[0046][Permutations]/[0046][Permutations].iml index c90834f..f080bef 100644 --- a/[0046][Permutations]/[0046][Permutations].iml +++ b/[0046][Permutations]/[0046][Permutations].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0047][Permutations II]/[0047][Permutations II].iml b/[0047][Permutations II]/[0047][Permutations II].iml index c90834f..f080bef 100644 --- a/[0047][Permutations II]/[0047][Permutations II].iml +++ b/[0047][Permutations II]/[0047][Permutations II].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0048][Rotate Image]/[0048][Rotate Image].iml b/[0048][Rotate Image]/[0048][Rotate Image].iml index c90834f..f080bef 100644 --- a/[0048][Rotate Image]/[0048][Rotate Image].iml +++ b/[0048][Rotate Image]/[0048][Rotate Image].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0049][Group Anagrams]/[0049][Group Anagrams].iml b/[0049][Group Anagrams]/[0049][Group Anagrams].iml index c90834f..f080bef 100644 --- a/[0049][Group Anagrams]/[0049][Group Anagrams].iml +++ b/[0049][Group Anagrams]/[0049][Group Anagrams].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0050][Pow(x,n)]/[0050][Pow(x,n)].iml b/[0050][Pow(x,n)]/[0050][Pow(x,n)].iml index c90834f..f080bef 100644 --- a/[0050][Pow(x,n)]/[0050][Pow(x,n)].iml +++ b/[0050][Pow(x,n)]/[0050][Pow(x,n)].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0051][N-Queens]/[0051][N-Queens].iml b/[0051][N-Queens]/[0051][N-Queens].iml index c90834f..f080bef 100644 --- a/[0051][N-Queens]/[0051][N-Queens].iml +++ b/[0051][N-Queens]/[0051][N-Queens].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0052][N-Queens II]/[0052][N-Queens II].iml b/[0052][N-Queens II]/[0052][N-Queens II].iml index c90834f..f080bef 100644 --- a/[0052][N-Queens II]/[0052][N-Queens II].iml +++ b/[0052][N-Queens II]/[0052][N-Queens II].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0053][Maximum Subarray]/[0053][Maximum Subarray].iml b/[0053][Maximum Subarray]/[0053][Maximum Subarray].iml index c90834f..f080bef 100644 --- a/[0053][Maximum Subarray]/[0053][Maximum Subarray].iml +++ b/[0053][Maximum Subarray]/[0053][Maximum Subarray].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0053][Maximum Subarray]/src/Solution.java b/[0053][Maximum Subarray]/src/Solution.java index 9c2d79b..4b97536 100644 --- a/[0053][Maximum Subarray]/src/Solution.java +++ b/[0053][Maximum Subarray]/src/Solution.java @@ -6,12 +6,19 @@ */ public class Solution { /** - *
-     * Find the contiguous subarray within an array (containing at least one number)
-     * which has the largest sum.
+     * 
+     * Given an integer array nums, find the contiguous subarray (containing at least one number)
+     * which has the largest sum and return its sum.
      *
-     * For example, given the array [?2,1,?3,4,?1,2,1,?5,4],
-     * the contiguous subarray [4,?1,2,1] has the largest sum = 6.
+     * Example:
+     *
+     * Input: [-2,1,-3,4,-1,2,1,-5,4],
+     * Output: 6
+     * Explanation: [4,-1,2,1] has the largest sum = 6.
+     * Follow up:
+     *
+     * If you have figured out the O(n) solution, try coding another solution using the divide and
+     * conquer approach, which is more subtle.
      *
      * Ŀ⣺
      * ĺ
@@ -19,7 +26,22 @@ public class Solution {
      * ̬滮⣬֪ǰkԪصкΪmaxSubѾ¼ˣԼһʱsum
      * ˵k+1Ԫأƣk+1Ԫ֮ǰĺС0ģ
      * ôk+1ԪشӶȥûй׵ģԿ԰sum 0
-     *
+ * + * Ǵͷβʱ򣬶һмѡأֻ + * ѡ1֮ǰSubArray2. ԼһSubArrayʲôʱأ + * ֮ǰSubArray ʹ0 ĻΪԺй׵ġ + * ѡ֮ǰSubArray + * ֮ǰSubArray Ϊ0 С0 ĻΪԺûйף + * кģС0 ʱѡֿʼһSubArray + * ״̬Ϊf[j]ʾS[j] βкͣ״̬תƷ£ + * f[j] = max {f[j - 1] + S[j]; S[j]} ; 1 <= j <= n + * target = max {f[j]}; 1 <= j <= n + * £ + * һS[j] ǰijЩһУкΪf[j - 1] + S[j] + * S[j] ֳΪһΣнһS[j]кΪS[j] + * + *
+ * * @param nums * @return */ @@ -34,7 +56,7 @@ public int maxSubArray(int[] nums) { for (int i : nums) { // ǰС0ͽǰֵcurSum - if (curSum <= 0){ + if (curSum <= 0) { curSum = i; } // ۼ diff --git a/[0054][Spiral Matrix]/[0054][Spiral Matrix].iml b/[0054][Spiral Matrix]/[0054][Spiral Matrix].iml index c90834f..f080bef 100644 --- a/[0054][Spiral Matrix]/[0054][Spiral Matrix].iml +++ b/[0054][Spiral Matrix]/[0054][Spiral Matrix].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0055][Jump Game]/[0055][Jump Game].iml b/[0055][Jump Game]/[0055][Jump Game].iml index c90834f..f080bef 100644 --- a/[0055][Jump Game]/[0055][Jump Game].iml +++ b/[0055][Jump Game]/[0055][Jump Game].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0056][Merge Intervals]/[0056][Merge Intervals].iml b/[0056][Merge Intervals]/[0056][Merge Intervals].iml index c90834f..f080bef 100644 --- a/[0056][Merge Intervals]/[0056][Merge Intervals].iml +++ b/[0056][Merge Intervals]/[0056][Merge Intervals].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0057][Insert Interval]/[0057][Insert Interval].iml b/[0057][Insert Interval]/[0057][Insert Interval].iml index c90834f..f080bef 100644 --- a/[0057][Insert Interval]/[0057][Insert Interval].iml +++ b/[0057][Insert Interval]/[0057][Insert Interval].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0058][Length Of Last Word]/[0058][Length Of Last Word].iml b/[0058][Length Of Last Word]/[0058][Length Of Last Word].iml index c90834f..f080bef 100644 --- a/[0058][Length Of Last Word]/[0058][Length Of Last Word].iml +++ b/[0058][Length Of Last Word]/[0058][Length Of Last Word].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0059][Spiral Matrix II]/[0059][Spiral Matrix II].iml b/[0059][Spiral Matrix II]/[0059][Spiral Matrix II].iml index c90834f..f080bef 100644 --- a/[0059][Spiral Matrix II]/[0059][Spiral Matrix II].iml +++ b/[0059][Spiral Matrix II]/[0059][Spiral Matrix II].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0060][Permutation Sequence]/[0060][Permutation Sequence].iml b/[0060][Permutation Sequence]/[0060][Permutation Sequence].iml index c90834f..f080bef 100644 --- a/[0060][Permutation Sequence]/[0060][Permutation Sequence].iml +++ b/[0060][Permutation Sequence]/[0060][Permutation Sequence].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0061][Rotate List]/[0061][Rotate List].iml b/[0061][Rotate List]/[0061][Rotate List].iml index c90834f..f080bef 100644 --- a/[0061][Rotate List]/[0061][Rotate List].iml +++ b/[0061][Rotate List]/[0061][Rotate List].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0062][Unique Paths]/[0062][Unique Paths].iml b/[0062][Unique Paths]/[0062][Unique Paths].iml index c90834f..f080bef 100644 --- a/[0062][Unique Paths]/[0062][Unique Paths].iml +++ b/[0062][Unique Paths]/[0062][Unique Paths].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0063][Unique Paths II]/[0063][Unique Paths II].iml b/[0063][Unique Paths II]/[0063][Unique Paths II].iml index c90834f..f080bef 100644 --- a/[0063][Unique Paths II]/[0063][Unique Paths II].iml +++ b/[0063][Unique Paths II]/[0063][Unique Paths II].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0064][Minimum Path Sum]/[0064][Minimum Path Sum].iml b/[0064][Minimum Path Sum]/[0064][Minimum Path Sum].iml index c90834f..f080bef 100644 --- a/[0064][Minimum Path Sum]/[0064][Minimum Path Sum].iml +++ b/[0064][Minimum Path Sum]/[0064][Minimum Path Sum].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0065][Valid Number]/[0065][Valid Number].iml b/[0065][Valid Number]/[0065][Valid Number].iml index c90834f..f080bef 100644 --- a/[0065][Valid Number]/[0065][Valid Number].iml +++ b/[0065][Valid Number]/[0065][Valid Number].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0066][Plus One]/[0066][Plus One].iml b/[0066][Plus One]/[0066][Plus One].iml index c90834f..f080bef 100644 --- a/[0066][Plus One]/[0066][Plus One].iml +++ b/[0066][Plus One]/[0066][Plus One].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0067][Add Binary]/[0067][Add Binary].iml b/[0067][Add Binary]/[0067][Add Binary].iml index c90834f..f080bef 100644 --- a/[0067][Add Binary]/[0067][Add Binary].iml +++ b/[0067][Add Binary]/[0067][Add Binary].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0069][Sqrt(x)]/[0069][Sqrt(x)].iml b/[0069][Sqrt(x)]/[0069][Sqrt(x)].iml index c90834f..f080bef 100644 --- a/[0069][Sqrt(x)]/[0069][Sqrt(x)].iml +++ b/[0069][Sqrt(x)]/[0069][Sqrt(x)].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0070][Climbing Stairs]/[0070][Climbing Stairs].iml b/[0070][Climbing Stairs]/[0070][Climbing Stairs].iml index c90834f..f080bef 100644 --- a/[0070][Climbing Stairs]/[0070][Climbing Stairs].iml +++ b/[0070][Climbing Stairs]/[0070][Climbing Stairs].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0071][Simplify Path]/[0071][Simplify Path].iml b/[0071][Simplify Path]/[0071][Simplify Path].iml index c90834f..f080bef 100644 --- a/[0071][Simplify Path]/[0071][Simplify Path].iml +++ b/[0071][Simplify Path]/[0071][Simplify Path].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0073][Set Matrix Zeroes]/[0073][Set Matrix Zeroes].iml b/[0073][Set Matrix Zeroes]/[0073][Set Matrix Zeroes].iml index c90834f..f080bef 100644 --- a/[0073][Set Matrix Zeroes]/[0073][Set Matrix Zeroes].iml +++ b/[0073][Set Matrix Zeroes]/[0073][Set Matrix Zeroes].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0074][Search A 2D Matrix]/[0074][Search A 2D Matrix].iml b/[0074][Search A 2D Matrix]/[0074][Search A 2D Matrix].iml index c90834f..f080bef 100644 --- a/[0074][Search A 2D Matrix]/[0074][Search A 2D Matrix].iml +++ b/[0074][Search A 2D Matrix]/[0074][Search A 2D Matrix].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0075][Sort Colors]/[0075][Sort Colors].iml b/[0075][Sort Colors]/[0075][Sort Colors].iml index c90834f..f080bef 100644 --- a/[0075][Sort Colors]/[0075][Sort Colors].iml +++ b/[0075][Sort Colors]/[0075][Sort Colors].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0077][Combinations]/[0077][Combinations].iml b/[0077][Combinations]/[0077][Combinations].iml index c90834f..f080bef 100644 --- a/[0077][Combinations]/[0077][Combinations].iml +++ b/[0077][Combinations]/[0077][Combinations].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0078][Subsets]/[0078][Subsets].iml b/[0078][Subsets]/[0078][Subsets].iml index c90834f..f080bef 100644 --- a/[0078][Subsets]/[0078][Subsets].iml +++ b/[0078][Subsets]/[0078][Subsets].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0079][Word Search]/[0079][Word Search].iml b/[0079][Word Search]/[0079][Word Search].iml index c90834f..f080bef 100644 --- a/[0079][Word Search]/[0079][Word Search].iml +++ b/[0079][Word Search]/[0079][Word Search].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0080][Remove Duplicates from Sorted Array II]/[0080][Remove Duplicates from Sorted Array II].iml b/[0080][Remove Duplicates from Sorted Array II]/[0080][Remove Duplicates from Sorted Array II].iml index c90834f..f080bef 100644 --- a/[0080][Remove Duplicates from Sorted Array II]/[0080][Remove Duplicates from Sorted Array II].iml +++ b/[0080][Remove Duplicates from Sorted Array II]/[0080][Remove Duplicates from Sorted Array II].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0081][Search In Rotated Sorted Array II]/[0081][Search In Rotated Sorted Array II].iml b/[0081][Search In Rotated Sorted Array II]/[0081][Search In Rotated Sorted Array II].iml index c90834f..f080bef 100644 --- a/[0081][Search In Rotated Sorted Array II]/[0081][Search In Rotated Sorted Array II].iml +++ b/[0081][Search In Rotated Sorted Array II]/[0081][Search In Rotated Sorted Array II].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0082][Remove Duplicates From Sorted List II]/[0082][Remove Duplicates From Sorted List II].iml b/[0082][Remove Duplicates From Sorted List II]/[0082][Remove Duplicates From Sorted List II].iml index c90834f..f080bef 100644 --- a/[0082][Remove Duplicates From Sorted List II]/[0082][Remove Duplicates From Sorted List II].iml +++ b/[0082][Remove Duplicates From Sorted List II]/[0082][Remove Duplicates From Sorted List II].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0083][Remove Duplicates From Sorted List]/[0083][Remove Duplicates From Sorted List].iml b/[0083][Remove Duplicates From Sorted List]/[0083][Remove Duplicates From Sorted List].iml index c90834f..f080bef 100644 --- a/[0083][Remove Duplicates From Sorted List]/[0083][Remove Duplicates From Sorted List].iml +++ b/[0083][Remove Duplicates From Sorted List]/[0083][Remove Duplicates From Sorted List].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0084][Largest Rectangle in Histogram]/[0084][Largest Rectangle in Histogram].iml b/[0084][Largest Rectangle in Histogram]/[0084][Largest Rectangle in Histogram].iml index c90834f..f080bef 100644 --- a/[0084][Largest Rectangle in Histogram]/[0084][Largest Rectangle in Histogram].iml +++ b/[0084][Largest Rectangle in Histogram]/[0084][Largest Rectangle in Histogram].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0086][Partition List]/[0086][Partition List].iml b/[0086][Partition List]/[0086][Partition List].iml index c90834f..f080bef 100644 --- a/[0086][Partition List]/[0086][Partition List].iml +++ b/[0086][Partition List]/[0086][Partition List].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0088][Merge Sorted Array]/[0088][Merge Sorted Array].iml b/[0088][Merge Sorted Array]/[0088][Merge Sorted Array].iml index c90834f..f080bef 100644 --- a/[0088][Merge Sorted Array]/[0088][Merge Sorted Array].iml +++ b/[0088][Merge Sorted Array]/[0088][Merge Sorted Array].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0089][Gray Code]/[0089][Gray Code].iml b/[0089][Gray Code]/[0089][Gray Code].iml index c90834f..f080bef 100644 --- a/[0089][Gray Code]/[0089][Gray Code].iml +++ b/[0089][Gray Code]/[0089][Gray Code].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0090][Subsets II]/[0090][Subsets II].iml b/[0090][Subsets II]/[0090][Subsets II].iml index c90834f..f080bef 100644 --- a/[0090][Subsets II]/[0090][Subsets II].iml +++ b/[0090][Subsets II]/[0090][Subsets II].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0092][Reverse Linked List II]/[0092][Reverse Linked List II].iml b/[0092][Reverse Linked List II]/[0092][Reverse Linked List II].iml index c90834f..f080bef 100644 --- a/[0092][Reverse Linked List II]/[0092][Reverse Linked List II].iml +++ b/[0092][Reverse Linked List II]/[0092][Reverse Linked List II].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0093][Restore IP Addresses]/[0093][Restore IP Addresses].iml b/[0093][Restore IP Addresses]/[0093][Restore IP Addresses].iml index c90834f..f080bef 100644 --- a/[0093][Restore IP Addresses]/[0093][Restore IP Addresses].iml +++ b/[0093][Restore IP Addresses]/[0093][Restore IP Addresses].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0094][Binary Tree Inorder Traversal]/[0094][Binary Tree Inorder Traversal].iml b/[0094][Binary Tree Inorder Traversal]/[0094][Binary Tree Inorder Traversal].iml index c90834f..f080bef 100644 --- a/[0094][Binary Tree Inorder Traversal]/[0094][Binary Tree Inorder Traversal].iml +++ b/[0094][Binary Tree Inorder Traversal]/[0094][Binary Tree Inorder Traversal].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0096][Unique Binary Search Trees]/[0096][Unique Binary Search Trees].iml b/[0096][Unique Binary Search Trees]/[0096][Unique Binary Search Trees].iml index c90834f..f080bef 100644 --- a/[0096][Unique Binary Search Trees]/[0096][Unique Binary Search Trees].iml +++ b/[0096][Unique Binary Search Trees]/[0096][Unique Binary Search Trees].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0098][Validate Binary Search Tree]/[0098][Validate Binary Search Tree].iml b/[0098][Validate Binary Search Tree]/[0098][Validate Binary Search Tree].iml index c90834f..f080bef 100644 --- a/[0098][Validate Binary Search Tree]/[0098][Validate Binary Search Tree].iml +++ b/[0098][Validate Binary Search Tree]/[0098][Validate Binary Search Tree].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0100][Same Tree]/[0100][Same Tree].iml b/[0100][Same Tree]/[0100][Same Tree].iml index c90834f..f080bef 100644 --- a/[0100][Same Tree]/[0100][Same Tree].iml +++ b/[0100][Same Tree]/[0100][Same Tree].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0101][Symmetric Tree]/[0101][Symmetric Tree].iml b/[0101][Symmetric Tree]/[0101][Symmetric Tree].iml index c90834f..f080bef 100644 --- a/[0101][Symmetric Tree]/[0101][Symmetric Tree].iml +++ b/[0101][Symmetric Tree]/[0101][Symmetric Tree].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0102][Binary Tree Level Order Traversal]/[0102][Binary Tree Level Order Traversal].iml b/[0102][Binary Tree Level Order Traversal]/[0102][Binary Tree Level Order Traversal].iml index c90834f..f080bef 100644 --- a/[0102][Binary Tree Level Order Traversal]/[0102][Binary Tree Level Order Traversal].iml +++ b/[0102][Binary Tree Level Order Traversal]/[0102][Binary Tree Level Order Traversal].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0103][Binary Tree Zigzag LevelOrder Traversal]/[0103][Binary Tree Zigzag LevelOrder Traversal].iml b/[0103][Binary Tree Zigzag LevelOrder Traversal]/[0103][Binary Tree Zigzag LevelOrder Traversal].iml index c90834f..f080bef 100644 --- a/[0103][Binary Tree Zigzag LevelOrder Traversal]/[0103][Binary Tree Zigzag LevelOrder Traversal].iml +++ b/[0103][Binary Tree Zigzag LevelOrder Traversal]/[0103][Binary Tree Zigzag LevelOrder Traversal].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0104][Maximum Depth Of Binary Tree]/[0104][Maximum Depth Of Binary Tree].iml b/[0104][Maximum Depth Of Binary Tree]/[0104][Maximum Depth Of Binary Tree].iml index c90834f..f080bef 100644 --- a/[0104][Maximum Depth Of Binary Tree]/[0104][Maximum Depth Of Binary Tree].iml +++ b/[0104][Maximum Depth Of Binary Tree]/[0104][Maximum Depth Of Binary Tree].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0105][Construct Binary Tree From Preorder And Inorder Traversal]/[0105][Construct Binary Tree From Preorder And Inorder Traversal].iml b/[0105][Construct Binary Tree From Preorder And Inorder Traversal]/[0105][Construct Binary Tree From Preorder And Inorder Traversal].iml index c90834f..f080bef 100644 --- a/[0105][Construct Binary Tree From Preorder And Inorder Traversal]/[0105][Construct Binary Tree From Preorder And Inorder Traversal].iml +++ b/[0105][Construct Binary Tree From Preorder And Inorder Traversal]/[0105][Construct Binary Tree From Preorder And Inorder Traversal].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0106][Construct Binary Tree From Inorder And Postorder Traversal]/[0106][Construct Binary Tree From Inorder And Postorder Traversal].iml b/[0106][Construct Binary Tree From Inorder And Postorder Traversal]/[0106][Construct Binary Tree From Inorder And Postorder Traversal].iml index c90834f..f080bef 100644 --- a/[0106][Construct Binary Tree From Inorder And Postorder Traversal]/[0106][Construct Binary Tree From Inorder And Postorder Traversal].iml +++ b/[0106][Construct Binary Tree From Inorder And Postorder Traversal]/[0106][Construct Binary Tree From Inorder And Postorder Traversal].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0107][Binary Tree Level Order Traversa lII]/[0107][Binary Tree Level Order Traversa lII].iml b/[0107][Binary Tree Level Order Traversa lII]/[0107][Binary Tree Level Order Traversa lII].iml index c90834f..f080bef 100644 --- a/[0107][Binary Tree Level Order Traversa lII]/[0107][Binary Tree Level Order Traversa lII].iml +++ b/[0107][Binary Tree Level Order Traversa lII]/[0107][Binary Tree Level Order Traversa lII].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0108][Convert Sorted Array To Binary Search Tree]/[0108][Convert Sorted Array To Binary Search Tree].iml b/[0108][Convert Sorted Array To Binary Search Tree]/[0108][Convert Sorted Array To Binary Search Tree].iml index c90834f..f080bef 100644 --- a/[0108][Convert Sorted Array To Binary Search Tree]/[0108][Convert Sorted Array To Binary Search Tree].iml +++ b/[0108][Convert Sorted Array To Binary Search Tree]/[0108][Convert Sorted Array To Binary Search Tree].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0109][Convert Sorted List To Binary Search Tree]/[0109][Convert Sorted List To Binary Search Tree].iml b/[0109][Convert Sorted List To Binary Search Tree]/[0109][Convert Sorted List To Binary Search Tree].iml index c90834f..f080bef 100644 --- a/[0109][Convert Sorted List To Binary Search Tree]/[0109][Convert Sorted List To Binary Search Tree].iml +++ b/[0109][Convert Sorted List To Binary Search Tree]/[0109][Convert Sorted List To Binary Search Tree].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0110][Balanced Binary Tree]/[0110][Balanced Binary Tree].iml b/[0110][Balanced Binary Tree]/[0110][Balanced Binary Tree].iml index c90834f..f080bef 100644 --- a/[0110][Balanced Binary Tree]/[0110][Balanced Binary Tree].iml +++ b/[0110][Balanced Binary Tree]/[0110][Balanced Binary Tree].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0111][Minimum Depth Of Binary Tree]/[0111][Minimum Depth Of Binary Tree].iml b/[0111][Minimum Depth Of Binary Tree]/[0111][Minimum Depth Of Binary Tree].iml index c90834f..f080bef 100644 --- a/[0111][Minimum Depth Of Binary Tree]/[0111][Minimum Depth Of Binary Tree].iml +++ b/[0111][Minimum Depth Of Binary Tree]/[0111][Minimum Depth Of Binary Tree].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0112][Path Sum]/[0112][Path Sum].iml b/[0112][Path Sum]/[0112][Path Sum].iml index c90834f..f080bef 100644 --- a/[0112][Path Sum]/[0112][Path Sum].iml +++ b/[0112][Path Sum]/[0112][Path Sum].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0113][Path Sum II]/[0113][Path Sum II].iml b/[0113][Path Sum II]/[0113][Path Sum II].iml index c90834f..f080bef 100644 --- a/[0113][Path Sum II]/[0113][Path Sum II].iml +++ b/[0113][Path Sum II]/[0113][Path Sum II].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0114][Flatten Binary Tree To Linked List]/[0114][Flatten Binary Tree To Linked List].iml b/[0114][Flatten Binary Tree To Linked List]/[0114][Flatten Binary Tree To Linked List].iml index c90834f..f080bef 100644 --- a/[0114][Flatten Binary Tree To Linked List]/[0114][Flatten Binary Tree To Linked List].iml +++ b/[0114][Flatten Binary Tree To Linked List]/[0114][Flatten Binary Tree To Linked List].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0116][Populating Next Right Pointersin Each Node]/[0116][Populating Next Right Pointersin Each Node].iml b/[0116][Populating Next Right Pointersin Each Node]/[0116][Populating Next Right Pointersin Each Node].iml index c90834f..f080bef 100644 --- a/[0116][Populating Next Right Pointersin Each Node]/[0116][Populating Next Right Pointersin Each Node].iml +++ b/[0116][Populating Next Right Pointersin Each Node]/[0116][Populating Next Right Pointersin Each Node].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0117][Populating Next Right Pointers In Each Node II]/[0117][Populating Next Right Pointers In Each Node II].iml b/[0117][Populating Next Right Pointers In Each Node II]/[0117][Populating Next Right Pointers In Each Node II].iml index c90834f..f080bef 100644 --- a/[0117][Populating Next Right Pointers In Each Node II]/[0117][Populating Next Right Pointers In Each Node II].iml +++ b/[0117][Populating Next Right Pointers In Each Node II]/[0117][Populating Next Right Pointers In Each Node II].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0118][Pascal's Triangle]/[0118][Pascal's Triangle].iml b/[0118][Pascal's Triangle]/[0118][Pascal's Triangle].iml index c90834f..f080bef 100644 --- a/[0118][Pascal's Triangle]/[0118][Pascal's Triangle].iml +++ b/[0118][Pascal's Triangle]/[0118][Pascal's Triangle].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0119][Pascal's Triangle II]/[0119][Pascal's Triangle II].iml b/[0119][Pascal's Triangle II]/[0119][Pascal's Triangle II].iml index c90834f..f080bef 100644 --- a/[0119][Pascal's Triangle II]/[0119][Pascal's Triangle II].iml +++ b/[0119][Pascal's Triangle II]/[0119][Pascal's Triangle II].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0120][Triangle]/[0120][Triangle].iml b/[0120][Triangle]/[0120][Triangle].iml index c90834f..f080bef 100644 --- a/[0120][Triangle]/[0120][Triangle].iml +++ b/[0120][Triangle]/[0120][Triangle].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0121][Best Time To Buy And Sell Stock]/[0121][Best Time To Buy And Sell Stock].iml b/[0121][Best Time To Buy And Sell Stock]/[0121][Best Time To Buy And Sell Stock].iml index c90834f..f080bef 100644 --- a/[0121][Best Time To Buy And Sell Stock]/[0121][Best Time To Buy And Sell Stock].iml +++ b/[0121][Best Time To Buy And Sell Stock]/[0121][Best Time To Buy And Sell Stock].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0122][Best Time to Buy and Sell Stock II]/[0122][Best Time to Buy and Sell Stock II].iml b/[0122][Best Time to Buy and Sell Stock II]/[0122][Best Time to Buy and Sell Stock II].iml index bb6b39c..c8cb479 100644 --- a/[0122][Best Time to Buy and Sell Stock II]/[0122][Best Time to Buy and Sell Stock II].iml +++ b/[0122][Best Time to Buy and Sell Stock II]/[0122][Best Time to Buy and Sell Stock II].iml @@ -17,5 +17,7 @@ + + \ No newline at end of file diff --git a/[0124][Binary Tree Maximum Path Sum]/[0124][Binary Tree Maximum Path Sum].iml b/[0124][Binary Tree Maximum Path Sum]/[0124][Binary Tree Maximum Path Sum].iml index c90834f..f080bef 100644 --- a/[0124][Binary Tree Maximum Path Sum]/[0124][Binary Tree Maximum Path Sum].iml +++ b/[0124][Binary Tree Maximum Path Sum]/[0124][Binary Tree Maximum Path Sum].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0125][Valid Palindrome]/[0125][Valid Palindrome].iml b/[0125][Valid Palindrome]/[0125][Valid Palindrome].iml index c90834f..f080bef 100644 --- a/[0125][Valid Palindrome]/[0125][Valid Palindrome].iml +++ b/[0125][Valid Palindrome]/[0125][Valid Palindrome].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0126][Word Ladder II]/[0126][Word Ladder II].iml b/[0126][Word Ladder II]/[0126][Word Ladder II].iml index c90834f..f080bef 100644 --- a/[0126][Word Ladder II]/[0126][Word Ladder II].iml +++ b/[0126][Word Ladder II]/[0126][Word Ladder II].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0127][Word Ladder]/[0127][Word Ladder].iml b/[0127][Word Ladder]/[0127][Word Ladder].iml index c90834f..f080bef 100644 --- a/[0127][Word Ladder]/[0127][Word Ladder].iml +++ b/[0127][Word Ladder]/[0127][Word Ladder].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0128][Longest Consecutive Sequence]/[0128][Longest Consecutive Sequence].iml b/[0128][Longest Consecutive Sequence]/[0128][Longest Consecutive Sequence].iml index c90834f..f080bef 100644 --- a/[0128][Longest Consecutive Sequence]/[0128][Longest Consecutive Sequence].iml +++ b/[0128][Longest Consecutive Sequence]/[0128][Longest Consecutive Sequence].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0129][Sum Root To Leaf Numbers]/[0129][Sum Root To Leaf Numbers].iml b/[0129][Sum Root To Leaf Numbers]/[0129][Sum Root To Leaf Numbers].iml index c90834f..f080bef 100644 --- a/[0129][Sum Root To Leaf Numbers]/[0129][Sum Root To Leaf Numbers].iml +++ b/[0129][Sum Root To Leaf Numbers]/[0129][Sum Root To Leaf Numbers].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0130][Surrounded Regions]/[0130][Surrounded Regions].iml b/[0130][Surrounded Regions]/[0130][Surrounded Regions].iml index c90834f..f080bef 100644 --- a/[0130][Surrounded Regions]/[0130][Surrounded Regions].iml +++ b/[0130][Surrounded Regions]/[0130][Surrounded Regions].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0131][Palindrome Partitioning]/[0131][Palindrome Partitioning].iml b/[0131][Palindrome Partitioning]/[0131][Palindrome Partitioning].iml index c90834f..f080bef 100644 --- a/[0131][Palindrome Partitioning]/[0131][Palindrome Partitioning].iml +++ b/[0131][Palindrome Partitioning]/[0131][Palindrome Partitioning].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0053][Maximum Subarray]/[0053][MaximumSubarray].iml b/[0132][Palindrome Partitioning II]/[0132][Palindrome Partitioning II].iml similarity index 74% rename from [0053][Maximum Subarray]/[0053][MaximumSubarray].iml rename to [0132][Palindrome Partitioning II]/[0132][Palindrome Partitioning II].iml index f080bef..c90834f 100644 --- a/[0053][Maximum Subarray]/[0053][MaximumSubarray].iml +++ b/[0132][Palindrome Partitioning II]/[0132][Palindrome Partitioning II].iml @@ -7,7 +7,5 @@ - - \ No newline at end of file diff --git a/[0132][Palindrome Partitioning II]/src/Solution.java b/[0132][Palindrome Partitioning II]/src/Solution.java new file mode 100644 index 0000000..6eddbef --- /dev/null +++ b/[0132][Palindrome Partitioning II]/src/Solution.java @@ -0,0 +1,56 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-24 19:22 + **/ +public class Solution { + /** + *
+     * Given a string s, partition s such that every substring of the partition is a palindrome.
+     *
+     * Return the minimum cuts needed for a palindrome partitioning of s.
+     *
+     * Example:
+     *
+     * Input: "aab"
+     * Output: 1
+     * Explanation: The palindrome partitioning ["aa","b"] could be produced using 1 cut.
+     *
+     * 分析
+     * 定义状态f(i,j) 表示区间[i,j] 之间最小的cut 数,则状态转移方程为
+     * f(i; j) = min {f(i; k) + f(k + 1; j)} ; i  k  j; 0  i  j < n
+     * 这是一个二维函数,实际写代码比较麻烦。
+     * 所以要转换成一维DP。如果每次,从i 往右扫描,每找到一个回文就算一次DP 的话,就可以
+     * 转换为f(i)= 区间[i, n-1] 之间最小的cut 数,n 为字符串长度,则状态转移方程为
+     * f(i) = min {f(j + 1) + 1} ; i <= j < n TODO 怎么理解?
+     * 一个问题出现了,就是如何判断[i,j] 是否是回文?每次都从i 到j 比较一遍?太浪费了,这
+     * 里也是一个DP 问题。
+     * 定义状态P[i][j] = true if [i,j] 为回文,那么
+     * P[i][j] = str[i] == str[j] && P[i+1][j-1]
+     *
+     * https://www.cnblogs.com/grandyang/p/4271456.html
+     * 
+ * + * @param s + * @return + */ + public int minCut(String s) { + final int n = s.length(); + + int[] dp = new int[n]; + boolean[][] p = new boolean[n][]; + + for (int i = 0; i < n; ++i) { + dp[i] = i; + p[i] = new boolean[n]; + + for (int j = 0; j <= i; ++j) { + if (s.charAt(i) == s.charAt(j) && (i - j < 2 || p[j + 1][i - 1])) { + p[j][i] = true; + dp[i] = (j == 0) ? 0 : Math.min(dp[i], dp[j - 1] + 1); + } + } + } + + return dp[n - 1]; + } +} diff --git a/[0132][Palindrome Partitioning II]/src/Solution2.java b/[0132][Palindrome Partitioning II]/src/Solution2.java new file mode 100644 index 0000000..ae1e9d6 --- /dev/null +++ b/[0132][Palindrome Partitioning II]/src/Solution2.java @@ -0,0 +1,63 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-24 19:22 + **/ +public class Solution2 { + /** + *
+     * Given a string s, partition s such that every substring of the partition is a palindrome.
+     *
+     * Return the minimum cuts needed for a palindrome partitioning of s.
+     *
+     * Example:
+     *
+     * Input: "aab"
+     * Output: 1
+     * Explanation: The palindrome partitioning ["aa","b"] could be produced using 1 cut.
+     *
+     * 分析
+     * 定义状态f(i,j) 表示区间[i,j] 之间最小的cut 数,则状态转移方程为
+     * f(i; j) = min {f(i; k) + f(k + 1; j)} ; i  k  j; 0  i  j < n
+     * 这是一个二维函数,实际写代码比较麻烦。
+     * 所以要转换成一维DP。如果每次,从i 往右扫描,每找到一个回文就算一次DP 的话,就可以
+     * 转换为f(i)= 区间[i, n-1] 之间最小的cut 数,n 为字符串长度,则状态转移方程为
+     * f(i) = min {f(j + 1) + 1} ; i <= j < n TODO 怎么理解?
+     * 一个问题出现了,就是如何判断[i,j] 是否是回文?每次都从i 到j 比较一遍?太浪费了,这
+     * 里也是一个DP 问题。
+     * 定义状态P[i][j] = true if [i,j] 为回文,那么
+     * P[i][j] = str[i] == str[j] && P[i+1][j-1]
+     *
+     * https://www.cnblogs.com/grandyang/p/4271456.html
+     * 
+ * + * @param s + * @return + */ + public int minCut(String s) { + final int n = s.length(); + + int[] f = new int[n + 1]; + boolean[][] p = new boolean[n][]; + //the worst case is cutting by each char + // 最后一个f[n]=-1 + for (int i = 0; i <= n; i++) { + // [n-1, n-2, ..., 1, 0, -1],为了后面做切分 + f[i] = n - 1 - i; + } + for (int i = n - 1; i >= 0; i--) { + p[i] = new boolean[n]; + + for (int j = i; j < n; j++) { + // j - i < 2 : 表示j在i位置或者j在i之后一个位置 + // p[i + 1][j - 1] : [i+1, j-1]是回文 + if (s.charAt(i) == s.charAt(j) && (j - i < 2 || p[i + 1][j - 1])) { + p[i][j] = true; + f[i] = Math.min(f[i], f[j + 1] + 1); + } + + } + } + + return f[0]; + } +} diff --git a/[0134][Gas Station]/[0134][Gas Station].iml b/[0134][Gas Station]/[0134][Gas Station].iml index c90834f..f080bef 100644 --- a/[0134][Gas Station]/[0134][Gas Station].iml +++ b/[0134][Gas Station]/[0134][Gas Station].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0135][Candy]/[0135][Candy].iml b/[0135][Candy]/[0135][Candy].iml index c90834f..f080bef 100644 --- a/[0135][Candy]/[0135][Candy].iml +++ b/[0135][Candy]/[0135][Candy].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0136][Single Number]/[0136][Single Number].iml b/[0136][Single Number]/[0136][Single Number].iml index c90834f..f080bef 100644 --- a/[0136][Single Number]/[0136][Single Number].iml +++ b/[0136][Single Number]/[0136][Single Number].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0137][Single Number II]/[0137][Single Number II].iml b/[0137][Single Number II]/[0137][Single Number II].iml index c90834f..f080bef 100644 --- a/[0137][Single Number II]/[0137][Single Number II].iml +++ b/[0137][Single Number II]/[0137][Single Number II].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0138][Copy List With Random Pointer]/[0138][Copy List With Random Pointer].iml b/[0138][Copy List With Random Pointer]/[0138][Copy List With Random Pointer].iml index c90834f..f080bef 100644 --- a/[0138][Copy List With Random Pointer]/[0138][Copy List With Random Pointer].iml +++ b/[0138][Copy List With Random Pointer]/[0138][Copy List With Random Pointer].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0139][Word Break]/[0139][Word Break].iml b/[0139][Word Break]/[0139][Word Break].iml index c90834f..f080bef 100644 --- a/[0139][Word Break]/[0139][Word Break].iml +++ b/[0139][Word Break]/[0139][Word Break].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0141][Linked List Cycle]/[0141][Linked List Cycle].iml b/[0141][Linked List Cycle]/[0141][Linked List Cycle].iml index c90834f..f080bef 100644 --- a/[0141][Linked List Cycle]/[0141][Linked List Cycle].iml +++ b/[0141][Linked List Cycle]/[0141][Linked List Cycle].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0142][Linked List Cycle II]/[0142][Linked List Cycle II].iml b/[0142][Linked List Cycle II]/[0142][Linked List Cycle II].iml index c90834f..f080bef 100644 --- a/[0142][Linked List Cycle II]/[0142][Linked List Cycle II].iml +++ b/[0142][Linked List Cycle II]/[0142][Linked List Cycle II].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0143][Reorder List]/[0143][Reorder List].iml b/[0143][Reorder List]/[0143][Reorder List].iml index c90834f..f080bef 100644 --- a/[0143][Reorder List]/[0143][Reorder List].iml +++ b/[0143][Reorder List]/[0143][Reorder List].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0144][Binary Tree Preorder Traversal]/[0144][Binary Tree Preorder Traversal].iml b/[0144][Binary Tree Preorder Traversal]/[0144][Binary Tree Preorder Traversal].iml index c90834f..f080bef 100644 --- a/[0144][Binary Tree Preorder Traversal]/[0144][Binary Tree Preorder Traversal].iml +++ b/[0144][Binary Tree Preorder Traversal]/[0144][Binary Tree Preorder Traversal].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0145][Binary Tree Postorder Traversal]/[0145][Binary Tree Postorder Traversal].iml b/[0145][Binary Tree Postorder Traversal]/[0145][Binary Tree Postorder Traversal].iml index c90834f..f080bef 100644 --- a/[0145][Binary Tree Postorder Traversal]/[0145][Binary Tree Postorder Traversal].iml +++ b/[0145][Binary Tree Postorder Traversal]/[0145][Binary Tree Postorder Traversal].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0146][LRU Cache]/[0146][LRU Cache].iml b/[0146][LRU Cache]/[0146][LRU Cache].iml index c90834f..f080bef 100644 --- a/[0146][LRU Cache]/[0146][LRU Cache].iml +++ b/[0146][LRU Cache]/[0146][LRU Cache].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0147][Insertion Sort List]/[0147][Insertion Sort List].iml b/[0147][Insertion Sort List]/[0147][Insertion Sort List].iml index c90834f..f080bef 100644 --- a/[0147][Insertion Sort List]/[0147][Insertion Sort List].iml +++ b/[0147][Insertion Sort List]/[0147][Insertion Sort List].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0148][Sort List]/[0148][Sort List].iml b/[0148][Sort List]/[0148][Sort List].iml index c90834f..f080bef 100644 --- a/[0148][Sort List]/[0148][Sort List].iml +++ b/[0148][Sort List]/[0148][Sort List].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0150][Evaluate Reverse Polish Notation]/[0150][Evaluate Reverse Polish Notation].iml b/[0150][Evaluate Reverse Polish Notation]/[0150][Evaluate Reverse Polish Notation].iml index c90834f..f080bef 100644 --- a/[0150][Evaluate Reverse Polish Notation]/[0150][Evaluate Reverse Polish Notation].iml +++ b/[0150][Evaluate Reverse Polish Notation]/[0150][Evaluate Reverse Polish Notation].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0151][Reverse Words In A String]/[0151][Reverse Words In A String].iml b/[0151][Reverse Words In A String]/[0151][Reverse Words In A String].iml index c90834f..f080bef 100644 --- a/[0151][Reverse Words In A String]/[0151][Reverse Words In A String].iml +++ b/[0151][Reverse Words In A String]/[0151][Reverse Words In A String].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0152][Maximum Product Subarray]/[0152][Maximum Product Subarray].iml b/[0152][Maximum Product Subarray]/[0152][Maximum Product Subarray].iml index c90834f..f080bef 100644 --- a/[0152][Maximum Product Subarray]/[0152][Maximum Product Subarray].iml +++ b/[0152][Maximum Product Subarray]/[0152][Maximum Product Subarray].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0153][Find Minimum In Rotated Sorted Array]/[0153][Find Minimum In Rotated Sorted Array].iml b/[0153][Find Minimum In Rotated Sorted Array]/[0153][Find Minimum In Rotated Sorted Array].iml index c90834f..f080bef 100644 --- a/[0153][Find Minimum In Rotated Sorted Array]/[0153][Find Minimum In Rotated Sorted Array].iml +++ b/[0153][Find Minimum In Rotated Sorted Array]/[0153][Find Minimum In Rotated Sorted Array].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0154][Find Minimum In Rotated Sorted Array II]/[0154][Find Minimum In Rotated Sorted Array II].iml b/[0154][Find Minimum In Rotated Sorted Array II]/[0154][Find Minimum In Rotated Sorted Array II].iml index c90834f..f080bef 100644 --- a/[0154][Find Minimum In Rotated Sorted Array II]/[0154][Find Minimum In Rotated Sorted Array II].iml +++ b/[0154][Find Minimum In Rotated Sorted Array II]/[0154][Find Minimum In Rotated Sorted Array II].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0155][Min Stack]/[0155][Min Stack].iml b/[0155][Min Stack]/[0155][Min Stack].iml index c90834f..f080bef 100644 --- a/[0155][Min Stack]/[0155][Min Stack].iml +++ b/[0155][Min Stack]/[0155][Min Stack].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0162][Find Peak Element]/[0162][Find Peak Element].iml b/[0162][Find Peak Element]/[0162][Find Peak Element].iml index c90834f..f080bef 100644 --- a/[0162][Find Peak Element]/[0162][Find Peak Element].iml +++ b/[0162][Find Peak Element]/[0162][Find Peak Element].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0167][Two Sum II - Input array is sorted]/[0167][Two Sum II - Input array is sorted].iml b/[0167][Two Sum II - Input array is sorted]/[0167][Two Sum II - Input array is sorted].iml index c90834f..f080bef 100644 --- a/[0167][Two Sum II - Input array is sorted]/[0167][Two Sum II - Input array is sorted].iml +++ b/[0167][Two Sum II - Input array is sorted]/[0167][Two Sum II - Input array is sorted].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0191][Number Of 1 Bits]/[0191][Number Of 1 Bits].iml b/[0191][Number Of 1 Bits]/[0191][Number Of 1 Bits].iml index c90834f..f080bef 100644 --- a/[0191][Number Of 1 Bits]/[0191][Number Of 1 Bits].iml +++ b/[0191][Number Of 1 Bits]/[0191][Number Of 1 Bits].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0198][House Robber]/[0198][House Robber].iml b/[0198][House Robber]/[0198][House Robber].iml index c90834f..f080bef 100644 --- a/[0198][House Robber]/[0198][House Robber].iml +++ b/[0198][House Robber]/[0198][House Robber].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0199][Binary Tree Right Side View]/[0199][Binary Tree Right Side View].iml b/[0199][Binary Tree Right Side View]/[0199][Binary Tree Right Side View].iml index c90834f..f080bef 100644 --- a/[0199][Binary Tree Right Side View]/[0199][Binary Tree Right Side View].iml +++ b/[0199][Binary Tree Right Side View]/[0199][Binary Tree Right Side View].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0200][Number Of Islands]/[0200][Number Of Islands].iml b/[0200][Number Of Islands]/[0200][Number Of Islands].iml index c90834f..f080bef 100644 --- a/[0200][Number Of Islands]/[0200][Number Of Islands].iml +++ b/[0200][Number Of Islands]/[0200][Number Of Islands].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0201][Bitwise AND Of Numbers Range]/[0201][Bitwise AND Of Numbers Range].iml b/[0201][Bitwise AND Of Numbers Range]/[0201][Bitwise AND Of Numbers Range].iml index c90834f..f080bef 100644 --- a/[0201][Bitwise AND Of Numbers Range]/[0201][Bitwise AND Of Numbers Range].iml +++ b/[0201][Bitwise AND Of Numbers Range]/[0201][Bitwise AND Of Numbers Range].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0202][Happy Number ]/[0202][Happy Number ].iml b/[0202][Happy Number ]/[0202][Happy Number ].iml index c90834f..f080bef 100644 --- a/[0202][Happy Number ]/[0202][Happy Number ].iml +++ b/[0202][Happy Number ]/[0202][Happy Number ].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0203][Remove Linked List Elements]/[0203][Remove Linked List Elements].iml b/[0203][Remove Linked List Elements]/[0203][Remove Linked List Elements].iml index c90834f..f080bef 100644 --- a/[0203][Remove Linked List Elements]/[0203][Remove Linked List Elements].iml +++ b/[0203][Remove Linked List Elements]/[0203][Remove Linked List Elements].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0204][Count Primes]/[0204][Count Primes].iml b/[0204][Count Primes]/[0204][Count Primes].iml index c90834f..f080bef 100644 --- a/[0204][Count Primes]/[0204][Count Primes].iml +++ b/[0204][Count Primes]/[0204][Count Primes].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0205][Isomorphic Strings]/[0205][Isomorphic Strings].iml b/[0205][Isomorphic Strings]/[0205][Isomorphic Strings].iml index c90834f..f080bef 100644 --- a/[0205][Isomorphic Strings]/[0205][Isomorphic Strings].iml +++ b/[0205][Isomorphic Strings]/[0205][Isomorphic Strings].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0206][Reverse Linked List]/[0206][Reverse Linked List].iml b/[0206][Reverse Linked List]/[0206][Reverse Linked List].iml index c90834f..f080bef 100644 --- a/[0206][Reverse Linked List]/[0206][Reverse Linked List].iml +++ b/[0206][Reverse Linked List]/[0206][Reverse Linked List].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0215][Kth Largest Element In An Array]/[0215][Kth Largest Element In An Array].iml b/[0215][Kth Largest Element In An Array]/[0215][Kth Largest Element In An Array].iml index c90834f..f080bef 100644 --- a/[0215][Kth Largest Element In An Array]/[0215][Kth Largest Element In An Array].iml +++ b/[0215][Kth Largest Element In An Array]/[0215][Kth Largest Element In An Array].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0216][Combination Sum III]/[0216][Combination Sum III].iml b/[0216][Combination Sum III]/[0216][Combination Sum III].iml index c90834f..f080bef 100644 --- a/[0216][Combination Sum III]/[0216][Combination Sum III].iml +++ b/[0216][Combination Sum III]/[0216][Combination Sum III].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0217][Contains Duplicate ]/[0217][Contains Duplicate ].iml b/[0217][Contains Duplicate ]/[0217][Contains Duplicate ].iml index c90834f..f080bef 100644 --- a/[0217][Contains Duplicate ]/[0217][Contains Duplicate ].iml +++ b/[0217][Contains Duplicate ]/[0217][Contains Duplicate ].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0219][Contains Duplicate II]/[0219][Contains Duplicate II].iml b/[0219][Contains Duplicate II]/[0219][Contains Duplicate II].iml index c90834f..f080bef 100644 --- a/[0219][Contains Duplicate II]/[0219][Contains Duplicate II].iml +++ b/[0219][Contains Duplicate II]/[0219][Contains Duplicate II].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0223][Rectangle Area]/[0223][Rectangle Area].iml b/[0223][Rectangle Area]/[0223][Rectangle Area].iml index c90834f..f080bef 100644 --- a/[0223][Rectangle Area]/[0223][Rectangle Area].iml +++ b/[0223][Rectangle Area]/[0223][Rectangle Area].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0225][Implement Stack Using Queues]/[0225][Implement Stack Using Queues].iml b/[0225][Implement Stack Using Queues]/[0225][Implement Stack Using Queues].iml index c90834f..f080bef 100644 --- a/[0225][Implement Stack Using Queues]/[0225][Implement Stack Using Queues].iml +++ b/[0225][Implement Stack Using Queues]/[0225][Implement Stack Using Queues].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0226][Invert Binary Tree]/[0226][Invert Binary Tree].iml b/[0226][Invert Binary Tree]/[0226][Invert Binary Tree].iml index c90834f..f080bef 100644 --- a/[0226][Invert Binary Tree]/[0226][Invert Binary Tree].iml +++ b/[0226][Invert Binary Tree]/[0226][Invert Binary Tree].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0231][Power of Two]/[0231][Power of Two].iml b/[0231][Power of Two]/[0231][Power of Two].iml index c90834f..f080bef 100644 --- a/[0231][Power of Two]/[0231][Power of Two].iml +++ b/[0231][Power of Two]/[0231][Power of Two].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0232][Implement Queue using Stacks]/[0232][Implement Queue using Stacks].iml b/[0232][Implement Queue using Stacks]/[0232][Implement Queue using Stacks].iml index c90834f..f080bef 100644 --- a/[0232][Implement Queue using Stacks]/[0232][Implement Queue using Stacks].iml +++ b/[0232][Implement Queue using Stacks]/[0232][Implement Queue using Stacks].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0234][Palindrome Linked List]/[0234][Palindrome Linked List].iml b/[0234][Palindrome Linked List]/[0234][Palindrome Linked List].iml index c90834f..f080bef 100644 --- a/[0234][Palindrome Linked List]/[0234][Palindrome Linked List].iml +++ b/[0234][Palindrome Linked List]/[0234][Palindrome Linked List].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0235][Lowest Common Ancestor of a Binary Search Tree]/[0235][Lowest Common Ancestor of a Binary Search Tree].iml b/[0235][Lowest Common Ancestor of a Binary Search Tree]/[0235][Lowest Common Ancestor of a Binary Search Tree].iml index c90834f..f080bef 100644 --- a/[0235][Lowest Common Ancestor of a Binary Search Tree]/[0235][Lowest Common Ancestor of a Binary Search Tree].iml +++ b/[0235][Lowest Common Ancestor of a Binary Search Tree]/[0235][Lowest Common Ancestor of a Binary Search Tree].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0237][Delete Node in a Linked List]/[0237][Delete Node in a Linked List].iml b/[0237][Delete Node in a Linked List]/[0237][Delete Node in a Linked List].iml index c90834f..f080bef 100644 --- a/[0237][Delete Node in a Linked List]/[0237][Delete Node in a Linked List].iml +++ b/[0237][Delete Node in a Linked List]/[0237][Delete Node in a Linked List].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0242][Valid Anagram]/[0242][Valid Anagram].iml b/[0242][Valid Anagram]/[0242][Valid Anagram].iml index c90834f..f080bef 100644 --- a/[0242][Valid Anagram]/[0242][Valid Anagram].iml +++ b/[0242][Valid Anagram]/[0242][Valid Anagram].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0257][Binary Tree Paths]/[0257][Binary Tree Paths].iml b/[0257][Binary Tree Paths]/[0257][Binary Tree Paths].iml index c90834f..f080bef 100644 --- a/[0257][Binary Tree Paths]/[0257][Binary Tree Paths].iml +++ b/[0257][Binary Tree Paths]/[0257][Binary Tree Paths].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0258][Add Digits]/[0258][Add Digits].iml b/[0258][Add Digits]/[0258][Add Digits].iml index c90834f..f080bef 100644 --- a/[0258][Add Digits]/[0258][Add Digits].iml +++ b/[0258][Add Digits]/[0258][Add Digits].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0263][Ugly Number]/[0263][Ugly Number].iml b/[0263][Ugly Number]/[0263][Ugly Number].iml index c90834f..f080bef 100644 --- a/[0263][Ugly Number]/[0263][Ugly Number].iml +++ b/[0263][Ugly Number]/[0263][Ugly Number].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0268][Missing Number]/[0268][Missing Number].iml b/[0268][Missing Number]/[0268][Missing Number].iml index c90834f..f080bef 100644 --- a/[0268][Missing Number]/[0268][Missing Number].iml +++ b/[0268][Missing Number]/[0268][Missing Number].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0278][First Bad Version]/[0278][First Bad Version].iml b/[0278][First Bad Version]/[0278][First Bad Version].iml index c90834f..f080bef 100644 --- a/[0278][First Bad Version]/[0278][First Bad Version].iml +++ b/[0278][First Bad Version]/[0278][First Bad Version].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0283][Move Zeroes]/[0283][Move Zeroes].iml b/[0283][Move Zeroes]/[0283][Move Zeroes].iml index c90834f..f080bef 100644 --- a/[0283][Move Zeroes]/[0283][Move Zeroes].iml +++ b/[0283][Move Zeroes]/[0283][Move Zeroes].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0290][Word Pattern]/[0290][Word Pattern].iml b/[0290][Word Pattern]/[0290][Word Pattern].iml index c90834f..f080bef 100644 --- a/[0290][Word Pattern]/[0290][Word Pattern].iml +++ b/[0290][Word Pattern]/[0290][Word Pattern].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0303][Range Sum Query - Immutable]/[0303][Range Sum Query - Immutable].iml b/[0303][Range Sum Query - Immutable]/[0303][Range Sum Query - Immutable].iml index c90834f..f080bef 100644 --- a/[0303][Range Sum Query - Immutable]/[0303][Range Sum Query - Immutable].iml +++ b/[0303][Range Sum Query - Immutable]/[0303][Range Sum Query - Immutable].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0326][Power of Three]/[0326][Power of Three].iml b/[0326][Power of Three]/[0326][Power of Three].iml index c90834f..f080bef 100644 --- a/[0326][Power of Three]/[0326][Power of Three].iml +++ b/[0326][Power of Three]/[0326][Power of Three].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0342][Power of Four]/[0342][Power of Four].iml b/[0342][Power of Four]/[0342][Power of Four].iml index c90834f..f080bef 100644 --- a/[0342][Power of Four]/[0342][Power of Four].iml +++ b/[0342][Power of Four]/[0342][Power of Four].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/[0344][Reverse String]/[0344][Reverse String].iml b/[0344][Reverse String]/[0344][Reverse String].iml index c90834f..f080bef 100644 --- a/[0344][Reverse String]/[0344][Reverse String].iml +++ b/[0344][Reverse String]/[0344][Reverse String].iml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/leetcode.iml b/leetcode.iml index 4fd5057..24c525d 100644 --- a/leetcode.iml +++ b/leetcode.iml @@ -8,5 +8,7 @@ + + \ No newline at end of file From 43f28159835e9918e4a4f117355b00b5ecd4d881 Mon Sep 17 00:00:00 2001 From: Wang-Jun-Chao Date: Wed, 26 Jun 2019 06:28:24 +0800 Subject: [PATCH 056/108] commit --- .idea/encodings.xml | 9 + .idea/modules.xml | 1 + .idea/workspace.xml | 704 +++++++++--------- ...[SubstringWithConcatenationOfAllWords].iml | 13 - .../src/Solution.java | 2 +- [0043][Multiply Strings]/src/Solution.java | 2 + .../[0056][MergeIntervals].iml | 13 - .../[0057][InsertInterval].iml | 13 - .../[0091][Decode Ways].iml | 12 +- [0091][Decode Ways]/src/Main.java | 15 + [0091][Decode Ways]/src/Solution.java | 51 ++ [0091][Decode Ways]/src/Solution2.java | 96 +++ .../[0132][Palindrome Partitioning II].iml | 2 + .../src/Solution2.java | 1 - [0139][Word Break]/[0139][Word Break].iml | 10 + [0139][Word Break]/[0139][WordBreak].iml | 13 - [0139][Word Break]/src/Main.java | 29 +- 17 files changed, 573 insertions(+), 413 deletions(-) delete mode 100644 [0030][Substring With Concatenation Of All Words]/[0030][SubstringWithConcatenationOfAllWords].iml delete mode 100644 [0056][Merge Intervals]/[0056][MergeIntervals].iml delete mode 100644 [0057][Insert Interval]/[0057][InsertInterval].iml rename [0009][Palindrome Number]/[0009][PalindromeNumber].iml => [0091][Decode Ways]/[0091][Decode Ways].iml (53%) create mode 100644 [0091][Decode Ways]/src/Main.java create mode 100644 [0091][Decode Ways]/src/Solution.java create mode 100644 [0091][Decode Ways]/src/Solution2.java delete mode 100644 [0139][Word Break]/[0139][WordBreak].iml diff --git a/.idea/encodings.xml b/.idea/encodings.xml index f46d2fe..d8dd417 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -7,6 +7,7 @@ + @@ -38,6 +39,7 @@ + @@ -46,11 +48,16 @@ + + + + + @@ -98,6 +105,8 @@ + + diff --git a/.idea/modules.xml b/.idea/modules.xml index 23df9b4..8772525 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -88,6 +88,7 @@ + diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 2b89e88..184ee67 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,192 +2,23 @@ - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -203,90 +34,91 @@ - + - - + + - + - - - - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - - + + - - + + - - - + + + + + + + - + - - + + @@ -333,12 +165,6 @@ @@ -395,10 +227,10 @@ - @@ -408,7 +240,6 @@ - @@ -417,6 +248,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -428,6 +303,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -451,10 +370,22 @@ + + + + + + + + + + + - @@ -509,13 +605,7 @@ - - - 1538119680847 - 1538119785733 @@ -853,7 +943,14 @@ - @@ -889,13 +986,13 @@ - - + @@ -1080,21 +1177,6 @@ - - - - - - - - - - - - - - - @@ -1203,13 +1285,6 @@ - - - - - - - @@ -1304,73 +1379,143 @@ - + - - + + - + - - + + - + - - + + - + - + - + - - + + - + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - + + - + - - + + - + - - + + + + + + + + + + + + + + + + + + + + + + + diff --git a/[0001][Two Sum]/src/Solution.java b/[0001][Two Sum]/src/Solution.java index 01bd269..5380a2f 100644 --- a/[0001][Two Sum]/src/Solution.java +++ b/[0001][Two Sum]/src/Solution.java @@ -41,7 +41,7 @@ public class Solution { public int[] twoSum(int[] nums, int target) { int[] result = {0, 0}; - // 因为无素可能会重复 + // 因为无素可能会重复,用于记录元素出现的下标 Map> map = new HashMap<>(nums.length); for (int i = 0; i < nums.length; i++) { diff --git a/[0002][Add Two Numbers]/src/Solution.java b/[0002][Add Two Numbers]/src/Solution.java index 8839d26..f785707 100644 --- a/[0002][Add Two Numbers]/src/Solution.java +++ b/[0002][Add Two Numbers]/src/Solution.java @@ -71,7 +71,7 @@ public ListNode addTwoNumbers(ListNode l1, ListNode l2) { // һӻнλ if (carry == 1) { // ʼʱr.nextǵһҪӵĽ - while (r.next != null) { + while (r.next != null && carry != 0) { sum = r.next.val + carry; r.next.val = sum % 10; carry = sum / 10; diff --git a/[0004][Median of Two Sorted Arrays]/src/Solution.java b/[0004][Median of Two Sorted Arrays]/src/Solution.java index 4303371..9547a99 100644 --- a/[0004][Median of Two Sorted Arrays]/src/Solution.java +++ b/[0004][Median of Two Sorted Arrays]/src/Solution.java @@ -36,12 +36,13 @@ public double findMedianSortedArrays(int[] nums1, int[] nums2) { /** * ҵkԪأk=1, 2, 3, ... * - * @param nums1 - * @param nums2 - * @param k + * @param nums1 1 + * @param start1 ʼλ1 + * @param nums2 2 + * @param start2 ʼλ2 + * @param k Ҫҵλλ * @return - **/ - + */ public int findKth(int[] nums1, final int start1, int[] nums2, final int start2, final int k) { @@ -50,6 +51,7 @@ public int findKth(int[] nums1, final int start1, return findKth(nums2, start2, nums1, start1, k); } + // ԪصѾﵽĩβ if (nums1.length == start1) { return nums2[start2 + k - 1]; } @@ -72,7 +74,7 @@ public int findKth(int[] nums1, final int start1, // ˵nums1[start, ..., ia-1]ˣҪҵֵnums1[ia, ..., nums1.length] // nums2[start, ..., ib-1, ib, ..., nums2.length] if (nums1[ia - 1] < nums2[ib - 1]) { - // k - (ia - start1) = k - (half + start1 - start1)=k - half + // k - (ia - start1) = k - (half + start1 - start1) = k - half return findKth(nums1, ia, nums2, start2, k - (ia - start1)); } diff --git a/[0006][Zig Zag Conversion]/.idea/[0006][Zig Zag Conversion].iml b/[0006][Zig Zag Conversion]/.idea/[0006][Zig Zag Conversion].iml deleted file mode 100644 index f72f179..0000000 --- a/[0006][Zig Zag Conversion]/.idea/[0006][Zig Zag Conversion].iml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/[0006][Zig Zag Conversion]/.idea/inspectionProfiles/Project_Default.xml b/[0006][Zig Zag Conversion]/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 8d66637..0000000 --- a/[0006][Zig Zag Conversion]/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/[0006][Zig Zag Conversion]/.idea/libraries/R_User_Library.xml b/[0006][Zig Zag Conversion]/.idea/libraries/R_User_Library.xml deleted file mode 100644 index 2778a36..0000000 --- a/[0006][Zig Zag Conversion]/.idea/libraries/R_User_Library.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/[0006][Zig Zag Conversion]/.idea/misc.xml b/[0006][Zig Zag Conversion]/.idea/misc.xml deleted file mode 100644 index 4dab169..0000000 --- a/[0006][Zig Zag Conversion]/.idea/misc.xml +++ /dev/null @@ -1,81 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/[0006][Zig Zag Conversion]/.idea/modules.xml b/[0006][Zig Zag Conversion]/.idea/modules.xml deleted file mode 100644 index d5aff09..0000000 --- a/[0006][Zig Zag Conversion]/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/[0006][Zig Zag Conversion]/.idea/vcs.xml b/[0006][Zig Zag Conversion]/.idea/vcs.xml deleted file mode 100644 index 6c0b863..0000000 --- a/[0006][Zig Zag Conversion]/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/[0006][Zig Zag Conversion]/.idea/workspace.xml b/[0006][Zig Zag Conversion]/.idea/workspace.xml deleted file mode 100644 index d3f4c80..0000000 --- a/[0006][Zig Zag Conversion]/.idea/workspace.xml +++ /dev/null @@ -1,215 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -437,9 +408,9 @@ - - - + + + - + + - @@ -541,21 +512,7 @@ - - - - 1538120564970 - - - 1538120774833 - 1538121073398 @@ -886,49 +843,63 @@ - - + - - + + - - + + - + - - + + - - + + - - + + - - + + - - + + - + - - + - + @@ -937,7 +908,7 @@ - + @@ -1076,15 +1047,45 @@ file://$PROJECT_DIR$/[0173][Binary Search Tree Iterator]/src/Solution.java - 45 + 25 - file://$PROJECT_DIR$/[0173][Binary Search Tree Iterator]/src/Solution.java - 25 + 17 - + + file://$PROJECT_DIR$/[0173][Binary Search Tree Iterator]/src/Solution.java + 18 + + + + file://$PROJECT_DIR$/[0173][Binary Search Tree Iterator]/src/Solution.java + 20 + + + + file://$PROJECT_DIR$/[0173][Binary Search Tree Iterator]/src/Solution.java + 22 + + + + file://$PROJECT_DIR$/[0173][Binary Search Tree Iterator]/src/Solution.java + 24 + + + + file://$PROJECT_DIR$/[0173][Binary Search Tree Iterator]/src/Solution.java + 41 + + file://$PROJECT_DIR$/[081][Search In Rotated Sorted Array II]/src/Solution2.java @@ -1152,30 +1153,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -1522,23 +1499,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - - + + - + + + + + + + + + + + + - - + + diff --git a/[0387][First Unique Character in a String]/[0387][First Unique Character in a String].iml b/[0387][First Unique Character in a String]/[0387][First Unique Character in a String].iml new file mode 100644 index 0000000..bb6b39c --- /dev/null +++ b/[0387][First Unique Character in a String]/[0387][First Unique Character in a String].iml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0387][First Unique Character in a String]/src/Main.java b/[0387][First Unique Character in a String]/src/Main.java new file mode 100644 index 0000000..4c695a9 --- /dev/null +++ b/[0387][First Unique Character in a String]/src/Main.java @@ -0,0 +1,20 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-30 13:50 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + Assert.assertEquals(0, solution.firstUniqChar("leetcode")); + } + + @Test + public void test2() { + Solution solution = new Solution(); + Assert.assertEquals(2, solution.firstUniqChar("loveleetcode")); + } +} diff --git a/[0387][First Unique Character in a String]/src/Solution.java b/[0387][First Unique Character in a String]/src/Solution.java new file mode 100644 index 0000000..349a460 --- /dev/null +++ b/[0387][First Unique Character in a String]/src/Solution.java @@ -0,0 +1,58 @@ +import java.util.HashMap; +import java.util.Map; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-30 13:43 + **/ +public class Solution { + + /** + *
+     * Given a string, find the first non-repeating character in it and return it's index.
+     * If it doesn't exist, return -1.
+     *
+     * Examples:
+     *
+     * s = "leetcode"
+     * return 0.
+     *
+     * s = "loveleetcode",
+     * return 2.
+     * 
+ * @param s + * @return + */ + public int firstUniqChar(String s) { + if (s == null || s.length() < 1) { + return -1; + } + + + Map map = new HashMap<>(s.length()); + + for (int i = 0; i < s.length(); i++) { + // 标记字符已经重复 + if (map.containsKey(s.charAt(i))) { + map.put(s.charAt(i), -1); + } else { + // 记录位置 + map.put(s.charAt(i), i); + } + } + + Integer result = null; + + for(Integer n: map.values()) { + if (n >= 0) { + if (result == null) { + result = n; + } else { + result = Math.min(n, result); + } + } + } + + return result == null ? -1 : result; + } +} From 632abd818759ea785389252f1102892d3040c747 Mon Sep 17 00:00:00 2001 From: Wang-Jun-Chao Date: Sun, 30 Jun 2019 14:10:43 +0800 Subject: [PATCH 066/108] commit --- .idea/modules.xml | 2 + .idea/workspace.xml | 246 +++++++++++------- .../[0389][Find the Difference].iml | 21 ++ [0389][Find the Difference]/src/Main.java | 25 ++ [0389][Find the Difference]/src/Solution.java | 53 ++++ .../[0404][Sum of Left Leaves].iml | 11 + 6 files changed, 257 insertions(+), 101 deletions(-) create mode 100644 [0389][Find the Difference]/[0389][Find the Difference].iml create mode 100644 [0389][Find the Difference]/src/Main.java create mode 100644 [0389][Find the Difference]/src/Solution.java create mode 100644 [0404][Sum of Left Leaves]/[0404][Sum of Left Leaves].iml diff --git a/.idea/modules.xml b/.idea/modules.xml index 78ea9e2..5df98f9 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -190,6 +190,8 @@ + +
diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 35d9848..d3afaa9 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,8 +2,9 @@ - - + + + @@ -43,47 +44,57 @@ - + - - + + + + + + + - + - - + + + + + - - - - - - + - - + + - - - + + + + + + + + + + - - + + @@ -185,9 +196,6 @@ @@ -247,8 +258,8 @@ - @@ -364,6 +375,17 @@ + + + + + + + + + + + @@ -430,7 +438,7 @@ - + - - + + - - + + - - + + - - + + - - - + + + + + + - - - @@ -533,14 +542,7 @@ - - - - 1538121487647 - 1538124828037 @@ -878,19 +880,17 @@ - - - - - - - - - - @@ -912,14 +912,24 @@ + + + + + + + + + - - + + - + @@ -928,7 +938,7 @@ - + @@ -1107,24 +1117,6 @@ - - - - - - - - - - - - - - - - - - - - - @@ -1499,13 +1470,6 @@ - - - - - - - @@ -1532,8 +1496,8 @@
- - + + @@ -1595,8 +1559,35 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/[0404][Sum of Left Leaves]/[0404][Sum of Left Leaves].iml b/[0404][Sum of Left Leaves]/[0404][Sum of Left Leaves].iml index c90834f..bb6b39c 100644 --- a/[0404][Sum of Left Leaves]/[0404][Sum of Left Leaves].iml +++ b/[0404][Sum of Left Leaves]/[0404][Sum of Left Leaves].iml @@ -7,5 +7,15 @@ + + + + + + + + + +
\ No newline at end of file diff --git a/[0404][Sum of Left Leaves]/src/Main.java b/[0404][Sum of Left Leaves]/src/Main.java new file mode 100644 index 0000000..b80e566 --- /dev/null +++ b/[0404][Sum of Left Leaves]/src/Main.java @@ -0,0 +1,28 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-30 14:18 + **/ +public class Main { + @Test + public void test1() { + TreeNode root = new TreeNode(3); + root.left =new TreeNode(9); + root.right = new TreeNode(20); + root.right.left = new TreeNode(15); + root.right.right = new TreeNode(7); + + Solution solution = new Solution(); + Assert.assertEquals(24, solution.sumOfLeftLeaves(root)); + } + + @Test + public void test2() { + TreeNode root = new TreeNode(1); + + Solution solution = new Solution(); + Assert.assertEquals(0, solution.sumOfLeftLeaves(root)); + } +} diff --git a/[0404][Sum of Left Leaves]/src/Solution.java b/[0404][Sum of Left Leaves]/src/Solution.java new file mode 100644 index 0000000..fb3f2d6 --- /dev/null +++ b/[0404][Sum of Left Leaves]/src/Solution.java @@ -0,0 +1,50 @@ + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-06-30 14:11 + **/ +public class Solution { + /** + *
+     * Find the sum of all left leaves in a given binary tree.
+     *
+     * Example:
+     *
+     *     3
+     *    / \
+     *   9  20
+     *     /  \
+     *    15   7
+     *
+     * There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24.
+     * 
+ * + * @param root + * @return + */ + public int sumOfLeftLeaves(TreeNode root) { + int[] result = new int[1]; + sumOfLeftLeaves(root, false, result); + return result[0]; + } + + /** + * 计算所有左叶子的和 + * @param root + * @param result + */ + private void sumOfLeftLeaves(TreeNode root, boolean isLeftLeaf, int[] result) { + + if (root == null) { + return; + } + + if (root.left == null && root.right==null && isLeftLeaf) { + result[0] += root.val; + return; + } + + sumOfLeftLeaves(root.left, true, result); + sumOfLeftLeaves(root.right, false, result); + } +} diff --git a/[0404][Sum of Left Leaves]/src/TreeNode.java b/[0404][Sum of Left Leaves]/src/TreeNode.java new file mode 100644 index 0000000..9aec4dd --- /dev/null +++ b/[0404][Sum of Left Leaves]/src/TreeNode.java @@ -0,0 +1,15 @@ +/** + * Author: + * Date: 2015-08-19 + * Time: 06:45 + * Declaration: All Rights Reserved !!! + */ +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} From e1e62aa73cea7f3049b0c784eb5d2ea6727d361d Mon Sep 17 00:00:00 2001 From: Wang-Jun-Chao Date: Mon, 1 Jul 2019 22:03:48 +0800 Subject: [PATCH 068/108] commit --- .idea/encodings.xml | 1 + .idea/modules.xml | 4 + .idea/workspace.xml | 763 ++++++++---------- [0000][common]/[0000][common].iml | 10 + [0000][common]/src/WithException.java | 28 + .../src/Solution.java | 3 +- .../[0095][Unique Binary Search Trees II].iml | 2 + .../[0173][Binary Search Tree Iterator].iml | 2 + .../[0230][Kth Smallest Element in a BST].iml | 21 + .../src/Main.java | 21 + .../src/Solution.java | 37 + .../src/TreeNode.java | 15 + .../[0238][Product of Array Except Self].iml | 10 + .../src/Main.java | 26 + .../src/Solution.java | 70 ++ .../[0349][Intersection of Two Arrays].iml | 2 + .../[0350][Intersection of Two Arrays II].iml | 2 + .../[0367][Valid Perfect Square].iml | 2 + .../[0374][Guess Number Higher or Lower].iml | 2 + [0383][Ransom Note]/[0383][Ransom Note].iml | 2 + ...7][First Unique Character in a String].iml | 2 + .../[0389][Find the Difference].iml | 2 + [0401][Binary Watch]/[0401][Binary Watch].iml | 21 + [0401][Binary Watch]/src/Main.java | 20 + [0401][Binary Watch]/src/Solution.java | 63 ++ .../[0404][Sum of Left Leaves].iml | 2 + ...429][N-ary Tree Level Order Traversal].iml | 21 + .../src/Main.java | 48 ++ .../src/Node.java | 18 + .../src/Solution.java | 37 + 30 files changed, 850 insertions(+), 407 deletions(-) create mode 100644 [0000][common]/src/WithException.java create mode 100644 [0230][Kth Smallest Element in a BST]/[0230][Kth Smallest Element in a BST].iml create mode 100644 [0230][Kth Smallest Element in a BST]/src/Main.java create mode 100644 [0230][Kth Smallest Element in a BST]/src/Solution.java create mode 100644 [0230][Kth Smallest Element in a BST]/src/TreeNode.java rename [0226][Invert Binary Tree]/[0226][InvertBinaryTree ].iml => [0238][Product of Array Except Self]/[0238][Product of Array Except Self].iml (60%) create mode 100644 [0238][Product of Array Except Self]/src/Main.java create mode 100644 [0238][Product of Array Except Self]/src/Solution.java create mode 100644 [0401][Binary Watch]/[0401][Binary Watch].iml create mode 100644 [0401][Binary Watch]/src/Main.java create mode 100644 [0401][Binary Watch]/src/Solution.java create mode 100644 [0429][N-ary Tree Level Order Traversal]/[0429][N-ary Tree Level Order Traversal].iml create mode 100644 [0429][N-ary Tree Level Order Traversal]/src/Main.java create mode 100644 [0429][N-ary Tree Level Order Traversal]/src/Node.java create mode 100644 [0429][N-ary Tree Level Order Traversal]/src/Solution.java diff --git a/.idea/encodings.xml b/.idea/encodings.xml index ba98a4c..2e0845e 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -129,6 +129,7 @@ + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index 5df98f9..c18c369 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -166,11 +166,13 @@ + + @@ -191,7 +193,9 @@ + + diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 9dfd052..9afd951 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,11 +2,35 @@ - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -26,13 +50,10 @@ - + - - - - - + + @@ -45,24 +66,23 @@ - + - - + + - - - + + - + - - + + @@ -71,43 +91,42 @@ - + + + + + + - - - - - + + - + - - + + - - + + - - + + - - + + - - - - - + + @@ -122,15 +141,15 @@ - + - + - - + + @@ -138,19 +157,6 @@ - - - - - - - - - - - - - @@ -193,18 +199,6 @@ @@ -255,8 +261,8 @@ - @@ -268,8 +274,6 @@ - - @@ -280,41 +284,12 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + @@ -331,73 +306,47 @@ - + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - @@ -368,14 +351,15 @@ - - + + - - + + + @@ -390,16 +374,18 @@ - - - - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - - + @@ -889,7 +875,7 @@ - + @@ -1086,6 +1072,18 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1450,9 +1322,7 @@ - - - + @@ -1463,13 +1333,6 @@ - - - - - - - @@ -1521,24 +1384,169 @@ - + - + - + + + + + + + + - + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1595,7 +1603,7 @@ - [0230][Kth Smallest Element in a BST] + [0414][Third Maximum Number]
+ + \ No newline at end of file diff --git a/[0384][Shuffle an Array]/[0384][Shuffle an Array].iml b/[0384][Shuffle an Array]/[0384][Shuffle an Array].iml new file mode 100644 index 0000000..c8cb479 --- /dev/null +++ b/[0384][Shuffle an Array]/[0384][Shuffle an Array].iml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0384][Shuffle an Array]/src/Main.java b/[0384][Shuffle an Array]/src/Main.java new file mode 100644 index 0000000..b5a927d --- /dev/null +++ b/[0384][Shuffle an Array]/src/Main.java @@ -0,0 +1,40 @@ +import org.junit.Assert; +import org.junit.Test; + +import java.util.Arrays; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-02 15:56 + **/ +public class Main { + @Test + public void test1() { + int[] nums = {1, 2, 3}; + Solution solution = new Solution(nums); + + int[] shuffle = solution.shuffle(); + System.out.println(Arrays.toString(shuffle)); + + int[] reset = solution.reset(); + Assert.assertArrayEquals(nums, reset); + + shuffle = solution.shuffle(); + System.out.println(Arrays.toString(shuffle)); + } + + @Test + public void test2() { + int[] nums = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; + Solution solution = new Solution(nums); + + int[] shuffle = solution.shuffle(); + System.out.println(Arrays.toString(shuffle)); + + int[] reset = solution.reset(); + Assert.assertArrayEquals(nums, reset); + + shuffle = solution.shuffle(); + System.out.println(Arrays.toString(shuffle)); + } +} diff --git a/[0384][Shuffle an Array]/src/Solution.java b/[0384][Shuffle an Array]/src/Solution.java new file mode 100644 index 0000000..2f16e89 --- /dev/null +++ b/[0384][Shuffle an Array]/src/Solution.java @@ -0,0 +1,61 @@ +import java.util.Arrays; +import java.util.Random; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-02 15:51 + **/ +public class Solution { + + private int[] original; + + /** + *
+     * // Init an array with set 1, 2, and 3.
+     * int[] nums = {1,2,3};
+     * Solution solution = new Solution(nums);
+     *
+     * // Shuffle the array [1,2,3] and return its result. Any permutation of [1,2,3]
+     * must equally likely to be returned.
+     * solution.shuffle();
+     *
+     * // Resets the array back to its original configuration [1,2,3].
+     * solution.reset();
+     *
+     * // Returns the random shuffling of array [1,2,3].
+     * solution.shuffle();
+     * 
+ * + * @param nums + */ + public Solution(int[] nums) { + original = nums; + } + + /** + * Resets the array to its original configuration and return it. + */ + public int[] reset() { + return Arrays.copyOf(original, original.length); + } + + /** + * Returns a random shuffling of the array. + */ + public int[] shuffle() { + int[] copy = Arrays.copyOf(original, original.length); + + Random random = new Random(); + for (int i = 0; i < copy.length - 1; i++) { + swap(copy, i, i + random.nextInt(copy.length - i)); + } + + return copy; + } + + private void swap(int[] copy, int i, int j) { + int t = copy[i]; + copy[i] = copy[j]; + copy[j] = t; + } +} diff --git a/[0401][Binary Watch]/[0401][Binary Watch].iml b/[0401][Binary Watch]/[0401][Binary Watch].iml index bb6b39c..c8cb479 100644 --- a/[0401][Binary Watch]/[0401][Binary Watch].iml +++ b/[0401][Binary Watch]/[0401][Binary Watch].iml @@ -17,5 +17,7 @@
+ + \ No newline at end of file diff --git a/[0414][Third Maximum Number]/[0414][Third Maximum Number].iml b/[0414][Third Maximum Number]/[0414][Third Maximum Number].iml new file mode 100644 index 0000000..c8cb479 --- /dev/null +++ b/[0414][Third Maximum Number]/[0414][Third Maximum Number].iml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0414][Third Maximum Number]/src/Main.java b/[0414][Third Maximum Number]/src/Main.java new file mode 100644 index 0000000..ee6c47b --- /dev/null +++ b/[0414][Third Maximum Number]/src/Main.java @@ -0,0 +1,36 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-02 08:18 + **/ +public class Main { + @Test + public void test1() { + int[] arr = {3, 2, 1}; + Solution solution = new Solution(); + Assert.assertEquals(1, solution.thirdMax(arr)); + } + + @Test + public void test2() { + int[] arr = {2, 1}; + Solution solution = new Solution(); + Assert.assertEquals(2, solution.thirdMax(arr)); + } + + @Test + public void test3() { + int[] arr = {2, 3, 2, 1}; + Solution solution = new Solution(); + Assert.assertEquals(1, solution.thirdMax(arr)); + } + + @Test + public void test4() { + int[] arr = {1, 2, 2, 5, 3, 5}; + Solution solution = new Solution(); + Assert.assertEquals(2, solution.thirdMax(arr)); + } +} diff --git a/[0414][Third Maximum Number]/src/Solution.java b/[0414][Third Maximum Number]/src/Solution.java new file mode 100644 index 0000000..e64ea97 --- /dev/null +++ b/[0414][Third Maximum Number]/src/Solution.java @@ -0,0 +1,56 @@ +import java.util.SortedSet; +import java.util.TreeSet; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-02 08:09 + **/ +public class Solution { + /** + *
+     * Given a non-empty array of integers, return the third maximum number in this array.
+     * If it does not exist, return the maximum number. The time complexity must be in O(n).
+     *
+     * Example 1:
+     * Input: [3, 2, 1]
+     *
+     * Output: 1
+     *
+     * Explanation: The third maximum is 1.
+     * Example 2:
+     * Input: [1, 2]
+     *
+     * Output: 2
+     *
+     * Explanation: The third maximum does not exist, so the maximum (2) is returned instead.
+     * Example 3:
+     * Input: [2, 2, 3, 1]
+     *
+     * Output: 1
+     *
+     * Explanation: Note that the third maximum here means the third maximum distinct number.
+     * Both numbers with value 2 are both considered as second maximum.
+     * 
+ * + * @param nums + * @return + */ + public int thirdMax(int[] nums) { + SortedSet result = new TreeSet<>(); + + for (int i : nums) { + addResult(i, result); + } + + return result.size() == 3 ? result.first() : result.last(); + } + + private void addResult(int i, SortedSet result) { + if (result.size() < 3) { + result.add(i); + } else if (result.size() == 3 && result.first() < i && !result.contains(i)) { + result.remove(result.first()); + result.add(i); + } + } +} diff --git a/[0429][N-ary Tree Level Order Traversal]/[0429][N-ary Tree Level Order Traversal].iml b/[0429][N-ary Tree Level Order Traversal]/[0429][N-ary Tree Level Order Traversal].iml index bb6b39c..c8cb479 100644 --- a/[0429][N-ary Tree Level Order Traversal]/[0429][N-ary Tree Level Order Traversal].iml +++ b/[0429][N-ary Tree Level Order Traversal]/[0429][N-ary Tree Level Order Traversal].iml @@ -17,5 +17,7 @@
+ + \ No newline at end of file diff --git a/[0448][Find All Numbers Disappeared in an Array]/[0448][Find All Numbers Disappeared in an Array].iml b/[0448][Find All Numbers Disappeared in an Array]/[0448][Find All Numbers Disappeared in an Array].iml new file mode 100644 index 0000000..c8cb479 --- /dev/null +++ b/[0448][Find All Numbers Disappeared in an Array]/[0448][Find All Numbers Disappeared in an Array].iml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0448][Find All Numbers Disappeared in an Array]/src/Main.java b/[0448][Find All Numbers Disappeared in an Array]/src/Main.java new file mode 100644 index 0000000..bf39e15 --- /dev/null +++ b/[0448][Find All Numbers Disappeared in an Array]/src/Main.java @@ -0,0 +1,14 @@ +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-02 08:38 + **/ +public class Main { + @Test + public void test1() { + int[] arr = {4, 3, 2, 7, 8, 2, 3, 1}; + Solution solution = new Solution(); + System.out.println(solution.findDisappearedNumbers(arr)); + } +} diff --git a/[0448][Find All Numbers Disappeared in an Array]/src/Solution.java b/[0448][Find All Numbers Disappeared in an Array]/src/Solution.java new file mode 100644 index 0000000..b85015a --- /dev/null +++ b/[0448][Find All Numbers Disappeared in an Array]/src/Solution.java @@ -0,0 +1,57 @@ +import java.util.ArrayList; +import java.util.List; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-02 08:29 + **/ +public class Solution { + /** + *
+     * Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear
+     * twice and others appear once.
+     *
+     * Find all the elements of [1, n] inclusive that do not appear in this array.
+     *
+     * Could you do it without extra space and in O(n) runtime? You may assume the returned list
+     * does not count as extra space.
+     *
+     * Example:
+     *
+     * Input:
+     * [4,3,2,7,8,2,3,1]
+     *
+     * Output:
+     * [5,6]
+     * 
+ * + * @param nums + * @return + */ + public List findDisappearedNumbers(int[] nums) { + + // i表示第几个元素,从1开始计数 + for (int i = 1; i <= nums.length; i++) { + // nums[idx - 1] != idx 对于nums[8] = 9的情况 + // nums[idx - 1] == nums[nums[idx - 1] - 1] 位置被占用了,表示有相同的数 + while (nums[i - 1] != i && nums[i - 1] != nums[nums[i - 1] - 1]) { + swap(nums, i - 1, nums[i - 1] - 1); + } + } + + List result = new ArrayList<>(); + for (int i = 1; i <= nums.length; i++) { + if (nums[i - 1] != i) { + result.add(i); + } + } + + return result; + } + + private void swap(int[] nums, int x, int y) { + int tmp = nums[x]; + nums[x] = nums[y]; + nums[y] = tmp; + } +} diff --git a/[0461][Hamming Distance]/[0461][Hamming Distance].iml b/[0461][Hamming Distance]/[0461][Hamming Distance].iml new file mode 100644 index 0000000..c8cb479 --- /dev/null +++ b/[0461][Hamming Distance]/[0461][Hamming Distance].iml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0461][Hamming Distance]/src/Main.java b/[0461][Hamming Distance]/src/Main.java new file mode 100644 index 0000000..9504141 --- /dev/null +++ b/[0461][Hamming Distance]/src/Main.java @@ -0,0 +1,14 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-02 09:29 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + Assert.assertEquals(2, solution.hammingDistance(4, 1)); + } +} diff --git a/[0461][Hamming Distance]/src/Solution.java b/[0461][Hamming Distance]/src/Solution.java new file mode 100644 index 0000000..78490f0 --- /dev/null +++ b/[0461][Hamming Distance]/src/Solution.java @@ -0,0 +1,55 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-02 09:25 + **/ +public class Solution { + /** + *
+     * The Hamming distance between two integers is the number of positions at which
+     * the corresponding bits are different.
+     *
+     * Given two integers x and y, calculate the Hamming distance.
+     *
+     * Note:
+     * 0 ≤ x, y < 231.
+     *
+     * Example:
+     *
+     * Input: x = 1, y = 4
+     *
+     * Output: 2
+     *
+     * Explanation:
+     * 1   (0 0 0 1)
+     * 4   (0 1 0 0)
+     *        ↑   ↑
+     *
+     * The above arrows point to positions where the corresponding bits are different.
+     * 
+ * @param x + * @param y + * @return + */ + public int hammingDistance(int x, int y) { + int result = 0; + while (x > 0 && y > 0) { + int xLeft = x % 2; + int yLeft = y % 2; + x /= 2; + y /= 2; + + result += xLeft ^ yLeft; + } + + if (y > 0) { + x = y; + } + + while (x > 0) { + result += x % 2; + x /= 2; + } + + return result; + } +} diff --git a/[0463][Island Perimeter]/[0463][Island Perimeter].iml b/[0463][Island Perimeter]/[0463][Island Perimeter].iml new file mode 100644 index 0000000..c8cb479 --- /dev/null +++ b/[0463][Island Perimeter]/[0463][Island Perimeter].iml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0463][Island Perimeter]/src/Main.java b/[0463][Island Perimeter]/src/Main.java new file mode 100644 index 0000000..9b79f56 --- /dev/null +++ b/[0463][Island Perimeter]/src/Main.java @@ -0,0 +1,30 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-02 13:07 + **/ +public class Main { + @Test + public void test1() { + int[][] grid = { + {0, 1, 0, 0}, + {1, 1, 1, 0}, + {0, 1, 0, 0}, + {1, 1, 0, 0}}; + Solution solution = new Solution(); + Assert.assertEquals(16, solution.islandPerimeter(grid)); + } + + @Test + public void test2() { + int[][] grid = { + {1, 1, 1, 1}, + {1, 1, 1, 1}, + {1, 1, 1, 1}, + {1, 1, 1, 1}}; + Solution solution = new Solution(); + Assert.assertEquals(16, solution.islandPerimeter(grid)); + } +} diff --git a/[0463][Island Perimeter]/src/Solution.java b/[0463][Island Perimeter]/src/Solution.java new file mode 100644 index 0000000..c17b74f --- /dev/null +++ b/[0463][Island Perimeter]/src/Solution.java @@ -0,0 +1,86 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-02 12:58 + **/ +public class Solution { + + /** + *
+     * You are given a map in form of a two-dimensional integer grid where 1 represents
+     * land and 0 represents water.
+     *
+     * Grid cells are connected horizontally/vertically (not diagonally). The grid is
+     * completely surrounded by water, and there is exactly one island (i.e., one or more
+     * connected land cells).
+     *
+     * The island doesn't have "lakes" (water inside that isn't connected to the water around
+     * the island). One cell is a square with side length 1. The grid is rectangular, width
+     * and height don't exceed 100. Determine the perimeter of the island.
+     *
+     * Example:
+     *
+     * Input:
+     * [[0,1,0,0],
+     *  [1,1,1,0],
+     *  [0,1,0,0],
+     *  [1,1,0,0]]
+     *
+     * Output: 16
+     *
+     * Explanation: The perimeter is the 16 yellow stripes in the image below:
+     * 
+ * + * @param grid + * @return + */ + public int islandPerimeter(int[][] grid) { + + // 假定输入都是合法的 + + int perimeter = 0; + + for (int i = 0; i < grid.length; i++) { + for (int j = 0; j < grid[0].length; j++) { + if (grid[i][j] == 0) { + // 上一格 + if (i > 0 && grid[i - 1][j] == 1) { + perimeter++; + } + + // 下一格 + if (i + 1 < grid.length && grid[i + 1][j] == 1) { + perimeter++; + } + + // 左一格 + if (j > 0 && grid[i][j - 1] == 1) { + perimeter++; + } + + // 右一格 + if (j + 1 < grid[0].length && grid[i][j + 1] == 1) { + perimeter++; + } + } + } + } + + // 如果在第一列和最后一列,第一行和最后一行有一,要再加上1出现的数次数 + + for (int i = 0; i < grid.length; i++) { + // 第一列有一 + perimeter += grid[i][0]; + // 最后一列有一 + perimeter += grid[i][grid[0].length - 1]; + } + + for (int i = 0; i < grid[0].length; i++) { + // 第一行有一 + perimeter += grid[0][i]; + // 最后一行有一 + perimeter += grid[grid.length - 1][i]; + } + + return perimeter; + } +} diff --git a/[0463][Island Perimeter]/src/Solution2.java b/[0463][Island Perimeter]/src/Solution2.java new file mode 100644 index 0000000..498b571 --- /dev/null +++ b/[0463][Island Perimeter]/src/Solution2.java @@ -0,0 +1,95 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-02 12:58 + **/ +public class Solution2 { + + /** + *
+     * You are given a map in form of a two-dimensional integer grid where 1 represents
+     * land and 0 represents water.
+     *
+     * Grid cells are connected horizontally/vertically (not diagonally). The grid is
+     * completely surrounded by water, and there is exactly one island (i.e., one or more
+     * connected land cells).
+     *
+     * The island doesn't have "lakes" (water inside that isn't connected to the water around
+     * the island). One cell is a square with side length 1. The grid is rectangular, width
+     * and height don't exceed 100. Determine the perimeter of the island.
+     *
+     * Example:
+     *
+     * Input:
+     * [[0,1,0,0],
+     *  [1,1,1,0],
+     *  [0,1,0,0],
+     *  [1,1,0,0]]
+     *
+     * Output: 16
+     *
+     * Explanation: The perimeter is the 16 yellow stripes in the image below:
+     * 
+ * @param grid + * @return + */ + public int islandPerimeter(int[][] grid) { + + // 假定输入都是合法的 + + int perimeter = 0; + + for (int i = 0; i < grid.length; i++) { + for (int j = 0; j < grid[0].length; j++) { + if (grid[i][j] == 0) { + // 上一格 + if (i > 0 && grid[i - 1][j] == 1) { + perimeter++; + } + + // 下一格 + if (i + 1 < grid.length && grid[i + 1][j] == 1) { + perimeter++; + } + + // 左一格 + if (j > 0 && grid[i][j - 1] == 1) { + perimeter++; + } + + // 右一格 + if (j + 1 < grid[0].length && grid[i][j + 1] == 1) { + perimeter++; + } + } + } + } + + // 如果在第一列和最后一列,第一行和最后一行有一,要再加上1出现的数次数 + + for (int i = 0; i < grid.length; i++) { + // 第一列有一 + if (grid[i][0] == 1) { + perimeter++; + } + + // 最后一列有一 + if (grid[i][grid[0].length - 1] == 1) { + perimeter++; + } + } + + for (int i = 0; i < grid[0].length; i++) { + // 第一行有一 + if (grid[0][i] == 1) { + perimeter++; + } + + // 最后一行有一 + if (grid[grid.length - 1][i] == 1) { + perimeter++; + } + } + + return perimeter; + } +} diff --git a/[0463][Island Perimeter]/src/island.png b/[0463][Island Perimeter]/src/island.png new file mode 100644 index 0000000000000000000000000000000000000000..76254a72468d5f2a5c04e70156895488f04e7c01 GIT binary patch literal 1995 zcmeAS@N?(olHy`uVBq!ia0vp^cY*jS2Q!d-;>qd?q!^2X+?^QKos)S9X`{qMNW-1ZNf`XbE_>V7v5Jno@e7*yC2)HC@hi%Uwym_jvspQRS>JxA?dxyvZ@m;`)_RTS!X`aikv9INOLMq#qmH*L zzb-hjYf^gbgCC_eUrt*^u)j`_T{fLBa%msG9GJ7Fxpb@W)sOGpuN|~{6KVb=QhWm+ zkQoua8ARoT9pA47;sW)>p0%2@``v{65|z)Ty>S~8qZ^KT8nnD8`p%_y|28clq$mPEZDQ_(v%2si@Lk>Z6IPB)?F)>_3SKVgmAYOU$uQ6*}nLypveY3 zutPVjOOrhpTfV{E>cz>lS5bR=FEa)6gP1eyLf-w4^s!x_zWc@I?9XhE9qYqI2cTM%>?6`!8pC84`XILpN-*LS#cS@N-P{!R$W;3i7E}yaT_2-+RmFr*q zat%m}jpsO}7kGTCv4&%7>0C|MnIIx^<>SxACtQz~#QytGdnY$t#_mCVTD8nxc0Zr8 z)y&K$M*~mZE0qj3Ilx#hzw-2q=dpKkZ#{p-l@`;J%U!!`o$l+Zub)55Z)RA&s^!Xa Q7Emec>FVdQ&MBb@02;E)Gynhq literal 0 HcmV?d00001 diff --git a/[0542][01 Matrix]/[0542][01 Matrix].iml b/[0542][01 Matrix]/[0542][01 Matrix].iml new file mode 100644 index 0000000..c8cb479 --- /dev/null +++ b/[0542][01 Matrix]/[0542][01 Matrix].iml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0542][01 Matrix]/src/Main.java b/[0542][01 Matrix]/src/Main.java new file mode 100644 index 0000000..984cd23 --- /dev/null +++ b/[0542][01 Matrix]/src/Main.java @@ -0,0 +1,92 @@ +import org.junit.Test; + +import java.util.Arrays; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-02 14:54 + **/ +public class Main { + @Test + public void test1() { + int[][] matrix = { + {0, 0, 0}, + {0, 1, 0}, + {1, 1, 1}}; + Solution solution = new Solution(); + matrix = solution.updateMatrix(matrix); + + for (int[] row : matrix) { + System.out.println(Arrays.toString(row)); + } + System.out.println(); + } + + @Test + public void test2() { + int[][] matrix = { + {1, 1, 1}, + {1, 0, 1}, + {1, 1, 1}}; + Solution solution = new Solution(); + matrix = solution.updateMatrix(matrix); + + for (int[] row : matrix) { + System.out.println(Arrays.toString(row)); + } + System.out.println(); + + } + + @Test + public void test3() { + int[][] matrix = { + {1, 1, 1, 1, 1}, + {1, 1, 1, 1, 1}, + {1, 1, 0, 1, 1}, + {1, 1, 1, 1, 1}, + {1, 1, 1, 1, 1}}; + Solution solution = new Solution(); + matrix = solution.updateMatrix(matrix); + + for (int[] row : matrix) { + System.out.println(Arrays.toString(row)); + } + System.out.println(); + + } + + @Test + public void test4() { + int[][] matrix = { + {0, 0, 0, 0, 0}, + {0, 1, 1, 1, 1}, + {0, 1, 0, 1, 1}, + {0, 1, 1, 1, 1}, + {0, 1, 1, 1, 1}}; + Solution solution = new Solution(); + matrix = solution.updateMatrix(matrix); + + for (int[] row : matrix) { + System.out.println(Arrays.toString(row)); + } + System.out.println(); + } + + @Test + public void test5() { + int[][] matrix = { + {0, 0, 0, 0, 0}, + {0, 1, 1, 1, 1}, + {0, 1, 1, 1, 1}, + {0, 1, 1, 1, 1}, + {0, 1, 1, 1, 1}}; + Solution solution = new Solution(); + matrix = solution.updateMatrix(matrix); + + for (int[] row : matrix) { + System.out.println(Arrays.toString(row)); + } + System.out.println(); + } +} diff --git a/[0542][01 Matrix]/src/Solution.java b/[0542][01 Matrix]/src/Solution.java new file mode 100644 index 0000000..5d30dcc --- /dev/null +++ b/[0542][01 Matrix]/src/Solution.java @@ -0,0 +1,115 @@ +import java.util.Deque; +import java.util.LinkedList; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-02 13:25 + **/ +public class Solution { + /** + *
+     * Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell.
+     *
+     * The distance between two adjacent cells is 1.
+     *
+     *
+     *
+     * Example 1:
+     *
+     * Input:
+     * [[0,0,0],
+     *  [0,1,0],
+     *  [0,0,0]]
+     *
+     * Output:
+     * [[0,0,0],
+     *  [0,1,0],
+     *  [0,0,0]]
+     * Example 2:
+     *
+     * Input:
+     * [[0,0,0],
+     *  [0,1,0],
+     *  [1,1,1]]
+     *
+     * Output:
+     * [[0,0,0],
+     *  [0,1,0],
+     *  [1,2,1]]
+     *
+     *  Note:
+     *
+     * The number of elements of the given matrix will not exceed 10,000.
+     * There are at least one 0 in the given matrix.
+     * The cells are adjacent in only four directions: up, down, left and right.
+     * 类似广度优化遍历
+     * 
+ * + * @param matrix + * @return + */ + public int[][] updateMatrix(int[][] matrix) { + + boolean[][] visit = new boolean[matrix.length][]; + Deque deque = new LinkedList<>(); + + for (int i = 0; i < visit.length; i++) { + visit[i] = new boolean[matrix[i].length]; + } + + for (int i = 0; i < matrix.length; i++) { + for (int j = 0; j < matrix[0].length; j++) { + if (matrix[i][j] == 0) { + visit[i][j] = true; + deque.addLast(i); + deque.addLast(j); + deque.addLast(0); + } + } + } + + while (!deque.isEmpty()) { + int i = deque.removeFirst(); + int j = deque.removeFirst(); + int v = deque.removeFirst(); + + // 上一个 + if (i - 1 >= 0 && !visit[i - 1][j]) { + visit[i - 1][j] = true; + matrix[i - 1][j] = v + 1; + deque.addLast(i - 1); + deque.addLast(j); + deque.addLast(v + 1); + } + + // 下一个 + if (i + 1 < matrix.length && !visit[i + 1][j]) { + visit[i + 1][j] = true; + matrix[i + 1][j] = v + 1; + deque.addLast(i + 1); + deque.addLast(j); + deque.addLast(v + 1); + } + + // 左一个 + if (j - 1 >= 0 && !visit[i][j - 1]) { + visit[i][j - 1] = true; + matrix[i][j - 1] = v + 1; + deque.addLast(i); + deque.addLast(j - 1); + deque.addLast(v + 1); + } + + // 右一个 + if (j + 1 < matrix[0].length && !visit[i][j + 1]) { + visit[i][j + 1] = true; + matrix[i][j + 1] = v + 1; + deque.addLast(i); + deque.addLast(j + 1); + deque.addLast(v + 1); + } + } + + return matrix; + } +} From a0d0d44c02fd57a8b6d76fbab946f6b524b86aa8 Mon Sep 17 00:00:00 2001 From: Wang-Jun-Chao Date: Wed, 3 Jul 2019 04:07:40 +0800 Subject: [PATCH 070/108] commit --- .idea/modules.xml | 1 + .idea/workspace.xml | 319 +++++++----------- ...0405][Convert a Number to Hexadecimal].iml | 21 ++ .../src/Main.java | 26 ++ .../src/Solution.java | 54 +++ 5 files changed, 233 insertions(+), 188 deletions(-) create mode 100644 [0405][Convert a Number to Hexadecimal]/[0405][Convert a Number to Hexadecimal].iml create mode 100644 [0405][Convert a Number to Hexadecimal]/src/Main.java create mode 100644 [0405][Convert a Number to Hexadecimal]/src/Solution.java diff --git a/.idea/modules.xml b/.idea/modules.xml index 43de30c..7cfd2ba 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -196,6 +196,7 @@ + diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 1d40150..db4723d 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,31 +2,11 @@ - - - - - - - - - - - - - - - - - - - - + + + - - - @@ -42,10 +22,10 @@ - + - - + + @@ -54,37 +34,33 @@ - + - - + + + + + - - + + - - - - - + + - - + + - - + + - - - - @@ -93,7 +69,7 @@ - + @@ -105,7 +81,7 @@ - + @@ -114,7 +90,7 @@ - + @@ -123,7 +99,7 @@ - + @@ -140,7 +116,7 @@ - + @@ -195,8 +171,6 @@ @@ -257,7 +233,7 @@ - - - + + + - - - + + @@ -314,7 +334,7 @@ - + - - + + - - + + - - + + - - + + + + - - @@ -422,14 +441,7 @@ - - - - 1539048078075 - 1539061614369 @@ -767,16 +779,17 @@ - - - - - - - @@ -801,15 +814,21 @@ + + + + + + - - + @@ -818,7 +837,7 @@ - + @@ -1103,34 +1122,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1493,6 +1484,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/[0409][Longest Palindrome]/[0409][Longest Palindrome].iml b/[0409][Longest Palindrome]/[0409][Longest Palindrome].iml new file mode 100644 index 0000000..bb6b39c --- /dev/null +++ b/[0409][Longest Palindrome]/[0409][Longest Palindrome].iml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0409][Longest Palindrome]/src/Main.java b/[0409][Longest Palindrome]/src/Main.java new file mode 100644 index 0000000..61a21bb --- /dev/null +++ b/[0409][Longest Palindrome]/src/Main.java @@ -0,0 +1,20 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-03 04:15 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + Assert.assertEquals(7, solution.longestPalindrome("abccccdd")); + } + + @Test + public void test2() { + Solution solution = new Solution(); + Assert.assertEquals(7, solution.longestPalindrome("aAaaaaaa")); + } +} diff --git a/[0409][Longest Palindrome]/src/Solution.java b/[0409][Longest Palindrome]/src/Solution.java new file mode 100644 index 0000000..f4de31d --- /dev/null +++ b/[0409][Longest Palindrome]/src/Solution.java @@ -0,0 +1,55 @@ +/** + * https://leetcode.com/problems/longest-palindrome/ + * + * @author: wangjunchao(王俊超) + * @time: 2019-07-03 04:08 + **/ +public class Solution { + /** + *
+     * Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.
+     *
+     * This is case sensitive, for example "Aa" is not considered a palindrome here.
+     *
+     * Note:
+     * Assume the length of given string will not exceed 1,010.
+     *
+     * Example:
+     *
+     * Input:
+     * "abccccdd"
+     *
+     * Output:
+     * 7
+     *
+     * Explanation:
+     * One longest palindrome that can be built is "dccaccd", whose length is 7.
+     * 思路
+     * 1、先记录每个字符出现的次数
+     * 2、取每个字符出现的最大的偶数
+     * 3、如果还有剩下的单个字符,只取其中的一个
+     * 
+ */ + public int longestPalindrome(String s) { + if (s == null || s.length() < 1) { + return 0; + } + + int[] counter = new int[256]; + + for (int i = 0; i < s.length(); i++) { + char ch = s.charAt(i); + counter[ch - 'A']++; + } + + int result = 0; + int left = 0; + for (int value : counter) { + + result += 0xFFFFFFFE & value; + left |= 0b1 & value; + } + + return result + left; + } +} diff --git a/[0409][Longest Palindrome]/src/Solution1.java b/[0409][Longest Palindrome]/src/Solution1.java new file mode 100644 index 0000000..797d326 --- /dev/null +++ b/[0409][Longest Palindrome]/src/Solution1.java @@ -0,0 +1,60 @@ +/** + * https://leetcode.com/problems/longest-palindrome/ + * + * @author: wangjunchao(王俊超) + * @time: 2019-07-03 04:08 + **/ +public class Solution1 { + /** + *
+     * Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.
+     *
+     * This is case sensitive, for example "Aa" is not considered a palindrome here.
+     *
+     * Note:
+     * Assume the length of given string will not exceed 1,010.
+     *
+     * Example:
+     *
+     * Input:
+     * "abccccdd"
+     *
+     * Output:
+     * 7
+     *
+     * Explanation:
+     * One longest palindrome that can be built is "dccaccd", whose length is 7.
+     * 思路
+     * 1、先记录每个字符出现的次数
+     * 2、取每个字符出现的最大的偶数
+     * 3、如果还有剩下的单个字符,只取其中的一个
+     * 
+ */ + public int longestPalindrome(String s) { + if (s == null || s.length() < 1) { + return 0; + } + + int[] counter = new int[256]; + + for (int i = 0; i < s.length(); i++) { + char ch = s.charAt(i); + counter[ch - 'A']++; + } + + int result = 0; + int left = 0; + for (int value : counter) { + if (value > 0) { + if (value % 2 == 0) { + result += value; + } else { + result += value - 1; + left = 1; + } + } + } + + return result + left; + } +} diff --git a/[0409][Longest Palindrome]/src/Solution2.java b/[0409][Longest Palindrome]/src/Solution2.java new file mode 100644 index 0000000..4546ba5 --- /dev/null +++ b/[0409][Longest Palindrome]/src/Solution2.java @@ -0,0 +1,66 @@ +/** + * https://leetcode.com/problems/longest-palindrome/ + * @author: wangjunchao(王俊超) + * @time: 2019-07-03 04:08 + **/ +public class Solution2 { + /** + *
+     * Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.
+     *
+     * This is case sensitive, for example "Aa" is not considered a palindrome here.
+     *
+     * Note:
+     * Assume the length of given string will not exceed 1,010.
+     *
+     * Example:
+     *
+     * Input:
+     * "abccccdd"
+     *
+     * Output:
+     * 7
+     *
+     * Explanation:
+     * One longest palindrome that can be built is "dccaccd", whose length is 7.
+     * 思路
+     * 1、先记录每个字符出现的次数
+     * 2、取每个字符出现的最大的偶数
+     * 3、如果还有剩下的单个字符,只取其中的一个
+     * 
+ */ + public int longestPalindrome(String s) { + if (s == null || s.length() < 1) { + return 0; + } + + int[] counter = new int[26]; + // TIP: 这里是大小写不敏感的 + for (int i = 0; i < s.length(); i++) { + char ch = s.charAt(i); + if (ch >= 'a' && ch <= 'z') { + counter[ch - 'a']++; + } else { + counter[ch - 'A']++; + } + } + + int result = 0; + int left = 0; + for (int value : counter) { + if (value > 0) { + if (value % 2 == 0) { + result += value; +// counter[i] = 0; + } else { + result += value - 1; +// counter[i] = 1; + // 记录还有剩下的1 + left = 1; + } + } + } + + return result + left; + } +} From 4917d5d311a8334624ea5af0b06171d9958b715f Mon Sep 17 00:00:00 2001 From: Wang-Jun-Chao Date: Wed, 3 Jul 2019 20:20:21 +0800 Subject: [PATCH 072/108] commit --- .idea/modules.xml | 7 + .idea/workspace.xml | 583 ++++++++++-------- .../[0260][Single Number III].iml | 21 + [0260][Single Number III]/src/Main.java | 17 + [0260][Single Number III]/src/Solution.java | 51 ++ .../[0287][Find the Duplicate Number].iml | 21 + .../src/Main.java | 20 + .../src/Solution.java | 55 ++ ...0405][Convert a Number to Hexadecimal].iml | 2 + .../[0409][Longest Palindrome].iml | 2 + [0409][Longest Palindrome]/src/Solution.java | 1 - [0415][Add Strings]/[0415][Add Strings].iml | 23 + [0415][Add Strings]/src/Main.java | 26 + [0415][Add Strings]/src/Solution.java | 67 ++ [0437][Path Sum III]/[0437][Path Sum III].iml | 23 + [0437][Path Sum III]/src/Main.java | 98 +++ [0437][Path Sum III]/src/Solution.java | 55 ++ [0437][Path Sum III]/src/TreeNode.java | 14 + .../[0459][Repeated Substring Pattern].iml | 11 + .../src/Solution.java | 35 ++ .../[0476][Number Complement].iml | 21 + [0476][Number Complement]/src/Main.java | 27 + [0476][Number Complement]/src/Solution.java | 40 ++ .../[0557][Reverse Words in a String III].iml | 21 + .../src/Main.java | 24 + .../src/Solution.java | 58 ++ 26 files changed, 1048 insertions(+), 275 deletions(-) create mode 100644 [0260][Single Number III]/[0260][Single Number III].iml create mode 100644 [0260][Single Number III]/src/Main.java create mode 100644 [0260][Single Number III]/src/Solution.java create mode 100644 [0287][Find the Duplicate Number]/[0287][Find the Duplicate Number].iml create mode 100644 [0287][Find the Duplicate Number]/src/Main.java create mode 100644 [0287][Find the Duplicate Number]/src/Solution.java create mode 100644 [0415][Add Strings]/[0415][Add Strings].iml create mode 100644 [0415][Add Strings]/src/Main.java create mode 100644 [0415][Add Strings]/src/Solution.java create mode 100644 [0437][Path Sum III]/[0437][Path Sum III].iml create mode 100644 [0437][Path Sum III]/src/Main.java create mode 100644 [0437][Path Sum III]/src/Solution.java create mode 100644 [0437][Path Sum III]/src/TreeNode.java create mode 100644 [0459][Repeated Substring Pattern]/[0459][Repeated Substring Pattern].iml create mode 100644 [0459][Repeated Substring Pattern]/src/Solution.java create mode 100644 [0476][Number Complement]/[0476][Number Complement].iml create mode 100644 [0476][Number Complement]/src/Main.java create mode 100644 [0476][Number Complement]/src/Solution.java create mode 100644 [0557][Reverse Words in a String III]/[0557][Reverse Words in a String III].iml create mode 100644 [0557][Reverse Words in a String III]/src/Main.java create mode 100644 [0557][Reverse Words in a String III]/src/Solution.java diff --git a/.idea/modules.xml b/.idea/modules.xml index 3400740..41b7c77 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -176,10 +176,12 @@ + + @@ -199,11 +201,16 @@ + + + + +
diff --git a/.idea/workspace.xml b/.idea/workspace.xml index f82cc8d..877bb32 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,13 +2,32 @@ - - - - - + + + + + + + + + + + + + + + + + + + + + + + + @@ -24,54 +43,59 @@ - + - - - - - + + - + - - + + + + + + - + - - + + - + - - + + - - - + + + + + + + - - + + - - + + @@ -80,10 +104,10 @@ - + - - + + @@ -92,10 +116,10 @@ - + - - + + @@ -104,15 +128,19 @@ - - + + + + + + - + - - + + @@ -166,20 +194,6 @@ @@ -228,8 +256,8 @@ - @@ -241,6 +269,7 @@ + @@ -251,44 +280,18 @@ - - - - - - - - - - - - - - - - - - - - - - - - - + - + - @@ -337,9 +327,9 @@ - - - + + + - - + + - - + + - - + + - + + - @@ -446,14 +435,7 @@ - - - - 1539138473362 - 1539139092234 @@ -791,13 +773,17 @@ - - - - @@ -825,12 +811,15 @@ + + + - - + @@ -1145,27 +1134,6 @@ - - - - - - - - - - - - - - - - - - - - - @@ -1542,11 +1510,28 @@ - + + + + + + + + + + + + + + + + + + diff --git a/[0338][Counting Bits ]/[0338][Counting Bits ].iml b/[0338][Counting Bits ]/[0338][Counting Bits ].iml new file mode 100644 index 0000000..bb6b39c --- /dev/null +++ b/[0338][Counting Bits ]/[0338][Counting Bits ].iml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0338][Counting Bits ]/src/Main.java b/[0338][Counting Bits ]/src/Main.java new file mode 100644 index 0000000..6fe5d61 --- /dev/null +++ b/[0338][Counting Bits ]/src/Main.java @@ -0,0 +1,20 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-03 20:50 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + Assert.assertArrayEquals(new int[]{0, 1, 1}, solution.countBits(2)); + } + + @Test + public void test2() { + Solution solution = new Solution(); + Assert.assertArrayEquals(new int[]{0, 1, 1, 2, 1, 2}, solution.countBits(5)); + } +} diff --git a/[0338][Counting Bits ]/src/Solution.java b/[0338][Counting Bits ]/src/Solution.java new file mode 100644 index 0000000..68effd5 --- /dev/null +++ b/[0338][Counting Bits ]/src/Solution.java @@ -0,0 +1,59 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-03 20:38 + **/ +public class Solution { + + /** + *
+     * Given a non negative integer number num. For every numbers i in the range
+     * 0 ≤ i ≤ num calculate the number of 1's in their binary representation and
+     * return them as an array.
+     *
+     * Example 1:
+     *
+     * Input: 2
+     * Output: [0,1,1]
+     * Example 2:
+     *
+     * Input: 5
+     * Output: [0,1,1,2,1,2]
+     * Follow up:
+     *
+     * It is very easy to come up with a solution with run time O(n*sizeof(integer)).
+     * But can you do it in linear time O(n) /possibly in a single pass?
+     * Space complexity should be O(n).
+     * Can you do it like a boss? Do it without using any builtin function like
+     * __builtin_popcount in c++ or in any other language.
+     *
+     * 思路:
+     * 使用治法,
+     * i为偶数 bit(i) = bit(i/2)
+     * i为奇数 bit(i) = bit(i/2) + 1
+     * 
+ * @param num + * @return + */ + public int[] countBits(int num) { + if (num < 0) { + return new int[0]; + } else if (num == 0) { + return new int[]{0}; + } else if (num == 1) { + return new int[]{0, 1}; + } + + int[] dp = new int[num + 1]; + dp[0] = 0; + dp[1] = 1; + for (int i = 2; i <= num; i++) { + dp[i] += dp[i / 2]; + // 不是偶数,说明其比 i/2多一个一 + if (i % 2 != 0) { + dp[i]++; + } + } + + return dp; + } +} From 64a8351d2dd55456483d4758f44d908f6e074365 Mon Sep 17 00:00:00 2001 From: Wang-Jun-Chao Date: Wed, 3 Jul 2019 21:27:32 +0800 Subject: [PATCH 074/108] commit --- .idea/modules.xml | 1 + .idea/workspace.xml | 244 +++++++++--------- .../[0347][Top K Frequent Elements].iml | 21 ++ [0347][Top K Frequent Elements]/src/Main.java | 19 ++ .../src/Solution.java | 78 ++++++ 5 files changed, 246 insertions(+), 117 deletions(-) create mode 100644 [0347][Top K Frequent Elements]/[0347][Top K Frequent Elements].iml create mode 100644 [0347][Top K Frequent Elements]/src/Main.java create mode 100644 [0347][Top K Frequent Elements]/src/Solution.java diff --git a/.idea/modules.xml b/.idea/modules.xml index af1efd2..8493602 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -189,6 +189,7 @@ + diff --git a/.idea/workspace.xml b/.idea/workspace.xml index a4289bc..3905bea 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,9 +2,9 @@ - - - + + + @@ -22,59 +22,65 @@ - + - - + + - + - - - - - - + + - + - - + + - - + + - - + + + + + + + - + + + + + + - - + + - - + + - - + + @@ -83,7 +89,7 @@ - + @@ -115,18 +121,6 @@ - - - - - - - - - - - - @@ -173,8 +167,6 @@ @@ -235,8 +229,8 @@ - @@ -278,6 +272,17 @@ + + + + + + + + + + + @@ -332,7 +351,7 @@ - + - - + + - + + - @@ -439,14 +458,7 @@ - - - - 1539149548535 - 1539150595863 @@ -784,13 +796,17 @@ - - - - @@ -818,13 +834,15 @@ + + + - - - + @@ -1138,20 +1156,6 @@ - - - - - - - - - - - - - - @@ -1159,13 +1163,6 @@ - - - - - - - @@ -1542,6 +1539,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/[0561][Array Partition I]/[0561][Array Partition I].iml b/[0561][Array Partition I]/[0561][Array Partition I].iml new file mode 100644 index 0000000..bb6b39c --- /dev/null +++ b/[0561][Array Partition I]/[0561][Array Partition I].iml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0561][Array Partition I]/src/Main.java b/[0561][Array Partition I]/src/Main.java new file mode 100644 index 0000000..92bec11 --- /dev/null +++ b/[0561][Array Partition I]/src/Main.java @@ -0,0 +1,15 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-04 08:49 + **/ +public class Main { + @Test + public void test1(){ + Solution solution = new Solution(); + int[] arr = {1,4,3,2}; + Assert.assertEquals(4, solution.arrayPairSum(arr)); + } +} diff --git a/[0561][Array Partition I]/src/Solution.java b/[0561][Array Partition I]/src/Solution.java new file mode 100644 index 0000000..4c41f06 --- /dev/null +++ b/[0561][Array Partition I]/src/Solution.java @@ -0,0 +1,41 @@ +import java.util.Arrays; + +/** + * https://leetcode.com/problems/array-partition-i/ + * @author: wangjunchao(王俊超) + * @time: 2019-07-04 08:46 + **/ +public class Solution { + /** + *
+     * Given an array of 2n integers, your task is to group these integers into n pairs of integer,
+     * say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of min(ai, bi) for all i from 1 to n
+     * as large as possible.
+     *
+     * Example 1:
+     * Input: [1,4,3,2]
+     *
+     * Output: 4
+     * Explanation: n is 2, and the maximum sum of pairs is 4 = min(1, 2) + min(3, 4).
+     * Note:
+     * n is a positive integer, which is in the range of [1, 10000].
+     * All the integers in the array will be in the range of [-10000, 10000].
+     *
+     * 解题思路
+     * 先将数据组排序,取偶数位置的数相加,即为结果
+     * 证明略
+     * 
+ * @param nums + * @return + */ + public int arrayPairSum(int[] nums) { + Arrays.sort(nums); + + int result = 0; + for (int i = 0; i < nums.length; i+=2) { + result += nums[i]; + } + + return result; + } +} diff --git a/[0617][Merge Two Binary Trees]/[0617][Merge Two Binary Trees].iml b/[0617][Merge Two Binary Trees]/[0617][Merge Two Binary Trees].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0617][Merge Two Binary Trees]/[0617][Merge Two Binary Trees].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file From ac069b251db8fc709c3067f27507e4cbda106109 Mon Sep 17 00:00:00 2001 From: Wang-Jun-Chao Date: Sat, 6 Jul 2019 19:29:41 +0800 Subject: [PATCH 076/108] commit --- .idea/encodings.xml | 1 + .idea/modules.xml | 1 + .idea/workspace.xml | 357 +++++++++--------- .../[0260][Single Number III].iml | 2 + .../[0287][Find the Duplicate Number].iml | 2 + .../[0338][Counting Bits ].iml | 2 + .../[0347][Top K Frequent Elements].iml | 2 + .../[0459][Repeated Substring Pattern].iml | 2 + .../[0476][Number Complement].iml | 2 + .../[0485][Max Consecutive Ones].iml | 21 ++ [0485][Max Consecutive Ones]/src/Main.java | 22 ++ .../src/Solution.java | 47 +++ .../[0557][Reverse Words in a String III].iml | 2 + .../[0561][Array Partition I].iml | 2 + .../[0617][Merge Two Binary Trees].iml | 12 + [0617][Merge Two Binary Trees]/src/Main.java | 34 ++ .../src/Solution.java | 54 +++ .../src/TreeNode.java | 17 + 18 files changed, 398 insertions(+), 184 deletions(-) create mode 100644 [0485][Max Consecutive Ones]/[0485][Max Consecutive Ones].iml create mode 100644 [0485][Max Consecutive Ones]/src/Main.java create mode 100644 [0485][Max Consecutive Ones]/src/Solution.java create mode 100644 [0617][Merge Two Binary Trees]/src/Main.java create mode 100644 [0617][Merge Two Binary Trees]/src/Solution.java create mode 100644 [0617][Merge Two Binary Trees]/src/TreeNode.java diff --git a/.idea/encodings.xml b/.idea/encodings.xml index 2e0845e..d581ce0 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -95,6 +95,7 @@ + diff --git a/.idea/modules.xml b/.idea/modules.xml index 6ecb2e2..5689ad7 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -211,6 +211,7 @@ + diff --git a/.idea/workspace.xml b/.idea/workspace.xml index e249f89..199cd6b 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,11 +2,24 @@ - - - + + + + + + + + + + + + + + + + @@ -22,59 +35,71 @@ - + - - + + - + + + + + + + + + + - - + + - + - - + + - - - + - - + + - - + + - - + + + + + + + - + @@ -97,27 +122,6 @@ - - - - - - - - - - - - - - - - - - - - - @@ -164,11 +168,6 @@ @@ -226,9 +230,9 @@ - @@ -239,7 +243,7 @@ - + @@ -291,22 +295,11 @@ - - - - - - - - - - - - @@ -322,15 +371,15 @@ - - - + + - - + + + @@ -345,9 +394,9 @@ - - - + + + - + - - + + - - + + - - - + + + + + + - - - @@ -456,14 +504,8 @@ - - - - 1539166307183 - 1539325195078 @@ -801,58 +843,65 @@ - - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + - + - + - + - + @@ -1222,99 +1271,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1578,61 +1534,158 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - - + + + + + + - + - - + + + + + + + + - - + + - + - - + + + + + + + + + + + + + + + + + + + + + + + - + - - + + + + + + + + + diff --git a/[0207][Course Schedule]/[0207][Course Schedule].iml b/[0207][Course Schedule]/[0207][Course Schedule].iml index bb6b39c..c8cb479 100644 --- a/[0207][Course Schedule]/[0207][Course Schedule].iml +++ b/[0207][Course Schedule]/[0207][Course Schedule].iml @@ -17,5 +17,7 @@
+ + \ No newline at end of file diff --git a/[0222][Count Complete Tree Nodes]/[0222][Count Complete Tree Nodes].iml b/[0222][Count Complete Tree Nodes]/[0222][Count Complete Tree Nodes].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0222][Count Complete Tree Nodes]/[0222][Count Complete Tree Nodes].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0222][Count Complete Tree Nodes]/src/Solution.java b/[0222][Count Complete Tree Nodes]/src/Solution.java new file mode 100644 index 0000000..77dd1c2 --- /dev/null +++ b/[0222][Count Complete Tree Nodes]/src/Solution.java @@ -0,0 +1,7 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-08 20:52 + **/ +public class Solution { + +} diff --git a/[0240][Search a 2D Matrix II]/[0240][Search a 2D Matrix II].iml b/[0240][Search a 2D Matrix II]/[0240][Search a 2D Matrix II].iml index bb6b39c..c8cb479 100644 --- a/[0240][Search a 2D Matrix II]/[0240][Search a 2D Matrix II].iml +++ b/[0240][Search a 2D Matrix II]/[0240][Search a 2D Matrix II].iml @@ -17,5 +17,7 @@ + + \ No newline at end of file diff --git a/[0241][Different Ways to Add Parentheses]/[0241][Different Ways to Add Parentheses].iml b/[0241][Different Ways to Add Parentheses]/[0241][Different Ways to Add Parentheses].iml index bb6b39c..c8cb479 100644 --- a/[0241][Different Ways to Add Parentheses]/[0241][Different Ways to Add Parentheses].iml +++ b/[0241][Different Ways to Add Parentheses]/[0241][Different Ways to Add Parentheses].iml @@ -17,5 +17,7 @@ + + \ No newline at end of file diff --git a/[0292][Nim Game]/[0292][Nim Game].iml b/[0292][Nim Game]/[0292][Nim Game].iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/[0292][Nim Game]/[0292][Nim Game].iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/[0292][Nim Game]/src/Solution.java b/[0292][Nim Game]/src/Solution.java new file mode 100644 index 0000000..2193932 --- /dev/null +++ b/[0292][Nim Game]/src/Solution.java @@ -0,0 +1,39 @@ +/** + * https://leetcode.com/problems/nim-game/ + * @author: wangjunchao(王俊超) + * @time: 2019-07-08 18:39 + **/ +public class Solution { + /** + *
+     * You are playing the following Nim Game with your friend: There is a heap of stones on the table,
+     * each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will
+     * be the winner. You will take the first turn to remove the stones.
+     *
+     * Both of you are very clever and have optimal strategies for the game. Write a function to determine
+     * whether you can win the game given the number of stones in the heap.
+     *
+     * Example:
+     *
+     * Input: 4
+     * Output: false
+     * Explanation: If there are 4 stones in the heap, then you will never win the game;
+     *              No matter 1, 2, or 3 stones you remove, the last stone will always be
+     *              removed by your friend.
+     *
+     * 这题往小说可以追溯到小学奥数或者脑筋急转弯的书中,往大说可以深究到博弈论。然而编程在这里并没有卵用,
+     * 策略在于,因为每个人都取不到4个,假设自己后走,要保证每轮自己和对方取得数量的和是4,这样就能确保每
+     * 轮完后都有4的倍数个石头被取走。这样,如果我们先走的话,先把n除4的余数个石头拿走,这样不管怎样,到最
+     * 后都会留4个下来,对方取1个你就取3个,对方取2个你就取2个,就必赢了。
+     * 
+ * @param n + * @return + */ + public boolean canWinNim(int n) { + return (n & 0b11) > 0; + } + + public boolean canWinNim2(int n) { + return n %4 != 0; + } +} diff --git a/[0427][Construct Quad Tree]/[0427][Construct Quad Tree].iml b/[0427][Construct Quad Tree]/[0427][Construct Quad Tree].iml index bb6b39c..c8cb479 100644 --- a/[0427][Construct Quad Tree]/[0427][Construct Quad Tree].iml +++ b/[0427][Construct Quad Tree]/[0427][Construct Quad Tree].iml @@ -17,5 +17,7 @@
+ + \ No newline at end of file diff --git a/[0438][Find All Anagrams in a String]/[0438][Find All Anagrams in a String].iml b/[0438][Find All Anagrams in a String]/[0438][Find All Anagrams in a String].iml new file mode 100644 index 0000000..bb6b39c --- /dev/null +++ b/[0438][Find All Anagrams in a String]/[0438][Find All Anagrams in a String].iml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0438][Find All Anagrams in a String]/src/Main.java b/[0438][Find All Anagrams in a String]/src/Main.java new file mode 100644 index 0000000..9dbfbc2 --- /dev/null +++ b/[0438][Find All Anagrams in a String]/src/Main.java @@ -0,0 +1,22 @@ +import org.junit.Assert; +import org.junit.Test; + +import java.util.Arrays; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-08 20:07 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + Assert.assertEquals(Arrays.asList(0, 6), solution.findAnagrams("cbaebabacd", "abc")); + } + + @Test + public void test2() { + Solution solution = new Solution(); + Assert.assertEquals(Arrays.asList(0, 1, 2), solution.findAnagrams("abab", "ab")); + } +} diff --git a/[0438][Find All Anagrams in a String]/src/Solution.java b/[0438][Find All Anagrams in a String]/src/Solution.java new file mode 100644 index 0000000..766fa5c --- /dev/null +++ b/[0438][Find All Anagrams in a String]/src/Solution.java @@ -0,0 +1,81 @@ +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-08 18:59 + **/ +public class Solution { + /** + *
+     * Given a string s and a non-empty string p, find all the start indices of p's anagrams in s.
+     *
+     * Strings consists of lowercase English letters only and the length of both strings s and p will not be larger than 20,100.
+     *
+     * The order of output does not matter.
+     *
+     * Example 1:
+     *
+     * Input:
+     * s: "cbaebabacd" p: "abc"
+     *
+     * Output:
+     * [0, 6]
+     *
+     * Explanation:
+     * The substring with start index = 0 is "cba", which is an anagram of "abc".
+     * The substring with start index = 6 is "bac", which is an anagram of "abc".
+     * Example 2:
+     *
+     * Input:
+     * s: "abab" p: "ab"
+     *
+     * Output:
+     * [0, 1, 2]
+     *
+     * Explanation:
+     * The substring with start index = 0 is "ab", which is an anagram of "ab".
+     * The substring with start index = 1 is "ba", which is an anagram of "ab".
+     * The substring with start index = 2 is "ab", which is an anagram of "ab".
+     * 
+ * + * @param s + * @param p + * @return + */ + public List findAnagrams(String s, String p) { + List result = new LinkedList<>(); + + if (s.length() < p.length()) { + return result; + } + + int[] pArr = new int[26]; + int[] sArr = new int[26]; + + for (int i = 0; i < p.length(); i++) { + pArr[p.charAt(i) - 'a']++; + } + + for (int i = 0; i < p.length(); i++) { + sArr[s.charAt(i) - 'a']++; + } + + for (int i = 0; i <= s.length() - p.length(); i++) { + if (i > 0) { + sArr[s.charAt(i - 1) - 'a']--; + sArr[s.charAt(i + p.length() - 1) - 'a']++; + } + + if (Arrays.equals(sArr, pArr) ) { + result.add(i); + } + } + + return result; + } +} diff --git a/[0438][Find All Anagrams in a String]/src/Solution2.java b/[0438][Find All Anagrams in a String]/src/Solution2.java new file mode 100644 index 0000000..f72d6e4 --- /dev/null +++ b/[0438][Find All Anagrams in a String]/src/Solution2.java @@ -0,0 +1,118 @@ +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-08 18:59 + **/ +public class Solution2 { + /** + *
+     * Given a string s and a non-empty string p, find all the start indices of p's anagrams in s.
+     *
+     * Strings consists of lowercase English letters only and the length of both strings s and p will not be larger than 20,100.
+     *
+     * The order of output does not matter.
+     *
+     * Example 1:
+     *
+     * Input:
+     * s: "cbaebabacd" p: "abc"
+     *
+     * Output:
+     * [0, 6]
+     *
+     * Explanation:
+     * The substring with start index = 0 is "cba", which is an anagram of "abc".
+     * The substring with start index = 6 is "bac", which is an anagram of "abc".
+     * Example 2:
+     *
+     * Input:
+     * s: "abab" p: "ab"
+     *
+     * Output:
+     * [0, 1, 2]
+     *
+     * Explanation:
+     * The substring with start index = 0 is "ab", which is an anagram of "ab".
+     * The substring with start index = 1 is "ba", which is an anagram of "ab".
+     * The substring with start index = 2 is "ab", which is an anagram of "ab".
+     * 
+ * + * @param s + * @param p + * @return + */ + public List findAnagrams(String s, String p) { + List result = new LinkedList<>(); + + if (s.length() < p.length()) { + return result; + } + + Map map1 = getMap(p); + Map map2 = getMap(s.substring(0, p.length())); + for (int i = 0; i <= s.length() - p.length(); i++) { + + char lastChar = s.charAt(i + p.length() - 1); + char prevChar; + if (i > 0 && (prevChar = s.charAt(i - 1)) != lastChar) { + Integer val = map2.get(prevChar); + if (val <= 1) { + map2.remove(prevChar); + } else { + map2.put(prevChar, val - 1); + } + + val = map2.get(lastChar); + if (val == null) { + map2.put(lastChar, 1); + } else { + map2.put(lastChar, val + 1); + } + } + + if (equals(map1, map2)) { + result.add(i); + } + } + return result; + } + + private boolean equals(Map map1, Map map2) { + if (map1.size() == map2.size()) { + return contains(map1, map2) && contains(map2, map1); + } + return false; + } + + /** + * map1是否包含map2,即map2中的(k, v)都在map1中 + * + * @param map1 + * @param map2 + * @return + */ + private boolean contains(Map map1, Map map2) { + for (Map.Entry e : map2.entrySet()) { + Integer v2 = map1.get(e.getKey()); + if (!map1.containsKey(e.getKey()) || !Objects.equals(e.getValue(), v2)) { + return false; + } + } + return true; + } + + + public Map getMap(String s) { + Map map = new HashMap<>(); + + for (int i = 0; i < s.length(); i++) { + map.merge(s.charAt(i), 1, Integer::sum); + } + return map; + } +} diff --git a/[0485][Max Consecutive Ones]/[0485][Max Consecutive Ones].iml b/[0485][Max Consecutive Ones]/[0485][Max Consecutive Ones].iml index bb6b39c..c8cb479 100644 --- a/[0485][Max Consecutive Ones]/[0485][Max Consecutive Ones].iml +++ b/[0485][Max Consecutive Ones]/[0485][Max Consecutive Ones].iml @@ -17,5 +17,7 @@
+ + \ No newline at end of file diff --git a/[0496][Next Greater Element I]/[0496][Next Greater Element I].iml b/[0496][Next Greater Element I]/[0496][Next Greater Element I].iml index bb6b39c..c8cb479 100644 --- a/[0496][Next Greater Element I]/[0496][Next Greater Element I].iml +++ b/[0496][Next Greater Element I]/[0496][Next Greater Element I].iml @@ -17,5 +17,7 @@ + + \ No newline at end of file diff --git a/[0504][Base 7]/[0504][Base 7].iml b/[0504][Base 7]/[0504][Base 7].iml index bb6b39c..c8cb479 100644 --- a/[0504][Base 7]/[0504][Base 7].iml +++ b/[0504][Base 7]/[0504][Base 7].iml @@ -17,5 +17,7 @@ + + \ No newline at end of file From 5a93d1d26f3b1db1414ad76583bcfc5d8239a35e Mon Sep 17 00:00:00 2001 From: Wang-Jun-Chao Date: Mon, 8 Jul 2019 21:14:07 +0800 Subject: [PATCH 082/108] commit --- .idea/encodings.xml | 2 + .idea/workspace.xml | 275 ++++++++---------- .../[0222][Count Complete Tree Nodes].iml | 10 + .../src/Main.java | 21 ++ .../src/Solution.java | 39 +++ .../src/TreeNode.java | 15 + 6 files changed, 216 insertions(+), 146 deletions(-) create mode 100644 [0222][Count Complete Tree Nodes]/src/Main.java create mode 100644 [0222][Count Complete Tree Nodes]/src/TreeNode.java diff --git a/.idea/encodings.xml b/.idea/encodings.xml index d581ce0..f468859 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -130,6 +130,8 @@ + + diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 34b3b52..d7b4bfd 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,22 +2,12 @@ - - - - - - - - + + + - - - - - - - + + @@ -33,54 +23,74 @@ - + - - + + - - + + + + + + + + + + + + + + + + + + + - + - - + + - - - - + - + - - + + - + + - - + + - - + + + + + + + @@ -107,37 +117,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -184,7 +163,6 @@ @@ -246,8 +225,8 @@ - @@ -290,6 +269,17 @@ + + + + + + + + + + + @@ -394,7 +384,7 @@ - + - - + + - + - - + + - + + - @@ -505,14 +495,7 @@ - - - - 1539325195078 - 1542353941348 @@ -850,16 +833,17 @@ - - - - - - - @@ -884,15 +868,21 @@ + + + + + + - - + - + @@ -901,7 +891,7 @@ - + @@ -1271,44 +1261,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1534,13 +1486,6 @@ - - - - - - - @@ -1679,10 +1624,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + @@ -1739,7 +1722,7 @@ - [0427][Construct Quad Tree] + [0235][Lowest Common Ancestor of a Binary Search Tree] \ No newline at end of file diff --git a/[0222][Count Complete Tree Nodes]/src/Main.java b/[0222][Count Complete Tree Nodes]/src/Main.java new file mode 100644 index 0000000..19fccc0 --- /dev/null +++ b/[0222][Count Complete Tree Nodes]/src/Main.java @@ -0,0 +1,21 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-08 21:07 + **/ +public class Main { + @Test + public void test1() { + TreeNode root = new TreeNode(1); + root.left = new TreeNode(2); + root.right = new TreeNode(3); + root.left.left = new TreeNode(4); + root.left.right = new TreeNode(5); + root.right.left = new TreeNode(6); + Solution solution = new Solution(); + + Assert.assertEquals(6, solution.countNodes(root)); + } +} diff --git a/[0222][Count Complete Tree Nodes]/src/Solution.java b/[0222][Count Complete Tree Nodes]/src/Solution.java index 77dd1c2..ce53173 100644 --- a/[0222][Count Complete Tree Nodes]/src/Solution.java +++ b/[0222][Count Complete Tree Nodes]/src/Solution.java @@ -3,5 +3,44 @@ * @time: 2019-07-08 20:52 **/ public class Solution { + public int countNodes(TreeNode root) { + if (root == null) { + return 0; + } + int h1 = leftestHeight(root); + int h2 = rightestHeight(root); + + if (h1 == h2) { + return ((1 << h1) - 1); + } + + return 1 + countNodes(root.left) + countNodes(root.right); + } + + /** + * 最右路径的长度 + * + * @param node + * @return + */ + private int rightestHeight(TreeNode node) { + if (node == null) { + return 0; + } + return 1 + rightestHeight(node.right); + } + + /** + * 最左路径的长度 + * + * @param node + * @return + */ + private int leftestHeight(TreeNode node) { + if (node == null) { + return 0; + } + return 1 + leftestHeight(node.left); + } } diff --git a/[0222][Count Complete Tree Nodes]/src/TreeNode.java b/[0222][Count Complete Tree Nodes]/src/TreeNode.java new file mode 100644 index 0000000..73c7ed9 --- /dev/null +++ b/[0222][Count Complete Tree Nodes]/src/TreeNode.java @@ -0,0 +1,15 @@ +/** + * Author: + * Date: 2015-06-18 + * Time: 10:02 + * Declaration: All Rights Reserved !!! + */ +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} From 166716f687e09e647dfc6693e82271ad48e97653 Mon Sep 17 00:00:00 2001 From: Wang-Jun-Chao Date: Tue, 9 Jul 2019 21:10:43 +0800 Subject: [PATCH 083/108] commit --- .idea/modules.xml | 5 + .idea/workspace.xml | 594 +++++++++--------- .../[0222][Count Complete Tree Nodes].iml | 2 + [0292][Nim Game]/[0292][Nim Game].iml | 2 + [0400][Nth Digit]/[0400][Nth Digit].iml | 11 + [0400][Nth Digit]/src/Solution.java | 80 +++ [0400][Nth Digit]/src/Solution2.java | 51 ++ [0412][Fizz Buzz]/[0412][Fizz Buzz].iml | 21 + [0412][Fizz Buzz]/src/Main.java | 20 + [0412][Fizz Buzz]/src/Solution.java | 62 ++ ...[0434][Number of Segments in a String].iml | 21 + .../src/Main.java | 15 + .../src/Solution.java | 48 ++ .../[0438][Find All Anagrams in a String].iml | 2 + .../[0459][Repeated Substring Pattern].iml | 10 + .../src/Main.java | 26 + .../src/Solution.java | 33 + .../[0969][Pancake Sorting].iml | 21 + [0969][Pancake Sorting]/src/Main.java | 17 + [0969][Pancake Sorting]/src/Solution.java | 87 +++ ...0979][Distribute Coins in Binary Tree].iml | 11 + .../src/Main.java | 7 + .../src/Solution.java | 56 ++ .../src/TreeNode.java | 13 + 24 files changed, 917 insertions(+), 298 deletions(-) create mode 100644 [0400][Nth Digit]/[0400][Nth Digit].iml create mode 100644 [0400][Nth Digit]/src/Solution.java create mode 100644 [0400][Nth Digit]/src/Solution2.java create mode 100644 [0412][Fizz Buzz]/[0412][Fizz Buzz].iml create mode 100644 [0412][Fizz Buzz]/src/Main.java create mode 100644 [0412][Fizz Buzz]/src/Solution.java create mode 100644 [0434][Number of Segments in a String]/[0434][Number of Segments in a String].iml create mode 100644 [0434][Number of Segments in a String]/src/Main.java create mode 100644 [0434][Number of Segments in a String]/src/Solution.java create mode 100644 [0459][Repeated Substring Pattern]/src/Main.java create mode 100644 [0969][Pancake Sorting]/[0969][Pancake Sorting].iml create mode 100644 [0969][Pancake Sorting]/src/Main.java create mode 100644 [0969][Pancake Sorting]/src/Solution.java create mode 100644 [0979][Distribute Coins in Binary Tree]/[0979][Distribute Coins in Binary Tree].iml create mode 100644 [0979][Distribute Coins in Binary Tree]/src/Main.java create mode 100644 [0979][Distribute Coins in Binary Tree]/src/Solution.java create mode 100644 [0979][Distribute Coins in Binary Tree]/src/TreeNode.java diff --git a/.idea/modules.xml b/.idea/modules.xml index caa8e4d..99a0e44 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -203,14 +203,17 @@ + + + @@ -225,6 +228,8 @@ + + diff --git a/.idea/workspace.xml b/.idea/workspace.xml index d7b4bfd..b6d3b71 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,12 +2,30 @@ - - - + + + + + + + + + + + + + + + + + + - + + + + @@ -23,10 +41,10 @@ - + - - + + @@ -34,29 +52,33 @@ - - + + - - + + - + - - + + + + + + - + - - + + @@ -65,51 +87,65 @@ - + - - - - - - + + - - + + - - + + - - + + + + + + + + + + - + - - + + + + + - - + + + + + + + + + - + - - + + @@ -163,20 +199,8 @@ @@ -225,9 +261,9 @@ - @@ -239,7 +275,6 @@ - @@ -250,96 +285,37 @@ - - - - - - - - - - - - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - + @@ -360,7 +330,7 @@ - + - - + + - + + - @@ -473,14 +443,7 @@ - - - - 1542355292660 - 1542355731301 @@ -818,16 +781,17 @@ - - - - - - - @@ -852,15 +816,21 @@ + + + + + + - - + - + @@ -868,8 +838,8 @@ - - + + @@ -1653,17 +1623,20 @@ - + - - + + + + + - + - - + + diff --git a/[0979][Distribute Coins in Binary Tree]/[0979][Distribute Coins in Binary Tree].iml b/[0979][Distribute Coins in Binary Tree]/[0979][Distribute Coins in Binary Tree].iml index c90834f..bb6b39c 100644 --- a/[0979][Distribute Coins in Binary Tree]/[0979][Distribute Coins in Binary Tree].iml +++ b/[0979][Distribute Coins in Binary Tree]/[0979][Distribute Coins in Binary Tree].iml @@ -7,5 +7,15 @@ + + + + + + + + + + \ No newline at end of file diff --git a/[0979][Distribute Coins in Binary Tree]/src/Main.java b/[0979][Distribute Coins in Binary Tree]/src/Main.java index eaed36a..c9963cb 100644 --- a/[0979][Distribute Coins in Binary Tree]/src/Main.java +++ b/[0979][Distribute Coins in Binary Tree]/src/Main.java @@ -1,7 +1,18 @@ +import org.junit.Assert; +import org.junit.Test; + /** * @author: wangjunchao(王俊超) * @time: 2019-07-09 21:10 **/ public class Main { - private final static Logger logger = LoggerFactory.getLogger(Main.class); + @Test + public void test1() { + TreeNode root = new TreeNode(3); + root.left = new TreeNode(0); + root.right = new TreeNode(0); + + Solution solution = new Solution(); + Assert.assertEquals(2, solution.distributeCoins(root)); + } } diff --git a/[0979][Distribute Coins in Binary Tree]/src/Solution.java b/[0979][Distribute Coins in Binary Tree]/src/Solution.java index 551a258..8819f14 100644 --- a/[0979][Distribute Coins in Binary Tree]/src/Solution.java +++ b/[0979][Distribute Coins in Binary Tree]/src/Solution.java @@ -1,4 +1,5 @@ /** + * https://leetcode.com/problems/distribute-coins-in-binary-tree/ * @author: wangjunchao(王俊超) * @time: 2019-07-09 18:52 **/ @@ -6,20 +7,20 @@ public class Solution { private int moves = 0; + /** + *
+     * 解题思路:这个题目有点意思,我的方法是“借”的思想。对于任意一个叶子节点,如果val是0,
+     * 那么表示要向其父节点取一个coin,那么parent.val -= 1, moves += 1;如果是叶子节点
+     * 的val大于1,那么表示要给父节点val-1个coin,同时moves += (val-1)。当然这两种情况
+     * 可以用通用的表达式:move += abs(node.val - 1), parent.val += (node.val - 1)。
+     * 按照后序遍历的方式即可算出总的move次数。
+     *
+     * https://www.cnblogs.com/seyjs/p/10369614.html
+     * 
+ * @param root + * @return + */ public int distributeCoins(TreeNode root) { - /** - *
-         * 一个节点有几种情况:
-         * 1、没有左和右孩子
-         *      1.1、自己的val为0,需要从上面借1个coin
-         *      1.2、自己的val为1,不需要借coin
-         *      1.3、自己的val>1,需要向父结点贡献 val-1个coin
-         * 2、只有左或者右孩子
-         *      2.1、自己的
-         * 
- */ - - if (root == null) { return 0; } @@ -30,7 +31,7 @@ public int distributeCoins(TreeNode root) { } /** - * + * 自底向上,对每一个节点,只能从父结点借,或者向父节点上交coin * @param node * @param parent */ @@ -41,15 +42,17 @@ private void distributeCoins(TreeNode node, TreeNode parent) { } if (node.left != null) { - distributeCoins(node.left, parent); + distributeCoins(node.left, node); } if (node.right != null) { - distributeCoins(node.right, parent); + distributeCoins(node.right, node); } + // 不论向父节点借还是上交都要移动Math.abs(node.val - 1)次 moves += Math.abs(node.val - 1); if (parent != null) { + // 标记父结点 parent.val += node.val - 1; } } From 0a701f1eeed09d80341d4e9a1179788db02b632a Mon Sep 17 00:00:00 2001 From: Wang-Jun-Chao Date: Wed, 10 Jul 2019 13:30:46 +0800 Subject: [PATCH 085/108] commit --- .idea/modules.xml | 5 + .idea/workspace.xml | 567 +++++++++--------- .../[0227][Basic Calculator II].iml | 21 + [0227][Basic Calculator II]/src/Main.java | 32 + [0227][Basic Calculator II]/src/Solution.java | 94 +++ [0400][Nth Digit]/[0400][Nth Digit].iml | 2 + [0412][Fizz Buzz]/[0412][Fizz Buzz].iml | 2 + ...[0434][Number of Segments in a String].iml | 2 + .../[0455][Assign Cookies].iml | 21 + [0455][Assign Cookies]/src/Main.java | 24 + [0455][Assign Cookies]/src/Solution.java | 80 +++ [0475][Heaters]/[0475][Heaters].iml | 21 + [0475][Heaters]/src/Main.java | 17 + [0475][Heaters]/src/Solution.java | 74 +++ .../[0482][License Key Formatting].iml | 21 + [0482][License Key Formatting]/src/Main.java | 38 ++ .../src/Solution.java | 79 +++ .../[0492][Construct the Rectangle].iml | 21 + [0492][Construct the Rectangle]/src/Main.java | 14 + .../src/Solution.java | 57 ++ .../[0969][Pancake Sorting].iml | 2 + ...0979][Distribute Coins in Binary Tree].iml | 2 + 22 files changed, 924 insertions(+), 272 deletions(-) create mode 100644 [0227][Basic Calculator II]/[0227][Basic Calculator II].iml create mode 100644 [0227][Basic Calculator II]/src/Main.java create mode 100644 [0227][Basic Calculator II]/src/Solution.java create mode 100644 [0455][Assign Cookies]/[0455][Assign Cookies].iml create mode 100644 [0455][Assign Cookies]/src/Main.java create mode 100644 [0455][Assign Cookies]/src/Solution.java create mode 100644 [0475][Heaters]/[0475][Heaters].iml create mode 100644 [0475][Heaters]/src/Main.java create mode 100644 [0475][Heaters]/src/Solution.java create mode 100644 [0482][License Key Formatting]/[0482][License Key Formatting].iml create mode 100644 [0482][License Key Formatting]/src/Main.java create mode 100644 [0482][License Key Formatting]/src/Solution.java create mode 100644 [0492][Construct the Rectangle]/[0492][Construct the Rectangle].iml create mode 100644 [0492][Construct the Rectangle]/src/Main.java create mode 100644 [0492][Construct the Rectangle]/src/Solution.java diff --git a/.idea/modules.xml b/.idea/modules.xml index 99a0e44..61ca19e 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -168,6 +168,7 @@ + @@ -217,11 +218,15 @@ + + + + diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 64255ab..a738407 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,11 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + - - @@ -21,44 +42,40 @@ - + - - - - - + + - + - - + + - - + + - - + + - - + - + - - + + @@ -66,20 +83,16 @@ - - - - - - - + + + - + - - + + @@ -88,47 +101,41 @@ - + - - - - - - + + - + - - - - - + + - + - - + + - + + - + - - + + @@ -182,16 +189,6 @@ @@ -244,10 +251,10 @@ - @@ -258,6 +265,7 @@ + @@ -268,12 +276,12 @@ - + - + @@ -285,7 +293,6 @@ @@ -303,15 +347,15 @@ - - - + + - - + + + @@ -326,9 +370,9 @@ - - - + + + - - + + - + - - + + - - + + + + - - - - + + @@ -440,14 +484,7 @@ - - - - 1560516767443 - 1560522000341 @@ -785,58 +822,65 @@ - - + - - + + - - + + - - + + - - + + - - + + - + - + - + - - + + - - + - + - + - + @@ -1118,6 +1162,12 @@ - + - - + + - + - - + + - - + - - - - - - - - + - - + + - - - - - - - - + - - + + + + + + - + - - + + - - + - + - + - - - - + - + - - + + + + + - + - - - - - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - - - - - - - + - - + + - + + + + + + - + - - + + - - - - + - - + + - + - - + + - + - - - - - + + - + - - + + + + + - + - - + + - + + + + - - + + - + - - + + - + - - + + - - + + - + - - + + - + - - + + - + - - - - - + + - + - - + + - + - - + + - + + + + + + + + - + - - + + - + - - - - - + + - + - - + + - + - - + + + + + + + + + + + - + - - + + - - - - - - + + + + - + - - + + - - + - + - - + + + + + + - + - - + + - + - - - - - + + - + - - + + + + + - + - - + + - + - - + + - - + + + + + + - + - - + + - + - - + + - + - - + + + + + + + + + - - + - + - - + + + + + + + + + + + + + + + + - + + - + + + + + + + + - - + + @@ -1713,7 +1789,7 @@ - [0235][Lowest Common Ancestor of a Binary Search Tree] + [0419][Battleships in a Board]
+ + \ No newline at end of file diff --git a/[0228][Summary Ranges]/[0228][Summary Ranges].iml b/[0228][Summary Ranges]/[0228][Summary Ranges].iml index bb6b39c..c8cb479 100644 --- a/[0228][Summary Ranges]/[0228][Summary Ranges].iml +++ b/[0228][Summary Ranges]/[0228][Summary Ranges].iml @@ -17,5 +17,7 @@ + + \ No newline at end of file diff --git a/[0419][Battleships in a Board]/[0419][Battleships in a Board].iml b/[0419][Battleships in a Board]/[0419][Battleships in a Board].iml new file mode 100644 index 0000000..c8cb479 --- /dev/null +++ b/[0419][Battleships in a Board]/[0419][Battleships in a Board].iml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0419][Battleships in a Board]/src/Main.java b/[0419][Battleships in a Board]/src/Main.java new file mode 100644 index 0000000..2ef0da0 --- /dev/null +++ b/[0419][Battleships in a Board]/src/Main.java @@ -0,0 +1,20 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-11 13:34 + **/ +public class Main { + @Test + public void test1() { + char[][] board = { + {'X','.', ',', 'X'}, + {'.','.', ',', 'X'}, + {'.','.', ',', 'X'} + }; + + Solution solution = new Solution(); + Assert.assertEquals(2, solution.countBattleships(board)); + } +} diff --git a/[0419][Battleships in a Board]/src/Solution.java b/[0419][Battleships in a Board]/src/Solution.java new file mode 100644 index 0000000..65b0a27 --- /dev/null +++ b/[0419][Battleships in a Board]/src/Solution.java @@ -0,0 +1,34 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-11 13:23 + **/ +public class Solution { + public int countBattleships(char[][] board) { + + if (board == null || board.length < 1) { + return 0; + } + + int result = 0; + for (int i = 0; i < board.length; i++) { + for (int j = 0; j < board[0].length; j++) { + // 当前位置是X + if (board[i][j] == 'X') { + // 如果左边一个并且上面一个不是X,说明是战舰的起点 + // 考虑边界情况 + if (i > 0 && j > 0 && board[i -1][j] != board[i][j] && board[i][j - 1] != board[i][j]) { + result++; + } else if (i > 0 && j == 0 && board[i -1][j] != board[i][j]) { + result++; + } else if (i == 0 && j > 0 && board[i][j - 1] != board[i][j] ) { + result++; + } else if (i == 0 && j == 0) { + result++; + } + } + } + } + + return result; + } +} diff --git a/[0442][Find All Duplicates in an Array]/[0442][Find All Duplicates in an Array].iml b/[0442][Find All Duplicates in an Array]/[0442][Find All Duplicates in an Array].iml new file mode 100644 index 0000000..c8cb479 --- /dev/null +++ b/[0442][Find All Duplicates in an Array]/[0442][Find All Duplicates in an Array].iml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0442][Find All Duplicates in an Array]/src/Main.java b/[0442][Find All Duplicates in an Array]/src/Main.java new file mode 100644 index 0000000..77f2555 --- /dev/null +++ b/[0442][Find All Duplicates in an Array]/src/Main.java @@ -0,0 +1,17 @@ +import org.junit.Assert; +import org.junit.Test; + +import java.util.Arrays; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-11 14:08 + **/ +public class Main { + @Test + public void test1() { + int[] nums = {4, 3, 2, 7, 8, 2, 3, 1}; + Solution solution = new Solution(); + Assert.assertEquals(Arrays.asList(2, 3), solution.findDuplicates(nums)); + } +} diff --git a/[0442][Find All Duplicates in an Array]/src/Solution.java b/[0442][Find All Duplicates in an Array]/src/Solution.java new file mode 100644 index 0000000..5582095 --- /dev/null +++ b/[0442][Find All Duplicates in an Array]/src/Solution.java @@ -0,0 +1,33 @@ +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-11 13:49 + **/ +public class Solution { + public List findDuplicates(int[] nums) { + List result = new ArrayList<>(); + + if (nums == null || nums.length < 1) { + return result; + } + + Set set = new HashSet<>(); + + for(int i: nums) { + if (set.contains(i)) { + result.add(i); + } else { + set.add(i); + } + } + + Collections.sort(result); + return result; + } +} diff --git a/[0442][Find All Duplicates in an Array]/src/Solution2.java b/[0442][Find All Duplicates in an Array]/src/Solution2.java new file mode 100644 index 0000000..5616c28 --- /dev/null +++ b/[0442][Find All Duplicates in an Array]/src/Solution2.java @@ -0,0 +1,44 @@ +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-11 13:49 + **/ +public class Solution2 { + public List findDuplicates(int[] nums) { + List result = new ArrayList<>(); + + if (nums == null || nums.length < 1) { + return result; + } + + int idx = 1; + + while (idx <= nums.length) { + // 如果nums[9-1] != 9 说明还没有调整到位置 + // nums[idx-1] == nums[nums[idx-1] - 1]说明有同样的值出现 + while (nums[idx - 1] != idx && nums[idx - 1] != nums[nums[idx - 1] - 1]) { + swap(nums, idx - 1, nums[idx - 1] - 1); + } + + idx++; + } + + for (int i = 1; i <= nums.length; i++) { + if (nums[i - 1] != i) { + result.add(nums[i - 1]); + } + } + + Collections.sort(result); + return result; + } + + private void swap(int[] nums, int x, int y) { + int temp = nums[x]; + nums[x] = nums[y]; + nums[y] = temp; + } +} diff --git a/[0455][Assign Cookies]/[0455][Assign Cookies].iml b/[0455][Assign Cookies]/[0455][Assign Cookies].iml index bb6b39c..c8cb479 100644 --- a/[0455][Assign Cookies]/[0455][Assign Cookies].iml +++ b/[0455][Assign Cookies]/[0455][Assign Cookies].iml @@ -17,5 +17,7 @@ + + \ No newline at end of file diff --git a/[0475][Heaters]/[0475][Heaters].iml b/[0475][Heaters]/[0475][Heaters].iml index bb6b39c..c8cb479 100644 --- a/[0475][Heaters]/[0475][Heaters].iml +++ b/[0475][Heaters]/[0475][Heaters].iml @@ -17,5 +17,7 @@ + + \ No newline at end of file diff --git a/[0482][License Key Formatting]/[0482][License Key Formatting].iml b/[0482][License Key Formatting]/[0482][License Key Formatting].iml index bb6b39c..c8cb479 100644 --- a/[0482][License Key Formatting]/[0482][License Key Formatting].iml +++ b/[0482][License Key Formatting]/[0482][License Key Formatting].iml @@ -17,5 +17,7 @@ + + \ No newline at end of file diff --git a/[0492][Construct the Rectangle]/[0492][Construct the Rectangle].iml b/[0492][Construct the Rectangle]/[0492][Construct the Rectangle].iml index bb6b39c..c8cb479 100644 --- a/[0492][Construct the Rectangle]/[0492][Construct the Rectangle].iml +++ b/[0492][Construct the Rectangle]/[0492][Construct the Rectangle].iml @@ -17,5 +17,7 @@ + + \ No newline at end of file diff --git a/[0500][Keyboard Row]/[0500][Keyboard Row].iml b/[0500][Keyboard Row]/[0500][Keyboard Row].iml new file mode 100644 index 0000000..c8cb479 --- /dev/null +++ b/[0500][Keyboard Row]/[0500][Keyboard Row].iml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0500][Keyboard Row]/src/Main.java b/[0500][Keyboard Row]/src/Main.java new file mode 100644 index 0000000..d761a70 --- /dev/null +++ b/[0500][Keyboard Row]/src/Main.java @@ -0,0 +1,15 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-11 10:39 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + + Assert.assertArrayEquals(new String[]{"Alaska", "Dad"}, solution.findWords(new String[]{"Hello", "Alaska", "Dad", "Peace"})); + } +} diff --git a/[0500][Keyboard Row]/src/Solution.java b/[0500][Keyboard Row]/src/Solution.java new file mode 100644 index 0000000..39dbb1b --- /dev/null +++ b/[0500][Keyboard Row]/src/Solution.java @@ -0,0 +1,46 @@ + +import java.util.LinkedList; +import java.util.List; + +/** + * https://leetcode.com/problems/keyboard-row/ + * @author: wangjunchao(王俊超) + * @time: 2019-07-11 10:25 + **/ +public class Solution { + + + public String[] findWords(String[] words) { + String[] lines = { + "`1234567890-=~!@#$%^&*()_+", + "qwertyuiop[]\\QWERTYUIOP{}|", + "asdfghjkl;'ASDFGHJKL:\"", + "zxcvbnm,./ZXCVBNM<>?"}; + + if (words == null || words.length < 1) { + return words; + } + + List result = new LinkedList<>(); + for (String s : words) { + for (String l : lines) { + if (contains(l, s)) { + result.add(s); + break; + } + } + } + + return result.toArray(new String[0]); + } + + private boolean contains(String s, String t) { + for (int i = 0; i < t.length(); i++) { + if (s.indexOf(t.charAt(i)) < 0) { + return false; + } + + } + return true; + } +} diff --git a/[0501][Find Mode in Binary Search Tree]/[0501][Find Mode in Binary Search Tree].iml b/[0501][Find Mode in Binary Search Tree]/[0501][Find Mode in Binary Search Tree].iml new file mode 100644 index 0000000..c8cb479 --- /dev/null +++ b/[0501][Find Mode in Binary Search Tree]/[0501][Find Mode in Binary Search Tree].iml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/[0501][Find Mode in Binary Search Tree]/src/Main.java b/[0501][Find Mode in Binary Search Tree]/src/Main.java new file mode 100644 index 0000000..862d639 --- /dev/null +++ b/[0501][Find Mode in Binary Search Tree]/src/Main.java @@ -0,0 +1,19 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-11 11:26 + **/ +public class Main { + @Test + public void test1() { + TreeNode root = new TreeNode(1); + root.right = new TreeNode(2); + root.right.right = new TreeNode(2); + + Solution solution = new Solution(); + + Assert.assertArrayEquals(new int[]{2}, solution.findMode(root)); + } +} diff --git a/[0501][Find Mode in Binary Search Tree]/src/Solution.java b/[0501][Find Mode in Binary Search Tree]/src/Solution.java new file mode 100644 index 0000000..af9abc6 --- /dev/null +++ b/[0501][Find Mode in Binary Search Tree]/src/Solution.java @@ -0,0 +1,51 @@ +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-11 11:08 + **/ +public class Solution { + public int[] findMode(TreeNode root) { + SortedMap map = new TreeMap<>(); + + findMode(root, map); + + int max = 0; + for (int v: map.values()) { + if (max < v) { + max = v; + } + } + + List list = new LinkedList<>(); + for(Map.Entry e: map.entrySet()) { + if (e.getValue() == max) { + list.add(e.getKey()); + } + } + + int[] result = new int[list.size()]; + int i = 0; + for (int v: list) { + result[i] = v; + i++; + } + return result; + } + + private void findMode(TreeNode root, SortedMap map) { + if (root == null) { + return; + } + + Integer count = map.get(root.val); + map.put(root.val, count == null ? 1 : count + 1); + findMode(root.left, map); + findMode(root.right, map); + + } +} diff --git a/[0501][Find Mode in Binary Search Tree]/src/TreeNode.java b/[0501][Find Mode in Binary Search Tree]/src/TreeNode.java new file mode 100644 index 0000000..8e2131e --- /dev/null +++ b/[0501][Find Mode in Binary Search Tree]/src/TreeNode.java @@ -0,0 +1,17 @@ + +/** + * Author: 王俊超 + * Date: 2015-08-21 + * Time: 18:45 + * Declaration: All Rights Reserved !!! + */ +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} + From d9819e787966550d097fdb15bc5f231d1e49f4a1 Mon Sep 17 00:00:00 2001 From: Wang-Jun-Chao Date: Fri, 12 Jul 2019 19:09:47 +0800 Subject: [PATCH 089/108] commit --- .idea/modules.xml | 2 + .idea/workspace.xml | 499 +++++++++--------- .../[1089][Duplicate Zeros].iml | 23 + [1089][Duplicate Zeros]/src/Main.java | 16 + [1089][Duplicate Zeros]/src/Solution.java | 21 + .../[1108][Defanging an IP Address].iml | 23 + [1108][Defanging an IP Address]/src/Main.java | 22 + .../src/Solution.java | 48 ++ 8 files changed, 404 insertions(+), 250 deletions(-) create mode 100644 [1089][Duplicate Zeros]/[1089][Duplicate Zeros].iml create mode 100644 [1089][Duplicate Zeros]/src/Main.java create mode 100644 [1089][Duplicate Zeros]/src/Solution.java create mode 100644 [1108][Defanging an IP Address]/[1108][Defanging an IP Address].iml create mode 100644 [1108][Defanging an IP Address]/src/Main.java create mode 100644 [1108][Defanging an IP Address]/src/Solution.java diff --git a/.idea/modules.xml b/.idea/modules.xml index db1eae5..2b7023a 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -240,6 +240,8 @@ + + diff --git a/.idea/workspace.xml b/.idea/workspace.xml index eaab73f..e736be2 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,20 +5,12 @@ - - - - - - - - - - - - - - + + + + + + @@ -36,107 +28,107 @@ - + - - - - - + + - + - - + + + + + + + + - - + + - - + + - + + - + - - + + - - + + - - - - - - + + - + - - + + + + + - + - - + + + + + - + - - - - - + + - + - - - - - + + - + - - + + @@ -188,10 +180,6 @@ @@ -250,8 +242,8 @@ - @@ -314,12 +306,17 @@ - + + + + + + - + @@ -370,9 +367,9 @@ - - - + + + - - + + - - + + - - + + - - + + - - - + + + + + + - - - @@ -485,13 +483,7 @@ - - - 1560522000341 - 1560552440693 @@ -829,25 +821,17 @@ - - - - - - - - - - - - - - - - @@ -863,24 +847,39 @@ + + + + + + + + + + + + + + + - - + - + - + - + @@ -1168,6 +1167,12 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1514,13 +1427,6 @@ - - - - - - - @@ -1538,13 +1444,6 @@ - - - - - - - @@ -1650,17 +1549,59 @@ - + - - + + + + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1669,7 +1610,7 @@ - + @@ -1677,65 +1618,123 @@ - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + + + + + + + + - - + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + - + - - + + + + + + + + + + + + + + + + diff --git a/[1089][Duplicate Zeros]/[1089][Duplicate Zeros].iml b/[1089][Duplicate Zeros]/[1089][Duplicate Zeros].iml new file mode 100644 index 0000000..c8cb479 --- /dev/null +++ b/[1089][Duplicate Zeros]/[1089][Duplicate Zeros].iml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/[1089][Duplicate Zeros]/src/Main.java b/[1089][Duplicate Zeros]/src/Main.java new file mode 100644 index 0000000..43d9011 --- /dev/null +++ b/[1089][Duplicate Zeros]/src/Main.java @@ -0,0 +1,16 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-12 08:53 + **/ +public class Main { + @Test + public void test1() { + Solution solution = new Solution(); + int[] arr = {1, 0, 2, 3, 0, 4, 5, 0}; + solution.duplicateZeros(arr); + Assert.assertArrayEquals(new int[]{1, 0, 0, 2, 3, 0, 0, 4}, arr); + } +} diff --git a/[1089][Duplicate Zeros]/src/Solution.java b/[1089][Duplicate Zeros]/src/Solution.java new file mode 100644 index 0000000..9975463 --- /dev/null +++ b/[1089][Duplicate Zeros]/src/Solution.java @@ -0,0 +1,21 @@ +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-12 08:44 + **/ +public class Solution { + public void duplicateZeros(int[] arr) { + for (int i = 0; i < arr.length - 1; i++) { + if (arr[i] == 0) { + move(arr, i+1); + arr[i + 1] = 0; + i++; + } + } + } + + private void move(int[] arr, int i) { + if (arr.length - 1 - i >= 0) { + System.arraycopy(arr, i, arr, i + 1, arr.length - 1 - i); + } + } +} diff --git a/[1108][Defanging an IP Address]/[1108][Defanging an IP Address].iml b/[1108][Defanging an IP Address]/[1108][Defanging an IP Address].iml new file mode 100644 index 0000000..c8cb479 --- /dev/null +++ b/[1108][Defanging an IP Address]/[1108][Defanging an IP Address].iml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/[1108][Defanging an IP Address]/src/Main.java b/[1108][Defanging an IP Address]/src/Main.java new file mode 100644 index 0000000..5e2aba0 --- /dev/null +++ b/[1108][Defanging an IP Address]/src/Main.java @@ -0,0 +1,22 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * @author: wangjunchao(王俊超) + * @time: 2019-07-12 08:37 + **/ +public class Main { + @Test + public void test1() { + String address = "1.1.1.1"; + Solution solution = new Solution(); + Assert.assertEquals("1[.]1[.]1[.]1", solution.defangIPaddr(address)); + } + + @Test + public void test2() { + String address = "255.100.50.0"; + Solution solution = new Solution(); + Assert.assertEquals("255[.]100[.]50[.]0", solution.defangIPaddr(address)); + } +} diff --git a/[1108][Defanging an IP Address]/src/Solution.java b/[1108][Defanging an IP Address]/src/Solution.java new file mode 100644 index 0000000..96d080d --- /dev/null +++ b/[1108][Defanging an IP Address]/src/Solution.java @@ -0,0 +1,48 @@ +/** + * https://leetcode.com/problems/defanging-an-ip-address/submissions/ + * @author: wangjunchao(王俊超) + * @time: 2019-07-12 08:31 + **/ +public class Solution { + /** + *
+     * Given a valid (IPv4) IP address, return a defanged version of that IP address.
+     *
+     * A defanged IP address replaces every period "." with "[.]".
+     *
+     *
+     *
+     * Example 1:
+     *
+     * Input: address = "1.1.1.1"
+     * Output: "1[.]1[.]1[.]1"
+     * Example 2:
+     *
+     * Input: address = "255.100.50.0"
+     * Output: "255[.]100[.]50[.]0"
+     * 
+ * @param address + * @return + */ + public String defangIPaddr(String address) { + if (address ==null || address.length() < 1) { + return address; + } + + StringBuilder builder = new StringBuilder(address.length() * 2); + + for (int i = 0; i < address.length(); i++) { + char ch = address.charAt(i); + if (Character.isDigit(ch)) { + builder.append(ch); + } else if (ch == '.') { + builder.append("[.]"); + } else { + throw new IllegalArgumentException(address + " contains invalid char"); + } + } + + + return builder.toString(); + } +} From f514c81af82ce992f64fffc869ff316255503815 Mon Sep 17 00:00:00 2001 From: "wangjunchao.o" Date: Fri, 26 Jun 2020 08:54:12 +0800 Subject: [PATCH 090/108] commit Change-Id: I63bc8e7801545b33d92bfc5d513ae134eacee1d6 --- .idea/codeStyles/codeStyleConfig.xml | 5 + .idea/encodings.xml | 1 + .idea/jarRepositories.xml | 20 + .idea/leetcode/editor.xml | 57 + .idea/modules.xml | 6 + .idea/workspace.xml | 1101 +++-------------- [0000][common]/[0000][common].iml | 26 + ...160][Intersection of Two Linked Lists].iml | 11 + .../src/ListNode.java | 9 + .../src/Solution.java | 129 ++ .../[0299][Bulls and Cows].iml | 21 + [0299][Bulls and Cows]/src/Solution.java | 85 ++ [0299][Bulls and Cows]/src/TestSolution.java | 14 + .../[0371][Sum of Two Integers].iml | 11 + [0371][Sum of Two Integers]/src/Solution.java | 51 + .../src/SolutionTest.java | 2 + .../[0392][Is Subsequence].iml | 21 + [0392][Is Subsequence]/src/Solution.java | 82 ++ [0392][Is Subsequence]/src/SolutionTest.java | 29 + .../[0441][Arranging Coins].iml | 21 + [0441][Arranging Coins]/src/Solution.java | 84 ++ [0441][Arranging Coins]/src/SolutionTest.java | 35 + .../[0443][String Compression].iml | 21 + [0443][String Compression]/src/Solution.java | 76 ++ .../src/SolutionTest.java | 41 + 25 files changed, 1045 insertions(+), 914 deletions(-) create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/leetcode/editor.xml create mode 100644 [0160][Intersection of Two Linked Lists]/[0160][Intersection of Two Linked Lists].iml create mode 100644 [0160][Intersection of Two Linked Lists]/src/ListNode.java create mode 100644 [0160][Intersection of Two Linked Lists]/src/Solution.java create mode 100644 [0299][Bulls and Cows]/[0299][Bulls and Cows].iml create mode 100644 [0299][Bulls and Cows]/src/Solution.java create mode 100644 [0299][Bulls and Cows]/src/TestSolution.java create mode 100644 [0371][Sum of Two Integers]/[0371][Sum of Two Integers].iml create mode 100644 [0371][Sum of Two Integers]/src/Solution.java create mode 100644 [0371][Sum of Two Integers]/src/SolutionTest.java create mode 100644 [0392][Is Subsequence]/[0392][Is Subsequence].iml create mode 100644 [0392][Is Subsequence]/src/Solution.java create mode 100644 [0392][Is Subsequence]/src/SolutionTest.java create mode 100644 [0441][Arranging Coins]/[0441][Arranging Coins].iml create mode 100644 [0441][Arranging Coins]/src/Solution.java create mode 100644 [0441][Arranging Coins]/src/SolutionTest.java create mode 100644 [0443][String Compression]/[0443][String Compression].iml create mode 100644 [0443][String Compression]/src/Solution.java create mode 100644 [0443][String Compression]/src/SolutionTest.java diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml index f468859..a444e6c 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -125,6 +125,7 @@ + diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/leetcode/editor.xml b/.idea/leetcode/editor.xml new file mode 100644 index 0000000..27dc992 --- /dev/null +++ b/.idea/leetcode/editor.xml @@ -0,0 +1,57 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index 2b7023a..1268fe5 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -146,6 +146,7 @@ + @@ -190,6 +191,7 @@ + @@ -200,11 +202,13 @@ + + @@ -219,7 +223,9 @@ + + diff --git a/.idea/workspace.xml b/.idea/workspace.xml index e736be2..f0fc058 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,140 +1,44 @@ - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - excludeEnd2 - 28 - *c - 83794 - gray code - gas stat - vec - atoi - /[ - [ - ] - - - ] - nums1.length - nums2.length - nums[a] - nums[b] - nums[c] - array - /[0 - { - } - - - $PROJECT_DIR$/[128][Longest Consecutive Sequence]/src - $PROJECT_DIR$/[0500][Keyboard Row]/src - - - - - - - - - -