์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์•Œ๊ณ ๋ฆฌ์ฆ˜ 67

[์ธํ”„๋Ÿฐ ์„น์…˜5] ์ตœ๋Œ€ ๋งค์ถœ (Javascript)

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป๋ฌธ์ œ๋งํฌ [์ธํ”„๋Ÿฐ ์„น์…˜5] ์ตœ๋Œ€ ๋งค์ถœ (Javascript) ์œ ๋ฃŒ ๊ฐ•์˜์ธ ๊ด€๊ณ„๋กœ ๋ฌธ์ œ ์„ค๋ช…์€ ์ƒ๋žตํ•ฉ๋‹ˆ๋‹ค. โœ๏ธIdea Sketch 2021-06-25 1. ์—ฐ์† ์ตœ๋Œ€ ๋งค์ถœ์•ก์€? 2. left์™€ right ๊ฐ„์˜ ๊ฐ„๊ฒฉ์€ k let left = 0, right = k-1; 3. left++, right++ํ•˜๋ฉด์„œ sum ๊ตฌํ•˜๊ธฐ 4. sum์ด max๋ณด๋‹ค ๋” ํฐ์ง€ ํŒ๋‹จ let max = Number.MIN_SAFE_INTEGER; max = sum > max ? sum : min; // ์ฒซ๋ฒˆ์งธ ๋ฐฉ๋ฒ• max = Math.max(max, sum); // ๋‘๋ฒˆ์งธ ๋ฐฉ๋ฒ• 5. ๋ฌธ์ œ์  : Math.max(max, sum) ์˜ NaN ๋ฐ˜ํ™˜ right๋ฅผ ์ „์œ„์—ฐ์‚ฐ์ž๋กœ ๊ณ„์‚ฐํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ƒ๊ธฐ๋Š” ๋ฌธ์ œ while (right < ..

[์ธํ”„๋Ÿฐ ์„น์…˜5] ์—ฐ์† ๋ถ€๋ถ„์ˆ˜์—ด 2 (Javascript)

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป๋ฌธ์ œ๋งํฌ [์ธํ”„๋Ÿฐ ์„น์…˜5] ์—ฐ์† ๋ถ€๋ถ„์ˆ˜์—ด 2 (Javascript) ์œ ๋ฃŒ ๊ฐ•์˜์ธ ๊ด€๊ณ„๋กœ ๋ฌธ์ œ ์„ค๋ช…์€ ์ƒ๋žตํ•ฉ๋‹ˆ๋‹ค. โœ๏ธIdea Sketch 2021-06-25 1. left๋ถ€ํ„ฐ right๊นŒ์ง€์˜ ํ•ฉ์ด m๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์œผ๋ฉด 1) cnt += (left๋ถ€ํ„ฐ right๊นŒ์ง€ ์›์†Œ์˜ ๊ฐœ์ˆ˜) cnt += right - left + 1 2) right++ 2. left๋ถ€ํ„ฐ right๊นŒ์ง€์˜ ํ•ฉ์ด m๋ณด๋‹ค ํฌ๋ฉด left++ 3. Example 1) left๊ฐ€ 0, right๊ฐ€ 2์ผ ๋•Œ --> ์›์†Œ๋Š” 1, 3, 1 --> sum === m (5 === 5) ์—ฐ์†๋ถ€๋ถ„์ˆ˜์—ด {1, 3, 1}, {3, 1}, {1} ์ด 3๊ฐœ๊ฐ€ ์ถ”๊ฐ€๋จ 2) left๊ฐ€ 0, right๊ฐ€ 3์ผ ๋•Œ --> ์›์†Œ๋Š” 1, 3, 1, 2 ==> sum >..

[์ธํ”„๋Ÿฐ ์„น์…˜5] ์—ฐ์† ๋ถ€๋ถ„์ˆ˜์—ด 1 (Javascript)

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป๋ฌธ์ œ๋งํฌ [์ธํ”„๋Ÿฐ ์„น์…˜5] ์—ฐ์† ๋ถ€๋ถ„์ˆ˜์—ด 1 (Javascript) ์œ ๋ฃŒ ๊ฐ•์˜์ธ ๊ด€๊ณ„๋กœ ๋ฌธ์ œ ์„ค๋ช…์€ ์ƒ๋žตํ•ฉ๋‹ˆ๋‹ค. โœ๏ธIdea Sketch 2021-06-25 1. left์™€ right ์ธ๋ฑ์Šค๋ฅผ ๋งŒ๋“ ๋‹ค 2. left๋ถ€ํ„ฐ right๊นŒ์ง€์˜ ํ•ฉ์ด m๋ณด๋‹ค ํฌ๋ฉด left++ 3. left๋ถ€ํ„ฐ right๊นŒ์ง€์˜ ํ•ฉ์ด m๋ณด๋‹ค ์ž‘์œผ๋ฉด right++ 4. m๊ณผ ๊ฐ™์œผ๋ฉด cnt++ 5. ์ „์œ„/ํ›„์œ„์—ฐ์‚ฐ์ž ์ฃผ์˜ โœ๏ธ์†Œ์Šค์ฝ”๋“œ 2021-06-25 function solution(arr, m) { let left = 0, right = 0; let cnt = 0; let sum = arr[0]; while (left < arr.length && right < arr.length) { if (sum === m) cnt++; if ..

[์ธํ”„๋Ÿฐ ์„น์…˜5] ๊ณตํ†ต์›์†Œ ๊ตฌํ•˜๊ธฐ (Javascript)

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป๋ฌธ์ œ๋งํฌ [์ธํ”„๋Ÿฐ ์„น์…˜5] ๊ณตํ†ต์›์†Œ ๊ตฌํ•˜๊ธฐ (Javascript) ์œ ๋ฃŒ ๊ฐ•์˜์ธ ๊ด€๊ณ„๋กœ ๋ฌธ์ œ ์„ค๋ช…์€ ์ƒ๋žตํ•ฉ๋‹ˆ๋‹ค. โœ๏ธIdea Sketch 2021-06-25 1. arr.includes() ์‚ฌ์šฉ for (let x of arr1) { if (arr2.includes(x)) res.push(x); } 2. arr.filter ์‚ฌ์šฉ arr1.filter(v => arr2.includes(v)); 3. ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ arr.sort((a, b) => a-b) โœ๏ธ์†Œ์Šค์ฝ”๋“œ 2021-06-25 function solution(arr1, arr2) { return arr1.filter(v => arr2.includes(v)).sort((a, b) => a-b); }

[์ธํ”„๋Ÿฐ ์„น์…˜5] ๋‘ ๋ฐฐ์—ด ํ•ฉ์น˜๊ธฐ (Javascript)

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป๋ฌธ์ œ๋งํฌ [์ธํ”„๋Ÿฐ ์„น์…˜5] ๋‘ ๋ฐฐ์—ด ํ•ฉ์น˜๊ธฐ (Javascript) ์œ ๋ฃŒ ๊ฐ•์˜์ธ ๊ด€๊ณ„๋กœ ๋ฌธ์ œ ์„ค๋ช…์€ ์ƒ๋žตํ•ฉ๋‹ˆ๋‹ค. โœ๏ธIdea Sketch 2021-06-25 1. […arr1, …arr2] ๋ฐฐ์—ด ํ•ฉ์น˜๊ธฐ 2. sort((a, b) => a-b) ๋ฐฐ์—ด ์ •๋ ฌ โœ๏ธ์†Œ์Šค์ฝ”๋“œ 2021-06-25 function solution(arr1, arr2) { return [...arr1, ...arr2].sort((a, b) => a-b) }

[์ธํ”„๋Ÿฐ ์„น์…˜1] ์ค‘๋ณต๋ฌธ์ž์ œ๊ฑฐ (Javascript)

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป๋ฌธ์ œ๋งํฌ [์ธํ”„๋Ÿฐ ์„น์…˜1] ์ค‘๋ณต๋ฌธ์ž์ œ๊ฑฐ (Javascript) ์œ ๋ฃŒ ๊ฐ•์˜์ธ ๊ด€๊ณ„๋กœ ๋ฌธ์ œ ์„ค๋ช…์€ ์ƒ๋žตํ•ฉ๋‹ˆ๋‹ค. โœ๏ธIdea Sketch 2021-06-25 1. str.indexOf(s, begin) ์ฐพ์œผ๋ ค๋Š” ๋ฌธ์ž์—ด๊ณผ ์ผ์น˜ํ•˜๋Š” ์ฒซ๋ฒˆ์งธ ์ธ๋ฑ์Šค๋ฅผ ๋ฐ˜ํ™˜ begin : ์ฐพ๊ธฐ ์‹œ์ž‘ํ•˜๋Š” ์œ„์น˜, ๊ธฐ๋ณธ๊ฐ’ 0 begin์ด ์Œ์ˆ˜์ธ ๊ฒฝ์šฐ, ์ „์ฒด ๋ฌธ์ž์—ด ํƒ์ƒ‰ begin์ด str.length๋ฅผ ์ดˆ๊ณผํ•˜๋Š” ๊ฒฝ์šฐ, -1 ๋ฐ˜ํ™˜ ์ผ์น˜ํ•˜๋Š” ๊ฐ’์ด ์—†๋Š” ๊ฒฝ์šฐ -1 ๋ฐ˜ํ™˜ ๋Œ€์†Œ๋ฌธ์ž ๊ตฌ๋ถ„ ๋‘๋ฒˆ์งธ ๋“ฑ์žฅ ์ธ๋ฑ์Šค ๊ตฌํ•˜๊ธฐ : ์ฒซ๋ฒˆ์งธ ๋“ฑ์žฅ ์ธ๋ฑ์Šค + 1 const str = 'The quick brown fox jumps over the lazy dog. If the dog barked, was it really lazy?'; const index =..

[์ธํ”„๋Ÿฐ ์„น์…˜1] ๊ฐ€์šด๋ฐ ๋ฌธ์ž ์ถœ๋ ฅ (Javascript)

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป๋ฌธ์ œ๋งํฌ [์ธํ”„๋Ÿฐ ์„น์…˜1] ๊ฐ€์šด๋ฐ ๋ฌธ์ž ์ถœ๋ ฅ (Javascript) ์œ ๋ฃŒ ๊ฐ•์˜์ธ ๊ด€๊ณ„๋กœ ๋ฌธ์ œ ์„ค๋ช…์€ ์ƒ๋žตํ•ฉ๋‹ˆ๋‹ค. โœ๏ธIdea Sketch 2021-06-25 1. str.substring(begin, end) : ๋ฌธ์ž์—ด์˜ ์‹œ์ž‘ ์ธ๋ฑ์Šค๋ถ€ํ„ฐ ์ข…๋ฃŒ ์ธ๋ฑ์Šค ์ง์ „๊นŒ์ง€ ๋ถ€๋ถ„ ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ const str = 'Mozilla'; console.log(str.substring(1, 3)); // output: "oz" console.log(str.substring(2)); // output: "zilla" 2. str.substr(begin, length) : ๋ฌธ์ž์—ด์˜ ์‹œ์ž‘ ์ธ๋ฑ์Šค๋ถ€ํ„ฐ ๋ฌธ์ž ๊ธธ์ด ๋งŒํผ์˜ ๋ฌธ์ž๋“ค์„ ๋ฐ˜ํ™˜ const str = 'Mozilla'; console.log(str.substr(1, 2))..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 12951] JadenCase ๋ฌธ์ž์—ด ๋งŒ๋“ค๊ธฐ (Javascript)

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป๋ฌธ์ œ๋งํฌ [ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 12951] JadenCase ๋ฌธ์ž์—ด ๋งŒ๋“ค๊ธฐ (Javascript) ๋ฌธ์ œ ์„ค๋ช… JadenCase๋ž€ ๋ชจ๋“  ๋‹จ์–ด์˜ ์ฒซ ๋ฌธ์ž๊ฐ€ ๋Œ€๋ฌธ์ž์ด๊ณ , ๊ทธ ์™ธ์˜ ์•ŒํŒŒ๋ฒณ์€ ์†Œ๋ฌธ์ž์ธ ๋ฌธ์ž์—ด์ž…๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด s๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, s๋ฅผ JadenCase๋กœ ๋ฐ”๊พผ ๋ฌธ์ž์—ด์„ ๋ฆฌํ„ดํ•˜๋Š” ํ•จ์ˆ˜, solution์„ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. ์ œํ•œ ์กฐ๊ฑด s๋Š” ๊ธธ์ด 1 ์ด์ƒ์ธ ๋ฌธ์ž์—ด์ž…๋‹ˆ๋‹ค. s๋Š” ์•ŒํŒŒ๋ฒณ๊ณผ ๊ณต๋ฐฑ๋ฌธ์ž(" ")๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค. ์ฒซ ๋ฌธ์ž๊ฐ€ ์˜๋ฌธ์ด ์•„๋‹๋•Œ์—๋Š” ์ด์–ด์ง€๋Š” ์˜๋ฌธ์€ ์†Œ๋ฌธ์ž๋กœ ์”๋‹ˆ๋‹ค. ( ์ฒซ๋ฒˆ์งธ ์ž…์ถœ๋ ฅ ์˜ˆ ์ฐธ๊ณ  ) ์ž…์ถœ๋ ฅ ์˜ˆ s return "3people unFollowed me" "3people Unfollowed Me" "for the last week" "For The Last Week" โœ๏ธIdea S..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 12953] N๊ฐœ์˜ ์ตœ์†Œ๊ณต๋ฐฐ์ˆ˜ (Javascript)

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป๋ฌธ์ œ๋งํฌ [ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 12953] N๊ฐœ์˜ ์ตœ์†Œ๊ณต๋ฐฐ์ˆ˜ (Javascript) ๋ฌธ์ œ ์„ค๋ช… ๋‘ ์ˆ˜์˜ ์ตœ์†Œ๊ณต๋ฐฐ์ˆ˜(Least Common Multiple)๋ž€ ์ž…๋ ฅ๋œ ๋‘ ์ˆ˜์˜ ๋ฐฐ์ˆ˜ ์ค‘ ๊ณตํ†ต์ด ๋˜๋Š” ๊ฐ€์žฅ ์ž‘์€ ์ˆซ์ž๋ฅผ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด 2์™€ 7์˜ ์ตœ์†Œ๊ณต๋ฐฐ์ˆ˜๋Š” 14๊ฐ€ ๋ฉ๋‹ˆ๋‹ค. ์ •์˜๋ฅผ ํ™•์žฅํ•ด์„œ, n๊ฐœ์˜ ์ˆ˜์˜ ์ตœ์†Œ๊ณต๋ฐฐ์ˆ˜๋Š” n ๊ฐœ์˜ ์ˆ˜๋“ค์˜ ๋ฐฐ์ˆ˜ ์ค‘ ๊ณตํ†ต์ด ๋˜๋Š” ๊ฐ€์žฅ ์ž‘์€ ์ˆซ์ž๊ฐ€ ๋ฉ๋‹ˆ๋‹ค. n๊ฐœ์˜ ์ˆซ์ž๋ฅผ ๋‹ด์€ ๋ฐฐ์—ด arr์ด ์ž…๋ ฅ๋˜์—ˆ์„ ๋•Œ ์ด ์ˆ˜๋“ค์˜ ์ตœ์†Œ๊ณต๋ฐฐ์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜, solution์„ ์™„์„ฑํ•ด ์ฃผ์„ธ์š”. ์ œํ•œ ์‚ฌํ•ญ arr์€ ๊ธธ์ด 1์ด์ƒ, 15์ดํ•˜์ธ ๋ฐฐ์—ด์ž…๋‹ˆ๋‹ค. arr์˜ ์›์†Œ๋Š” 100 ์ดํ•˜์ธ ์ž์—ฐ์ˆ˜์ž…๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ arr result [2,6,8,14] 168 [1,2,3] 6 โœ๏ธIdea Sketch 202..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 42576] ์™„์ฃผํ•˜์ง€ ๋ชปํ•œ ์„ ์ˆ˜ (Javascript)

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป๋ฌธ์ œ๋งํฌ [ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 42576] ์™„์ฃผํ•˜์ง€ ๋ชปํ•œ ์„ ์ˆ˜ (Javascript) ๋ฌธ์ œ ์„ค๋ช… ์ˆ˜๋งŽ์€ ๋งˆ๋ผํ†ค ์„ ์ˆ˜๋“ค์ด ๋งˆ๋ผํ†ค์— ์ฐธ์—ฌํ•˜์˜€์Šต๋‹ˆ๋‹ค. ๋‹จ ํ•œ ๋ช…์˜ ์„ ์ˆ˜๋ฅผ ์ œ์™ธํ•˜๊ณ ๋Š” ๋ชจ๋“  ์„ ์ˆ˜๊ฐ€ ๋งˆ๋ผํ†ค์„ ์™„์ฃผํ•˜์˜€์Šต๋‹ˆ๋‹ค. ๋งˆ๋ผํ†ค์— ์ฐธ์—ฌํ•œ ์„ ์ˆ˜๋“ค์˜ ์ด๋ฆ„์ด ๋‹ด๊ธด ๋ฐฐ์—ด participant์™€ ์™„์ฃผํ•œ ์„ ์ˆ˜๋“ค์˜ ์ด๋ฆ„์ด ๋‹ด๊ธด ๋ฐฐ์—ด completion์ด ์ฃผ์–ด์งˆ ๋•Œ, ์™„์ฃผํ•˜์ง€ ๋ชปํ•œ ์„ ์ˆ˜์˜ ์ด๋ฆ„์„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”. ์ œํ•œ์‚ฌํ•ญ ๋งˆ๋ผํ†ค ๊ฒฝ๊ธฐ์— ์ฐธ์—ฌํ•œ ์„ ์ˆ˜์˜ ์ˆ˜๋Š” 1๋ช… ์ด์ƒ 100,000๋ช… ์ดํ•˜์ž…๋‹ˆ๋‹ค. completion์˜ ๊ธธ์ด๋Š” participant์˜ ๊ธธ์ด๋ณด๋‹ค 1 ์ž‘์Šต๋‹ˆ๋‹ค. ์ฐธ๊ฐ€์ž์˜ ์ด๋ฆ„์€ 1๊ฐœ ์ด์ƒ 20๊ฐœ ์ดํ•˜์˜ ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค. ์ฐธ๊ฐ€์ž ์ค‘์—๋Š” ๋™๋ช…์ด์ธ์ด ์žˆ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ..