├── gradle.properties ├── settings.gradle ├── src ├── main │ ├── java │ │ └── com │ │ │ └── jyami │ │ │ ├── hashCode │ │ │ ├── output │ │ │ │ └── a_example.txt │ │ │ └── data │ │ │ │ └── a_example.txt │ │ │ ├── ewhaAlgorithm │ │ │ ├── testData │ │ │ │ ├── graph3.txt │ │ │ │ ├── p2data0.txt │ │ │ │ ├── p2data1.txt │ │ │ │ ├── p2data2.txt │ │ │ │ ├── graph1.txt │ │ │ │ ├── graph2.txt │ │ │ │ ├── p2data3.txt │ │ │ │ ├── p2data4.txt │ │ │ │ ├── p2data5.txt │ │ │ │ ├── p2data6.txt │ │ │ │ ├── graph4.txt │ │ │ │ └── graph5.txt │ │ │ ├── Epper2019Num10.java │ │ │ ├── Epper1_1.java │ │ │ ├── Epper2019Num1.java │ │ │ ├── Epper2019Num9.java │ │ │ ├── Epper2019Num2.java │ │ │ ├── Epper2019Num4.java │ │ │ ├── Epper2019Num6.java │ │ │ ├── Epper2019Num7.java │ │ │ └── Epper2019Num3.java │ │ │ ├── baekjoon │ │ │ ├── Main_2110.java │ │ │ ├── Main_2557.java │ │ │ ├── Main_1000.java │ │ │ ├── Main_2558.java │ │ │ ├── Main_10951.java │ │ │ ├── Main_10950.java │ │ │ ├── Main_10797.java │ │ │ ├── Main_10952.java │ │ │ ├── Main_10953.java │ │ │ ├── Main_11021.java │ │ │ ├── Main_11022.java │ │ │ ├── Main_10039.java │ │ │ ├── Main_11726.java │ │ │ ├── Main_10430.java │ │ │ ├── Main_1110.java │ │ │ ├── Main_10809.java │ │ │ ├── Main_11729.java │ │ │ ├── Main_9095.java │ │ │ ├── Main_1676.java │ │ │ ├── Main_1026.java │ │ │ ├── Main_1874.java │ │ │ ├── Main_1146.java │ │ │ ├── Main_1874_2.java │ │ │ ├── Main_9012_2.java │ │ │ ├── Main_9084.java │ │ │ ├── Main_1463.java │ │ │ ├── Main_12865.java │ │ │ ├── Main_9093.java │ │ │ ├── Main_2504.java │ │ │ ├── Main_1912.java │ │ │ ├── Main_1158.java │ │ │ ├── Main_9012.java │ │ │ ├── Main_5639.java │ │ │ ├── Main_11650.java │ │ │ ├── Main_1406_2.java │ │ │ ├── Main_1431.java │ │ │ ├── Main_1406.java │ │ │ ├── Main_1260.java │ │ │ └── Main_10828.java │ │ │ ├── leetCode │ │ │ ├── problem │ │ │ │ ├── Solution292.java │ │ │ │ ├── Solution342.java │ │ │ │ ├── Solution977.java │ │ │ │ ├── Solution876.kt │ │ │ │ ├── Solution344.kt │ │ │ │ ├── Solution283.kt │ │ │ │ ├── Solution70.java │ │ │ │ ├── Solution78.py │ │ │ │ ├── ListNode.java │ │ │ │ ├── Solution441.java │ │ │ │ ├── Solution27.java │ │ │ │ ├── Solution287.java │ │ │ │ ├── Solution35.kt │ │ │ │ ├── Solution50.java │ │ │ │ ├── Solution190.java │ │ │ │ ├── Solution9.java │ │ │ │ ├── Solution7.java │ │ │ │ ├── Solution171.java │ │ │ │ ├── Solution258.java │ │ │ │ ├── Solution11.java │ │ │ │ ├── Solution26.java │ │ │ │ ├── Solution96.java │ │ │ │ ├── Solution151.java │ │ │ │ ├── Solution167.kt │ │ │ │ ├── Solution905.java │ │ │ │ ├── Solution119.java │ │ │ │ ├── Solution704.kt │ │ │ │ ├── Solution470.java │ │ │ │ ├── Solution189.java │ │ │ │ ├── Solution100.java │ │ │ │ ├── Solution551.java │ │ │ │ ├── Solution557.kt │ │ │ │ ├── Solution62.java │ │ │ │ ├── Solution275.java │ │ │ │ ├── Solution304.kt │ │ │ │ ├── Solution12.java │ │ │ │ ├── Soultion19.kt │ │ │ │ ├── Solution279.java │ │ │ │ ├── Solution461.java │ │ │ │ ├── Solution278.kt │ │ │ │ ├── TreeNode.java │ │ │ │ ├── soultion_7.cpp │ │ │ │ ├── Solution260.java │ │ │ │ ├── Solution274.java │ │ │ │ ├── Solution66.java │ │ │ │ ├── Solution468.java │ │ │ │ ├── Solution264.java │ │ │ │ ├── Solution705.java │ │ │ │ ├── Solution136.java │ │ │ │ ├── Solution409.java │ │ │ │ ├── Solution442.java │ │ │ │ ├── Solution203.java │ │ │ │ ├── Solution412.java │ │ │ │ ├── Solution3.kt │ │ │ │ ├── Solution125.java │ │ │ │ ├── Solution3Java.java │ │ │ │ ├── Solution28.java │ │ │ │ ├── Solution404.java │ │ │ │ ├── Solution1.java │ │ │ │ ├── Solution1344.java │ │ │ │ ├── Solution436.java │ │ │ │ ├── Solution575.java │ │ │ │ ├── Solution154.java │ │ │ │ ├── Solution14.java │ │ │ │ ├── Solution143.java │ │ │ │ ├── Solution520.java │ │ │ │ ├── Solution567.kt │ │ │ │ ├── Solution202.java │ │ │ │ ├── Solution6.java │ │ │ │ ├── Solution78.java │ │ │ │ ├── Solution435.java │ │ │ │ ├── Solution21.java │ │ │ │ ├── TrieNode.java │ │ │ │ ├── Solution347.java │ │ │ │ ├── Solution621.java │ │ │ │ ├── Solution824.java │ │ │ │ ├── Solution797.java │ │ │ │ ├── Solution309.java │ │ │ │ ├── Solution20.java │ │ │ │ ├── Solution437.java │ │ │ │ ├── Solution67.java │ │ │ │ ├── Solution2.java │ │ │ │ ├── Solution129.java │ │ │ │ ├── Solution983.java │ │ │ │ ├── Solution963.java │ │ │ │ ├── Solution238.java │ │ │ │ ├── Solution107.java │ │ │ │ ├── Solution463.java │ │ │ │ ├── Solution497.java │ │ │ │ ├── Solution957.java │ │ │ │ ├── Solution1286.java │ │ │ │ ├── Solution13.java │ │ │ │ ├── Solution15.java │ │ │ │ └── Solution662.java │ │ │ └── notSolved │ │ │ │ ├── Solution53.java │ │ │ │ ├── Solution8.java │ │ │ │ ├── Solution79.java │ │ │ │ └── Solution1427.java │ │ │ ├── exam │ │ │ ├── programmers │ │ │ │ ├── Programmers_LevelTest2_1.java │ │ │ │ ├── KakaoIntern3.java │ │ │ │ ├── NBPSolution2.java │ │ │ │ ├── NBPSolution3.java │ │ │ │ ├── Programmers_LevelTest3_1.java │ │ │ │ ├── Programmers_LevelTest2_2.java │ │ │ │ ├── HackDay2019Winter1.java │ │ │ │ ├── TechWoowa1.java │ │ │ │ ├── Programmers_LevelTest1_1.java │ │ │ │ ├── NBPSolution1.java │ │ │ │ ├── TechWoowa2.java │ │ │ │ ├── KakaoIntern1.java │ │ │ │ ├── TechWoowa3.java │ │ │ │ ├── Programmers_LevelTest3_2.java │ │ │ │ └── Programmers_LevelTest1_2.java │ │ │ ├── codility │ │ │ │ ├── Naver_AI_HACK_3.java │ │ │ │ ├── Naver_Intern_Codility_3.java │ │ │ │ ├── Naver_Intern_Codility_1.java │ │ │ │ ├── Naver_AI_HACK_2.java │ │ │ │ └── Naver_Intern_Codility_2.java │ │ │ └── hackerRank │ │ │ │ ├── KakaoResult1.java │ │ │ │ └── KakaoResult2.java │ │ │ ├── kickStart │ │ │ ├── RoundF2019Flattening.java │ │ │ ├── RoundD2020AlienPiano.java │ │ │ ├── RoundD2020RecordBreaker.java │ │ │ └── RoundF2019TeachMe2.java │ │ │ ├── programmers │ │ │ ├── hash │ │ │ │ ├── PhoneNumberList.java │ │ │ │ ├── NotCompletionPlayer.java │ │ │ │ ├── Camouflage.java │ │ │ │ └── not_completion_player.cpp │ │ │ ├── completeSearch │ │ │ │ ├── Capet.java │ │ │ │ └── MockTest.java │ │ │ └── sort │ │ │ │ ├── KthNumber.java │ │ │ │ ├── Hindex.java │ │ │ │ └── MostBigNumber.java │ │ │ └── codejam │ │ │ └── april2020 │ │ │ └── round1 │ │ │ └── Solution1.java │ └── kotlin │ │ └── com │ │ └── jyami │ │ └── leetCode │ │ ├── Soultion1545.kt │ │ └── Soultion1106.kt └── test │ └── java │ └── com │ └── jyami │ └── leetCode │ ├── problem │ ├── Solution62Test.java │ ├── Solution171Test.java │ ├── Solution287Test.java │ ├── Solution119Test.java │ ├── Solution13Test.java │ ├── Solution441Test.java │ ├── Solution20Test.java │ ├── Solution409Test.java │ ├── Solution279Test.java │ ├── Solution100Test.java │ ├── Solution520Test.java │ ├── Solution342Test.java │ └── Solution468Test.java │ └── notSolved │ └── Solution332Test.java ├── gradle └── wrapper │ └── gradle-wrapper.properties ├── README.md └── .gitignore /gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.code.style=official -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'Algorithm' 2 | 3 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/hashCode/output/a_example.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 0 5 3 | 0 1 2 3 4 4 | 1 1 5 | 5 6 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/ewhaAlgorithm/testData/graph3.txt: -------------------------------------------------------------------------------- 1 | 3 3 2 | 0 4 11 3 | 6 0 2 4 | 3 2147483647 0 -------------------------------------------------------------------------------- /src/main/java/com/jyami/ewhaAlgorithm/testData/p2data0.txt: -------------------------------------------------------------------------------- 1 | 4 2 | 50 40 10 30 3 | 10 2 5 5 4 | 16 5 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/hashCode/data/a_example.txt: -------------------------------------------------------------------------------- 1 | 6 2 7 2 | 1 2 3 6 5 4 3 | 5 2 2 4 | 0 1 2 3 4 5 | 4 3 1 6 | 0 2 3 5 7 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/ewhaAlgorithm/testData/p2data1.txt: -------------------------------------------------------------------------------- 1 | 8 2 | 1 10 15 40 60 90 100 15 3 | 10 60 30 40 30 20 20 2 4 | 102 5 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/ewhaAlgorithm/testData/p2data2.txt: -------------------------------------------------------------------------------- 1 | 10 2 | 70 20 39 37 7 5 10 8 15 21 3 | 31 10 20 19 4 3 6 8 12 7 4 | 65 5 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/ewhaAlgorithm/Epper2019Num10.java: -------------------------------------------------------------------------------- 1 | package com.jyami.ewhaAlgorithm; 2 | 3 | public class Epper2019Num10 { 4 | } 5 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/ewhaAlgorithm/testData/graph1.txt: -------------------------------------------------------------------------------- 1 | 5 1 2 | 0 4 2147483647 25 12 3 | 4 0 32 11 1 4 | 2147483647 32 0 100 7 5 | 25 11 100 0 60 6 | 12 1 7 60 0 -------------------------------------------------------------------------------- /src/main/java/com/jyami/ewhaAlgorithm/testData/graph2.txt: -------------------------------------------------------------------------------- 1 | 5 2 2 | 0 4 2147483647 25 12 3 | 4 0 32 11 1 4 | 2147483647 32 0 100 7 5 | 25 11 100 0 60 6 | 12 1 7 60 0 -------------------------------------------------------------------------------- /src/main/java/com/jyami/ewhaAlgorithm/testData/p2data3.txt: -------------------------------------------------------------------------------- 1 | 15 2 | 70 20 39 37 7 5 10 8 15 21 32 40 44 12 2 3 | 31 10 20 19 4 3 6 8 12 7 15 26 50 25 14 4 | 77 5 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_2110.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | public class Main_2110 { 4 | public static void main(String[] args) { 5 | 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/ewhaAlgorithm/testData/p2data4.txt: -------------------------------------------------------------------------------- 1 | 20 2 | 40 35 18 4 10 2 70 20 39 37 7 5 10 8 15 21 50 40 10 30 3 | 100 50 45 20 10 5 31 10 20 19 4 3 6 8 12 7 10 2 5 5 4 | 137 5 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/ewhaAlgorithm/testData/p2data5.txt: -------------------------------------------------------------------------------- 1 | 26 2 | 40 35 18 4 10 2 70 20 39 37 7 5 10 8 15 21 50 40 10 30 40 35 18 4 10 2 3 | 10 50 45 20 10 5 31 10 20 19 4 3 6 8 12 7 10 2 5 5 10 50 45 20 10 5 4 | 260 5 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_2557.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | public class Main_2557 { 4 | public static void main(String[] args) { 5 | System.out.println("Hello World!"); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/ewhaAlgorithm/testData/p2data6.txt: -------------------------------------------------------------------------------- 1 | 30 2 | 360 83 59 130 431 67 230 52 93 125 670 892 600 38 48 147 78 256 63 17 120 164 432 35 92 110 22 42 50 323 3 | 40 35 18 4 10 2 70 20 39 37 7 5 10 8 15 21 50 40 10 30 40 35 18 4 10 2 100 50 45 20 4 | 250 5 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution292.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | /** 4 | * Created by jyami on 2020/06/28 5 | */ 6 | public class Solution292 { 7 | public boolean canWinNim(int n) { 8 | return n % 4 != 0; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution342.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | 4 | /** 5 | * Created by jyami on 2020/08/04 6 | */ 7 | public class Solution342 { 8 | public boolean isPowerOfFour(int num) { 9 | return Integer.bitCount(num) == 1 && Integer.bitCount(num - 1) % 2 == 0; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_1000.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Main_1000 { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int a = sc.nextInt(); 9 | int b = sc.nextInt(); 10 | System.out.println(a + b); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_2558.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Main_2558 { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int a = sc.nextInt(); 9 | int b = sc.nextInt(); 10 | System.out.println(a + b); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution977.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import java.util.Arrays; 4 | 5 | public class Solution977 { 6 | public int[] sortedSquares(int[] nums) { 7 | for(int i =0; i List[List[int]]: 6 | result = [] 7 | result.append([]) 8 | for i in range(1, len(nums)+1): 9 | for j in list(combinations(nums, i)): 10 | result.append(list(j)) 11 | return result 12 | 13 | print(Solution().subsets([1,2,3])) -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/ListNode.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | /** 4 | * Created by jyami on 2020/07/21 5 | */ 6 | 7 | public class ListNode { 8 | int val; 9 | ListNode next; 10 | 11 | ListNode() { 12 | } 13 | 14 | ListNode(int val) { 15 | this.val = val; 16 | } 17 | 18 | ListNode(int val, ListNode next) { 19 | this.val = val; 20 | this.next = next; 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_10950.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Main_10950 { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int t = sc.nextInt(); 9 | for (int i = 0; i < t; i++) { 10 | int a = sc.nextInt(); 11 | int b = sc.nextInt(); 12 | System.out.println(a + b); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution441.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | 4 | /** 5 | * Created by jyami on 2020/07/01 6 | */ 7 | public class Solution441 { 8 | public int arrangeCoins(int n) { 9 | long temp = 0; 10 | int increase = 1; 11 | while (temp <= n && temp <= Integer.MAX_VALUE) { 12 | temp += increase; 13 | increase++; 14 | } 15 | return increase - 2; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_10797.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Main_10797 { 6 | public static void main(String args[]){ 7 | Scanner in = new Scanner(System.in); 8 | int num = in.nextInt(); 9 | int wrong = 0; 10 | for(int i=0; i<5; i++){ 11 | if(in.nextInt() == num) 12 | wrong++; 13 | } 14 | System.out.println(wrong); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_10952.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Main_10952 { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | while (true) { 9 | int a = sc.nextInt(); 10 | int b = sc.nextInt(); 11 | if (a == 0 && b == 0) 12 | break; 13 | System.out.println(a + b); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_10953.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Main_10953 { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int t = sc.nextInt(); 9 | for (int i = 0; i < t; i++) { 10 | String[] st = sc.next().split(","); 11 | System.out.println(Integer.valueOf(st[0]) + Integer.valueOf(st[1])); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_11021.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Main_11021 { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int t = sc.nextInt(); 9 | for (int i = 0; i < t; i++) { 10 | int a = sc.nextInt(); 11 | int b = sc.nextInt(); 12 | System.out.printf("Case #%d: %d\n", i + 1, a + b); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution27.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | /** 4 | * Created by jyami on 2020/06/24 5 | */ 6 | public class Solution27 { 7 | public int removeElement(int[] nums, int val) { 8 | int index = 0; 9 | for(int i = 0; i< nums.length; i++){ 10 | if(val != nums[i]){ 11 | nums[index] = nums[i]; 12 | index++; 13 | } 14 | } 15 | return index; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/test/java/com/jyami/leetCode/problem/Solution119Test.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import org.junit.jupiter.params.ParameterizedTest; 4 | import org.junit.jupiter.params.provider.ValueSource; 5 | 6 | import static org.junit.jupiter.api.Assertions.*; 7 | 8 | class Solution119Test { 9 | 10 | @ParameterizedTest 11 | @ValueSource(ints = {1, 2, 3, 4, 5, 6}) 12 | void getRowTest(int i) { 13 | System.out.println(new Solution119().getRow(i)); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution287.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | 4 | import java.util.Arrays; 5 | 6 | /** 7 | * Created by jyami on 2020/06/25 8 | */ 9 | public class Solution287 { 10 | public int findDuplicate(int[] nums) { 11 | Arrays.sort(nums); 12 | for (int i = 0; i < nums.length - 1; i++) { 13 | if(nums[i] == nums[i+1]){ 14 | return nums[i]; 15 | } 16 | } 17 | return 0; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution35.kt: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem 2 | 3 | class Solution35 { 4 | fun searchInsert(nums: IntArray, target: Int): Int { 5 | var low = 0 6 | var high = nums.size - 1 7 | while(low <= high){ 8 | val mid = (low + high) / 2 9 | if(nums[mid] == target) return mid 10 | else if (nums[mid] > target) high = mid - 1 11 | else low = mid + 1 12 | } 13 | return low 14 | } 15 | } -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_11022.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Main_11022 { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int t = sc.nextInt(); 9 | for (int i = 0; i < t; i++) { 10 | int a = sc.nextInt(); 11 | int b = sc.nextInt(); 12 | System.out.printf("Case #%d: %d + %d = %d\n", i + 1, a, b, a + b); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/com/jyami/leetCode/problem/Solution13Test.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import org.junit.jupiter.params.ParameterizedTest; 4 | import org.junit.jupiter.params.provider.ValueSource; 5 | class Solution13Test { 6 | 7 | @ParameterizedTest 8 | @ValueSource(strings = {"III", "IV", "IX", "LVIII", "MCMXCIV"}) 9 | void romanToIntTest(String value) { 10 | int result = new Solution13().romanToInt(value); 11 | System.out.println(result); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/test/java/com/jyami/leetCode/problem/Solution441Test.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import org.junit.jupiter.params.ParameterizedTest; 4 | import org.junit.jupiter.params.provider.ValueSource; 5 | 6 | import static org.junit.jupiter.api.Assertions.*; 7 | 8 | class Solution441Test { 9 | 10 | @ParameterizedTest 11 | @ValueSource(ints = {0, 1, 3, 5, 8}) 12 | void arrangeCoinsTest(int i) { 13 | System.out.println(new Solution441().arrangeCoins(i)); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution50.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | /** 4 | * Created by jyami on 2020/07/17 5 | */ 6 | public class Solution50 { 7 | public double myPow(double x, int n) { 8 | if (n == Integer.MIN_VALUE) return x == 1 || x == -1 ? 1 : 0; 9 | if (n < 0) return 1 / myPow(x, -n); 10 | if (n == 0) return 1; 11 | if (n % 2 == 0) 12 | return myPow(x * x, n / 2); 13 | return myPow(x, n - 1) * x; 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution190.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | /** 4 | * Created by jyami on 2020/07/13 5 | */ 6 | public class Solution190 { 7 | public int reverseBits(int n) { 8 | 9 | int result = 0; 10 | for (int i = 0; i < 32; i++) { 11 | result = result << 1; 12 | if (n != 0) { 13 | result += n % 2; 14 | n = n >>> 1; 15 | } 16 | } 17 | return result; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution9.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | /** 4 | * Created by jyami on 2020/06/17 5 | */ 6 | public class Solution9 { 7 | public boolean isPalindrome(int x) { 8 | String input = String.valueOf(x); 9 | int len = input.length(); 10 | for(int i = 0; i< len/2; i++){ 11 | if(input.charAt(i) != input.charAt(len-1-i)){ 12 | return false; 13 | } 14 | } 15 | return true; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_10039.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Main_10039 { 6 | public static void main(String args[]){ 7 | Scanner in = new Scanner(System.in); 8 | int sum = 0; 9 | for(int i=0; i<5; i++){ 10 | int score = in.nextInt(); 11 | if(score < 40) 12 | sum += 40; 13 | else 14 | sum += score; 15 | } 16 | System.out.println(sum/5); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/com/jyami/leetCode/problem/Solution20Test.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import org.junit.jupiter.params.ParameterizedTest; 4 | import org.junit.jupiter.params.provider.ValueSource; 5 | 6 | import static org.junit.jupiter.api.Assertions.*; 7 | 8 | class Solution20Test { 9 | 10 | @ParameterizedTest 11 | @ValueSource(strings = {"]","()","{}[]()","([)]", "{[]}"}) 12 | void isValidTest(String strings){ 13 | System.out.println(new Solution20().isValid(strings)); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution7.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | 4 | /** 5 | * Created by jyami on 2020/06/17 6 | */ 7 | public class Solution7 { 8 | public int reverse(int x) { 9 | 10 | long result = x % 10; 11 | x = x / 10; 12 | 13 | while (x != 0) { 14 | result = result * 10 + x % 10; 15 | x = x / 10; 16 | } 17 | 18 | return result < Integer.MIN_VALUE || result > Integer.MAX_VALUE ? 0 : (int)result; 19 | } 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/com/jyami/leetCode/problem/Solution409Test.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import org.junit.jupiter.params.ParameterizedTest; 4 | import org.junit.jupiter.params.provider.ValueSource; 5 | 6 | import static org.junit.jupiter.api.Assertions.*; 7 | 8 | class Solution409Test { 9 | 10 | @ParameterizedTest 11 | @ValueSource(strings = {"abccccdd", "aaaccccddd"}) 12 | void longestPalindromeTest(String str) { 13 | System.out.println(new Solution409().longestPalindrome(str)); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/ewhaAlgorithm/Epper2019Num1.java: -------------------------------------------------------------------------------- 1 | package com.jyami.ewhaAlgorithm; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Epper2019Num1 { 6 | private static Scanner sc; 7 | 8 | public static void main(String args[]) { 9 | 10 | sc = new Scanner(System.in); 11 | int year = sc.nextInt(); 12 | if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) { 13 | System.out.println("T"); 14 | } else { 15 | System.out.println("F"); 16 | } 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/test/java/com/jyami/leetCode/problem/Solution279Test.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import org.junit.jupiter.params.ParameterizedTest; 4 | import org.junit.jupiter.params.provider.ValueSource; 5 | 6 | import static org.junit.jupiter.api.Assertions.*; 7 | 8 | class Solution279Test { 9 | 10 | @ParameterizedTest 11 | @ValueSource(ints = {1, 2, 3, 4, 5, 6, 7, 8, 9}) 12 | void numSquaresTest(int i) { 13 | System.out.println("num : " + i + " => " + new Solution279().numSquares(i)); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/com/jyami/leetCode/problem/Solution100Test.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.*; 6 | 7 | class Solution100Test { 8 | 9 | @Test 10 | void isSameTreeTest() { 11 | TreeNode p = new TreeNode(1, new TreeNode(2), null); 12 | TreeNode q = new TreeNode(1, null, new TreeNode(2)); 13 | 14 | boolean sameTree = new Solution100().isSameTree(null, null); 15 | System.out.println(sameTree); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution171.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | /** 4 | * Created by jyami on 2020/08/10 5 | */ 6 | public class Solution171 { 7 | 8 | public static final int NUMBER = 64; 9 | 10 | public int titleToNumber(String s) { 11 | int sum = 0; 12 | int length = s.length() - 1; 13 | for (int i = 0; i <= length; i++) { 14 | int digit = length - i; 15 | sum += (s.charAt(i) - NUMBER) * Math.pow(26, digit); 16 | } 17 | return sum; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution258.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | 4 | /** 5 | * Created by jyami on 2020/07/26 6 | * Article : https://leetcode.com/articles/add-digits/ 7 | */ 8 | public class Solution258 { 9 | public int addDigits(int num) { 10 | while (num / 10 != 0) { 11 | int result = 0; 12 | while (num != 0) { 13 | result += num % 10; 14 | num = num / 10; 15 | } 16 | num = result; 17 | } 18 | return num; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/com/jyami/leetCode/problem/Solution520Test.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import org.junit.jupiter.params.ParameterizedTest; 4 | import org.junit.jupiter.params.provider.ValueSource; 5 | 6 | import static org.junit.jupiter.api.Assertions.*; 7 | 8 | class Solution520Test { 9 | 10 | @ParameterizedTest 11 | @ValueSource(strings = {"A","Ba","bA","GloBal", "USA", "letter"}) 12 | void detectCapitalUseTest(String str) { 13 | boolean b = new Solution520().detectCapitalUse(str); 14 | System.out.println(b); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution11.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | /** 4 | * Created by jyami on 2020/06/26 5 | */ 6 | public class Solution11 { 7 | public int maxArea(int[] height) { 8 | int max = 0; 9 | for (int i = 1; i < height.length; i++) { 10 | for (int j = 0; j < i; j++) { 11 | int s = (i - j) * Math.min(height[i], height[j]); 12 | if (s > max) { 13 | max = s; 14 | } 15 | } 16 | } 17 | return max; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution26.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | /** 4 | * Created by jyami on 2020/06/24 5 | */ 6 | public class Solution26 { 7 | 8 | public int removeDuplicates(int[] nums) { 9 | if(nums.length == 0){ 10 | return 0; 11 | } 12 | int index = 1; 13 | for (int i = 0; i < nums.length - 1; i++) { 14 | if (nums[i] != nums[i + 1]) { 15 | nums[index] = nums[i+1]; 16 | index++; 17 | } 18 | } 19 | return index; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_11726.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Main_11726 { 6 | 7 | public static int fib[] = new int[1001]; 8 | 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | int n = sc.nextInt(); 12 | fib[0] = 1; 13 | fib[1] = 1; 14 | if(n >= 2){ 15 | for(int i=2; i<=n; i++){ 16 | fib[i] = (fib[i-1] + fib[i-2]) % 10007; 17 | } 18 | } 19 | System.out.println(fib[n]); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution96.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | /** 4 | * Created by jyami on 2020/06/24 5 | */ 6 | public class Solution96 { 7 | 8 | public int numTrees(int n) { 9 | int[] arr = new int[n + 1]; 10 | arr[0] = 1; 11 | arr[1] = 1; 12 | for (int i = 2; i <= n; i++) { 13 | int result = 0; 14 | for (int j = 0; j < i; j++) { 15 | result += arr[i - j-1] * arr[j]; 16 | } 17 | arr[i] = result; 18 | } 19 | return arr[n]; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution151.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | 4 | /** 5 | * Created by jyami on 2020/07/16 6 | */ 7 | public class Solution151 { 8 | public String reverseWords(String s) { 9 | String[] strings = s.trim().split(" "); 10 | StringBuilder sb = new StringBuilder(); 11 | for (int i = strings.length - 1; i > 0; i--) { 12 | if(!strings[i].isEmpty()){ 13 | sb.append(strings[i]).append(" "); 14 | } 15 | } 16 | sb.append(strings[0]); 17 | return sb.toString(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution167.kt: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem 2 | 3 | class Solution167 { 4 | fun twoSum(numbers: IntArray, target: Int): IntArray { 5 | var low = 0 6 | var high = numbers.size-1 7 | while(low<=high){ 8 | if(numbers[low]+numbers[high] == target){ 9 | return intArrayOf(low+1, high+1) 10 | } 11 | if(numbers[low]+numbers[high] < target){ 12 | low++ 13 | }else{ 14 | high-- 15 | } 16 | } 17 | return intArrayOf(-1, -1) 18 | } 19 | } -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution905.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | /** 4 | * Created by jyami on 2020/08/21 5 | */ 6 | public class Solution905 { 7 | public int[] sortArrayByParity(int[] A) { 8 | int[] result = new int[A.length]; 9 | int right = 0; 10 | int left = A.length - 1; 11 | for (int i = 0; A.length > i; i++) { 12 | if (A[i] % 2 == 0) { 13 | result[right++] = A[i]; 14 | } else { 15 | result[left--] = A[i]; 16 | } 17 | } 18 | return result; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution119.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * Created by jyami on 2020/08/12 8 | */ 9 | public class Solution119 { 10 | public List getRow(int rowIndex) { 11 | List list = new ArrayList<>(); 12 | for (int i = 0; i <= rowIndex + 1; i++) { 13 | list.add(0, 1); 14 | for (int j = 1; j < i; j++) { 15 | list.set(j, list.get(j) + list.get(j + 1)); 16 | } 17 | } 18 | return list; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution704.kt: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem 2 | 3 | class Solution704 { 4 | fun search(nums: IntArray, target: Int): Int { 5 | var left = 0 6 | var right = nums.size - 1 7 | 8 | while (left <= right) { 9 | val pivot = (left + right) / 2 10 | if (target == nums[pivot]){ 11 | return pivot 12 | } 13 | if(target > nums[pivot]){ 14 | left = pivot + 1 15 | }else{ 16 | right = pivot -1 17 | } 18 | } 19 | return -1 20 | } 21 | } -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution470.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import java.util.Random; 4 | 5 | /** 6 | * Created by jyami on 2020/08/28 7 | */ 8 | public class Solution470 { 9 | 10 | public int rand10() { 11 | int row, col, index; 12 | do { 13 | row = rand7(); 14 | col = rand7(); 15 | index = (row - 1) * 7 + col - 1; 16 | } while (index >= 40); 17 | return 1 + index % 10; 18 | } 19 | 20 | private int rand7() { 21 | Random random = new Random(); 22 | return random.nextInt(7) + 1; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/ewhaAlgorithm/testData/graph4.txt: -------------------------------------------------------------------------------- 1 | 10 1 2 | 0 12 30 16 14 22 2147483647 31 2147483647 5 3 | 12 0 10 2147483647 2147483647 44 2147483647 100 2147483647 2147483647 4 | 30 10 0 35 2147483647 2147483647 7 2147483647 11 25 5 | 16 2147483647 35 0 15 2147483647 77 40 2147483647 9 6 | 14 2147483647 2147483647 15 0 3 2147483647 2 2147483647 1 7 | 22 44 2147483647 2147483647 3 0 17 2147483647 100 70 8 | 2147483647 2147483647 7 77 2147483647 17 0 50 2147483647 3 9 | 31 100 2147483647 40 2 2147483647 50 0 60 2147483647 10 | 2147483647 2147483647 11 2147483647 2147483647 100 2147483647 60 0 32 11 | 5 2147483647 25 9 1 70 3 2147483647 32 0 -------------------------------------------------------------------------------- /src/main/java/com/jyami/ewhaAlgorithm/testData/graph5.txt: -------------------------------------------------------------------------------- 1 | 10 10 2 | 0 12 30 16 14 22 2147483647 31 2147483647 5 3 | 12 0 10 2147483647 2147483647 44 2147483647 100 2147483647 2147483647 4 | 30 10 0 35 2147483647 2147483647 7 2147483647 11 25 5 | 16 2147483647 35 0 15 2147483647 77 40 2147483647 9 6 | 14 2147483647 2147483647 15 0 3 2147483647 2 2147483647 1 7 | 22 44 2147483647 2147483647 3 0 17 2147483647 100 70 8 | 2147483647 2147483647 7 77 2147483647 17 0 50 2147483647 3 9 | 31 100 2147483647 40 2 2147483647 50 0 60 2147483647 10 | 2147483647 2147483647 11 2147483647 2147483647 100 2147483647 60 0 32 11 | 5 2147483647 25 9 1 70 3 2147483647 32 0 -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution189.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | public class Solution189 { 4 | public void rotate(int[] nums, int k) { 5 | int rotate = k % nums.length; 6 | reverse(nums, 0, nums.length-1); 7 | reverse(nums, 0, rotate-1 ); 8 | reverse(nums, rotate, nums.length-1 ); 9 | } 10 | 11 | private void reverse(int[] nums, int start, int end){ 12 | while(start < end){ 13 | int tmp = nums[start]; 14 | nums[start] = nums[end]; 15 | nums[end] = tmp; 16 | start++; end--; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution100.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | 4 | /** 5 | * Created by jyami on 2020/07/14 6 | */ 7 | public class Solution100 { 8 | public boolean isSameTree(TreeNode p, TreeNode q) { 9 | if (p != null && q != null) { 10 | if (p.val != q.val) { 11 | return false; 12 | } else { 13 | return isSameTree(p.left, q.left) && isSameTree(p.right, q.right); 14 | } 15 | } else if (p == null && q == null) { 16 | return true; 17 | } else { 18 | return false; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution551.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | /** 4 | * Created by jyami on 2020/06/28 5 | */ 6 | public class Solution551 { 7 | public boolean checkRecord(String s) { 8 | int a = 0; 9 | int l = 0; 10 | for (char c : s.toCharArray()) { 11 | if (c == 'A') { 12 | a++; 13 | } 14 | if (c == 'L') { 15 | l++; 16 | } else { 17 | l = 0; 18 | } 19 | if (a > 1 || l > 2) 20 | return false; 21 | } 22 | return true; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_10430.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Main_10430 { 6 | public static void main(String args[]){ 7 | // (A+B)%C 8 | // ((A%C) + (B%C))%C 9 | // (A×B)%C 10 | // ((A%C) × (B%C))%C 11 | Scanner in = new Scanner(System.in); 12 | int A = in.nextInt(); 13 | int B = in.nextInt(); 14 | int C = in.nextInt(); 15 | 16 | System.out.println((A+B)%C); 17 | System.out.println(((A%C) + (B%C))%C); 18 | System.out.println((A*B)%C); 19 | System.out.println(((A%C) * (B%C))%C); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution557.kt: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem 2 | 3 | class Solution557 { 4 | fun reverseWords(s: String): String { 5 | return s.split(" ") 6 | .map{reverse(it)} 7 | .joinToString(" ") 8 | } 9 | 10 | fun reverse(s: String): String{ 11 | var array = s.toCharArray() 12 | var low = 0 13 | var high = array.size-1 14 | while(low < high){ 15 | val tmp = array[low] 16 | array[low] = array[high] 17 | array[high] = tmp 18 | low++ 19 | high-- 20 | } 21 | return String(array) 22 | } 23 | } -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution62.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | /** 4 | * Created by jyami on 2020/06/29 5 | */ 6 | public class Solution62 { 7 | public int uniquePaths(int m, int n) { 8 | int[][] map = new int[m][n]; 9 | for (int i = 0; i < m; i++) { 10 | map[i][0] = 1; 11 | } 12 | for (int i = 0; i < n; i++) { 13 | map[0][i] = 1; 14 | } 15 | for (int i = 1; i < m; i++) { 16 | for (int j = 1; j < n; j++) { 17 | map[i][j] = map[i][j-1] + map[i-1][j]; 18 | } 19 | } 20 | return map[m-1][n-1]; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution275.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import java.util.Arrays; 4 | 5 | /** 6 | * Created by jyami on 2020/06/18 7 | */ 8 | public class Solution275 { 9 | public int hIndex(int[] citations) { 10 | Arrays.sort(citations); 11 | 12 | // N-h <= h 13 | // h번 인용한게 h개 이상 있다 14 | int h = 0; 15 | int len = citations.length; 16 | for(int i =0; i) { // 한개 클래스를 생성해서 계속해서 사용하는 로직이기 때문에, dp 사용함 7 | 8 | val dp = Array(matrix.size + 1) { IntArray(matrix[0].size + 1) { 0 } } 9 | init{ 10 | for (i in matrix.indices) { 11 | for (j in matrix[0].indices) { 12 | dp[i+1][j+1] = dp[i][j+1] + dp[i+1][j] + matrix[i][j] - dp[i][j] 13 | } 14 | } 15 | } 16 | 17 | fun sumRegion(row1: Int, col1: Int, row2: Int, col2: Int): Int { 18 | return dp[row2][col2] - dp[row1][col1] + dp[row2][col1] + dp[row1][col2] 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution12.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | /** 4 | * Created by jyami on 2020/06/27 5 | */ 6 | public class Solution12 { 7 | public String intToRoman(int num) { 8 | StringBuilder sb = new StringBuilder(); 9 | int[] nums = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}; 10 | String[] symbol = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"}; 11 | for (int i = 0; i < nums.length; i++) { 12 | while(num >= nums[i]){ 13 | num -= nums[i]; 14 | sb.append(symbol[i]); 15 | } 16 | } 17 | return sb.toString(); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # algorithm 2 | 3 | 알고리즘 문제를 푸는 레포지토리. 4 | 5 | - **백준 알고리즘** : 백준 알고리즘 문제를 해결한 소스코드 입니다. 6 | 7 | 백준 알고리즘 번호에 따라 Main_\[번호] 규칙으로 정렬 8 | 9 | [소스 폴더 보기](src/main/java/com/jyami/baekjoon) 10 | 11 | - **이화여대 알고리즘** : 이화여대 알고리즘 수업 프로그래밍 과제 소스 및 Epper 경진대회 소스 입니다. 12 | 13 | [소스 폴더 보기](src/main/java/com/jyami/ewhaAlgorithm) 14 | 15 | - **킥스타트** : 킥스타트 소스코드입니다 16 | 17 | [소스 폴더 보기](src/main/java/com/jyami/kickStart) 18 | 19 | - **프로그래머스** : 프로그래머스 문제를 해결한 소스코드 입니다. 20 | 21 | [소스 폴더 보기](src/main/java/com/jyami/programmers) 22 | 23 | - **리트코드** : 리트코드 문제를 해결한 소스코드 입니다. 24 | 25 | 백준 알고리즘 번호에 따라 Solution\[번호] 규칙으로 정렬 26 | 27 | [소스 폴더 보기](src/main/java/com/jyami/leetCode) 28 | 29 | . 30 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Soultion19.kt: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem 2 | 3 | class Soultion19 { 4 | fun removeNthFromEnd(head: ListNode?, n: Int): ListNode? { 5 | val nodeArray : Array = arrayOfNulls(30) 6 | var length = 0 7 | var start = head 8 | var current = head 9 | while(current != null){ 10 | nodeArray[length++] = current 11 | current = current.next 12 | } 13 | val removeNode = nodeArray[length - n] 14 | if(length - n > 0 ) { 15 | nodeArray[length - n - 1]?.next = removeNode?.next 16 | }else{ 17 | start = start?.next 18 | } 19 | return start 20 | } 21 | } -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution279.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | /** 4 | * Created by jyami on 2020/06/28 5 | */ 6 | public class Solution279 { 7 | public int numSquares(int n) { 8 | int[] dp = new int[n + 1]; 9 | dp[0] = 0; 10 | int square = 1; 11 | for (int i = 1; i <= n; i++) { 12 | if ((square + 1) * (square + 1) <= i) { 13 | square += 1; 14 | } 15 | int min = Integer.MAX_VALUE; 16 | for (int j = square; j >= 1; j--) { 17 | min = Math.min(min, dp[i - j * j]); 18 | } 19 | dp[i] = min + 1; 20 | } 21 | return dp[n]; 22 | } 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/com/jyami/leetCode/problem/Solution342Test.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.junit.jupiter.params.ParameterizedTest; 5 | import org.junit.jupiter.params.provider.ValueSource; 6 | 7 | import static org.junit.jupiter.api.Assertions.*; 8 | 9 | class Solution342Test { 10 | 11 | @ParameterizedTest 12 | @ValueSource(ints = {0, 1, 4, 5, 16}) 13 | void isPowerOfFourTest(int num) { 14 | System.out.println(new Solution342().isPowerOfFour(num) + " : " + num); 15 | } 16 | 17 | @Test 18 | void test() { 19 | for (int i = 0; i < 100; i++) { 20 | System.out.println(i + " : " + Integer.bitCount(i)); 21 | } 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution461.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | /** 4 | * Created by jyami on 2020/07/05 5 | */ 6 | public class Solution461 { 7 | public int hammingDistance(int x, int y) { 8 | int hamming = 0; 9 | while (x != 0 && y != 0) { 10 | if (x % 2 != y % 2) 11 | hamming++; 12 | y = y / 2; 13 | x = x / 2; 14 | } 15 | while (x != 0) { 16 | if (x % 2 == 1) 17 | hamming++; 18 | x = x / 2; 19 | } 20 | while (y != 0) { 21 | if (y % 2 == 1) 22 | hamming++; 23 | y = y / 2; 24 | } 25 | return hamming; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_1110.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Main_1110 { 6 | 7 | public static void main(String args[]) { 8 | Scanner sc = new Scanner(System.in); 9 | int input = sc.nextInt(); 10 | int count = 0; 11 | 12 | if (input / 10 == 0 && input != 10) { 13 | input = input * 10 + input; 14 | } 15 | 16 | int temp = input; 17 | 18 | do { 19 | int tenDigit = temp % 10; 20 | int oneDigit = (temp / 10 + temp % 10) % 10; 21 | temp = tenDigit * 10 + oneDigit; 22 | count++; 23 | } while (temp != input); 24 | 25 | System.out.println(count); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/exam/programmers/Programmers_LevelTest2_1.java: -------------------------------------------------------------------------------- 1 | package com.jyami.exam.programmers; 2 | 3 | public class Programmers_LevelTest2_1 { 4 | public static void main(String args[]) { 5 | int n = 6; 6 | int solution = new Solution().solution(n); 7 | System.out.println(solution); 8 | 9 | } 10 | 11 | static class Solution { 12 | 13 | public int solution(int n) { 14 | 15 | int result = 1; 16 | 17 | while(n != 1){ 18 | if(n%2 == 0){ 19 | n = n/2; 20 | }else{ 21 | n = n-1; 22 | result ++; 23 | } 24 | } 25 | 26 | return result; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution278.kt: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem 2 | 3 | 4 | 5 | class Solution278: VersionControl { 6 | override fun firstBadVersion(n: Int) : Int { 7 | var good : Int = 1 8 | var bad :Int = n 9 | 10 | while(good < bad){ 11 | val mid: Int = (bad - good) / 2 + good 12 | if( isBadVersion(mid) ){ 13 | bad = mid 14 | } else { 15 | good = mid + 1 16 | } 17 | } 18 | return bad 19 | } 20 | } 21 | 22 | interface VersionControl : Version{ 23 | fun isBadVersion(version: Int) : Boolean{ 24 | return true // api로 제공 25 | } 26 | } 27 | 28 | interface Version{ 29 | fun firstBadVersion(n: Int): Int 30 | } -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/TreeNode.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | /** 4 | * Created by jyami on 2020/07/10 5 | */ 6 | public class TreeNode { 7 | 8 | int val; 9 | TreeNode left; 10 | TreeNode right; 11 | 12 | TreeNode() { 13 | } 14 | 15 | TreeNode(int val) { 16 | this.val = val; 17 | } 18 | 19 | TreeNode(int val, TreeNode left, TreeNode right) { 20 | this.val = val; 21 | this.left = left; 22 | this.right = right; 23 | } 24 | 25 | @Override 26 | public String toString() { 27 | return "TreeNode{" + 28 | "val=" + val + 29 | ", left=" + left + 30 | ", right=" + right + 31 | '}'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/soultion_7.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by mor22 on 2019-11-29. 3 | // 4 | 5 | #include 6 | #include "stdio.h" 7 | 8 | class Solution { 9 | public: 10 | int hello(int a) { 11 | bool first = true; 12 | int result = 0; 13 | while (a != 0) { 14 | int digit = a % 10; 15 | if (first) { 16 | result = digit; 17 | first = false; 18 | } else { 19 | result = result * 10; 20 | result += digit; 21 | } 22 | a = a / 10; 23 | } 24 | return result; 25 | } 26 | }; 27 | 28 | int main() { 29 | Solution solution = Solution(); 30 | int a = solution.hello(1234); 31 | printf("%d\n", a); 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/com/jyami/leetCode/problem/Solution468Test.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import org.junit.jupiter.params.ParameterizedTest; 4 | import org.junit.jupiter.params.provider.ValueSource; 5 | 6 | import static org.junit.jupiter.api.Assertions.*; 7 | 8 | class Solution468Test { 9 | 10 | @ParameterizedTest() 11 | @ValueSource(strings = {"172.16.254.1", "172.16.254.01", "20EE:Fb8:85a3:0:0:8A2E:0370:7334", 12 | "2001:0db8:85a3:0:0:8A2E:0370:7334:", "2001:0db8:85a3:0000:0000:8a2e:0370:7334", "2001:db8:85a3:0:0:8A2E:0370:7334", 13 | "2001:0db8:85a3::8A2E:0370:7334", "02001:0db8:85a3:0000:0000:8a2e:0370:7334"}) 14 | void validIPAddressTest(String ip) { 15 | System.out.println(new Solution468().validIPAddress(ip)); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution260.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | /** 8 | * Created by jyami on 2020/07/23 9 | */ 10 | public class Solution260 { 11 | public int[] singleNumber(int[] nums) { 12 | List list = new ArrayList<>(); 13 | for (int num : nums) { 14 | if (list.contains(num)) { 15 | list.remove(Integer.valueOf(num)); 16 | } else { 17 | list.add(num); 18 | } 19 | } 20 | int[] array = new int[list.size()]; 21 | for (int i = 0; i < list.size(); i++) { 22 | array[i] = list.get(i); 23 | } 24 | return array; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution274.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | 4 | import java.util.Arrays; 5 | 6 | /** 7 | * Created by jyami on 2020/08/11 8 | */ 9 | public class Solution274 { 10 | 11 | // 어느 과학자가 h개의 논문이 h번 이상 인용되고 나머지 논문들은 h번 미만 인용되었다면, 그 과학자의 h-index는 h이다. 12 | // https://m.blog.naver.com/PostView.nhn?blogId=analdong&logNo=140127150175&proxyReferer=https:%2F%2Fwww.google.com%2FLeetcode: 0810 challenge 13 | 14 | public int hIndex(int[] citations) { 15 | Arrays.sort(citations); 16 | 17 | int h = 0; 18 | int i; 19 | for (i = citations.length - 1; i >= 0; i--) { 20 | if (h >= citations[i]) 21 | break; 22 | h++; 23 | } 24 | 25 | return h; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/kotlin/com/jyami/leetCode/Soultion1545.kt: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode 2 | 3 | class Solution1545 { 4 | fun findKthBit(n: Int, k: Int): Char { 5 | var prev = "0" 6 | for(i in 1..n){ 7 | prev = makeS(prev) 8 | println(prev) 9 | } 10 | return prev.toCharArray()[k-1] 11 | } 12 | 13 | fun makeS(prev: String): String{ 14 | return prev + "1" + invert(prev).reversed() 15 | } 16 | 17 | fun invert(str: String): String{ 18 | return str.map{ 19 | if (it == '0'){ 20 | '1' 21 | }else{ 22 | '0' 23 | } 24 | }.toString() 25 | } 26 | } 27 | fun main(){ 28 | val solution1545 = Solution1545() 29 | println(solution1545.findKthBit(4, 11)) 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_10809.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Main_10809 { 6 | public static void main(String args[]) { 7 | Scanner sc = new Scanner(System.in); 8 | char[] word = sc.next().toCharArray(); 9 | //ASCII 문자 a는 97 10 | Integer[] characters = new Integer[26]; 11 | 12 | for (int i = 0; i < word.length; i++) { 13 | int index = word[i] - 97; 14 | if (characters[index] == null) { 15 | characters[index] = i; 16 | } 17 | } 18 | 19 | for (int i = 0; i < characters.length; i++) { 20 | int result = characters[i] == null ? -1 : characters[i]; 21 | System.out.print(result + " "); 22 | } 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution66.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import java.util.Arrays; 4 | 5 | /** 6 | * Created by jyami on 2020/07/06 7 | */ 8 | public class Solution66 { 9 | public int[] plusOne(int[] digits) { 10 | int carry = 1; 11 | int index = digits.length - 1; 12 | while (carry != 0 && index >= 0) { 13 | int result = digits[index] + carry; 14 | digits[index--] = result % 10; 15 | carry = result / 10; 16 | } 17 | if (carry == 1) { 18 | int[] result = new int[digits.length + 1]; 19 | result[0] = 1; 20 | System.arraycopy(digits, 0, result, 1, result.length - 1); 21 | return result; 22 | } 23 | return digits; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution468.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import java.util.regex.Pattern; 4 | 5 | /** 6 | * Created by jyami on 2020/06/17 7 | */ 8 | public class Solution468 { 9 | 10 | 11 | static final String chunkIPv4 = "([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"; 12 | static final Pattern pattenIPv4 = Pattern.compile("^(" + chunkIPv4 + "\\.){3}" + chunkIPv4 + "$"); 13 | 14 | static final String chunkIPv6 = "([0-9a-fA-F]{1,4})"; 15 | static final Pattern pattenIPv6 = Pattern.compile("^(" + chunkIPv6 + "\\:){7}" + chunkIPv6 + "$"); 16 | 17 | public String validIPAddress(String IP) { 18 | return pattenIPv4.matcher(IP).matches() ? "IPv4" : 19 | pattenIPv6.matcher(IP).matches() ? "IPv6" : "Neither"; 20 | } 21 | 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution264.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | /** 4 | * Created by jyami on 2020/07/05 5 | */ 6 | public class Solution264 { 7 | public int nthUglyNumber(int n) { 8 | 9 | int[] dp = new int[n]; 10 | dp[0] = 1; 11 | 12 | int ugly, i2 = 0, i3 = 0, i5 = 0; 13 | 14 | for (int i = 1; i < n; i++) { 15 | ugly = Math.min(Math.min(dp[i2] * 2, dp[i3] * 3), dp[i5] * 5); 16 | dp[i] = ugly; 17 | if (ugly == dp[i2] * 2) ++i2; 18 | if (ugly == dp[i3] * 3) ++i3; 19 | if (ugly == dp[i5] * 5) ++i5; 20 | } 21 | 22 | return dp[n-1]; 23 | } 24 | 25 | public static void main(String[] args) { 26 | System.out.println(new Solution264().nthUglyNumber(10)); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution705.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import java.util.HashSet; 4 | 5 | /** 6 | * Created by jyami on 2020/08/02 7 | */ 8 | public class Solution705 { 9 | 10 | } 11 | 12 | class MyHashSet { 13 | 14 | boolean[] hashSet = new boolean[0]; 15 | 16 | /** 17 | * Initialize your data structure here. 18 | */ 19 | public MyHashSet() { 20 | hashSet = new boolean[1000001]; 21 | } 22 | 23 | public void add(int key) { 24 | hashSet[key] = true; 25 | } 26 | 27 | public void remove(int key) { 28 | hashSet[key] = false; 29 | } 30 | 31 | /** 32 | * Returns true if this set contains the specified element 33 | */ 34 | public boolean contains(int key) { 35 | return hashSet[key]; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution136.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import java.util.Arrays; 4 | 5 | /** 6 | * Created by jyami on 2020/04/08 7 | */ 8 | class Solution136 { 9 | public static void main(String[] args) { 10 | int[] a = {17, 12, 5, -6, 12, 4, 17, -5, 2, -3, 2, 4, 5, 16, -3, -4, 15, 15, -4, -5, -6}; 11 | int i = new Solution136().singleNumber(a); 12 | System.out.println(i); 13 | } 14 | 15 | public int singleNumber(int[] nums) { 16 | Arrays.sort(nums); 17 | for (int i = 0; i < nums.length / 2; i++) { 18 | int num1 = nums[2 * i]; 19 | int num2 = nums[2 * i + 1]; 20 | if (num1 != num2) { 21 | return num1; 22 | } 23 | } 24 | return nums[nums.length - 1]; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution409.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import java.util.HashMap; 4 | 5 | /** 6 | * Created by jyami on 2020/08/14 7 | */ 8 | public class Solution409 { 9 | public int longestPalindrome(String s) { 10 | HashMap hashMap = new HashMap<>(); 11 | int single = 0; 12 | for (char c : s.toCharArray()) { 13 | if (hashMap.containsKey(c)) { 14 | hashMap.put(c, hashMap.get(c) + 1); 15 | } else { 16 | hashMap.put(c, 1); 17 | } 18 | } 19 | for (int num : hashMap.values()) { 20 | if (num % 2 == 1) { 21 | single++; 22 | } 23 | } 24 | return single > 1 ? s.length() - single + 1 : s.length(); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution442.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | /** 8 | * Created by jyami on 2020/08/06 9 | */ 10 | public class Solution442 { 11 | public List findDuplicates(int[] nums) { 12 | List list = new ArrayList<>(); 13 | for (int i = 0; i < nums.length; i++) { 14 | int abs = Math.abs(nums[i]); 15 | if (nums[abs - 1] < 0) { 16 | list.add(abs); 17 | } 18 | nums[abs - 1] = -1 * nums[abs - 1]; 19 | } 20 | return list; 21 | } 22 | 23 | 24 | public static void main(String[] args) { 25 | int[] nums = {4,3,2,7,8,2,3,1}; 26 | System.out.println(new Solution442().findDuplicates(nums)); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/kickStart/RoundF2019Flattening.java: -------------------------------------------------------------------------------- 1 | package com.jyami.kickStart; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Scanner; 6 | 7 | public class RoundF2019Flattening { 8 | public static void main(String args[]) { 9 | Scanner sc = new Scanner(System.in); 10 | 11 | int n = sc.nextInt(); 12 | int k = sc.nextInt(); 13 | // int testInput = sc.nextInt(); 14 | // 15 | // for(int i=0; i list = new ArrayList<>(); 20 | 21 | // for(int i=0; i) 22 | 23 | } 24 | } 25 | 26 | class NumberGroup{ 27 | int groupSize; 28 | int count; 29 | 30 | public NumberGroup(int groupSize, int count) { 31 | this.groupSize = groupSize; 32 | this.count = count; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/notSolved/Solution8.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.notSolved; 2 | 3 | import java.util.regex.Matcher; 4 | import java.util.regex.Pattern; 5 | 6 | /** 7 | * Created by jyami on 2020/06/25 8 | */ 9 | public class Solution8 { 10 | 11 | static Pattern pattern = Pattern.compile("(-?\\d+)"); 12 | 13 | public int myAtoi(String str) { 14 | str = str.trim().split(" ")[0]; 15 | Matcher matcher = pattern.matcher(str); 16 | if (matcher.find()) { 17 | long l = Long.parseLong(matcher.group()); 18 | if (l > Integer.MAX_VALUE) 19 | return Integer.MAX_VALUE; 20 | else if(lnum) min=num; 25 | } 26 | return min; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution412.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * Created by jyami on 2020/08/26 8 | */ 9 | public class Solution412 { 10 | public List fizzBuzz(int n) { 11 | List result = new ArrayList<>(); 12 | for (int i = 1; i <= n; i++) { 13 | if (i % 15 == 0) 14 | result.add("FizzBuzz"); 15 | else if (i % 3 == 0) 16 | result.add("Fizz"); 17 | else if (i % 5 == 0) 18 | result.add("Buzz"); 19 | else 20 | result.add(Integer.toString(i)); 21 | } 22 | return result; 23 | } 24 | 25 | public static void main(String[] args) { 26 | System.out.println(new Solution412().fizzBuzz(15)); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution3.kt: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem 2 | 3 | class Solution3 { 4 | fun lengthOfLongestSubstring(s: String): Int { 5 | var max = 0 6 | for (i in s.indices) { 7 | val maxLength = maxLength(s, i) 8 | if(max < maxLength){ 9 | max = maxLength 10 | } 11 | } 12 | return max 13 | } 14 | 15 | private fun maxLength(s: String, startIdx: Int): Int { 16 | val charArray = BooleanArray(128) { false } 17 | var idx = startIdx 18 | var max = 0 19 | while (idx < s.length) { 20 | val code = s[idx++].code 21 | if(charArray[code]){ 22 | return max 23 | }else{ 24 | charArray[code] = true 25 | } 26 | max++ 27 | } 28 | return max 29 | } 30 | } -------------------------------------------------------------------------------- /src/main/java/com/jyami/exam/programmers/KakaoIntern3.java: -------------------------------------------------------------------------------- 1 | package com.jyami.exam.programmers; 2 | 3 | import java.util.Stack; 4 | 5 | public class KakaoIntern3 { 6 | public static void main(String args[]) { 7 | String[] user_id = {"frodo", "fradi", "crodo", "abc123", "frodoc"}; 8 | String[] banned_id = {"fr*d*", "abc1**"}; 9 | 10 | Solution solution = new Solution(); 11 | int solution1 = solution.solution(user_id, banned_id); 12 | System.out.println(solution1); 13 | } 14 | 15 | static class Solution { 16 | public int solution(String[] user_id, String[] banned_id) { 17 | int answer = 0; 18 | for(String user : banned_id){ 19 | 20 | } 21 | return answer; 22 | } 23 | 24 | private void checkDupleUser(String[] userId, String bann){ 25 | 26 | } 27 | } 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution125.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | 4 | /** 5 | * Created by jyami on 2020/08/04 6 | */ 7 | public class Solution125 { 8 | 9 | public boolean isPalindrome(String s) { 10 | int low = 0; 11 | int high = s.length() - 1; 12 | 13 | while (low <= high && low < s.length() && high >= 0) { 14 | if(!Character.isLetterOrDigit(s.charAt(low))){ 15 | low++; 16 | continue; 17 | } 18 | if (!Character.isLetterOrDigit(s.charAt(high))) { 19 | high--; 20 | continue; 21 | } 22 | if (Character.toLowerCase(s.charAt(high)) != Character.toLowerCase(s.charAt(low))) 23 | return false; 24 | low++; 25 | high--; 26 | } 27 | return true; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution3Java.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | public class Solution3Java { 4 | public int lengthOfLongestSubstring(String s) { 5 | int max = 0; 6 | for (int i = 0; i < s.length(); i++) { 7 | int result = maxLength(s, i); 8 | max = Math.max(max, result); 9 | } 10 | return max; 11 | } 12 | 13 | private int maxLength(String s, int startIndex) { 14 | boolean[] charArray = new boolean[128]; 15 | int index = startIndex; 16 | int count = 0; 17 | while(index < s.length()){ 18 | char c = s.charAt(index++); 19 | if(charArray[c]){ 20 | return count; 21 | }else{ 22 | charArray[c] = true; 23 | } 24 | count++; 25 | } 26 | return count; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution28.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | /** 4 | * Created by jyami on 2020/06/24 5 | */ 6 | public class Solution28 { 7 | 8 | static String input; 9 | static int needleLen; 10 | 11 | public int strStr(String haystack, String needle) { 12 | input = needle; 13 | needleLen = needle.length(); 14 | byte[] bytes = haystack.getBytes(); 15 | for (int i = 0; i <= haystack.length() - needleLen; i++) { 16 | if (checkIsSame(bytes, i)) { 17 | return i; 18 | } 19 | } 20 | return -1; 21 | } 22 | 23 | public boolean checkIsSame(byte[] bytes, int start) { 24 | for(int i = 0; i 0) { 14 | if (candies > nowCandies) { 15 | nowPeople[index] += nowCandies; 16 | } else { 17 | nowPeople[index] += candies; 18 | } 19 | index = (index + 1) % num_people; 20 | candies -= nowCandies++; 21 | } 22 | return nowPeople; 23 | } 24 | 25 | 26 | public static void main(String[] args) { 27 | System.out.println(Arrays.toString(new Solution575().distributeCandies(10, 3))); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/exam/programmers/NBPSolution2.java: -------------------------------------------------------------------------------- 1 | package com.jyami.exam.programmers; 2 | 3 | import java.util.*; 4 | 5 | /** 6 | * Created by jyami on 2020/07/01 7 | */ 8 | public class NBPSolution2 { 9 | 10 | public int solution(int[] arr) { 11 | Map map = new HashMap<>(); 12 | List duplication = new ArrayList<>(); 13 | for (int i = 0; i < arr.length; i++) { 14 | if (map.containsKey(arr[i])) 15 | duplication.add(i - map.get(arr[i])); 16 | map.put(arr[i], i); 17 | } 18 | if (duplication.isEmpty()) 19 | return -1; 20 | return Collections.min(duplication); 21 | } 22 | 23 | public static void main(String[] args) { 24 | int[] arr = {2, 1, 3, 1, 4, 1, 1, 3}; 25 | // int[] arr = {1, 2, 3}; 26 | int solution = new NBPSolution2().solution(arr); 27 | System.out.println(solution); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution154.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | /** 4 | * Created by jyami on 2020/07/25 5 | */ 6 | public class Solution154 { 7 | public int findMin(int[] nums) { 8 | int low = 0; 9 | int high = nums.length - 1; 10 | while (low < high) { 11 | int mid = (low + high) / 2; 12 | if (nums[mid] > nums[high]) { 13 | low = mid + 1; 14 | } else if (nums[mid] < nums[low]) { 15 | high = mid; 16 | low++; 17 | } else { 18 | high--; 19 | } 20 | } 21 | return nums[low]; 22 | } 23 | 24 | public static void main(String[] args) { 25 | // int[] arr = {3, 1}; 26 | int[] arr = {4, 5, 6, 7, 0, 1, 2}; 27 | // int[] arr = {2,2,2,2}; 28 | int min = new Solution154().findMin(arr); 29 | System.out.println(min); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution14.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | /** 4 | * Created by jyami on 2020/06/18 5 | */ 6 | public class Solution14 { 7 | public String longestCommonPrefix(String[] strs) { 8 | int minLength; 9 | if(strs.length == 0){ 10 | minLength = 0; 11 | }else{ 12 | minLength = strs[0].length(); 13 | } 14 | for(String str : strs){ 15 | if( str.length() < minLength ){ 16 | minLength = str.length(); 17 | } 18 | } 19 | StringBuilder sb = new StringBuilder(); 20 | for(int i =0; i < minLength; i++){ 21 | char c = strs[0].charAt(i); 22 | for(String str: strs){ 23 | if(c != str.charAt(i)){ 24 | return sb.toString(); 25 | } 26 | } 27 | sb.append(c); 28 | } 29 | return sb.toString(); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_11729.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | import java.io.*; 4 | 5 | public class Main_11729 { 6 | 7 | public static StringBuilder sb = new StringBuilder(); 8 | public static int count =0; 9 | 10 | public static void main(String[] args) throws IOException{ 11 | 12 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 13 | 14 | int number = Integer.parseInt(br.readLine()); 15 | 16 | hanoi(number, 1,3,2); 17 | System.out.println(count); 18 | System.out.println(sb.toString()); 19 | 20 | } 21 | 22 | public static void hanoi(int size,int from, int to, int by){ 23 | if(size == 1){ 24 | sb.append(from+ " " + to+"\n"); 25 | count++; 26 | }else{ 27 | hanoi(size-1, from, by, to); 28 | count++; 29 | sb.append(from+ " " + to+"\n"); 30 | hanoi(size-1, by, to, from); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/ewhaAlgorithm/Epper2019Num9.java: -------------------------------------------------------------------------------- 1 | package com.jyami.ewhaAlgorithm; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Epper2019Num9 { 6 | 7 | private static Scanner sc; 8 | 9 | public static void main(String args[]){ 10 | sc = new Scanner(System.in); 11 | 12 | int num = sc.nextInt(); 13 | 14 | int[][] arr = new int[num][num]; 15 | 16 | for(int i =0 ; i0 ; i--){ 23 | for(int j =0 ; jb){ 27 | arr[i-1][j] += a ; 28 | }else{ 29 | arr[i-1][j] += b; 30 | } 31 | } 32 | } 33 | 34 | System.out.println(arr[0][0]); 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution143.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import java.util.Stack; 4 | 5 | /** 6 | * Created by jyami on 2020/08/20 7 | */ 8 | public class Solution143 { 9 | 10 | public void reorderList(ListNode head) { 11 | if (head == null) 12 | return; 13 | Stack stack = new Stack<>(); 14 | ListNode tmp = head; 15 | while (tmp != null) { 16 | stack.push(tmp); 17 | tmp = tmp.next; 18 | } 19 | tmp = head; 20 | ListNode next; 21 | while (true) { 22 | ListNode pop = stack.pop(); 23 | next = tmp.next; 24 | if (pop == tmp || pop == next) { 25 | pop.next = null; 26 | break; 27 | } 28 | tmp.next = pop; 29 | pop.next = next; 30 | tmp = next; 31 | } 32 | stack.clear(); 33 | System.out.println(head); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution520.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import java.util.function.Predicate; 4 | 5 | /** 6 | * Created by jyami on 2020/08/01 7 | */ 8 | public class Solution520 { 9 | public boolean detectCapitalUse(String word) { 10 | Predicate characterFilter; 11 | 12 | if(word.length() == 1) 13 | return true; 14 | 15 | if(Character.isUpperCase(word.charAt(0))){ 16 | if(Character.isUpperCase(word.charAt(1))) 17 | characterFilter = Character::isUpperCase; 18 | else{ 19 | characterFilter = Character::isLowerCase; 20 | } 21 | }else { 22 | characterFilter = Character::isLowerCase; 23 | } 24 | 25 | for(int i = 1; i< word.length(); i++){ 26 | if(!characterFilter.test(word.charAt(i))){ 27 | return false; 28 | } 29 | } 30 | return true; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/exam/programmers/NBPSolution3.java: -------------------------------------------------------------------------------- 1 | package com.jyami.exam.programmers; 2 | 3 | import java.util.Collections; 4 | import java.util.HashMap; 5 | 6 | /** 7 | * Created by jyami on 2020/07/01 8 | */ 9 | public class NBPSolution3 { 10 | public int solution(int[] p) { 11 | HashMap map = new HashMap<>(); 12 | 13 | for (int i = 0; i < p.length; i++) { 14 | if (!map.containsKey(p[i])) { 15 | map.put(p[i], 1); 16 | } else { 17 | map.put(p[i], map.get(p[i]) + 1); 18 | } 19 | } 20 | 21 | Integer max = Collections.max(map.values()); 22 | Integer sum = map.values().stream() 23 | .reduce(0, Integer::sum); 24 | 25 | return sum - max; 26 | } 27 | 28 | public static void main(String[] args) { 29 | int[] arr = {103,101,103,103,101,102,100,100,101,104}; 30 | System.out.println(new NBPSolution3().solution(arr)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_9095.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Scanner; 6 | 7 | public class Main_9095 { 8 | public static void main(String args[]) { 9 | 10 | Scanner s = new Scanner(System.in); 11 | 12 | int num = s.nextInt(); 13 | int max = 0; 14 | List list = new ArrayList<>(); 15 | 16 | 17 | for (int i = 0; i < num; i++) { 18 | int input = s.nextInt(); 19 | list.add(input); 20 | if (input > max) 21 | max = input; 22 | } 23 | 24 | int dp[] = new int[max + 1]; 25 | 26 | dp[1] = 1; 27 | dp[2] = 2; 28 | dp[3] = 4; 29 | 30 | for (int i = 4; i <= max; i++) { 31 | dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3]; 32 | } 33 | 34 | for (Integer integer : list) { 35 | System.out.println(dp[integer]); 36 | } 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/ewhaAlgorithm/Epper2019Num2.java: -------------------------------------------------------------------------------- 1 | package com.jyami.ewhaAlgorithm; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Epper2019Num2 { 6 | private static Scanner sc; 7 | 8 | public static void main(String[] args) { 9 | 10 | sc = new Scanner(System.in); 11 | 12 | 13 | int number = sc.nextInt(); 14 | int[] score = new int[number]; 15 | int sum = 0; 16 | double avg = 0; 17 | int overPeople = 0; 18 | 19 | for (int i = 0; i < number; i++) { 20 | score[i] = sc.nextInt(); 21 | sum += score[i]; 22 | } 23 | 24 | 25 | avg = (double) sum / (double) number; 26 | 27 | for (int i = 0; i < number; i++) { 28 | if (score[i] > avg) { 29 | overPeople += 1; 30 | } 31 | } 32 | 33 | double result = (double) overPeople / (double) number * 100; 34 | 35 | System.out.printf("%.3f", result); 36 | System.out.println("%"); 37 | 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/ewhaAlgorithm/Epper2019Num4.java: -------------------------------------------------------------------------------- 1 | package com.jyami.ewhaAlgorithm; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Epper2019Num4 { 6 | private static Scanner sc; 7 | 8 | public static void main(String args[]) { 9 | sc = new Scanner(System.in); 10 | 11 | int row = sc.nextInt(); 12 | int col = sc.nextInt(); 13 | 14 | int count = 0; 15 | if (row < col) { 16 | row--; 17 | if (row == 0) { 18 | System.out.println(count); 19 | return; 20 | } 21 | count++; 22 | } 23 | while (true) { 24 | col--; 25 | if (col == 0) { 26 | System.out.println(count); 27 | return; 28 | } 29 | count++; 30 | row--; 31 | if (row == 0) { 32 | System.out.println(count); 33 | return; 34 | } 35 | count++; 36 | } 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/programmers/hash/PhoneNumberList.java: -------------------------------------------------------------------------------- 1 | package com.jyami.programmers.hash; 2 | 3 | /** 4 | * Created by jyami on 2020/01/05 5 | * 해시 - 전화번호 목록 6 | * https://programmers.co.kr/learn/courses/30/lessons/42577?language=java 7 | */ 8 | public class PhoneNumberList { 9 | 10 | public static void main(String[] args) { 11 | Solution solution = new Solution(); 12 | String[] phoneBook = {"119", "97674223", "1195524421"}; 13 | solution.solution(phoneBook); 14 | System.out.println(); 15 | } 16 | 17 | static class Solution { 18 | public boolean solution(String[] phoneBook) { 19 | for(int i =0; i a = new ArrayList<>(); 16 | List b = new ArrayList<>(); 17 | int sum = 0; 18 | 19 | for (int i = 0; i < arrSize; i++) { 20 | a.add(scanner.nextInt()); 21 | } 22 | 23 | for (int i = 0; i < arrSize; i++) { 24 | b.add(scanner.nextInt()); 25 | } 26 | 27 | a.sort(Comparator.naturalOrder()); 28 | b.sort(Comparator.reverseOrder()); 29 | 30 | for (int i = 0; i < arrSize; i++) { 31 | int mult = a.get(i) * b.get(i); 32 | sum += mult; 33 | } 34 | 35 | System.out.println(sum); 36 | 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution567.kt: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem 2 | 3 | class Solution567 { 4 | fun checkInclusion(s1: String, s2: String): Boolean { 5 | for (i in 0..(s2.length - s1.length)) { 6 | if (findLength(s1, s2, i)) { 7 | return true 8 | } 9 | } 10 | return false 11 | } 12 | 13 | private fun findLength(s1: String, s2: String, startIdx: Int): Boolean { 14 | val array = IntArray(26) 15 | for (i in s1.indices) { 16 | array[s1[i].toInt() - 97]++ 17 | } 18 | for (i in startIdx until startIdx + s1.length) { 19 | val charIdx = s2[i].toInt() - 97 20 | if (array[charIdx] == 0) { 21 | return false 22 | }else{ 23 | array[charIdx]-- 24 | } 25 | } 26 | for(i in s1.indices){ 27 | if(array[s1[i].toInt() - 97] != 0){ 28 | return false 29 | } 30 | } 31 | return true 32 | } 33 | } -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution202.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | /** 7 | * Created by jyami on 2020/04/08 8 | */ 9 | public class Solution202 { 10 | public static void main(String[] args) { 11 | boolean happy = new Solution202().isHappy(19); 12 | System.out.println(happy); 13 | } 14 | 15 | public boolean isHappy(int n) { 16 | Set integers = new HashSet<>(); 17 | int num = result(n); 18 | while(num != 1){ 19 | if(integers.contains(num)){ 20 | return false; 21 | } 22 | integers.add(num); 23 | num = result(num); 24 | } 25 | return true; 26 | } 27 | 28 | public int result(int n){ 29 | int temp = n; 30 | int sum = 0; 31 | while (temp != 0) { 32 | int num = temp % 10; 33 | sum += Math.pow(num, 2); 34 | temp = temp / 10; 35 | } 36 | return sum; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/ewhaAlgorithm/Epper2019Num6.java: -------------------------------------------------------------------------------- 1 | package com.jyami.ewhaAlgorithm; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Epper2019Num6 { 6 | 7 | private static Scanner sc; 8 | 9 | public static void main(String args[]){ 10 | sc = new Scanner(System.in); 11 | 12 | int x = sc.nextInt(); 13 | int y = sc.nextInt(); 14 | double y2=0; 15 | double x2=0; 16 | 17 | double width = 250 * 250 /2; 18 | 19 | if(x + y == 250){ 20 | x2 = 250 - width/y; 21 | 22 | y2 = 250 - width/x; 23 | 24 | if(x2 < 0){ 25 | x2 =0; 26 | }else{ 27 | y2 =0; 28 | } 29 | 30 | }else{ // ���� �ִ� ��� 31 | if(y == 0){ 32 | y2 = width/(250-x); 33 | x2 = 250 - y2; 34 | }else{ 35 | x2 = width/(250-y); 36 | y2 = 250 - x2; 37 | } 38 | } 39 | 40 | System.out.printf("%.2f %.2f", x2, y2); 41 | 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution6.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | /** 4 | * Created by jyami on 2020/06/25 5 | */ 6 | public class Solution6 { 7 | public String convert(String s, int numRows) { 8 | 9 | if(numRows == 1){ 10 | return s; 11 | } 12 | StringBuilder sb = new StringBuilder(); 13 | int len = s.length(); 14 | for(int i =0; i> subsets(int[] nums) { 11 | List> resultList = new ArrayList<>(); 12 | resultList.add(new ArrayList<>()); 13 | for (int num : nums) { 14 | List> additionalList = new ArrayList<>(); 15 | for (List subList : resultList) { 16 | List sub = new ArrayList<>(subList); 17 | sub.add(num); 18 | additionalList.add(sub); 19 | } 20 | resultList.addAll(additionalList); 21 | } 22 | return resultList; 23 | } 24 | 25 | public static void main(String[] args) { 26 | 27 | int[] nums = {1,2,3,4}; 28 | List> subsets = new Solution78().subsets(nums); 29 | System.out.println(subsets); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution435.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import java.util.Arrays; 4 | import java.util.Comparator; 5 | 6 | /** 7 | * Created by jyami on 2020/08/16 8 | */ 9 | public class Solution435 { 10 | public int eraseOverlapIntervals(int[][] intervals) { 11 | if(intervals == null || intervals.length == 0) return 0; 12 | int result = 0; 13 | Arrays.sort(intervals, Comparator.comparingInt(a -> a[0])); 14 | int end = intervals[0][1]; 15 | for (int i = 1; i < intervals.length; i++) { 16 | if (intervals[i][0] < end) { 17 | end = Math.min(end, intervals[i][1]); 18 | result++; 19 | } else { 20 | end = intervals[i][1]; 21 | } 22 | } 23 | return result; 24 | } 25 | 26 | public static void main(String[] args) { 27 | int[][] intervals = {{1, 2}, {1, 2}, {1, 2}}; 28 | int i = new Solution435().eraseOverlapIntervals(intervals); 29 | System.out.println(i); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution21.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | /** 4 | * Created by jyami on 2020/06/18 5 | */ 6 | public class Solution21 { 7 | public ListNode mergeTwoLists(ListNode l1, ListNode l2) { 8 | 9 | ListNode head = new ListNode(); 10 | ListNode line = head; 11 | while (l1 != null || l2 != null) { 12 | if(l1 == null){ 13 | line.next = l2; 14 | line = l2; 15 | l2 = l2.next; 16 | }else if(l2 == null){ 17 | line.next = l1; 18 | line = l1; 19 | l1 = l1.next; 20 | }else{ 21 | if (l2.val > l1.val) { 22 | line.next = l1; 23 | line = l1; 24 | l1 = l1.next; 25 | } else { 26 | line.next = l2; 27 | line = l2; 28 | l2 = l2.next; 29 | } 30 | } 31 | } 32 | return head.next; 33 | } 34 | 35 | 36 | } 37 | 38 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_1874.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | import java.util.Scanner; 4 | import java.util.Stack; 5 | 6 | public class Main_1874 { 7 | 8 | public static void main(String args[]) { 9 | Scanner in = new Scanner(System.in); 10 | StringBuilder stringBuilder = new StringBuilder(); 11 | Stack stack = new Stack(); 12 | 13 | int arrsize = in.nextInt(); 14 | int[] arr = new int[arrsize]; 15 | 16 | for (int i = 0; i < arrsize; i++) { 17 | arr[i] = in.nextInt(); 18 | } 19 | int index = 0; 20 | for (int i = 0; i < arrsize; i++) { 21 | stack.push(i + 1); 22 | stringBuilder.append("+\n"); 23 | while (!(stack.isEmpty()) && stack.peek() == arr[index]) { 24 | stack.pop(); 25 | stringBuilder.append("-\n"); 26 | index++; 27 | } 28 | } 29 | if (!stack.isEmpty()) 30 | System.out.println("NO"); 31 | else 32 | System.out.print(stringBuilder); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/exam/programmers/Programmers_LevelTest2_2.java: -------------------------------------------------------------------------------- 1 | package com.jyami.exam.programmers; 2 | 3 | import java.util.EmptyStackException; 4 | import java.util.Stack; 5 | 6 | public class Programmers_LevelTest2_2 { 7 | 8 | public static void main(String args[]) { 9 | String a = "(())()"; 10 | boolean solution = new Solution().solution(a); 11 | System.out.println(solution); 12 | } 13 | 14 | static class Solution { 15 | 16 | boolean solution(String s) { 17 | 18 | Stack stack = new Stack(); 19 | 20 | for (char c : s.toCharArray()) { 21 | if (c == '(') { 22 | stack.push(c); 23 | } else { 24 | try { 25 | stack.pop(); 26 | } catch (EmptyStackException e) { 27 | return false; 28 | } 29 | } 30 | } 31 | if (!stack.empty()) { 32 | return false; 33 | } 34 | return true; 35 | } 36 | 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/TrieNode.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.Objects; 6 | import java.util.stream.Collectors; 7 | 8 | /** 9 | * Created by jyami on 2020/08/05 10 | */ 11 | public class TrieNode { 12 | private TrieNode[] link; 13 | 14 | private boolean isEnd = false; 15 | 16 | public TrieNode() { 17 | this.link = new TrieNode[26]; 18 | } 19 | 20 | public TrieNode get(char c) { 21 | return link[c - 'a']; 22 | } 23 | 24 | public void put(char c, TrieNode node) { 25 | link[c - 'a'] = node; 26 | } 27 | 28 | public boolean isEnd() { 29 | return isEnd; 30 | } 31 | 32 | public void setEnd() { 33 | isEnd = true; 34 | } 35 | 36 | public boolean containsKey(char ch) { 37 | return link[ch - 'a'] != null; 38 | } 39 | 40 | public List getList() { 41 | return Arrays.stream(link) 42 | .filter(Objects::nonNull) 43 | .collect(Collectors.toList()); 44 | } 45 | 46 | } -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/notSolved/Solution79.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.notSolved; 2 | 3 | /** 4 | * Created by jyami on 2020/07/22 5 | */ 6 | public class Solution79 { 7 | 8 | public boolean exist(char[][] board, String word) { // 4 x 2 9 | int i = 0, j = 0; 10 | boolean[][] visited = new boolean[board.length][board[0].length]; 11 | for (i = 0; i < board.length; i++) { 12 | for (j = 0; j < board[0].length; j++) { 13 | if (board[i][j] == word.charAt(0)) { 14 | break; 15 | } 16 | } 17 | } 18 | visited[i][j] = true; 19 | dfs(visited, word, board, i, j, 0); 20 | return true; 21 | } 22 | 23 | public void dfs(boolean[][] visited, String word, char[][] board, int i, int j, int length) { 24 | if (length == word.length()) { 25 | return; 26 | } 27 | visited[i + 1][j] = true; 28 | // dfs(visited, word, board,); 29 | 30 | visited[i][j] = false; 31 | if (board[i][j] == word.charAt(++length)) { 32 | 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/exam/hackerRank/KakaoResult1.java: -------------------------------------------------------------------------------- 1 | package com.jyami.exam.hackerRank; 2 | 3 | 4 | /** 5 | * Created by jyami on 2020/06/29 6 | */ 7 | public class KakaoResult1 { 8 | 9 | /* 10 | * Complete the 'solution' function below. 11 | * 12 | * The function is expected to return a LONG_INTEGER. 13 | * The function accepts STRING s as parameter. 14 | */ 15 | 16 | public static int CHARACTER_DIFF = 26; // A = 65 , Z = 90 17 | 18 | public static long solution(String s) { 19 | long sum = 0; 20 | int from = 'A'; 21 | for (char to : s.toCharArray()) { 22 | sum += getDistance(from, to); 23 | from = to; 24 | } 25 | return sum; 26 | } 27 | 28 | public static int getDistance(int from, int to) { 29 | int rightDistance = Math.abs(from - to); 30 | int leftDistance = CHARACTER_DIFF - rightDistance; 31 | return Math.min(rightDistance, leftDistance); 32 | } 33 | 34 | public static void main(String[] args) { 35 | long bza = solution("AZGB"); 36 | System.out.println(bza); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/exam/programmers/HackDay2019Winter1.java: -------------------------------------------------------------------------------- 1 | package com.jyami.exam.programmers; 2 | 3 | public class HackDay2019Winter1 { 4 | public static void main(String args[]) { 5 | // int[] input = {2, 1, 3}; 6 | // int[] input = {1, 2, 3}; 7 | // int[] input = {3, 2, 3, 6, 4, 5}; 8 | int[] input = {3, 2, 1}; 9 | 10 | int solution = new Solution().solution(input); 11 | System.out.println(solution); 12 | } 13 | 14 | static class Solution { 15 | public int solution(int grade[]) { 16 | 17 | int result = 0; 18 | 19 | for (int i = grade.length - 2; i >= 0; i--) { 20 | if (grade[i + 1] < grade[i]) { 21 | result += grade[i] - grade[i + 1]; 22 | grade[i] = grade[i + 1]; 23 | 24 | } 25 | } 26 | // for (int i = 1; i < grade.length; i++) { 27 | // if (grade[i - 1] > grade[i]) { 28 | // result += grade[i - 1] - grade[i]; 29 | // } 30 | // } 31 | 32 | return result; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution347.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import java.util.*; 4 | 5 | /** 6 | * Created by jyami on 2020/07/17 7 | */ 8 | public class Solution347 { 9 | public int[] topKFrequent(int[] nums, int k) { 10 | Arrays.sort(nums); 11 | PriorityQueue pq = new PriorityQueue<>((o1, o2) -> Integer.compare(o2[0], o1[0])); 12 | int count = 0; 13 | for (int i = 0; i < nums.length - 1; i++) { 14 | count++; 15 | if (nums[i] != nums[i + 1]) { 16 | pq.add(new int[]{count, nums[i]}); 17 | count = 0; 18 | } 19 | } 20 | pq.add(new int[]{++count, nums[nums.length-1]}); 21 | int[] result = new int[k]; 22 | for (int i = 0; i < k; i++) { 23 | result[i] = pq.poll()[1]; 24 | } 25 | return result; 26 | } 27 | 28 | public static void main(String[] args) { 29 | int[] nums = {1,2,2}; 30 | int k = 1; 31 | int[] ints = new Solution347().topKFrequent(nums, k); 32 | System.out.println(Arrays.toString(ints)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_1146.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStreamReader; 6 | 7 | public class Main_1146 { 8 | public static void main(String[] args) throws IOException { 9 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 10 | int n = Integer.parseInt(br.readLine()); 11 | int arr[][] = new int[n][3]; 12 | 13 | for (int i = 0; i < n; i++) { 14 | String[] input = br.readLine().split(" "); 15 | for (int j = 0; j < 3; j++) { 16 | arr[i][j] = Integer.parseInt(input[j]); 17 | } 18 | } 19 | int index[][] = new int[n][3]; 20 | int result[][] = new int[n][3]; 21 | for (int i = 0; i < n; i++) { 22 | result[0][i] = arr[0][i]; 23 | index[0][i] = i; 24 | } 25 | 26 | for (int i = 1; i < n; i++) { 27 | for (int j = 0; j < n; j++) { 28 | 29 | } 30 | } 31 | } 32 | 33 | public static int getIndex(int i, int j) { 34 | 35 | return 1; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_1874_2.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | import java.util.Scanner; 4 | import java.util.Stack; 5 | 6 | public class Main_1874_2 { 7 | static Scanner sc; 8 | 9 | public static void main(String[] args) { 10 | sc = new Scanner(System.in); 11 | int n = sc.nextInt(); 12 | int index = 1; 13 | StringBuilder sb = new StringBuilder(); 14 | Stack stack = new Stack(); 15 | 16 | for (int i = 1; i <= n; i++) { 17 | int num = sc.nextInt(); 18 | if (index <= num) { 19 | while (index <= num) { 20 | stack.push(index++); 21 | sb.append("+\n"); 22 | } 23 | stack.pop(); 24 | sb.append("-\n"); 25 | } else { 26 | if (stack.peek() == num) { 27 | stack.pop(); 28 | sb.append("-\n"); 29 | } else { 30 | System.out.println("NO"); 31 | return; 32 | } 33 | } 34 | } 35 | System.out.println(sb); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_9012_2.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Main_9012_2 { 6 | 7 | static Scanner scanner; 8 | 9 | public static void main(String[] args) { 10 | scanner = new Scanner(System.in); 11 | int t = scanner.nextInt(); 12 | // sb = new StringBuilder(); 13 | for (int i = 0; i < t; i++) { 14 | String result = calcResult(scanner.next()); 15 | // sb.append(re) 16 | System.out.println(result); 17 | } 18 | } 19 | 20 | public static String calcResult(String str) { 21 | int stackSize = 0; 22 | for (char ch : str.toCharArray()) { 23 | if (ch == '(') { 24 | stackSize++; 25 | } else { 26 | if (stackSize == 0) { // ')' 이 와서 pop을 해야하는 상태인데 할게 없을 때 27 | return "NO"; 28 | } 29 | stackSize--; 30 | } 31 | } 32 | if (stackSize != 0) { // 'loop'를 전부 도았는데 ( 가 남아있는 상태 33 | return "NO"; 34 | } 35 | return "YES"; //loop를 전부 돌아서 stack size가 0인 상태 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_9084.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Main_9084 { 6 | 7 | public static StringBuilder sb = new StringBuilder(); 8 | 9 | public static void main(String args[]){ 10 | Scanner sc = new Scanner(System.in); 11 | 12 | int testCase = sc.nextInt(); 13 | 14 | for(int i=0; i map = new HashMap<>(); 12 | for (char c : tasks) { 13 | if (!map.containsKey(c)) 14 | map.put(c, 0); 15 | map.put(c, map.get(c) + 1); 16 | } 17 | 18 | Integer mapMax = map.values().stream() 19 | .max(Integer::compare).orElse(0); 20 | 21 | int count = (int) map.values().stream() 22 | .filter(x -> x.equals(mapMax)) 23 | .count() - 1; 24 | 25 | int max = (mapMax * (n + 1)) - n + count; 26 | 27 | return Math.max(tasks.length, max); 28 | } 29 | 30 | public static void main(String[] args) { 31 | char[] tasks = {'a','a','a','b','b','b'}; 32 | // char[] tasks = {'a','a','a','a','a','a','b','c','d','e','f','g'}; 33 | System.out.println(new Solution621().leastInterval(tasks, 1)); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_1463.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Main_1463 { 6 | 7 | public static int dp[]; 8 | 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | int input = sc.nextInt(); 12 | if (input > 3) { 13 | dp = new int[input + 1]; 14 | } else { 15 | dp = new int[4]; 16 | } 17 | dp[1] = 0; 18 | dp[2] = 1; 19 | dp[3] = 1; 20 | 21 | for (int i = 4; i <= input; i++) { 22 | int result = i - 1; 23 | if (i % 3 == 0) { 24 | int tmp1 = i / 3; 25 | result = minCheck(result, tmp1); 26 | } 27 | if (i % 2 == 0) { 28 | int tmp2 = i / 2; 29 | result = minCheck(result, tmp2); 30 | } 31 | dp[i] = dp[result] + 1; 32 | } 33 | 34 | System.out.println(dp[input]); 35 | } 36 | 37 | public static int minCheck(int tmp1, int tmp2) { 38 | if (dp[tmp1] > dp[tmp2]) 39 | return tmp2; 40 | return tmp1; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution824.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.stream.Collectors; 6 | 7 | /** 8 | * Created by jyami on 2020/08/19 9 | */ 10 | public class Solution824 { 11 | 12 | List letter = Arrays.asList('A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o', 'u'); 13 | 14 | public String toGoatLatin(String S) { 15 | String[] sentence = S.split(" "); 16 | for (int i = 0; i < sentence.length; i++) { 17 | char first = sentence[i].charAt(0); 18 | if (!letter.contains(first)) { 19 | sentence[i] = sentence[i].substring(1) + first; 20 | } 21 | sentence[i] = sentence[i] + iterateStringA(i + 1); 22 | } 23 | return Arrays.stream(sentence).collect(Collectors.joining(" ")); 24 | } 25 | 26 | private String iterateStringA(int iterateNum) { 27 | StringBuilder sb = new StringBuilder(); 28 | sb.append("ma"); 29 | for (int i = 0; i < iterateNum; i++) { 30 | sb.append("a"); 31 | } 32 | return sb.toString(); 33 | } 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/exam/programmers/TechWoowa1.java: -------------------------------------------------------------------------------- 1 | package com.jyami.exam.programmers; 2 | 3 | public class TechWoowa1 { 4 | 5 | public static void main(String args[]) { 6 | int restaurant[] = {0, 0}; 7 | int riders[][] = {{-700, 0}, {150, 180}, {500, 500}, {150, -800}, {800, 800}, {-900, 500}, {-1100, 900}}; 8 | int k = 1000; 9 | 10 | Solution solution = new Solution(); 11 | int solution1 = solution.solution(restaurant, riders, k); 12 | System.out.println(solution1); 13 | } 14 | 15 | static class Solution { 16 | public int solution(int[] restaurant, int[][] riders, int k) { 17 | int count = 0; 18 | for (int[] vector : riders) { 19 | if (isCircleIn(restaurant, vector, k)) 20 | count++; 21 | } 22 | return count; 23 | } 24 | 25 | private boolean isCircleIn(int[] restaurant, int[] vector, int k) { 26 | double calc = (Math.pow((restaurant[0] - vector[0]), 2) + Math.pow((restaurant[1] - vector[1]), 2)); 27 | double bound = Math.pow(k, 2); 28 | return calc < bound; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution797.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * Created by jyami on 2020/07/24 8 | */ 9 | public class Solution797 { 10 | 11 | List> list = new ArrayList<>(); 12 | 13 | public List> allPathsSourceTarget(int[][] graph) { 14 | list = new ArrayList<>(); 15 | int now = 0; 16 | List nowList = new ArrayList<>(); 17 | dfs(graph, now, nowList); 18 | return list; 19 | } 20 | 21 | public void dfs(int[][] graph, int now, List nowList) { 22 | System.out.println(now); 23 | nowList.add(now); 24 | if (graph[now].length == 0) { 25 | list.add(nowList); 26 | } 27 | for (int other : graph[now]) { 28 | dfs(graph, other, new ArrayList<>(nowList)); 29 | } 30 | } 31 | 32 | 33 | public static void main(String[] args) { 34 | int[][] arrays = {{1, 2}, {3}, {3}, {}}; 35 | List> lists = new Solution797().allPathsSourceTarget(arrays); 36 | System.out.println(lists); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution309.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | /** 4 | * Created by jyami on 2020/07/29 5 | */ 6 | public class Solution309 { 7 | public int maxProfit(int[] prices) { 8 | if (prices.length <= 1) 9 | return 0; 10 | 11 | if (prices.length == 2) 12 | return Math.max(prices[1] - prices[0], 0); 13 | 14 | int days = prices.length; 15 | int[][] dp = new int[days][2]; 16 | // 0 : 주식이 있다! // 1 : 주식이 없다! 17 | 18 | dp[0][0] = -prices[0]; 19 | dp[0][1] = 0; 20 | dp[1][0] = Math.max(dp[0][0], dp[0][1] - prices[1]); 21 | dp[1][1] = Math.max(dp[0][0] + prices[1], dp[0][1]); 22 | 23 | for (int i = 2; i < days; i++) { 24 | dp[i][0] = Math.max(dp[i - 2][1] - prices[i], dp[i - 1][0]); 25 | dp[i][1] = Math.max(dp[i - 1][0] + prices[i], dp[i - 1][1]); 26 | } 27 | 28 | return Math.max(dp[days - 1][0], dp[days - 1][1]); 29 | } 30 | 31 | public static void main(String[] args) { 32 | int[] arr = {1, 2, 3, 0, 2}; 33 | int i = new Solution309().maxProfit(arr); 34 | System.out.println(i); 35 | } 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_12865.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | public class Main_12865 { 6 | public static void main(String[] args) throws Exception { 7 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 8 | String[] s = br.readLine().split(" "); 9 | int itemNum = Integer.parseInt(s[0]); 10 | int maxWeight = Integer.parseInt(s[1]); 11 | int[][] dp = new int[itemNum + 1][maxWeight + 1]; 12 | 13 | for (int i = 1; i <= itemNum; i++) { // 처음부분은 따로 설정할 필요없게 비워있는 0인덱스 추가 14 | String[] ss = br.readLine().split(" "); 15 | int itemWeight = Integer.parseInt(ss[0]); 16 | int itemValue = Integer.parseInt(ss[1]); 17 | 18 | for (int j = 0; j <= maxWeight; j++) { 19 | if(j < itemWeight) { // 해당 무게 되기전까진 앞의 무게 그대로 사용 20 | dp[i][j] = dp[i - 1][j]; 21 | continue; 22 | } 23 | 24 | dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - itemWeight] + itemValue); 25 | } 26 | } 27 | System.out.println(dp[itemNum][maxWeight]); 28 | } 29 | } -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution20.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | 4 | import java.util.Stack; 5 | 6 | /** 7 | * Created by jyami on 2020/06/18 8 | */ 9 | public class Solution20 { 10 | public boolean isValid(String s) { 11 | Stack stack = new Stack<>(); 12 | for (int i = 0; i < s.length(); i++) { 13 | char c = s.charAt(i); 14 | switch (c) { 15 | case '[': 16 | case '{': 17 | case '(': 18 | stack.push(c); 19 | break; 20 | case ']': 21 | case '}': 22 | case ')': 23 | if(stack.size() ==0) 24 | return false; 25 | Character pop = stack.pop(); 26 | if(!((c == ']' && pop == '[') || (c == '}' && pop =='{') || (c == ')' && pop=='('))){ 27 | return false; 28 | } 29 | break; 30 | default: 31 | return false; 32 | } 33 | } 34 | if(stack.size() != 0) 35 | return false; 36 | return true; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution437.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | /** 4 | * Created by jyami on 2020/08/08 5 | */ 6 | public class Solution437 { 7 | 8 | int sumNum = 0; 9 | 10 | public int pathSum(TreeNode root, int sum) { 11 | if (root == null) 12 | return 0; 13 | pathHelper(root, sum); 14 | pathSum(root.left, sum); 15 | pathSum(root.right, sum); 16 | return sumNum; 17 | } 18 | 19 | private void pathHelper(TreeNode root, int sum) { 20 | if (root != null && root.val == sum) { 21 | sumNum++; 22 | } 23 | if (root != null) { 24 | sum -= root.val; 25 | pathHelper(root.left, sum); 26 | pathHelper(root.right, sum); 27 | } 28 | } 29 | 30 | public static void main(String[] args) { 31 | TreeNode treeNode = new TreeNode(10, 32 | new TreeNode(5, 33 | new TreeNode(3, new TreeNode(3), new TreeNode(-2)), 34 | new TreeNode(2, null, new TreeNode(1))), 35 | new TreeNode(-3, null, new TreeNode(11))); 36 | 37 | System.out.println(new Solution437().pathSum(treeNode, 8)); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_9093.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | import java.io.IOException; 4 | import java.util.Scanner; 5 | import java.util.Stack; 6 | 7 | public class Main_9093 { 8 | public static Stack stack = new Stack(); 9 | public static StringBuilder sb = new StringBuilder(); 10 | 11 | public static void main(String[] args) throws IOException { 12 | 13 | Scanner sc = new Scanner(System.in); 14 | int t = Integer.valueOf(sc.nextLine()); 15 | 16 | for (int i = 0; i < t; i++) { 17 | String[] texts = sc.nextLine().split(" "); 18 | for (int j = 0; j < texts.length; j++) { 19 | printReverse(texts[j]); 20 | if (j != texts.length - 1) { 21 | sb.append(" "); 22 | } 23 | } 24 | sb.append("\n"); 25 | } 26 | System.out.println(sb); 27 | } 28 | 29 | public static void printReverse(String text) { 30 | char[] chars = text.toCharArray(); 31 | for (char c : chars) { 32 | stack.push(c); 33 | } 34 | while (!stack.empty()) { 35 | sb.append(stack.pop()); 36 | } 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution67.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | /** 4 | * Created by jyami on 2020/07/20 5 | */ 6 | public class Solution67 { 7 | public String addBinary(String a, String b) { 8 | StringBuilder sb = new StringBuilder(); 9 | int indexA = a.length() - 1; 10 | int indexB = b.length() - 1; 11 | int carry = 0; 12 | 13 | while (indexA >= 0 && indexB >= 0) { 14 | int result = carry + (a.charAt(indexA) - '0') + b.charAt(indexB) - '0'; 15 | carry = result / 2; 16 | sb.insert(0, result % 2); 17 | indexA--; 18 | indexB--; 19 | } 20 | while (indexA >= 0) { 21 | int result = carry + (a.charAt(indexA) - '0'); 22 | carry = result / 2; 23 | sb.insert(0, result % 2); 24 | indexA--; 25 | } 26 | while (indexB >= 0) { 27 | int result = carry + (b.charAt(indexB) - '0'); 28 | carry = result / 2; 29 | sb.insert(0, result % 2); 30 | indexB--; 31 | } 32 | if (carry == 1) { 33 | sb.insert(0, 1); 34 | } 35 | return sb.toString(); 36 | } 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/exam/programmers/Programmers_LevelTest1_1.java: -------------------------------------------------------------------------------- 1 | package com.jyami.exam.programmers; 2 | 3 | import java.util.Arrays; 4 | import java.util.Comparator; 5 | 6 | public class Programmers_LevelTest1_1 { 7 | 8 | public static void main(String args[]) { 9 | String [] strings = {"sun", "bed", "car"}; 10 | int n = 1; 11 | Solution solution = new Solution(); 12 | String[] solution1 = solution.solution(strings, n); 13 | for(String s: solution1){ 14 | System.out.println(s); 15 | } 16 | } 17 | 18 | static class Solution { 19 | public String[] solution(String[] strings, int n) { 20 | 21 | Arrays.sort(strings, new CustomCompartor(n)); 22 | 23 | return strings; 24 | } 25 | } 26 | 27 | static class CustomCompartor implements Comparator { 28 | 29 | int index = 0; 30 | 31 | public CustomCompartor(int index) { 32 | this.index = index; 33 | } 34 | 35 | @Override 36 | public int compare(String o1, String o2) { 37 | return o1.charAt(index) > o2.charAt(index) ? 1 : o1.charAt(index) < o2.charAt(index) ? -1 : 38 | o1.compareTo(o2); 39 | } 40 | } 41 | 42 | 43 | 44 | } 45 | 46 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution2.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | /** 4 | * Created by jyami on 2020/06/16 5 | */ 6 | public class Solution2 { 7 | 8 | public ListNode addTwoNumbers(ListNode l1, ListNode l2) { 9 | int carry = 0; 10 | 11 | ListNode h = new ListNode(); 12 | ListNode node = h; 13 | while (l1 != null || l2 != null) { 14 | int n1 = l1 != null ? l1.val : 0; 15 | int n2 = l2 != null ? l2.val : 0; 16 | int val = n1 + n2 + carry; 17 | carry = val / 10; 18 | node.next = new ListNode(val % 10); 19 | if (l1 != null && l2 != null) { 20 | l1 = l1.next; 21 | l2 = l2.next; 22 | } else if (l1 == null) { 23 | l2 = l2.next; 24 | } else { 25 | l1 = l1.next; 26 | } 27 | node = node.next; 28 | } 29 | if(carry == 1){ 30 | node.next = new ListNode(1); 31 | } 32 | return h.next; 33 | } 34 | 35 | public static void main(String[] args) { 36 | ListNode l1 = new ListNode(9); 37 | ListNode l2 = new ListNode(9); 38 | ListNode listNode = new Solution2().addTwoNumbers(l1, l2); 39 | 40 | } 41 | 42 | } 43 | 44 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution129.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | /** 4 | * Created by jyami on 2020/06/26 5 | */ 6 | public class Solution129 { 7 | 8 | public int sumNumbers(TreeNode root) { 9 | if(root == null) 10 | return 0; 11 | return getSolution(root, 0); 12 | } 13 | 14 | public int getSolution(TreeNode root, int num) { 15 | int val = root.val; 16 | System.out.println(root.val); 17 | if (root.right == null && root.left == null) { 18 | return num * 10 + val; 19 | } 20 | int sum = 0; 21 | if (root.left != null) { 22 | sum += getSolution(root.left, num * 10 + val); 23 | } 24 | if (root.right != null) { 25 | sum += getSolution(root.right, num * 10 + val); 26 | } 27 | return sum; 28 | } 29 | 30 | 31 | 32 | public int getNowPow(int num) { 33 | int pow = 0; 34 | while (num != 0) { 35 | num = num / 10; 36 | pow++; 37 | } 38 | return pow; 39 | } 40 | 41 | class Result { 42 | int result; 43 | int pow; 44 | 45 | Result(int result, int pow) { 46 | this.result = result; 47 | this.pow = pow; 48 | } 49 | 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution983.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | /** 7 | * Created by jyami on 2020/08/26 8 | */ 9 | public class Solution983 { 10 | 11 | int[] cost; 12 | Set days = new HashSet<>(); 13 | Integer[] date = new Integer[366]; 14 | 15 | public int mincostTickets(int[] days, int[] costs) { 16 | this.cost = costs; 17 | for (int d : days) { 18 | this.days.add(d); 19 | } 20 | return dp(1); 21 | } 22 | 23 | public int dp(int day) { 24 | if (day > 365) 25 | return 0; 26 | if (date[day] != null) 27 | return date[day]; 28 | int answer; 29 | if (this.days.contains(day)) { 30 | answer = Math.min(dp(day + 1) + cost[0], dp(day + 7) + cost[1]); 31 | answer = Math.min(answer, dp(day + 30) + cost[2]); 32 | } else { 33 | answer = dp(day + 1); 34 | } 35 | date[day] = answer; 36 | return answer; 37 | } 38 | 39 | public static void main(String[] args) { 40 | int[] days = {1,4,6,7,8,20}; 41 | int[] costs = {2,7,15}; 42 | System.out.println(new Solution983().mincostTickets(days, costs)); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution963.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import java.util.*; 4 | 5 | /** 6 | * Created by jyami on 2020/08/18 7 | */ 8 | public class Solution963 { 9 | public int[] numsSameConsecDiff(int N, int K) { 10 | Queue list = new LinkedList<>(); 11 | for (int i = 1; i < 10; i++) { 12 | list.offer(i); 13 | } 14 | if (N == 1) 15 | list.offer(0); 16 | for (int i = 1; i < N; i++) { 17 | int size = list.size(); 18 | for (int j = 0; j < size; j++) { 19 | Integer poll = list.poll(); 20 | int digitNum = poll % 10; 21 | if (digitNum + K < 10) 22 | list.offer(poll * 10 + (digitNum + K)); 23 | if (digitNum - K >= 0 && K != 0) 24 | list.offer(poll * 10 + (digitNum - K)); 25 | } 26 | } 27 | int[] result = new int[list.size()]; 28 | for (int i = 0; i < result.length; i++) { 29 | result[i] = list.poll(); 30 | } 31 | return result; 32 | } 33 | 34 | public static void main(String[] args) { 35 | int[] ints = new Solution963().numsSameConsecDiff(2, 0); 36 | System.out.println(Arrays.toString(ints)); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/programmers/hash/NotCompletionPlayer.java: -------------------------------------------------------------------------------- 1 | package com.jyami.programmers.hash; 2 | 3 | import java.util.*; 4 | 5 | /** 6 | * 해시 - 완주하지 못한 선수 7 | * https://programmers.co.kr/learn/courses/30/lessons/42576 8 | */ 9 | 10 | 11 | public class NotCompletionPlayer { 12 | 13 | public static void main(String[] args) { 14 | Solution solution = new Solution(); 15 | String[] participant = {"a","b","c", "a"}; 16 | String[] completion = {"a","c", "a"}; 17 | solution.solution(participant, completion); 18 | System.out.println(); 19 | } 20 | 21 | static class Solution { 22 | public String solution(String[] participant, String[] completion) { 23 | HashMap map = new HashMap(); 24 | 25 | for(String part : participant){ 26 | Integer num = map.getOrDefault(part, 0); 27 | map.put(part, ++num); 28 | } 29 | 30 | for(String comp : completion){ 31 | Integer num = map.get(comp); 32 | if(num == 1){ 33 | map.remove(comp); 34 | continue; 35 | } 36 | map.put(comp, --num); 37 | } 38 | 39 | return map.keySet().iterator().next(); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/exam/codility/Naver_Intern_Codility_3.java: -------------------------------------------------------------------------------- 1 | package com.jyami.exam.codility; 2 | 3 | import java.util.*; 4 | import java.util.stream.Stream; 5 | 6 | /** 7 | * Created by jyami on 2020/01/10 8 | */ 9 | public class Naver_Intern_Codility_3 { 10 | public static void main(String[] args) { 11 | String s = "cbcana"; 12 | System.out.println(new Solution().solution(s)); 13 | } 14 | 15 | static class Solution { 16 | public int solution(String S) { 17 | char[] chars = S.toCharArray(); 18 | int prev = 0; 19 | int count =0; 20 | for(int i=1; ichars[i]){ 22 | if(chars[prev]> chars[i]){ 23 | count++; 24 | } 25 | count++; 26 | prev = i; 27 | } 28 | 29 | } 30 | return count; 31 | } 32 | } 33 | 34 | 35 | static class MyComparator implements Comparator{ 36 | 37 | @Override 38 | public int compare(String o1, String o2) { 39 | String replace1 = o1.replace("-", ""); 40 | String replace2 = o2.replace("-", ""); 41 | return replace1.compareTo(replace2); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/exam/codility/Naver_Intern_Codility_1.java: -------------------------------------------------------------------------------- 1 | package com.jyami.exam.codility; 2 | 3 | /** 4 | * Created by jyami on 2020/01/10 5 | */ 6 | public class Naver_Intern_Codility_1 { 7 | public static void main(String[] args) { 8 | int[][] array = {{0,1,9,3},{7,5,8,3},{9,2,9,4},{4,6,7,1}}; 9 | System.out.println(new Solution().solution(array)); 10 | 11 | } 12 | 13 | static class Solution { 14 | public int solution(int[][] A) { 15 | int row = A.length; 16 | int col = A[0].length; 17 | int count =0; 18 | for(int p=1; p A[p][q] && A[p][q] < A[p][q+1]) && (A[p-1][q] < A[p][q] && A[p][q] > A[p+1][q]); 29 | } 30 | 31 | public boolean isSaddlePoint2(int p, int q, int[][] A){ // row max / col min 32 | return (A[p][q-1] < A[p][q] && A[p][q] > A[p][q+1]) && (A[p-1][q] > A[p][q] && A[p][q] < A[p+1][q]); 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_2504.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | import java.util.Scanner; 4 | import java.util.Stack; 5 | 6 | public class Main_2504 { 7 | public static void main(String args[]){ 8 | Scanner in = new Scanner (System.in); 9 | 10 | Stack brank = new Stack(); 11 | Stackcalc = new Stack(); 12 | StringBuilder stringBuilder = new StringBuilder(); 13 | 14 | String str = in.next(); 15 | char []words = new char[str.length()]; 16 | for(int i=0; i a[i]){ 36 | dp[i] = + a[i] + dp[i-1]; 37 | }else{ 38 | dp[i] = a[i]; 39 | } 40 | if(dp[i] >max){ 41 | max = dp[i]; 42 | } 43 | } 44 | System.out.println(max); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_1158.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStreamReader; 6 | import java.util.LinkedList; 7 | 8 | public class Main_1158 { 9 | public static void main(String[] args) throws IOException { 10 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 11 | String[] input = br.readLine().split(" "); 12 | StringBuffer sb = new StringBuffer("<"); 13 | 14 | LinkedList queue = new LinkedList<>(); 15 | int t = Integer.parseInt(input[0]); 16 | int jump = Integer.parseInt(input[1]); 17 | 18 | for (int i = 0; i < t; i++) { 19 | queue.addLast(jump++); 20 | jump = getNumber(jump, t); 21 | } 22 | for (int i = 0; i < t - 1; i++) { 23 | Integer num = queue.removeFirst(); 24 | sb.append(num + ", "); 25 | for (int j = 0; j < jump - 1; j++) { 26 | Integer pop = queue.removeFirst(); 27 | queue.addLast(pop); 28 | } 29 | } 30 | sb.append(queue.removeFirst() + ">"); 31 | System.out.println(sb); 32 | } 33 | 34 | public static int getNumber(int num, int divider) { 35 | return num % divider == 0 ? divider : num % divider; 36 | } 37 | } -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution238.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import java.util.Arrays; 4 | 5 | /** 6 | * Created by jyami on 2020/04/15 7 | */ 8 | public class Solution238 { 9 | public static void main(String[] args) { 10 | int[] nums = {9,0,-2}; 11 | int[] ints = new Solution238().productExceptSelf(nums); 12 | System.out.println(Arrays.toString(ints)); 13 | } 14 | 15 | public int[] productExceptSelf(int[] nums) { 16 | int all = 1; 17 | boolean zero = false; 18 | for (int i = 0; i < nums.length; i++) { 19 | all *= nums[i]; 20 | if(nums[i] == 0){ 21 | zero = true; 22 | } 23 | } 24 | if(zero){ 25 | int [] result = new int[nums.length]; 26 | for(int i =0; i< nums.length; i++){ 27 | result[i] = 1; 28 | } 29 | for(int i =0; i< nums.length; i++){ 30 | for(int j =0 ; j start = new ArrayList<>(); 16 | for (int i = 0; i < arrB.length; i++) { 17 | if (arrA[0] == arrB[i]) { 18 | start.add(i); 19 | } 20 | } 21 | 22 | if (start.isEmpty()) 23 | return false; 24 | 25 | 26 | for (Integer startIndex : start) { 27 | int i; 28 | for (i = 0; i < arrA.length; i++) { 29 | if (arrA[i] != arrB[startIndex]) { 30 | break; 31 | } 32 | startIndex = (startIndex + 1) % arrB.length; 33 | } 34 | if (i == arrA.length) 35 | return true; 36 | } 37 | return false; 38 | } 39 | 40 | 41 | public static void main(String[] args) { 42 | int[] arrA = {4, 3, 4, 1}; 43 | int[] arrB = {4, 1, 4, 3}; 44 | boolean solution = new NBPSolution1().solution(arrA, arrB); 45 | System.out.println(solution); 46 | } 47 | 48 | } 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_9012.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | import java.util.Scanner; 4 | import java.util.Stack; 5 | 6 | 7 | public class Main_9012 { 8 | 9 | public static StringBuilder stringBuilder = new StringBuilder(); 10 | 11 | 12 | public static boolean check(String str) { 13 | Stack stack = new Stack(); 14 | char[] word = new char[str.length()]; 15 | for (int i = 0; i < str.length(); i++) { 16 | word[i] = str.charAt(i); 17 | } 18 | for (int i = 0; i < word.length; i++) { 19 | 20 | if (word[i] == '(') 21 | stack.push('('); 22 | if (word[i] == ')') { 23 | if (stack.isEmpty()) 24 | return false; 25 | stack.pop(); 26 | } 27 | } 28 | if (stack.isEmpty()) 29 | return true; 30 | else 31 | return false; 32 | } 33 | 34 | public static void main(String args[]) { 35 | int num; 36 | Scanner in = new Scanner(System.in); 37 | num = in.nextInt(); 38 | for (int i = 0; i < num; i++) { 39 | String str = in.next(); 40 | if (check(str)) 41 | stringBuilder.append("YES\n"); 42 | else 43 | stringBuilder.append("NO\n"); 44 | } 45 | System.out.print(stringBuilder); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/programmers/hash/Camouflage.java: -------------------------------------------------------------------------------- 1 | package com.jyami.programmers.hash; 2 | 3 | import java.util.*; 4 | 5 | /** 6 | * Created by jyami on 2020/01/05 7 | * 위장 8 | * https://programmers.co.kr/learn/courses/30/lessons/42578 9 | */ 10 | 11 | public class Camouflage { 12 | 13 | public static void main(String[] args) { 14 | Solution solution = new Solution(); 15 | String[][] clothes = {{"yellow_hat", "headgear"}, {"blue_sunglasses", "eyewear"}, {"green_turban", "headgear"}}; 16 | int solution1 = solution.solution(clothes); 17 | System.out.println(solution1); 18 | } 19 | 20 | static class Solution { 21 | 22 | public int solution(String[][] clothes) { 23 | int answer = 1; 24 | HashMap map = new HashMap(); 25 | for(String[] cloth : clothes){ 26 | int count = map.getOrDefault(cloth[1], 0); 27 | map.put(cloth[1], ++count); 28 | } 29 | 30 | List values = new ArrayList<>(map.values()); 31 | for(int value : map.values()){ 32 | answer *= (value+1); 33 | } 34 | 35 | return answer-1; 36 | } 37 | 38 | // 팁 순서가 있는 순열과 마찬가지 이기 때문에 가능하다. 39 | // 상의 : A가지 // 하의 : B가지 // 모자 : C가지 40 | // (A+1)(B+1)(C+1)-1 41 | // +1을 하는 이유는 벗는 경우가 있기 때문이다. -1을 하는 이유는 아무것도 안입으면 안되기 때문이다. 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/programmers/sort/KthNumber.java: -------------------------------------------------------------------------------- 1 | package com.jyami.programmers.sort; 2 | 3 | import java.util.Arrays; 4 | import java.util.Comparator; 5 | 6 | /** 7 | * Created by jyami on 2020/01/06 8 | * K번째 수 9 | * https://programmers.co.kr/learn/courses/30/lessons/42748 10 | */ 11 | public class KthNumber { 12 | public static void main(String[] args) { 13 | Solution solution = new Solution(); 14 | int[] array = {1, 5, 2, 6, 3, 7, 4}; 15 | int[][] commands = {{2, 5, 3}, {4, 4, 1}, {1, 7, 3}}; 16 | int[] solution1 = solution.solution(array, commands); 17 | System.out.println(Arrays.toString(solution1)); 18 | } 19 | 20 | static class Solution { 21 | public int[] solution(int[] array, int[][] commands) { 22 | int[] answer = new int[commands.length]; 23 | int i = 0; 24 | 25 | /* 26 | copyOfRange(array, start, end) : start-inclusive, end-exclusive 27 | {2,5,3} 일 때, 28 | 2번째는 index 1을 의미하므로 -- 해주기 29 | 5번째는 index 5를 포함하지 않으므로 그대로 30 | 3번째 수는 inedx 2를 의미하므로 -- 해주기 31 | */ 32 | 33 | for(int[] com : commands){ 34 | int[] result = Arrays.copyOfRange(array, --com[0], com[1]); 35 | Arrays.sort(result); 36 | answer[i++] = result[--com[2]]; 37 | } 38 | 39 | return answer; 40 | } 41 | } 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/ewhaAlgorithm/Epper2019Num3.java: -------------------------------------------------------------------------------- 1 | package com.jyami.ewhaAlgorithm; 2 | 3 | import java.util.HashMap; 4 | import java.util.Scanner; 5 | 6 | public class Epper2019Num3 { 7 | public static void main(String args[]) { 8 | Scanner sc = new Scanner(System.in); 9 | 10 | HashMap hs = new HashMap(); 11 | 12 | char[] first = sc.next().toLowerCase().toCharArray(); 13 | char[] second = sc.next().toLowerCase().toCharArray(); 14 | 15 | if (first.length != second.length) 16 | System.out.println("F"); 17 | 18 | for (int i = 0; i < first.length; i++) { 19 | if (hs.containsKey(first[i])) { 20 | int count = hs.get(first[i]); 21 | hs.put(first[i], count++); 22 | } else { 23 | hs.put(first[i], 1); 24 | } 25 | } 26 | 27 | 28 | for (int i = 0; i < second.length; i++) { 29 | if (hs.containsKey(second[i])) { 30 | int count = hs.get(second[i]); 31 | hs.put(first[i], --count); 32 | } else { 33 | System.out.println("F"); 34 | return; 35 | } 36 | } 37 | 38 | for (int num : hs.values()) { 39 | if (num != 0) { 40 | System.out.println("F"); 41 | return; 42 | } 43 | } 44 | 45 | System.out.println("T"); 46 | 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution107.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import java.util.*; 4 | 5 | /** 6 | * Created by jyami on 2020/07/02 7 | */ 8 | public class Solution107 { 9 | 10 | static class Node { 11 | int depth; 12 | TreeNode treeNode; 13 | 14 | public Node(int depth, TreeNode treeNode) { 15 | this.depth = depth; 16 | this.treeNode = treeNode; 17 | } 18 | } 19 | 20 | public List> levelOrderBottom(TreeNode root) { 21 | Queue queue = new LinkedList<>(); 22 | 23 | List> result = new ArrayList<>(); 24 | 25 | queue.offer(new Node(1, root)); 26 | while (!queue.isEmpty()) { 27 | Node node = queue.poll(); 28 | TreeNode poll = node.treeNode; 29 | 30 | if (poll != null) { 31 | if (result.size() < node.depth) { 32 | result.add(new ArrayList<>()); 33 | } 34 | result.get(node.depth - 1).add(poll.val); 35 | 36 | if (poll.left != null) { 37 | queue.add(new Node(node.depth + 1, poll.left)); 38 | } 39 | if (poll.right != null) { 40 | queue.add(new Node(node.depth + 1, poll.right)); 41 | } 42 | } 43 | } 44 | Collections.reverse(result); 45 | 46 | return result; 47 | } 48 | 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution463.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | /** 4 | * Created by jyami on 2020/07/08 5 | */ 6 | public class Solution463 { 7 | public int islandPerimeter(int[][] grid) { 8 | int sum = 0; 9 | 10 | for (int i = 0; i < grid.length; i++) { 11 | if (grid[i][0] == 1) { 12 | sum++; 13 | } 14 | for (int j = 0; j < grid[0].length - 1; j++) { 15 | if (grid[i][j] + grid[i][j + 1] == 1) { 16 | sum++; 17 | } 18 | } 19 | if (grid[i][grid[0].length - 1] == 1) { 20 | sum++; 21 | } 22 | } 23 | 24 | for (int i = 0; i < grid[0].length; i++) { 25 | if (grid[0][i] == 1) { 26 | sum++; 27 | } 28 | for (int j = 0; j < grid.length - 1; j++) { 29 | if (grid[j][i] + grid[j + 1][i] == 1) { 30 | sum++; 31 | } 32 | } 33 | if (grid[grid.length - 1][i] == 1) { 34 | sum++; 35 | } 36 | } 37 | return sum; 38 | } 39 | 40 | public static void main(String[] args) { 41 | // int[][] arr = {{0, 1, 0, 0}, {1, 1, 1, 0}, {0, 1, 0, 0}, {1, 1, 0, 0}}; 42 | int[][] arr = {{1,0}}; 43 | int i = new Solution463().islandPerimeter(arr); 44 | System.out.println(i); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution497.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import java.util.Arrays; 4 | import java.util.Random; 5 | 6 | /** 7 | * Created by jyami on 2020/08/22 8 | */ 9 | public class Solution497 { 10 | int[][] rects; 11 | int[] range; 12 | int totalArea = 0; // uniformly 하게 배치하기 위해서 area에 따른 random 가중치를 부여함. 13 | Random r = new Random(); 14 | 15 | public Solution497() { 16 | } 17 | 18 | public Solution497(int[][] rects) { 19 | this.rects = rects; 20 | range = new int[rects.length]; 21 | for (int i = 0; i < rects.length; i++) { 22 | int area = Math.abs((rects[i][2] - rects[i][0] + 1) * (rects[i][3] - rects[i][1] + 1)); 23 | totalArea += area; 24 | range[i] = totalArea; 25 | } 26 | } 27 | 28 | public int[] pick() { 29 | int area = r.nextInt(totalArea + 1); 30 | 31 | int index = 0; 32 | while (index < range.length && range[index] < area) { 33 | index++; 34 | } 35 | int[] rect = rects[index]; 36 | 37 | int x = r.nextInt(rect[2] - rect[0] + 1) + rect[0]; 38 | int y = r.nextInt(rect[3] - rect[1] + 1) + rect[1]; 39 | return new int[]{x, y}; 40 | } 41 | 42 | public static void main(String[] args) { 43 | int[][] rects = {{1, 1, 5, 5}}; 44 | Solution497 solution497 = new Solution497(rects); 45 | System.out.println(Arrays.toString(solution497.pick())); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_5639.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | import java.util.NoSuchElementException; 4 | import java.util.Scanner; 5 | 6 | public class Main_5639 { 7 | 8 | public static void main(String args[]){ 9 | Scanner in = new Scanner(System.in); 10 | Node root; 11 | try{ 12 | root = new Node(in.nextInt()); 13 | while(in.hasNextInt()){ 14 | Node n = new Node(in.nextInt()); 15 | root.insert(n); 16 | } 17 | root.postorder(); 18 | }catch (NoSuchElementException ex){ 19 | System.out.println(); 20 | } 21 | } 22 | } 23 | 24 | class Node{ 25 | public Node left; 26 | public Node right; 27 | public int data; 28 | 29 | public Node(int data){ 30 | this.left = null; 31 | this.right = null; 32 | this.data = data; 33 | } 34 | 35 | void insert(Node newNode){ 36 | if(data > newNode.data){ //left 넣기 37 | if(left!=null) 38 | left.insert(newNode); 39 | else 40 | left = newNode; 41 | }else{ //right 넣기 42 | if(right != null) 43 | right.insert(newNode); 44 | else 45 | right = newNode; 46 | } 47 | } 48 | 49 | void postorder(){ 50 | if(left != null) 51 | left.postorder(); 52 | if(right !=null) 53 | right.postorder(); 54 | System.out.println(data); 55 | } 56 | } -------------------------------------------------------------------------------- /src/main/java/com/jyami/exam/codility/Naver_AI_HACK_2.java: -------------------------------------------------------------------------------- 1 | package com.jyami.exam.codility; 2 | 3 | /** 4 | * Created by jyami on 2020/01/29 5 | */ 6 | public class Naver_AI_HACK_2 { 7 | 8 | public static void main(String[] args) { 9 | String[] input ={"?ab??a", "bab??a", "?a?"}; 10 | for(String str : input){ 11 | String solution = new Solution().solution(str); 12 | System.out.println(solution); 13 | } 14 | } 15 | 16 | static class Solution { 17 | public String solution(String str) { 18 | char[] chars = str.toCharArray(); 19 | int len = str.length(); 20 | int s = 0; 21 | int f = len-1; 22 | 23 | while(s <= f){ 24 | char a = chars[s]; 25 | char b = chars[f]; 26 | 27 | if(a != '?' && b != '?'){ // 둘다 문자일 때 28 | if(a != b){ 29 | return "NO"; 30 | } 31 | }else if(a == '?' && b == '?'){ // 둘다 ? 일때 32 | chars[s] = 'a'; 33 | chars[f] = 'a'; 34 | } 35 | else{ // 하나만 ? 일 때 36 | if(a == '?'){ 37 | chars[s] = chars[f]; 38 | }else{ 39 | chars[f] = chars[s]; 40 | } 41 | } 42 | s++; 43 | f--; 44 | } 45 | 46 | return String.valueOf(chars); 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/com/jyami/leetCode/notSolved/Solution332Test.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.notSolved; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | 8 | import static org.junit.jupiter.api.Assertions.*; 9 | 10 | class Solution332Test { 11 | @Test 12 | void findItineraryTest() { 13 | List> input = Arrays.asList( 14 | Arrays.asList("JFK", "ATL"), 15 | Arrays.asList("ORD", "PHL"), 16 | Arrays.asList("JFK", "ORD"), 17 | Arrays.asList("PHX", "LAX"), 18 | Arrays.asList("LAX", "JFK"), 19 | Arrays.asList("PHL", "ATL"), 20 | Arrays.asList("ATL", "PHX")); 21 | 22 | //["JFK","ATL","PHX","LAX","JFK","ORD","PHL","ATL"] 23 | 24 | 25 | // List> input = Arrays.asList( 26 | // Arrays.asList("JFK", "SFO"), 27 | // Arrays.asList("JFK", "ATL"), 28 | // Arrays.asList("SFO", "ATL"), 29 | // Arrays.asList("ATL", "JFK"), 30 | // Arrays.asList("ATL", "SFO")); 31 | 32 | //["JFK","ATL","JFK","SFO","ATL","SFO"] 33 | 34 | // List> input = Arrays.asList( 35 | // Arrays.asList("MUC", "LHR"), 36 | // Arrays.asList("JFK", "MUC"), 37 | // Arrays.asList("SFO", "SJC"), 38 | // Arrays.asList("LHR", "SFO")); 39 | // ["JFK", "MUC", "LHR", "SFO", "SJC"] 40 | 41 | System.out.println(new Solution332().findItinerary(input)); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/notSolved/Solution1427.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.notSolved; 2 | 3 | /** 4 | * Created by jyami on 2020/04/15 5 | */ 6 | public class Solution1427 { 7 | 8 | public static void main(String[] args) { 9 | 10 | String s = "abcdefg"; 11 | // String s = "abc"; 12 | int[][] shift = {{1, 1}}; // l로 1번 이동. 13 | // int[][] shift = {{0,1},{1,2}}; 14 | // int[][] shift = {{1, 1}, {1, 1}, {0, 2}, {1, 3}}; 15 | // int[][] shift = {{0,3}}; 16 | // 17 | // System.out.println(s.substring(1)); 18 | // System.out.println(s.substring(0, 1)); 19 | // System.out.println(s.substring(0, 2)); 20 | 21 | String s1 = new Solution1427().stringShift(s, shift); 22 | System.out.println(s1); 23 | } 24 | 25 | public String stringShift(String s, int[][] shift) { 26 | int l = 0; 27 | int sum = 0; 28 | for (int i = 0; i < shift.length; i++) { 29 | if (i == l) { 30 | sum -= shift[i][1]; 31 | } else { 32 | sum += shift[i][1]; 33 | } 34 | } 35 | String left; 36 | String right; 37 | if (sum > 0) { // r 38 | left = s.substring(s.length() - sum); 39 | right = s.substring(0, sum + 1); 40 | } else { // l 41 | sum = -sum; 42 | left = s.substring(sum); 43 | right = s.substring(0, sum); 44 | } 45 | System.out.println(left); 46 | System.out.println(right); 47 | return left + right; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/programmers/completeSearch/MockTest.java: -------------------------------------------------------------------------------- 1 | package com.jyami.programmers.completeSearch; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | /** 8 | * Created by jyami on 2020/01/07 9 | * 모의고사 10 | * https://programmers.co.kr/learn/courses/30/lessons/42840# 11 | */ 12 | public class MockTest { 13 | public static void main(String[] args) { 14 | int[] answers = {1,2,3,4,5,1,2,3,4,5}; 15 | int[] answers2 = {5}; 16 | int[] solution = new Solution().solution(answers); 17 | System.out.println(Arrays.toString(solution)); 18 | } 19 | 20 | static class Solution { 21 | public int[] solution(int[] answers) { 22 | int[] p1 = {1,2,3,4,5}; 23 | int[] p2 = {2, 1, 2, 3, 2, 4, 2, 5}; 24 | int[] p3 = {3, 3, 1, 1, 2, 2, 4, 4, 5, 5}; 25 | int c1 =0, c2 =0, c3 =0; 26 | for(int i = 0; i list = new ArrayList<>(); 33 | if(c1 == max) list.add(1); 34 | if(c2 == max) list.add(2); 35 | if(c3 == max) list.add(3); 36 | 37 | 38 | int[] a = new int[list.size()]; 39 | for(int i =0; i map = new HashMap<>(); 17 | int[] result = new int[cells.length]; 18 | result[0] = 0; 19 | result[cells.length - 1] = 0; 20 | 21 | for (int i = 0; i < diff; i++) { 22 | for (int j = 1; j < cells.length - 1; j++) { 23 | result[j] = checkStatus(cells[j - 1], cells[j + 1]); 24 | } 25 | cells = result.clone(); 26 | String resultString = Arrays.toString(result); 27 | map.put(i, resultString); 28 | } 29 | 30 | Integer index = (N-1) % diff; 31 | String value = map.get(index); 32 | String[] split = value.substring(1, value.length() - 1).split(","); 33 | for (int i = 0; i < split.length; i++) { 34 | result[i] = Integer.parseInt(split[i].trim()); 35 | } 36 | return result; 37 | } 38 | 39 | public int checkStatus(int before, int after) { 40 | return before == after ? 1 : 0; 41 | } 42 | 43 | public static void main(String[] args) { 44 | int[] cells = {0, 1, 0, 1, 1, 0, 0, 1}; 45 | int[] ints = new Solution957().prisonAfterNDays(cells, 7); 46 | System.out.println(Arrays.toString(ints)); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_11650.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.List; 6 | import java.util.Scanner; 7 | 8 | public class Main_11650 { 9 | public static void main(String args[]) { 10 | Scanner sc = new Scanner(System.in); 11 | int num = sc.nextInt(); 12 | 13 | List points = new ArrayList<>(); 14 | for (int i = 0; i < num; i++) { 15 | points.add(new Point(sc.nextInt(), sc.nextInt())); 16 | } 17 | 18 | Collections.sort(points); 19 | 20 | for (Point p : points) { 21 | System.out.println(p.toString()); 22 | } 23 | } 24 | } 25 | 26 | class Point implements Comparable { 27 | private int x; 28 | private int y; 29 | 30 | private int getX() { 31 | return x; 32 | } 33 | 34 | private int getY() { 35 | return y; 36 | } 37 | 38 | Point(int x, int y) { 39 | this.x = x; 40 | this.y = y; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return x + " " + y; 46 | } 47 | 48 | @Override 49 | public int compareTo(Point o) { 50 | if (this.x > o.getX()) { 51 | return 1; 52 | } else if (this.x < o.getX()) { 53 | return -1; 54 | } else { 55 | if (this.y > o.getY()) { 56 | return 1; 57 | } else if (this.y < o.getY()) { 58 | return -1; 59 | } else { 60 | return 0; 61 | } 62 | } 63 | } 64 | 65 | } -------------------------------------------------------------------------------- /src/main/java/com/jyami/exam/hackerRank/KakaoResult2.java: -------------------------------------------------------------------------------- 1 | package com.jyami.exam.hackerRank; 2 | 3 | import java.util.*; 4 | import java.util.stream.Collectors; 5 | 6 | /** 7 | * Created by jyami on 2020/06/29 8 | */ 9 | public class KakaoResult2 { 10 | 11 | static class Digit implements Comparable { 12 | int index; 13 | List digitList; 14 | 15 | public Digit(int index, List digitList) { 16 | this.index = index; 17 | this.digitList = digitList; 18 | } 19 | 20 | @Override 21 | public int compareTo(Digit o) { 22 | for (int i = 0; i < this.digitList.size(); i++) { 23 | int compare = Integer.compare(o.digitList.get(i), this.digitList.get(i)); 24 | if (compare != 0) 25 | return compare; 26 | } 27 | return 0; 28 | } 29 | } 30 | 31 | public static List solution(List> arr) { 32 | 33 | List digits = new ArrayList<>(); 34 | 35 | for (int i = 0; i < arr.size(); i++) { 36 | arr.get(i).sort(Comparator.reverseOrder()); 37 | digits.add(new Digit(i, arr.get(i))); 38 | } 39 | 40 | Collections.sort(digits); 41 | 42 | return digits.stream() 43 | .map(x -> x.index) 44 | .collect(Collectors.toList()); 45 | } 46 | 47 | 48 | public static void main(String[] args) { 49 | List> list = Arrays.asList(Arrays.asList(0, 2), Arrays.asList(2, 3), Arrays.asList(2, 1)); 50 | System.out.println(solution(list)); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/programmers/hash/not_completion_player.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // main.cpp 3 | // hash_not_completion_player 4 | // 5 | // Created by jyami on 2020/01/03. 6 | // Copyright © 2020 jyami. All rights reserved. 7 | // https://programmers.co.kr/learn/courses/30/lessons/42576?language=cpp 8 | // 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | 16 | using namespace std; 17 | 18 | string solution(vector participant, vector completion); 19 | 20 | int main() { 21 | // insert code here... 22 | 23 | std::vector participant; 24 | participant.push_back("a"); 25 | participant.push_back("b"); 26 | participant.push_back("b"); 27 | 28 | std::vector completion; 29 | completion.push_back("a"); 30 | completion.push_back("b"); 31 | 32 | string a = solution(participant, completion); 33 | std::cout << a; 34 | return 0; 35 | } 36 | 37 | string solution(vector participant, vector completion) { 38 | 39 | unordered_map map; 40 | 41 | for(auto iter : participant){ 42 | string key = iter; 43 | int value = map[key]; 44 | if(!map.count(key)){ 45 | value = 0; 46 | } 47 | map[key] = ++value; 48 | } 49 | 50 | for(auto iter : completion){ 51 | string key = iter; 52 | int value = map[key]; 53 | map[key] = --value; 54 | } 55 | 56 | for(auto iter : map){ 57 | if(iter.second == 1){ 58 | return iter.first; 59 | } 60 | } 61 | 62 | return ""; 63 | } 64 | 65 | -------------------------------------------------------------------------------- /src/main/kotlin/com/jyami/leetCode/Soultion1106.kt: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode 2 | 3 | import java.util.* 4 | 5 | class Soultion1106 { 6 | 7 | val stack = Stack() 8 | 9 | fun parseBoolExpr(expression: String): Boolean { 10 | 11 | for(c in expression){ 12 | if(c == ')'){ 13 | val result = cacl() 14 | val push = if(result){ 15 | 't' 16 | }else{ 17 | 'f' 18 | } 19 | stack.push(push) 20 | } else { 21 | stack.push(c) 22 | } 23 | } 24 | return stack.pop() == 't' 25 | } 26 | 27 | fun cacl() : Boolean{ 28 | var pop = stack.pop() 29 | val bools = mutableListOf() 30 | while(pop != '('){ 31 | if(pop == 't'){ 32 | bools.add(true) 33 | }else if(pop=='f'){ 34 | bools.add(false) 35 | } 36 | // else : case , 37 | pop = stack.pop() 38 | } 39 | val op = stack.pop() 40 | if(op == '&'){ 41 | for(b in bools){ 42 | if(!b){ 43 | return true 44 | } 45 | } 46 | return false 47 | } 48 | if(op == '|'){ 49 | for(b in bools){ 50 | if(b){ 51 | return true 52 | } 53 | } 54 | return false 55 | } 56 | if(op == '!'){ 57 | val b = bools[0] 58 | return !b 59 | } 60 | return false 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/exam/programmers/TechWoowa2.java: -------------------------------------------------------------------------------- 1 | package com.jyami.exam.programmers; 2 | 3 | public class TechWoowa2 { 4 | 5 | public static void main(String args[]) { 6 | String log = "2019/05/01 00:59:19\n" + 7 | "2019/06/01 01:35:20\n" + 8 | "2019/08/01 02:01:22\n" + 9 | "2019/08/01 02:01:23\n" + 10 | "2019/08/02 03:02:35\n" + 11 | "2019/10/03 04:05:40\n" + 12 | "2019/10/04 06:23:10\n" + 13 | "2019/10/10 08:23:20\n" + 14 | "2019/10/12 08:42:24\n" + 15 | "2019/10/23 08:43:26\n" + 16 | "2019/11/14 08:43:29\n" + 17 | "2019/11/01 10:19:02\n" + 18 | "2019/12/01 11:23:10"; 19 | 20 | Solution solution = new Solution(); 21 | int[] solution1 = solution.solution(log); 22 | for (int sol : solution1) { 23 | System.out.print(sol + " "); 24 | } 25 | 26 | } 27 | 28 | static class Solution { 29 | static final int LOG_TIME_START_INDEX = 11; 30 | static final int LOG_TIME_END_INDEX = 13; 31 | static final int UTC_KOREA = 9; 32 | 33 | public int[] solution(String logs) { 34 | int[] answer = new int[24]; 35 | String[] split = logs.split("\n"); 36 | 37 | for (String oneLog : split) { 38 | String hourString = oneLog.substring(LOG_TIME_START_INDEX, LOG_TIME_END_INDEX); 39 | int hour = Integer.valueOf(hourString) + UTC_KOREA % 24; 40 | answer[hour]++; 41 | } 42 | return answer; 43 | } 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/programmers/sort/Hindex.java: -------------------------------------------------------------------------------- 1 | package com.jyami.programmers.sort; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.stream.Collectors; 6 | 7 | /** 8 | * Created by jyami on 2020/01/07 9 | * H-index 10 | * https://programmers.co.kr/learn/courses/30/lessons/42747 11 | */ 12 | public class Hindex { 13 | 14 | public static void main(String[] args) { 15 | Solution solution = new Solution(); 16 | // int[] citations = {3,0,6,1,5}; 17 | // int[] citations = {10,8,4,5,3}; 18 | int[] citations = {25,8,5,1,1}; 19 | int solution1 = solution.solution(citations); 20 | System.out.println(solution1); 21 | } 22 | 23 | static class Solution { 24 | public int solution(int[] citations) { 25 | List list = Arrays.stream(citations) 26 | .boxed() 27 | .sorted() 28 | .collect(Collectors.toList()); 29 | 30 | int m = citations.length; 31 | int h = 0; 32 | for(int i = 0; i= k && k >= i){ 37 | h = k; 38 | } 39 | //만약 인용 논문의 개수가 엄청 많다면? length 기준으로 하나씩 빼줘야함 40 | // ex ) 테스트 케이스 [43,42] = 2 41 | if(m>k){ 42 | m--; 43 | } 44 | } 45 | 46 | return Math.max(h, m); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution1286.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import java.util.ArrayList; 4 | import java.util.LinkedList; 5 | import java.util.List; 6 | import java.util.Queue; 7 | 8 | /** 9 | * Created by jyami on 2020/08/13 10 | */ 11 | public class Solution1286 { 12 | 13 | public static void main(String[] args) { 14 | CombinationIterator abc = new CombinationIterator("abc", 2); 15 | System.out.println(abc.next()); 16 | System.out.println(abc.hasNext()); 17 | System.out.println(abc.next()); 18 | System.out.println(abc.hasNext()); 19 | System.out.println(abc.next()); 20 | System.out.println(abc.hasNext()); 21 | } 22 | } 23 | 24 | 25 | class CombinationIterator { 26 | 27 | String characters; 28 | Queue queue = new LinkedList<>(); 29 | 30 | public CombinationIterator(String characters, int combinationLength) { 31 | this.characters = characters; 32 | for (int i = 0; i < (1 << characters.length()); i++) { 33 | StringBuilder sb = new StringBuilder(); 34 | for (int j = 0; j < characters.length(); j++) { 35 | if ((i & (1 << j)) > 0) { // 주어진 i를 한 자리씩 탐색 : i = 2(10), j = 0(1) => 3(11) : c추가 36 | sb.append(characters.charAt(i)); 37 | } 38 | } 39 | if (sb.toString().length() == combinationLength) { 40 | queue.add(sb.toString()); 41 | } 42 | } 43 | 44 | } 45 | 46 | public String next() { 47 | return queue.poll(); 48 | } 49 | 50 | public boolean hasNext() { 51 | return !queue.isEmpty(); 52 | } 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution13.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | /** 4 | * Created by jyami on 2020/06/17 5 | */ 6 | public class Solution13 { 7 | 8 | public int romanToInt(String s) { 9 | int result = 0; 10 | int i = 0; 11 | for (; i < s.length() - 1; i++) { 12 | char c = s.charAt(i); 13 | int anInt = getInt(c); 14 | char nextChar = s.charAt(i + 1); 15 | if (checkMinus(c, nextChar)) { 16 | result = result + getInt(nextChar) - anInt; 17 | i++; 18 | }else{ 19 | result = result + anInt; 20 | } 21 | } 22 | if(i != s.length()){ 23 | int anInt = getInt(s.charAt(s.length() - 1)); 24 | return result + anInt; 25 | } 26 | return result; 27 | } 28 | 29 | public static boolean checkMinus(char c, char next) { 30 | if (c == 'I' && (next == 'V' || next == 'X') 31 | || c == 'X' && (next == 'L' || next == 'C') 32 | || c == 'C' && (next == 'D' || next == 'M')) { 33 | return true; 34 | } 35 | return false; 36 | } 37 | 38 | public int getInt(char c) { 39 | switch (c) { 40 | case 'I': 41 | return 1; 42 | case 'V': 43 | return 5; 44 | case 'X': 45 | return 10; 46 | case 'L': 47 | return 50; 48 | case 'C': 49 | return 100; 50 | case 'D': 51 | return 500; 52 | case 'M': 53 | return 1000; 54 | } 55 | return 0; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/codejam/april2020/round1/Solution1.java: -------------------------------------------------------------------------------- 1 | package com.jyami.codejam.april2020.round1; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStreamReader; 6 | 7 | /** 8 | * Created by jyami on 2020/04/11 9 | */ 10 | public class Solution1 { 11 | 12 | public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 13 | 14 | public static void main(String[] args) throws IOException { 15 | int t = Integer.parseInt(br.readLine()); 16 | StringBuilder sb = new StringBuilder(); 17 | for (int i = 0; i < t; i++) { 18 | int n = Integer.parseInt(br.readLine()); 19 | String answer = answer(n); 20 | sb.append(String.format("CASE #%d: %s\n", i + 1, answer)); 21 | } 22 | System.out.println(sb); 23 | } 24 | 25 | public static String answer(int n) throws IOException { 26 | String[] arr = new String[n]; 27 | arr[0] = br.readLine().replace("*", ""); 28 | String key = arr[0]; 29 | boolean flag = false; 30 | for (int i = 1; i < n; i++) { 31 | arr[i] = br.readLine().replace("*", ""); 32 | if (arr[i].contains(key)) { 33 | key = arr[i]; 34 | for (int j = 0; j < i; j++) { 35 | if (!key.contains(arr[j])) { 36 | return "*"; 37 | } 38 | } 39 | } else if (key.contains(arr[i])) { 40 | flag = true; 41 | } else { 42 | return "*"; 43 | } 44 | } 45 | if (flag) { 46 | return key; 47 | } else { 48 | return "*"; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution15.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import java.util.*; 4 | 5 | /** 6 | * Created by jyami on 2020/07/09 7 | */ 8 | public class Solution15 { 9 | public List> threeSum(int[] nums) { 10 | Arrays.sort(nums); 11 | Set> result = new HashSet<>(); 12 | 13 | for (int n = 0; n < nums.length - 2; n++) { 14 | if (n == 0 || nums[n] != nums[n - 1]) { 15 | int sum = -nums[n]; 16 | int low = n + 1; 17 | int high = nums.length - 1; 18 | while (low < high) { 19 | if (sum == nums[low] + nums[high]) { 20 | result.add(Arrays.asList(-sum, nums[low], nums[high])); 21 | List list = new ArrayList<>(); 22 | while ((low < high) && nums[low] == nums[low + 1]) { 23 | low++; 24 | } 25 | while ((low < high) && nums[high] == nums[high - 1]) { 26 | high--; 27 | } 28 | low++; 29 | high--; 30 | } else if (sum > nums[low] + nums[high]) { 31 | low++; 32 | } else { 33 | high--; 34 | } 35 | } 36 | } 37 | } 38 | return new ArrayList<>(result); 39 | } 40 | 41 | 42 | public static void main(String[] args) { 43 | int[] input = {-1, 0, 1, 2, -1, -4}; 44 | List> lists = new Solution15().threeSum(input); 45 | System.out.println(lists); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/exam/programmers/KakaoIntern1.java: -------------------------------------------------------------------------------- 1 | package com.jyami.exam.programmers; 2 | 3 | import java.util.Stack; 4 | 5 | public class KakaoIntern1 { 6 | public static void main(String args[]) { 7 | int[][] board = {{0, 0, 0, 0, 0}, {0, 0, 1, 0, 3}, {0, 2, 5, 0, 1}, {4, 2, 4, 4, 2}, {3, 5, 1, 3, 1}}; 8 | int[] moves = {1, 5, 3, 5, 1, 2, 1, 4}; 9 | 10 | Solution solution = new Solution(); 11 | int solution1 = solution.solution(board, moves); 12 | System.out.println(solution1); 13 | } 14 | 15 | static class Solution { 16 | 17 | static int amount = 0; 18 | static Stack stack = new Stack<>(); 19 | 20 | public int solution(int[][] board, int[] moves) { 21 | stack.add(-1); 22 | int size = board[0].length; 23 | for (int move : moves) { 24 | getDoll(board, move - 1, size); 25 | } 26 | return amount; 27 | } 28 | 29 | private void stackPopCheck(int beforeDoll) { 30 | Integer peek = stack.peek(); 31 | if (peek == beforeDoll) { 32 | stack.pop(); 33 | stack.pop(); 34 | amount += 2; 35 | } 36 | } 37 | 38 | private void getDoll(int[][] board, int move, int size) { 39 | for (int i = 0; i < size; i++) { 40 | int tong = board[i][move]; 41 | if (tong != 0) { 42 | Integer beforeDoll = stack.peek(); 43 | board[i][move] = 0; 44 | stack.add(tong); 45 | stackPopCheck(beforeDoll); 46 | break; 47 | } 48 | } 49 | } 50 | 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/exam/programmers/TechWoowa3.java: -------------------------------------------------------------------------------- 1 | package com.jyami.exam.programmers; 2 | 3 | import java.util.Arrays; 4 | import java.util.Collections; 5 | import java.util.List; 6 | import java.util.stream.Collectors; 7 | 8 | public class TechWoowa3 { 9 | 10 | public static void main(String args[]) { 11 | // int prices[] = {13000, 88000, 10000}; 12 | // int discounts[] = {30, 20}; 13 | 14 | int prices[] = {13000, 88000, 10000}; 15 | int discounts[] = {30, 20}; 16 | 17 | Solution solution = new Solution(); 18 | int solution1 = solution.solution(prices, discounts); 19 | System.out.println(solution1); 20 | } 21 | 22 | static class Solution { 23 | public int solution(int[] prices, int[] discounts) { 24 | List sortedPrice = intArrayToList(prices); 25 | List sortedDiscounts = intArrayToList(discounts); 26 | 27 | int index = 0; 28 | int result = 0; 29 | int discountSize = sortedDiscounts.size(); 30 | for (Integer price : sortedPrice) { 31 | if (index < discountSize) { 32 | double multipleRate = 100 - sortedDiscounts.get(index++); 33 | double calculate = price * multipleRate / 100; 34 | result += calculate; 35 | } else { 36 | result += price; 37 | } 38 | } 39 | return result; 40 | } 41 | 42 | private List intArrayToList(int[] array) { 43 | return Arrays.stream(array) 44 | .boxed() 45 | .sorted(Collections.reverseOrder()) 46 | .collect(Collectors.toList()); 47 | } 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_1406_2.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStreamReader; 6 | import java.util.LinkedList; 7 | 8 | public class Main_1406_2 { 9 | 10 | static LinkedList list = new LinkedList<>(); 11 | 12 | static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 13 | static int headIndex = 0; 14 | 15 | public static void main(String[] args) throws IOException { 16 | String input = br.readLine(); 17 | 18 | for (char ch : input.toCharArray()) { 19 | list.add(ch); 20 | headIndex++; 21 | } 22 | 23 | int t = Integer.parseInt(br.readLine()); 24 | 25 | for (int i = 0; i < t; i++) { 26 | command(br.readLine()); 27 | } 28 | for (char c : list) { 29 | System.out.print(c); 30 | } 31 | } 32 | 33 | public static void command(String str) throws IOException { 34 | switch (str) { 35 | case "L": 36 | if (headIndex != 0) { 37 | headIndex--; 38 | } 39 | break; 40 | case "D": 41 | if (headIndex != list.size()) { 42 | headIndex++; 43 | } 44 | break; 45 | case "B": 46 | if (headIndex != 0) { 47 | list.remove(headIndex - 1); 48 | headIndex--; 49 | } 50 | break; 51 | default: 52 | char text = str.split(" ")[1].charAt(0); 53 | list.add(headIndex, text); 54 | headIndex++; 55 | break; 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_1431.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.List; 6 | import java.util.Scanner; 7 | 8 | public class Main_1431 { 9 | public static void main(String args[]) { 10 | 11 | String str = "안녕1234"; 12 | String replace = str.replace("1234", ""); 13 | 14 | String replaceAll = str.replaceAll("\\d", ""); 15 | 16 | System.out.println(replace); 17 | System.out.println(replaceAll); 18 | 19 | Scanner sc = new Scanner(System.in); 20 | int num = sc.nextInt(); 21 | 22 | List list = new ArrayList<>(); 23 | for (int i = 0; i < num; i++) { 24 | list.add(new Item(sc.next())); 25 | } 26 | 27 | Collections.sort(list); 28 | 29 | for (Item item : list) { 30 | System.out.println(item.text); 31 | } 32 | 33 | } 34 | } 35 | 36 | 37 | class Item implements Comparable { 38 | int size; 39 | String text; 40 | int number; 41 | 42 | public Item(String text) { 43 | this.text = text; 44 | this.size = text.length(); 45 | this.number = findNumber(text); 46 | } 47 | 48 | private int findNumber(String str) { 49 | int sum = 0; 50 | for (int i = 0; i < str.length(); i++) { 51 | if (str.charAt(i) >= '0' && str.charAt(i) <= '9') { 52 | sum += str.charAt(i) - '0'; 53 | } 54 | } 55 | return sum; 56 | } 57 | 58 | @Override 59 | public int compareTo(Item o) { 60 | return this.size > o.size ? 1 : this.size < o.size ? -1 : 61 | this.number > o.number ? 1 : this.number < o.number ? -1 : 62 | this.text.compareTo(o.text); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/exam/programmers/Programmers_LevelTest3_2.java: -------------------------------------------------------------------------------- 1 | package com.jyami.exam.programmers; 2 | 3 | import java.util.PriorityQueue; 4 | 5 | public class Programmers_LevelTest3_2 { 6 | 7 | public static void main(String args[]) { 8 | 9 | String[] input = {"I 653", "I -45", "I -45", "D -1"}; 10 | int[] solution = new Solution().solution(input); 11 | for (int i : solution) { 12 | System.out.println(i); 13 | } 14 | } 15 | 16 | static class Solution { 17 | public static PriorityQueue queue; 18 | 19 | 20 | public int[] solution(String[] operations) { 21 | 22 | 23 | queue = new PriorityQueue<>(); 24 | 25 | for (String oper : operations) { 26 | exe(oper); 27 | } 28 | 29 | if (queue.isEmpty()) { 30 | int[] answer = {0, 0}; 31 | return answer; 32 | } 33 | 34 | Integer[] arr = new Integer[queue.size()]; 35 | queue.toArray(arr); 36 | int max = arr.length - 1; 37 | int[] answer = {arr[max], arr[0]}; 38 | 39 | return answer; 40 | } 41 | 42 | public void exe(String s) { 43 | Integer num = Integer.valueOf(s.substring(2)); 44 | 45 | if (s.charAt(0) == 'I') { 46 | queue.add(num); 47 | } else if (!queue.isEmpty()) { 48 | if (num == 1) { // 최대값삭제 49 | Integer[] arr = new Integer[queue.size()]; 50 | queue.toArray(arr); 51 | int max = arr[arr.length - 1]; 52 | queue.remove(max); 53 | } else { // 최소값 삭제 54 | queue.poll(); 55 | } 56 | } 57 | 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | 3 | .gradle 4 | build 5 | 6 | ## mac 7 | .DS_Store 8 | 9 | .idea 10 | venv 11 | ### Java template 12 | # Compiled class file 13 | *.class 14 | 15 | # Log file 16 | *.log 17 | 18 | # BlueJ files 19 | *.ctxt 20 | 21 | # Mobile Tools for Java (J2ME) 22 | .mtj.tmp/ 23 | 24 | # Package Files # 25 | *.jar 26 | *.war 27 | *.nar 28 | *.ear 29 | *.zip 30 | *.tar.gz 31 | *.rar 32 | 33 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 34 | hs_err_pid* 35 | 36 | ### JetBrains template 37 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm 38 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 39 | 40 | # User-specific stuff 41 | .idea/**/workspace.xml 42 | .idea/**/tasks.xml 43 | .idea/**/dictionaries 44 | .idea/**/shelf 45 | 46 | # Sensitive or high-churn files 47 | .idea/**/dataSources/ 48 | .idea/**/dataSources.ids 49 | .idea/**/dataSources.local.xml 50 | .idea/**/sqlDataSources.xml 51 | .idea/**/dynamic.xml 52 | .idea/**/uiDesigner.xml 53 | .idea/**/dbnavigator.xml 54 | 55 | # Gradle 56 | .idea/**/gradle.xml 57 | .idea/**/libraries 58 | 59 | # CMake 60 | cmake-build-debug/ 61 | cmake-build-release/ 62 | 63 | # Mongo Explorer plugin 64 | .idea/**/mongoSettings.xml 65 | 66 | # File-based project format 67 | *.iws 68 | 69 | # IntelliJ 70 | out/ 71 | 72 | # mpeltonen/sbt-idea plugin 73 | .idea_modules/ 74 | 75 | # JIRA plugin 76 | atlassian-ide-plugin.xml 77 | 78 | # Cursive Clojure plugin 79 | .idea/replstate.xml 80 | 81 | # Crashlytics plugin (for Android Studio and IntelliJ) 82 | com_crashlytics_export_strings.xml 83 | crashlytics.properties 84 | crashlytics-build.properties 85 | fabric.properties 86 | 87 | # Editor-based Rest Client 88 | .idea/httpRequests 89 | 90 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/kickStart/RoundD2020AlienPiano.java: -------------------------------------------------------------------------------- 1 | package com.jyami.kickStart; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStreamReader; 6 | 7 | /** 8 | * Created by jyami on 2020/07/12 9 | */ 10 | public class RoundD2020AlienPiano { 11 | 12 | public static void main(String[] args) throws IOException { 13 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 14 | StringBuilder sb = new StringBuilder(); 15 | int testCase = Integer.parseInt(br.readLine()); 16 | for (int i = 0; i < testCase; i++) { 17 | 18 | int n = Integer.parseInt(br.readLine()); 19 | String[] s = br.readLine().split(" "); 20 | int[] collect = new int[n]; 21 | for (int j = 0; j < n; j++) { 22 | collect[j] = Integer.parseInt(s[j]); 23 | } 24 | 25 | sb.append(alienPiano(i + 1, collect)).append("\n"); 26 | } 27 | System.out.println(sb); 28 | } 29 | 30 | public static String alienPiano(int caseNum, int[] nums) { 31 | int[] result = new int[nums.length]; 32 | result[0] = 0; 33 | 34 | int count = 0; 35 | int min = 0, max = 0; 36 | 37 | for (int i = 1; i < nums.length; i++) { 38 | int compare = Integer.compare(nums[i], nums[i - 1]); 39 | result[i] = result[i - 1] + compare; 40 | 41 | if (result[i] < min) 42 | min = result[i]; 43 | if (result[i] > max) 44 | max = result[i]; 45 | if (max - min > 3) { 46 | count++; 47 | min = result[i]; 48 | max = result[i]; 49 | } 50 | 51 | } 52 | 53 | return String.format("Case #%d: %d", caseNum, count); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/kickStart/RoundD2020RecordBreaker.java: -------------------------------------------------------------------------------- 1 | package com.jyami.kickStart; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStreamReader; 6 | 7 | 8 | /** 9 | * Created by jyami on 2020/07/12 10 | */ 11 | public class RoundD2020RecordBreaker { 12 | 13 | public static void main(String[] args) throws IOException { 14 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 15 | StringBuilder sb = new StringBuilder(); 16 | int testCase = Integer.parseInt(br.readLine()); 17 | for (int i = 0; i < testCase; i++) { 18 | sb.append(recordBreaker(i + 1, br)).append("\n"); 19 | } 20 | System.out.println(sb); 21 | } 22 | 23 | public static String recordBreaker(int caseNum, BufferedReader br) throws IOException { 24 | int n = Integer.parseInt(br.readLine()); 25 | String[] s = br.readLine().split(" "); 26 | int[] collect = new int[n]; 27 | for (int i = 0; i < n; i++) { 28 | collect[i] = Integer.parseInt(s[i]); 29 | } 30 | 31 | int count = 0; 32 | int max = collect[0]; 33 | int size = collect.length; 34 | 35 | if (size == 1) { 36 | count++; 37 | } 38 | 39 | if (size > 1 && max > collect[1]) { 40 | count++; 41 | } 42 | 43 | for (int i = 1; i < size - 1; i++) { 44 | if (max < collect[i] && collect[i] > collect[i + 1]) { 45 | count++; 46 | } 47 | if (collect[i] > max) { 48 | max = collect[i]; 49 | } 50 | } 51 | if (size > 1 && max < collect[size - 1]) { 52 | count++; 53 | } 54 | 55 | return String.format("Case #%d: %d", caseNum, count); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/exam/codility/Naver_Intern_Codility_2.java: -------------------------------------------------------------------------------- 1 | package com.jyami.exam.codility; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.stream.Collectors; 6 | 7 | /** 8 | * Created by jyami on 2020/01/10 9 | */ 10 | public class Naver_Intern_Codility_2 { 11 | public static void main(String[] args) { 12 | String[] s = { 13 | "aaaaa aaaaa aaa a", 14 | "aaaaa a aaaaa a aaaaa", 15 | "a a a a", 16 | "aaa aaaaa aaa aaaaa aaaaaa a aaa aaaaaaaaaaaa", 17 | "aaa aaaaa aaa aaaaa aaaaaa a aaa", 18 | "aaa aaaaa aaa aaaaa aaaaaa a", 19 | "aaa aaaaa aaa aaaaa aaaaaa", 20 | "aaa aaaaa aaa aaaaa", 21 | "aaa aaaaa aaa", 22 | }; 23 | int[] k= { 24 | 5, 7, 1, 12, 25 | 12, 12,12,12,12}; 26 | for(int i =0; i collect = Arrays.stream(s) 37 | .map(String::length) 38 | .collect(Collectors.toList()); 39 | 40 | int sum = collect.get(0); 41 | int result =1; 42 | for(int i =1 ;i < collect.size(); i++){ 43 | if(sum + collect.get(i) + 1 <= K){ 44 | sum = sum + collect.get(i) + 1; 45 | }else { 46 | sum = collect.get(i); 47 | } 48 | if(sum == collect.get(i)){ 49 | result++; 50 | } 51 | } 52 | 53 | return result; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_1406.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStreamReader; 6 | import java.util.Stack; 7 | 8 | public class Main_1406 { 9 | 10 | static Stack left = new Stack<>(); 11 | static Stack right = new Stack<>(); 12 | 13 | static BufferedReader bp = new BufferedReader(new InputStreamReader(System.in)); 14 | 15 | public static void main(String[] args) throws IOException { 16 | String input = bp.readLine(); 17 | 18 | for (int i = 0; i < input.length(); i++) { 19 | left.push(input.charAt(i)); 20 | } 21 | 22 | int t = Integer.parseInt(bp.readLine()); 23 | 24 | for (int i = 0; i < t; i++) { 25 | command(bp.readLine()); 26 | } 27 | while (!left.empty()) { 28 | Character pop = left.pop(); 29 | right.push(pop); 30 | } 31 | while (!right.empty()) { 32 | System.out.print(right.pop()); 33 | } 34 | } 35 | 36 | public static void command(String str) { 37 | switch (str) { 38 | case "L": 39 | if (!left.empty()) { 40 | Character text = left.pop(); 41 | right.push(text); 42 | } 43 | break; 44 | case "D": 45 | if (!right.empty()) { 46 | Character text = right.pop(); 47 | left.push(text); 48 | } 49 | break; 50 | case "B": 51 | if (!left.empty()) { 52 | left.pop(); 53 | } 54 | break; 55 | default: 56 | char text = str.split(" ")[1].charAt(0); 57 | left.push(text); 58 | break; 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /src/main/java/com/jyami/exam/programmers/Programmers_LevelTest1_2.java: -------------------------------------------------------------------------------- 1 | package com.jyami.exam.programmers; 2 | 3 | public class Programmers_LevelTest1_2 { 4 | public static void main(String args[]) { 5 | int n = 5; 6 | int[] lost = {2, 4}; 7 | int[] reserve = {1, 3, 5}; 8 | 9 | Solution solution = new Solution(); 10 | int solution1 = solution.solution(n, lost, reserve); 11 | System.out.println(solution1); 12 | 13 | } 14 | 15 | 16 | static class Solution { 17 | public int solution(int n, int[] lost, int[] reserve) { 18 | int answer = 0; 19 | 20 | int[] result = new int[n + 1]; 21 | 22 | for (int i = 0; i < lost.length; i++) { 23 | for (int j = 0; j < reserve.length; j++) { 24 | if(lost[i] == reserve[j]){ 25 | lost[i] = -1; 26 | reserve[j] = -1; 27 | } 28 | } 29 | } 30 | 31 | for (int i = 0; i < lost.length; i++) { 32 | if(lost[i] == -1){ 33 | continue; 34 | } 35 | result[lost[i]] = 1; 36 | answer++; 37 | } 38 | 39 | for (int i = 0; i < reserve.length; i++) { 40 | int index = reserve[i]; 41 | if(index == -1){ 42 | continue; 43 | } 44 | if (index != 0 && result[index - 1] == 1) { 45 | result[index - 1] = 0; 46 | answer--; 47 | continue; 48 | } else if (index != n && result[index + 1] == 1) { 49 | result[index + 1] = 0; 50 | answer--; 51 | continue; 52 | } 53 | } 54 | 55 | return n - answer; 56 | } 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/kickStart/RoundF2019TeachMe2.java: -------------------------------------------------------------------------------- 1 | package com.jyami.kickStart; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Scanner; 6 | 7 | public class RoundF2019TeachMe2 { 8 | public static Scanner sc; 9 | 10 | public static void main(String args[]) { 11 | sc = new Scanner(System.in); 12 | int testCase = sc.nextInt(); 13 | 14 | StringBuilder sb = new StringBuilder(); 15 | 16 | for (int i = 0; i < testCase; i++) { 17 | int teacherNumber = sc.nextInt(); 18 | int skillMax = sc.nextInt(); 19 | 20 | List> teachers = new ArrayList<>(); 21 | 22 | for (int j = 0; j < teacherNumber; j++) { 23 | int skillNumberSize = sc.nextInt(); 24 | List skillNumber = new ArrayList<>(); 25 | for (int k = 0; k < skillNumberSize; k++) { 26 | skillNumber.add(sc.nextInt()); 27 | } 28 | teachers.add(skillNumber); 29 | } 30 | 31 | int count = 0; 32 | 33 | for (int j = 0; j < teacherNumber; j++) { 34 | List t1 = teachers.get(i); 35 | for (int k = 0; k < teacherNumber; k++) { 36 | List t2 = teachers.get(j); 37 | if (t1.equals(t2)) 38 | continue; 39 | List skillNumberA = new ArrayList<>(t1); 40 | List skillNumberB = new ArrayList<>(t2); 41 | skillNumberA.removeAll(skillNumberB); 42 | if (skillNumberA.size() != 0) { 43 | count++; 44 | } 45 | } 46 | } 47 | 48 | sb.append("Case #" + (i + 1) + ": " + count + "\n"); 49 | } 50 | 51 | System.out.println(sb); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/programmers/sort/MostBigNumber.java: -------------------------------------------------------------------------------- 1 | package com.jyami.programmers.sort; 2 | 3 | import java.util.*; 4 | import java.util.stream.Collectors; 5 | 6 | /** 7 | * Created by jyami on 2020/01/06 8 | * 가장 큰 수 9 | * https://programmers.co.kr/learn/courses/30/lessons/42746 10 | */ 11 | public class MostBigNumber { 12 | 13 | public static void main(String[] args) { 14 | Solution solution = new Solution(); 15 | 16 | int[] ar = {40,403}; 17 | 18 | String sol = solution.solution(ar); 19 | System.out.println(sol); 20 | 21 | int[][] array = {{1,2,3}, 22 | {6,10,2}, 23 | {3, 30, 34, 5, 9}, 24 | {998,9,999}, 25 | {20,200,20}, 26 | {12,121}, 27 | {0,0,0}, 28 | {10,100,1000}}; 29 | 30 | for(int[] arr : array){ 31 | String solution1 = solution.solution(arr); 32 | System.out.println(solution1); 33 | } 34 | 35 | } 36 | 37 | static class Solution { 38 | public String solution(int[] numbers) { 39 | StringBuilder sb = new StringBuilder(); 40 | List collect = Arrays.stream(numbers) 41 | .mapToObj(String::valueOf) 42 | .sorted(new BigComparator()) 43 | .collect(Collectors.toList()); 44 | 45 | if(collect.get(0).startsWith("0")){ 46 | return "0"; 47 | } 48 | for(String i : collect){ 49 | sb.append(i); 50 | } 51 | return sb.toString(); 52 | } 53 | 54 | 55 | class BigComparator implements Comparator { 56 | @Override 57 | public int compare(String o1, String o2) { 58 | String l1 = o1 + o2; 59 | String l2 = o2 + o1; 60 | return l2.compareTo(l1); 61 | } 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/baekjoon/Main_1260.java: -------------------------------------------------------------------------------- 1 | package com.jyami.baekjoon; 2 | 3 | import java.util.*; 4 | 5 | public class Main_1260 { 6 | 7 | public static ArrayList[] adj; 8 | public static Queue q; 9 | 10 | public static boolean[] dfs_visite; 11 | public static boolean[] bfs_visite; 12 | 13 | public static void main(String[] args){ 14 | Scanner sc = new Scanner(System.in); 15 | int node = sc.nextInt(); 16 | int edge = sc.nextInt(); 17 | int start = sc.nextInt(); 18 | 19 | adj = (ArrayList[])new ArrayList[node+1]; 20 | for(int i=1; i<=node; i++){ 21 | adj[i] = new ArrayList<>(); 22 | } 23 | q = new LinkedList<>(); 24 | 25 | for(int i =0; i stack = new ArrayList(); 9 | static int top; 10 | 11 | public static void push(int num) { 12 | stack.add(num); 13 | top++; 14 | } 15 | 16 | public static int pop() { 17 | if (top != -1) { 18 | return stack.remove(top--); 19 | } 20 | return -1; 21 | 22 | } 23 | 24 | public static int isEmpty() { 25 | if (stack.size() == 0) { 26 | return 1; 27 | } 28 | return 0; 29 | } 30 | 31 | public static int top() { 32 | if (top != -1) 33 | return stack.get(top); 34 | return -1; 35 | } 36 | 37 | public static void main(String args[]) { 38 | int input, number; 39 | String command; 40 | Scanner in = new Scanner(System.in); 41 | input = in.nextInt(); 42 | top = -1; 43 | for (int i = 0; i < input; i++) { 44 | command = in.next(); 45 | switch (command) { 46 | case "push": 47 | number = in.nextInt(); 48 | push(number); 49 | break; 50 | case "size": 51 | stringBuilder.append(stack.size()).append("\n"); 52 | break; 53 | case "empty": 54 | stringBuilder.append(isEmpty()).append("\n"); 55 | break; 56 | case "pop": 57 | stringBuilder.append(pop()).append("\n"); 58 | break; 59 | case "top": 60 | stringBuilder.append(top()).append("\n"); 61 | break; 62 | } 63 | } 64 | System.out.print(stringBuilder.toString()); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/jyami/leetCode/problem/Solution662.java: -------------------------------------------------------------------------------- 1 | package com.jyami.leetCode.problem; 2 | 3 | import java.util.LinkedList; 4 | import java.util.Queue; 5 | 6 | /** 7 | * Created by jyami on 2020/07/10 8 | */ 9 | public class Solution662 { 10 | 11 | static class Node { 12 | private TreeNode treeNode; 13 | private int index; 14 | 15 | public Node(TreeNode treeNode, int index) { 16 | this.treeNode = treeNode; 17 | this.index = index; 18 | } 19 | } 20 | 21 | public int widthOfBinaryTree(TreeNode root) { 22 | Queue queue = new LinkedList<>(); 23 | queue.offer(new Node(root, 1)); 24 | int result = 0; 25 | while (!queue.isEmpty()) { 26 | int size = queue.size(); 27 | int min = 0, max = 0; 28 | for (int i = 0; i < size; i++) { 29 | Node node = queue.poll(); 30 | if (i == 0) { 31 | min = node.index; 32 | } 33 | if (i == size - 1) { 34 | max = node.index; 35 | } 36 | if (node.treeNode.left != null) { 37 | queue.offer(new Node(node.treeNode.left, node.index * 2)); 38 | } 39 | if (node.treeNode.right != null) { 40 | queue.offer(new Node(node.treeNode.right, node.index * 2 + 1)); 41 | } 42 | } 43 | result = Math.max(result, max - min); 44 | } 45 | return result + 1; 46 | } 47 | 48 | public static void main(String[] args) { 49 | // TreeNode root = new TreeNode(1, new TreeNode(3, new TreeNode(5), null), new TreeNode(2)); 50 | TreeNode root = new TreeNode(1, 51 | new TreeNode(3, new TreeNode(5, new TreeNode(6), null), null), 52 | new TreeNode(2, null, new TreeNode(9, null, new TreeNode(7)))); 53 | System.out.println(new Solution662().widthOfBinaryTree(root)); 54 | } 55 | 56 | } 57 | --------------------------------------------------------------------------------