├── LICENSE ├── README.md ├── issue_11 └── findGapBetweenOnes.c ├── issue_6 └── ftoa.c ├── issue_7 └── Currency.java ├── prob_1.5 ├── .gitignore ├── README.md ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src │ ├── main │ └── java │ │ └── Prob.java │ └── test │ └── java │ └── ProbTest.java ├── prob_1.7 ├── .gitignore ├── README.md ├── build.gradle ├── gradlew ├── gradlew.bat ├── settings.gradle └── src │ ├── main │ └── java │ │ └── Prob.java │ └── test │ └── java │ └── ProbTest.java ├── prob_2.7_issue-13 ├── .gitignore ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src │ ├── main │ └── java │ │ └── Prob.java │ └── test │ └── java │ └── ProbTest.java ├── prob_3.5_issue_10 └── Queue │ ├── Queue.java │ └── QueueTest.java ├── prob_3.6_issue_9 └── SortStack │ ├── SortStack.java │ └── SortStackTest.java └── 알고리즘문제풀이전략 ├── 17_06_11 └── SortAlgorithm.java └── 17_06_25 └── MergeSort.java /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 algorithm-study-of-GN 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 코딩 인터뷰를 위한 알고리즘 스터디 2 | 코딩 인터뷰 완전 분석의 문제 해결 저장소입니다. 3 | 4 | - 시간: 일요일 오후 2시 ~ 4시 5 | - 장소: 토스랩 사무실 (강남구 역삼동 823-30 라인빌딩 11층) 6 | - 방식: 7 | 8 | 1. 코딩 인터뷰에 적합하다고 판단되는 문제를 인터넷, 책 등에서 구해서 업로드 9 | 2. 매 스터디 시간에 랜덤으로 1명은 출제, 1명은 풀이 하는 식으로 4-5문제 풀이 10 | 3. 전부 끝난 후 다른 의견 토론 11 | 12 | 13 | 14 | ## 문제 15 | - 첫 번째 스터디 모임을 위해, 문제를 2개씩 준비해주세요. 16 | -------------------------------------------------------------------------------- /issue_11/findGapBetweenOnes.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int findGapBetweenOnes(int N){ 4 | int max_count=0; 5 | int cur_count=0; 6 | while(N && ((N&1)==0)) N>>=1; 7 | 8 | while(N){ 9 | if(N&1){ 10 | if(cur_count>max_count){ 11 | max_count=cur_count; 12 | } 13 | cur_count=0; 14 | } 15 | else{ 16 | cur_count++; 17 | } 18 | N>>=1; 19 | } 20 | return max_count; 21 | } 22 | 23 | int main(){ 24 | int N = 74901729; //100011101101110100011100001 => 4 25 | printf("find gap between ones for %d : %d\n", N, findGapBetweenOnes(N)); 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /issue_6/ftoa.c: -------------------------------------------------------------------------------- 1 | /* 2016.06.13 Eunice */ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #define PRECESION 5 8 | 9 | void ftoa(char* result, float value); 10 | 11 | int main() { 12 | 13 | char result[50]; 14 | float value; 15 | 16 | printf("Enter float:"); 17 | scanf("%f", &value); 18 | ftoa(result, value); 19 | printf("Convert:%s\n", result); 20 | return 0; 21 | } 22 | 23 | void ftoa(char* result, float value) { 24 | 25 | int intpart, temp; 26 | float fraction; 27 | int i, n, cur; 28 | char* pos = result; 29 | 30 | if (value < 0) { 31 | *pos = '-'; 32 | pos++; 33 | value *= -1; 34 | } 35 | 36 | intpart = (int)value; 37 | n = (int)log10(intpart)+1; 38 | 39 | for (i = 0; i a2b1c10a2 7 | 8 | 단, 원래의 문자열보다 짧아지지 않는 경우, 원래의 문자열을 그대로 반환하라. -------------------------------------------------------------------------------- /prob_1.5/build.gradle: -------------------------------------------------------------------------------- 1 | version '1.0-SNAPSHOT' 2 | 3 | apply plugin: 'java' 4 | 5 | sourceCompatibility = 1.5 6 | 7 | repositories { 8 | mavenCentral() 9 | } 10 | 11 | dependencies { 12 | testCompile group: 'junit', name: 'junit', version: '4.11' 13 | testCompile 'org.assertj:assertj-core:3.4.1' 14 | } 15 | -------------------------------------------------------------------------------- /prob_1.5/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithm-study-of-GN/problem-of-coding-interview/b4830f160f623c3590a1287aff307b4649fdd606/prob_1.5/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /prob_1.5/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Jun 15 22:40:49 KST 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip 7 | -------------------------------------------------------------------------------- /prob_1.5/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /prob_1.5/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /prob_1.5/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'prob_1.5' 2 | 3 | -------------------------------------------------------------------------------- /prob_1.5/src/main/java/Prob.java: -------------------------------------------------------------------------------- 1 | public class Prob { 2 | public static String input(String input) { 3 | 4 | if (input == null || input.isEmpty()) { 5 | return ""; 6 | } 7 | 8 | StringBuffer buffer = new StringBuffer(); 9 | int lastCount = 1; 10 | char lastChar = input.charAt(0); 11 | buffer.append(lastChar); 12 | 13 | for (int idx = 1; idx < input.length(); idx++) { 14 | if (lastChar == input.charAt(idx)) { 15 | lastCount++; 16 | } else { 17 | buffer.append(lastCount); 18 | lastChar = input.charAt(idx); 19 | lastCount = 1; 20 | buffer.append(lastChar); 21 | } 22 | 23 | if (buffer.length() >= input.length()) { 24 | return input; 25 | } 26 | } 27 | 28 | buffer.append(lastCount); 29 | 30 | 31 | return buffer.toString(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /prob_1.5/src/test/java/ProbTest.java: -------------------------------------------------------------------------------- 1 | import static org.assertj.core.api.Assertions.assertThat; 2 | 3 | public class ProbTest { 4 | 5 | private static final String EXAM_1 = "aabccccccccccaa"; 6 | private static final String EXAM_2 = "abcd"; 7 | 8 | @org.junit.Test 9 | public void testInput() throws Exception { 10 | String input = Prob.input(EXAM_1); 11 | assertThat(input).isEqualTo("a2b1c10a2"); 12 | 13 | input = Prob.input(EXAM_2); 14 | assertThat(input).isEqualTo(EXAM_2); 15 | 16 | input = Prob.input(""); 17 | assertThat(input).hasSize(0); 18 | 19 | input = Prob.input(null); 20 | assertThat(input).hasSize(0); 21 | } 22 | } -------------------------------------------------------------------------------- /prob_1.7/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/idea,intellij,java,gradle 3 | 4 | #!! ERROR: idea is undefined. Use list command to see defined gitignore types !!# 5 | 6 | ### Intellij ### 7 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 8 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 9 | 10 | # User-specific stuff: 11 | .idea/workspace.xml 12 | .idea/tasks.xml 13 | .idea/dictionaries 14 | .idea/vcs.xml 15 | .idea/jsLibraryMappings.xml 16 | .idea 17 | # Sensitive or high-churn files: 18 | .idea/dataSources.ids 19 | .idea/dataSources.xml 20 | .idea/dataSources.local.xml 21 | .idea/sqlDataSources.xml 22 | .idea/dynamic.xml 23 | .idea/uiDesigner.xml 24 | 25 | # Gradle: 26 | .idea/gradle.xml 27 | .idea/libraries 28 | 29 | # Mongo Explorer plugin: 30 | .idea/mongoSettings.xml 31 | 32 | ## File-based project format: 33 | *.iws 34 | 35 | ## Plugin-specific files: 36 | 37 | # IntelliJ 38 | /out/ 39 | 40 | # mpeltonen/sbt-idea plugin 41 | .idea_modules/ 42 | 43 | # JIRA plugin 44 | atlassian-ide-plugin.xml 45 | 46 | # Crashlytics plugin (for Android Studio and IntelliJ) 47 | com_crashlytics_export_strings.xml 48 | crashlytics.properties 49 | crashlytics-build.properties 50 | fabric.properties 51 | 52 | ### Intellij Patch ### 53 | # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 54 | 55 | # *.iml 56 | # modules.xml 57 | 58 | 59 | ### Java ### 60 | *.class 61 | 62 | # Mobile Tools for Java (J2ME) 63 | .mtj.tmp/ 64 | 65 | # Package Files # 66 | *.jar 67 | *.war 68 | *.ear 69 | 70 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 71 | hs_err_pid* 72 | 73 | 74 | ### Gradle ### 75 | .gradle 76 | build/ 77 | 78 | # Ignore Gradle GUI config 79 | gradle-app.setting 80 | 81 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 82 | !gradle-wrapper.jar 83 | 84 | # Cache of project 85 | .gradletasknamecache 86 | 87 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 88 | # gradle/wrapper/gradle-wrapper.properties 89 | 90 | *.iml -------------------------------------------------------------------------------- /prob_1.7/README.md: -------------------------------------------------------------------------------- 1 | ## 문제 1.7 저장소 2 | ---- 3 | 4 | M x N 행렬의 한 원소가 0일 경우, 해당 원소가 속한 행과 열의 모든 원소를 0으로 설정하는 알고리즘을 작성하라. -------------------------------------------------------------------------------- /prob_1.7/build.gradle: -------------------------------------------------------------------------------- 1 | version '1.0-SNAPSHOT' 2 | 3 | apply plugin: 'java' 4 | 5 | sourceCompatibility = 1.5 6 | 7 | repositories { 8 | mavenCentral() 9 | } 10 | 11 | dependencies { 12 | testCompile group: 'junit', name: 'junit', version: '4.11' 13 | testCompile 'org.assertj:assertj-core:3.4.1' 14 | } 15 | -------------------------------------------------------------------------------- /prob_1.7/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /prob_1.7/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /prob_1.7/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'prob_1.7' 2 | 3 | -------------------------------------------------------------------------------- /prob_1.7/src/main/java/Prob.java: -------------------------------------------------------------------------------- 1 | public class Prob { 2 | 3 | public static int[][] input(int[][] input) { 4 | 5 | int height = input.length; 6 | int width = input[0].length; 7 | 8 | boolean[] rows = new boolean[height]; 9 | boolean[] cols = new boolean[width]; 10 | 11 | for (int row = 0; row < height; row++) { 12 | for (int col = 0; col < width; col++) { 13 | if (input[row][col] == 0) { 14 | rows[row] = true; 15 | cols[col] = true; 16 | } 17 | } 18 | } 19 | 20 | 21 | for (int row = 0; row < height; row++) { 22 | for (int col = 0; col < width; col++) { 23 | if (rows[row] || cols[col]) { 24 | input[row][col] = 0; 25 | } 26 | } 27 | } 28 | 29 | 30 | return input; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /prob_1.7/src/test/java/ProbTest.java: -------------------------------------------------------------------------------- 1 | import org.junit.Test; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | public class ProbTest { 6 | 7 | private static final int[][] EXAM_1 = { 8 | {1, 1, 1, 1, 1, 1, 1}, 9 | {1, 0, 1, 1, 1, 1, 1}, 10 | {1, 1, 1, 1, 1, 1, 1}, 11 | {1, 1, 1, 0, 1, 1, 1}, 12 | {1, 1, 1, 1, 1, 1, 1}, 13 | {1, 0, 1, 1, 1, 1, 1}, 14 | {1, 1, 1, 1, 1, 1, 1} 15 | }; 16 | 17 | private static final int[][] SOL_1 = { 18 | {1, 0, 1, 0, 1, 1, 1}, 19 | {0, 0, 0, 0, 0, 0, 0}, 20 | {1, 0, 1, 0, 1, 1, 1}, 21 | {0, 0, 0, 0, 0, 0, 0}, 22 | {1, 0, 1, 0, 1, 1, 1}, 23 | {0, 0, 0, 0, 0, 0, 0}, 24 | {1, 1, 1, 0, 1, 1, 1} 25 | }; 26 | 27 | @Test 28 | public void testInput() throws Exception { 29 | int[][] input = Prob.input(EXAM_1); 30 | 31 | 32 | int colLength = input[0].length; 33 | for (int row = 0; row < input.length; row++) { 34 | for (int col = 0; col < colLength; col++) { 35 | assertThat(input[row][col]).isEqualTo(input[row][col]); 36 | } 37 | } 38 | 39 | } 40 | } -------------------------------------------------------------------------------- /prob_2.7_issue-13/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/intellij,gradle,java 3 | 4 | ### Intellij ### 5 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 6 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 7 | 8 | # User-specific stuff: 9 | .idea/workspace.xml 10 | .idea/tasks.xml 11 | .idea/dictionaries 12 | .idea/vcs.xml 13 | .idea/jsLibraryMappings.xml 14 | .idea 15 | 16 | # Sensitive or high-churn files: 17 | .idea/dataSources.ids 18 | .idea/dataSources.xml 19 | .idea/dataSources.local.xml 20 | .idea/sqlDataSources.xml 21 | .idea/dynamic.xml 22 | .idea/uiDesigner.xml 23 | 24 | # Gradle: 25 | .idea/gradle.xml 26 | .idea/libraries 27 | 28 | # Mongo Explorer plugin: 29 | .idea/mongoSettings.xml 30 | 31 | ## File-based project format: 32 | *.iws 33 | 34 | ## Plugin-specific files: 35 | 36 | # IntelliJ 37 | /out/ 38 | 39 | # mpeltonen/sbt-idea plugin 40 | .idea_modules/ 41 | 42 | # JIRA plugin 43 | atlassian-ide-plugin.xml 44 | 45 | # Crashlytics plugin (for Android Studio and IntelliJ) 46 | com_crashlytics_export_strings.xml 47 | crashlytics.properties 48 | crashlytics-build.properties 49 | fabric.properties 50 | 51 | ### Intellij Patch ### 52 | # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 53 | 54 | *.iml 55 | # modules.xml 56 | # .idea/misc.xml 57 | # *.ipr 58 | 59 | 60 | ### Java ### 61 | *.class 62 | 63 | # Mobile Tools for Java (J2ME) 64 | .mtj.tmp/ 65 | 66 | # Package Files # 67 | *.jar 68 | *.war 69 | *.ear 70 | 71 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 72 | hs_err_pid* 73 | 74 | 75 | ### Gradle ### 76 | .gradle 77 | build/ 78 | 79 | # Ignore Gradle GUI config 80 | gradle-app.setting 81 | 82 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 83 | !gradle-wrapper.jar 84 | 85 | # Cache of project 86 | .gradletasknamecache 87 | 88 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 89 | # gradle/wrapper/gradle-wrapper.properties -------------------------------------------------------------------------------- /prob_2.7_issue-13/build.gradle: -------------------------------------------------------------------------------- 1 | version '1.0-SNAPSHOT' 2 | 3 | apply plugin: 'java' 4 | 5 | repositories { 6 | mavenCentral() 7 | } 8 | 9 | dependencies { 10 | testCompile group: 'junit', name: 'junit', version: '4.11' 11 | testCompile 'org.assertj:assertj-core:3.4.1' 12 | } 13 | -------------------------------------------------------------------------------- /prob_2.7_issue-13/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithm-study-of-GN/problem-of-coding-interview/b4830f160f623c3590a1287aff307b4649fdd606/prob_2.7_issue-13/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /prob_2.7_issue-13/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Jun 26 13:15:41 KST 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-bin.zip 7 | -------------------------------------------------------------------------------- /prob_2.7_issue-13/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /prob_2.7_issue-13/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /prob_2.7_issue-13/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'prob_2.7_issue-13' 2 | 3 | -------------------------------------------------------------------------------- /prob_2.7_issue-13/src/main/java/Prob.java: -------------------------------------------------------------------------------- 1 | public class Prob { 2 | 3 | 4 | public static boolean input(Node first) { 5 | 6 | boolean finish = false; 7 | boolean half = false; 8 | 9 | Node now = first; 10 | Node runner2x = first; 11 | while (!finish) { 12 | 13 | if (!half) { 14 | if (runner2x.next != null) { 15 | if (runner2x.next.next != null) { 16 | runner2x = runner2x.next.next; 17 | now = now.next; 18 | } else { 19 | // 짝수 20 | half = true; 21 | runner2x = now.next; 22 | } 23 | } else { 24 | // 홀수 25 | half = true; 26 | runner2x = now.next; 27 | now = now.prev; 28 | } 29 | 30 | } else { 31 | 32 | if (now.value != runner2x.value) { 33 | return false; 34 | } else { 35 | now = now.prev; 36 | runner2x = runner2x.next; 37 | finish = true; 38 | 39 | if (now == null || runner2x == null) { 40 | return true; 41 | } 42 | } 43 | } 44 | } 45 | return true; 46 | } 47 | 48 | public static class Node { 49 | Node prev; 50 | Node next; 51 | 52 | char value; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /prob_2.7_issue-13/src/test/java/ProbTest.java: -------------------------------------------------------------------------------- 1 | import org.junit.Test; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | /** 6 | * Created by jsuch2362 on 2016. 6. 26.. 7 | */ 8 | public class ProbTest { 9 | 10 | private static final String TEST_1 = "abcddcba"; 11 | private static final String TEST_2 = "abcdcba"; 12 | private static final String TEST_3 = "abcdbcba"; 13 | 14 | @Test 15 | public void testInput() throws Exception { 16 | assertThat(Prob.input(makeNode(TEST_1))).isTrue(); 17 | assertThat(Prob.input(makeNode(TEST_2))).isTrue(); 18 | assertThat(Prob.input(makeNode(TEST_3))).isFalse(); 19 | } 20 | 21 | private Prob.Node makeNode(String input) { 22 | 23 | int size = input.length(); 24 | Prob.Node first = new Prob.Node(); 25 | first.value = input.charAt(0); 26 | Prob.Node last = first; 27 | for (int idx = 1; idx < size; idx++) { 28 | Prob.Node node = new Prob.Node(); 29 | 30 | node.prev = last; 31 | node.value = input.charAt(idx); 32 | last.next = node; 33 | 34 | last = node; 35 | 36 | } 37 | 38 | return first; 39 | } 40 | } -------------------------------------------------------------------------------- /prob_3.5_issue_10/Queue/Queue.java: -------------------------------------------------------------------------------- 1 | package Queue; 2 | 3 | import java.util.Stack; 4 | 5 | public class Queue { 6 | Stack in; 7 | Stack out; 8 | 9 | public Queue() { 10 | in = new Stack(); 11 | out = new Stack(); 12 | } 13 | public void enqueue(int val) { 14 | in.push(val); 15 | } 16 | 17 | public int dequeue() { 18 | if(out.isEmpty()) { 19 | if(in.isEmpty()) { 20 | return -1; 21 | } else { 22 | do { 23 | out.push(in.pop()); 24 | } while(!in.isEmpty()); 25 | } 26 | } 27 | return out.pop(); 28 | 29 | 30 | } 31 | 32 | public boolean isEmpty() { 33 | return in.isEmpty() && out.isEmpty(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /prob_3.5_issue_10/Queue/QueueTest.java: -------------------------------------------------------------------------------- 1 | package Queue; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Before; 6 | import org.junit.Test; 7 | 8 | public class QueueTest { 9 | Queue q; 10 | public void testing(Object expected, Object actual) { 11 | assertEquals(expected, actual); 12 | } 13 | 14 | @Before 15 | public void setup() { 16 | q = new Queue(); 17 | q.enqueue(10); 18 | q.enqueue(5); 19 | q.enqueue(1); 20 | q.enqueue(4); 21 | } 22 | 23 | @Test 24 | public void testQueue() { 25 | 26 | testing(10, q.dequeue()); 27 | q.enqueue(8); 28 | testing(5, q.dequeue()); 29 | testing(1, q.dequeue()); 30 | testing(4, q.dequeue()); 31 | testing(8, q.dequeue()); 32 | q.enqueue(15); 33 | testing(15, q.dequeue()); 34 | 35 | } 36 | 37 | @Test 38 | public void testIsEmpty() { 39 | assertFalse(q.isEmpty()); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /prob_3.6_issue_9/SortStack/SortStack.java: -------------------------------------------------------------------------------- 1 | package SortStack; 2 | 3 | import java.util.Stack; 4 | 5 | public class SortStack { 6 | public static void sortStack(Stack s1) { 7 | Stack s2 = new Stack(); 8 | int val; 9 | 10 | while(!s1.isEmpty()) { 11 | val = s1.pop(); 12 | while(!s2.isEmpty() && val > s2.peek()) { 13 | s1.push(s2.pop()); 14 | } 15 | s2.push(val); 16 | } 17 | 18 | while(!s2.isEmpty()) { 19 | s1.push(s2.pop()); 20 | } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /prob_3.6_issue_9/SortStack/SortStackTest.java: -------------------------------------------------------------------------------- 1 | package SortStack; 2 | 3 | import java.util.Stack; 4 | import static org.junit.Assert.*; 5 | import org.junit.Test; 6 | 7 | public class SortStackTest { 8 | 9 | @Test 10 | public void testSortStack() { 11 | Stack a = new Stack(); 12 | a.push(10); a.push(2); a.push(5); a.push(8); a.push(3); a.push(1); 13 | SortStack.sortStack(a); 14 | 15 | assertEquals(new Integer(10), a.pop()); 16 | assertEquals(new Integer(8), a.pop()); 17 | assertEquals(new Integer(5), a.pop()); 18 | assertEquals(new Integer(3), a.pop()); 19 | assertEquals(new Integer(2), a.pop()); 20 | assertEquals(new Integer(1), a.pop()); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /알고리즘문제풀이전략/17_06_11/SortAlgorithm.java: -------------------------------------------------------------------------------- 1 | 2 | public class SortAlgorithm { 3 | 4 | public void BubbleSort() throws Exception { 5 | int[] array = new int[] {4,2,10,35,3,12,54,23}; 6 | int temp = -1; 7 | 8 | for(int count : array){ 9 | System.out.print(count + ","); 10 | 11 | } 12 | 13 | System.out.println(""); 14 | 15 | for(int q = array.length; q > 0; q--) { 16 | for (int i = 0; i < q -1; i++) { 17 | int comparePos = i + 1; 18 | 19 | if (array[i] > array[comparePos]) { 20 | temp = array[comparePos]; 21 | array[comparePos] = array[i]; 22 | array[i] = temp; 23 | } 24 | } 25 | } 26 | 27 | for (int count : array){ 28 | System.out.print(count + ","); 29 | } 30 | } 31 | 32 | public void SelectionSort() throws Exception { 33 | int[] array = new int[] {4,2,10,35,3,12,54,23}; 34 | int temp = -1; 35 | int minValue = Integer.MAX_VALUE; 36 | int selectIdx = -1; 37 | 38 | for(int count : array){ 39 | System.out.print(count + ","); 40 | } 41 | 42 | System.out.println(""); 43 | 44 | for(int i = 0; i < array.length - 1; i++){ 45 | minValue = array[i]; 46 | for(int q = i + 1; q < array.length; q ++){ 47 | if(array[q] < minValue){ 48 | minValue = array[q]; 49 | selectIdx = q; 50 | } 51 | } 52 | 53 | temp = array[selectIdx]; 54 | array[selectIdx] = array[i]; 55 | array[i] = temp; 56 | } 57 | 58 | for(int count : array){ 59 | System.out.print(count + ","); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /알고리즘문제풀이전략/17_06_25/MergeSort.java: -------------------------------------------------------------------------------- 1 | 2 | public class MergeSort { 3 | 4 | private static final int ITEM_SIZE = 8; 5 | 6 | public void mergeSort() throws Exception { 7 | int[] array = new int[] {4,2,10,35,3,12,54,23}; 8 | 9 | for(int count : array){ 10 | System.out.print(count + ","); 11 | } 12 | 13 | System.out.println(""); 14 | 15 | divide_merge(array, 0, ITEM_SIZE -1); 16 | 17 | for(int count : array){ 18 | System.out.print(count + ","); 19 | } 20 | 21 | System.out.println(""); 22 | } 23 | 24 | private void divide_merge(int[] arr, int left, int right){ 25 | 26 | if(left == right) 27 | return ; 28 | int mid = (left + right) / 2; 29 | 30 | divide_merge(arr, left, mid); 31 | divide_merge(arr, mid + 1, right); 32 | merge(arr, left, mid, right); 33 | } 34 | 35 | private void merge(int[] array, int left, int mid, int right){ 36 | 37 | int i = left; 38 | int j = mid + 1; 39 | int idx = left; 40 | 41 | int[] tempArray = new int[ITEM_SIZE]; 42 | 43 | while (i <= mid && j <= right){ 44 | if(array[i] < array[j]){ 45 | tempArray[idx] = array[i]; 46 | i++; 47 | } else{ 48 | tempArray[idx] = array[j]; 49 | j++; 50 | } 51 | idx ++; 52 | } 53 | 54 | if(i <= mid){ 55 | for(int m = i; m <= mid; m++){ 56 | tempArray[idx] = array[m]; 57 | idx ++; 58 | } 59 | }else if(j <= right){ 60 | for(int q = j; q <= right; q++){ 61 | tempArray[idx] = array[q]; 62 | idx++; 63 | } 64 | } 65 | 66 | for(int m = left; m <= right; m++){ 67 | array[m] = tempArray[m]; 68 | } 69 | } 70 | 71 | } 72 | --------------------------------------------------------------------------------