From b74254e33f2018c59824d5dde00315b3add28d73 Mon Sep 17 00:00:00 2001 From: Dongho Gang Date: Thu, 26 May 2022 16:01:07 +0900 Subject: [PATCH 01/10] =?UTF-8?q?feat:=20=EA=B0=80=EC=9E=A5=20=ED=81=B0=20?= =?UTF-8?q?=EC=88=98=20=ED=92=80=EC=9D=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\236\245 \355\201\260 \354\210\230.kt" | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 "src/2week/dongho/\352\260\200\354\236\245 \355\201\260 \354\210\230.kt" diff --git "a/src/2week/dongho/\352\260\200\354\236\245 \355\201\260 \354\210\230.kt" "b/src/2week/dongho/\352\260\200\354\236\245 \355\201\260 \354\210\230.kt" new file mode 100644 index 0000000..f0679c6 --- /dev/null +++ "b/src/2week/dongho/\352\260\200\354\236\245 \355\201\260 \354\210\230.kt" @@ -0,0 +1,21 @@ +package `2week`.dongho + +class Solution { + companion object { + fun getSolution(): Solution { + return Solution() + } + } + + fun solution(numbers: IntArray): String { + val sort = numbers.sortedWith({ a, b -> (b.toString() + a.toString()).compareTo(a.toString() + b.toString()) }) + val answer = sort.joinToString("") { it.toString() } + return if (answer.first() === '0') "0" else answer + } +} + +fun main() { + val solution = Solution.getSolution() + println(solution.solution(intArrayOf(6, 10, 2))) + println(solution.solution(intArrayOf(3, 30, 34, 5, 9))) +} \ No newline at end of file From e9b184eb6ff7435076d036d7760e7aa7bdca5e2a Mon Sep 17 00:00:00 2001 From: Dongho Gang Date: Fri, 27 May 2022 02:32:40 +0900 Subject: [PATCH 02/10] =?UTF-8?q?code:=20=EC=BD=94=EB=93=9C=20=EC=B5=9C?= =?UTF-8?q?=EC=A0=81=ED=99=94=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\352\260\200\354\236\245 \355\201\260 \354\210\230.kt" | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git "a/src/2week/dongho/\352\260\200\354\236\245 \355\201\260 \354\210\230.kt" "b/src/2week/dongho/\352\260\200\354\236\245 \355\201\260 \354\210\230.kt" index f0679c6..60c5081 100644 --- "a/src/2week/dongho/\352\260\200\354\236\245 \355\201\260 \354\210\230.kt" +++ "b/src/2week/dongho/\352\260\200\354\236\245 \355\201\260 \354\210\230.kt" @@ -8,8 +8,7 @@ class Solution { } fun solution(numbers: IntArray): String { - val sort = numbers.sortedWith({ a, b -> (b.toString() + a.toString()).compareTo(a.toString() + b.toString()) }) - val answer = sort.joinToString("") { it.toString() } + val answer = numbers.sortedWith { a, b -> ("$b$a").compareTo("$a$b") }.joinToString("") { it.toString() } return if (answer.first() === '0') "0" else answer } } From 1e361d8017d661f33fab17aed6e78c8cead02aaf Mon Sep 17 00:00:00 2001 From: Dongho Gang Date: Fri, 27 May 2022 02:50:19 +0900 Subject: [PATCH 03/10] =?UTF-8?q?feat:=20ATM=20=ED=92=80=EC=9D=B4=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/2week/dongho/ATM.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/2week/dongho/ATM.kt diff --git a/src/2week/dongho/ATM.kt b/src/2week/dongho/ATM.kt new file mode 100644 index 0000000..4217fae --- /dev/null +++ b/src/2week/dongho/ATM.kt @@ -0,0 +1,17 @@ +package `2week`.dongho + +import java.io.* +import java.util.* + +fun main() { + val br = BufferedReader(InputStreamReader(System.`in`)) + br.readLine() + val pq = PriorityQueue(br.readLine().split(" ").map { it.toInt() }.toList()) + var temp = 0 + var answer = 0 + while (!pq.isEmpty()) { + temp += pq.poll() + answer += temp + } + println(answer) +} \ No newline at end of file From c5841a15f2c4ce797ffdf2f495e8d32f63db670b Mon Sep 17 00:00:00 2001 From: Dongho Gang Date: Fri, 27 May 2022 03:30:34 +0900 Subject: [PATCH 04/10] =?UTF-8?q?feat:=20=EC=9D=B4=EA=B1=B4=20=EA=BC=AD=20?= =?UTF-8?q?=ED=92=80=EC=96=B4=EC=95=BC=20=ED=95=B4!=20=ED=92=80=EC=9D=B4?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\226\264\354\225\274 \355\225\264!.kt" | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 "src/2week/dongho/\354\235\264\352\261\264 \352\274\255 \355\222\200\354\226\264\354\225\274 \355\225\264!.kt" diff --git "a/src/2week/dongho/\354\235\264\352\261\264 \352\274\255 \355\222\200\354\226\264\354\225\274 \355\225\264!.kt" "b/src/2week/dongho/\354\235\264\352\261\264 \352\274\255 \355\222\200\354\226\264\354\225\274 \355\225\264!.kt" new file mode 100644 index 0000000..576e48d --- /dev/null +++ "b/src/2week/dongho/\354\235\264\352\261\264 \352\274\255 \355\222\200\354\226\264\354\225\274 \355\225\264!.kt" @@ -0,0 +1,20 @@ +package `2week`.dongho + +import java.io.* + +fun main() { + val br = BufferedReader(InputStreamReader(System.`in`)) + val bw = BufferedWriter(OutputStreamWriter(System.out)) + val (_, Q) = br.readLine().split(" ").map { it.toInt() } + val B = br.readLine().split(" ").map { it.toInt() }.sorted() + val Bsum = B.fold(mutableListOf(0)) { prev, next -> + prev.add((prev.lastOrNull() ?: 0) + next) + prev + } + repeat(Q) { + val (L, R) = br.readLine().split(" ").map { it.toInt() } + bw.write("${Bsum.get(R) - Bsum.get(L - 1)}\n") + } + bw.flush() + bw.close() +} \ No newline at end of file From b54587077a33257e3c7942a9d23645bd365dcda7 Mon Sep 17 00:00:00 2001 From: Dongho Gang Date: Sat, 28 May 2022 00:02:41 +0900 Subject: [PATCH 05/10] =?UTF-8?q?feat:=20=EB=82=B4=EB=B6=80=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EB=82=B4=EB=B6=80=EB=A1=9C=20=EC=A0=95?= =?UTF-8?q?=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/2week/dongho/H-index.kt | 31 +++++++++++++++++++ ...\354\236\245 \355\201\260 \354\210\230.kt" | 14 ++++++--- ...4 \354\204\270\354\232\260\352\270\260.kt" | 14 +++++++++ 3 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 src/2week/dongho/H-index.kt create mode 100644 "src/2week/dongho/\354\244\204 \354\204\270\354\232\260\352\270\260.kt" diff --git a/src/2week/dongho/H-index.kt b/src/2week/dongho/H-index.kt new file mode 100644 index 0000000..1e5431e --- /dev/null +++ b/src/2week/dongho/H-index.kt @@ -0,0 +1,31 @@ +package `2week`.dongho + +class `H-index` { + companion object { + fun getSolution(): Solution { + return Solution() + } + } + + class Solution { + fun solution(citations: IntArray): Int { + var answer = 0 + citations.sort() + val length = citations.size + for (i in 0 until length) { + val diff = length - i + val v = citations[i] + if (diff <= v) { + answer = diff + break + } + } + return answer + } + } +} + +fun main() { + val solution = `H-index`.getSolution() + println(solution.solution(intArrayOf(3, 0, 6, 1, 5))) +} \ No newline at end of file diff --git "a/src/2week/dongho/\352\260\200\354\236\245 \355\201\260 \354\210\230.kt" "b/src/2week/dongho/\352\260\200\354\236\245 \355\201\260 \354\210\230.kt" index 60c5081..ace9226 100644 --- "a/src/2week/dongho/\352\260\200\354\236\245 \355\201\260 \354\210\230.kt" +++ "b/src/2week/dongho/\352\260\200\354\236\245 \355\201\260 \354\210\230.kt" @@ -1,20 +1,24 @@ package `2week`.dongho -class Solution { +class `가장 큰 수` { companion object { fun getSolution(): Solution { return Solution() } } - fun solution(numbers: IntArray): String { - val answer = numbers.sortedWith { a, b -> ("$b$a").compareTo("$a$b") }.joinToString("") { it.toString() } - return if (answer.first() === '0') "0" else answer + class Solution { + + fun solution(numbers: IntArray): String { + val answer = numbers.sortedWith { a, b -> ("$b$a").compareTo("$a$b") }.joinToString("") { it.toString() } + return if (answer.first() === '0') "0" else answer + } } + } fun main() { - val solution = Solution.getSolution() + val solution = `가장 큰 수`.getSolution() println(solution.solution(intArrayOf(6, 10, 2))) println(solution.solution(intArrayOf(3, 30, 34, 5, 9))) } \ No newline at end of file diff --git "a/src/2week/dongho/\354\244\204 \354\204\270\354\232\260\352\270\260.kt" "b/src/2week/dongho/\354\244\204 \354\204\270\354\232\260\352\270\260.kt" new file mode 100644 index 0000000..1ed1e51 --- /dev/null +++ "b/src/2week/dongho/\354\244\204 \354\204\270\354\232\260\352\270\260.kt" @@ -0,0 +1,14 @@ +package `2week`.dongho + +import java.io.* +import java.util.* + +fun main() { + val br = BufferedReader(InputStreamReader(System.`in`)) + val bw = BufferedWriter(OutputStreamWriter(System.out)) + val (N, M) = br.readLine().split(" ").map { it.toInt() } + + bw.write("HelloWorld\n") + bw.flush() + bw.close() +} \ No newline at end of file From 0763fd2b6fdbc661d22805427dd3f0c87179ddd3 Mon Sep 17 00:00:00 2001 From: Dongho Gang Date: Sat, 28 May 2022 00:20:59 +0900 Subject: [PATCH 06/10] =?UTF-8?q?feat:=20=EC=A4=84=20=EC=84=B8=EC=9A=B0?= =?UTF-8?q?=EA=B8=B0=20=ED=92=80=EC=9D=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \354\204\270\354\232\260\352\270\260.kt" | 38 +++++++++++++++++-- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git "a/src/2week/dongho/\354\244\204 \354\204\270\354\232\260\352\270\260.kt" "b/src/2week/dongho/\354\244\204 \354\204\270\354\232\260\352\270\260.kt" index 1ed1e51..a896519 100644 --- "a/src/2week/dongho/\354\244\204 \354\204\270\354\232\260\352\270\260.kt" +++ "b/src/2week/dongho/\354\244\204 \354\204\270\354\232\260\352\270\260.kt" @@ -3,12 +3,42 @@ package `2week`.dongho import java.io.* import java.util.* +// 이쪽 풀이 참고하시면 좋을것 같아요 설명 잘되어있음! +// https://blog.naver.com/PostView.nhn?blogId=sweetgirl0111&logNo=222227941751&parentCategoryNo=&categoryNo=&viewDate=&isShowPopularPosts=false&from=postView fun main() { val br = BufferedReader(InputStreamReader(System.`in`)) - val bw = BufferedWriter(OutputStreamWriter(System.out)) val (N, M) = br.readLine().split(" ").map { it.toInt() } - bw.write("HelloWorld\n") - bw.flush() - bw.close() + val indegree = IntArray(N + 1) + val graph: MutableList> = ArrayList() + for (i in 0 until N + 1) { + graph.add(ArrayList()) + } + for (i in 0 until M) { + val (a, b) = br.readLine().split(" ").map { it.toInt() } + graph[a].add(b) + indegree[b]++ + } + + val q: Queue = LinkedList() + val result: Queue = LinkedList() + for (i in 1 until indegree.size) { + if (indegree[i] == 0) { + q.offer(i) + } + } + + var current: Int + while (!q.isEmpty()) { + current = q.poll() + result.offer(current) + for (i in graph[current]) { + indegree[i]-- + if (indegree[i] == 0) { + q.offer(i) + } + } + } + + println(result.map { it.toString() }.joinToString(" ")) } \ No newline at end of file From 160ee481fe3b28e6406ddb7ab63643aad8eae1e7 Mon Sep 17 00:00:00 2001 From: Dongho Gang Date: Sat, 28 May 2022 14:36:37 +0900 Subject: [PATCH 07/10] =?UTF-8?q?feat:=20leetcode=20Non-overlapping=20Inte?= =?UTF-8?q?rvals=20=ED=92=80=EC=9D=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/2week/dongho/Non-overlappingIntervals.kt | 51 ++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/2week/dongho/Non-overlappingIntervals.kt diff --git a/src/2week/dongho/Non-overlappingIntervals.kt b/src/2week/dongho/Non-overlappingIntervals.kt new file mode 100644 index 0000000..bf90a61 --- /dev/null +++ b/src/2week/dongho/Non-overlappingIntervals.kt @@ -0,0 +1,51 @@ +package `2week`.dongho + +class `Non-overlappingIntervals` { + companion object { + fun getSolution(): Solution { + return Solution() + } + } + + class Solution { + fun eraseOverlapIntervals(intervals: Array): Int { + var connectedCount = 1 + val length = intervals.size + intervals.sortWith(Comparator { a: IntArray, b: IntArray -> a[1] - b[1] }) + var prevEnd = intervals.first().get(1) + for (i in 1 until length) { + val (start, end) = intervals.get(i) + if (prevEnd <= start) { + prevEnd = end + connectedCount++ + } + } + return length - connectedCount + } + } +} + +fun main() { + val solution = `Non-overlappingIntervals`.getSolution() + println(solution.eraseOverlapIntervals(arrayOf( + intArrayOf(1, 2), + intArrayOf(2, 3), + intArrayOf(3, 4), + intArrayOf(1, 3) + ))) + println(solution.eraseOverlapIntervals(arrayOf( + intArrayOf(1, 2), + intArrayOf(1, 2), + intArrayOf(1, 2) + ))) + println(solution.eraseOverlapIntervals(arrayOf( + intArrayOf(1, 2), + intArrayOf(2, 3), + ))) + println(solution.eraseOverlapIntervals(arrayOf( + intArrayOf(1, 100), + intArrayOf(11, 22), + intArrayOf(1, 11), + intArrayOf(2, 12), + ))) +} \ No newline at end of file From 1d9e09c243b2114f1adfc40105a397043a45abb4 Mon Sep 17 00:00:00 2001 From: Dongho Gang Date: Sat, 28 May 2022 14:42:09 +0900 Subject: [PATCH 08/10] =?UTF-8?q?feat:=20=ED=98=84=EC=88=98=EB=8B=98=20?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\354\244\204 \354\204\270\354\232\260\352\270\260.kt" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/src/2week/dongho/\354\244\204 \354\204\270\354\232\260\352\270\260.kt" "b/src/2week/dongho/\354\244\204 \354\204\270\354\232\260\352\270\260.kt" index a896519..8bb2d57 100644 --- "a/src/2week/dongho/\354\244\204 \354\204\270\354\232\260\352\270\260.kt" +++ "b/src/2week/dongho/\354\244\204 \354\204\270\354\232\260\352\270\260.kt" @@ -29,7 +29,7 @@ fun main() { } var current: Int - while (!q.isEmpty()) { + while (q.isNotEmpty()) { current = q.poll() result.offer(current) for (i in graph[current]) { From ca63814265f55d1c4739af3e87a9c5dea11dbb30 Mon Sep 17 00:00:00 2001 From: Dongho Gang Date: Sat, 28 May 2022 14:42:28 +0900 Subject: [PATCH 09/10] =?UTF-8?q?feat:=20joinToString=20=EB=82=B4=EC=97=90?= =?UTF-8?q?=20toString=20=ED=8F=AC=ED=95=A8=EB=90=98=EC=96=B4=EC=9E=88?= =?UTF-8?q?=EC=9D=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\352\260\200\354\236\245 \355\201\260 \354\210\230.kt" | 2 +- .../\354\244\204 \354\204\270\354\232\260\352\270\260.kt" | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git "a/src/2week/dongho/\352\260\200\354\236\245 \355\201\260 \354\210\230.kt" "b/src/2week/dongho/\352\260\200\354\236\245 \355\201\260 \354\210\230.kt" index ace9226..8f9bdcb 100644 --- "a/src/2week/dongho/\352\260\200\354\236\245 \355\201\260 \354\210\230.kt" +++ "b/src/2week/dongho/\352\260\200\354\236\245 \355\201\260 \354\210\230.kt" @@ -10,7 +10,7 @@ class `가장 큰 수` { class Solution { fun solution(numbers: IntArray): String { - val answer = numbers.sortedWith { a, b -> ("$b$a").compareTo("$a$b") }.joinToString("") { it.toString() } + val answer = numbers.sortedWith { a, b -> ("$b$a").compareTo("$a$b") }.joinToString("") return if (answer.first() === '0') "0" else answer } } diff --git "a/src/2week/dongho/\354\244\204 \354\204\270\354\232\260\352\270\260.kt" "b/src/2week/dongho/\354\244\204 \354\204\270\354\232\260\352\270\260.kt" index 8bb2d57..2c18176 100644 --- "a/src/2week/dongho/\354\244\204 \354\204\270\354\232\260\352\270\260.kt" +++ "b/src/2week/dongho/\354\244\204 \354\204\270\354\232\260\352\270\260.kt" @@ -40,5 +40,5 @@ fun main() { } } - println(result.map { it.toString() }.joinToString(" ")) + println(result.joinToString(" ")) } \ No newline at end of file From 79f45762bb5b54dbaf5da5678db3a47ecf2775af Mon Sep 17 00:00:00 2001 From: Dongho Gang Date: Sat, 28 May 2022 14:58:56 +0900 Subject: [PATCH 10/10] =?UTF-8?q?feat:=20sort=20by=EB=A1=9C=20=EB=8D=94=20?= =?UTF-8?q?=EC=89=BD=EA=B2=8C=20=ED=92=80=20=EC=88=98=20=EC=9E=88=EC=9D=8C?= =?UTF-8?q?!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/2week/dongho/Non-overlappingIntervals.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/2week/dongho/Non-overlappingIntervals.kt b/src/2week/dongho/Non-overlappingIntervals.kt index bf90a61..38129da 100644 --- a/src/2week/dongho/Non-overlappingIntervals.kt +++ b/src/2week/dongho/Non-overlappingIntervals.kt @@ -11,7 +11,8 @@ class `Non-overlappingIntervals` { fun eraseOverlapIntervals(intervals: Array): Int { var connectedCount = 1 val length = intervals.size - intervals.sortWith(Comparator { a: IntArray, b: IntArray -> a[1] - b[1] }) + intervals.sortBy { it[1] } +// intervals.sortWith(Comparator { a: IntArray, b: IntArray -> a[1] - b[1] }) var prevEnd = intervals.first().get(1) for (i in 1 until length) { val (start, end) = intervals.get(i)