LeetCode - Two Sum
Coding Test 2021. 11. 8. 23:59

Description Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order. Example 1: Input: nums = [2,7,11,15], target = 9 Output: [0,1] Output: Because nums[0] + nums[1] == 9, we return [0,..

Programmers: ๋‘ ๊ฐœ ๋ฝ‘์•„์„œ ๋”ํ•˜๊ธฐ
Coding Test 2021. 8. 22. 18:30

โœ… ์ƒˆ๋กœ ๋ฐฐ์šด ์  ์ด ๋ฌธ์ œ๋Š” ์ง€๋‚œ ์ฃผ์— ์ด์šฉํ–ˆ๋˜ sort์™€ ๋‚˜์—๊ฒŒ๋Š” ์•„์ง ์ต์ˆ™ํ•˜์ง€ ์•Š์€ ! ๋ฌธ๋ฒ•์„ ๋ณต์Šตํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค. sort ํ•จ์ˆ˜ ์ด์šฉ๊ณผ ๊ด€๋ จํ•ด์„œ๋Š” ์•„๋ž˜ ๊ธ€ ์ฐธ๊ณ ! [์ •๋ ฌ: K๋ฒˆ์งธ ์ˆ˜] https://high-developer.tistory.com/25 Programmers ์ •๋ ฌ: K๋ฒˆ์งธ์ˆ˜ ์ƒˆ๋กœ ๋ฐฐ์šด ์  sort๋Š” ๋ฌธ์ž์—ด์„ ์ •๋ ฌํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ์ˆซ์žํ˜•์œผ ์ •๋ ฌํ•ฉ๋‹ˆ๋‹ค. ์ˆซ์ž ํฌ๊ธฐ ์ˆœ์œผ๋กœ ์ •๋ ฌํ•˜๊ณ  ์‹ถ์„ ๋•Œ๋Š” compareFunction์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. compareFunction์€ ์ •๋ ฌ ๊ธฐ์ค€์„ ์ •์˜ํ•ด์„œ ์ •๋ ฌํ•ด์ค๋‹ˆ๋‹ค. ์ฐธ high-developer.tistory.com ๊ทธ๋ฆฌ๊ณ  !๋ฅผ ์“ฐ๋ ค๋ฉด ๋ญ”๊ฐ€ ์ „์ฒด๋ฅผ ๊ฐ์‹ธ์ฃผ๋Š” ๊ด„ํ˜ธ๊ฐ€ ์žˆ์–ด์•ผ ํ•  ๊ฒƒ ๊ฐ™์€๋ฐ ์•„๋‹ˆ๋”๋ผ๊ตฌ..! ํ•œํŽธ, ๋‹ค๋ฅธ ์‚ฌ๋žŒ๋“ค์˜ ํ’€์ด๋ฅผ ๋ด๋ณด๋‹ˆ Set์„ ์‚ฌ์šฉํ•œ ๋ถ€๋ถ„์ด ๊ธฐ..

Programmers: ํฌ๋ ˆ์ธ ์ธํ˜•๋ฝ‘๊ธฐ ๊ฒŒ์ž„
Coding Test 2021. 8. 22. 18:09

โœ… ์ƒˆ๋กœ ๋ฐฐ์šด ์  ๋จธ๋ฆฟ์†์œผ๋กœ ํ•œ๋ฒˆ์— ์ •๋ฆฌ๊ฐ€ ์•ˆ๋˜๋ฉด ์ˆ˜๋„์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์ž. ๋‚ด ๋จธ๋ฆฌ๋กœ๋Š” ์ด ๋ฌธ์ œ๋ฅผ ์ฝ๊ณ  ํ•œ๋ฒˆ์— ์ฝ”๋“œ๊ฐ€ ๊ตฌ์กฐํ™”๊ฐ€ ๋˜์ง€ ์•Š์•˜๋‹ค... ์‚ฌ์‹ค ๋ฌธ์ œ ์ž…์ถœ๋ ฅ ์˜ˆ์‹œ๋„ ๊ทธ ์˜ˆ์‹œ ๋ฐ”๋กœ ์œ„ ๊ทธ๋ฆผ์— ํ•ด๋‹นํ•˜๋Š” ์ค„ ์•Œ๊ณ  ๋ฌธ์ œ ์ดํ•ด๋งŒ ์‹ญ๋ถ„ ๋„˜๊ฒŒ ๊ฑธ๋ ธ๋‹ค ํ•˜ํ•ณ ์›๋ž˜๋Š” ์ ค ์œ„์˜ ๊ทธ๋ฆผ์— ํ•ด๋‹นํ•œ ์˜ˆ์‹œ์˜€๋˜ ๊ฒƒ. ๋ฌธ์ œ ์ดํ•ด์— ์‹œ๊ฐ„ ์ผ๋‹ค๋Š” ์ƒ๊ฐ์— ๋ง˜ ๊ธ‰ํ•ด์ ธ์„œ ๊ทธ๋ƒฅ ์ƒ๊ฐ๋‚˜๋Š” ๋Œ€๋กœ ๋ฐ”๋กœ๋ฐ”๋กœ ์ฝ”๋“œ ์น˜๋‹ˆ๊น ์˜ค๋ฅ˜๊ฐ€ ๋ง‰ ๋‚˜๋”๋ผ๊ตฌ..?! "์ด๋Ÿด๋• ์ฒœ์ฒœํžˆ ๊ฐ€๋”๋ผ๋„ ์ˆ˜๋„์ง€"๋ผ๊ณ  ์ƒ๊ฐํ•ด์„œ ์ƒํ™ฉ์„ ์ตœ๋Œ€ํ•œ ์„ธ์„ธํžˆ ๋‚˜๋ˆ„์–ด์„œ ์ˆ˜๋„์ฝ”๋“œ๋ฅผ ๋จผ์ € ์ž‘์„ฑํ•˜๊ณ  ๊ทธ๊ฑฐ์— ๋”ฐ๋ผ์„œ ์ฝ”๋”ฉ์„ ํ•ด๋ดค๋”๋‹ˆ ๋๋‹ค. ๋‚˜์ค‘์—๋Š” ์ด๋Ÿฐ ๋ฌธ์ œ๋„ ๋ฐ”๋กœ๋ฐ”๋กœ ๋‚ด ๋จธ๋ฆฟ์†์—์„œ ๊ตฌ์กฐํ™” ๋  ์ˆ˜ ์žˆ๊ธธ...๐Ÿ™ function solution(board, moves) { //board์˜ ๊ฐ’์ด 0์ด ์•„๋‹ ๋•Œ /..

Programmers ํ•ด์‹œ: ์™„์ฃผํ•˜์ง€ ๋ชปํ•œ ์„ ์ˆ˜
Coding Test 2021. 8. 22. 18:02

โœ… ์ƒˆ๋กœ ๋ฐฐ์šด ์  ๋ฐฐ์—ด์˜ find ํ•จ์ˆ˜ ๋ฐฐ์—ด ๊ด€๋ จํ•œ ๋ฉ”์†Œ๋“œ ๋ฐฐ์šธ ๋•Œ ์–ผํ• ๋ดค๋˜ ๊ฒƒ ๊ฐ™์€๋ฐ ์ œ๋Œ€๋กœ ๊ธฐ์–ต์ด ์•ˆ๋‚˜ ๋‹ค์‹œ ํ•œ๋ฒˆ ์ œ๋Œ€๋กœ ์ฐพ์•„๋ณด์•˜๋‹ค. for๋ฌธ์œผ๋กœ๋„ ์‚ฌ์šฉํ•ด์„œ ํ’€ ์ˆ˜ ์žˆ๊ฒ ์ง€๋งŒ! find ํ•จ์ˆ˜ ์‚ฌ์šฉํ•ด๋ณด๊ณ  ์‹ถ์—ˆ๋‹น! https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/find Array.prototype.find() - JavaScript | MDN find() ๋ฉ”์„œ๋“œ๋Š” ์ฃผ์–ด์ง„ ํŒ๋ณ„ ํ•จ์ˆ˜๋ฅผ ๋งŒ์กฑํ•˜๋Š” ์ฒซ ๋ฒˆ์งธ ์š”์†Œ์˜ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ ์š”์†Œ๊ฐ€ ์—†๋‹ค๋ฉด undefined๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. developer.mozilla.org function solution(participant, comple..

Programmers ์™„์ „ํƒ์ƒ‰: ๋ชจ์˜๊ณ ์‚ฌ
Coding Test 2021. 8. 15. 10:24

โœ… ์ƒˆ๋กœ ๋ฐฐ์šด ์  filter ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ์„ธ ๊ฐ€์ง€์˜ argument๋ฅผ ๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. 1. ๊ธฐ๋ณธ์ ์ธ element 2. ํ˜„์žฌ ์‚ฌ์šฉ๋˜๊ณ  ์žˆ๋Š” element์˜ ์ธ๋ฑ์Šค ๋ฒˆํ˜ธ 3. filter ํ•จ์ˆ˜์— ์‚ฌ์šฉ๋˜๋Š” ๋ฐฐ์—ด element The current element being processed in the array. index (Optional) The index of the current element being processed in the array. array (Optional) The array filter was called upon. ์ฐธ๊ณ  Array.prototype.filter() Array.prototype.filter() - JavaScript | MDN The filter() me..

Programmers ์ •๋ ฌ: K๋ฒˆ์งธ์ˆ˜
Coding Test 2021. 8. 15. 10:07

โœ… ์ƒˆ๋กœ ๋ฐฐ์šด ์  sort๋Š” ๋ฌธ์ž์—ด์„ ์ •๋ ฌํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ์ˆซ์žํ˜•์œผ ์ •๋ ฌํ•ฉ๋‹ˆ๋‹ค. ์ˆซ์ž ํฌ๊ธฐ ์ˆœ์œผ๋กœ ์ •๋ ฌํ•˜๊ณ  ์‹ถ์„ ๋•Œ๋Š” compareFunction์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. compareFunction์€ ์ •๋ ฌ ๊ธฐ์ค€์„ ์ •์˜ํ•ด์„œ ์ •๋ ฌํ•ด์ค๋‹ˆ๋‹ค. ์ฐธ๊ณ  MDN Array.prototype.sort() Array.prototype.sort() - JavaScript | MDN The sort() method sorts the elements of an array in place and returns the sorted array. The default sort order is ascending, built upon converting the elements into strings, then comparing their sequen..