Skip to content

[jdy8739] week 8#955

Merged
jdy8739 merged 9 commits intoDaleStudy:mainfrom
jdy8739:main
Jan 31, 2025
Merged

[jdy8739] week 8#955
jdy8739 merged 9 commits intoDaleStudy:mainfrom
jdy8739:main

Conversation

@jdy8739
Copy link
Contributor

@jdy8739 jdy8739 commented Jan 25, 2025

๋‹ต์•ˆ ์ œ์ถœ ๋ฌธ์ œ

  • 232
  • 244
  • 259
  • 274

์ฒดํฌ ๋ฆฌ์ŠคํŠธ

  • ์šฐ์ธก ๋ฉ”๋‰ด์—์„œ PR์„ Projects์— ์ถ”๊ฐ€ํ•ด์ฃผ์„ธ์š”.
  • Projects์˜ ์˜ค๋ฅธ์ชฝ ๋ฒ„ํŠผ(โ–ผ)์„ ๋ˆŒ๋Ÿฌ ํ™•์žฅํ•œ ๋’ค, Week๋ฅผ ํ˜„์žฌ ์ฃผ์ฐจ๋กœ ์„ค์ •ํ•ด์ฃผ์„ธ์š”.
  • ๋ฐ”๋กœ ์•ž์— PR์„ ์—ด์–ด์ฃผ์‹  ๋ถ„์„ ์ฝ”๋“œ ๊ฒ€ํ† ์ž๋กœ ์ง€์ •ํ•ด์ฃผ์„ธ์š”.
  • ๋ฌธ์ œ๋ฅผ ๋ชจ๋‘ ํ‘ธ์‹œ๋ฉด ํ”„๋กœ์ ํŠธ์—์„œ Status๋ฅผ In Review๋กœ ์„ค์ •ํ•ด์ฃผ์„ธ์š”.
  • ์ฝ”๋“œ ๊ฒ€ํ† ์ž 1๋ถ„ ์ด์ƒ์œผ๋กœ๋ถ€ํ„ฐ ์Šน์ธ์„ ๋ฐ›์œผ์…จ๋‹ค๋ฉด PR์„ ๋ณ‘ํ•ฉํ•ด์ฃผ์„ธ์š”.

@jdy8739 jdy8739 requested a review from a team as a code owner January 25, 2025 15:42
@github-actions github-actions bot added the js label Jan 25, 2025
@jdy8739 jdy8739 requested a review from imsosleepy January 25, 2025 15:43
Copy link
Contributor

@obzva obzva left a comment

Choose a reason for hiding this comment

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

์•ˆ๋…•ํ•˜์„ธ์š” ์ด๋ฒˆ ํ•œ ์ฃผ๋„ ๊ณ ์ƒ ๋งŽ์œผ์…จ์Šต๋‹ˆ๋‹ค.
์„ค ์—ฐํœด์ž„์—๋„ ๋ถˆ๊ตฌํ•˜๊ณ  4๋ฌธ์ œ๋‚˜ ํ’€์–ด์ฃผ์…จ๋„ค์š” :)
์ฝ”๋ฉ˜ํŠธ๋ฅผ ๋‚จ๊ฒจ ๋†“์•˜์œผ๋‹ˆ ๋ณ‘ํ•ฉ ์ „์— ํ™•์ธํ•˜๊ณ  ๋ณ‘ํ•ฉ ์ง„ํ–‰ ๋ถ€ํƒ ๋“œ๋ฆฝ๋‹ˆ๋‹ค
์ถ”๊ฐ€์ ์ธ ์ฝ”๋ฉ˜ํŠธ ๊ตํ™˜์„ ์›ํ•˜์‹ ๋‹ค๋ฉด re-request reviewํ•ด์ฃผ์„ธ์š”!


// ์žฌ๊ท€๋ฅผ ํ™œ์šฉํ•œ dfs๋ฅผ ์‚ฌ์šฉํ•œ ํ’€์ด
// ์‹œ๊ฐ„๋ณต์žก๋„ O(v + e) -> v(๋…ธ๋“œ์˜ ์ˆ˜) + e(๊ฐ„์„ ์˜ ์ˆ˜) ๋งŒํผ ํƒ์ƒ‰์„ ์ˆ˜ํ–‰
// ๊ณต๊ฐ„๋ณต์žก๋„ O(n) -> map์ด ์ด ๋…ธ๋“œ์˜ ์ˆ˜ ๋งŒํผ ํฌ๊ธฐ๋ฅผ ๊ฐ€์ง
Copy link
Contributor

Choose a reason for hiding this comment

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

  • ๊ณต๊ฐ„๋ณต์žก๋„ ๋ถ„์„œ ๊ฒฐ๊ณผ์—๋Š” ์˜ํ–ฅ์„ ๋ฏธ์น˜์ง€ ์•Š์ง€๋งŒ, ์žฌ๊ท€ํ˜ธ์ถœ ์Šคํƒ์— ๋Œ€ํ•œ ์–ธ๊ธ‰๋„ ํ•ด์ฃผ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”!
  • ์‹œ๊ฐ„๋ณต์žก๋„์—์„œ ๋…ธ๋“œ์˜ ์ˆ˜๋ฅผ v๋ผ๊ณ  ํ‘œํ˜„ํ•˜์…จ์œผ๋‹ˆ๊นŒ ๊ณต๊ฐ„๋ณต์žก๋„๋„ O(v)๋ผ๊ณ  ์จ์ฃผ๋ฉด ๋” ๋‚˜์„ ๊ฒƒ ๊ฐ™์•„์š”

nodeMap.set(clone.val, clone);

for (const nei of nodeParam.neighbors) {
clone.neighbors = [...clone.neighbors, dfs(nei)];
Copy link
Contributor

Choose a reason for hiding this comment

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

Array๋ฅผ ๋งค๋ฒˆ ์ƒˆ๋กœ ๋งŒ๋“ค์–ด์ฃผ๋Š” ๋Œ€์‹ ์— ์ƒˆ ์›์†Œ๋ฅผ pushํ•ด์ฃผ๋Š” ๋ฐฉ์‹์€ ์–ด๋–ค๊ฐ€์š”?

Suggested change
clone.neighbors = [...clone.neighbors, dfs(nei)];
clone.neighbors.push(dfs(nei));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

๋„ต ํ’€์ด์— ๊ทธ๋ ‡๊ฒŒ push๋กœ ์›์†Œ๋ฅผ ๋„ฃ์–ด ์ฃผ๋˜๋ฐ ๊ทธ ๋ฐฉ์‹์ด ์ข€ ๋” ๊ฐ„๊ฒฐํ•˜๊ณ  ์„ฑ๋Šฅ๋„ ๋‚˜์€ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค :)


// ํ๋ฅผ ํ™œ์šฉํ•œ bfs๋ฅผ ์‚ฌ์šฉํ•œ ํ’€์ด
// ์‹œ๊ฐ„๋ณต์žก๋„ O(v + e) -> v(๋…ธ๋“œ์˜ ์ˆ˜) + e(๊ฐ„์„ ์˜ ์ˆ˜) ๋งŒํผ ํƒ์ƒ‰์„ ์ˆ˜ํ–‰
// ๊ณต๊ฐ„๋ณต์žก๋„ O(n) -> map์ด ์ด ๋…ธ๋“œ์˜ ์ˆ˜ ๋งŒํผ ํฌ๊ธฐ๋ฅผ ๊ฐ€์ง
Copy link
Contributor

Choose a reason for hiding this comment

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

์‹œ๊ฐ„๋ณต์žก๋„์—์„œ ๋…ธ๋“œ์˜ ์ˆ˜๋ฅผ v๋ผ๊ณ  ํ‘œํ˜„ํ•˜์…จ์œผ๋‹ˆ๊นŒ ๊ณต๊ฐ„๋ณต์žก๋„๋„ O(v)๋ผ๊ณ  ์จ์ฃผ๋ฉด ๋” ๋‚˜์„ ๊ฒƒ ๊ฐ™์•„์š”

Copy link
Contributor Author

Choose a reason for hiding this comment

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

๊ทธ๋Ÿฌ๋„ค์š” ์ˆ˜์ •ํ•ด์„œ ์ปค๋ฐ‹ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! :)

Comment on lines +58 to +59
// ์ด queue์—๋Š” ํด๋ก ์ด ์•„๋‹ˆ๋ผ ์›๋ณธ ๋…ธ๋“œ๊ฐ€ ๋“ค์–ด๊ฐ€์•ผํ•จ(neighbors์— ๋Œ€ํ•œ ์ฐธ์กฐ ๋•Œ๋ฌธ)
const queue = [node];
Copy link
Contributor

Choose a reason for hiding this comment

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

์•Œ๊ณ ๋ฆฌ์ฆ˜์€ ์ •์ƒ์ ์œผ๋กœ ๋™์ž‘ํ•˜์ง€๋งŒ ํ•ด๋‹น Array๋Š” queue๊ฐ€ ์•„๋‹ˆ๋„ค์š” (stack์ฒ˜๋Ÿผ ๋™์ž‘ํ•ด์š”!)

return dfs(0, 0);
};

// ์‹œ๊ฐ„๋ณต์žก๋„ O(m * n) -> ์žฌ๊ท€๋ฅผ ํ†ตํ•ด m๊ณผ n์ด 1์”ฉ ์ฆ๊ฐ€ํ•˜๋ฉด์„œ ์ƒ๋Œ€ํŽธ์˜ m or n ๋ฒˆ ์งธ ์ธ๋ฑ์Šค ๋ฌธ์ž์—ด์„ ๋น„๊ตํ•˜๋ฏ€๋กœ??? (์ž˜ ๋ชจ๋ฅด๊ฒ ์Šต๋‹ˆ๋‹ค. ๋ฆฌ๋ทฐ์–ด๋ถ„์ด ์—ฌ์œ ๋˜์‹œ๋ฉด ์„ค๋ช…๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค ใ…œใ…œ)
Copy link
Contributor

Choose a reason for hiding this comment

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

์–ด๋””๊นŒ์ง€ ์ดํ•ด๋˜์…จ๊ณ  ์–ด๋””๋ถ€ํ„ฐ ์ดํ•ด๊ฐ€ ์ž˜ ์•ˆ๋˜์‹œ๋Š”์ง€ Discussion์— ์˜ฌ๋ ค์ฃผ์„ธ์š”~!

const countOfOthers = currLength - maxCountOfChar;

// ํ˜„์žฌ ๋ฌธ์ž์—ด์˜ ๊ธธ์ด์—์„œ ๊ฐ€์žฅ ๋งŽ์ด ๋‚˜์˜ค๋Š” ๋ฌธ์ž์—ด์˜ ์ˆ˜๋ฅผ ๋บธ ๊ฐ’์ธ countOfOthers๊ฐ€
// k๋ณด๋‹ค ์ž‘์œผ๋ฉด ํ˜„์žฌ ๋ฌธ์ž์—ด์—์„œ start๋ฒˆ ์งธ ๋ฌธ์ž์˜ ์ˆ˜๋ฅผ map์—์„œ ๊ฐ์†Œ์‹œํ‚ค๊ณ  star์˜ ๊ฐ’์„ ์ฆ๊ฐ€์‹œํ‚จ๋‹ค.
Copy link
Contributor

Choose a reason for hiding this comment

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

typo) k๋ณด๋‹ค ํฌ๋ฉด

Comment on lines +1 to +30
/**
* @param {number} n
* @return {number}
*/
var hammingWeight = function (n) {
const binary = [1];

while (binary[0] < n) {
const latest = binary[0] * 2;

binary.unshift(latest);
}

let count = 0;

for (let i = 0; i < binary.length; i++) {
if (binary[i] <= n) {
count++;
n = n - binary[i];
}

if (n === 0) {
break;
}
}

return count;
};

// ์‹œ๊ฐ„๋ณต์žก๋„ O(logn) -> ์ด์ง„ํƒ์ƒ‰์ฒ˜๋Ÿผ 2์”ฉ ๊ณฑํ•ด๊ฐ€๋ฉฐ n์„ ๋„˜์–ด๊ฐ€๋Š” ๊ฐ€์žฅ ํฐ ์ˆ˜๋ฅผ ์ฐพ์œผ๋ฏ€๋กœ
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. bitwise์—ฐ์‚ฐ์ž์— ๋Œ€ํ•ด์„œ ํ•œ ๋ฒˆ ์ฐพ์•„๋ณด์‹œ๋Š” ๊ฑธ ์ถ”์ฒœ๋“œ๋ฆฝ๋‹ˆ๋‹ค e.g. Right shift. bitwise ์—ฐ์‚ฐ์ž๋ฅผ ์ด์šฉํ•œ ํ’€์ด๊ฐ€ ๋– ์˜ค๋ฅด์ง€ ์•Š๋Š”๋‹ค๋ฉด ๋‹ค๋ฅธ ๋ถ„๋“ค ํ’€์ด๋ฅผ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”~!
  2. ์ œ๊ฐ€ ์•Œ๊ธฐ๋ก  unshift์˜ ์‹œ๊ฐ„ ๋ณต์žก๋„๋Š” O(1)์ด ์•„๋‹™๋‹ˆ๋‹ค. (์ด ๋ถ€๋ถ„๋„ ์ฐพ์•„๋ณด์‹œ๋Š”๊ฒŒ ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”) ๋”ฐ๋ผ์„œ ํ•ด๋‹น ํ’€์ด์˜ ์‹œ๊ฐ„ ๋ณต์žก๋„ ๋ถ„์„๋„ ๋‹ค์‹œ ์ด๋ค„์ ธ์•ผํ•  ๊ฒƒ ๊ฐ™๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“ญ๋‹ˆ๋‹ค.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

js์˜ ๋ฐฐ์—ด์ด ์›์†Œ๋“ค์ด ์—ฐ๋‹ฌ์•„ ์ฃผ์†Œ๊ฐ’์„ ๊ฐ€์ง€๋Š” ํ˜•ํƒœ๊ฐ€ ์•„๋‹ˆ๋‹ค๋ณด๋‹ˆ O(1)๋ผ๊ณ  ์ƒ๊ฐํ–ˆ๋Š”๋ฐ์š”, ํ•œ ๋ฒˆ ์•Œ์•„๋ณด๊ณ  ์ฃผ์„์„ ๋‹ค์‹œ ๋‹ฌ์•„ ์ปค๋ฐ‹ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ์ฝ”๋ฉ˜ํŠธ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

js์˜ unshift๋Š” ๋ฐฐ์—ด์˜ ์š”์†Œ๊ฐ€ ๋งจ ์•ž์— ์ถ”๊ฐ€๋  ๋•Œ๋งˆ๋‹ค ๋’ค ๋ชจ๋“  ์š”์†Œ๋“ค์˜ index๊ฐ€ 1 ์”ฉ ์ถ”๊ฐ€๋˜๋ฏ€๋กœ O(n)์˜ ๋ณต์žก๋„๋ฅผ ๊ฐ–๋Š”๋‹ค๋Š” ๊ฒƒ์„ ์•Œ๊ฒŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค!!

  1. JavaScript ๋ฐฐ์—ด์˜ ๋‚ด๋ถ€ ๊ตฌ์กฐ
    JavaScript ์—”์ง„(V8 ๊ธฐ์ค€)์—์„œ ๋ฐฐ์—ด์€ ๋‘ ๊ฐ€์ง€ ํ˜•ํƒœ๋กœ ์ €์žฅ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

โœ… (1) Packed Elements (์—ฐ์†๋œ ๋ฉ”๋ชจ๋ฆฌ, ๋น ๋ฆ„)
๋ฐฐ์—ด์ด ์ˆซ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ๊ณ , ์ธ๋ฑ์Šค๊ฐ€ ์—ฐ์†์ ์ด๋ฉด
๋‚ด๋ถ€์ ์œผ๋กœ ์ผ๋ฐ˜์ ์ธ ๋™์  ๋ฐฐ์—ด์ฒ˜๋Ÿผ ์—ฐ์†๋œ ๋ฉ”๋ชจ๋ฆฌ์— ์ €์žฅ๋จ
O(1)๋กœ ๋น ๋ฅธ ์กฐํšŒ๊ฐ€ ๊ฐ€๋Šฅ

let arr = [1, 2, 3, 4]; // Packed Elements ์‚ฌ์šฉ
โœ… (2) Sparse Elements (๋น„์—ฐ์†์ , ๋А๋ฆผ)
๋ฐฐ์—ด์ด ์ค‘๊ฐ„์— ๋นˆ ์š”์†Œ๊ฐ€ ์žˆ๊ฑฐ๋‚˜, ์ˆซ์ž๊ฐ€ ์•„๋‹Œ ๊ฐ์ฒด๊ฐ€ ํฌํ•จ๋œ ๊ฒฝ์šฐ
๋‚ด๋ถ€์ ์œผ๋กœ ํ•ด์‹œ ํ…Œ์ด๋ธ”(Hash Map)์ฒ˜๋Ÿผ ๋™์ž‘
์š”์†Œ๋ฅผ ์กฐํšŒํ•  ๋•Œ ํ•ด์‹œ ํ…Œ์ด๋ธ”์—์„œ ๊ฒ€์ƒ‰ํ•ด์•ผ ํ•˜๋ฏ€๋กœ ๋А๋ ค์ง (O(1) โ†’ O(n))

let arr = [];
arr[0] = 1;
arr[100] = 2; // ํฌ์†Œ ๋ฐฐ์—ด (Sparse Array)
โœ… ์œ„์ฒ˜๋Ÿผ ์ธ๋ฑ์Šค๊ฐ€ ์—ฐ์†๋˜์ง€ ์•Š์œผ๋ฉด ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ์—ฐ์†์ ์ด์ง€ ์•Š์Œ!

@jdy8739 jdy8739 merged commit a747d1f into DaleStudy:main Jan 31, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels