diff --git "a/\355\231\251\354\236\254\354\230\201/\352\260\200\354\236\245 \352\270\264 \355\214\260\353\246\260\353\223\234\353\241\254.md" "b/\355\231\251\354\236\254\354\230\201/\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..c061f89 --- /dev/null +++ "b/\355\231\251\354\236\254\354\230\201/\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,37 @@ +```js +const getPalindromeLength = (str, leftStart, rightStart) => { + let cnt = 0; + + let left = leftStart; + let right = rightStart; + + while (left >= 0 && right < str.length) { + const leftStr = str[left]; + const rightStr = str[right]; + + if (leftStr !== rightStr) { + break; + } + + cnt += left === right ? 1 : 2; + left -= 1; + right += 1; + } + + return cnt; +}; + +function solution(s) { + let answer = 0; + + for (let start = 0; start < s.length; start += 1) { + answer = Math.max( + answer, + getPalindromeLength(s, start, start), + getPalindromeLength(s, start, start + 1) + ); + } + + return answer; +} +``` diff --git "a/\355\231\251\354\236\254\354\230\201/\353\213\244\353\213\250\352\263\204 \354\271\253\354\206\224 \355\214\220\353\247\244.md" "b/\355\231\251\354\236\254\354\230\201/\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..d461076 --- /dev/null +++ "b/\355\231\251\354\236\254\354\230\201/\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,60 @@ +```kt + +class Solution { + val revenue: MutableMap = mutableMapOf(); + val graph: MutableMap = mutableMapOf(); + + fun solution( + enroll: Array, + referral: Array, + seller: Array, + amount: IntArray + ): IntArray { + var answer: IntArray = IntArray(enroll.size); + + for (i in enroll.indices) { + val from = enroll[i]; + val to = referral[i]; + + graph.set(from, to); + revenue.set(from, 0); + } + + for (i in seller.indices) { + calculate(seller[i], amount[i] * 100) + } + + for (i in enroll.indices) { + answer[i] = revenue.get(enroll[i]) ?: 0 + } + + return answer + } + + fun getFee(money: Int): Int { + if (money < 10) { + return 0; + } + + return money / 10 + } + + fun calculate( + seller: String, + amount: Int + ) { + val to = graph.get(seller); + + val fee: Int = getFee(amount); + val exceptForFee: Int = amount - fee; + + revenue.set(seller, (revenue.get(seller) ?: 0) + exceptForFee); + + if (to == "-" || fee < 1) return; + + if (to != null) { + calculate(to, fee); + } + } +} +```