Skip to content

Conversation

@bona1122
Copy link
Collaborator

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

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

๋‘ ๊ฐœ ๋ฝ‘์•„์„œ ๋”ํ•˜๊ธฐ

// https://school.programmers.co.kr/learn/courses/30/lessons/68644

const solution = numbers => {
  const set = new Set();
  
  for(let i = 0; i < numbers.length; i++){
      for(let j = i + 1; j <numbers.length; j++){
          const num = numbers[i] + numbers[j]
          set.add(num)
      }
  }
  
  return [...set].sort((a, b) => a - b)
}

์‚ผ์ด์‚ฌ

// https://school.programmers.co.kr/learn/courses/30/lessons/131705

const solution = (number) => {
  // ํ•™์ƒ์€ ๊ฐ์ž ์ •์ˆ˜๋ฒˆํ˜ธ๊ฐ€์ง
  // ์„ธ๋ช…์˜ ๋ฒˆํ˜ธ๋ฅผ ๋”ํ•ด์„œ 0์ด ๋˜๋ฉด ์‚ผ์ด์‚ฌ, ์‚ผ์ด์‚ฌ ๋งŒ๋“œ๋Š” ๊ฐ€์ง“์ˆ˜ ๊ตฌํ•˜๊ธฐ
  let result = 0
  const selected = Array(3).fill(0)
  const dfs = (depth, start) => {
    if (depth === 3) {
      let sum = 0
      for (let i of selected) {
        sum += number[i]
      }
      if (sum === 0) result++
      return
    }
    for (let i = start; i < number.length; i++) {
      selected[depth] = i
      dfs(depth + 1, i + 1)
    }
  }
  dfs(0, 0)
  return result
}

๊ฐ€์žฅ ํฐ ์ˆ˜

// https://school.programmers.co.kr/learn/courses/30/lessons/42746

function solution(numbers) {
  const convertString = numbers.map((number) => number.toString())
  const sorted = convertString.sort((a, b) => {
    const AB = Number(a + b)
    const BA = Number(b + a)
    return BA - AB
  })
  const result = sorted.join("")
  return result[0] === "0" ? "0" : result
}

H-Index

// https://school.programmers.co.kr/learn/courses/30/lessons/42747
// ํ•ต์‹ฌ: ๋…ผ๋ฌธ์„ ์ธ์šฉ ํšŸ์ˆ˜ ๊ธฐ์ค€ ๋‚ด๋ฆผ์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•œ ํ›„,
// ๋…ผ๋ฌธ์˜ ๊ฐœ์ˆ˜(์ธ๋ฑ์Šค+1)๊ฐ€ ํ•ด๋‹น ๋…ผ๋ฌธ์˜ ์ธ์šฉ ํšŸ์ˆ˜๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ตœ๋Œ€ ์ง€์ ์„ ์ฐพ๋Š” ๊ฒƒ

function solution(citations) {
  citations = citations.sort((a, b) => b - a)

  let i = 0 // ํ˜„์žฌ๊นŒ์ง€ ํ™•์ธํ•œ ๋…ผ๋ฌธ์˜ ์ธ๋ฑ์Šค
  // i+1 <= citations[i]๊ฐ€ ์ฐธ์ด๋ฉด:
  // "i+1๋ฒˆ ์ด์ƒ ์ธ์šฉ๋œ ๋…ผ๋ฌธ์ด i+1ํŽธ ์ด์ƒ"์ด๋ผ๋Š” ์˜๋ฏธ
  while (i + 1 <= citations[i]) {
    i++
  }

  return i
}

ํŒŒ์ผ๋ช… ์ •๋ ฌ

// https://school.programmers.co.kr/learn/courses/30/lessons/17686

function solution(files) {
  const regex = /([^0-9]+)([0-9]+)(.*)/
  files = files.map((file, idx) => ({
    name: file,
    parts: file.match(regex),
    originalIndex: idx,
  }))

  files = files.sort((a, b) => {
    {
      // HEAD ๋ถ€๋ถ„ ๋น„๊ต (๋Œ€์†Œ๋ฌธ์ž ๋ฌด์‹œ)
      const headA = a.parts[1].toLowerCase()
      const headB = b.parts[1].toLowerCase()

      if (headA < headB) return -1
      if (headA > headB) return 1

      // HEAD๊ฐ€ ๊ฐ™์œผ๋ฉด NUMBER ๋ถ€๋ถ„ ๋น„๊ต (์ˆซ์ž๋กœ ๋น„๊ต)
      const numberA = Number(a.parts[2])
      const numberB = Number(b.parts[2])

      if (numberA < numberB) return -1
      if (numberA > numberB) return 1

      // HEAD์™€ NUMBER๊ฐ€ ๋ชจ๋‘ ๊ฐ™์œผ๋ฉด ์›๋ž˜ ์ˆœ์„œ ์œ ์ง€
      return a.originalIndex - b.originalIndex
    }
  })

  return files.map((file) => file.name)
}

@bona1122 bona1122 self-assigned this Mar 19, 2025
@bona1122 bona1122 changed the title [Bona1122] 25.03.06 [Bona1122] 25.03.13 Mar 19, 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.

๋งŽ์ด ๋ฐฐ์šฐ๊ณ  ๊ฐ‘๋‹ˆ๋‹ค! ํ•œ์ฃผ๋™์•ˆ ์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค!

Comment on lines +5 to +9
const sorted = convertString.sort((a, b) => {
const AB = Number(a + b)
const BA = Number(b + a)
return BA - AB
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

์ด๋ถ€๋ถ„์€ ์ˆซ์ž๋กœ ๋ณ€๊ฒฝํ•˜์ง€ ์•Š๊ณ  ๋ฌธ์ž์—ด ๋น„๊ต ํ›„ ๋ฐ˜ํ™˜ ํ•ด๋„ ๊ดœ์ฐฎ์„ ๊ฒƒ ๊ฐ™์•„์š”!!

const sorted = convertString.sort((a, b) => (b + a) > (a + b) ? 1 : -1)

Copy link
Collaborator

Choose a reason for hiding this comment

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

์ฝ”๋“œ ์ž˜ ๋ณด์•˜์Šต๋‹ˆ๋‹ค!
selected ๋ฐฐ์—ด ๋Œ€์‹  ์„ ํƒ๋œ ๊ฐ’์˜ ๋ˆ„์ ํ•ฉ์„ ์‹ค์‹œ๊ฐ„์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๊ณ , sum์„ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋„˜๊ธด ๋’ค depth๊ฐ€ 3์ผ ๋•Œ๋งŒ ๋น„๊ตํ•˜๋Š” ๋ฐฉ์‹์€ ์–ด๋–จ๊นŒ์š”?
์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ์ธ๋ฑ์Šค๋ฅผ ๋ฐฐ์—ด์— ์ €์žฅํ•˜๊ณ  ๋‹ค์‹œ ๊ฐ’์„ ๊บผ๋‚ด๋Š” ๊ณผ์ •์„ ์ƒ๋žตํ•  ์ˆ˜ ์žˆ๊ณ , ๋งค๋ฒˆ for๋ฌธ์œผ๋กœ ํ•ฉ์„ ๊ตฌํ•˜์ง€ ์•Š์•„๋„ ๋ผ์š”!

const solution = (number) => {
  let result = 0
  const dfs = (depth, start, sum) => {
    if (depth === 3) {
      if (sum === 0) result++
      return
    }
    for (let i = start; i < number.length; i++) {
      dfs(depth + 1, i + 1, sum + number[i])
    }
  }

  dfs(0, 0, 0)
  return result
}

@JooKangsan JooKangsan merged commit 4ab4edc into codingTestStd:main Mar 20, 2025
0 of 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.

2 participants