cur = mIterators.get(mCurIdx);
-
- if (cur.hasNext()) {
- return true;
- }
- mIterators.remove(mCurIdx);
- }
- return false;
- }
-}
diff --git a/gradle.properties b/gradle.properties
deleted file mode 100644
index aac7c9b..0000000
--- a/gradle.properties
+++ /dev/null
@@ -1,17 +0,0 @@
-# Project-wide Gradle settings.
-
-# IDE (e.g. Android Studio) users:
-# Gradle settings configured through the IDE *will override*
-# any settings specified in this file.
-
-# For more details on how to configure your build environment visit
-# http://www.gradle.org/docs/current/userguide/build_environment.html
-
-# Specifies the JVM arguments used for the daemon process.
-# The setting is particularly useful for tweaking memory settings.
-org.gradle.jvmargs=-Xmx1536m
-
-# When configured, Gradle will run in incubating parallel mode.
-# This option should only be used with decoupled projects. More details, visit
-# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
-# org.gradle.parallel=true
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
deleted file mode 100644
index 13372ae..0000000
Binary files a/gradle/wrapper/gradle-wrapper.jar and /dev/null differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
deleted file mode 100644
index c7a4e33..0000000
--- a/gradle/wrapper/gradle-wrapper.properties
+++ /dev/null
@@ -1,6 +0,0 @@
-#Mon Mar 20 10:01:35 CST 2017
-distributionBase=GRADLE_USER_HOME
-distributionPath=wrapper/dists
-zipStoreBase=GRADLE_USER_HOME
-zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-4.3.1-all.zip
diff --git a/gradlew b/gradlew
deleted file mode 100644
index 9d82f78..0000000
--- a/gradlew
+++ /dev/null
@@ -1,160 +0,0 @@
-#!/usr/bin/env bash
-
-##############################################################################
-##
-## Gradle start up script for UN*X
-##
-##############################################################################
-
-# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-DEFAULT_JVM_OPTS=""
-
-APP_NAME="Gradle"
-APP_BASE_NAME=`basename "$0"`
-
-# Use the maximum available, or set MAX_FD != -1 to use that value.
-MAX_FD="maximum"
-
-warn ( ) {
- echo "$*"
-}
-
-die ( ) {
- echo
- echo "$*"
- echo
- exit 1
-}
-
-# OS specific support (must be 'true' or 'false').
-cygwin=false
-msys=false
-darwin=false
-case "`uname`" in
- CYGWIN* )
- cygwin=true
- ;;
- Darwin* )
- darwin=true
- ;;
- MINGW* )
- msys=true
- ;;
-esac
-
-# Attempt to set APP_HOME
-# Resolve links: $0 may be a link
-PRG="$0"
-# Need this for relative symlinks.
-while [ -h "$PRG" ] ; do
- ls=`ls -ld "$PRG"`
- link=`expr "$ls" : '.*-> \(.*\)$'`
- if expr "$link" : '/.*' > /dev/null; then
- PRG="$link"
- else
- PRG=`dirname "$PRG"`"/$link"
- fi
-done
-SAVED="`pwd`"
-cd "`dirname \"$PRG\"`/" >/dev/null
-APP_HOME="`pwd -P`"
-cd "$SAVED" >/dev/null
-
-CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
-
-# Determine the Java command to use to start the JVM.
-if [ -n "$JAVA_HOME" ] ; then
- if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
- # IBM's JDK on AIX uses strange locations for the executables
- JAVACMD="$JAVA_HOME/jre/sh/java"
- else
- JAVACMD="$JAVA_HOME/bin/java"
- fi
- if [ ! -x "$JAVACMD" ] ; then
- die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
-
-Please set the JAVA_HOME variable in your environment to match the
-location of your Java installation."
- fi
-else
- JAVACMD="java"
- which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
-
-Please set the JAVA_HOME variable in your environment to match the
-location of your Java installation."
-fi
-
-# Increase the maximum file descriptors if we can.
-if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
- MAX_FD_LIMIT=`ulimit -H -n`
- if [ $? -eq 0 ] ; then
- if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
- MAX_FD="$MAX_FD_LIMIT"
- fi
- ulimit -n $MAX_FD
- if [ $? -ne 0 ] ; then
- warn "Could not set maximum file descriptor limit: $MAX_FD"
- fi
- else
- warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
- fi
-fi
-
-# For Darwin, add options to specify how the application appears in the dock
-if $darwin; then
- GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
-fi
-
-# For Cygwin, switch paths to Windows format before running java
-if $cygwin ; then
- APP_HOME=`cygpath --path --mixed "$APP_HOME"`
- CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
- JAVACMD=`cygpath --unix "$JAVACMD"`
-
- # We build the pattern for arguments to be converted via cygpath
- ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
- SEP=""
- for dir in $ROOTDIRSRAW ; do
- ROOTDIRS="$ROOTDIRS$SEP$dir"
- SEP="|"
- done
- OURCYGPATTERN="(^($ROOTDIRS))"
- # Add a user-defined pattern to the cygpath arguments
- if [ "$GRADLE_CYGPATTERN" != "" ] ; then
- OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
- fi
- # Now convert the arguments - kludge to limit ourselves to /bin/sh
- i=0
- for arg in "$@" ; do
- CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
- CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
-
- if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
- eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
- else
- eval `echo args$i`="\"$arg\""
- fi
- i=$((i+1))
- done
- case $i in
- (0) set -- ;;
- (1) set -- "$args0" ;;
- (2) set -- "$args0" "$args1" ;;
- (3) set -- "$args0" "$args1" "$args2" ;;
- (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
- (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
- (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
- (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
- (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
- (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
- esac
-fi
-
-# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
-function splitJvmOpts() {
- JVM_OPTS=("$@")
-}
-eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
-JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
-
-exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/gradlew.bat b/gradlew.bat
deleted file mode 100644
index 8a0b282..0000000
--- a/gradlew.bat
+++ /dev/null
@@ -1,90 +0,0 @@
-@if "%DEBUG%" == "" @echo off
-@rem ##########################################################################
-@rem
-@rem Gradle startup script for Windows
-@rem
-@rem ##########################################################################
-
-@rem Set local scope for the variables with windows NT shell
-if "%OS%"=="Windows_NT" setlocal
-
-@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-set DEFAULT_JVM_OPTS=
-
-set DIRNAME=%~dp0
-if "%DIRNAME%" == "" set DIRNAME=.
-set APP_BASE_NAME=%~n0
-set APP_HOME=%DIRNAME%
-
-@rem Find java.exe
-if defined JAVA_HOME goto findJavaFromJavaHome
-
-set JAVA_EXE=java.exe
-%JAVA_EXE% -version >NUL 2>&1
-if "%ERRORLEVEL%" == "0" goto init
-
-echo.
-echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
-
-goto fail
-
-:findJavaFromJavaHome
-set JAVA_HOME=%JAVA_HOME:"=%
-set JAVA_EXE=%JAVA_HOME%/bin/java.exe
-
-if exist "%JAVA_EXE%" goto init
-
-echo.
-echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
-
-goto fail
-
-:init
-@rem Get command-line arguments, handling Windowz variants
-
-if not "%OS%" == "Windows_NT" goto win9xME_args
-if "%@eval[2+2]" == "4" goto 4NT_args
-
-:win9xME_args
-@rem Slurp the command line arguments.
-set CMD_LINE_ARGS=
-set _SKIP=2
-
-:win9xME_args_slurp
-if "x%~1" == "x" goto execute
-
-set CMD_LINE_ARGS=%*
-goto execute
-
-:4NT_args
-@rem Get arguments from the 4NT Shell from JP Software
-set CMD_LINE_ARGS=%$
-
-:execute
-@rem Setup the command line
-
-set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
-
-@rem Execute Gradle
-"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
-
-:end
-@rem End local scope for the variables with windows NT shell
-if "%ERRORLEVEL%"=="0" goto mainEnd
-
-:fail
-rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
-rem the _cmd.exe /c_ return code!
-if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
-exit /b 1
-
-:mainEnd
-if "%OS%"=="Windows_NT" endlocal
-
-:omega
diff --git a/leetcode.iml b/leetcode.iml
deleted file mode 100644
index ce86a2c..0000000
--- a/leetcode.iml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/leetcode/common/common.iml b/leetcode/common/common.iml
new file mode 100644
index 0000000..c90834f
--- /dev/null
+++ b/leetcode/common/common.iml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/library/src/main/java/com/leetcode/library/CommonUtils.java b/leetcode/common/src/CommonUtils.java
similarity index 77%
rename from library/src/main/java/com/leetcode/library/CommonUtils.java
rename to leetcode/common/src/CommonUtils.java
index f40173c..4e25df5 100644
--- a/library/src/main/java/com/leetcode/library/CommonUtils.java
+++ b/leetcode/common/src/CommonUtils.java
@@ -1,9 +1,3 @@
-package com.leetcode.library;
-
-/**
- * Created by dingjikerbo on 2016/12/12.
- */
-
public class CommonUtils {
diff --git a/library/src/main/java/com/leetcode/library/Interval.java b/leetcode/common/src/Interval.java
similarity index 76%
rename from library/src/main/java/com/leetcode/library/Interval.java
rename to leetcode/common/src/Interval.java
index b1e3dd6..749239e 100644
--- a/library/src/main/java/com/leetcode/library/Interval.java
+++ b/leetcode/common/src/Interval.java
@@ -1,9 +1,3 @@
-package com.leetcode.library;
-
-/**
- * Created by dingjikerbo on 16/11/20.
- */
-
/**
* Definition for an interval.
*/
diff --git a/library/src/main/java/com/leetcode/library/ListNode.java b/leetcode/common/src/ListNode.java
similarity index 83%
rename from library/src/main/java/com/leetcode/library/ListNode.java
rename to leetcode/common/src/ListNode.java
index 7902529..02be290 100644
--- a/library/src/main/java/com/leetcode/library/ListNode.java
+++ b/leetcode/common/src/ListNode.java
@@ -1,9 +1,3 @@
-package com.leetcode.library;
-
-/**
- * Created by dingjikerbo on 2016/11/16.
- */
-
public class ListNode {
public int val;
diff --git a/library/src/main/java/com/leetcode/library/NestedInteger.java b/leetcode/common/src/NestedInteger.java
similarity index 87%
rename from library/src/main/java/com/leetcode/library/NestedInteger.java
rename to leetcode/common/src/NestedInteger.java
index ce8f1d3..39cb29e 100644
--- a/library/src/main/java/com/leetcode/library/NestedInteger.java
+++ b/leetcode/common/src/NestedInteger.java
@@ -1,11 +1,5 @@
-package com.leetcode.library;
-
import java.util.List;
-/**
- * Created by dingjikerbo on 2016/11/22.
- */
-
public interface NestedInteger {
// @return true if this NestedInteger holds a single integer, rather than a nested list.
diff --git a/library/src/main/java/com/leetcode/library/Point.java b/leetcode/common/src/Point.java
similarity index 87%
rename from library/src/main/java/com/leetcode/library/Point.java
rename to leetcode/common/src/Point.java
index aeda913..991a20a 100644
--- a/library/src/main/java/com/leetcode/library/Point.java
+++ b/leetcode/common/src/Point.java
@@ -1,9 +1,3 @@
-package com.leetcode.library;
-
-/**
- * Created by dingjikerbo on 16/12/7.
- */
-
class Point {
int x;
int y;
diff --git a/library/src/main/java/com/leetcode/library/RandomListNode.java b/leetcode/common/src/RandomListNode.java
similarity index 68%
rename from library/src/main/java/com/leetcode/library/RandomListNode.java
rename to leetcode/common/src/RandomListNode.java
index e3eb267..8816baa 100644
--- a/library/src/main/java/com/leetcode/library/RandomListNode.java
+++ b/leetcode/common/src/RandomListNode.java
@@ -1,9 +1,3 @@
-package com.leetcode.library;
-
-/**
- * Created by liwentian on 17/8/9.
- */
-
public class RandomListNode {
public int label;
public RandomListNode next, random;
diff --git a/library/src/main/java/com/leetcode/library/TreeLinkNode.java b/leetcode/common/src/TreeLinkNode.java
similarity index 72%
rename from library/src/main/java/com/leetcode/library/TreeLinkNode.java
rename to leetcode/common/src/TreeLinkNode.java
index d1122b3..0b21dca 100644
--- a/library/src/main/java/com/leetcode/library/TreeLinkNode.java
+++ b/leetcode/common/src/TreeLinkNode.java
@@ -1,9 +1,3 @@
-package com.leetcode.library;
-
-/**
- * Created by dingjikerbo on 16/11/23.
- */
-
/**
* Definition for binary tree with next pointer.
*/
diff --git a/library/src/main/java/com/leetcode/library/TreeNode.java b/leetcode/common/src/TreeNode.java
similarity index 93%
rename from library/src/main/java/com/leetcode/library/TreeNode.java
rename to leetcode/common/src/TreeNode.java
index e028f26..6a1f777 100644
--- a/library/src/main/java/com/leetcode/library/TreeNode.java
+++ b/leetcode/common/src/TreeNode.java
@@ -1,9 +1,3 @@
-package com.leetcode.library;
-
-/**
- * Created by dingjikerbo on 2016/11/16.
- */
-
public class TreeNode {
public int val;
diff --git a/library/src/main/java/com/leetcode/library/TrieNode.java b/leetcode/common/src/TrieNode.java
similarity index 64%
rename from library/src/main/java/com/leetcode/library/TrieNode.java
rename to leetcode/common/src/TrieNode.java
index 5053139..58a80df 100644
--- a/library/src/main/java/com/leetcode/library/TrieNode.java
+++ b/leetcode/common/src/TrieNode.java
@@ -1,9 +1,3 @@
-package com.leetcode.library;
-
-/**
- * Created by dingjikerbo on 2016/11/22.
- */
-
public class TrieNode {
public TrieNode[] nodes;
diff --git a/library/src/main/java/com/leetcode/library/UndirectedGraphNode.java b/leetcode/common/src/UndirectedGraphNode.java
similarity index 78%
rename from library/src/main/java/com/leetcode/library/UndirectedGraphNode.java
rename to leetcode/common/src/UndirectedGraphNode.java
index 068b8c6..5193303 100644
--- a/library/src/main/java/com/leetcode/library/UndirectedGraphNode.java
+++ b/leetcode/common/src/UndirectedGraphNode.java
@@ -1,12 +1,6 @@
-package com.leetcode.library;
-
import java.util.ArrayList;
import java.util.List;
-/**
- * Created by dingjikerbo on 16/12/19.
- */
-
public class UndirectedGraphNode {
public int label;
diff --git a/leetcode/common/src/Utils.java b/leetcode/common/src/Utils.java
new file mode 100644
index 0000000..fdedf69
--- /dev/null
+++ b/leetcode/common/src/Utils.java
@@ -0,0 +1,10 @@
+public class Utils {
+
+ public static int max(int... val) {
+ int max = Integer.MIN_VALUE;
+ for (int k : val) {
+ max = Math.max(max, k);
+ }
+ return max;
+ }
+}
diff --git a/leetcode/leetcode.iml b/leetcode/leetcode.iml
new file mode 100644
index 0000000..da061d4
--- /dev/null
+++ b/leetcode/leetcode.iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/leetcode/solution/solution.iml b/leetcode/solution/solution.iml
new file mode 100644
index 0000000..99e828d
--- /dev/null
+++ b/leetcode/solution/solution.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/solution/src/main/java/com/inuker/solution/AddBinary.java b/leetcode/solution/src/AddBinary.java
similarity index 85%
rename from solution/src/main/java/com/inuker/solution/AddBinary.java
rename to leetcode/solution/src/AddBinary.java
index 95f4c5b..e94a5ae 100644
--- a/solution/src/main/java/com/inuker/solution/AddBinary.java
+++ b/leetcode/solution/src/AddBinary.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/11/19.
- */
-
public class AddBinary {
public String addBinary(String a, String b) {
diff --git a/solution/src/main/java/com/inuker/solution/AddTwoNumber.java b/leetcode/solution/src/AddTwoNumber.java
similarity index 83%
rename from solution/src/main/java/com/inuker/solution/AddTwoNumber.java
rename to leetcode/solution/src/AddTwoNumber.java
index 42c3576..9469ff4 100644
--- a/solution/src/main/java/com/inuker/solution/AddTwoNumber.java
+++ b/leetcode/solution/src/AddTwoNumber.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import com.leetcode.library.ListNode;
-
-/**
- * Created by dingjikerbo on 2016/11/17.
- */
-
public class AddTwoNumber {
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
diff --git a/solution/src/main/java/com/inuker/solution/AddTwoNumbersII.java b/leetcode/solution/src/AddTwoNumbersII.java
similarity index 87%
rename from solution/src/main/java/com/inuker/solution/AddTwoNumbersII.java
rename to leetcode/solution/src/AddTwoNumbersII.java
index 7331e93..08ca684 100644
--- a/solution/src/main/java/com/inuker/solution/AddTwoNumbersII.java
+++ b/leetcode/solution/src/AddTwoNumbersII.java
@@ -1,13 +1,5 @@
-package com.inuker.solution;
-
-import com.leetcode.library.ListNode;
-
import java.util.Stack;
-/**
- * Created by liwentian on 2017/9/11.
- */
-
public class AddTwoNumbersII {
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
diff --git a/solution/src/main/java/com/inuker/solution/AlienDictionary.java b/leetcode/solution/src/AlienDictionary.java
similarity index 93%
rename from solution/src/main/java/com/inuker/solution/AlienDictionary.java
rename to leetcode/solution/src/AlienDictionary.java
index 8c45184..6fd8f05 100644
--- a/solution/src/main/java/com/inuker/solution/AlienDictionary.java
+++ b/leetcode/solution/src/AlienDictionary.java
@@ -1,14 +1,6 @@
-package com.inuker.solution;
-
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.Queue;
-import java.util.Set;
+import java.util.*;
/**
- * Created by dingjikerbo on 16/12/17.
*
* TestCases
* "z", "z" => "z"
diff --git a/solution/src/main/java/com/inuker/solution/AndroidUnlockPatterns.java b/leetcode/solution/src/AndroidUnlockPatterns.java
similarity index 95%
rename from solution/src/main/java/com/inuker/solution/AndroidUnlockPatterns.java
rename to leetcode/solution/src/AndroidUnlockPatterns.java
index e3790fb..6912537 100644
--- a/solution/src/main/java/com/inuker/solution/AndroidUnlockPatterns.java
+++ b/leetcode/solution/src/AndroidUnlockPatterns.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by liwentian on 2017/9/6.
- */
-
/**
* https://leetcode.com/articles/android-unlock-patterns/
*/
diff --git a/solution/src/main/java/com/inuker/solution/AverageOfLevelsInBinaryTree.java b/leetcode/solution/src/AverageOfLevelsInBinaryTree.java
similarity index 89%
rename from solution/src/main/java/com/inuker/solution/AverageOfLevelsInBinaryTree.java
rename to leetcode/solution/src/AverageOfLevelsInBinaryTree.java
index ff9b246..1324566 100644
--- a/solution/src/main/java/com/inuker/solution/AverageOfLevelsInBinaryTree.java
+++ b/leetcode/solution/src/AverageOfLevelsInBinaryTree.java
@@ -1,15 +1,7 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
-/**
- * Created by dingjikerbo on 2017/7/22.
- */
-
public class AverageOfLevelsInBinaryTree {
public List averageOfLevels(TreeNode root) {
diff --git a/solution/src/main/java/com/inuker/solution/BSTIterator.java b/leetcode/solution/src/BSTIterator.java
similarity index 92%
rename from solution/src/main/java/com/inuker/solution/BSTIterator.java
rename to leetcode/solution/src/BSTIterator.java
index a3dc689..e484df4 100644
--- a/solution/src/main/java/com/inuker/solution/BSTIterator.java
+++ b/leetcode/solution/src/BSTIterator.java
@@ -1,13 +1,5 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
import java.util.Stack;
-/**
- * Created by dingjikerbo on 16/11/21.
- */
-
public class BSTIterator {
private Stack mStack;
diff --git a/solution/src/main/java/com/inuker/solution/BalancedBinaryTree.java b/leetcode/solution/src/BalancedBinaryTree.java
similarity index 85%
rename from solution/src/main/java/com/inuker/solution/BalancedBinaryTree.java
rename to leetcode/solution/src/BalancedBinaryTree.java
index 525fe8a..0e88812 100644
--- a/solution/src/main/java/com/inuker/solution/BalancedBinaryTree.java
+++ b/leetcode/solution/src/BalancedBinaryTree.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/11/28.
- */
-
-import com.leetcode.library.TreeNode;
-
/**
* 平衡二叉树条件是左边是平衡,右边是平衡,且两边高度差相差不超过1
* 树的高度是所有子树的最大高度
diff --git a/solution/src/main/java/com/inuker/solution/BasicCalculator.java b/leetcode/solution/src/BasicCalculator.java
similarity index 94%
rename from solution/src/main/java/com/inuker/solution/BasicCalculator.java
rename to leetcode/solution/src/BasicCalculator.java
index 51194d3..a246d72 100644
--- a/solution/src/main/java/com/inuker/solution/BasicCalculator.java
+++ b/leetcode/solution/src/BasicCalculator.java
@@ -1,11 +1,5 @@
-package com.inuker.solution;
-
import java.util.Stack;
-/**
- * Created by liwentian on 2017/9/12.
- */
-
public class BasicCalculator {
public int calculate(String s) {
diff --git a/solution/src/main/java/com/inuker/solution/BeautifulArrangement.java b/leetcode/solution/src/BeautifulArrangement.java
similarity index 89%
rename from solution/src/main/java/com/inuker/solution/BeautifulArrangement.java
rename to leetcode/solution/src/BeautifulArrangement.java
index de49e8b..8c7ebb0 100644
--- a/solution/src/main/java/com/inuker/solution/BeautifulArrangement.java
+++ b/leetcode/solution/src/BeautifulArrangement.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by liwentian on 2017/9/6.
- */
-
/**
* https://leetcode.com/articles/beautiful-arrangement/
*/
diff --git a/solution/src/main/java/com/inuker/solution/BestTimeBuySellStock.java b/leetcode/solution/src/BestTimeBuySellStock.java
similarity index 87%
rename from solution/src/main/java/com/inuker/solution/BestTimeBuySellStock.java
rename to leetcode/solution/src/BestTimeBuySellStock.java
index 19fd88f..8661ea7 100644
--- a/solution/src/main/java/com/inuker/solution/BestTimeBuySellStock.java
+++ b/leetcode/solution/src/BestTimeBuySellStock.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/11/17.
- */
-
/**
* https://leetcode.com/articles/best-time-buy-and-sell-stock/
*/
diff --git a/solution/src/main/java/com/inuker/solution/BestTimeBuySellStockII.java b/leetcode/solution/src/BestTimeBuySellStockII.java
similarity index 82%
rename from solution/src/main/java/com/inuker/solution/BestTimeBuySellStockII.java
rename to leetcode/solution/src/BestTimeBuySellStockII.java
index c26588f..4428037 100644
--- a/solution/src/main/java/com/inuker/solution/BestTimeBuySellStockII.java
+++ b/leetcode/solution/src/BestTimeBuySellStockII.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/11/17.
- */
-
/**
* https://leetcode.com/articles/best-time-buy-and-sell-stock-ii/
*/
diff --git a/solution/src/main/java/com/inuker/solution/BestTimeBuySellStockIII.java b/leetcode/solution/src/BestTimeBuySellStockIII.java
similarity index 89%
rename from solution/src/main/java/com/inuker/solution/BestTimeBuySellStockIII.java
rename to leetcode/solution/src/BestTimeBuySellStockIII.java
index 7505fe0..f97d430 100644
--- a/solution/src/main/java/com/inuker/solution/BestTimeBuySellStockIII.java
+++ b/leetcode/solution/src/BestTimeBuySellStockIII.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/11/17.
- */
-
-/**
- */
public class BestTimeBuySellStockIII {
public int maxProfit(int[] prices) {
diff --git a/solution/src/main/java/com/inuker/solution/BestTimeBuySellStockIV.java b/leetcode/solution/src/BestTimeBuySellStockIV.java
similarity index 90%
rename from solution/src/main/java/com/inuker/solution/BestTimeBuySellStockIV.java
rename to leetcode/solution/src/BestTimeBuySellStockIV.java
index 62733db..72e784e 100644
--- a/solution/src/main/java/com/inuker/solution/BestTimeBuySellStockIV.java
+++ b/leetcode/solution/src/BestTimeBuySellStockIV.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/11/17.
- */
-
-/**
- */
public class BestTimeBuySellStockIV {
public int maxProfit(int k, int[] prices) {
diff --git a/solution/src/main/java/com/inuker/solution/BestTimeBuySellStockWithCoolDown.java b/leetcode/solution/src/BestTimeBuySellStockWithCoolDown.java
similarity index 82%
rename from solution/src/main/java/com/inuker/solution/BestTimeBuySellStockWithCoolDown.java
rename to leetcode/solution/src/BestTimeBuySellStockWithCoolDown.java
index ad799c9..e0acc92 100644
--- a/solution/src/main/java/com/inuker/solution/BestTimeBuySellStockWithCoolDown.java
+++ b/leetcode/solution/src/BestTimeBuySellStockWithCoolDown.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/11/17.
- */
-
-/**
- */
public class BestTimeBuySellStockWithCoolDown {
public int maxProfit(int[] prices) {
diff --git a/solution/src/main/java/com/inuker/solution/BinaryTreeInorderTraversal.java b/leetcode/solution/src/BinaryTreeInorderTraversal.java
similarity index 93%
rename from solution/src/main/java/com/inuker/solution/BinaryTreeInorderTraversal.java
rename to leetcode/solution/src/BinaryTreeInorderTraversal.java
index 4b65895..f7cc6c1 100644
--- a/solution/src/main/java/com/inuker/solution/BinaryTreeInorderTraversal.java
+++ b/leetcode/solution/src/BinaryTreeInorderTraversal.java
@@ -1,14 +1,10 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
/**
- * Created by dingjikerbo on 16/12/1.
+ * https://leetcode.com/articles/binary-tree-inorder-traversal/
*/
public class BinaryTreeInorderTraversal {
diff --git a/solution/src/main/java/com/inuker/solution/BinaryTreeLevelOrderTraversal.java b/leetcode/solution/src/BinaryTreeLevelOrderTraversal.java
similarity index 90%
rename from solution/src/main/java/com/inuker/solution/BinaryTreeLevelOrderTraversal.java
rename to leetcode/solution/src/BinaryTreeLevelOrderTraversal.java
index 4b8e235..f132a20 100644
--- a/solution/src/main/java/com/inuker/solution/BinaryTreeLevelOrderTraversal.java
+++ b/leetcode/solution/src/BinaryTreeLevelOrderTraversal.java
@@ -1,15 +1,7 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
-/**
- * Created by dingjikerbo on 2016/11/17.
- */
-
public class BinaryTreeLevelOrderTraversal {
// 耗时2ms
diff --git a/amazon/src/main/java/com/leetcode/amazon/BinaryTreeLevelOrderTraversal.java b/leetcode/solution/src/BinaryTreeLevelOrderTraversalII.java
similarity index 66%
rename from amazon/src/main/java/com/leetcode/amazon/BinaryTreeLevelOrderTraversal.java
rename to leetcode/solution/src/BinaryTreeLevelOrderTraversalII.java
index 470d700..f14eb4c 100644
--- a/amazon/src/main/java/com/leetcode/amazon/BinaryTreeLevelOrderTraversal.java
+++ b/leetcode/solution/src/BinaryTreeLevelOrderTraversalII.java
@@ -1,18 +1,12 @@
-package com.leetcode.amazon;
-
-import com.leetcode.library.TreeNode;
-
+import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
-/**
- * Created by liwentian on 17/8/12.
- */
-
-public class BinaryTreeLevelOrderTraversal {
+public class BinaryTreeLevelOrderTraversalII {
- public List> levelOrder(TreeNode root) {
+ // 耗时2ms,和I一样,只不过加到result时添加到头
+ public List> levelOrderBottom(TreeNode root) {
List> result = new LinkedList<>();
if (root == null) {
@@ -22,36 +16,33 @@ public List> levelOrder(TreeNode root) {
Queue queue = new LinkedList<>();
Queue next = new LinkedList<>();
- queue.add(root);
-
List list = null;
+ queue.offer(root);
+
while (!queue.isEmpty()) {
TreeNode node = queue.poll();
if (list == null) {
- list = new LinkedList<>();
+ list = new ArrayList<>();
}
list.add(node.val);
if (node.left != null) {
- next.add(node.left);
+ next.offer(node.left);
}
-
if (node.right != null) {
- next.add(node.right);
+ next.offer(node.right);
}
if (queue.isEmpty()) {
- result.add(list);
- list = null;
-
queue.addAll(next);
next.clear();
+ result.add(0, list);
+ list = null;
}
}
-
return result;
}
}
diff --git a/solution/src/main/java/com/inuker/solution/BinaryTreeLongestConsecutiveSequence.java b/leetcode/solution/src/BinaryTreeLongestConsecutiveSequence.java
similarity index 86%
rename from solution/src/main/java/com/inuker/solution/BinaryTreeLongestConsecutiveSequence.java
rename to leetcode/solution/src/BinaryTreeLongestConsecutiveSequence.java
index a766b34..611244b 100644
--- a/solution/src/main/java/com/inuker/solution/BinaryTreeLongestConsecutiveSequence.java
+++ b/leetcode/solution/src/BinaryTreeLongestConsecutiveSequence.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/12/2.
- */
-
-import com.leetcode.library.TreeNode;
-
/**
* https://leetcode.com/articles/binary-tree-longest-consecutive-sequence/
*/
diff --git a/solution/src/main/java/com/inuker/solution/BinaryTreeMaximumPathSum.java b/leetcode/solution/src/BinaryTreeMaximumPathSum.java
similarity index 90%
rename from solution/src/main/java/com/inuker/solution/BinaryTreeMaximumPathSum.java
rename to leetcode/solution/src/BinaryTreeMaximumPathSum.java
index e67097c..d7159b2 100644
--- a/solution/src/main/java/com/inuker/solution/BinaryTreeMaximumPathSum.java
+++ b/leetcode/solution/src/BinaryTreeMaximumPathSum.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/11/28.
- */
-
-import com.leetcode.library.TreeNode;
-
/**
* 单边的或者双边的,或只包含根节点的
*/
diff --git a/solution/src/main/java/com/inuker/solution/BinaryTreePaths.java b/leetcode/solution/src/BinaryTreePaths.java
similarity index 85%
rename from solution/src/main/java/com/inuker/solution/BinaryTreePaths.java
rename to leetcode/solution/src/BinaryTreePaths.java
index 1a919b5..a09e484 100644
--- a/solution/src/main/java/com/inuker/solution/BinaryTreePaths.java
+++ b/leetcode/solution/src/BinaryTreePaths.java
@@ -1,14 +1,6 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by dingjikerbo on 16/11/20.
- */
-
public class BinaryTreePaths {
// 耗时2ms
diff --git a/solution/src/main/java/com/inuker/solution/BinaryTreePostorderTraversal.java b/leetcode/solution/src/BinaryTreePostorderTraversal.java
similarity index 89%
rename from solution/src/main/java/com/inuker/solution/BinaryTreePostorderTraversal.java
rename to leetcode/solution/src/BinaryTreePostorderTraversal.java
index 019889b..2d9558b 100644
--- a/solution/src/main/java/com/inuker/solution/BinaryTreePostorderTraversal.java
+++ b/leetcode/solution/src/BinaryTreePostorderTraversal.java
@@ -1,16 +1,8 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by dingjikerbo on 16/12/1.
- */
-
public class BinaryTreePostorderTraversal {
/**
diff --git a/solution/src/main/java/com/inuker/solution/BinaryTreePreorderTraversal.java b/leetcode/solution/src/BinaryTreePreorderTraversal.java
similarity index 84%
rename from solution/src/main/java/com/inuker/solution/BinaryTreePreorderTraversal.java
rename to leetcode/solution/src/BinaryTreePreorderTraversal.java
index e88e4be..891c8e3 100644
--- a/solution/src/main/java/com/inuker/solution/BinaryTreePreorderTraversal.java
+++ b/leetcode/solution/src/BinaryTreePreorderTraversal.java
@@ -1,16 +1,8 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
-/**
- * Created by dingjikerbo on 16/12/1.
- */
-
public class BinaryTreePreorderTraversal {
public List preorderTraversal(TreeNode root) {
diff --git a/amazon/src/main/java/com/leetcode/amazon/BinaryTreeRightSideView.java b/leetcode/solution/src/BinaryTreeRightSideView.java
similarity index 72%
rename from amazon/src/main/java/com/leetcode/amazon/BinaryTreeRightSideView.java
rename to leetcode/solution/src/BinaryTreeRightSideView.java
index 62ff01d..4a8dcc8 100644
--- a/amazon/src/main/java/com/leetcode/amazon/BinaryTreeRightSideView.java
+++ b/leetcode/solution/src/BinaryTreeRightSideView.java
@@ -1,31 +1,28 @@
-package com.leetcode.amazon;
-
-import com.leetcode.library.TreeNode;
-
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
-/**
- * Created by liwentian on 17/8/12.
- */
-
public class BinaryTreeRightSideView {
public List rightSideView(TreeNode root) {
- List list = new LinkedList<>();
+ List result = new LinkedList<>();
if (root == null) {
- return list;
+ return result;
}
Queue queue = new LinkedList<>();
Queue next = new LinkedList<>();
- queue.add(root);
+
+ TreeNode last = null;
+
+ queue.offer(root);
while (!queue.isEmpty()) {
TreeNode node = queue.poll();
+ last = node;
+
if (node.left != null) {
next.offer(node.left);
}
@@ -35,13 +32,12 @@ public List rightSideView(TreeNode root) {
}
if (queue.isEmpty()) {
- list.add(node.val);
-
queue.addAll(next);
next.clear();
+ result.add(last.val);
}
}
- return list;
+ return result;
}
}
diff --git a/solution/src/main/java/com/inuker/solution/BinaryTreeUpsideDown.java b/leetcode/solution/src/BinaryTreeUpsideDown.java
similarity index 84%
rename from solution/src/main/java/com/inuker/solution/BinaryTreeUpsideDown.java
rename to leetcode/solution/src/BinaryTreeUpsideDown.java
index 6dedc73..f86829c 100644
--- a/solution/src/main/java/com/inuker/solution/BinaryTreeUpsideDown.java
+++ b/leetcode/solution/src/BinaryTreeUpsideDown.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
-/**
- * Created by dingjikerbo on 16/12/2.
- */
-
public class BinaryTreeUpsideDown {
/**
diff --git a/solution/src/main/java/com/inuker/solution/BinaryTreeVerticalOrderTraversal.java b/leetcode/solution/src/BinaryTreeVerticalOrderTraversal.java
similarity index 92%
rename from solution/src/main/java/com/inuker/solution/BinaryTreeVerticalOrderTraversal.java
rename to leetcode/solution/src/BinaryTreeVerticalOrderTraversal.java
index 7440106..79365f5 100644
--- a/solution/src/main/java/com/inuker/solution/BinaryTreeVerticalOrderTraversal.java
+++ b/leetcode/solution/src/BinaryTreeVerticalOrderTraversal.java
@@ -1,16 +1,8 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
-/**
- * Created by dingjikerbo on 2016/11/19.
- */
-
public class BinaryTreeVerticalOrderTraversal {
private int minKey = 0, maxKey = 0;
diff --git a/solution/src/main/java/com/inuker/solution/BinaryTreeZigzagLevelOrderTraversal.java b/leetcode/solution/src/BinaryTreeZigzagLevelOrderTraversal.java
similarity index 91%
rename from solution/src/main/java/com/inuker/solution/BinaryTreeZigzagLevelOrderTraversal.java
rename to leetcode/solution/src/BinaryTreeZigzagLevelOrderTraversal.java
index 5175477..8641f80 100644
--- a/solution/src/main/java/com/inuker/solution/BinaryTreeZigzagLevelOrderTraversal.java
+++ b/leetcode/solution/src/BinaryTreeZigzagLevelOrderTraversal.java
@@ -1,14 +1,6 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by dingjikerbo on 2016/12/2.
- */
-
public class BinaryTreeZigzagLevelOrderTraversal {
public List> zigzagLevelOrder(TreeNode root) {
diff --git a/solution/src/main/java/com/inuker/solution/BinaryWatch.java b/leetcode/solution/src/BinaryWatch.java
similarity index 92%
rename from solution/src/main/java/com/inuker/solution/BinaryWatch.java
rename to leetcode/solution/src/BinaryWatch.java
index 4c08f08..d23e246 100644
--- a/solution/src/main/java/com/inuker/solution/BinaryWatch.java
+++ b/leetcode/solution/src/BinaryWatch.java
@@ -1,12 +1,6 @@
-package com.inuker.solution;
-
import java.util.ArrayList;
import java.util.List;
-/**
- * Created by liwentian on 2016/12/29.
- */
-
public class BinaryWatch {
public List readBinaryWatch(int num) {
diff --git a/solution/src/main/java/com/inuker/solution/BombEnemy.java b/leetcode/solution/src/BombEnemy.java
similarity index 93%
rename from solution/src/main/java/com/inuker/solution/BombEnemy.java
rename to leetcode/solution/src/BombEnemy.java
index 2c66aef..0f75d72 100644
--- a/solution/src/main/java/com/inuker/solution/BombEnemy.java
+++ b/leetcode/solution/src/BombEnemy.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/12/11.
- */
-
public class BombEnemy {
public int maxKilledEnemies(char[][] grid) {
diff --git a/solution/src/main/java/com/inuker/solution/BulbSwitcher.java b/leetcode/solution/src/BulbSwitcher.java
similarity index 93%
rename from solution/src/main/java/com/inuker/solution/BulbSwitcher.java
rename to leetcode/solution/src/BulbSwitcher.java
index 499c847..ba9d281 100644
--- a/solution/src/main/java/com/inuker/solution/BulbSwitcher.java
+++ b/leetcode/solution/src/BulbSwitcher.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/12/8.
- */
-
public class BulbSwitcher {
/**
* https://discuss.leetcode.com/topic/39558/share-my-o-1-solution-with-explanation/2
diff --git a/solution/src/main/java/com/inuker/solution/BurstBalloons.java b/leetcode/solution/src/BurstBalloons.java
similarity index 95%
rename from solution/src/main/java/com/inuker/solution/BurstBalloons.java
rename to leetcode/solution/src/BurstBalloons.java
index dc1f2e8..c05a99a 100644
--- a/solution/src/main/java/com/inuker/solution/BurstBalloons.java
+++ b/leetcode/solution/src/BurstBalloons.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/12/21.
- */
-
/**
* 这题用的闭区间DP,dp[start][end]表示区间start,end内所有气球爆掉的最大coin
* 假设最后爆第i个气球,start <= i <= end,则对应的coin为
diff --git a/solution/src/main/java/com/inuker/solution/CanArrangeWords.java b/leetcode/solution/src/CanArrangeWords.java
similarity index 92%
rename from solution/src/main/java/com/inuker/solution/CanArrangeWords.java
rename to leetcode/solution/src/CanArrangeWords.java
index f14128c..a48632a 100644
--- a/solution/src/main/java/com/inuker/solution/CanArrangeWords.java
+++ b/leetcode/solution/src/CanArrangeWords.java
@@ -1,11 +1,5 @@
-package com.inuker.solution;
-
import java.util.HashSet;
-/**
- * Created by dingjikerbo on 2017/9/29.
- */
-
/**
* 单词接龙,前一个单词的尾巴和后一个单词的头相同就算接上了
* 如果要返回接龙的结果,可以给HashSet改成List
diff --git a/solution/src/main/java/com/inuker/solution/CloneGraph.java b/leetcode/solution/src/CloneGraph.java
similarity index 94%
rename from solution/src/main/java/com/inuker/solution/CloneGraph.java
rename to leetcode/solution/src/CloneGraph.java
index bb03431..087d010 100644
--- a/solution/src/main/java/com/inuker/solution/CloneGraph.java
+++ b/leetcode/solution/src/CloneGraph.java
@@ -1,15 +1,7 @@
-package com.inuker.solution;
-
-import com.leetcode.library.UndirectedGraphNode;
-
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
-/**
- * Created by dingjikerbo on 2016/12/21.
- */
-
public class CloneGraph {
/**
diff --git a/solution/src/main/java/com/inuker/solution/ClosestBinarySearchTreeValue.java b/leetcode/solution/src/ClosestBinarySearchTreeValue.java
similarity index 88%
rename from solution/src/main/java/com/inuker/solution/ClosestBinarySearchTreeValue.java
rename to leetcode/solution/src/ClosestBinarySearchTreeValue.java
index 4335590..3a2adf6 100644
--- a/solution/src/main/java/com/inuker/solution/ClosestBinarySearchTreeValue.java
+++ b/leetcode/solution/src/ClosestBinarySearchTreeValue.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
-/**
- * Created by dingjikerbo on 2016/12/2.
- */
-
public class ClosestBinarySearchTreeValue {
public int closestValue(TreeNode root, double target) {
diff --git a/solution/src/main/java/com/inuker/solution/ClosestBinarySearchTreeValueII.java b/leetcode/solution/src/ClosestBinarySearchTreeValueII.java
similarity index 97%
rename from solution/src/main/java/com/inuker/solution/ClosestBinarySearchTreeValueII.java
rename to leetcode/solution/src/ClosestBinarySearchTreeValueII.java
index 2c9c360..41edbf3 100644
--- a/solution/src/main/java/com/inuker/solution/ClosestBinarySearchTreeValueII.java
+++ b/leetcode/solution/src/ClosestBinarySearchTreeValueII.java
@@ -1,16 +1,7 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
-import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
-/**
- * Created by dingjikerbo on 2016/12/2.
- */
-
/**
* 有三种解法:
* 2,中序遍历两遍二叉树,不过每次都会中途退出,构成双栈,一个是大于target,一个是小于target,然后依次出栈满k为止,复杂度O(n + k)
diff --git a/solution/src/main/java/com/inuker/solution/Codec.java b/leetcode/solution/src/Codec.java
similarity index 94%
rename from solution/src/main/java/com/inuker/solution/Codec.java
rename to leetcode/solution/src/Codec.java
index d1d7d90..588c86e 100644
--- a/solution/src/main/java/com/inuker/solution/Codec.java
+++ b/leetcode/solution/src/Codec.java
@@ -1,16 +1,4 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
-import java.util.Arrays;
-import java.util.Deque;
-import java.util.LinkedList;
-import java.util.Queue;
-import java.util.Stack;
-
-/**
- * Created by dingjikerbo on 2016/11/16.
- */
+import java.util.*;
/**
* 类似题
diff --git a/solution/src/main/java/com/inuker/solution/CombinationSum.java b/leetcode/solution/src/CombinationSum.java
similarity index 94%
rename from solution/src/main/java/com/inuker/solution/CombinationSum.java
rename to leetcode/solution/src/CombinationSum.java
index e5e881d..824a65a 100644
--- a/solution/src/main/java/com/inuker/solution/CombinationSum.java
+++ b/leetcode/solution/src/CombinationSum.java
@@ -1,13 +1,6 @@
-package com.inuker.solution;
-
-import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by dingjikerbo on 16/11/22.
- */
-
public class CombinationSum {
// 耗时23ms
diff --git a/solution/src/main/java/com/inuker/solution/CombinationSumII.java b/leetcode/solution/src/CombinationSumII.java
similarity index 96%
rename from solution/src/main/java/com/inuker/solution/CombinationSumII.java
rename to leetcode/solution/src/CombinationSumII.java
index eb22a9e..2ab9acd 100644
--- a/solution/src/main/java/com/inuker/solution/CombinationSumII.java
+++ b/leetcode/solution/src/CombinationSumII.java
@@ -1,13 +1,7 @@
-package com.inuker.solution;
-
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by dingjikerbo on 16/11/22.
- */
-
public class CombinationSumII {
// 耗时29ms
diff --git a/solution/src/main/java/com/inuker/solution/CombinationSumIII.java b/leetcode/solution/src/CombinationSumIII.java
similarity index 94%
rename from solution/src/main/java/com/inuker/solution/CombinationSumIII.java
rename to leetcode/solution/src/CombinationSumIII.java
index 4e4eccc..c64c203 100644
--- a/solution/src/main/java/com/inuker/solution/CombinationSumIII.java
+++ b/leetcode/solution/src/CombinationSumIII.java
@@ -1,12 +1,6 @@
-package com.inuker.solution;
-
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by dingjikerbo on 16/11/22.
- */
-
/**
* 这题不允许重复数字
*/
diff --git a/solution/src/main/java/com/inuker/solution/CombinationSumIV.java b/leetcode/solution/src/CombinationSumIV.java
similarity index 91%
rename from solution/src/main/java/com/inuker/solution/CombinationSumIV.java
rename to leetcode/solution/src/CombinationSumIV.java
index 8f45652..3920298 100644
--- a/solution/src/main/java/com/inuker/solution/CombinationSumIV.java
+++ b/leetcode/solution/src/CombinationSumIV.java
@@ -1,11 +1,5 @@
-package com.inuker.solution;
-
import java.util.Arrays;
-/**
- * Created by dingjikerbo on 16/11/22.
- */
-
public class CombinationSumIV {
/**
diff --git a/solution/src/main/java/com/inuker/solution/Combinations.java b/leetcode/solution/src/Combinations.java
similarity index 90%
rename from solution/src/main/java/com/inuker/solution/Combinations.java
rename to leetcode/solution/src/Combinations.java
index f2673a0..f4091d3 100644
--- a/solution/src/main/java/com/inuker/solution/Combinations.java
+++ b/leetcode/solution/src/Combinations.java
@@ -1,12 +1,6 @@
-package com.inuker.solution;
-
import java.util.ArrayList;
import java.util.List;
-/**
- * Created by dingjikerbo on 2016/12/17.
- */
-
public class Combinations {
public List> combine(int n, int k) {
diff --git a/solution/src/main/java/com/inuker/solution/ConstructBinaryTreeFromInorderAndPostorderTraversal.java b/leetcode/solution/src/ConstructBinaryTreeFromInorderAndPostorderTraversal.java
similarity index 89%
rename from solution/src/main/java/com/inuker/solution/ConstructBinaryTreeFromInorderAndPostorderTraversal.java
rename to leetcode/solution/src/ConstructBinaryTreeFromInorderAndPostorderTraversal.java
index f841314..7610466 100644
--- a/solution/src/main/java/com/inuker/solution/ConstructBinaryTreeFromInorderAndPostorderTraversal.java
+++ b/leetcode/solution/src/ConstructBinaryTreeFromInorderAndPostorderTraversal.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
-/**
- * Created by dingjikerbo on 2016/12/2.
- */
-
public class ConstructBinaryTreeFromInorderAndPostorderTraversal {
public TreeNode buildTree(int[] inorder, int[] postorder) {
diff --git a/solution/src/main/java/com/inuker/solution/ConstructBinaryTreeFromPreorderInorderTraversal.java b/leetcode/solution/src/ConstructBinaryTreeFromPreorderInorderTraversal.java
similarity index 88%
rename from solution/src/main/java/com/inuker/solution/ConstructBinaryTreeFromPreorderInorderTraversal.java
rename to leetcode/solution/src/ConstructBinaryTreeFromPreorderInorderTraversal.java
index d3fb909..58477f7 100644
--- a/solution/src/main/java/com/inuker/solution/ConstructBinaryTreeFromPreorderInorderTraversal.java
+++ b/leetcode/solution/src/ConstructBinaryTreeFromPreorderInorderTraversal.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
-/**
- * Created by dingjikerbo on 16/11/30.
- */
-
public class ConstructBinaryTreeFromPreorderInorderTraversal {
public TreeNode buildTree(int[] preorder, int[] inorder) {
diff --git a/leetcode/solution/src/ConstructStringFromBinaryTree.java b/leetcode/solution/src/ConstructStringFromBinaryTree.java
new file mode 100644
index 0000000..96747ce
--- /dev/null
+++ b/leetcode/solution/src/ConstructStringFromBinaryTree.java
@@ -0,0 +1,21 @@
+/**
+ * https://leetcode.com/articles/construct-string-from-binary-tree/
+ */
+public class ConstructStringFromBinaryTree {
+
+ /**
+ * 左子树如果为空'()'是不能省略的
+ * 右子树如果为空可以省略
+ */
+ public String tree2str(TreeNode t) {
+ if (t == null) {
+ return "";
+ }
+ if (t.left == null && t.right == null) {
+ return t.val + "";
+ }
+ String left = "(" + tree2str(t.left) + ")";
+ String right = t.right != null ? "(" + tree2str(t.right) + ")" : "";
+ return t.val + left + right;
+ }
+}
diff --git a/solution/src/main/java/com/inuker/solution/ContainerWithMostWater.java b/leetcode/solution/src/ContainerWithMostWater.java
similarity index 83%
rename from solution/src/main/java/com/inuker/solution/ContainerWithMostWater.java
rename to leetcode/solution/src/ContainerWithMostWater.java
index dce553d..75232b4 100644
--- a/solution/src/main/java/com/inuker/solution/ContainerWithMostWater.java
+++ b/leetcode/solution/src/ContainerWithMostWater.java
@@ -1,14 +1,9 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 17/5/2.
- */
-
/**
* 题目的意思是选定两块板子组成一个桶,使得装水量最大。注意其余的板子都忽略。
* 一种O(n)的方法是对于区间[left, right],假如height[left] < height[right],则我们可以认定[left, right - 1],[left, right - 2] ...
* 都不会比[left, right]装的水更多。原因是木桶的短板没变,所以水平面不会变,但是宽度减小了。
* 所以我们要继续尝试的方向是从较短的一方推进,寄希望于其之后的板子能高一点
+ * 如果两边一样高,那随便推进哪一边都行,因为假如之后还能装更多水,一定不会包含这两边任意一块。如果包含了,水量不会超过当前。
*/
public class ContainerWithMostWater {
diff --git a/solution/src/main/java/com/inuker/solution/ContainsDuplicate.java b/leetcode/solution/src/ContainsDuplicate.java
similarity index 76%
rename from solution/src/main/java/com/inuker/solution/ContainsDuplicate.java
rename to leetcode/solution/src/ContainsDuplicate.java
index c642c0c..3a56afa 100644
--- a/solution/src/main/java/com/inuker/solution/ContainsDuplicate.java
+++ b/leetcode/solution/src/ContainsDuplicate.java
@@ -1,13 +1,5 @@
-package com.inuker.solution;
-
-import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
-import java.util.TreeSet;
-
-/**
- * Created by dingjikerbo on 16/12/8.
- */
/**
* https://leetcode.com/articles/contains-duplicate/
diff --git a/solution/src/main/java/com/inuker/solution/ContainsDuplicateII.java b/leetcode/solution/src/ContainsDuplicateII.java
similarity index 90%
rename from solution/src/main/java/com/inuker/solution/ContainsDuplicateII.java
rename to leetcode/solution/src/ContainsDuplicateII.java
index a2225ef..0e0ac92 100644
--- a/solution/src/main/java/com/inuker/solution/ContainsDuplicateII.java
+++ b/leetcode/solution/src/ContainsDuplicateII.java
@@ -1,12 +1,5 @@
-package com.inuker.solution;
-
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Set;
-
-/**
- * Created by dingjikerbo on 16/12/8.
- */
/**
* https://leetcode.com/articles/contains-duplicate-ii/
diff --git a/solution/src/main/java/com/inuker/solution/ContainsDuplicateIII.java b/leetcode/solution/src/ContainsDuplicateIII.java
similarity index 96%
rename from solution/src/main/java/com/inuker/solution/ContainsDuplicateIII.java
rename to leetcode/solution/src/ContainsDuplicateIII.java
index e7ca4b8..ca6dc6f 100644
--- a/solution/src/main/java/com/inuker/solution/ContainsDuplicateIII.java
+++ b/leetcode/solution/src/ContainsDuplicateIII.java
@@ -1,13 +1,7 @@
-package com.inuker.solution;
-
import java.util.HashMap;
import java.util.Map;
import java.util.TreeSet;
-/**
- * Created by dingjikerbo on 16/12/8.
- */
-
/**
* https://leetcode.com/articles/contains-duplicate-iii/
*/
diff --git a/leetcode/solution/src/ConvertBSTToGreaterTree.java b/leetcode/solution/src/ConvertBSTToGreaterTree.java
new file mode 100644
index 0000000..f9fe841
--- /dev/null
+++ b/leetcode/solution/src/ConvertBSTToGreaterTree.java
@@ -0,0 +1,26 @@
+import java.util.Stack;
+
+/**
+ * https://leetcode.com/articles/convert-bst-to-greater-tree/
+ */
+public class ConvertBSTToGreaterTree {
+
+ public TreeNode convertBST(TreeNode root) {
+ Stack stack = new Stack<>();
+ int sum = 0;
+ TreeNode node = root;
+ while (!stack.isEmpty() || node != null) {
+ if (node != null) {
+ stack.push(node);
+ node = node.right;
+ } else {
+ node = stack.pop();
+ int s = sum;
+ sum += node.val;
+ node.val += s;
+ node = node.left;
+ }
+ }
+ return root;
+ }
+}
diff --git a/solution/src/main/java/com/inuker/solution/ConvertSortedArrayToBinarySearchTree.java b/leetcode/solution/src/ConvertSortedArrayToBinarySearchTree.java
similarity index 82%
rename from solution/src/main/java/com/inuker/solution/ConvertSortedArrayToBinarySearchTree.java
rename to leetcode/solution/src/ConvertSortedArrayToBinarySearchTree.java
index 6e9d784..a81ae81 100644
--- a/solution/src/main/java/com/inuker/solution/ConvertSortedArrayToBinarySearchTree.java
+++ b/leetcode/solution/src/ConvertSortedArrayToBinarySearchTree.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
-/**
- * Created by dingjikerbo on 16/11/28.
- */
-
public class ConvertSortedArrayToBinarySearchTree {
public TreeNode sortedArrayToBST(int[] nums) {
diff --git a/solution/src/main/java/com/inuker/solution/ConvertSortedListToBinarySearchTree.java b/leetcode/solution/src/ConvertSortedListToBinarySearchTree.java
similarity index 80%
rename from solution/src/main/java/com/inuker/solution/ConvertSortedListToBinarySearchTree.java
rename to leetcode/solution/src/ConvertSortedListToBinarySearchTree.java
index eea3e9d..6723b13 100644
--- a/solution/src/main/java/com/inuker/solution/ConvertSortedListToBinarySearchTree.java
+++ b/leetcode/solution/src/ConvertSortedListToBinarySearchTree.java
@@ -1,12 +1,3 @@
-package com.inuker.solution;
-
-import com.leetcode.library.ListNode;
-import com.leetcode.library.TreeNode;
-
-/**
- * Created by liwentian on 2017/9/11.
- */
-
public class ConvertSortedListToBinarySearchTree {
public TreeNode sortedListToBST(ListNode head) {
diff --git a/leetcode/solution/src/CopyListWithRandomPointer.java b/leetcode/solution/src/CopyListWithRandomPointer.java
new file mode 100644
index 0000000..19c0f75
--- /dev/null
+++ b/leetcode/solution/src/CopyListWithRandomPointer.java
@@ -0,0 +1,32 @@
+/**
+ * 易错的地方在于random要判空
+ */
+public class CopyListWithRandomPointer {
+
+
+ public RandomListNode copyRandomList(RandomListNode head) {
+ for (RandomListNode p = head; p != null; ) {
+ RandomListNode next = p.next;
+ RandomListNode temp = new RandomListNode(p.label);
+ temp.next = p.next;
+ p.next = temp;
+ p = next;
+ }
+ for (RandomListNode p = head; p != null; ) {
+ if (p.random != null) {
+ p.next.random = p.random.next;
+ }
+ p = p.next.next;
+ }
+ RandomListNode dummy = new RandomListNode(0), cur = dummy;
+ for (RandomListNode p = head; p != null; ) {
+ cur.next = p.next;
+ cur = cur.next;
+ p.next = p.next.next;
+ p = p.next;
+ }
+ return dummy.next;
+ }
+}
+
+
diff --git a/solution/src/main/java/com/inuker/solution/CountAndSay.java b/leetcode/solution/src/CountAndSay.java
similarity index 91%
rename from solution/src/main/java/com/inuker/solution/CountAndSay.java
rename to leetcode/solution/src/CountAndSay.java
index 2e9c9af..ec3f9b2 100644
--- a/solution/src/main/java/com/inuker/solution/CountAndSay.java
+++ b/leetcode/solution/src/CountAndSay.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/11/22.
- */
-
public class CountAndSay {
public String countAndSay(int n) {
diff --git a/solution/src/main/java/com/inuker/solution/CountCompleteTreeNodes.java b/leetcode/solution/src/CountCompleteTreeNodes.java
similarity index 85%
rename from solution/src/main/java/com/inuker/solution/CountCompleteTreeNodes.java
rename to leetcode/solution/src/CountCompleteTreeNodes.java
index 5650df6..0dfa900 100644
--- a/solution/src/main/java/com/inuker/solution/CountCompleteTreeNodes.java
+++ b/leetcode/solution/src/CountCompleteTreeNodes.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
-/**
- * Created by dingjikerbo on 2016/11/29.
- */
-
public class CountCompleteTreeNodes {
/** 适合通用的二叉树,但是对于完全二叉树会超时
@@ -34,7 +26,7 @@ public int countNodes(TreeNode root) {
return count;
}*/
- // 119ms,最差复杂度是O(n),最好是O(lgn)
+ // 119ms,最差复杂度是O((lgn)^2),最好是O(lgn)
public int countNodes(TreeNode root) {
int left = 0, right = 0;
for (TreeNode node = root; node != null; node = node.left, left++);
diff --git a/solution/src/main/java/com/inuker/solution/CountNumberWithUniqueDigits.java b/leetcode/solution/src/CountNumberWithUniqueDigits.java
similarity index 80%
rename from solution/src/main/java/com/inuker/solution/CountNumberWithUniqueDigits.java
rename to leetcode/solution/src/CountNumberWithUniqueDigits.java
index 4fab953..50283e3 100644
--- a/solution/src/main/java/com/inuker/solution/CountNumberWithUniqueDigits.java
+++ b/leetcode/solution/src/CountNumberWithUniqueDigits.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by liwentian on 2016/12/29.
- */
-
public class CountNumberWithUniqueDigits {
public int countNumbersWithUniqueDigits(int n) {
diff --git a/solution/src/main/java/com/inuker/solution/CountOfSmallerNumbersAfterSelf.java b/leetcode/solution/src/CountOfSmallerNumbersAfterSelf.java
similarity index 96%
rename from solution/src/main/java/com/inuker/solution/CountOfSmallerNumbersAfterSelf.java
rename to leetcode/solution/src/CountOfSmallerNumbersAfterSelf.java
index 4fab12b..4aa9c80 100644
--- a/solution/src/main/java/com/inuker/solution/CountOfSmallerNumbersAfterSelf.java
+++ b/leetcode/solution/src/CountOfSmallerNumbersAfterSelf.java
@@ -1,12 +1,6 @@
-package com.inuker.solution;
-
import java.util.Arrays;
import java.util.List;
-/**
- * Created by dingjikerbo on 2016/12/21.
- */
-
/**
* 这题理解了好久才搞明白
* 建立一棵二叉树,从数组末尾开始遍历,这里每个树的节点要记录sum和dup
diff --git a/solution/src/main/java/com/inuker/solution/CountPrimes.java b/leetcode/solution/src/CountPrimes.java
similarity index 87%
rename from solution/src/main/java/com/inuker/solution/CountPrimes.java
rename to leetcode/solution/src/CountPrimes.java
index d14a019..e0ddfd0 100644
--- a/solution/src/main/java/com/inuker/solution/CountPrimes.java
+++ b/leetcode/solution/src/CountPrimes.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import java.util.Arrays;
-
-/**
- * Created by dingjikerbo on 16/12/10.
- */
-
/**
* 如果一个数是另一个数的倍数,那这个数肯定不是素数。
* 利用这个性质,我们可以建立一个素数数组,从2开始将素数的倍数都标注为不是素数。
diff --git a/solution/src/main/java/com/inuker/solution/CountUnivalueSubtrees.java b/leetcode/solution/src/CountUnivalueSubtrees.java
similarity index 86%
rename from solution/src/main/java/com/inuker/solution/CountUnivalueSubtrees.java
rename to leetcode/solution/src/CountUnivalueSubtrees.java
index c7933ff..b0071b2 100644
--- a/solution/src/main/java/com/inuker/solution/CountUnivalueSubtrees.java
+++ b/leetcode/solution/src/CountUnivalueSubtrees.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
-/**
- * Created by dingjikerbo on 16/12/1.
- */
-
public class CountUnivalueSubtrees {
public int countUnivalSubtrees(TreeNode root) {
diff --git a/solution/src/main/java/com/inuker/solution/CourseSchedule.java b/leetcode/solution/src/CourseSchedule.java
similarity index 81%
rename from solution/src/main/java/com/inuker/solution/CourseSchedule.java
rename to leetcode/solution/src/CourseSchedule.java
index 21bd7da..12a928d 100644
--- a/solution/src/main/java/com/inuker/solution/CourseSchedule.java
+++ b/leetcode/solution/src/CourseSchedule.java
@@ -1,15 +1,4 @@
-package com.inuker.solution;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Queue;
-import java.util.Set;
-
-/**
- * Created by dingjikerbo on 2016/12/17.
- */
+import java.util.*;
public class CourseSchedule {
diff --git a/solution/src/main/java/com/inuker/solution/CourseScheduleII.java b/leetcode/solution/src/CourseScheduleII.java
similarity index 91%
rename from solution/src/main/java/com/inuker/solution/CourseScheduleII.java
rename to leetcode/solution/src/CourseScheduleII.java
index 203bc7e..95fc851 100644
--- a/solution/src/main/java/com/inuker/solution/CourseScheduleII.java
+++ b/leetcode/solution/src/CourseScheduleII.java
@@ -1,15 +1,8 @@
-package com.inuker.solution;
-
-import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Set;
-/**
- * Created by dingjikerbo on 2016/12/17.
- */
-
public class CourseScheduleII {
public int[] findOrder(int numCourses, int[][] prerequisites) {
diff --git a/solution/src/main/java/com/inuker/solution/DecodeString.java b/leetcode/solution/src/DecodeString.java
similarity index 95%
rename from solution/src/main/java/com/inuker/solution/DecodeString.java
rename to leetcode/solution/src/DecodeString.java
index a316137..48315d9 100644
--- a/solution/src/main/java/com/inuker/solution/DecodeString.java
+++ b/leetcode/solution/src/DecodeString.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import java.util.Stack;
-
-/**
- * Created by dingjikerbo on 2016/12/11.
- */
-
public class DecodeString {
/**
diff --git a/solution/src/main/java/com/inuker/solution/DecodeWays.java b/leetcode/solution/src/DecodeWays.java
similarity index 97%
rename from solution/src/main/java/com/inuker/solution/DecodeWays.java
rename to leetcode/solution/src/DecodeWays.java
index 98006a6..6d4a70e 100644
--- a/solution/src/main/java/com/inuker/solution/DecodeWays.java
+++ b/leetcode/solution/src/DecodeWays.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/11/20.
- */
-
/**
* TestCases
* ""
diff --git a/solution/src/main/java/com/inuker/solution/DeleteNodeInALinkedList.java b/leetcode/solution/src/DeleteNodeInALinkedList.java
similarity index 66%
rename from solution/src/main/java/com/inuker/solution/DeleteNodeInALinkedList.java
rename to leetcode/solution/src/DeleteNodeInALinkedList.java
index 9648546..d7d9aa0 100644
--- a/solution/src/main/java/com/inuker/solution/DeleteNodeInALinkedList.java
+++ b/leetcode/solution/src/DeleteNodeInALinkedList.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by liwentian on 2017/9/11.
- */
-
-import com.leetcode.library.ListNode;
-
/**
* https://leetcode.com/articles/delete-node-linked-list/
*/
diff --git a/solution/src/main/java/com/inuker/solution/DeleteNodeInBST.java b/leetcode/solution/src/DeleteNodeInBST.java
similarity index 86%
rename from solution/src/main/java/com/inuker/solution/DeleteNodeInBST.java
rename to leetcode/solution/src/DeleteNodeInBST.java
index f40bd3a..b33cc58 100644
--- a/solution/src/main/java/com/inuker/solution/DeleteNodeInBST.java
+++ b/leetcode/solution/src/DeleteNodeInBST.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
-/**
- * Created by dingjikerbo on 17/1/2.
- */
-
public class DeleteNodeInBST {
public TreeNode deleteNode(TreeNode root, int key) {
diff --git a/leetcode/solution/src/DiameterOfBinaryTree.java b/leetcode/solution/src/DiameterOfBinaryTree.java
new file mode 100644
index 0000000..ca696c4
--- /dev/null
+++ b/leetcode/solution/src/DiameterOfBinaryTree.java
@@ -0,0 +1,24 @@
+public class DiameterOfBinaryTree {
+
+ /**
+ * 这题和 124. Binary Tree Maximum Path Sum比较像
+ * 都是分两种情况,一种是必须包括root的,带上必须包括left和right的单边结果;
+ * 还有不是必须包括root的,对比left和right的双边结果
+ * flag为true表示必须包括root,false表示不是必须包括root
+ */
+ public int diameterOfBinaryTree(TreeNode root) {
+ if (root == null) {
+ return 0;
+ }
+ return dfs(root, false);
+ }
+
+ public int dfs(TreeNode root, boolean flag) {
+ if (root == null) {
+ return -1;
+ }
+ return flag ? Math.max(dfs(root.left, true) + 1, dfs(root.right, true) + 1) :
+ Math.max(Math.max(dfs(root.left, false), dfs(root.right, false)),
+ dfs(root.left, true) + 2 + dfs(root.right, true));
+ }
+}
diff --git a/solution/src/main/java/com/inuker/solution/DifferenceWaysToAddParentheses.java b/leetcode/solution/src/DifferenceWaysToAddParentheses.java
similarity index 92%
rename from solution/src/main/java/com/inuker/solution/DifferenceWaysToAddParentheses.java
rename to leetcode/solution/src/DifferenceWaysToAddParentheses.java
index 4ae23c5..a176668 100644
--- a/solution/src/main/java/com/inuker/solution/DifferenceWaysToAddParentheses.java
+++ b/leetcode/solution/src/DifferenceWaysToAddParentheses.java
@@ -1,12 +1,6 @@
-package com.inuker.solution;
-
import java.util.ArrayList;
import java.util.List;
-/**
- * Created by dingjikerbo on 2016/12/17.
- */
-
public class DifferenceWaysToAddParentheses {
public List diffWaysToCompute(String input) {
diff --git a/solution/src/main/java/com/inuker/solution/DivideTwoIntegers.java b/leetcode/solution/src/DivideTwoIntegers.java
similarity index 94%
rename from solution/src/main/java/com/inuker/solution/DivideTwoIntegers.java
rename to leetcode/solution/src/DivideTwoIntegers.java
index fa64bc0..855a504 100644
--- a/solution/src/main/java/com/inuker/solution/DivideTwoIntegers.java
+++ b/leetcode/solution/src/DivideTwoIntegers.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 17/1/12.
- */
-
public class DivideTwoIntegers {
/**
diff --git a/solution/src/main/java/com/inuker/solution/EditDistance.java b/leetcode/solution/src/EditDistance.java
similarity index 92%
rename from solution/src/main/java/com/inuker/solution/EditDistance.java
rename to leetcode/solution/src/EditDistance.java
index 6aec8e1..95d8798 100644
--- a/solution/src/main/java/com/inuker/solution/EditDistance.java
+++ b/leetcode/solution/src/EditDistance.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/12/15.
- */
-
/**
* 这题非常重要的是对f的初始化,千万不能漏
* 所有DP问题都要注意初始化边界条件
diff --git a/solution/src/main/java/com/inuker/solution/EncodeAndDecodeStrings.java b/leetcode/solution/src/EncodeAndDecodeStrings.java
similarity index 91%
rename from solution/src/main/java/com/inuker/solution/EncodeAndDecodeStrings.java
rename to leetcode/solution/src/EncodeAndDecodeStrings.java
index 9b88a71..f5b1bd2 100644
--- a/solution/src/main/java/com/inuker/solution/EncodeAndDecodeStrings.java
+++ b/leetcode/solution/src/EncodeAndDecodeStrings.java
@@ -1,12 +1,6 @@
-package com.inuker.solution;
-
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by dingjikerbo on 2016/12/11.
- */
-
public class EncodeAndDecodeStrings {
/**
diff --git a/solution/src/main/java/com/inuker/solution/EncodeAndDecodeTinyURL.java b/leetcode/solution/src/EncodeAndDecodeTinyURL.java
similarity index 94%
rename from solution/src/main/java/com/inuker/solution/EncodeAndDecodeTinyURL.java
rename to leetcode/solution/src/EncodeAndDecodeTinyURL.java
index 64e5d99..386e4fa 100644
--- a/solution/src/main/java/com/inuker/solution/EncodeAndDecodeTinyURL.java
+++ b/leetcode/solution/src/EncodeAndDecodeTinyURL.java
@@ -1,12 +1,6 @@
-package com.inuker.solution;
-
import java.util.HashMap;
import java.util.Random;
-/**
- * Created by dingjikerbo on 2017/8/20.
- */
-
/**
* https://leetcode.com/articles/encode-and-decode-tinyurl/
*/
diff --git a/solution/src/main/java/com/inuker/solution/EvaluateDivision.java b/leetcode/solution/src/EvaluateDivision.java
similarity index 96%
rename from solution/src/main/java/com/inuker/solution/EvaluateDivision.java
rename to leetcode/solution/src/EvaluateDivision.java
index 1811f62..f772c14 100644
--- a/solution/src/main/java/com/inuker/solution/EvaluateDivision.java
+++ b/leetcode/solution/src/EvaluateDivision.java
@@ -1,13 +1,7 @@
-package com.inuker.solution;
-
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
-/**
- * Created by liwentian on 2017/9/3.
- */
-
/**
* 1, 首先给除的结果都存起来,建立有向图
* 2,用DFS遍历路径
diff --git a/solution/src/main/java/com/inuker/solution/EvaluateReversePolishNotation.java b/leetcode/solution/src/EvaluateReversePolishNotation.java
similarity index 90%
rename from solution/src/main/java/com/inuker/solution/EvaluateReversePolishNotation.java
rename to leetcode/solution/src/EvaluateReversePolishNotation.java
index bd85961..0099e69 100644
--- a/solution/src/main/java/com/inuker/solution/EvaluateReversePolishNotation.java
+++ b/leetcode/solution/src/EvaluateReversePolishNotation.java
@@ -1,11 +1,5 @@
-package com.inuker.solution;
-
import java.util.Stack;
-/**
- * Created by liwentian on 2017/9/12.
- */
-
public class EvaluateReversePolishNotation {
public int evalRPN(String[] tokens) {
diff --git a/solution/src/main/java/com/inuker/solution/ExcelSheetColumnNumber.java b/leetcode/solution/src/ExcelSheetColumnNumber.java
similarity index 86%
rename from solution/src/main/java/com/inuker/solution/ExcelSheetColumnNumber.java
rename to leetcode/solution/src/ExcelSheetColumnNumber.java
index 26fb5cd..4d8a79f 100644
--- a/solution/src/main/java/com/inuker/solution/ExcelSheetColumnNumber.java
+++ b/leetcode/solution/src/ExcelSheetColumnNumber.java
@@ -1,14 +1,6 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by dingjikerbo on 2016/12/17.
- */
-
public class ExcelSheetColumnNumber {
public List binaryTreePaths(TreeNode root) {
diff --git a/solution/src/main/java/com/inuker/solution/ExcelSheetColumnTitle.java b/leetcode/solution/src/ExcelSheetColumnTitle.java
similarity index 82%
rename from solution/src/main/java/com/inuker/solution/ExcelSheetColumnTitle.java
rename to leetcode/solution/src/ExcelSheetColumnTitle.java
index a5ea8eb..88fcd30 100644
--- a/solution/src/main/java/com/inuker/solution/ExcelSheetColumnTitle.java
+++ b/leetcode/solution/src/ExcelSheetColumnTitle.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/12/17.
- */
-
public class ExcelSheetColumnTitle {
/**
diff --git a/solution/src/main/java/com/inuker/solution/ExpressionAddOperators.java b/leetcode/solution/src/ExpressionAddOperators.java
similarity index 95%
rename from solution/src/main/java/com/inuker/solution/ExpressionAddOperators.java
rename to leetcode/solution/src/ExpressionAddOperators.java
index 58e79c1..da1008c 100644
--- a/solution/src/main/java/com/inuker/solution/ExpressionAddOperators.java
+++ b/leetcode/solution/src/ExpressionAddOperators.java
@@ -1,12 +1,6 @@
-package com.inuker.solution;
-
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by dingjikerbo on 16/11/21.
- */
-
public class ExpressionAddOperators {
/**
diff --git a/solution/src/main/java/com/inuker/solution/FactorCombinations.java b/leetcode/solution/src/FactorCombinations.java
similarity index 90%
rename from solution/src/main/java/com/inuker/solution/FactorCombinations.java
rename to leetcode/solution/src/FactorCombinations.java
index c6ac34c..b16a400 100644
--- a/solution/src/main/java/com/inuker/solution/FactorCombinations.java
+++ b/leetcode/solution/src/FactorCombinations.java
@@ -1,12 +1,6 @@
-package com.inuker.solution;
-
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by liwentian on 2017/9/6.
- */
-
public class FactorCombinations {
public List> getFactors(int n) {
diff --git a/solution/src/main/java/com/inuker/solution/FactorialTrailingZeroes.java b/leetcode/solution/src/FactorialTrailingZeroes.java
similarity index 69%
rename from solution/src/main/java/com/inuker/solution/FactorialTrailingZeroes.java
rename to leetcode/solution/src/FactorialTrailingZeroes.java
index d0beb44..a816916 100644
--- a/solution/src/main/java/com/inuker/solution/FactorialTrailingZeroes.java
+++ b/leetcode/solution/src/FactorialTrailingZeroes.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/12/7.
- */
-
public class FactorialTrailingZeroes {
public int trailingZeroes(int n) {
diff --git a/solution/src/main/java/com/inuker/solution/FindAllAnagramsInString.java b/leetcode/solution/src/FindAllAnagramsInString.java
similarity index 95%
rename from solution/src/main/java/com/inuker/solution/FindAllAnagramsInString.java
rename to leetcode/solution/src/FindAllAnagramsInString.java
index 63c7aa4..98a9d5b 100644
--- a/solution/src/main/java/com/inuker/solution/FindAllAnagramsInString.java
+++ b/leetcode/solution/src/FindAllAnagramsInString.java
@@ -1,14 +1,7 @@
-package com.inuker.solution;
-
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by dingjikerbo on 2016/11/17.
- */
-
public class FindAllAnagramsInString {
// 耗时16ms,复杂度O(n)
diff --git a/solution/src/main/java/com/inuker/solution/FindAllDuplicatesInAnArray.java b/leetcode/solution/src/FindAllDuplicatesInAnArray.java
similarity index 85%
rename from solution/src/main/java/com/inuker/solution/FindAllDuplicatesInAnArray.java
rename to leetcode/solution/src/FindAllDuplicatesInAnArray.java
index 85961b4..5233bf3 100644
--- a/solution/src/main/java/com/inuker/solution/FindAllDuplicatesInAnArray.java
+++ b/leetcode/solution/src/FindAllDuplicatesInAnArray.java
@@ -1,12 +1,6 @@
-package com.inuker.solution;
-
import java.util.ArrayList;
import java.util.List;
-/**
- * Created by liwentian on 2017/9/10.
- */
-
public class FindAllDuplicatesInAnArray {
public List findDuplicates(int[] nums) {
diff --git a/solution/src/main/java/com/inuker/solution/FindAllNumbersDisappearedInAnArray.java b/leetcode/solution/src/FindAllNumbersDisappearedInAnArray.java
similarity index 91%
rename from solution/src/main/java/com/inuker/solution/FindAllNumbersDisappearedInAnArray.java
rename to leetcode/solution/src/FindAllNumbersDisappearedInAnArray.java
index 0269e8d..159043c 100644
--- a/solution/src/main/java/com/inuker/solution/FindAllNumbersDisappearedInAnArray.java
+++ b/leetcode/solution/src/FindAllNumbersDisappearedInAnArray.java
@@ -1,12 +1,6 @@
-package com.inuker.solution;
-
import java.util.ArrayList;
import java.util.List;
-/**
- * Created by liwentian on 2017/9/10.
- */
-
public class FindAllNumbersDisappearedInAnArray {
//4,3,2,7,8,2,3,1
diff --git a/solution/src/main/java/com/inuker/solution/FindBottomLeftTreeValue.java b/leetcode/solution/src/FindBottomLeftTreeValue.java
similarity index 88%
rename from solution/src/main/java/com/inuker/solution/FindBottomLeftTreeValue.java
rename to leetcode/solution/src/FindBottomLeftTreeValue.java
index dc12267..a177a75 100644
--- a/solution/src/main/java/com/inuker/solution/FindBottomLeftTreeValue.java
+++ b/leetcode/solution/src/FindBottomLeftTreeValue.java
@@ -1,14 +1,6 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
import java.util.LinkedList;
import java.util.Queue;
-/**
- * Created by liwentian on 17/8/3.
- */
-
public class FindBottomLeftTreeValue {
public int findBottomLeftValue(TreeNode root) {
diff --git a/solution/src/main/java/com/inuker/solution/FindCelebrity.java b/leetcode/solution/src/FindCelebrity.java
similarity index 89%
rename from solution/src/main/java/com/inuker/solution/FindCelebrity.java
rename to leetcode/solution/src/FindCelebrity.java
index 18ebcf7..09e1a45 100644
--- a/solution/src/main/java/com/inuker/solution/FindCelebrity.java
+++ b/leetcode/solution/src/FindCelebrity.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/11/20.
- */
-
/**
* 先用排除法扫一轮,剩下的是唯一的候选人,然后再严格判断
*/
diff --git a/solution/src/main/java/com/inuker/solution/FindDuplicateSubtrees.java b/leetcode/solution/src/FindDuplicateSubtrees.java
similarity index 87%
rename from solution/src/main/java/com/inuker/solution/FindDuplicateSubtrees.java
rename to leetcode/solution/src/FindDuplicateSubtrees.java
index e353480..7036b91 100644
--- a/solution/src/main/java/com/inuker/solution/FindDuplicateSubtrees.java
+++ b/leetcode/solution/src/FindDuplicateSubtrees.java
@@ -1,15 +1,7 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by liwentian on 17/8/3.
- */
-
public class FindDuplicateSubtrees {
/**
diff --git a/solution/src/main/java/com/inuker/solution/FindKPairsWithSmallestSums.java b/leetcode/solution/src/FindKPairsWithSmallestSums.java
similarity index 91%
rename from solution/src/main/java/com/inuker/solution/FindKPairsWithSmallestSums.java
rename to leetcode/solution/src/FindKPairsWithSmallestSums.java
index dad9523..0513bd1 100644
--- a/solution/src/main/java/com/inuker/solution/FindKPairsWithSmallestSums.java
+++ b/leetcode/solution/src/FindKPairsWithSmallestSums.java
@@ -1,13 +1,7 @@
-package com.inuker.solution;
-
import java.util.ArrayList;
import java.util.List;
import java.util.PriorityQueue;
-/**
- * Created by liwentian on 2017/9/22.
- */
-
public class FindKPairsWithSmallestSums {
public List kSmallestPairs(int[] nums1, int[] nums2, int k) {
diff --git a/solution/src/main/java/com/inuker/solution/FindLargestValueInEachTreeRow.java b/leetcode/solution/src/FindLargestValueInEachTreeRow.java
similarity index 89%
rename from solution/src/main/java/com/inuker/solution/FindLargestValueInEachTreeRow.java
rename to leetcode/solution/src/FindLargestValueInEachTreeRow.java
index 4fd1361..2c2bd6f 100644
--- a/solution/src/main/java/com/inuker/solution/FindLargestValueInEachTreeRow.java
+++ b/leetcode/solution/src/FindLargestValueInEachTreeRow.java
@@ -1,15 +1,7 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
-/**
- * Created by liwentian on 17/7/25.
- */
-
public class FindLargestValueInEachTreeRow {
public List largestValues(TreeNode root) {
diff --git a/solution/src/main/java/com/inuker/solution/FindLeavesOfBinaryTree.java b/leetcode/solution/src/FindLeavesOfBinaryTree.java
similarity index 85%
rename from solution/src/main/java/com/inuker/solution/FindLeavesOfBinaryTree.java
rename to leetcode/solution/src/FindLeavesOfBinaryTree.java
index b14a9df..d0fc777 100644
--- a/solution/src/main/java/com/inuker/solution/FindLeavesOfBinaryTree.java
+++ b/leetcode/solution/src/FindLeavesOfBinaryTree.java
@@ -1,14 +1,6 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by dingjikerbo on 16/12/3.
- */
-
public class FindLeavesOfBinaryTree {
public List> findLeaves(TreeNode root) {
diff --git a/solution/src/main/java/com/inuker/solution/FindMedianFromDataStream.java b/leetcode/solution/src/FindMedianFromDataStream.java
similarity index 89%
rename from solution/src/main/java/com/inuker/solution/FindMedianFromDataStream.java
rename to leetcode/solution/src/FindMedianFromDataStream.java
index 75b5ec5..9169ed3 100644
--- a/solution/src/main/java/com/inuker/solution/FindMedianFromDataStream.java
+++ b/leetcode/solution/src/FindMedianFromDataStream.java
@@ -1,13 +1,6 @@
-package com.inuker.solution;
-
-import java.util.Collections;
import java.util.Comparator;
import java.util.PriorityQueue;
-/**
- * Created by dingjikerbo on 17/1/2.
- */
-
public class FindMedianFromDataStream {
/**
diff --git a/solution/src/main/java/com/inuker/solution/FindMinimumInRotatedSortedArray.java b/leetcode/solution/src/FindMinimumInRotatedSortedArray.java
similarity index 85%
rename from solution/src/main/java/com/inuker/solution/FindMinimumInRotatedSortedArray.java
rename to leetcode/solution/src/FindMinimumInRotatedSortedArray.java
index 98145ac..ed1c5aa 100644
--- a/solution/src/main/java/com/inuker/solution/FindMinimumInRotatedSortedArray.java
+++ b/leetcode/solution/src/FindMinimumInRotatedSortedArray.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/12/17.
- */
-
public class FindMinimumInRotatedSortedArray {
public int findMin(int[] nums) {
diff --git a/solution/src/main/java/com/inuker/solution/FindMinimumInRotatedSortedArrayII.java b/leetcode/solution/src/FindMinimumInRotatedSortedArrayII.java
similarity index 92%
rename from solution/src/main/java/com/inuker/solution/FindMinimumInRotatedSortedArrayII.java
rename to leetcode/solution/src/FindMinimumInRotatedSortedArrayII.java
index 7944bfe..36b1176 100644
--- a/solution/src/main/java/com/inuker/solution/FindMinimumInRotatedSortedArrayII.java
+++ b/leetcode/solution/src/FindMinimumInRotatedSortedArrayII.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/12/17.
- */
-
public class FindMinimumInRotatedSortedArrayII {
public int findMin(int[] nums) {
diff --git a/solution/src/main/java/com/inuker/solution/FindModeInBinarySearchTree.java b/leetcode/solution/src/FindModeInBinarySearchTree.java
similarity index 95%
rename from solution/src/main/java/com/inuker/solution/FindModeInBinarySearchTree.java
rename to leetcode/solution/src/FindModeInBinarySearchTree.java
index 9cca839..be9319f 100644
--- a/solution/src/main/java/com/inuker/solution/FindModeInBinarySearchTree.java
+++ b/leetcode/solution/src/FindModeInBinarySearchTree.java
@@ -1,15 +1,6 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
-import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by liwentian on 17/8/3.
- */
-
/**
* 这题是要找BST中出现次数最多的节点集合,这里允许有重复节点
* 思路很简单,中序遍历,会按升序排列,再统计重复的值
diff --git a/solution/src/main/java/com/inuker/solution/FindPeakElement.java b/leetcode/solution/src/FindPeakElement.java
similarity index 92%
rename from solution/src/main/java/com/inuker/solution/FindPeakElement.java
rename to leetcode/solution/src/FindPeakElement.java
index c868529..8b78217 100644
--- a/solution/src/main/java/com/inuker/solution/FindPeakElement.java
+++ b/leetcode/solution/src/FindPeakElement.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by liwentian on 2017/9/10.
- */
-
/**
* https://leetcode.com/articles/find-peak-element/
*/
diff --git a/solution/src/main/java/com/inuker/solution/FindRightInterval.java b/leetcode/solution/src/FindRightInterval.java
similarity index 84%
rename from solution/src/main/java/com/inuker/solution/FindRightInterval.java
rename to leetcode/solution/src/FindRightInterval.java
index 8f2ee9a..bc914df 100644
--- a/solution/src/main/java/com/inuker/solution/FindRightInterval.java
+++ b/leetcode/solution/src/FindRightInterval.java
@@ -1,14 +1,6 @@
-package com.inuker.solution;
-
-import com.leetcode.library.Interval;
-
import java.util.Map;
import java.util.TreeMap;
-/**
- * Created by liwentian on 2017/9/22.
- */
-
public class FindRightInterval {
public int[] findRightInterval(Interval[] intervals) {
diff --git a/solution/src/main/java/com/inuker/solution/FindTheDuplicateNumber.java b/leetcode/solution/src/FindTheDuplicateNumber.java
similarity index 94%
rename from solution/src/main/java/com/inuker/solution/FindTheDuplicateNumber.java
rename to leetcode/solution/src/FindTheDuplicateNumber.java
index 72ad9e1..d6ac374 100644
--- a/solution/src/main/java/com/inuker/solution/FindTheDuplicateNumber.java
+++ b/leetcode/solution/src/FindTheDuplicateNumber.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/12/17.
- */
-
/**
* 题目的意思是有n+1个数,这些数的范围限定在[1,n],其中只有一个重复数,重复的次数不限
*/
diff --git a/solution/src/main/java/com/inuker/solution/FirstBadVersion.java b/leetcode/solution/src/FirstBadVersion.java
similarity index 91%
rename from solution/src/main/java/com/inuker/solution/FirstBadVersion.java
rename to leetcode/solution/src/FirstBadVersion.java
index d42389e..aca392a 100644
--- a/solution/src/main/java/com/inuker/solution/FirstBadVersion.java
+++ b/leetcode/solution/src/FirstBadVersion.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/11/19.
- */
-
/**
* https://leetcode.com/articles/first-bad-version/
*/
diff --git a/solution/src/main/java/com/inuker/solution/FirstMissingPositive.java b/leetcode/solution/src/FirstMissingPositive.java
similarity index 92%
rename from solution/src/main/java/com/inuker/solution/FirstMissingPositive.java
rename to leetcode/solution/src/FirstMissingPositive.java
index 4a72ea4..aa290f4 100644
--- a/solution/src/main/java/com/inuker/solution/FirstMissingPositive.java
+++ b/leetcode/solution/src/FirstMissingPositive.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 17/5/11.
- */
-
/**
* 这里要注意的是nums[nums[i] - 1] != nums[i]这个条件,意思是目标坑和当前坑的值不等,此时才能swap
* 倘若换成nums[i] - 1 != i是不行的,这表示目标坑和当前坑不是一个坑就swap,会死循环
diff --git a/amazon/src/main/java/com/leetcode/amazon/FirstUniqueCharacterInAString.java b/leetcode/solution/src/FirstUniqueCharacterInAString.java
similarity index 83%
rename from amazon/src/main/java/com/leetcode/amazon/FirstUniqueCharacterInAString.java
rename to leetcode/solution/src/FirstUniqueCharacterInAString.java
index 206cba8..c0966a8 100644
--- a/amazon/src/main/java/com/leetcode/amazon/FirstUniqueCharacterInAString.java
+++ b/leetcode/solution/src/FirstUniqueCharacterInAString.java
@@ -1,11 +1,6 @@
-package com.leetcode.amazon;
-
-/**
- * Created by liwentian on 17/8/10.
- */
-
public class FirstUniqueCharacterInAString {
+ // 耗时21ms,O(2n)
public int firstUniqChar(String s) {
int[] cnt = new int[26];
for (char c : s.toCharArray()) {
diff --git a/solution/src/main/java/com/inuker/solution/FizzBuzz.java b/leetcode/solution/src/FizzBuzz.java
similarity index 88%
rename from solution/src/main/java/com/inuker/solution/FizzBuzz.java
rename to leetcode/solution/src/FizzBuzz.java
index 34cb0b6..776b9bf 100644
--- a/solution/src/main/java/com/inuker/solution/FizzBuzz.java
+++ b/leetcode/solution/src/FizzBuzz.java
@@ -1,12 +1,6 @@
-package com.inuker.solution;
-
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by dingjikerbo on 16/12/7.
- */
-
public class FizzBuzz {
public List fizzBuzz(int n) {
diff --git a/solution/src/main/java/com/inuker/solution/FlattenBinaryTreeToLinkedList.java b/leetcode/solution/src/FlattenBinaryTreeToLinkedList.java
similarity index 72%
rename from solution/src/main/java/com/inuker/solution/FlattenBinaryTreeToLinkedList.java
rename to leetcode/solution/src/FlattenBinaryTreeToLinkedList.java
index 53b2985..60028c4 100644
--- a/solution/src/main/java/com/inuker/solution/FlattenBinaryTreeToLinkedList.java
+++ b/leetcode/solution/src/FlattenBinaryTreeToLinkedList.java
@@ -1,15 +1,7 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
-/**
- * Created by dingjikerbo on 16/11/30.
- */
-
public class FlattenBinaryTreeToLinkedList {
/**
@@ -40,22 +32,25 @@ public void flatten2(TreeNode root) {
helper(root);
}
+ /**
+ * 这题要注意ltail和rtail都为null的情况
+ */
public TreeNode helper(TreeNode root) {
if (root == null) {
- return null;
+ return root;
}
+
+ TreeNode ltail = helper(root.left);
+ TreeNode rtail = helper(root.right);
+
TreeNode right = root.right;
- TreeNode leftTail = null, rightTail = null;
- if (root.left != null) {
- leftTail = helper(root.left);
+ if (ltail != null) {
root.right = root.left;
root.left = null;
- leftTail.right = right;
+ ltail.right = right;
}
- rightTail = helper(right);
-
- return rightTail != null ? rightTail : leftTail;
+ return rtail != null ? rtail : ltail != null ? ltail : root;
}
}
diff --git a/solution/src/main/java/com/inuker/solution/FlattenNestedListIterator.java b/leetcode/solution/src/FlattenNestedListIterator.java
similarity index 87%
rename from solution/src/main/java/com/inuker/solution/FlattenNestedListIterator.java
rename to leetcode/solution/src/FlattenNestedListIterator.java
index 56c4bff..eb7d611 100644
--- a/solution/src/main/java/com/inuker/solution/FlattenNestedListIterator.java
+++ b/leetcode/solution/src/FlattenNestedListIterator.java
@@ -1,15 +1,7 @@
-package com.inuker.solution;
-
-import com.leetcode.library.NestedInteger;
-
import java.util.Iterator;
import java.util.List;
import java.util.Stack;
-/**
- * Created by dingjikerbo on 2016/11/22.
- */
-
public abstract class FlattenNestedListIterator implements Iterator {
private Stack stack;
diff --git a/solution/src/main/java/com/inuker/solution/FlipGame.java b/leetcode/solution/src/FlipGame.java
similarity index 87%
rename from solution/src/main/java/com/inuker/solution/FlipGame.java
rename to leetcode/solution/src/FlipGame.java
index 472b455..030671f 100644
--- a/solution/src/main/java/com/inuker/solution/FlipGame.java
+++ b/leetcode/solution/src/FlipGame.java
@@ -1,12 +1,6 @@
-package com.inuker.solution;
-
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by liwentian on 2017/9/6.
- */
-
public class FlipGame {
public List generatePossibleNextMoves(String s) {
diff --git a/solution/src/main/java/com/inuker/solution/FlipGameII.java b/leetcode/solution/src/FlipGameII.java
similarity index 78%
rename from solution/src/main/java/com/inuker/solution/FlipGameII.java
rename to leetcode/solution/src/FlipGameII.java
index 97f56a7..29ead0e 100644
--- a/solution/src/main/java/com/inuker/solution/FlipGameII.java
+++ b/leetcode/solution/src/FlipGameII.java
@@ -1,12 +1,3 @@
-package com.inuker.solution;
-
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- * Created by liwentian on 2017/9/6.
- */
-
public class FlipGameII {
public boolean canWin(String s) {
diff --git a/solution/src/main/java/com/inuker/solution/FourSum.java b/leetcode/solution/src/FourSum.java
similarity index 94%
rename from solution/src/main/java/com/inuker/solution/FourSum.java
rename to leetcode/solution/src/FourSum.java
index 2225598..0f9f8f4 100644
--- a/solution/src/main/java/com/inuker/solution/FourSum.java
+++ b/leetcode/solution/src/FourSum.java
@@ -1,13 +1,7 @@
-package com.inuker.solution;
-
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by dingjikerbo on 17/5/5.
- */
-
/**
* 本题要注意的一个是溢出,一个是查重
*/
diff --git a/solution/src/main/java/com/inuker/solution/GameOfLife.java b/leetcode/solution/src/GameOfLife.java
similarity index 94%
rename from solution/src/main/java/com/inuker/solution/GameOfLife.java
rename to leetcode/solution/src/GameOfLife.java
index ebaca62..3d5744c 100644
--- a/solution/src/main/java/com/inuker/solution/GameOfLife.java
+++ b/leetcode/solution/src/GameOfLife.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by liwentian on 2017/9/10.
- */
-
public class GameOfLife {
public void gameOfLife(int[][] board) {
diff --git a/solution/src/main/java/com/inuker/solution/GeneralizedAbbreviation.java b/leetcode/solution/src/GeneralizedAbbreviation.java
similarity index 91%
rename from solution/src/main/java/com/inuker/solution/GeneralizedAbbreviation.java
rename to leetcode/solution/src/GeneralizedAbbreviation.java
index ccc62bc..dca0bfb 100644
--- a/solution/src/main/java/com/inuker/solution/GeneralizedAbbreviation.java
+++ b/leetcode/solution/src/GeneralizedAbbreviation.java
@@ -1,12 +1,6 @@
-package com.inuker.solution;
-
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by liwentian on 2016/12/29.
- */
-
/**
* https://leetcode.com/articles/generalized-abbreviation/
* 思路就是back tracking,对于每个字母,到底是选择留下还是缩写
diff --git a/solution/src/main/java/com/inuker/solution/GenerateParentheses.java b/leetcode/solution/src/GenerateParentheses.java
similarity index 94%
rename from solution/src/main/java/com/inuker/solution/GenerateParentheses.java
rename to leetcode/solution/src/GenerateParentheses.java
index a40c139..92acd47 100644
--- a/solution/src/main/java/com/inuker/solution/GenerateParentheses.java
+++ b/leetcode/solution/src/GenerateParentheses.java
@@ -1,13 +1,7 @@
-package com.inuker.solution;
-
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by dingjikerbo on 16/12/8.
- */
-
public class GenerateParentheses {
// 耗时4ms
diff --git a/solution/src/main/java/com/inuker/solution/GraphValidTree.java b/leetcode/solution/src/GraphValidTree.java
similarity index 94%
rename from solution/src/main/java/com/inuker/solution/GraphValidTree.java
rename to leetcode/solution/src/GraphValidTree.java
index ab388a9..43912a4 100644
--- a/solution/src/main/java/com/inuker/solution/GraphValidTree.java
+++ b/leetcode/solution/src/GraphValidTree.java
@@ -1,7 +1,4 @@
-package com.inuker.solution;
-
/**
- * Created by dingjikerbo on 17/1/2.
*
* 判断无向图是否带环,可采用UF, DFS, BFS。
* UF实现简单,性能很好
@@ -16,12 +13,7 @@
* 题目中已声明不会有重复的边,类似[0,1]和[1,0]认为是重复的,也不会同时存在
*/
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Queue;
-import java.util.Set;
+import java.util.*;
/**
* 这题就是给了一堆边,看这些边构成的无向图会不会有环,另外这些边是不是都连在一起的
diff --git a/solution/src/main/java/com/inuker/solution/GrayCode.java b/leetcode/solution/src/GrayCode.java
similarity index 82%
rename from solution/src/main/java/com/inuker/solution/GrayCode.java
rename to leetcode/solution/src/GrayCode.java
index c5a1b6e..8947b74 100644
--- a/solution/src/main/java/com/inuker/solution/GrayCode.java
+++ b/leetcode/solution/src/GrayCode.java
@@ -1,12 +1,6 @@
-package com.inuker.solution;
-
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by dingjikerbo on 2016/12/29.
- */
-
/**
* 关键公式整数n的格雷码为n ^ (n / 2)
*/
diff --git a/amazon/src/main/java/com/leetcode/amazon/GroupAnagrams.java b/leetcode/solution/src/GroupAnagrams.java
similarity index 89%
rename from amazon/src/main/java/com/leetcode/amazon/GroupAnagrams.java
rename to leetcode/solution/src/GroupAnagrams.java
index 7b068c2..cfc1833 100644
--- a/amazon/src/main/java/com/leetcode/amazon/GroupAnagrams.java
+++ b/leetcode/solution/src/GroupAnagrams.java
@@ -1,14 +1,8 @@
-package com.leetcode.amazon;
-
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by liwentian on 17/8/13.
- */
-
public class GroupAnagrams {
public List> groupAnagrams(String[] strs) {
@@ -31,4 +25,5 @@ public List> groupAnagrams(String[] strs) {
return new LinkedList<>(map.values());
}
+
}
diff --git a/solution/src/main/java/com/inuker/solution/GroupShiftedStrings.java b/leetcode/solution/src/GroupShiftedStrings.java
similarity index 82%
rename from solution/src/main/java/com/inuker/solution/GroupShiftedStrings.java
rename to leetcode/solution/src/GroupShiftedStrings.java
index 3d2877e..00a3249 100644
--- a/solution/src/main/java/com/inuker/solution/GroupShiftedStrings.java
+++ b/leetcode/solution/src/GroupShiftedStrings.java
@@ -1,14 +1,4 @@
-package com.inuker.solution;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Created by liwentian on 2017/12/9.
- */
+import java.util.*;
public class GroupShiftedStrings {
/**
diff --git a/solution/src/main/java/com/inuker/solution/GuessNumberHigherOrLower.java b/leetcode/solution/src/GuessNumberHigherOrLower.java
similarity index 88%
rename from solution/src/main/java/com/inuker/solution/GuessNumberHigherOrLower.java
rename to leetcode/solution/src/GuessNumberHigherOrLower.java
index 8902f74..da86cd6 100644
--- a/solution/src/main/java/com/inuker/solution/GuessNumberHigherOrLower.java
+++ b/leetcode/solution/src/GuessNumberHigherOrLower.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/12/10.
- */
-
/**
* 可参考官方文档
* https://leetcode.com/articles/guess-number-higher-or-lower/
diff --git a/solution/src/main/java/com/inuker/solution/GuessNumberHigherOrLowerII.java b/leetcode/solution/src/GuessNumberHigherOrLowerII.java
similarity index 97%
rename from solution/src/main/java/com/inuker/solution/GuessNumberHigherOrLowerII.java
rename to leetcode/solution/src/GuessNumberHigherOrLowerII.java
index 1757aed..7b0275c 100644
--- a/solution/src/main/java/com/inuker/solution/GuessNumberHigherOrLowerII.java
+++ b/leetcode/solution/src/GuessNumberHigherOrLowerII.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/12/10.
- */
-
/**
* 可参考官方文档
* https://leetcode.com/articles/guess-number-higher-or-lower-ii/
diff --git a/solution/src/main/java/com/inuker/solution/HIndex.java b/leetcode/solution/src/HIndex.java
similarity index 93%
rename from solution/src/main/java/com/inuker/solution/HIndex.java
rename to leetcode/solution/src/HIndex.java
index c519f2d..771e95e 100644
--- a/solution/src/main/java/com/inuker/solution/HIndex.java
+++ b/leetcode/solution/src/HIndex.java
@@ -1,10 +1,5 @@
-package com.inuker.solution;
-
import java.util.Arrays;
-/**
- * Created by dingjikerbo on 16/11/23.
- */
/**
* https://leetcode.com/articles/h-index/
*/
diff --git a/solution/src/main/java/com/inuker/solution/HIndexII.java b/leetcode/solution/src/HIndexII.java
similarity index 90%
rename from solution/src/main/java/com/inuker/solution/HIndexII.java
rename to leetcode/solution/src/HIndexII.java
index 994e1a5..e9c5918 100644
--- a/solution/src/main/java/com/inuker/solution/HIndexII.java
+++ b/leetcode/solution/src/HIndexII.java
@@ -1,8 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/11/23.
- */
public class HIndexII {
diff --git a/solution/src/main/java/com/inuker/solution/HammingDistance.java b/leetcode/solution/src/HammingDistance.java
similarity index 70%
rename from solution/src/main/java/com/inuker/solution/HammingDistance.java
rename to leetcode/solution/src/HammingDistance.java
index 1803ee6..eb2900a 100644
--- a/solution/src/main/java/com/inuker/solution/HammingDistance.java
+++ b/leetcode/solution/src/HammingDistance.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 17/1/7.
- */
-
public class HammingDistance {
public int hammingDistance(int x, int y) {
diff --git a/solution/src/main/java/com/inuker/solution/HouseRobber.java b/leetcode/solution/src/HouseRobber.java
similarity index 91%
rename from solution/src/main/java/com/inuker/solution/HouseRobber.java
rename to leetcode/solution/src/HouseRobber.java
index 58ccaf9..9ae674e 100644
--- a/solution/src/main/java/com/inuker/solution/HouseRobber.java
+++ b/leetcode/solution/src/HouseRobber.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/12/1.
- */
-
public class HouseRobber {
/**
diff --git a/solution/src/main/java/com/inuker/solution/HouseRobberII.java b/leetcode/solution/src/HouseRobberII.java
similarity index 89%
rename from solution/src/main/java/com/inuker/solution/HouseRobberII.java
rename to leetcode/solution/src/HouseRobberII.java
index 479a6e3..0865864 100644
--- a/solution/src/main/java/com/inuker/solution/HouseRobberII.java
+++ b/leetcode/solution/src/HouseRobberII.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/12/10.
- */
-
public class HouseRobberII {
public int rob(int[] nums) {
diff --git a/leetcode/solution/src/HouseRobberIII.java b/leetcode/solution/src/HouseRobberIII.java
new file mode 100644
index 0000000..6e0cc3d
--- /dev/null
+++ b/leetcode/solution/src/HouseRobberIII.java
@@ -0,0 +1,46 @@
+public class HouseRobberIII {
+
+ /**
+ * 效率堪忧,耗时1000ms
+ */
+ public int rob(TreeNode root) {
+ return rob(root, true);
+ }
+
+ /**
+ * @param rob true表示不定,false表示不选root
+ */
+ private int rob(TreeNode root, boolean rob) {
+ if (root == null) {
+ return 0;
+ }
+
+ if (rob) {
+ return Math.max(root.val + rob(root.left, false) + rob(root.right, false),
+ rob(root.left, true) + rob(root.right, true));
+ } else {
+ return rob(root.left, true) + rob(root.right, true);
+ }
+ }
+
+ /**
+ * 优化写法如下,耗时1ms
+ */
+ public int rob2(TreeNode root) {
+ int[] val = helper(root);
+ return Math.max(val[0], val[1]);
+ }
+
+ private int[] helper(TreeNode node) {
+ if (node == null) {
+ return new int[]{0,0};
+ }
+ int[] left = helper(node.left);
+ int[] right = helper(node.right);
+ int[] value = new int[2];
+ value[0] = Math.max(left[0], left[1]) + Math.max(right[0], right[1]);
+ value[1] = node.val + left[0] + right[0];
+ return value;
+ }
+
+}
diff --git a/solution/src/main/java/com/inuker/solution/IncreasingTripletSubsequence.java b/leetcode/solution/src/IncreasingTripletSubsequence.java
similarity index 88%
rename from solution/src/main/java/com/inuker/solution/IncreasingTripletSubsequence.java
rename to leetcode/solution/src/IncreasingTripletSubsequence.java
index f2e6528..8801679 100644
--- a/solution/src/main/java/com/inuker/solution/IncreasingTripletSubsequence.java
+++ b/leetcode/solution/src/IncreasingTripletSubsequence.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/11/23.
- */
-
// 是longest increasing subsequence的简化版
public class IncreasingTripletSubsequence {
diff --git a/solution/src/main/java/com/inuker/solution/InorderSuccessorInBST.java b/leetcode/solution/src/InorderSuccessorInBST.java
similarity index 84%
rename from solution/src/main/java/com/inuker/solution/InorderSuccessorInBST.java
rename to leetcode/solution/src/InorderSuccessorInBST.java
index af0cff9..dc0e56d 100644
--- a/solution/src/main/java/com/inuker/solution/InorderSuccessorInBST.java
+++ b/leetcode/solution/src/InorderSuccessorInBST.java
@@ -1,15 +1,7 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
-/**
- * Created by dingjikerbo on 16/11/20.
- */
-
/**
* 有两种方法,用栈做普通的中序遍历,这种没有充分利用BST的特点
* 第二种方法比较巧妙,首先遍历到p,然后继续遍历找到p的右子树的最小值
@@ -37,15 +29,33 @@ public TreeNode inorderSuccessor(TreeNode root, TreeNode p) {
return null;
}
+ // 耗时2ms,简单的递归写法,更容易理解
/**
- * p的下一个节点一定是比p大的,所以这里遍历时当p的值小于当前节点,则当前节点
- * 可作为备选,同时往左走。如果在遍历过程中遇到仍然比p大的,说明更接近p,则更新备选。
- *
- * 有两点要注意,
- * 1, 首先res初始要为null,一个节点时,或root为null时,或p为最大节点时,res都没机会赋值
- * 2, 当root迭代到等于p时,走哪个分支呢,为什么选root = root.right,假如root.right为空,则之前的res即可,否则
- * 下一个迭代肯定走到root.val > p.val分支中,更新res。
- */
+ public TreeNode inorderSuccessor(TreeNode root, TreeNode p) {
+ if (root == null) {
+ return null;
+ }
+ if (root.val > p.val) {
+ TreeNode node = inorderSuccessor(root.left, p);
+ return node != null ? node : root;
+ } else {
+ return inorderSuccessor(root.right, p);
+ }
+ }
+
+ public TreeNode predecessor(TreeNode root, TreeNode p) {
+ if (root == null)
+ return null;
+
+ if (root.val >= p.val) {
+ return predecessor(root.left, p);
+ } else {
+ TreeNode right = predecessor(root.right, p);
+ return (right != null) ? right : root;
+ }
+ }*/
+
+ // 给上面的递归换成迭代写法
// 耗时4ms
public TreeNode inorderSuccessor2(TreeNode root, TreeNode p) {
TreeNode res = null;
@@ -65,6 +75,8 @@ public TreeNode inorderSuccessor2(TreeNode root, TreeNode p) {
* 给定Node,求其successor,步骤如下:
* 1, 如果Node.right != null,则在Node.right中找最小的那个节点,即从Node.right开始,最左下角的节点
* 2, 如果Node.right == null,则不断往parent走,直到当前节点是其parent的左节点为止,其parent即为给定Node的successor
+ */
+ /*
private TreeNode inOrderSuccessor(TreeNode root, TreeNode node) {
if (node.right != null) {
return minValue(node.right);
diff --git a/solution/src/main/java/com/inuker/solution/InsertDeleteGetRandom.java b/leetcode/solution/src/InsertDeleteGetRandom.java
similarity index 94%
rename from solution/src/main/java/com/inuker/solution/InsertDeleteGetRandom.java
rename to leetcode/solution/src/InsertDeleteGetRandom.java
index 6404809..6f4348d 100644
--- a/solution/src/main/java/com/inuker/solution/InsertDeleteGetRandom.java
+++ b/leetcode/solution/src/InsertDeleteGetRandom.java
@@ -1,14 +1,8 @@
-package com.inuker.solution;
-
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
-/**
- * Created by dingjikerbo on 2016/11/16.
- */
-
/**
* 有几点要注意:
* remove时要判断删除的是不是最后一个,另外交换了结尾后要更新结尾数的idx
diff --git a/solution/src/main/java/com/inuker/solution/InsertDeleteGetRandomII.java b/leetcode/solution/src/InsertDeleteGetRandomII.java
similarity index 90%
rename from solution/src/main/java/com/inuker/solution/InsertDeleteGetRandomII.java
rename to leetcode/solution/src/InsertDeleteGetRandomII.java
index c3bf840..ec6f23d 100644
--- a/solution/src/main/java/com/inuker/solution/InsertDeleteGetRandomII.java
+++ b/leetcode/solution/src/InsertDeleteGetRandomII.java
@@ -1,15 +1,4 @@
-package com.inuker.solution;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Random;
-import java.util.Vector;
-
-/**
- * Created by dingjikerbo on 2016/12/17.
- */
+import java.util.*;
/**
* 这题的区别在于允许数字重复,那么保存index需要用set,删除的时候从set中随便删一个就行了
diff --git a/solution/src/main/java/com/inuker/solution/InsertInterval.java b/leetcode/solution/src/InsertInterval.java
similarity index 86%
rename from solution/src/main/java/com/inuker/solution/InsertInterval.java
rename to leetcode/solution/src/InsertInterval.java
index 3b46189..5369066 100644
--- a/solution/src/main/java/com/inuker/solution/InsertInterval.java
+++ b/leetcode/solution/src/InsertInterval.java
@@ -1,14 +1,6 @@
-package com.inuker.solution;
-
-import com.leetcode.library.Interval;
-
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by dingjikerbo on 16/11/22.
- */
-
public class InsertInterval {
public List insert(List intervals, Interval newInterval) {
diff --git a/solution/src/main/java/com/inuker/solution/InsertionSortList.java b/leetcode/solution/src/InsertionSortList.java
similarity index 85%
rename from solution/src/main/java/com/inuker/solution/InsertionSortList.java
rename to leetcode/solution/src/InsertionSortList.java
index 4aab3b9..4090938 100644
--- a/solution/src/main/java/com/inuker/solution/InsertionSortList.java
+++ b/leetcode/solution/src/InsertionSortList.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import com.leetcode.library.ListNode;
-
-/**
- * Created by liwentian on 2017/9/11.
- */
-
public class InsertionSortList {
/**
diff --git a/solution/src/main/java/com/inuker/solution/IntegerToEnglishWords.java b/leetcode/solution/src/IntegerToEnglishWords.java
similarity index 95%
rename from solution/src/main/java/com/inuker/solution/IntegerToEnglishWords.java
rename to leetcode/solution/src/IntegerToEnglishWords.java
index 9d892b2..74375a4 100644
--- a/solution/src/main/java/com/inuker/solution/IntegerToEnglishWords.java
+++ b/leetcode/solution/src/IntegerToEnglishWords.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/11/19.
- */
-
/**
* TestCase
* 0
diff --git a/solution/src/main/java/com/inuker/solution/IntegerToRoman.java b/leetcode/solution/src/IntegerToRoman.java
similarity index 88%
rename from solution/src/main/java/com/inuker/solution/IntegerToRoman.java
rename to leetcode/solution/src/IntegerToRoman.java
index 27d661e..3e814cf 100644
--- a/solution/src/main/java/com/inuker/solution/IntegerToRoman.java
+++ b/leetcode/solution/src/IntegerToRoman.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/12/17.
- */
-
public class IntegerToRoman {
public String intToRoman(int num) {
diff --git a/solution/src/main/java/com/inuker/solution/IntersectionOfTwoArrays.java b/leetcode/solution/src/IntersectionOfTwoArrays.java
similarity index 96%
rename from solution/src/main/java/com/inuker/solution/IntersectionOfTwoArrays.java
rename to leetcode/solution/src/IntersectionOfTwoArrays.java
index 0721cf4..2a14c72 100644
--- a/solution/src/main/java/com/inuker/solution/IntersectionOfTwoArrays.java
+++ b/leetcode/solution/src/IntersectionOfTwoArrays.java
@@ -1,13 +1,7 @@
-package com.inuker.solution;
-
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
-/**
- * Created by liwentian on 2017/9/22.
- */
-
public class IntersectionOfTwoArrays {
public int[] intersection(int[] nums1, int[] nums2) {
diff --git a/solution/src/main/java/com/inuker/solution/IntersectionOfTwoArraysII.java b/leetcode/solution/src/IntersectionOfTwoArraysII.java
similarity index 91%
rename from solution/src/main/java/com/inuker/solution/IntersectionOfTwoArraysII.java
rename to leetcode/solution/src/IntersectionOfTwoArraysII.java
index 3dda626..5d812cb 100644
--- a/solution/src/main/java/com/inuker/solution/IntersectionOfTwoArraysII.java
+++ b/leetcode/solution/src/IntersectionOfTwoArraysII.java
@@ -1,12 +1,6 @@
-package com.inuker.solution;
-
import java.util.ArrayList;
import java.util.HashMap;
-/**
- * Created by liwentian on 2017/9/22.
- */
-
public class IntersectionOfTwoArraysII {
public int[] intersect(int[] nums1, int[] nums2) {
diff --git a/solution/src/main/java/com/inuker/solution/IntersectionOfTwoLinkedLists.java b/leetcode/solution/src/IntersectionOfTwoLinkedLists.java
similarity index 91%
rename from solution/src/main/java/com/inuker/solution/IntersectionOfTwoLinkedLists.java
rename to leetcode/solution/src/IntersectionOfTwoLinkedLists.java
index 2ad7edb..f1f5661 100644
--- a/solution/src/main/java/com/inuker/solution/IntersectionOfTwoLinkedLists.java
+++ b/leetcode/solution/src/IntersectionOfTwoLinkedLists.java
@@ -1,7 +1,3 @@
-package com.inuker.solution;
-
-import com.leetcode.library.ListNode;
-
/**
* Created by dingjiekrbo on 2016/11/17.
* https://leetcode.com/articles/intersection-two-linked-lists/
diff --git a/solution/src/main/java/com/inuker/solution/InvertBinaryTree.java b/leetcode/solution/src/InvertBinaryTree.java
similarity index 72%
rename from solution/src/main/java/com/inuker/solution/InvertBinaryTree.java
rename to leetcode/solution/src/InvertBinaryTree.java
index 0e763f1..6efd2c9 100644
--- a/solution/src/main/java/com/inuker/solution/InvertBinaryTree.java
+++ b/leetcode/solution/src/InvertBinaryTree.java
@@ -1,30 +1,12 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
import java.util.LinkedList;
import java.util.Queue;
-/**
- * Created by dingjikerbo on 16/11/28.
- */
-
/**
* 给非递归法也要会写
+ * 核心思路就是访问所有的节点,将其左右节点交换,可以采用递归,也可以BFS
*/
public class InvertBinaryTree {
- /** 错误的写法,写顺手了
- public TreeNode invertTree(TreeNode root) {
- if (root == null) {
- return null;
- }
-
- root.right = invertTree(root.left);
- root.left = invertTree(root.right);
- return root;
- }*/
-
public TreeNode invertTree(TreeNode root) {
if (root == null) {
return null;
diff --git a/solution/src/main/java/com/inuker/solution/JumpGame.java b/leetcode/solution/src/JumpGame.java
similarity index 76%
rename from solution/src/main/java/com/inuker/solution/JumpGame.java
rename to leetcode/solution/src/JumpGame.java
index a91d60b..beb0863 100644
--- a/solution/src/main/java/com/inuker/solution/JumpGame.java
+++ b/leetcode/solution/src/JumpGame.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 17/5/11.
- */
-
public class JumpGame {
public boolean canJump(int[] nums) {
diff --git a/solution/src/main/java/com/inuker/solution/JumpGameII.java b/leetcode/solution/src/JumpGameII.java
similarity index 93%
rename from solution/src/main/java/com/inuker/solution/JumpGameII.java
rename to leetcode/solution/src/JumpGameII.java
index c2213d7..03b00b0 100644
--- a/solution/src/main/java/com/inuker/solution/JumpGameII.java
+++ b/leetcode/solution/src/JumpGameII.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2017/5/20.
- */
-
public class JumpGameII {
/**
diff --git a/solution/src/main/java/com/inuker/solution/KthLargestElementInArray.java b/leetcode/solution/src/KthLargestElementInArray.java
similarity index 95%
rename from solution/src/main/java/com/inuker/solution/KthLargestElementInArray.java
rename to leetcode/solution/src/KthLargestElementInArray.java
index 288d2dc..119617b 100644
--- a/solution/src/main/java/com/inuker/solution/KthLargestElementInArray.java
+++ b/leetcode/solution/src/KthLargestElementInArray.java
@@ -1,12 +1,5 @@
-package com.inuker.solution;
-
import java.util.Arrays;
import java.util.PriorityQueue;
-import java.util.Queue;
-
-/**
- * Created by dingjikerbo on 2016/11/17.
- */
public class KthLargestElementInArray {
diff --git a/solution/src/main/java/com/inuker/solution/KthSmallestElementInASortedMatrix.java b/leetcode/solution/src/KthSmallestElementInASortedMatrix.java
similarity index 91%
rename from solution/src/main/java/com/inuker/solution/KthSmallestElementInASortedMatrix.java
rename to leetcode/solution/src/KthSmallestElementInASortedMatrix.java
index e176d07..5d7e85b 100644
--- a/solution/src/main/java/com/inuker/solution/KthSmallestElementInASortedMatrix.java
+++ b/leetcode/solution/src/KthSmallestElementInASortedMatrix.java
@@ -1,11 +1,5 @@
-package com.inuker.solution;
-
import java.util.PriorityQueue;
-/**
- * Created by liwentian on 2017/9/12.
- */
-
public class KthSmallestElementInASortedMatrix {
public int kthSmallest(int[][] matrix, int k) {
diff --git a/solution/src/main/java/com/inuker/solution/KthSmallestElementInBST.java b/leetcode/solution/src/KthSmallestElementInBST.java
similarity index 74%
rename from solution/src/main/java/com/inuker/solution/KthSmallestElementInBST.java
rename to leetcode/solution/src/KthSmallestElementInBST.java
index 488a1ff..31e34d0 100644
--- a/solution/src/main/java/com/inuker/solution/KthSmallestElementInBST.java
+++ b/leetcode/solution/src/KthSmallestElementInBST.java
@@ -1,13 +1,5 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
import java.util.Stack;
-/**
- * Created by dingjikerbo on 16/11/30.
- */
-
/**
* 这题关键是follow up
* 如果更新频繁,则通常的做法每次都是O(n),更优的做法是O(lgn)
@@ -22,30 +14,6 @@
public class KthSmallestElementInBST {
public int kthSmallest(TreeNode root, int k) {
- int[] kth = new int[1];
- inorderTraversal(root, k, kth);
- return kth[0];
- }
-
- private int inorderTraversal(TreeNode root, int k, int[] kth) {
- if (root == null) {
- return k;
- }
-
- k = inorderTraversal(root.left, k, kth);
-
- if (--k == 0) {
- kth[0] = root.val;
- return 0;
- }
-
- return inorderTraversal(root.right, k, kth);
- }
-
- /**
- * 非递归法
- */
- public int kthSmallest2(TreeNode root, int k) {
Stack stack = new Stack<>();
while (root != null || !stack.isEmpty()) {
if (root != null) {
@@ -67,7 +35,7 @@ public int kthSmallest2(TreeNode root, int k) {
/**
* Morris
*/
- private int kthSmallest3(TreeNode root, int k) {
+ private int kthSmallest2(TreeNode root, int k) {
TreeNode temp;
while (root != null) {
diff --git a/solution/src/main/java/com/inuker/solution/LFUCache.java b/leetcode/solution/src/LFUCache.java
similarity index 97%
rename from solution/src/main/java/com/inuker/solution/LFUCache.java
rename to leetcode/solution/src/LFUCache.java
index 797cff6..0878c1a 100644
--- a/solution/src/main/java/com/inuker/solution/LFUCache.java
+++ b/leetcode/solution/src/LFUCache.java
@@ -1,11 +1,6 @@
-package com.inuker.solution;
-
import java.util.HashMap;
import java.util.LinkedHashSet;
-/**
- * Created by dingjikerbo on 17/1/2.
- */
/**
* 和LRU的区别是
* LRU,即便历史频率再高,如果最近用的少了一样踢掉
diff --git a/leetcode/solution/src/LRUCache.java b/leetcode/solution/src/LRUCache.java
new file mode 100644
index 0000000..69b9695
--- /dev/null
+++ b/leetcode/solution/src/LRUCache.java
@@ -0,0 +1,64 @@
+import java.util.HashMap;
+
+public class LRUCache {
+
+ private Node mHead;
+ private HashMap mMap;
+ private int mCapacity;
+
+ public LRUCache(int capacity) {
+ mMap = new HashMap<>();
+ mCapacity = capacity;
+ mHead = new Node(0, 0);
+ }
+
+ public int get(int key) {
+ if (!mMap.containsKey(key)) {
+ return -1;
+ }
+ Node node = mMap.get(key);
+ node.remove();
+ node.add(mHead);
+ return node.val;
+ }
+
+ public void put(int key, int value) {
+ Node node = mMap.get(key);
+ if (node == null) {
+ node = new Node(key, value);
+ mMap.put(key, node);
+ } else {
+ node.val = value;
+ node.remove();
+ }
+ node.add(mHead);
+ if (mMap.size() > mCapacity) {
+ Node prev = mHead.prev;
+ prev.remove();
+ mMap.remove(prev.key);
+ }
+ }
+
+ class Node {
+ Node prev, next;
+ int key, val;
+
+ Node(int key, int val) {
+ this.key = key;
+ this.val = val;
+ prev = next = this;
+ }
+
+ void remove() {
+ prev.next = next;
+ next.prev = prev;
+ }
+
+ void add(Node head) {
+ next = head.next;
+ head.next.prev = this;
+ prev = head;
+ head.next = this;
+ }
+ }
+}
diff --git a/solution/src/main/java/com/inuker/solution/LargestBSTSubtree.java b/leetcode/solution/src/LargestBSTSubtree.java
similarity index 90%
rename from solution/src/main/java/com/inuker/solution/LargestBSTSubtree.java
rename to leetcode/solution/src/LargestBSTSubtree.java
index 3df7a17..d7b906a 100644
--- a/solution/src/main/java/com/inuker/solution/LargestBSTSubtree.java
+++ b/leetcode/solution/src/LargestBSTSubtree.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
-/**
- * Created by dingjikerbo on 16/12/3.
- */
-
public class LargestBSTSubtree {
class Result {
diff --git a/solution/src/main/java/com/inuker/solution/LargestNumber.java b/leetcode/solution/src/LargestNumber.java
similarity index 91%
rename from solution/src/main/java/com/inuker/solution/LargestNumber.java
rename to leetcode/solution/src/LargestNumber.java
index 1e0f9f6..cce7008 100644
--- a/solution/src/main/java/com/inuker/solution/LargestNumber.java
+++ b/leetcode/solution/src/LargestNumber.java
@@ -1,12 +1,6 @@
-package com.inuker.solution;
-
import java.util.Arrays;
import java.util.Comparator;
-/**
- * Created by dingjikerbo on 16/12/8.
- */
-
public class LargestNumber {
public String largestNumber(int[] nums) {
diff --git a/solution/src/main/java/com/inuker/solution/LargestRectangleInHistogram.java b/leetcode/solution/src/LargestRectangleInHistogram.java
similarity index 97%
rename from solution/src/main/java/com/inuker/solution/LargestRectangleInHistogram.java
rename to leetcode/solution/src/LargestRectangleInHistogram.java
index 47f3d94..237defa 100644
--- a/solution/src/main/java/com/inuker/solution/LargestRectangleInHistogram.java
+++ b/leetcode/solution/src/LargestRectangleInHistogram.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/11/23.
- */
-
import java.util.Stack;
/**
diff --git a/leetcode/solution/src/LetterCombinationOfPhoneNumber.java b/leetcode/solution/src/LetterCombinationOfPhoneNumber.java
new file mode 100644
index 0000000..853afbc
--- /dev/null
+++ b/leetcode/solution/src/LetterCombinationOfPhoneNumber.java
@@ -0,0 +1,39 @@
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Queue;
+
+public class LetterCombinationOfPhoneNumber {
+
+ /**
+ * leetcode的测试用例中不包括包含"0"或"1"的情况
+ */
+
+ private static final String[] ARR = {
+ "", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"
+ };
+
+ // 耗时2ms
+ public List letterCombinations(String digits) {
+ List res = new ArrayList<>();
+ if (digits.length() == 0) {
+ return res;
+ }
+ dfs(digits, new StringBuilder(), res, 0);
+ return res;
+ }
+
+ private void dfs(String digits, StringBuilder sb, List res, int start) {
+ if (start >= digits.length()) {
+ res.add(sb.toString());
+ return;
+ }
+
+ int n = digits.charAt(start) - '0';
+ for (char c : ARR[n].toCharArray()) {
+ sb.append(c);
+ dfs(digits, sb, res, start + 1);
+ sb.setLength(sb.length() - 1);
+ }
+ }
+}
diff --git a/solution/src/main/java/com/inuker/solution/LicenseKeyFormatting.java b/leetcode/solution/src/LicenseKeyFormatting.java
similarity index 90%
rename from solution/src/main/java/com/inuker/solution/LicenseKeyFormatting.java
rename to leetcode/solution/src/LicenseKeyFormatting.java
index 6b721b8..18b7b58 100644
--- a/solution/src/main/java/com/inuker/solution/LicenseKeyFormatting.java
+++ b/leetcode/solution/src/LicenseKeyFormatting.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by liwentian on 17/8/26.
- */
-
/**
* 将字符串s按长度k为一组,从右往左重排,组之间用"-"分隔,还要转成大写
* 注意别在最前面多加一个"-",即下面判断i != 0
diff --git a/solution/src/main/java/com/inuker/solution/LinkedListCycle.java b/leetcode/solution/src/LinkedListCycle.java
similarity index 66%
rename from solution/src/main/java/com/inuker/solution/LinkedListCycle.java
rename to leetcode/solution/src/LinkedListCycle.java
index e1cee81..2b6d823 100644
--- a/solution/src/main/java/com/inuker/solution/LinkedListCycle.java
+++ b/leetcode/solution/src/LinkedListCycle.java
@@ -1,14 +1,6 @@
-package com.inuker.solution;
-
-import com.leetcode.library.ListNode;
-
-/**
- * Created by dingjikerbo on 2016/11/17.
- * https://leetcode.com/articles/linked-list-cycle/
- */
-
public class LinkedListCycle {
+ // 注意判空
public boolean hasCycle(ListNode head) {
for (ListNode fast = head, slow = head; fast != null && fast.next != null; ) {
slow = slow.next;
diff --git a/solution/src/main/java/com/inuker/solution/LinkedListCycleII.java b/leetcode/solution/src/LinkedListCycleII.java
similarity index 87%
rename from solution/src/main/java/com/inuker/solution/LinkedListCycleII.java
rename to leetcode/solution/src/LinkedListCycleII.java
index 8fe19d7..5c16094 100644
--- a/solution/src/main/java/com/inuker/solution/LinkedListCycleII.java
+++ b/leetcode/solution/src/LinkedListCycleII.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import com.leetcode.library.ListNode;
-
-/**
- * Created by liwentian on 2017/9/11.
- */
-
public class LinkedListCycleII {
/**
* 这里有个问题,如果链表是a,b,然后又回到a
diff --git a/solution/src/main/java/com/inuker/solution/LinkedListRandomNode.java b/leetcode/solution/src/LinkedListRandomNode.java
similarity index 85%
rename from solution/src/main/java/com/inuker/solution/LinkedListRandomNode.java
rename to leetcode/solution/src/LinkedListRandomNode.java
index 02d1fcb..3b7573b 100644
--- a/solution/src/main/java/com/inuker/solution/LinkedListRandomNode.java
+++ b/leetcode/solution/src/LinkedListRandomNode.java
@@ -1,13 +1,5 @@
-package com.inuker.solution;
-
-import com.leetcode.library.ListNode;
-
import java.util.Random;
-/**
- * Created by dingjikerbo on 2016/12/17.
- */
-
public class LinkedListRandomNode {
private Random mRandom;
diff --git a/solution/src/main/java/com/inuker/solution/LoggerRateLimiter.java b/leetcode/solution/src/LoggerRateLimiter.java
similarity index 95%
rename from solution/src/main/java/com/inuker/solution/LoggerRateLimiter.java
rename to leetcode/solution/src/LoggerRateLimiter.java
index 8aab161..db6a6e5 100644
--- a/solution/src/main/java/com/inuker/solution/LoggerRateLimiter.java
+++ b/leetcode/solution/src/LoggerRateLimiter.java
@@ -1,14 +1,8 @@
-package com.inuker.solution;
-
import java.util.Comparator;
import java.util.HashMap;
import java.util.PriorityQueue;
import java.util.Queue;
-/**
- * Created by liwentian on 2017/8/31.
- */
-
/**
* 如果要考虑到空间消耗,则要另外定义一个List,每次新来一条日志,都要遍历
* list中10s外的poll了,同时从map中remove
diff --git a/solution/src/main/java/com/inuker/solution/LongestAbsoluteFilePath.java b/leetcode/solution/src/LongestAbsoluteFilePath.java
similarity index 84%
rename from solution/src/main/java/com/inuker/solution/LongestAbsoluteFilePath.java
rename to leetcode/solution/src/LongestAbsoluteFilePath.java
index 6aa74fe..2116455 100644
--- a/solution/src/main/java/com/inuker/solution/LongestAbsoluteFilePath.java
+++ b/leetcode/solution/src/LongestAbsoluteFilePath.java
@@ -1,13 +1,5 @@
-package com.inuker.solution;
-
-import java.util.ArrayDeque;
-import java.util.Deque;
import java.util.Stack;
-/**
- * Created by dingjikerbo on 16/11/26.
- */
-
public class LongestAbsoluteFilePath {
// 耗时4ms
diff --git a/solution/src/main/java/com/inuker/solution/LongestCommonPrefix.java b/leetcode/solution/src/LongestCommonPrefix.java
similarity index 89%
rename from solution/src/main/java/com/inuker/solution/LongestCommonPrefix.java
rename to leetcode/solution/src/LongestCommonPrefix.java
index 4996559..1246091 100644
--- a/solution/src/main/java/com/inuker/solution/LongestCommonPrefix.java
+++ b/leetcode/solution/src/LongestCommonPrefix.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 17/5/2.
- */
-
/**
* 注意只有一个字符串的情况
* 还要注意字符串越界问题
diff --git a/solution/src/main/java/com/inuker/solution/LongestConsecutiveSequence.java b/leetcode/solution/src/LongestConsecutiveSequence.java
similarity index 93%
rename from solution/src/main/java/com/inuker/solution/LongestConsecutiveSequence.java
rename to leetcode/solution/src/LongestConsecutiveSequence.java
index 7ea27cb..cf90150 100644
--- a/solution/src/main/java/com/inuker/solution/LongestConsecutiveSequence.java
+++ b/leetcode/solution/src/LongestConsecutiveSequence.java
@@ -1,9 +1,6 @@
-package com.inuker.solution;
-
import java.util.HashMap;
/**
- * Created by dingjikerbo on 16/11/22.
* https://leetcode.com/articles/longest-consecutive-sequence/
*/
public class LongestConsecutiveSequence {
diff --git a/solution/src/main/java/com/inuker/solution/LongestIncreasingPathInAMatrix.java b/leetcode/solution/src/LongestIncreasingPathInAMatrix.java
similarity index 94%
rename from solution/src/main/java/com/inuker/solution/LongestIncreasingPathInAMatrix.java
rename to leetcode/solution/src/LongestIncreasingPathInAMatrix.java
index 4af1f18..e4eb4ff 100644
--- a/solution/src/main/java/com/inuker/solution/LongestIncreasingPathInAMatrix.java
+++ b/leetcode/solution/src/LongestIncreasingPathInAMatrix.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by liwentian on 2017/9/1.
- */
-
/**
* https://leetcode.com/articles/longest-increasing-path-matrix/
*/
diff --git a/solution/src/main/java/com/inuker/solution/LongestIncreasingSubsequence.java b/leetcode/solution/src/LongestIncreasingSubsequence.java
similarity index 94%
rename from solution/src/main/java/com/inuker/solution/LongestIncreasingSubsequence.java
rename to leetcode/solution/src/LongestIncreasingSubsequence.java
index 34a886e..b8d1fd8 100644
--- a/solution/src/main/java/com/inuker/solution/LongestIncreasingSubsequence.java
+++ b/leetcode/solution/src/LongestIncreasingSubsequence.java
@@ -1,11 +1,5 @@
-package com.inuker.solution;
-
import java.util.Arrays;
-/**
- * Created by dingjikerbo on 17/1/5.
- */
-
public class LongestIncreasingSubsequence {
/**
diff --git a/solution/src/main/java/com/inuker/solution/LongestPalindrome.java b/leetcode/solution/src/LongestPalindrome.java
similarity index 85%
rename from solution/src/main/java/com/inuker/solution/LongestPalindrome.java
rename to leetcode/solution/src/LongestPalindrome.java
index 7e2224c..4326fbe 100644
--- a/solution/src/main/java/com/inuker/solution/LongestPalindrome.java
+++ b/leetcode/solution/src/LongestPalindrome.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/12/19.
- */
-
public class LongestPalindrome {
public int longestPalindrome(String s) {
diff --git a/solution/src/main/java/com/inuker/solution/LongestPalindromicSubstring.java b/leetcode/solution/src/LongestPalindromicSubstring.java
similarity index 61%
rename from solution/src/main/java/com/inuker/solution/LongestPalindromicSubstring.java
rename to leetcode/solution/src/LongestPalindromicSubstring.java
index 1217e54..9c2d555 100644
--- a/solution/src/main/java/com/inuker/solution/LongestPalindromicSubstring.java
+++ b/leetcode/solution/src/LongestPalindromicSubstring.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/11/16.
- */
-
/**
* 这题采用动态规划也可,但是不论时间还是空间性能都不好
*/
@@ -11,21 +5,26 @@ public class LongestPalindromicSubstring {
private int begin, maxLen;
- // 耗时14ms,平均复杂度O(n)
- public String longestPalindrome(String s) {
+ // 耗时11ms,平均复杂度O(n)
+ public String longestPalindrome(String s) {
+ int[] res = new int[2];
for (int i = 0; i < s.length(); i++) {
- helper(s, i, i);
- helper(s, i, i + 1);
+ helper(s, i - 1, i + 1, res);
+ helper(s, i, i + 1, res);
}
- return s.substring(begin, begin + maxLen);
+ return s.substring(res[1], res[1] + res[0]);
}
- private void helper(String s, int i, int j) {
- for (; i >= 0 && j < s.length() && s.charAt(i) == s.charAt(j); i--, j++) ;
- int len = j - i - 1;
- if (len > maxLen) {
- maxLen = len;
- begin = i + 1;
+ private void helper(String s, int left, int right, int[] res) {
+ for ( ; left >= 0 && right < s.length(); left--, right++) {
+ if (s.charAt(left) != s.charAt(right)) {
+ break;
+ }
+ }
+ int len = --right - ++left + 1;
+ if (len > res[0]) {
+ res[0] = len;
+ res[1] = left;
}
}
diff --git a/solution/src/main/java/com/inuker/solution/LongestSubstringWithAtLeastKRepeatingCharacters.java b/leetcode/solution/src/LongestSubstringWithAtLeastKRepeatingCharacters.java
similarity index 95%
rename from solution/src/main/java/com/inuker/solution/LongestSubstringWithAtLeastKRepeatingCharacters.java
rename to leetcode/solution/src/LongestSubstringWithAtLeastKRepeatingCharacters.java
index 3da934b..0abd7e2 100644
--- a/solution/src/main/java/com/inuker/solution/LongestSubstringWithAtLeastKRepeatingCharacters.java
+++ b/leetcode/solution/src/LongestSubstringWithAtLeastKRepeatingCharacters.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/11/27.
- */
-
/**
* 要注意,这道题不能用window法来做,window法是先尽可能扩张window到不符合条件,然后
* 缩小window直到将不符合因素排除,所以通常适用于AtMost类型的问题,因为首先要超出most,
diff --git a/solution/src/main/java/com/inuker/solution/LongestSubstringWithAtMostKDistinctCharacters.java b/leetcode/solution/src/LongestSubstringWithAtMostKDistinctCharacters.java
similarity index 87%
rename from solution/src/main/java/com/inuker/solution/LongestSubstringWithAtMostKDistinctCharacters.java
rename to leetcode/solution/src/LongestSubstringWithAtMostKDistinctCharacters.java
index f8d46e3..46cdd41 100644
--- a/solution/src/main/java/com/inuker/solution/LongestSubstringWithAtMostKDistinctCharacters.java
+++ b/leetcode/solution/src/LongestSubstringWithAtMostKDistinctCharacters.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import java.util.HashMap;
-
-/**
- * Created by dingjikerbo on 16/11/27.
- */
-
public class LongestSubstringWithAtMostKDistinctCharacters {
/**
diff --git a/solution/src/main/java/com/inuker/solution/LongestSubstringWithAtMostTwoDistinctCharacters.java b/leetcode/solution/src/LongestSubstringWithAtMostTwoDistinctCharacters.java
similarity index 85%
rename from solution/src/main/java/com/inuker/solution/LongestSubstringWithAtMostTwoDistinctCharacters.java
rename to leetcode/solution/src/LongestSubstringWithAtMostTwoDistinctCharacters.java
index 24e48b7..aa25f8e 100644
--- a/solution/src/main/java/com/inuker/solution/LongestSubstringWithAtMostTwoDistinctCharacters.java
+++ b/leetcode/solution/src/LongestSubstringWithAtMostTwoDistinctCharacters.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import java.util.HashMap;
-
-/**
- * Created by dingjikerbo on 16/11/27.
- */
-
public class LongestSubstringWithAtMostTwoDistinctCharacters {
// 7ms
diff --git a/solution/src/main/java/com/inuker/solution/LongestSubstringWithoutRepeatingCharacters.java b/leetcode/solution/src/LongestSubstringWithoutRepeatingCharacters.java
similarity index 88%
rename from solution/src/main/java/com/inuker/solution/LongestSubstringWithoutRepeatingCharacters.java
rename to leetcode/solution/src/LongestSubstringWithoutRepeatingCharacters.java
index 4465e72..3ff3e38 100644
--- a/solution/src/main/java/com/inuker/solution/LongestSubstringWithoutRepeatingCharacters.java
+++ b/leetcode/solution/src/LongestSubstringWithoutRepeatingCharacters.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/11/17.
- */
-
/**
* https://leetcode.com/articles/longest-substring-without-repeating-characters/
*/
diff --git a/solution/src/main/java/com/inuker/solution/LongestValidParentheses.java b/leetcode/solution/src/LongestValidParentheses.java
similarity index 92%
rename from solution/src/main/java/com/inuker/solution/LongestValidParentheses.java
rename to leetcode/solution/src/LongestValidParentheses.java
index e6789ca..b1ee7b9 100644
--- a/solution/src/main/java/com/inuker/solution/LongestValidParentheses.java
+++ b/leetcode/solution/src/LongestValidParentheses.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/12/17.
- */
-
import java.util.Stack;
/**
diff --git a/solution/src/main/java/com/inuker/solution/LongestWordInDictionaryThroughDeleting.java b/leetcode/solution/src/LongestWordInDictionaryThroughDeleting.java
similarity index 92%
rename from solution/src/main/java/com/inuker/solution/LongestWordInDictionaryThroughDeleting.java
rename to leetcode/solution/src/LongestWordInDictionaryThroughDeleting.java
index 1a492c8..98a9890 100644
--- a/solution/src/main/java/com/inuker/solution/LongestWordInDictionaryThroughDeleting.java
+++ b/leetcode/solution/src/LongestWordInDictionaryThroughDeleting.java
@@ -1,11 +1,5 @@
-package com.inuker.solution;
-
import java.util.List;
-/**
- * Created by liwentian on 2017/12/10.
- */
-
public class LongestWordInDictionaryThroughDeleting {
public String findLongestWord(String s, List d) {
diff --git a/solution/src/main/java/com/inuker/solution/LowestCommonAncestorOfBinarySearchTree.java b/leetcode/solution/src/LowestCommonAncestorOfBinarySearchTree.java
similarity index 92%
rename from solution/src/main/java/com/inuker/solution/LowestCommonAncestorOfBinarySearchTree.java
rename to leetcode/solution/src/LowestCommonAncestorOfBinarySearchTree.java
index 8b58c0d..b895c46 100644
--- a/solution/src/main/java/com/inuker/solution/LowestCommonAncestorOfBinarySearchTree.java
+++ b/leetcode/solution/src/LowestCommonAncestorOfBinarySearchTree.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
-/**
- * Created by dingjikerbo on 2016/11/16.
- */
-
public class LowestCommonAncestorOfBinarySearchTree {
/**
diff --git a/solution/src/main/java/com/inuker/solution/LowestCommonAncestorOfBinaryTree.java b/leetcode/solution/src/LowestCommonAncestorOfBinaryTree.java
similarity index 90%
rename from solution/src/main/java/com/inuker/solution/LowestCommonAncestorOfBinaryTree.java
rename to leetcode/solution/src/LowestCommonAncestorOfBinaryTree.java
index 13ca994..4c5689f 100644
--- a/solution/src/main/java/com/inuker/solution/LowestCommonAncestorOfBinaryTree.java
+++ b/leetcode/solution/src/LowestCommonAncestorOfBinaryTree.java
@@ -1,16 +1,5 @@
-package com.inuker.solution;
+import java.util.*;
-import com.leetcode.library.TreeNode;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.Queue;
-import java.util.Set;
-
-/**
- * Created by dingjikerbo on 2016/11/16.
- */
public class LowestCommonAncestorOfBinaryTree {
/**
diff --git a/solution/src/main/java/com/inuker/solution/MajorityElement.java b/leetcode/solution/src/MajorityElement.java
similarity index 84%
rename from solution/src/main/java/com/inuker/solution/MajorityElement.java
rename to leetcode/solution/src/MajorityElement.java
index f9c00cb..bdedd39 100644
--- a/solution/src/main/java/com/inuker/solution/MajorityElement.java
+++ b/leetcode/solution/src/MajorityElement.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by liwentian on 2017/9/10.
- */
-
public class MajorityElement {
public int majorityElement(int[] nums) {
diff --git a/solution/src/main/java/com/inuker/solution/MajorityElementII.java b/leetcode/solution/src/MajorityElementII.java
similarity index 94%
rename from solution/src/main/java/com/inuker/solution/MajorityElementII.java
rename to leetcode/solution/src/MajorityElementII.java
index a7496b8..83a9cce 100644
--- a/solution/src/main/java/com/inuker/solution/MajorityElementII.java
+++ b/leetcode/solution/src/MajorityElementII.java
@@ -1,12 +1,6 @@
-package com.inuker.solution;
-
import java.util.ArrayList;
import java.util.List;
-/**
- * Created by liwentian on 2017/9/10.
- */
-
public class MajorityElementII {
public List majorityElement(int[] nums) {
diff --git a/solution/src/main/java/com/inuker/solution/MaxConsecutiveOnes.java b/leetcode/solution/src/MaxConsecutiveOnes.java
similarity index 76%
rename from solution/src/main/java/com/inuker/solution/MaxConsecutiveOnes.java
rename to leetcode/solution/src/MaxConsecutiveOnes.java
index d9215dd..f51f473 100644
--- a/solution/src/main/java/com/inuker/solution/MaxConsecutiveOnes.java
+++ b/leetcode/solution/src/MaxConsecutiveOnes.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by liwentian on 2017/9/10.
- */
-
public class MaxConsecutiveOnes {
public int findMaxConsecutiveOnes(int[] nums) {
diff --git a/solution/src/main/java/com/inuker/solution/MaxConsecutiveOnesII.java b/leetcode/solution/src/MaxConsecutiveOnesII.java
similarity index 95%
rename from solution/src/main/java/com/inuker/solution/MaxConsecutiveOnesII.java
rename to leetcode/solution/src/MaxConsecutiveOnesII.java
index a3b7867..b98a62a 100644
--- a/solution/src/main/java/com/inuker/solution/MaxConsecutiveOnesII.java
+++ b/leetcode/solution/src/MaxConsecutiveOnesII.java
@@ -1,12 +1,6 @@
-package com.inuker.solution;
-
import java.util.LinkedList;
import java.util.Queue;
-/**
- * Created by liwentian on 2017/9/10.
- */
-
public class MaxConsecutiveOnesII {
/**
diff --git a/solution/src/main/java/com/inuker/solution/MaxPointsOnALine.java b/leetcode/solution/src/MaxPointsOnALine.java
similarity index 95%
rename from solution/src/main/java/com/inuker/solution/MaxPointsOnALine.java
rename to leetcode/solution/src/MaxPointsOnALine.java
index c2b6ac4..f77bcfd 100644
--- a/solution/src/main/java/com/inuker/solution/MaxPointsOnALine.java
+++ b/leetcode/solution/src/MaxPointsOnALine.java
@@ -1,12 +1,6 @@
-package com.inuker.solution;
-
import java.awt.Point;
import java.util.HashMap;
-/**
- * Created by dingjikerbo on 16/12/7.
- */
-
/**
* TestCase
* 边界条件很多,比如有重复的点,有斜率无穷大的线
diff --git a/solution/src/main/java/com/inuker/solution/MaximalRectangle.java b/leetcode/solution/src/MaximalRectangle.java
similarity index 96%
rename from solution/src/main/java/com/inuker/solution/MaximalRectangle.java
rename to leetcode/solution/src/MaximalRectangle.java
index 053904d..ddc77be 100644
--- a/solution/src/main/java/com/inuker/solution/MaximalRectangle.java
+++ b/leetcode/solution/src/MaximalRectangle.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/11/23.
- */
-
public abstract class MaximalRectangle {
// 耗时10ms,时间复杂度是O(mn),空间复杂度O(n)
diff --git a/solution/src/main/java/com/inuker/solution/MaximalSquare.java b/leetcode/solution/src/MaximalSquare.java
similarity index 93%
rename from solution/src/main/java/com/inuker/solution/MaximalSquare.java
rename to leetcode/solution/src/MaximalSquare.java
index 7558aee..2000238 100644
--- a/solution/src/main/java/com/inuker/solution/MaximalSquare.java
+++ b/leetcode/solution/src/MaximalSquare.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/11/23.
- */
-
/**
* https://leetcode.com/articles/maximal-square/
*/
diff --git a/leetcode/solution/src/MaximumBinaryTree.java b/leetcode/solution/src/MaximumBinaryTree.java
new file mode 100644
index 0000000..767ca33
--- /dev/null
+++ b/leetcode/solution/src/MaximumBinaryTree.java
@@ -0,0 +1,25 @@
+public class MaximumBinaryTree {
+
+ /**
+ * 复杂度平均O(nlgn),最差O(n^2)
+ */
+ public TreeNode constructMaximumBinaryTree(int[] nums, int start, int end) {
+ if (start > end) {
+ return null;
+ }
+ int max = start;
+ for (int i = start + 1; i <= end; i++) {
+ if (nums[i] > nums[max]) {
+ max = i;
+ }
+ }
+ TreeNode root = new TreeNode(nums[max]);
+ root.left = constructMaximumBinaryTree(nums, start, max - 1);
+ root.right = constructMaximumBinaryTree(nums, max + 1, end);
+ return root;
+ }
+
+ public TreeNode constructMaximumBinaryTree(int[] nums) {
+ return constructMaximumBinaryTree(nums, 0, nums.length - 1);
+ }
+}
diff --git a/solution/src/main/java/com/inuker/solution/MaximumDepthOfBinaryTree.java b/leetcode/solution/src/MaximumDepthOfBinaryTree.java
similarity index 53%
rename from solution/src/main/java/com/inuker/solution/MaximumDepthOfBinaryTree.java
rename to leetcode/solution/src/MaximumDepthOfBinaryTree.java
index 2e1f7c0..73fe2f7 100644
--- a/solution/src/main/java/com/inuker/solution/MaximumDepthOfBinaryTree.java
+++ b/leetcode/solution/src/MaximumDepthOfBinaryTree.java
@@ -1,14 +1,6 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
-/**
- * Created by dingjikerbo on 16/11/28.
- */
-
public class MaximumDepthOfBinaryTree {
- private int maxDepth(TreeNode node) {
+ public int maxDepth(TreeNode node) {
if (node == null) {
return 0;
}
diff --git a/solution/src/main/java/com/inuker/solution/MaximumGap.java b/leetcode/solution/src/MaximumGap.java
similarity index 95%
rename from solution/src/main/java/com/inuker/solution/MaximumGap.java
rename to leetcode/solution/src/MaximumGap.java
index e91a3ef..c151ae1 100644
--- a/solution/src/main/java/com/inuker/solution/MaximumGap.java
+++ b/leetcode/solution/src/MaximumGap.java
@@ -1,11 +1,5 @@
-package com.inuker.solution;
-
import java.util.Arrays;
-/**
- * Created by dingjikerbo on 16/12/8.
- */
-
public class MaximumGap {
/**
diff --git a/solution/src/main/java/com/inuker/solution/MaximumProductSubarray.java b/leetcode/solution/src/MaximumProductSubarray.java
similarity index 92%
rename from solution/src/main/java/com/inuker/solution/MaximumProductSubarray.java
rename to leetcode/solution/src/MaximumProductSubarray.java
index 8839090..6c4d5a9 100644
--- a/solution/src/main/java/com/inuker/solution/MaximumProductSubarray.java
+++ b/leetcode/solution/src/MaximumProductSubarray.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 17/1/5.
- */
-
public class MaximumProductSubarray {
/**
diff --git a/solution/src/main/java/com/inuker/solution/MaximumSizeSubarraySumEqualsK.java b/leetcode/solution/src/MaximumSizeSubarraySumEqualsK.java
similarity index 88%
rename from solution/src/main/java/com/inuker/solution/MaximumSizeSubarraySumEqualsK.java
rename to leetcode/solution/src/MaximumSizeSubarraySumEqualsK.java
index f7663da..022112d 100644
--- a/solution/src/main/java/com/inuker/solution/MaximumSizeSubarraySumEqualsK.java
+++ b/leetcode/solution/src/MaximumSizeSubarraySumEqualsK.java
@@ -1,11 +1,5 @@
-package com.inuker.solution;
-
import java.util.HashMap;
-/**
- * Created by dingjikerbo on 2016/11/19.
- */
-
public class MaximumSizeSubarraySumEqualsK {
// 耗时29ms,时间复杂度O(n)
diff --git a/solution/src/main/java/com/inuker/solution/MaximumSubarray.java b/leetcode/solution/src/MaximumSubarray.java
similarity index 58%
rename from solution/src/main/java/com/inuker/solution/MaximumSubarray.java
rename to leetcode/solution/src/MaximumSubarray.java
index bf81892..2c7d279 100644
--- a/solution/src/main/java/com/inuker/solution/MaximumSubarray.java
+++ b/leetcode/solution/src/MaximumSubarray.java
@@ -1,34 +1,24 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/12/15.
- */
-
public class MaximumSubarray {
// dp[i]表示包含第i个元素时的最大和
public int maxSubArray(int[] nums) {
- if (nums.length == 0) {
- return 0;
- }
int[] dp = new int[nums.length];
int max = Integer.MIN_VALUE;
for (int i = 0; i < nums.length; i++) {
- dp[i] = nums[i];
- if (i > 0 && dp[i - 1] > 0) {
- dp[i] += dp[i - 1];
- }
+ dp[i] = Math.max(i > 0 ? dp[i - 1] + nums[i] : nums[i], nums[i]);
max = Math.max(max, dp[i]);
}
return max;
}
- public int maxSubArray2(int[] nums) {
+ /* 这里dp其实可以去掉,换成一个普通int变量即可
+ public int maxSubArray(int[] nums) {
int max = Integer.MIN_VALUE, prev = 0;
for (int i = 0; i < nums.length; i++) {
- prev = Math.max(nums[i], nums[i] + prev);
+ prev = Math.max(i > 0 ? prev + nums[i] : nums[i], nums[i]);
max = Math.max(max, prev);
}
return max;
}
+ */
}
diff --git a/solution/src/main/java/com/inuker/solution/MedianOfTwoSortedArrays.java b/leetcode/solution/src/MedianOfTwoSortedArrays.java
similarity index 93%
rename from solution/src/main/java/com/inuker/solution/MedianOfTwoSortedArrays.java
rename to leetcode/solution/src/MedianOfTwoSortedArrays.java
index 9e7a4d5..1edb615 100644
--- a/solution/src/main/java/com/inuker/solution/MedianOfTwoSortedArrays.java
+++ b/leetcode/solution/src/MedianOfTwoSortedArrays.java
@@ -1,7 +1,4 @@
-package com.inuker.solution;
-
/**
- * Created by dingjikerbo on 16/12/20.
* https://leetcode.com/articles/median-of-two-sorted-arrays/
*/
@@ -27,7 +24,7 @@ private double findKth(int[] nums1, int start1, int end1, int[] nums2, int start
if (len1 > len2) {
return findKth(nums2, start2, end2, nums1, start1, end1, k);
} else if (len1 == 0) {
- return nums2[k - 1];
+ return nums2[start2 + k - 1];
} else if (k == 1) {
return Math.min(nums1[start1], nums2[start2]);
}
diff --git a/solution/src/main/java/com/inuker/solution/MeetingRooms.java b/leetcode/solution/src/MeetingRooms.java
similarity index 84%
rename from solution/src/main/java/com/inuker/solution/MeetingRooms.java
rename to leetcode/solution/src/MeetingRooms.java
index 490e3c8..c2ae246 100644
--- a/solution/src/main/java/com/inuker/solution/MeetingRooms.java
+++ b/leetcode/solution/src/MeetingRooms.java
@@ -1,14 +1,6 @@
-package com.inuker.solution;
-
-import com.leetcode.library.Interval;
-
import java.util.Arrays;
import java.util.Comparator;
-/**
- * Created by dingjikerbo on 16/11/20.
- */
-
/**
* https://leetcode.com/articles/meeting-rooms/
*/
diff --git a/solution/src/main/java/com/inuker/solution/MeetingRoomsII.java b/leetcode/solution/src/MeetingRoomsII.java
similarity index 88%
rename from solution/src/main/java/com/inuker/solution/MeetingRoomsII.java
rename to leetcode/solution/src/MeetingRoomsII.java
index 16540f1..4d0dd4b 100644
--- a/solution/src/main/java/com/inuker/solution/MeetingRoomsII.java
+++ b/leetcode/solution/src/MeetingRoomsII.java
@@ -1,16 +1,8 @@
-package com.inuker.solution;
-
-import com.leetcode.library.Interval;
-
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Queue;
-/**
- * Created by dingjikerbo on 16/11/20.
- */
-
public class MeetingRoomsII {
// 耗时17ms,时间复杂度O(nlgn)
diff --git a/solution/src/main/java/com/inuker/solution/MergeIntervals.java b/leetcode/solution/src/MergeIntervals.java
similarity index 90%
rename from solution/src/main/java/com/inuker/solution/MergeIntervals.java
rename to leetcode/solution/src/MergeIntervals.java
index 7242531..ba5e827 100644
--- a/solution/src/main/java/com/inuker/solution/MergeIntervals.java
+++ b/leetcode/solution/src/MergeIntervals.java
@@ -1,14 +1,9 @@
-package com.inuker.solution;
-
-import com.leetcode.library.Interval;
-
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
/**
- * Created by dingjikerbo on 16/11/21.
* https://leetcode.com/articles/merge-intervals/
*/
diff --git a/leetcode/solution/src/MergeKSortedList.java b/leetcode/solution/src/MergeKSortedList.java
new file mode 100644
index 0000000..c046b9d
--- /dev/null
+++ b/leetcode/solution/src/MergeKSortedList.java
@@ -0,0 +1,81 @@
+import java.util.Comparator;
+import java.util.PriorityQueue;
+
+/**
+ * https://leetcode.com/articles/merge-k-sorted-list/
+ */
+
+public class MergeKSortedList {
+
+ // 耗时19ms
+ // 时间复杂度为O(knlgn),空间复杂度O(k)
+ /**
+ * 这里要注意lists中可能有node为null
+ */
+ public ListNode mergeKLists(ListNode[] lists) {
+ ListNode dummy = new ListNode(0), cur = dummy;
+
+ PriorityQueue queue = new PriorityQueue<>(new Comparator() {
+ @Override
+ public int compare(ListNode node1, ListNode node2) {
+ return node1.val - node2.val;
+ }
+ });
+
+ for (ListNode node : lists) {
+ if (node != null) {
+ queue.offer(node);
+ }
+ }
+
+ while (!queue.isEmpty()) {
+ ListNode node = queue.poll();
+ cur.next = node;
+ cur = cur.next;
+ if (node.next != null) {
+ queue.offer(node.next);
+ }
+ }
+
+ return dummy.next;
+ }
+
+ /**
+ * 第二种方法
+ * 时间复杂度O(Nlgk),空间O(l)
+ * 耗时10ms
+ */
+ public ListNode mergeKLists2(ListNode[] lists) {
+ return helper(lists, 0, lists.length - 1);
+ }
+
+ private ListNode helper(ListNode[] lists, int start, int end) {
+ if (start > end) {
+ return null;
+ }
+ if (start == end) {
+ return lists[start];
+ }
+ int mid = start + (end - start) / 2;
+ ListNode l1 = helper(lists, start, mid);
+ ListNode l2 = helper(lists, mid + 1, end);
+ return mergeTwoLists(l1, l2);
+ }
+
+ public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
+ ListNode dummy = new ListNode(0);
+ ListNode p = l1, q = l2, cur = dummy;
+ for ( ; p != null && q != null; ) {
+ if (p.val < q.val) {
+ cur.next = p;
+ p = p.next;
+ } else {
+ cur.next = q;
+ q = q.next;
+ }
+ cur = cur.next;
+ }
+ cur.next = p != null ? p : q;
+ return dummy.next;
+ }
+}
diff --git a/solution/src/main/java/com/inuker/solution/MergeSortedArray.java b/leetcode/solution/src/MergeSortedArray.java
similarity index 87%
rename from solution/src/main/java/com/inuker/solution/MergeSortedArray.java
rename to leetcode/solution/src/MergeSortedArray.java
index 1dfd673..d834f14 100644
--- a/solution/src/main/java/com/inuker/solution/MergeSortedArray.java
+++ b/leetcode/solution/src/MergeSortedArray.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/11/23.
- */
-
public class MergeSortedArray {
public void merge(int[] nums1, int m, int[] nums2, int n) {
diff --git a/leetcode/solution/src/MergeTwoBinaryTrees.java b/leetcode/solution/src/MergeTwoBinaryTrees.java
new file mode 100644
index 0000000..49cae76
--- /dev/null
+++ b/leetcode/solution/src/MergeTwoBinaryTrees.java
@@ -0,0 +1,13 @@
+public class MergeTwoBinaryTrees {
+
+ public TreeNode mergeTrees(TreeNode t1, TreeNode t2) {
+ if (t1 == null)
+ return t2;
+ if (t2 == null)
+ return t1;
+ t1.val += t2.val;
+ t1.left = mergeTrees(t1.left, t2.left);
+ t1.right = mergeTrees(t1.right, t2.right);
+ return t1;
+ }
+}
diff --git a/solution/src/main/java/com/inuker/solution/MergeTwoSortedList.java b/leetcode/solution/src/MergeTwoSortedList.java
similarity index 81%
rename from solution/src/main/java/com/inuker/solution/MergeTwoSortedList.java
rename to leetcode/solution/src/MergeTwoSortedList.java
index 2b3e110..f006d7c 100644
--- a/solution/src/main/java/com/inuker/solution/MergeTwoSortedList.java
+++ b/leetcode/solution/src/MergeTwoSortedList.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import com.leetcode.library.ListNode;
-
-/**
- * Created by dingjikerbo on 2016/11/17.
- */
-
public class MergeTwoSortedList {
// 耗时15ms
diff --git a/solution/src/main/java/com/inuker/solution/MinStack.java b/leetcode/solution/src/MinStack.java
similarity index 89%
rename from solution/src/main/java/com/inuker/solution/MinStack.java
rename to leetcode/solution/src/MinStack.java
index 253ab94..ac8cf47 100644
--- a/solution/src/main/java/com/inuker/solution/MinStack.java
+++ b/leetcode/solution/src/MinStack.java
@@ -1,11 +1,5 @@
-package com.inuker.solution;
-
import java.util.Stack;
-/**
- * Created by dingjikerbo on 2016/11/17.
- */
-
public class MinStack {
Stack mMinStack;
diff --git a/solution/src/main/java/com/inuker/solution/MinimumDepthOfBinaryTree.java b/leetcode/solution/src/MinimumDepthOfBinaryTree.java
similarity index 50%
rename from solution/src/main/java/com/inuker/solution/MinimumDepthOfBinaryTree.java
rename to leetcode/solution/src/MinimumDepthOfBinaryTree.java
index ceffc06..82ad4f4 100644
--- a/solution/src/main/java/com/inuker/solution/MinimumDepthOfBinaryTree.java
+++ b/leetcode/solution/src/MinimumDepthOfBinaryTree.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
-/**
- * Created by dingjikerbo on 16/11/28.
- */
-
public class MinimumDepthOfBinaryTree {
/**
@@ -24,31 +16,15 @@ public int minDepth(TreeNode root) {
if (root == null) {
return 0;
}
- // 如果一边空了,那这边深度为0,但是由于不是叶子节点,所以不能算,得看另一边。
+ if (root.left == null && root.right == null) {
+ return 1;
+ }
if (root.left == null) {
return minDepth(root.right) + 1;
- } else if (root.right == null) {
- return minDepth(root.left) + 1;
- } else {
- return Math.min(minDepth(root.left), minDepth(root.right)) + 1;
}
- }
-
- /**
- public int minDepth(TreeNode root) {
- if (root == null) {
- return 0;
+ if (root.right == null) {
+ return minDepth(root.left) + 1;
}
- return helper(root);
+ return Math.min(minDepth(root.left), minDepth(root.right)) + 1;
}
-
- private int helper(TreeNode root) {
- if (root == null) {
- return Integer.MAX_VALUE;
- }
- if (root.left == null && root.right == null) {
- return 1;
- }
- return Math.min(helper(root.left), helper(root.right)) + 1;
- }*/
}
diff --git a/solution/src/main/java/com/inuker/solution/MinimumHeightTrees.java b/leetcode/solution/src/MinimumHeightTrees.java
similarity index 86%
rename from solution/src/main/java/com/inuker/solution/MinimumHeightTrees.java
rename to leetcode/solution/src/MinimumHeightTrees.java
index 8d51200..a231294 100644
--- a/solution/src/main/java/com/inuker/solution/MinimumHeightTrees.java
+++ b/leetcode/solution/src/MinimumHeightTrees.java
@@ -1,14 +1,4 @@
-package com.inuker.solution;
-
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-
-/**
- * Created by liwentian on 2017/9/3.
- */
+import java.util.*;
/**
* 从叶子节点开始,一层层剥掉,直到最后剩下的节点就是所求深度最大的
diff --git a/solution/src/main/java/com/inuker/solution/MinimumSizeSubarraySum.java b/leetcode/solution/src/MinimumSizeSubarraySum.java
similarity index 94%
rename from solution/src/main/java/com/inuker/solution/MinimumSizeSubarraySum.java
rename to leetcode/solution/src/MinimumSizeSubarraySum.java
index 4bf67a0..74245f5 100644
--- a/solution/src/main/java/com/inuker/solution/MinimumSizeSubarraySum.java
+++ b/leetcode/solution/src/MinimumSizeSubarraySum.java
@@ -1,11 +1,5 @@
-package com.inuker.solution;
-
import java.util.Arrays;
-/**
- * Created by dingjikerbo on 16/11/22.
- */
-
public class MinimumSizeSubarraySum {
/**
* 仍然采用滑动窗口的办法
diff --git a/solution/src/main/java/com/inuker/solution/MinimumWindowSubstring.java b/leetcode/solution/src/MinimumWindowSubstring.java
similarity index 92%
rename from solution/src/main/java/com/inuker/solution/MinimumWindowSubstring.java
rename to leetcode/solution/src/MinimumWindowSubstring.java
index 6886d04..57186fb 100644
--- a/solution/src/main/java/com/inuker/solution/MinimumWindowSubstring.java
+++ b/leetcode/solution/src/MinimumWindowSubstring.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/11/21.
- */
-
public class MinimumWindowSubstring {
// 耗时8ms,时间复杂度O(n)
diff --git a/solution/src/main/java/com/inuker/solution/MissingNumber.java b/leetcode/solution/src/MissingNumber.java
similarity index 74%
rename from solution/src/main/java/com/inuker/solution/MissingNumber.java
rename to leetcode/solution/src/MissingNumber.java
index 89c7763..97c42e2 100644
--- a/solution/src/main/java/com/inuker/solution/MissingNumber.java
+++ b/leetcode/solution/src/MissingNumber.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by liwentian on 2017/9/10.
- */
-
public class MissingNumber {
public int missingNumber(int[] nums) {
diff --git a/solution/src/main/java/com/inuker/solution/MissingRanges.java b/leetcode/solution/src/MissingRanges.java
similarity index 91%
rename from solution/src/main/java/com/inuker/solution/MissingRanges.java
rename to leetcode/solution/src/MissingRanges.java
index d27c689..4380310 100644
--- a/solution/src/main/java/com/inuker/solution/MissingRanges.java
+++ b/leetcode/solution/src/MissingRanges.java
@@ -1,12 +1,6 @@
-package com.inuker.solution;
-
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by dingjikerbo on 2016/12/11.
- */
-
/**
* TestCases
* [], lower=1, upper=1
diff --git a/solution/src/main/java/com/inuker/solution/MostFrequentSubtreeSum.java b/leetcode/solution/src/MostFrequentSubtreeSum.java
similarity index 93%
rename from solution/src/main/java/com/inuker/solution/MostFrequentSubtreeSum.java
rename to leetcode/solution/src/MostFrequentSubtreeSum.java
index 43558b0..ab746d4 100644
--- a/solution/src/main/java/com/inuker/solution/MostFrequentSubtreeSum.java
+++ b/leetcode/solution/src/MostFrequentSubtreeSum.java
@@ -1,15 +1,7 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by liwentian on 17/8/3.
- */
-
/**
* 这题算法比较直观
*/
diff --git a/solution/src/main/java/com/inuker/solution/MoveZeroes.java b/leetcode/solution/src/MoveZeroes.java
similarity index 91%
rename from solution/src/main/java/com/inuker/solution/MoveZeroes.java
rename to leetcode/solution/src/MoveZeroes.java
index 038c848..0356ac1 100644
--- a/solution/src/main/java/com/inuker/solution/MoveZeroes.java
+++ b/leetcode/solution/src/MoveZeroes.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/11/19.
- */
-
/**
* https://leetcode.com/articles/move-zeroes/
*/
diff --git a/solution/src/main/java/com/inuker/solution/MovingAverage.java b/leetcode/solution/src/MovingAverage.java
similarity index 83%
rename from solution/src/main/java/com/inuker/solution/MovingAverage.java
rename to leetcode/solution/src/MovingAverage.java
index 4d7eb68..3916cfa 100644
--- a/solution/src/main/java/com/inuker/solution/MovingAverage.java
+++ b/leetcode/solution/src/MovingAverage.java
@@ -1,12 +1,5 @@
-package com.inuker.solution;
-
import java.util.Deque;
import java.util.LinkedList;
-import java.util.List;
-
-/**
- * Created by dingjikerbo on 16/12/4.
- */
public class MovingAverage {
diff --git a/solution/src/main/java/com/inuker/solution/MultiplyStrings.java b/leetcode/solution/src/MultiplyStrings.java
similarity index 91%
rename from solution/src/main/java/com/inuker/solution/MultiplyStrings.java
rename to leetcode/solution/src/MultiplyStrings.java
index e596665..114cc6e 100644
--- a/solution/src/main/java/com/inuker/solution/MultiplyStrings.java
+++ b/leetcode/solution/src/MultiplyStrings.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/11/22.
- */
-
public class MultiplyStrings {
public String multiply(String num1, String num2) {
diff --git a/solution/src/main/java/com/inuker/solution/MyQueue.java b/leetcode/solution/src/MyQueue.java
similarity index 92%
rename from solution/src/main/java/com/inuker/solution/MyQueue.java
rename to leetcode/solution/src/MyQueue.java
index fbe1a71..6341b73 100644
--- a/solution/src/main/java/com/inuker/solution/MyQueue.java
+++ b/leetcode/solution/src/MyQueue.java
@@ -1,11 +1,5 @@
-package com.inuker.solution;
-
import java.util.Stack;
-/**
- * Created by dingjikerbo on 16/12/10.
- */
-
/**
* https://leetcode.com/articles/implement-queue-using-stacks/
*/
diff --git a/solution/src/main/java/com/inuker/solution/MyStack.java b/leetcode/solution/src/MyStack.java
similarity index 95%
rename from solution/src/main/java/com/inuker/solution/MyStack.java
rename to leetcode/solution/src/MyStack.java
index 073f29b..e22ec04 100644
--- a/solution/src/main/java/com/inuker/solution/MyStack.java
+++ b/leetcode/solution/src/MyStack.java
@@ -1,12 +1,6 @@
-package com.inuker.solution;
-
import java.util.LinkedList;
import java.util.Queue;
-/**
- * Created by dingjikerbo on 16/12/10.
- */
-
/**
* https://leetcode.com/articles/implement-stack-using-queues/
*/
diff --git a/solution/src/main/java/com/inuker/solution/NQueens.java b/leetcode/solution/src/NQueens.java
similarity index 96%
rename from solution/src/main/java/com/inuker/solution/NQueens.java
rename to leetcode/solution/src/NQueens.java
index 030b708..43444a2 100644
--- a/solution/src/main/java/com/inuker/solution/NQueens.java
+++ b/leetcode/solution/src/NQueens.java
@@ -1,13 +1,7 @@
-package com.inuker.solution;
-
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by dingjikerbo on 17/1/12.
- */
-
public class NQueens {
public List> solveNQueens(int n) {
diff --git a/solution/src/main/java/com/inuker/solution/NQueensII.java b/leetcode/solution/src/NQueensII.java
similarity index 91%
rename from solution/src/main/java/com/inuker/solution/NQueensII.java
rename to leetcode/solution/src/NQueensII.java
index c2fb4e6..d4ae0d5 100644
--- a/solution/src/main/java/com/inuker/solution/NQueensII.java
+++ b/leetcode/solution/src/NQueensII.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 17/1/12.
- */
-
public class NQueensII {
private int total;
diff --git a/solution/src/main/java/com/inuker/solution/NestedListWeightSum.java b/leetcode/solution/src/NestedListWeightSum.java
similarity index 88%
rename from solution/src/main/java/com/inuker/solution/NestedListWeightSum.java
rename to leetcode/solution/src/NestedListWeightSum.java
index b0b2580..606fa13 100644
--- a/solution/src/main/java/com/inuker/solution/NestedListWeightSum.java
+++ b/leetcode/solution/src/NestedListWeightSum.java
@@ -1,11 +1,5 @@
-package com.inuker.solution;
-
import java.util.List;
-/**
- * Created by dingjikerbo on 2016/12/17.
- */
-
/**
* https://leetcode.com/articles/nested-list-weight-sum/
*/
diff --git a/solution/src/main/java/com/inuker/solution/NestedListWeightSumII.java b/leetcode/solution/src/NestedListWeightSumII.java
similarity index 95%
rename from solution/src/main/java/com/inuker/solution/NestedListWeightSumII.java
rename to leetcode/solution/src/NestedListWeightSumII.java
index a304283..59e2bbf 100644
--- a/solution/src/main/java/com/inuker/solution/NestedListWeightSumII.java
+++ b/leetcode/solution/src/NestedListWeightSumII.java
@@ -1,11 +1,5 @@
-package com.inuker.solution;
-
import java.util.List;
-/**
- * Created by dingjikerbo on 2016/12/17.
- */
-
/**
* https://leetcode.com/articles/nested-list-weight-sum/
*/
diff --git a/solution/src/main/java/com/inuker/solution/NextPermutation.java b/leetcode/solution/src/NextPermutation.java
similarity index 93%
rename from solution/src/main/java/com/inuker/solution/NextPermutation.java
rename to leetcode/solution/src/NextPermutation.java
index a4fce65..4fccdc6 100644
--- a/solution/src/main/java/com/inuker/solution/NextPermutation.java
+++ b/leetcode/solution/src/NextPermutation.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/12/17.
- */
-
/**
* https://leetcode.com/articles/next-permutation/
*/
diff --git a/solution/src/main/java/com/inuker/solution/NumArray.java b/leetcode/solution/src/NumArray.java
similarity index 88%
rename from solution/src/main/java/com/inuker/solution/NumArray.java
rename to leetcode/solution/src/NumArray.java
index 9005296..9659f01 100644
--- a/solution/src/main/java/com/inuker/solution/NumArray.java
+++ b/leetcode/solution/src/NumArray.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/11/26.
- */
-
/**
* https://leetcode.com/articles/range-sum-query-immutable/
*/
diff --git a/solution/src/main/java/com/inuker/solution/NumArrayII.java b/leetcode/solution/src/NumArrayII.java
similarity index 97%
rename from solution/src/main/java/com/inuker/solution/NumArrayII.java
rename to leetcode/solution/src/NumArrayII.java
index 6b8e206..153d026 100644
--- a/solution/src/main/java/com/inuker/solution/NumArrayII.java
+++ b/leetcode/solution/src/NumArrayII.java
@@ -1,8 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/11/26.
- */
/**
* 这题可以用segment tree或binary index tree(bit),两者时间复杂度都是lgn,不过segment tree因为用到树,
* 而bit用的是数组,所以bit更省空间。
diff --git a/solution/src/main/java/com/inuker/solution/NumMatrix.java b/leetcode/solution/src/NumMatrix.java
similarity index 92%
rename from solution/src/main/java/com/inuker/solution/NumMatrix.java
rename to leetcode/solution/src/NumMatrix.java
index 6661c58..f5d5323 100644
--- a/solution/src/main/java/com/inuker/solution/NumMatrix.java
+++ b/leetcode/solution/src/NumMatrix.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/11/26.
- */
-
/**
* https://leetcode.com/articles/range-sum-query-2d-immutable/
*/
diff --git a/solution/src/main/java/com/inuker/solution/NumMatrixII.java b/leetcode/solution/src/NumMatrixII.java
similarity index 97%
rename from solution/src/main/java/com/inuker/solution/NumMatrixII.java
rename to leetcode/solution/src/NumMatrixII.java
index 20de7c5..ce0c8c9 100644
--- a/solution/src/main/java/com/inuker/solution/NumMatrixII.java
+++ b/leetcode/solution/src/NumMatrixII.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/11/27.
- */
-
/**
* 这道题有两种方法
* 1,2D BIT
diff --git a/solution/src/main/java/com/inuker/solution/NumberOfConnectedComponents.java b/leetcode/solution/src/NumberOfConnectedComponents.java
similarity index 95%
rename from solution/src/main/java/com/inuker/solution/NumberOfConnectedComponents.java
rename to leetcode/solution/src/NumberOfConnectedComponents.java
index 9ba9593..07446e3 100644
--- a/solution/src/main/java/com/inuker/solution/NumberOfConnectedComponents.java
+++ b/leetcode/solution/src/NumberOfConnectedComponents.java
@@ -1,14 +1,8 @@
-package com.inuker.solution;
-
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-/**
- * Created by dingjikerbo on 17/1/2.
- */
-
public class NumberOfConnectedComponents {
// 8ms
diff --git a/solution/src/main/java/com/inuker/solution/NumberOfDigitOne.java b/leetcode/solution/src/NumberOfDigitOne.java
similarity index 91%
rename from solution/src/main/java/com/inuker/solution/NumberOfDigitOne.java
rename to leetcode/solution/src/NumberOfDigitOne.java
index dce32db..fe8b2b3 100644
--- a/solution/src/main/java/com/inuker/solution/NumberOfDigitOne.java
+++ b/leetcode/solution/src/NumberOfDigitOne.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/12/21.
- */
-
public class NumberOfDigitOne {
/**
diff --git a/solution/src/main/java/com/inuker/solution/NumberOfIslands.java b/leetcode/solution/src/NumberOfIslands.java
similarity index 95%
rename from solution/src/main/java/com/inuker/solution/NumberOfIslands.java
rename to leetcode/solution/src/NumberOfIslands.java
index 3f1f93d..7e699e8 100644
--- a/solution/src/main/java/com/inuker/solution/NumberOfIslands.java
+++ b/leetcode/solution/src/NumberOfIslands.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/11/16.
- */
-
import java.util.LinkedList;
import java.util.Queue;
diff --git a/solution/src/main/java/com/inuker/solution/NumberOfIslandsII.java b/leetcode/solution/src/NumberOfIslandsII.java
similarity index 94%
rename from solution/src/main/java/com/inuker/solution/NumberOfIslandsII.java
rename to leetcode/solution/src/NumberOfIslandsII.java
index a835dcf..2a4d191 100644
--- a/solution/src/main/java/com/inuker/solution/NumberOfIslandsII.java
+++ b/leetcode/solution/src/NumberOfIslandsII.java
@@ -1,13 +1,7 @@
-package com.inuker.solution;
-
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by dingjikerbo on 2016/12/11.
- */
-
/**
* 经典的UF(Union Find)问题,可翻阅《算法》1.5章
* UF时间复杂度和节点个数有关
diff --git a/solution/src/main/java/com/inuker/solution/OddEvenLinkedList.java b/leetcode/solution/src/OddEvenLinkedList.java
similarity index 83%
rename from solution/src/main/java/com/inuker/solution/OddEvenLinkedList.java
rename to leetcode/solution/src/OddEvenLinkedList.java
index 9e6608f..dbd91a7 100644
--- a/solution/src/main/java/com/inuker/solution/OddEvenLinkedList.java
+++ b/leetcode/solution/src/OddEvenLinkedList.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import com.leetcode.library.ListNode;
-
-/**
- * Created by dingjikerbo on 16/12/7.
- */
-
public class OddEvenLinkedList {
public ListNode oddEvenList(ListNode head) {
diff --git a/solution/src/main/java/com/inuker/solution/OneEditDistance.java b/leetcode/solution/src/OneEditDistance.java
similarity index 90%
rename from solution/src/main/java/com/inuker/solution/OneEditDistance.java
rename to leetcode/solution/src/OneEditDistance.java
index 6063d64..3786f06 100644
--- a/solution/src/main/java/com/inuker/solution/OneEditDistance.java
+++ b/leetcode/solution/src/OneEditDistance.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/11/20.
- */
-
public class OneEditDistance {
/**
* 最容易错的是结尾的条件sL != tL
diff --git a/solution/src/main/java/com/inuker/solution/PaintHouse.java b/leetcode/solution/src/PaintHouse.java
similarity index 85%
rename from solution/src/main/java/com/inuker/solution/PaintHouse.java
rename to leetcode/solution/src/PaintHouse.java
index 3360784..2e4d1b8 100644
--- a/solution/src/main/java/com/inuker/solution/PaintHouse.java
+++ b/leetcode/solution/src/PaintHouse.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/12/18.
- */
-
public class PaintHouse {
public int minCost(int[][] costs) {
diff --git a/solution/src/main/java/com/inuker/solution/PaintHouseII.java b/leetcode/solution/src/PaintHouseII.java
similarity index 93%
rename from solution/src/main/java/com/inuker/solution/PaintHouseII.java
rename to leetcode/solution/src/PaintHouseII.java
index d1bf76a..751d23e 100644
--- a/solution/src/main/java/com/inuker/solution/PaintHouseII.java
+++ b/leetcode/solution/src/PaintHouseII.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/12/18.
- */
-
public class PaintHouseII {
/**
diff --git a/solution/src/main/java/com/inuker/solution/PalindromeLinkedList.java b/leetcode/solution/src/PalindromeLinkedList.java
similarity index 88%
rename from solution/src/main/java/com/inuker/solution/PalindromeLinkedList.java
rename to leetcode/solution/src/PalindromeLinkedList.java
index e8b91e2..d6128d4 100644
--- a/solution/src/main/java/com/inuker/solution/PalindromeLinkedList.java
+++ b/leetcode/solution/src/PalindromeLinkedList.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import com.leetcode.library.ListNode;
-
-/**
- * Created by dingjikerbo on 2016/11/17.
- */
-
public class PalindromeLinkedList {
// 耗时2ms
diff --git a/solution/src/main/java/com/inuker/solution/PalindromeNumber.java b/leetcode/solution/src/PalindromeNumber.java
similarity index 53%
rename from solution/src/main/java/com/inuker/solution/PalindromeNumber.java
rename to leetcode/solution/src/PalindromeNumber.java
index 63e8338..2fd2171 100644
--- a/solution/src/main/java/com/inuker/solution/PalindromeNumber.java
+++ b/leetcode/solution/src/PalindromeNumber.java
@@ -1,11 +1,6 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/12/17.
- */
-
public class PalindromeNumber {
+ // 耗时101ms
public boolean isPalindrome(int x) {
if (x < 0) {
return false;
@@ -22,4 +17,19 @@ public boolean isPalindrome(int x) {
return true;
}
+
+ /**
+ * 直接给数倒过来看是否相等
+ * 耗时103ms
+ */
+ public boolean isPalindrome2(int x) {
+ if (x < 0) {
+ return false;
+ }
+ int n = 0, m = x;
+ for ( ; x > 0; x /= 10) {
+ n = n * 10 + x % 10;
+ }
+ return n == m;
+ }
}
diff --git a/solution/src/main/java/com/inuker/solution/PalindromePairs.java b/leetcode/solution/src/PalindromePairs.java
similarity index 97%
rename from solution/src/main/java/com/inuker/solution/PalindromePairs.java
rename to leetcode/solution/src/PalindromePairs.java
index c46f38c..8f9c3b8 100644
--- a/solution/src/main/java/com/inuker/solution/PalindromePairs.java
+++ b/leetcode/solution/src/PalindromePairs.java
@@ -1,13 +1,7 @@
-package com.inuker.solution;
-
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-/**
- * Created by dingjikerbo on 2016/12/17.
- */
-
public class PalindromePairs {
public List> palindromePairs(String[] words) {
diff --git a/solution/src/main/java/com/inuker/solution/PalindromePartitioning.java b/leetcode/solution/src/PalindromePartitioning.java
similarity index 93%
rename from solution/src/main/java/com/inuker/solution/PalindromePartitioning.java
rename to leetcode/solution/src/PalindromePartitioning.java
index f3013be..3693b58 100644
--- a/solution/src/main/java/com/inuker/solution/PalindromePartitioning.java
+++ b/leetcode/solution/src/PalindromePartitioning.java
@@ -1,13 +1,7 @@
-package com.inuker.solution;
-
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by dingjikerbo on 2016/12/17.
- */
-
public class PalindromePartitioning {
/**
diff --git a/solution/src/main/java/com/inuker/solution/PalindromePartitioningII.java b/leetcode/solution/src/PalindromePartitioningII.java
similarity index 89%
rename from solution/src/main/java/com/inuker/solution/PalindromePartitioningII.java
rename to leetcode/solution/src/PalindromePartitioningII.java
index 5cce6af..3d14b4d 100644
--- a/solution/src/main/java/com/inuker/solution/PalindromePartitioningII.java
+++ b/leetcode/solution/src/PalindromePartitioningII.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/12/17.
- */
-
public class PalindromePartitioningII {
/**
diff --git a/solution/src/main/java/com/inuker/solution/PalindromePermutation.java b/leetcode/solution/src/PalindromePermutation.java
similarity index 84%
rename from solution/src/main/java/com/inuker/solution/PalindromePermutation.java
rename to leetcode/solution/src/PalindromePermutation.java
index 39cf299..0f02c8f 100644
--- a/solution/src/main/java/com/inuker/solution/PalindromePermutation.java
+++ b/leetcode/solution/src/PalindromePermutation.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/12/19.
- */
-
public class PalindromePermutation {
public boolean canPermutePalindrome(String s) {
diff --git a/solution/src/main/java/com/inuker/solution/PalindromePermutationII.java b/leetcode/solution/src/PalindromePermutationII.java
similarity index 94%
rename from solution/src/main/java/com/inuker/solution/PalindromePermutationII.java
rename to leetcode/solution/src/PalindromePermutationII.java
index 2e08cb0..1e92297 100644
--- a/solution/src/main/java/com/inuker/solution/PalindromePermutationII.java
+++ b/leetcode/solution/src/PalindromePermutationII.java
@@ -1,12 +1,6 @@
-package com.inuker.solution;
-
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by dingjikerbo on 2016/12/19.
- */
-
/**
* https://leetcode.com/articles/palindrome-permutation-ii/
*/
diff --git a/solution/src/main/java/com/inuker/solution/PartitionList.java b/leetcode/solution/src/PartitionList.java
similarity index 80%
rename from solution/src/main/java/com/inuker/solution/PartitionList.java
rename to leetcode/solution/src/PartitionList.java
index 68d8200..f03168f 100644
--- a/solution/src/main/java/com/inuker/solution/PartitionList.java
+++ b/leetcode/solution/src/PartitionList.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import com.leetcode.library.ListNode;
-
-/**
- * Created by liwentian on 2017/9/11.
- */
-
public class PartitionList {
ListNode partition(ListNode head, int x) {
diff --git a/solution/src/main/java/com/inuker/solution/PascalTriangleII.java b/leetcode/solution/src/PascalTriangleII.java
similarity index 86%
rename from solution/src/main/java/com/inuker/solution/PascalTriangleII.java
rename to leetcode/solution/src/PascalTriangleII.java
index c448c85..da420e5 100644
--- a/solution/src/main/java/com/inuker/solution/PascalTriangleII.java
+++ b/leetcode/solution/src/PascalTriangleII.java
@@ -1,12 +1,6 @@
-package com.inuker.solution;
-
import java.util.ArrayList;
import java.util.List;
-/**
- * Created by liwentian on 17/8/12.
- */
-
public class PascalTriangleII {
public List getRow(int rowIndex) {
diff --git a/solution/src/main/java/com/inuker/solution/PascalsTriangle.java b/leetcode/solution/src/PascalsTriangle.java
similarity index 87%
rename from solution/src/main/java/com/inuker/solution/PascalsTriangle.java
rename to leetcode/solution/src/PascalsTriangle.java
index 93bdb63..00c940e 100644
--- a/solution/src/main/java/com/inuker/solution/PascalsTriangle.java
+++ b/leetcode/solution/src/PascalsTriangle.java
@@ -1,12 +1,6 @@
-package com.inuker.solution;
-
import java.util.ArrayList;
import java.util.List;
-/**
- * Created by liwentian on 2017/9/10.
- */
-
public class PascalsTriangle {
public List> generate(int numRows) {
diff --git a/solution/src/main/java/com/inuker/solution/PathSum.java b/leetcode/solution/src/PathSum.java
similarity index 74%
rename from solution/src/main/java/com/inuker/solution/PathSum.java
rename to leetcode/solution/src/PathSum.java
index 8a7f0f6..f984901 100644
--- a/solution/src/main/java/com/inuker/solution/PathSum.java
+++ b/leetcode/solution/src/PathSum.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
-/**
- * Created by dingjikerbo on 2016/11/29.
- */
-
public class PathSum {
public boolean hasPathSum(TreeNode root, int sum) {
diff --git a/leetcode/solution/src/PathSumII.java b/leetcode/solution/src/PathSumII.java
new file mode 100644
index 0000000..8601018
--- /dev/null
+++ b/leetcode/solution/src/PathSumII.java
@@ -0,0 +1,30 @@
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+public class PathSumII {
+
+ public List> pathSum(TreeNode root, int sum) {
+ List> result = new LinkedList<>();
+ helper(root, sum, result, new LinkedList<>());
+ return result;
+ }
+
+ private void helper(TreeNode node, int sum, List> result, List list) {
+ if (node == null) {
+ return;
+ }
+
+ list.add(node.val);
+ sum -= node.val;
+
+ if (node.left == null && node.right == null && sum == 0) {
+ result.add(new ArrayList<>(list));
+ } else {
+ helper(node.left, sum, result, list);
+ helper(node.right, sum, result, list);
+ }
+
+ list.remove(list.size() - 1);
+ }
+}
diff --git a/solution/src/main/java/com/inuker/solution/PathSumIII.java b/leetcode/solution/src/PathSumIII.java
similarity index 57%
rename from solution/src/main/java/com/inuker/solution/PathSumIII.java
rename to leetcode/solution/src/PathSumIII.java
index e6f29b8..50c85ef 100644
--- a/solution/src/main/java/com/inuker/solution/PathSumIII.java
+++ b/leetcode/solution/src/PathSumIII.java
@@ -1,13 +1,4 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- * Created by dingjikerbo on 16/12/3.
- */
+import java.util.HashMap;
public class PathSumIII {
@@ -58,35 +49,34 @@ private void helper(TreeNode root, int sum, int[] count) {
helper(root.right, sum - root.val, count);
}
- /* 如果要给路径打出来
- public List pathSum(TreeNode root, int sum) {
- List result = new LinkedList<>();
- pathSum(root, sum, result, "");
- return result;
+ /**
+ * 更优化的写法,时间复杂度O(n)
+ * 和Two Sum较类似,都是算出从root到当前节点的和,target为两段和的差值
+ */
+ public int pathSum2(TreeNode root, int sum) {
+ HashMap map = new HashMap<>();
+ map.put(0, 1);
+
+ int[] count = new int[1];
+ helper(root, sum, 0, map, count);
+ return count[0];
}
- private void pathSum(TreeNode root, int sum, List list, String path) {
- if (root == null) {
+ private void helper(TreeNode node, int target, int sum, HashMap map, int[] count) {
+ if (node == null) {
return;
}
- pathSumWithRoot(root, sum, list, path);
-
- pathSum(root.left, sum, list, "");
- pathSum(root.right, sum, list, "");
- }
-
- private void pathSumWithRoot(TreeNode root, int sum, List list, String path) {
- if (root == null) {
- return;
+ sum += node.val;
+ if (map.containsKey(sum - target)) {
+ count[0] += map.get(sum - target);
}
- String prefix = path.isEmpty() ? "" : path + "->";
+ map.put(sum, map.getOrDefault(sum, 0) + 1);
- if (root.val == sum) {
- list.add(prefix + root.val);
- }
- pathSumWithRoot(root.left, sum - root.val, list, prefix + root.val);
- pathSumWithRoot(root.right, sum - root.val, list, prefix + root.val);
- }*/
+ helper(node.left, target, sum, map, count);
+ helper(node.right, target, sum, map, count);
+
+ map.put(sum, map.getOrDefault(sum, 0) - 1);
+ }
}
diff --git a/solution/src/main/java/com/inuker/solution/PeekingIterator.java b/leetcode/solution/src/PeekingIterator.java
similarity index 92%
rename from solution/src/main/java/com/inuker/solution/PeekingIterator.java
rename to leetcode/solution/src/PeekingIterator.java
index 8da49e1..89dc5d2 100644
--- a/solution/src/main/java/com/inuker/solution/PeekingIterator.java
+++ b/leetcode/solution/src/PeekingIterator.java
@@ -1,11 +1,5 @@
-package com.inuker.solution;
-
import java.util.Iterator;
-/**
- * Created by dingjikerbo on 16/12/10.
- */
-
public class PeekingIterator implements Iterator {
private Iterator mIterator;
diff --git a/solution/src/main/java/com/inuker/solution/PerfectRectangle.java b/leetcode/solution/src/PerfectRectangle.java
similarity index 95%
rename from solution/src/main/java/com/inuker/solution/PerfectRectangle.java
rename to leetcode/solution/src/PerfectRectangle.java
index 2722304..b1d7d04 100644
--- a/solution/src/main/java/com/inuker/solution/PerfectRectangle.java
+++ b/leetcode/solution/src/PerfectRectangle.java
@@ -1,11 +1,5 @@
-package com.inuker.solution;
-
import java.util.HashSet;
-/**
- * Created by dingjikerbo on 17/1/2.
- */
-
/**
* https://discuss.leetcode.com/topic/56052/really-easy-understanding-solution-o-n-java
* http://www.cnblogs.com/grandyang/p/5825619.html
diff --git a/solution/src/main/java/com/inuker/solution/PerfectSquares.java b/leetcode/solution/src/PerfectSquares.java
similarity index 82%
rename from solution/src/main/java/com/inuker/solution/PerfectSquares.java
rename to leetcode/solution/src/PerfectSquares.java
index c707c8a..c980f06 100644
--- a/solution/src/main/java/com/inuker/solution/PerfectSquares.java
+++ b/leetcode/solution/src/PerfectSquares.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/12/10.
- */
-
public class PerfectSquares {
public int numSquares(int n) {
diff --git a/solution/src/main/java/com/inuker/solution/PermutationSequence.java b/leetcode/solution/src/PermutationSequence.java
similarity index 88%
rename from solution/src/main/java/com/inuker/solution/PermutationSequence.java
rename to leetcode/solution/src/PermutationSequence.java
index 3080eee..ad5af92 100644
--- a/solution/src/main/java/com/inuker/solution/PermutationSequence.java
+++ b/leetcode/solution/src/PermutationSequence.java
@@ -1,12 +1,6 @@
-package com.inuker.solution;
-
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by dingjikerbo on 2016/12/17.
- */
-
public class PermutationSequence {
public String getPermutation(int n, int k) {
diff --git a/solution/src/main/java/com/inuker/solution/Permutations.java b/leetcode/solution/src/Permutations.java
similarity index 91%
rename from solution/src/main/java/com/inuker/solution/Permutations.java
rename to leetcode/solution/src/Permutations.java
index 22fd2ac..35aaf3d 100644
--- a/solution/src/main/java/com/inuker/solution/Permutations.java
+++ b/leetcode/solution/src/Permutations.java
@@ -1,12 +1,6 @@
-package com.inuker.solution;
-
import java.util.ArrayList;
import java.util.List;
-/**
- * Created by dingjikerbo on 2016/12/17.
- */
-
public class Permutations {
public List> permute(int[] nums) {
diff --git a/solution/src/main/java/com/inuker/solution/PermutationsII.java b/leetcode/solution/src/PermutationsII.java
similarity index 91%
rename from solution/src/main/java/com/inuker/solution/PermutationsII.java
rename to leetcode/solution/src/PermutationsII.java
index bbd7bd0..854645f 100644
--- a/solution/src/main/java/com/inuker/solution/PermutationsII.java
+++ b/leetcode/solution/src/PermutationsII.java
@@ -1,11 +1,4 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/12/17.
- */
-
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
diff --git a/solution/src/main/java/com/inuker/solution/PlusOne.java b/leetcode/solution/src/PlusOne.java
similarity index 82%
rename from solution/src/main/java/com/inuker/solution/PlusOne.java
rename to leetcode/solution/src/PlusOne.java
index d2bf40a..c632da3 100644
--- a/solution/src/main/java/com/inuker/solution/PlusOne.java
+++ b/leetcode/solution/src/PlusOne.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by liwentian on 2017/8/30.
- */
-
public class PlusOne {
public int[] plusOne(int[] digits) {
diff --git a/solution/src/main/java/com/inuker/solution/PlusOneLinkedList.java b/leetcode/solution/src/PlusOneLinkedList.java
similarity index 85%
rename from solution/src/main/java/com/inuker/solution/PlusOneLinkedList.java
rename to leetcode/solution/src/PlusOneLinkedList.java
index ada866a..766b196 100644
--- a/solution/src/main/java/com/inuker/solution/PlusOneLinkedList.java
+++ b/leetcode/solution/src/PlusOneLinkedList.java
@@ -1,13 +1,5 @@
-package com.inuker.solution;
-
-import com.leetcode.library.ListNode;
-
import java.util.Stack;
-/**
- * Created by liwentian on 2017/9/10.
- */
-
public class PlusOneLinkedList {
public ListNode plusOne(ListNode head) {
diff --git a/solution/src/main/java/com/inuker/solution/PopulatingNextRightPointersInEachNode.java b/leetcode/solution/src/PopulatingNextRightPointersInEachNode.java
similarity index 91%
rename from solution/src/main/java/com/inuker/solution/PopulatingNextRightPointersInEachNode.java
rename to leetcode/solution/src/PopulatingNextRightPointersInEachNode.java
index d619254..9e8c5bf 100644
--- a/solution/src/main/java/com/inuker/solution/PopulatingNextRightPointersInEachNode.java
+++ b/leetcode/solution/src/PopulatingNextRightPointersInEachNode.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeLinkNode;
-
-/**
- * Created by dingjikerbo on 16/11/23.
- */
-
public class PopulatingNextRightPointersInEachNode {
/** 递归法,巧妙地运用dummy使代码很简洁
diff --git a/solution/src/main/java/com/inuker/solution/PopulatingNextRightPointersInEachNodeII.java b/leetcode/solution/src/PopulatingNextRightPointersInEachNodeII.java
similarity index 91%
rename from solution/src/main/java/com/inuker/solution/PopulatingNextRightPointersInEachNodeII.java
rename to leetcode/solution/src/PopulatingNextRightPointersInEachNodeII.java
index a6be3eb..cb5747e 100644
--- a/solution/src/main/java/com/inuker/solution/PopulatingNextRightPointersInEachNodeII.java
+++ b/leetcode/solution/src/PopulatingNextRightPointersInEachNodeII.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeLinkNode;
-
-/**
- * Created by dingjikerbo on 16/11/23.
- */
-
public class PopulatingNextRightPointersInEachNodeII {
/**
diff --git a/solution/src/main/java/com/inuker/solution/Pow.java b/leetcode/solution/src/Pow.java
similarity index 88%
rename from solution/src/main/java/com/inuker/solution/Pow.java
rename to leetcode/solution/src/Pow.java
index a5f1e71..c6175ed 100644
--- a/solution/src/main/java/com/inuker/solution/Pow.java
+++ b/leetcode/solution/src/Pow.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/11/23.
- */
-
public class Pow {
/**
diff --git a/leetcode/solution/src/ProductOfArrayExceptSelf.java b/leetcode/solution/src/ProductOfArrayExceptSelf.java
new file mode 100644
index 0000000..ca37575
--- /dev/null
+++ b/leetcode/solution/src/ProductOfArrayExceptSelf.java
@@ -0,0 +1,20 @@
+public class ProductOfArrayExceptSelf {
+
+ // 耗时1ms
+ /**
+ * 对于每个数,就是给其左边所有数乘一遍,再给其右边所有数乘一遍
+ */
+ public int[] productExceptSelf(int[] nums) {
+ int[] res = new int[nums.length];
+ int left = 1, right = 1;
+ for (int i = 0; i < nums.length; i++) {
+ res[i] = left;
+ left *= nums[i];
+ }
+ for (int i = nums.length - 1; i >= 0; i--) {
+ res[i] *= right;
+ right *= nums[i];
+ }
+ return res;
+ }
+}
diff --git a/solution/src/main/java/com/inuker/solution/QueueReconstructionByHeight.java b/leetcode/solution/src/QueueReconstructionByHeight.java
similarity index 96%
rename from solution/src/main/java/com/inuker/solution/QueueReconstructionByHeight.java
rename to leetcode/solution/src/QueueReconstructionByHeight.java
index 17bd267..539f846 100644
--- a/solution/src/main/java/com/inuker/solution/QueueReconstructionByHeight.java
+++ b/leetcode/solution/src/QueueReconstructionByHeight.java
@@ -1,12 +1,9 @@
-package com.inuker.solution;
-
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
/**
- * Created by liwentian on 2017/9/1.
*
* 这题核心思路是:
* 1,先取出高度最高的那一组,如果有若干个高度相同的,则按k升序排列,这就是他们之后的相对顺序了。
diff --git a/solution/src/main/java/com/inuker/solution/RandomPickIndex.java b/leetcode/solution/src/RandomPickIndex.java
similarity index 96%
rename from solution/src/main/java/com/inuker/solution/RandomPickIndex.java
rename to leetcode/solution/src/RandomPickIndex.java
index 61abcec..390e589 100644
--- a/solution/src/main/java/com/inuker/solution/RandomPickIndex.java
+++ b/leetcode/solution/src/RandomPickIndex.java
@@ -1,11 +1,5 @@
-package com.inuker.solution;
-
import java.util.Random;
-/**
- * Created by dingjikerbo on 16/11/22.
- */
-
/**
* 注意这里一定要给整个数组遍历完,这样才能保证所有数字的概率是一样的,否则只能保证
* 当前遍历过的数都是等概率的。
diff --git a/solution/src/main/java/com/inuker/solution/RangeAddition.java b/leetcode/solution/src/RangeAddition.java
similarity index 88%
rename from solution/src/main/java/com/inuker/solution/RangeAddition.java
rename to leetcode/solution/src/RangeAddition.java
index c6ba1c0..5d0a220 100644
--- a/solution/src/main/java/com/inuker/solution/RangeAddition.java
+++ b/leetcode/solution/src/RangeAddition.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by liwentian on 2017/9/10.
- */
-
/**
* https://leetcode.com/articles/range-addition/
*/
diff --git a/solution/src/main/java/com/inuker/solution/ReadNCharactersGivenRead4.java b/leetcode/solution/src/ReadNCharactersGivenRead4.java
similarity index 85%
rename from solution/src/main/java/com/inuker/solution/ReadNCharactersGivenRead4.java
rename to leetcode/solution/src/ReadNCharactersGivenRead4.java
index 2447bb8..9f916e2 100644
--- a/solution/src/main/java/com/inuker/solution/ReadNCharactersGivenRead4.java
+++ b/leetcode/solution/src/ReadNCharactersGivenRead4.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/11/20.
- */
-
public abstract class ReadNCharactersGivenRead4 {
public int read(char[] buf, int n) {
diff --git a/solution/src/main/java/com/inuker/solution/ReadNCharactersGivenRead4II.java b/leetcode/solution/src/ReadNCharactersGivenRead4II.java
similarity index 87%
rename from solution/src/main/java/com/inuker/solution/ReadNCharactersGivenRead4II.java
rename to leetcode/solution/src/ReadNCharactersGivenRead4II.java
index afd8a1d..c49256f 100644
--- a/solution/src/main/java/com/inuker/solution/ReadNCharactersGivenRead4II.java
+++ b/leetcode/solution/src/ReadNCharactersGivenRead4II.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/11/20.
- */
-
public abstract class ReadNCharactersGivenRead4II {
private char[] mTmp = new char[4];
diff --git a/solution/src/main/java/com/inuker/solution/RearrangeStringKDistanceApart.java b/leetcode/solution/src/RearrangeStringKDistanceApart.java
similarity index 96%
rename from solution/src/main/java/com/inuker/solution/RearrangeStringKDistanceApart.java
rename to leetcode/solution/src/RearrangeStringKDistanceApart.java
index 3e0d464..2ab20c4 100644
--- a/solution/src/main/java/com/inuker/solution/RearrangeStringKDistanceApart.java
+++ b/leetcode/solution/src/RearrangeStringKDistanceApart.java
@@ -1,14 +1,8 @@
-package com.inuker.solution;
-
import java.util.Comparator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
-/**
- * Created by dingjikerbo on 17/1/6.
- */
-
public class RearrangeStringKDistanceApart {
/**
* 这题思路是先统计有哪些字符,并将这些字符按频率从高到底放在优先队列中,由于相同字符之间距离至少是k,
diff --git a/solution/src/main/java/com/inuker/solution/ReconstructItinerary.java b/leetcode/solution/src/ReconstructItinerary.java
similarity index 92%
rename from solution/src/main/java/com/inuker/solution/ReconstructItinerary.java
rename to leetcode/solution/src/ReconstructItinerary.java
index 745c17b..43f80f1 100644
--- a/solution/src/main/java/com/inuker/solution/ReconstructItinerary.java
+++ b/leetcode/solution/src/ReconstructItinerary.java
@@ -1,18 +1,5 @@
-package com.inuker.solution;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.PriorityQueue;
-import java.util.Stack;
+import java.util.*;
-/**
- * Created by liwentian on 2017/9/2.
- */
/**
* 这题有两个前提
* 1, 必须从JFK开始
diff --git a/solution/src/main/java/com/inuker/solution/RecoverBinarySearchTree.java b/leetcode/solution/src/RecoverBinarySearchTree.java
similarity index 93%
rename from solution/src/main/java/com/inuker/solution/RecoverBinarySearchTree.java
rename to leetcode/solution/src/RecoverBinarySearchTree.java
index 982106f..3f3e335 100644
--- a/solution/src/main/java/com/inuker/solution/RecoverBinarySearchTree.java
+++ b/leetcode/solution/src/RecoverBinarySearchTree.java
@@ -1,13 +1,5 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
import java.util.Stack;
-/**
- * Created by dingjikerbo on 16/11/30.
- */
-
public class RecoverBinarySearchTree {
TreeNode first, second, prev;
diff --git a/solution/src/main/java/com/inuker/solution/RectangleArea.java b/leetcode/solution/src/RectangleArea.java
similarity index 84%
rename from solution/src/main/java/com/inuker/solution/RectangleArea.java
rename to leetcode/solution/src/RectangleArea.java
index 6a36bfc..93deb8b 100644
--- a/solution/src/main/java/com/inuker/solution/RectangleArea.java
+++ b/leetcode/solution/src/RectangleArea.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/12/8.
- */
-
public class RectangleArea {
public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
diff --git a/solution/src/main/java/com/inuker/solution/RedundantConnection.java b/leetcode/solution/src/RedundantConnection.java
similarity index 91%
rename from solution/src/main/java/com/inuker/solution/RedundantConnection.java
rename to leetcode/solution/src/RedundantConnection.java
index 27799cf..01ee412 100644
--- a/solution/src/main/java/com/inuker/solution/RedundantConnection.java
+++ b/leetcode/solution/src/RedundantConnection.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by liwentian on 2017/12/7.
- */
-
/**
* https://leetcode.com/articles/redundant-connection/
*/
diff --git a/solution/src/main/java/com/inuker/solution/RegularExpressionMatching.java b/leetcode/solution/src/RegularExpressionMatching.java
similarity index 93%
rename from solution/src/main/java/com/inuker/solution/RegularExpressionMatching.java
rename to leetcode/solution/src/RegularExpressionMatching.java
index a7300e7..cbdac88 100644
--- a/solution/src/main/java/com/inuker/solution/RegularExpressionMatching.java
+++ b/leetcode/solution/src/RegularExpressionMatching.java
@@ -1,8 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/11/20.
- */
/**
* 这道题最重要的是no bug,而不是性能
* 要给所有cases cover到
diff --git a/solution/src/main/java/com/inuker/solution/RemoveDuplicateLetters.java b/leetcode/solution/src/RemoveDuplicateLetters.java
similarity index 94%
rename from solution/src/main/java/com/inuker/solution/RemoveDuplicateLetters.java
rename to leetcode/solution/src/RemoveDuplicateLetters.java
index 61819b8..831e6a9 100644
--- a/solution/src/main/java/com/inuker/solution/RemoveDuplicateLetters.java
+++ b/leetcode/solution/src/RemoveDuplicateLetters.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 17/1/2.
- */
-
public class RemoveDuplicateLetters {
diff --git a/solution/src/main/java/com/inuker/solution/RemoveDuplicatesFromSortedArray.java b/leetcode/solution/src/RemoveDuplicatesFromSortedArray.java
similarity index 82%
rename from solution/src/main/java/com/inuker/solution/RemoveDuplicatesFromSortedArray.java
rename to leetcode/solution/src/RemoveDuplicatesFromSortedArray.java
index 003af37..fa93580 100644
--- a/solution/src/main/java/com/inuker/solution/RemoveDuplicatesFromSortedArray.java
+++ b/leetcode/solution/src/RemoveDuplicatesFromSortedArray.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/11/24.
- */
-
/**
* https://leetcode.com/articles/remove-duplicates-sorted-array/
*/
diff --git a/solution/src/main/java/com/inuker/solution/RemoveDuplicatesFromSortedArrayII.java b/leetcode/solution/src/RemoveDuplicatesFromSortedArrayII.java
similarity index 79%
rename from solution/src/main/java/com/inuker/solution/RemoveDuplicatesFromSortedArrayII.java
rename to leetcode/solution/src/RemoveDuplicatesFromSortedArrayII.java
index 327dc10..11230f5 100644
--- a/solution/src/main/java/com/inuker/solution/RemoveDuplicatesFromSortedArrayII.java
+++ b/leetcode/solution/src/RemoveDuplicatesFromSortedArrayII.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/11/24.
- */
-
public class RemoveDuplicatesFromSortedArrayII {
public int removeDuplicates(int[] nums) {
diff --git a/solution/src/main/java/com/inuker/solution/RemoveDuplicatesFromSortedList.java b/leetcode/solution/src/RemoveDuplicatesFromSortedList.java
similarity index 80%
rename from solution/src/main/java/com/inuker/solution/RemoveDuplicatesFromSortedList.java
rename to leetcode/solution/src/RemoveDuplicatesFromSortedList.java
index 2dda9c5..0814495 100644
--- a/solution/src/main/java/com/inuker/solution/RemoveDuplicatesFromSortedList.java
+++ b/leetcode/solution/src/RemoveDuplicatesFromSortedList.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/11/24.
- */
-
-import com.leetcode.library.ListNode;
-
/**
* https://leetcode.com/articles/remove-duplicates-sorted-list/
*/
diff --git a/solution/src/main/java/com/inuker/solution/RemoveDuplicatesFromSortedListII.java b/leetcode/solution/src/RemoveDuplicatesFromSortedListII.java
similarity index 84%
rename from solution/src/main/java/com/inuker/solution/RemoveDuplicatesFromSortedListII.java
rename to leetcode/solution/src/RemoveDuplicatesFromSortedListII.java
index 9f7e0ff..1cea4bc 100644
--- a/solution/src/main/java/com/inuker/solution/RemoveDuplicatesFromSortedListII.java
+++ b/leetcode/solution/src/RemoveDuplicatesFromSortedListII.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import com.leetcode.library.ListNode;
-
-/**
- * Created by dingjikerbo on 16/11/24.
- */
-
public class RemoveDuplicatesFromSortedListII {
public ListNode deleteDuplicates(ListNode head) {
diff --git a/solution/src/main/java/com/inuker/solution/RemoveElement.java b/leetcode/solution/src/RemoveElement.java
similarity index 78%
rename from solution/src/main/java/com/inuker/solution/RemoveElement.java
rename to leetcode/solution/src/RemoveElement.java
index f96b265..8e8fcef 100644
--- a/solution/src/main/java/com/inuker/solution/RemoveElement.java
+++ b/leetcode/solution/src/RemoveElement.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/12/20.
- */
-
public class RemoveElement {
public int removeElement(int[] nums, int val) {
diff --git a/solution/src/main/java/com/inuker/solution/RemoveInvalidParentheses.java b/leetcode/solution/src/RemoveInvalidParentheses.java
similarity index 98%
rename from solution/src/main/java/com/inuker/solution/RemoveInvalidParentheses.java
rename to leetcode/solution/src/RemoveInvalidParentheses.java
index ab2703f..3bc3c0e 100644
--- a/solution/src/main/java/com/inuker/solution/RemoveInvalidParentheses.java
+++ b/leetcode/solution/src/RemoveInvalidParentheses.java
@@ -1,14 +1,8 @@
-package com.inuker.solution;
-
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
-/**
- * Created by dingjikerbo on 2016/11/19.
- */
-
/**
* TestCase
* ""
diff --git a/solution/src/main/java/com/inuker/solution/RemoveKDigits.java b/leetcode/solution/src/RemoveKDigits.java
similarity index 93%
rename from solution/src/main/java/com/inuker/solution/RemoveKDigits.java
rename to leetcode/solution/src/RemoveKDigits.java
index a15ab70..9394e25 100644
--- a/solution/src/main/java/com/inuker/solution/RemoveKDigits.java
+++ b/leetcode/solution/src/RemoveKDigits.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/12/20.
- */
-
/**
* TestCase:
* "10", 2
diff --git a/solution/src/main/java/com/inuker/solution/RemoveLinkedListElements.java b/leetcode/solution/src/RemoveLinkedListElements.java
similarity index 76%
rename from solution/src/main/java/com/inuker/solution/RemoveLinkedListElements.java
rename to leetcode/solution/src/RemoveLinkedListElements.java
index 7faf5d0..cb724ff 100644
--- a/solution/src/main/java/com/inuker/solution/RemoveLinkedListElements.java
+++ b/leetcode/solution/src/RemoveLinkedListElements.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import com.leetcode.library.ListNode;
-
-/**
- * Created by dingjikerbo on 2016/12/20.
- */
-
public class RemoveLinkedListElements {
public ListNode removeElements(ListNode head, int val) {
diff --git a/solution/src/main/java/com/inuker/solution/RemoveNthNodeFromEndOfList.java b/leetcode/solution/src/RemoveNthNodeFromEndOfList.java
similarity index 83%
rename from solution/src/main/java/com/inuker/solution/RemoveNthNodeFromEndOfList.java
rename to leetcode/solution/src/RemoveNthNodeFromEndOfList.java
index 78e2133..ea2dd02 100644
--- a/solution/src/main/java/com/inuker/solution/RemoveNthNodeFromEndOfList.java
+++ b/leetcode/solution/src/RemoveNthNodeFromEndOfList.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/12/20.
- */
-
-import com.leetcode.library.ListNode;
-
/**
* https://leetcode.com/articles/remove-nth-node-end-list/
*/
diff --git a/solution/src/main/java/com/inuker/solution/ReorderList.java b/leetcode/solution/src/ReorderList.java
similarity index 88%
rename from solution/src/main/java/com/inuker/solution/ReorderList.java
rename to leetcode/solution/src/ReorderList.java
index 2c81b8e..ed4940e 100644
--- a/solution/src/main/java/com/inuker/solution/ReorderList.java
+++ b/leetcode/solution/src/ReorderList.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import com.leetcode.library.ListNode;
-
-/**
- * Created by liwentian on 2017/9/11.
- */
-
public class ReorderList {
public void reorderList(ListNode head) {
diff --git a/solution/src/main/java/com/inuker/solution/RepeatedSubstringPattern.java b/leetcode/solution/src/RepeatedSubstringPattern.java
similarity index 89%
rename from solution/src/main/java/com/inuker/solution/RepeatedSubstringPattern.java
rename to leetcode/solution/src/RepeatedSubstringPattern.java
index 588309a..aae18c5 100644
--- a/solution/src/main/java/com/inuker/solution/RepeatedSubstringPattern.java
+++ b/leetcode/solution/src/RepeatedSubstringPattern.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by liwentian on 2017/12/9.
- */
-
public class RepeatedSubstringPattern {
/**
diff --git a/solution/src/main/java/com/inuker/solution/RestoreIPAddresses.java b/leetcode/solution/src/RestoreIPAddresses.java
similarity index 93%
rename from solution/src/main/java/com/inuker/solution/RestoreIPAddresses.java
rename to leetcode/solution/src/RestoreIPAddresses.java
index ef854b9..5cce134 100644
--- a/solution/src/main/java/com/inuker/solution/RestoreIPAddresses.java
+++ b/leetcode/solution/src/RestoreIPAddresses.java
@@ -1,12 +1,6 @@
-package com.inuker.solution;
-
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by liwentian on 2017/9/6.
- */
-
public class RestoreIPAddresses {
/**
diff --git a/solution/src/main/java/com/inuker/solution/ReverseBits.java b/leetcode/solution/src/ReverseBits.java
similarity index 87%
rename from solution/src/main/java/com/inuker/solution/ReverseBits.java
rename to leetcode/solution/src/ReverseBits.java
index 8927358..5285fbc 100644
--- a/solution/src/main/java/com/inuker/solution/ReverseBits.java
+++ b/leetcode/solution/src/ReverseBits.java
@@ -1,8 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/12/10.
- */
public class ReverseBits {
diff --git a/solution/src/main/java/com/inuker/solution/ReverseInteger.java b/leetcode/solution/src/ReverseInteger.java
similarity index 83%
rename from solution/src/main/java/com/inuker/solution/ReverseInteger.java
rename to leetcode/solution/src/ReverseInteger.java
index f24da04..3c6b2f9 100644
--- a/solution/src/main/java/com/inuker/solution/ReverseInteger.java
+++ b/leetcode/solution/src/ReverseInteger.java
@@ -1,8 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/12/10.
- */
public class ReverseInteger {
diff --git a/solution/src/main/java/com/inuker/solution/ReverseLinkedList.java b/leetcode/solution/src/ReverseLinkedList.java
similarity index 85%
rename from solution/src/main/java/com/inuker/solution/ReverseLinkedList.java
rename to leetcode/solution/src/ReverseLinkedList.java
index eb625cb..e858f36 100644
--- a/solution/src/main/java/com/inuker/solution/ReverseLinkedList.java
+++ b/leetcode/solution/src/ReverseLinkedList.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/11/16.
- */
-
-import com.leetcode.library.ListNode;
-
/**
* https://leetcode.com/articles/reverse-linked-list/
*/
diff --git a/solution/src/main/java/com/inuker/solution/ReverseLinkedListII.java b/leetcode/solution/src/ReverseLinkedListII.java
similarity index 83%
rename from solution/src/main/java/com/inuker/solution/ReverseLinkedListII.java
rename to leetcode/solution/src/ReverseLinkedListII.java
index 96e45dc..fa6e474 100644
--- a/solution/src/main/java/com/inuker/solution/ReverseLinkedListII.java
+++ b/leetcode/solution/src/ReverseLinkedListII.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import com.leetcode.library.ListNode;
-
-/**
- * Created by liwentian on 2017/9/11.
- */
-
public class ReverseLinkedListII {
public ListNode reverseBetween(ListNode head, int m, int n) {
diff --git a/solution/src/main/java/com/inuker/solution/ReverseNodesInKGroup.java b/leetcode/solution/src/ReverseNodesInKGroup.java
similarity index 83%
rename from solution/src/main/java/com/inuker/solution/ReverseNodesInKGroup.java
rename to leetcode/solution/src/ReverseNodesInKGroup.java
index bf713a9..0f6903a 100644
--- a/solution/src/main/java/com/inuker/solution/ReverseNodesInKGroup.java
+++ b/leetcode/solution/src/ReverseNodesInKGroup.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import com.leetcode.library.ListNode;
-
-/**
- * Created by dingjikerbo on 2016/11/24.
- */
-
public class ReverseNodesInKGroup {
public ListNode reverseKGroup(ListNode head, int k) {
diff --git a/solution/src/main/java/com/inuker/solution/ReverseString.java b/leetcode/solution/src/ReverseString.java
similarity index 64%
rename from solution/src/main/java/com/inuker/solution/ReverseString.java
rename to leetcode/solution/src/ReverseString.java
index 8d2480a..86bb628 100644
--- a/solution/src/main/java/com/inuker/solution/ReverseString.java
+++ b/leetcode/solution/src/ReverseString.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by liwentian on 2017/9/10.
- */
-
public class ReverseString {
public String reverseString(String s) {
diff --git a/solution/src/main/java/com/inuker/solution/ReverseStringII.java b/leetcode/solution/src/ReverseStringII.java
similarity index 83%
rename from solution/src/main/java/com/inuker/solution/ReverseStringII.java
rename to leetcode/solution/src/ReverseStringII.java
index 68f8c25..3c0142c 100644
--- a/solution/src/main/java/com/inuker/solution/ReverseStringII.java
+++ b/leetcode/solution/src/ReverseStringII.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by liwentian on 2017/9/10.
- */
-
public class ReverseStringII {
public String reverseStr(String s, int k) {
diff --git a/solution/src/main/java/com/inuker/solution/ReverseVowelsOfaString.java b/leetcode/solution/src/ReverseVowelsOfaString.java
similarity index 90%
rename from solution/src/main/java/com/inuker/solution/ReverseVowelsOfaString.java
rename to leetcode/solution/src/ReverseVowelsOfaString.java
index 89f5b71..3ea675c 100644
--- a/solution/src/main/java/com/inuker/solution/ReverseVowelsOfaString.java
+++ b/leetcode/solution/src/ReverseVowelsOfaString.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by liwentian on 2017/8/31.
- */
-
public class ReverseVowelsOfaString {
diff --git a/solution/src/main/java/com/inuker/solution/ReverseWordsInAString.java b/leetcode/solution/src/ReverseWordsInAString.java
similarity index 94%
rename from solution/src/main/java/com/inuker/solution/ReverseWordsInAString.java
rename to leetcode/solution/src/ReverseWordsInAString.java
index 3dc4420..d88788d 100644
--- a/solution/src/main/java/com/inuker/solution/ReverseWordsInAString.java
+++ b/leetcode/solution/src/ReverseWordsInAString.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by liwentian on 17/8/14.
- */
-
public class ReverseWordsInAString {
diff --git a/solution/src/main/java/com/inuker/solution/ReverseWordsInAStringII.java b/leetcode/solution/src/ReverseWordsInAStringII.java
similarity index 88%
rename from solution/src/main/java/com/inuker/solution/ReverseWordsInAStringII.java
rename to leetcode/solution/src/ReverseWordsInAStringII.java
index 432ef7a..fb079d4 100644
--- a/solution/src/main/java/com/inuker/solution/ReverseWordsInAStringII.java
+++ b/leetcode/solution/src/ReverseWordsInAStringII.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by liwentian on 17/8/12.
- */
-
public class ReverseWordsInAStringII {
public void reverseWords(char[] s) {
diff --git a/solution/src/main/java/com/inuker/solution/ReverseWordsInAStringIII.java b/leetcode/solution/src/ReverseWordsInAStringIII.java
similarity index 85%
rename from solution/src/main/java/com/inuker/solution/ReverseWordsInAStringIII.java
rename to leetcode/solution/src/ReverseWordsInAStringIII.java
index 7f864cc..5787f79 100644
--- a/solution/src/main/java/com/inuker/solution/ReverseWordsInAStringIII.java
+++ b/leetcode/solution/src/ReverseWordsInAStringIII.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by liwentian on 2017/9/10.
- */
-
/**
* https://leetcode.com/articles/reverse-words-in-a-string/
*/
diff --git a/solution/src/main/java/com/inuker/solution/RomanToInteger.java b/leetcode/solution/src/RomanToInteger.java
similarity index 88%
rename from solution/src/main/java/com/inuker/solution/RomanToInteger.java
rename to leetcode/solution/src/RomanToInteger.java
index 1ce840b..96da591 100644
--- a/solution/src/main/java/com/inuker/solution/RomanToInteger.java
+++ b/leetcode/solution/src/RomanToInteger.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/12/17.
- */
-
public class RomanToInteger {
public int romanToInt(String s) {
diff --git a/solution/src/main/java/com/inuker/solution/RotateArray.java b/leetcode/solution/src/RotateArray.java
similarity index 86%
rename from solution/src/main/java/com/inuker/solution/RotateArray.java
rename to leetcode/solution/src/RotateArray.java
index f712b8b..b0deb0a 100644
--- a/solution/src/main/java/com/inuker/solution/RotateArray.java
+++ b/leetcode/solution/src/RotateArray.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by liwentian on 2017/9/10.
- */
-
public class RotateArray {
public void rotate(int[] nums, int k) {
diff --git a/amazon/src/main/java/com/leetcode/amazon/RotateImage.java b/leetcode/solution/src/RotateImage.java
similarity index 88%
rename from amazon/src/main/java/com/leetcode/amazon/RotateImage.java
rename to leetcode/solution/src/RotateImage.java
index b24b160..8ce4a29 100644
--- a/amazon/src/main/java/com/leetcode/amazon/RotateImage.java
+++ b/leetcode/solution/src/RotateImage.java
@@ -1,11 +1,6 @@
-package com.leetcode.amazon;
-
-/**
- * Created by liwentian on 17/8/9.
- */
-
public class RotateImage {
+ // 耗时2ms
public void rotate(int[][] matrix) {
int n = matrix.length;
diff --git a/solution/src/main/java/com/inuker/solution/RotateList.java b/leetcode/solution/src/RotateList.java
similarity index 84%
rename from solution/src/main/java/com/inuker/solution/RotateList.java
rename to leetcode/solution/src/RotateList.java
index efbbc71..4200872 100644
--- a/solution/src/main/java/com/inuker/solution/RotateList.java
+++ b/leetcode/solution/src/RotateList.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import com.leetcode.library.ListNode;
-
-/**
- * Created by liwentian on 2017/9/11.
- */
-
public class RotateList {
public ListNode rotateRight(ListNode head, int n) {
diff --git a/solution/src/main/java/com/inuker/solution/SameTree.java b/leetcode/solution/src/SameTree.java
similarity index 73%
rename from solution/src/main/java/com/inuker/solution/SameTree.java
rename to leetcode/solution/src/SameTree.java
index 8292901..503fa6e 100644
--- a/solution/src/main/java/com/inuker/solution/SameTree.java
+++ b/leetcode/solution/src/SameTree.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import com.leetcode.library.TreeNode;
-
-/**
- * Created by dingjikerbo on 16/11/28.
- */
-
public class SameTree {
public boolean isSameTree(TreeNode p, TreeNode q) {
diff --git a/solution/src/main/java/com/inuker/solution/Search2DMatrix.java b/leetcode/solution/src/Search2DMatrix.java
similarity index 86%
rename from solution/src/main/java/com/inuker/solution/Search2DMatrix.java
rename to leetcode/solution/src/Search2DMatrix.java
index 017cbe0..0f424b4 100644
--- a/solution/src/main/java/com/inuker/solution/Search2DMatrix.java
+++ b/leetcode/solution/src/Search2DMatrix.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import java.util.Arrays;
-
-/**
- * Created by dingjikerbo on 2016/11/16.
- */
-
public class Search2DMatrix {
// 耗时11ms
diff --git a/solution/src/main/java/com/inuker/solution/Search2DMatrixII.java b/leetcode/solution/src/Search2DMatrixII.java
similarity index 87%
rename from solution/src/main/java/com/inuker/solution/Search2DMatrixII.java
rename to leetcode/solution/src/Search2DMatrixII.java
index 5757c86..b8e3be7 100644
--- a/solution/src/main/java/com/inuker/solution/Search2DMatrixII.java
+++ b/leetcode/solution/src/Search2DMatrixII.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/11/16.
- */
-
public class Search2DMatrixII {
// 耗时14ms
diff --git a/solution/src/main/java/com/inuker/solution/SearchForARange.java b/leetcode/solution/src/SearchForARange.java
similarity index 96%
rename from solution/src/main/java/com/inuker/solution/SearchForARange.java
rename to leetcode/solution/src/SearchForARange.java
index c7114b7..d5a117e 100644
--- a/solution/src/main/java/com/inuker/solution/SearchForARange.java
+++ b/leetcode/solution/src/SearchForARange.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/12/17.
- */
-
public class SearchForARange {
/**
diff --git a/solution/src/main/java/com/inuker/solution/SearchInRotatedSortedArray.java b/leetcode/solution/src/SearchInRotatedSortedArray.java
similarity index 84%
rename from solution/src/main/java/com/inuker/solution/SearchInRotatedSortedArray.java
rename to leetcode/solution/src/SearchInRotatedSortedArray.java
index aadbc9c..75b7472 100644
--- a/solution/src/main/java/com/inuker/solution/SearchInRotatedSortedArray.java
+++ b/leetcode/solution/src/SearchInRotatedSortedArray.java
@@ -1,15 +1,9 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/11/23.
- */
-
public class SearchInRotatedSortedArray {
+
/**
- * TestCase
- * [1, 2], 1/2/3
- * [2, 1], 2/1/3
- * [1], 1/2
+ * 给各种情况考虑到位
+ * 关键是判断范围时要先固定单调区间
+ * 注意Case[3,1],1
*/
public int search(int[] nums, int target) {
int left = 0, right = nums.length - 1;
diff --git a/solution/src/main/java/com/inuker/solution/SearchInRotatedSortedArrayII.java b/leetcode/solution/src/SearchInRotatedSortedArrayII.java
similarity index 94%
rename from solution/src/main/java/com/inuker/solution/SearchInRotatedSortedArrayII.java
rename to leetcode/solution/src/SearchInRotatedSortedArrayII.java
index eec8ff6..5014371 100644
--- a/solution/src/main/java/com/inuker/solution/SearchInRotatedSortedArrayII.java
+++ b/leetcode/solution/src/SearchInRotatedSortedArrayII.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/11/23.
- */
-
public class SearchInRotatedSortedArrayII {
/**
* TestCase
diff --git a/solution/src/main/java/com/inuker/solution/SearchInsertPosition.java b/leetcode/solution/src/SearchInsertPosition.java
similarity index 89%
rename from solution/src/main/java/com/inuker/solution/SearchInsertPosition.java
rename to leetcode/solution/src/SearchInsertPosition.java
index 49ce536..15e2abb 100644
--- a/solution/src/main/java/com/inuker/solution/SearchInsertPosition.java
+++ b/leetcode/solution/src/SearchInsertPosition.java
@@ -1,11 +1,5 @@
-package com.inuker.solution;
-
import java.util.Arrays;
-/**
- * Created by dingjikerbo on 2016/12/17.
- */
-
public class SearchInsertPosition {
public int searchInsert(int[] nums, int target) {
diff --git a/solution/src/main/java/com/inuker/solution/SegmentTreeNode.java b/leetcode/solution/src/SegmentTreeNode.java
similarity index 74%
rename from solution/src/main/java/com/inuker/solution/SegmentTreeNode.java
rename to leetcode/solution/src/SegmentTreeNode.java
index a132182..15eb3e2 100644
--- a/solution/src/main/java/com/inuker/solution/SegmentTreeNode.java
+++ b/leetcode/solution/src/SegmentTreeNode.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/11/26.
- */
-
public class SegmentTreeNode {
public SegmentTreeNode left, right;
diff --git a/solution/src/main/java/com/inuker/solution/SelfCrossing.java b/leetcode/solution/src/SelfCrossing.java
similarity index 92%
rename from solution/src/main/java/com/inuker/solution/SelfCrossing.java
rename to leetcode/solution/src/SelfCrossing.java
index 61311f2..ee9c63c 100644
--- a/solution/src/main/java/com/inuker/solution/SelfCrossing.java
+++ b/leetcode/solution/src/SelfCrossing.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/12/21.
- */
-
/**
* 这题非常数学,最好画一下,总的来说可以归纳为三种情况:
* 1. 第4条线和第1条线相交
diff --git a/solution/src/main/java/com/inuker/solution/SentenceScreenFitting.java b/leetcode/solution/src/SentenceScreenFitting.java
similarity index 96%
rename from solution/src/main/java/com/inuker/solution/SentenceScreenFitting.java
rename to leetcode/solution/src/SentenceScreenFitting.java
index 32db5fc..d4ab086 100644
--- a/solution/src/main/java/com/inuker/solution/SentenceScreenFitting.java
+++ b/leetcode/solution/src/SentenceScreenFitting.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/12/11.
- */
-
/**
* https://discuss.leetcode.com/category/546/sentence-screen-fitting
*/
diff --git a/solution/src/main/java/com/inuker/solution/SerializeAndDeserializeBST.java b/leetcode/solution/src/SerializeAndDeserializeBST.java
similarity index 79%
rename from solution/src/main/java/com/inuker/solution/SerializeAndDeserializeBST.java
rename to leetcode/solution/src/SerializeAndDeserializeBST.java
index acb7ca2..7b0a36e 100644
--- a/solution/src/main/java/com/inuker/solution/SerializeAndDeserializeBST.java
+++ b/leetcode/solution/src/SerializeAndDeserializeBST.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by liwentian on 17/8/3.
- */
-
/**
* 本题和#297一样
*/
diff --git a/solution/src/main/java/com/inuker/solution/SetMatrixZeroes.java b/leetcode/solution/src/SetMatrixZeroes.java
similarity index 95%
rename from solution/src/main/java/com/inuker/solution/SetMatrixZeroes.java
rename to leetcode/solution/src/SetMatrixZeroes.java
index f9c258f..00206d3 100644
--- a/solution/src/main/java/com/inuker/solution/SetMatrixZeroes.java
+++ b/leetcode/solution/src/SetMatrixZeroes.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by liwentian on 17/8/12.
- */
-
public class SetMatrixZeroes {
public void setZeroes(int[][] matrix) {
diff --git a/solution/src/main/java/com/inuker/solution/ShortestDistanceFromAllBuildings.java b/leetcode/solution/src/ShortestDistanceFromAllBuildings.java
similarity index 97%
rename from solution/src/main/java/com/inuker/solution/ShortestDistanceFromAllBuildings.java
rename to leetcode/solution/src/ShortestDistanceFromAllBuildings.java
index ea243b8..b623b0f 100644
--- a/solution/src/main/java/com/inuker/solution/ShortestDistanceFromAllBuildings.java
+++ b/leetcode/solution/src/ShortestDistanceFromAllBuildings.java
@@ -1,12 +1,6 @@
-package com.inuker.solution;
-
import java.util.LinkedList;
import java.util.Queue;
-/**
- * Created by dingjikerbo on 2016/12/11.
- */
-
public class ShortestDistanceFromAllBuildings {
/**
diff --git a/solution/src/main/java/com/inuker/solution/ShortestPalindrome.java b/leetcode/solution/src/ShortestPalindrome.java
similarity index 92%
rename from solution/src/main/java/com/inuker/solution/ShortestPalindrome.java
rename to leetcode/solution/src/ShortestPalindrome.java
index 478743f..8ffdb4e 100644
--- a/solution/src/main/java/com/inuker/solution/ShortestPalindrome.java
+++ b/leetcode/solution/src/ShortestPalindrome.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/12/17.
- */
-
/**
* https://segmentfault.com/a/1190000003059361
*/
diff --git a/solution/src/main/java/com/inuker/solution/ShortestWordDistance.java b/leetcode/solution/src/ShortestWordDistance.java
similarity index 81%
rename from solution/src/main/java/com/inuker/solution/ShortestWordDistance.java
rename to leetcode/solution/src/ShortestWordDistance.java
index 949e380..67bd274 100644
--- a/solution/src/main/java/com/inuker/solution/ShortestWordDistance.java
+++ b/leetcode/solution/src/ShortestWordDistance.java
@@ -1,12 +1,3 @@
-package com.inuker.solution;
-
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- * Created by dingjikerbo on 2016/11/25.
- */
-
public class ShortestWordDistance {
// 耗时3ms
diff --git a/solution/src/main/java/com/inuker/solution/ShortestWordDistanceII.java b/leetcode/solution/src/ShortestWordDistanceII.java
similarity index 90%
rename from solution/src/main/java/com/inuker/solution/ShortestWordDistanceII.java
rename to leetcode/solution/src/ShortestWordDistanceII.java
index dcf4f78..8ad89d4 100644
--- a/solution/src/main/java/com/inuker/solution/ShortestWordDistanceII.java
+++ b/leetcode/solution/src/ShortestWordDistanceII.java
@@ -1,15 +1,8 @@
-package com.inuker.solution;
-
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-/**
- * Created by liwentian on 2017/9/10.
- */
-
public class ShortestWordDistanceII {
private Map> map;
diff --git a/solution/src/main/java/com/inuker/solution/ShortestWordDistanceIII.java b/leetcode/solution/src/ShortestWordDistanceIII.java
similarity index 87%
rename from solution/src/main/java/com/inuker/solution/ShortestWordDistanceIII.java
rename to leetcode/solution/src/ShortestWordDistanceIII.java
index cef3649..584d71a 100644
--- a/solution/src/main/java/com/inuker/solution/ShortestWordDistanceIII.java
+++ b/leetcode/solution/src/ShortestWordDistanceIII.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by liwentian on 2017/9/10.
- */
-
public class ShortestWordDistanceIII {
public int shortestWordDistance(String[] words, String word1, String word2) {
diff --git a/solution/src/main/java/com/inuker/solution/ShuffleAnArray.java b/leetcode/solution/src/ShuffleAnArray.java
similarity index 93%
rename from solution/src/main/java/com/inuker/solution/ShuffleAnArray.java
rename to leetcode/solution/src/ShuffleAnArray.java
index c44160a..5bfd258 100644
--- a/solution/src/main/java/com/inuker/solution/ShuffleAnArray.java
+++ b/leetcode/solution/src/ShuffleAnArray.java
@@ -1,12 +1,6 @@
-package com.inuker.solution;
-
import java.util.Arrays;
import java.util.Random;
-/**
- * Created by dingjikerbo on 16/12/8.
- */
-
public class ShuffleAnArray {
private int[] mNums;
diff --git a/solution/src/main/java/com/inuker/solution/SimplifyPath.java b/leetcode/solution/src/SimplifyPath.java
similarity index 93%
rename from solution/src/main/java/com/inuker/solution/SimplifyPath.java
rename to leetcode/solution/src/SimplifyPath.java
index 2faa399..dff04a8 100644
--- a/solution/src/main/java/com/inuker/solution/SimplifyPath.java
+++ b/leetcode/solution/src/SimplifyPath.java
@@ -1,12 +1,6 @@
-package com.inuker.solution;
-
import java.util.Deque;
import java.util.LinkedList;
-/**
- * Created by dingjikerbo on 16/11/22.
- */
-
public class SimplifyPath {
public String simplifyPath(String path) {
diff --git a/solution/src/main/java/com/inuker/solution/SlidingWindowMaximum.java b/leetcode/solution/src/SlidingWindowMaximum.java
similarity index 87%
rename from solution/src/main/java/com/inuker/solution/SlidingWindowMaximum.java
rename to leetcode/solution/src/SlidingWindowMaximum.java
index 8c2c7e9..3524255 100644
--- a/solution/src/main/java/com/inuker/solution/SlidingWindowMaximum.java
+++ b/leetcode/solution/src/SlidingWindowMaximum.java
@@ -1,14 +1,4 @@
-package com.inuker.solution;
-
-import java.util.Comparator;
-import java.util.Deque;
-import java.util.LinkedList;
-import java.util.PriorityQueue;
-import java.util.Queue;
-
-/**
- * Created by dingjikerbo on 2016/11/16.
- */
+import java.util.*;
/**
* TestCases
diff --git a/solution/src/main/java/com/inuker/solution/SlidingWindowMedian.java b/leetcode/solution/src/SlidingWindowMedian.java
similarity index 95%
rename from solution/src/main/java/com/inuker/solution/SlidingWindowMedian.java
rename to leetcode/solution/src/SlidingWindowMedian.java
index c555d6a..a9b939c 100644
--- a/solution/src/main/java/com/inuker/solution/SlidingWindowMedian.java
+++ b/leetcode/solution/src/SlidingWindowMedian.java
@@ -1,12 +1,8 @@
-package com.inuker.solution;
-
-import java.util.Collections;
import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;
/**
- * Created by liwentian on 2017/9/12.
* https://leetcode.com/articles/sliding-window-median/
* 和 #295 Find Median from Data Stream 比较类似
*/
diff --git a/solution/src/main/java/com/inuker/solution/SmallestGoodBase.java b/leetcode/solution/src/SmallestGoodBase.java
similarity index 92%
rename from solution/src/main/java/com/inuker/solution/SmallestGoodBase.java
rename to leetcode/solution/src/SmallestGoodBase.java
index 8c533e8..257d024 100644
--- a/solution/src/main/java/com/inuker/solution/SmallestGoodBase.java
+++ b/leetcode/solution/src/SmallestGoodBase.java
@@ -1,11 +1,5 @@
-package com.inuker.solution;
-
import java.math.BigInteger;
-/**
- * Created by liwentian on 2017/9/22.
- */
-
public class SmallestGoodBase {
public String smallestGoodBase(String nn) {
diff --git a/solution/src/main/java/com/inuker/solution/SmallestRectangleEnclosingBlackPixels.java b/leetcode/solution/src/SmallestRectangleEnclosingBlackPixels.java
similarity index 93%
rename from solution/src/main/java/com/inuker/solution/SmallestRectangleEnclosingBlackPixels.java
rename to leetcode/solution/src/SmallestRectangleEnclosingBlackPixels.java
index 1c14288..f71408d 100644
--- a/solution/src/main/java/com/inuker/solution/SmallestRectangleEnclosingBlackPixels.java
+++ b/leetcode/solution/src/SmallestRectangleEnclosingBlackPixels.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by liwentian on 2017/9/22.
- */
-
public class SmallestRectangleEnclosingBlackPixels {
private char[][] image;
diff --git a/solution/src/main/java/com/inuker/solution/SortCharactersByFrequency.java b/leetcode/solution/src/SortCharactersByFrequency.java
similarity index 89%
rename from solution/src/main/java/com/inuker/solution/SortCharactersByFrequency.java
rename to leetcode/solution/src/SortCharactersByFrequency.java
index d1bc049..858813c 100644
--- a/solution/src/main/java/com/inuker/solution/SortCharactersByFrequency.java
+++ b/leetcode/solution/src/SortCharactersByFrequency.java
@@ -1,15 +1,4 @@
-package com.inuker.solution;
-
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.PriorityQueue;
-
-/**
- * Created by liwentian on 2017/9/22.
- */
+import java.util.*;
public class SortCharactersByFrequency {
diff --git a/solution/src/main/java/com/inuker/solution/SortColors.java b/leetcode/solution/src/SortColors.java
similarity index 97%
rename from solution/src/main/java/com/inuker/solution/SortColors.java
rename to leetcode/solution/src/SortColors.java
index e529289..8554544 100644
--- a/solution/src/main/java/com/inuker/solution/SortColors.java
+++ b/leetcode/solution/src/SortColors.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/11/22.
- */
-
public class SortColors {
/**
diff --git a/solution/src/main/java/com/inuker/solution/SortList.java b/leetcode/solution/src/SortList.java
similarity index 95%
rename from solution/src/main/java/com/inuker/solution/SortList.java
rename to leetcode/solution/src/SortList.java
index c2d035c..bd10a33 100644
--- a/solution/src/main/java/com/inuker/solution/SortList.java
+++ b/leetcode/solution/src/SortList.java
@@ -1,11 +1,3 @@
-package com.inuker.solution;
-
-import com.leetcode.library.ListNode;
-
-/**
- * Created by liwentian on 2017/9/11.
- */
-
/**
* 这题采用merge sort,可自顶向下或自底向上
* 区别是自顶向下是递归的,需要额外的空间
diff --git a/solution/src/main/java/com/inuker/solution/SparseMatrixMultiplication.java b/leetcode/solution/src/SparseMatrixMultiplication.java
similarity index 88%
rename from solution/src/main/java/com/inuker/solution/SparseMatrixMultiplication.java
rename to leetcode/solution/src/SparseMatrixMultiplication.java
index 0df48e5..60ec5fb 100644
--- a/solution/src/main/java/com/inuker/solution/SparseMatrixMultiplication.java
+++ b/leetcode/solution/src/SparseMatrixMultiplication.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/11/19.
- */
-
/**
* 这题有点意思,只要给里层两个for循环交换一下顺序即可
*/
diff --git a/solution/src/main/java/com/inuker/solution/SpiralMatrix.java b/leetcode/solution/src/SpiralMatrix.java
similarity index 94%
rename from solution/src/main/java/com/inuker/solution/SpiralMatrix.java
rename to leetcode/solution/src/SpiralMatrix.java
index fcc9c6a..3cd7e21 100644
--- a/solution/src/main/java/com/inuker/solution/SpiralMatrix.java
+++ b/leetcode/solution/src/SpiralMatrix.java
@@ -1,12 +1,6 @@
-package com.inuker.solution;
-
import java.util.ArrayList;
import java.util.List;
-/**
- * Created by liwentian on 2017/9/10.
- */
-
public class SpiralMatrix {
public List spiralOrder(int[][] matrix) {
diff --git a/solution/src/main/java/com/inuker/solution/SplitArrayLargestSum.java b/leetcode/solution/src/SplitArrayLargestSum.java
similarity index 97%
rename from solution/src/main/java/com/inuker/solution/SplitArrayLargestSum.java
rename to leetcode/solution/src/SplitArrayLargestSum.java
index 9fadf84..b1370a6 100644
--- a/solution/src/main/java/com/inuker/solution/SplitArrayLargestSum.java
+++ b/leetcode/solution/src/SplitArrayLargestSum.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 2016/12/19.
- */
-
/**
* 将数组切成m段,求所有段中最大值的最小值
* 我们倒过来思考,假设这个值为k,则意味着所有段的和都不会超过k,如果我们能确保这种情况下数组能被切成m段,则表明k是候选的值。那怎样确保k是最小值呢?
diff --git a/solution/src/main/java/com/inuker/solution/Sqrt.java b/leetcode/solution/src/Sqrt.java
similarity index 92%
rename from solution/src/main/java/com/inuker/solution/Sqrt.java
rename to leetcode/solution/src/Sqrt.java
index 13d2c32..e8aff4e 100644
--- a/solution/src/main/java/com/inuker/solution/Sqrt.java
+++ b/leetcode/solution/src/Sqrt.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/11/23.
- */
-
public class Sqrt {
/**
diff --git a/solution/src/main/java/com/inuker/solution/StrStr.java b/leetcode/solution/src/StrStr.java
similarity index 87%
rename from solution/src/main/java/com/inuker/solution/StrStr.java
rename to leetcode/solution/src/StrStr.java
index 10bb0ca..4f49e9b 100644
--- a/solution/src/main/java/com/inuker/solution/StrStr.java
+++ b/leetcode/solution/src/StrStr.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 16/11/23.
- */
-
public class StrStr {
// 这里非常重要的是i<=len1-len2,如果没有这个会超时
diff --git a/solution/src/main/java/com/inuker/solution/String2Integer.java b/leetcode/solution/src/String2Integer.java
similarity index 93%
rename from solution/src/main/java/com/inuker/solution/String2Integer.java
rename to leetcode/solution/src/String2Integer.java
index 6ee927c..dcf028a 100644
--- a/solution/src/main/java/com/inuker/solution/String2Integer.java
+++ b/leetcode/solution/src/String2Integer.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by dingjikerbo on 17/4/29.
- */
-
/**
* 要求如下:
* 1. 过滤掉前面的空格
diff --git a/solution/src/main/java/com/inuker/solution/StrobogrammaticNumber.java b/leetcode/solution/src/StrobogrammaticNumber.java
similarity index 82%
rename from solution/src/main/java/com/inuker/solution/StrobogrammaticNumber.java
rename to leetcode/solution/src/StrobogrammaticNumber.java
index de3bdd3..5ffcd25 100644
--- a/solution/src/main/java/com/inuker/solution/StrobogrammaticNumber.java
+++ b/leetcode/solution/src/StrobogrammaticNumber.java
@@ -1,9 +1,3 @@
-package com.inuker.solution;
-
-/**
- * Created by liwentian on 2017/8/31.
- */
-
/**
* 旋转180度,而不是上下镜像
*/
diff --git a/solution/src/main/java/com/inuker/solution/SubarraySumEqualsK.java b/leetcode/solution/src/SubarraySumEqualsK.java
similarity index 89%
rename from solution/src/main/java/com/inuker/solution/SubarraySumEqualsK.java
rename to leetcode/solution/src/SubarraySumEqualsK.java
index ed45c26..bdf26fd 100644
--- a/solution/src/main/java/com/inuker/solution/SubarraySumEqualsK.java
+++ b/leetcode/solution/src/SubarraySumEqualsK.java
@@ -1,9 +1,6 @@
-package com.inuker.solution;
-
import java.util.HashMap;
/**
- * Created by liwentian on 2017/12/5.
* https://leetcode.com/articles/subarray-sum-equals-k/
*/
diff --git a/solution/src/main/java/com/inuker/solution/Subsets.java b/leetcode/solution/src/Subsets.java
similarity index 95%
rename from solution/src/main/java/com/inuker/solution/Subsets.java
rename to leetcode/solution/src/Subsets.java
index d9deacf..c26b40f 100644
--- a/solution/src/main/java/com/inuker/solution/Subsets.java
+++ b/leetcode/solution/src/Subsets.java
@@ -1,13 +1,7 @@
-package com.inuker.solution;
-
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by dingjikerbo on 2016/11/22.
- */
-
/**
* 思路是对每个index,有两种情况,要还是不要
* 要注意的是添加结果到result时,要复制一个列表,别直接加list
diff --git a/solution/src/main/java/com/inuker/solution/SubsetsII.java b/leetcode/solution/src/SubsetsII.java
similarity index 93%
rename from solution/src/main/java/com/inuker/solution/SubsetsII.java
rename to leetcode/solution/src/SubsetsII.java
index 7166f0d..c84b198 100644
--- a/solution/src/main/java/com/inuker/solution/SubsetsII.java
+++ b/leetcode/solution/src/SubsetsII.java
@@ -1,13 +1,7 @@
-package com.inuker.solution;
-
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by dingjikerbo on 2016/11/22.
- */
-
public class SubsetsII {
public List