230201(μ)
π μ±μ₯μΌμ§ 3.1
μ±
ν볡ν μ΄κΈ°μ£Όμμ(μ¨μΈ λ€μ΄μ΄)
μ λ΄μ©μ μκ·Ήλ°μ μμνλ μλ°ν μ±μ₯κΈ°λ‘
μ΄μμλ κ½κ³Ό μ£½μ κ½μ μ΄λ»κ² ꡬλ³νλκ°?
μ±μ₯νκ³ μλ κ²μ΄ μ΄μ μλ κ²μ΄λ€.
μλͺ μ μ μΌν μ¦κ±°λ μ±μ₯μ΄λ€!
π³ ν€μλ (1.0)
μ΅λν κ°λ¨νκ² μ 리, μΆνμ 보면μ μ€μ€λ‘ μ€λͺ
π κ²½ν μμ£Όλ‘ (2.0)
λ¨μ μ 보λ₯Ό μ λ¬νκΈ°λ³΄λ€ λ¬΄μμ λ°°μ κ³ μ΄λ»κ² ν΄κ²°νλμ§ μ§§κ³ κ°λ¨νκ² μμ±
βοΈ μ ν΄μ§ ν νλ¦Ώμ λ§μΆ°μ (3.0)
ν€μλ, κ²½ν λͺ¨λ μ’λ€. λ€λ§ λ§€μΌ μμ±νκΈ°λ‘ λ§μ λ¨Ήμλ§νΌ ν΅μ¬λ§ κ°κ²°νκ² μ 리ν μ μκ² ν νλ¦Ώμ μμ± (3.1) 230102λΆν° μμλλ νμ΅μ κ΄ν λ΄μ© μΆκ°
π μ€λμ ν€μλ
μ΅λν ν¨μν νλ‘κ·Έλλ°μΌλ‘ μκ³ λ¦¬μ¦ λ¬Έμ νκΈ°
κΈ°μ‘΄μ νμλ μκ³ λ¦¬μ¦ λ¬Έμ λ₯Ό λ€μ ν κΈ°νκ° μκ²Όλ€. λ€μ νΈλ κΉμ νμ μ€ν¬λ¦½νΈ + ν¨μν νλ‘κ·Έλλ°μ μ΅λν μ§ν€λ©΄μ νμ΄λ³΄κΈ°λ‘ νλ€.
μλ‘μ΄ νμ΄
type NumberArray = number[];
const solution = (
array: NumberArray,
commands: NumberArray[],
): NumberArray => {
return commands.map(
(command) =>
array.slice(command[0] - 1, command[1]).sort((a, b) => a - b)[
command[2] - 1
],
);
};
κΈ°μ‘΄ νμ΄
function solution(array, commands) {
let answer = [];
for (let command of commands) {
let arr = new Array(...array);
let i = command[0];
let j = command[1];
let k = command[2];
let tempArr = arr.splice(i - 1, j - i + 1);
tempArr.sort((a,b) => a-b);
let num = tempArr[k - 1];
answer.push(num);
}
return answer;
}
μλ‘μ΄ νμ΄(μ»€λ§ ν¨μ μ¬μ©)
type ChangeString = (word: string) => string;
const changeOddCapital = (word: string): string => {
return [...word]
.map((l, i) => (i % 2 ? l.toLowerCase() : l.toUpperCase()))
.join('');
};
const solutionCurrying =
(fn: ChangeString) =>
(s: string): string => {
return s.split(' ').map(fn).join(' ');
};
const solution = solutionCurrying(changeOddCapital);
κΈ°μ‘΄ νμ΄
function solution(s) {
let words = s.split(' ');
const changeUpperLower = (word) => {
let arrWord = [...word]
for (let i = 0; i < arrWord.length; i++) {
arrWord[i] = i % 2 === 0 ? arrWord[i].toUpperCase() : arrWord[i].toLowerCase();
}
return arrWord.join('');
}
return words.map((word) => changeUpperLower(word)).join(' ');
}
μλ‘μ΄ νμ΄(μ§μ λΆν΄λ 컀λ§μ κ·Ήλν ν΄λ³΄κΈ°)
const solutionCurrying =
(firstPattern: number[]) =>
(secondPattern: number[]) =>
(thirdPattern: number[]) =>
(answers: number[]): number[] => {
const scores = [
answers.filter(
(answer, i) => answer === firstPattern[i % firstPattern.length],
).length,
answers.filter(
(answer, i) => answer === secondPattern[i % secondPattern.length],
).length,
answers.filter(
(answer, i) => answer === thirdPattern[i % thirdPattern.length],
).length,
];
const maxScore = Math.max(...scores);
return scores
.map((score, i) => (score === maxScore ? i + 1 : 0))
.filter((score) => score);
};
let [firstPatterns, secondPatterns, thirdPatterns] = [
[1, 2, 3, 4, 5],
[2, 1, 2, 3, 2, 4, 2, 5],
[3, 3, 1, 1, 2, 2, 4, 4, 5, 5],
];
const solution =
solutionCurrying(firstPatterns)(secondPatterns)(thirdPatterns);
κΈ°μ‘΄ νμ΄
function solution(answers) {
const lengthAns = answers.length;
const first = [1,2,3,4,5];
const second = [2,1,2,3,2,4,2,5];
const third = [3,3,1,1,2,2,4,4,5,5];
const firstAns = new Array(Math.ceil(lengthAns / first.length)).fill(first).flat();
const secondAns = new Array(Math.ceil(lengthAns / second.length)).fill(second).flat();
const thirdAns = new Array(Math.ceil(lengthAns / third.length)).fill(third).flat();
let countFirst = 0;
let countSecond = 0;
let countThird = 0;
for (let i=0; i < lengthAns; i++) {
if (answers[i] === firstAns[i]) {
countFirst++;
}
if (answers[i] === secondAns[i]) {
countSecond++;
}
if (answers[i] === thirdAns[i]) {
countThird++;
}
}
let answer = [];
let temp = [countFirst, countSecond, countThird];
let countMax = Math.max(...temp);
for (let i = 0; i < 3; i++) {
if (temp[i] === countMax) {
answer.push(i+1)
}
}
return answer;
}
μλ‘μ΄ νμ΄
type NumberArray = number[];
type NumberStack = (number | undefined)[];
const solution = (board: NumberArray[], moves: NumberArray): number => {
const stack: NumberStack = [];
let count: number = 0;
const machineStacks: NumberArray[] = new Array(board.length)
.fill(0)
.map((_, i) =>
board.flat().filter((num, j) => num && j % board.length === i),
);
const pickedNums = moves
.map((move) => {
let picked = machineStacks[move - 1].shift();
return picked ? picked : -1;
})
.filter((num) => num >= 0);
pickedNums.forEach((pickedNum) => {
let stackPick = stack.pop();
stackPick === pickedNum ? count++ : stack.push(stackPick, pickedNum);
});
return count * 2;
};
κΈ°μ‘΄ νμ΄
function solution(board, moves) {
let answer = 0;
const n = board.length;
let basket = [];
let moveToIndex = moves.map((move) => move - 1);
for (let move of moveToIndex) {
for (let i = 0; i < n; i++) {
if (board[i][move]) {
if (basket[basket.length - 1] === board[i][move]) {
basket.pop();
board[i][move] = 0;
answer += 2;
break;
} else {
basket.push(board[i][move]);
board[i][move] = 0;
break;
}
}
}
}
return answer;
}
μ°Έκ³ μλ£
- νλ‘κ·Έλλ¨Έμ€ - Kλ²μ§Έ μ
- νλ‘κ·Έλλ¨Έμ€ - μ΄μν λ¬Έμ λ§λ€κΈ°
- νλ‘κ·Έλλ¨Έμ€ - λͺ¨μκ³ μ¬
- νλ‘κ·Έλλ¨Έμ€ - ν¬λ μΈ μΈνλ½κΈ° κ²μ
π μμ½ λ° ν루 κ°λ¨ νκ³
κ³Όκ±°μ μ½λλ μμ£Ό μ€λμ μ μλμ§λ§, μ΄λ κ² νμ¬μ μ½λμ λΉκ΅ν΄λ³΄λ κ°νκ° μλ‘λ€. μκ°λ³΅μ‘λμ λν ν¨μ¨μ±μ ν
μ€νΈν΄λ³Έ κ²μ μλμ§λ§, λͺ©νλ‘ νλ νμ
μ€ν¬λ¦½νΈ + λλ¦μ ν¨μνμΌλ‘ μμ±ν΄μ
μ λ§ κΈ°μλ€. ν¨μν νλ‘κ·Έλλ°μ μ λ§ μ‘°κΈμ΄λΌλ κ³ λ €νλ©΄μ μκ³ λ¦¬μ¦μ μ μ©ν΄λ³Έ κ²½νμ΄ μ λ§ κ°μ§λ€. μμ§ν μ’λ ν¨μν λλμΌλ‘ μμν¨μλ€μ ꡬλΆνκ³ νμ΄νλ₯Ό ꡬμΆνλ―μ΄ νκ³ μΆμλλ°, μμλ μ½μ§λ μμλ€.
μ΄ μ λ 곡λΆνκ³ μ½κ²μ½κ² ν¨μνμ΄ λμ€λ©΄ κ·Έκ²λ μ¬λ―ΈμμΌλκΉ..!
μμΌλ‘λ μκ³ λ¦¬μ¦μ ν λ, μ’λ λ€μν κ΄μ μΌλ‘ μ κ·Όνλλ‘ λ
Έλ ₯ν΄λ΄μΌκ² λ€. μμ§ κ³΅λΆν κ²λ λ§κ³ λμκ° κΈΈλ λ§μ§λ§, μ΄λ κ² μ΄μ μ λμ λΉκ΅ν΄λ³΄λ μλ€λ₯Έ μ¬λ―Έκ° μλ κ² κ°λ€!
μ€λμ μν μ
- μλ²½ 6μμ μΌμ΄λμ ν¬μ€μ₯ λλμ΄ κ°λ€!!!!!!!
- νμ μ€ν¬λ¦½νΈμ λν΄ μ‘°κΈ μ΅μν΄μ§ μ
- ν¨μν νλ‘κ·Έλλ°μΌλ‘ μκ³ λ¦¬μ¦μ μ κ·Όν΄λ³Έ κ²!(κ³ λ―Όν΄λ³΄λ μκ°μ΄ μ λ§ μ’μλ€!)
- μ‘°κΈμ μ§μ λΆνκ³ μ΅μ§μ€λ½μ§λ§ 컀λ§λ μ¨λ³΄λ €νκ³ , νμ€νμ€ ν¨μνμΌλ‘ κ³ λ―Όν΄λ³Έ μκ°μ΄ μ λ§ λ»κΉμλ€.
μ€λμ μμ¬μ΄ μ
- μ€λβ¦ ν β¦ μλ€..! μ€λμ κ·Έλ₯ λ€ μνλ€!!! κ·Έλ κ² μκ°νμ γ γ