From aa47bc1ccd543e6a6d62ad804c08013007c816b3 Mon Sep 17 00:00:00 2001 From: tonic523 Date: Fri, 28 Jun 2024 08:51:23 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=EB=8B=A4=EB=8B=A8=EA=B3=84=20?= =?UTF-8?q?=EC=B9=AB=EC=86=94=20=ED=8C=90=EB=A7=A4=20=ED=92=80=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...3\354\206\224 \355\214\220\353\247\244.md" | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 "\354\265\234\354\232\260\354\204\235/\353\213\244\353\213\250\352\263\204 \354\271\253\354\206\224 \355\214\220\353\247\244.md" diff --git "a/\354\265\234\354\232\260\354\204\235/\353\213\244\353\213\250\352\263\204 \354\271\253\354\206\224 \355\214\220\353\247\244.md" "b/\354\265\234\354\232\260\354\204\235/\353\213\244\353\213\250\352\263\204 \354\271\253\354\206\224 \355\214\220\353\247\244.md" new file mode 100644 index 0000000..015ef15 --- /dev/null +++ "b/\354\265\234\354\232\260\354\204\235/\353\213\244\353\213\250\352\263\204 \354\271\253\354\206\224 \355\214\220\353\247\244.md" @@ -0,0 +1,51 @@ +# 다단계 칫솔 판매 + +```kotlin +class Solution { + fun solution(enroll: Array, referral: Array, seller: Array, amount: IntArray): IntArray { + var answer: IntArray = intArrayOf() + + val employees = mutableListOf() + + for (i in 0 until enroll.size) { + val referralEmployee = employees.find { it.name == referral[i] } + if (referralEmployee == null) { + employees.add(Employee(enroll[i], null)) + continue + } + employees.add(Employee(enroll[i], referralEmployee)) + } + + for (i in 0 until seller.size) { + val employee = employees.find { it.name == seller[i] } + employee!!.sell(amount[i] * 100) + } + + return employees.map { it.profit }.toIntArray() + } +} + +class Employee( + val name: String, + val referralEmployee: Employee?, + var profit: Int = 0 +) { + + fun sell(profit: Int) { + val interest = profit / 10 + + if (interest == 0) { + this.profit += profit + return + } + + this.profit += profit - interest + + if (referralEmployee != null) { + referralEmployee.sell(interest) + } + } +} + + +``` \ No newline at end of file From 12cb600c328d3a436147defeedaed7e03c1f30c9 Mon Sep 17 00:00:00 2001 From: tonic523 Date: Fri, 28 Jun 2024 08:52:20 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=EA=B0=80=EC=9E=A5=20=EA=B8=B4=20?= =?UTF-8?q?=ED=8C=B0=EB=A6=B0=EB=93=9C=EB=A1=AC=20=ED=92=80=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...60\353\246\260\353\223\234\353\241\254.md" | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 "\354\265\234\354\232\260\354\204\235/\352\260\200\354\236\245 \352\270\264 \355\214\260\353\246\260\353\223\234\353\241\254.md" diff --git "a/\354\265\234\354\232\260\354\204\235/\352\260\200\354\236\245 \352\270\264 \355\214\260\353\246\260\353\223\234\353\241\254.md" "b/\354\265\234\354\232\260\354\204\235/\352\260\200\354\236\245 \352\270\264 \355\214\260\353\246\260\353\223\234\353\241\254.md" new file mode 100644 index 0000000..48cd449 --- /dev/null +++ "b/\354\265\234\354\232\260\354\204\235/\352\260\200\354\236\245 \352\270\264 \355\214\260\353\246\260\353\223\234\353\241\254.md" @@ -0,0 +1,50 @@ +# 가장 긴 팰린드롬 + +```kotlin +import kotlin.math.* + +class Solution { + fun solution(s: String): Int { + var answer = 0 + + for ((i, c) in s.withIndex()) { + answer = max(answer, palindrome(s, i, c)) + } + + return answer + } + + fun palindrome(s: String, i: Int, c: Char): Int { + var t = 1 + + var twinLength = 1 + while (0 <= i - t && i + t < s.length && s[i - t] == s[i + t]) { + t += 1 + twinLength += 2 + } + + t = 1 + var rightLength = 1 + while (i + t < s.length && s[i + t] == c) { + t += 1 + rightLength += 1 + } + + var result = max(twinLength, rightLength) + + var twinLength2 = 2 + if (i + t < s.length && s[i + 1] == c) { + t = 1 + var l_i = i + var r_i = i + 1 + while (0 <= l_i - t && r_i + t < s.length && s[l_i - t] == s[r_i + t]) { + t += 1 + twinLength2 += 2 + } + result = max(result, twinLength2) + } + + return result + } +} +``` \ No newline at end of file