Skip to content

Conversation

@tkddbs587
Copy link
Collaborator

Queue

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

๋ฌธ์ œ์ด๋ฆ„ ๋ฌธ์ œ๋งํฌ
์ˆœ์„œ์Œ์˜ ๊ฐœ์ˆ˜ https://school.programmers.co.kr/learn/courses/30/lessons/120836
์ ์˜ ์œ„์น˜ ๊ตฌํ•˜๊ธฐ https://school.programmers.co.kr/learn/courses/30/lessons/120841
๋กœ๊ทธ์ธ ์„ฑ๊ณต? https://school.programmers.co.kr/learn/courses/30/lessons/120883
์นด๋“œ ๋ญ‰์น˜ https://school.programmers.co.kr/learn/courses/30/lessons/159994
ํ–„๋ฒ„๊ฑฐ ๋งŒ๋“ค๊ธฐ https://school.programmers.co.kr/learn/courses/30/lessons/133502

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

์ˆœ์„œ์Œ์˜ ๊ฐœ์ˆ˜

function solution(n) {
  let count = 0;

  for (let i = 1; i <= n; i++) {
    if (n % i === 0) {
      // n์˜ ์•ฝ์ˆ˜ ๊ตฌํ•˜๊ธฐ
      count++; // ์•ฝ์ˆ˜ ๊ตฌํ• ๋•Œ๋งˆ๋‹ค ์นด์šดํŠธ์—…
    }
  }

  return count; // ์ˆœ์„œ์Œ ๊ฐฏ์ˆ˜ ๋ฐ˜ํ™˜
}

์ ์˜ ์œ„์น˜ ๊ตฌํ•˜๊ธฐ

function solution(dot) {
  const [x, y] = dot; // x, y ๊ฐ’

  if (Math.sign(x) === 1) {
    // x๊ฐ’์ด ์–‘์ˆ˜์ผ๋•Œ
    if (Math.sign(y) === 1) {
      // y๊ฐ’๋„ ์–‘์ˆ˜๋ฉด
      return 1; // 1์‚ฌ๋ถ„๋ฉด
    } else {
      return 4; // x๊ฐ’์€ ์–‘์ˆ˜๊ณ  y๊ฐ’์€ ์Œ์ˆ˜ -> 4์‚ฌ๋ถ„๋ฉด
    }
  }

  if (Math.sign(x) === -1) {
    // x๊ฐ’์ด ์Œ์ˆ˜์ผ๋•Œ
    if (Math.sign(y) === -1) {
      // y๊ฐ’๋„ ์Œ์ˆ˜๋ฉด
      return 3; // 3์‚ฌ๋ถ„๋ฉด
    } else {
      return 2; // y๊ฐ’์€ ์–‘์ˆ˜๊ณ  x๊ฐ’์€ ์Œ์ˆ˜ -> 2์‚ฌ๋ถ„๋ฉด
    }
  }
}

๋กœ๊ทธ์ธ ์„ฑ๊ณต?

function solution(id_pw, db) {
  const [id, pw] = id_pw; // ์•„์ด๋””, ํŒจ์Šค์›Œ๋“œ ๋ถ„๋ฆฌ
  const map = new Map(db); // db๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ Map ๊ฐ์ฒด ์ƒ์„ฑ
  console.log(map);

  if (map.has(id)) {
    // map ๊ฐ์ฒด์— id ๊ฐ€ ์žˆ์„๋•Œ
    if (map.get(id) === pw) {
      // ์•„์ด๋””์™€ ํŒจ์Šค์›Œ๋“œ๊ฐ€ ์ผ์น˜ํ•˜๋ฉด
      return "login"; // 'login' ๋ฐ˜ํ™˜
    } else return "wrong pw"; // ์•„์ด๋””๋Š” ๊ฐ™์€๋ฐ ํŒจ์Šค์›Œ๋“œ๋งŒ ํ‹€๋ฆฌ๋ฉด 'wrong pw' ๋ฐ˜ํ™˜
  } else return "fail"; // ๋‘˜ ๋‹ค ํ‹€๋ฆฌ๋ฉด 'fail' ๋ฐ˜ํ™˜
}

์นด๋“œ ๋ญ‰์น˜

function solution(cards1, cards2, goal) {
  let index1 = 0; // ์นด๋“œ1์˜ ์ธ๋ฑ์Šค
  let index2 = 0; // ์นด๋“œ2์˜ ์ธ๋ฑ์Šค

  for (let i = 0; i < goal.length; i++) {
    if (cards1[index1] === goal[i]) {
      // ์นด๋“œ1์˜ ์ธ๋ฑ์Šค 0๋ถ€ํ„ฐ ์ˆœ์„œ๋Œ€๋กœ ๊ณจ์˜ ์ธ๋ฑ์Šค i์™€ ๊ฐ™์œผ๋ฉด
      index1++; // ์นด๋“œ 1์˜ ์ธ๋ฑ์Šค 1 ์ฆ๊ฐ€
    } else if (cards2[index2] === goal[i]) {
      // ์นด๋“œ2์˜ ์ธ๋ฑ์Šค 0๋ถ€ํ„ฐ ์ˆœ์„œ๋Œ€๋กœ ๊ณจ์˜ ์ธ๋ฑ์Šค i์™€ ๊ฐ™์œผ๋ฉด
      index2++; // ์นด๋“œ 2์˜ ์ธ๋ฑ์Šค 1 ์ฆ๊ฐ€
    } else return "No"; // ์ˆœ์„œ๋Œ€๋กœ ๋น„๊ตํ•˜๋‹ค๊ฐ€ ๋” ์ด์ƒ ์ผ์น˜ํ•˜๋Š” ์ธ๋ฑ์Šค๊ฐ€ ์—†์œผ๋ฉด ๋งŒ๋“ค ์ˆ˜ ์—†๋Š” ๋ฌธ์žฅ์ด๋ฏ€๋กœ No ๋ฐ˜ํ™˜
  }
  return "Yes"; // goal์˜ ์ธ๋ฑ์Šค๋งŒํผ ์ˆœํšŒ๋ฅผ ์„ฑ๊ณต์ ์œผ๋กœ ๋งˆ์น˜๋ฉด ๋ฌธ์žฅ์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ Yes ๋ฐ˜ํ™˜
}

ํ–„๋ฒ„๊ฑฐ ๋งŒ๋“ค๊ธฐ

function solution(ingredient) {
  let stack = []; // ์Šคํƒ
  let count = 0; // ํ–„๋ฒ„๊ฑฐ ํฌ์žฅ ๊ฐฏ์ˆ˜
  for (let i = 0; i < ingredient.length; i++) {
    stack.push(ingredient[i]); // ingredient ์ธ๋ฑ์Šค ์ˆœ์„œ๋Œ€๋กœ ์Šคํƒ์— ์ถ”๊ฐ€
    if (stack.length >= 4) {
      // ์Šคํƒ์— ์žฌ๋ฃŒ๊ฐ€ 4๊ฐœ ์ด์ƒ ์Œ“์˜€์„๋•Œ
      const hamburger = stack.slice(-4).join(""); // ์Šคํƒ์˜ ๋์—์„œ๋ถ€ํ„ฐ 4๊ฐœ์˜ ์š”์†Œ ๋ฌธ์ž์—ด๋กœ ์ถ”์ถœ

      if (hamburger === "1231") {
        // ์ถ”์ถœํ•œ ๋ฌธ์ž์—ด์ด 1231 ์ˆœ์„œ์™€ ์ผ์น˜ํ•˜๋ฉด
        count++; // ํฌ์žฅ ๊ฐฏ์ˆ˜ 1 ์ฆ๊ฐ€
        stack.splice(-4); // ์Šคํƒ์—์„œ ํฌ์žฅ๋œ ํ–„๋ฒ„๊ฑฐ ์ œ๊ฑฐ
      }
    }
  }
  return count; // ์ด ํฌ์žฅ ๊ฐฏ์ˆ˜ ๋ฐ˜ํ™˜
}

@tkddbs587 tkddbs587 self-assigned this Jan 17, 2025
Copy link
Collaborator

@JooKangsan JooKangsan 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

Choose a reason for hiding this comment

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

function solution(dot) {
  const [x, y] = dot;
  
  switch (true) {
    case (x > 0 && y > 0):
      return 1;
    case (x < 0 && y > 0):
      return 2;
    case (x < 0 && y < 0):
      return 3;
    case (x > 0 && y < 0):
      return 4;
    default:
      throw new Error('Invalid coordinates');
  }
}

์ด๋Ÿฐ์‹์œผ๋กœ ์Šค์œ„์น˜ ๋ฌธ์„ ์‚ฌ์šฉํ•ด์„œ ํ‘œํ—Œํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์žˆ์–ด์š”!

@JooKangsan JooKangsan merged commit 22c3f15 into main Jan 23, 2025
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.

3 participants