Skip to content

[재영] 가장 긴 팰린드롬, 다단계 칫솔 판매 #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions 황재영/가장 긴 팰린드롬.md
Original file line number Diff line number Diff line change
@@ -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;
}
```
60 changes: 60 additions & 0 deletions 황재영/다단계 칫솔 판매.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
```kt

class Solution {
val revenue: MutableMap<String, Int> = mutableMapOf();
val graph: MutableMap<String, String> = mutableMapOf();

fun solution(
enroll: Array<String>,
referral: Array<String>,
seller: Array<String>,
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);
}
}
}
```