Skip to content

Conversation

@JustDevRae
Copy link
Collaborator

๐Ÿ“Œ ํ‘ผ ๋ฌธ์ œ


๐Ÿ“ ๊ฐ„๋‹จํ•œ ํ’€์ด ๊ณผ์ •

๋ชจ์Šค ๋ถ€ํ˜ธ

๋ชจ์Šค ๋ถ€ํ˜ธ๋ฅผ ํ‚ค, ์•ŒํŒŒ๋ฒณ์„ ๊ฐ’์œผ๋กœ ๊ฐ€์ง€๋Š” morse ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๊ณ , ๊ณต๋ฐฑ์œผ๋กœ ๋‚˜๋ˆ ์ง„ ๋ชจ์Šค ๋ถ€ํ˜ธ ๋ฐฐ์—ด์„ ์ˆœํšŒํ•˜๋ฉด์„œ ํ•ด๋‹น ์•ŒํŒŒ๋ฒณ์„ ์ฐพ์•„ ๊ฒฐ๊ณผ ๋ฌธ์ž์—ด์— ์ถ”๊ฐ€ํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ํ•ด๊ฒฐํ–ˆ์Šต๋‹ˆ๋‹ค.

function solution(letter) {
  var answer = "";
  const morse = {
    ".-": "a",
    "-...": "b",
    "-.-.": "c",
    "-..": "d",
    ".": "e",
    "..-.": "f",
    "--.": "g",
    "....": "h",
    "..": "i",
    ".---": "j",
    "-.-": "k",
    ".-..": "l",
    "--": "m",
    "-.": "n",
    "---": "o",
    ".--.": "p",
    "--.-": "q",
    ".-.": "r",
    "...": "s",
    "-": "t",
    "..-": "u",
    "...-": "v",
    ".--": "w",
    "-..-": "x",
    "-.--": "y",
    "--..": "z",
  };
  const str = letter.split(" ");

  for (const s of str) {
    answer += morse[s];
  }
  return answer;
}

A๋กœ B ๋งŒ๋“ค๊ธฐ

๊ฐ ๋ฌธ์ž์—ด์˜ ๋ฌธ์ž๋ฅผ ์นด์šดํŒ…ํ•˜์—ฌ ๊ฐ์ฒด๋กœ ๋งŒ๋“  ํ›„, ๊ฐ ํ‚ค์™€ ๊ฐ’์„ ๋น„๊ตํ•˜์—ฌ ๋ชจ๋“  ๋ฌธ์ž๊ฐ€ ๋™์ผํ•˜๋ฉด 1, ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด 0์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ํ•ด๊ฒฐํ–ˆ์Šต๋‹ˆ๋‹ค.

function solution(before, after) {
  var answer = 0;
  const beforeCount = {};
  const afterCount = {};

  for (const char of before) {
    beforeCount[char] = (beforeCount[char] || 0) + 1;
  }

  for (const char of after) {
    afterCount[char] = (afterCount[char] || 0) + 1;
  }

  for (const key in beforeCount) {
    if (beforeCount[key] !== afterCount[key]) {
      return (answer = 0);
    }
  }

  return (answer = 1);
}

์ง„๋ฃŒ ์ˆœ์„œ ์ •ํ•˜๊ธฐ

๋ฐฐ์—ด์„ ๋‚ด๋ฆผ์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•˜์—ฌ ๊ฐ ๊ฐ’์˜ ์ˆœ์œ„๋ฅผ ๋งคํ•‘ํ•˜๋Š” Map ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•œ ๋’ค, ์›๋ž˜ ๋ฐฐ์—ด์˜ ๊ฐ ๊ฐ’์— ๋Œ€ํ•ด ์ˆœ์œ„๋ฅผ ์ฐพ์•„ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ํ•ด๊ฒฐํ–ˆ์Šต๋‹ˆ๋‹ค.

function solution(emergency) {
  const sorted = [...emergency].sort((a, b) => b - a);
  const rankMap = new Map();

  sorted.forEach((value, index) => {
    rankMap.set(value, index + 1);
  });

  return emergency.map((value) => rankMap.get(value));
}

๋“ฑ์ˆ˜ ๋งค๊ธฐ๊ธฐ

ํ‰๊ท  ์ ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•œ ๋’ค, ๋‚ด๋ฆผ์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌ๋œ ๋ฐฐ์—ด์„ ์ƒ์„ฑํ•˜๊ณ , ์›๋ž˜ ๋ฐฐ์—ด์˜ ๊ฐ ํ‰๊ท  ์ ์ˆ˜์— ๋Œ€ํ•ด ์ •๋ ฌ๋œ ๋ฐฐ์—ด์—์„œ์˜ ์ˆœ์œ„๋ฅผ ์ฐพ์•„ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ๊ตฌํ˜„ํ–ˆ์Šต๋‹ˆ๋‹ค.

function solution(score) {
  const averages = score.map(([english, math]) => (english + math) / 2);
  const sortedAverages = [...averages].sort((a, b) => b - a);

  return averages.map((avg) => sortedAverages.indexOf(avg) + 1);
}

์™„์ฃผํ•˜์ง€ ๋ชปํ•œ ์„ ์ˆ˜

์ฐธ๊ฐ€์ž ์ด๋ฆ„์˜ ๊ฐœ์ˆ˜๋ฅผ ์„ธ์–ด ๊ฐ์ฒด๋กœ ์ €์žฅํ•œ ๋’ค, ์™„์ฃผํ•œ ์ด๋ฆ„์— ๋Œ€ํ•ด ๊ฐœ์ˆ˜๋ฅผ ์ค„์ด๊ณ , ์ตœ์ข…์ ์œผ๋กœ ๊ฐ’์ด 0๋ณด๋‹ค ํฐ ์ด๋ฆ„์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ๊ตฌํ˜„ํ–ˆ์Šต๋‹ˆ๋‹ค.

function solution(participant, completion) {
  const obj = {};

  for (const p of participant) {
    if (obj[p]) {
      obj[p] += 1;
    } else {
      obj[p] = 1;
    }
  }

  for (const c of completion) {
    obj[c] -= 1;
  }

  for (const key in obj) {
    if (obj[key] > 0) {
      return key;
    }
  }
}

Copy link
Collaborator

@Moonjonghoo Moonjonghoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ค‘๋ณต์„ ์ค„์ด๊ฑฐ๋‚˜ ๊ณ„์‚ฐ๊ณผ์ •์—์„œ ๋ฏธ๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ ๋”ํ•˜๋Š”์‹์œผ๋กœ ์ˆ˜์ •ํ•ด๋ด๋„ ์ข‹์„๊ฑฐ๊ฐ™์•„์š”!
ํ•œ์ฃผ๊ฐ„ ๊ณ ์ƒํ•˜์…จ์Šต๋‹ˆ๋‹ค.

Copy link
Collaborator

@unn04012 unn04012 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ณ ์ƒํ•˜์…จ์Šต๋‹ˆ๋‹ค

@JooKangsan JooKangsan merged commit 8d39ffd into main Feb 6, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants