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,..
โ ์๋ก ๋ฐฐ์ด ์ ์ด ๋ฌธ์ ๋ ์ง๋ ์ฃผ์ ์ด์ฉํ๋ sort์ ๋์๊ฒ๋ ์์ง ์ต์ํ์ง ์์ ! ๋ฌธ๋ฒ์ ๋ณต์ตํ ์ ์์๋ค. sort ํจ์ ์ด์ฉ๊ณผ ๊ด๋ จํด์๋ ์๋ ๊ธ ์ฐธ๊ณ ! [์ ๋ ฌ: K๋ฒ์งธ ์] https://high-developer.tistory.com/25 Programmers ์ ๋ ฌ: K๋ฒ์งธ์ ์๋ก ๋ฐฐ์ด ์ sort๋ ๋ฌธ์์ด์ ์ ๋ ฌํ๋ ๋ฐฉ์์ผ๋ก ์ซ์ํ์ผ ์ ๋ ฌํฉ๋๋ค. ์ซ์ ํฌ๊ธฐ ์์ผ๋ก ์ ๋ ฌํ๊ณ ์ถ์ ๋๋ compareFunction์ ์ฌ์ฉํฉ๋๋ค. compareFunction์ ์ ๋ ฌ ๊ธฐ์ค์ ์ ์ํด์ ์ ๋ ฌํด์ค๋๋ค. ์ฐธ high-developer.tistory.com ๊ทธ๋ฆฌ๊ณ !๋ฅผ ์ฐ๋ ค๋ฉด ๋ญ๊ฐ ์ ์ฒด๋ฅผ ๊ฐ์ธ์ฃผ๋ ๊ดํธ๊ฐ ์์ด์ผ ํ ๊ฒ ๊ฐ์๋ฐ ์๋๋๋ผ๊ตฌ..! ํํธ, ๋ค๋ฅธ ์ฌ๋๋ค์ ํ์ด๋ฅผ ๋ด๋ณด๋ Set์ ์ฌ์ฉํ ๋ถ๋ถ์ด ๊ธฐ..
โ ์๋ก ๋ฐฐ์ด ์ ๋จธ๋ฆฟ์์ผ๋ก ํ๋ฒ์ ์ ๋ฆฌ๊ฐ ์๋๋ฉด ์๋์ฝ๋๋ฅผ ์ฌ์ฉํ์. ๋ด ๋จธ๋ฆฌ๋ก๋ ์ด ๋ฌธ์ ๋ฅผ ์ฝ๊ณ ํ๋ฒ์ ์ฝ๋๊ฐ ๊ตฌ์กฐํ๊ฐ ๋์ง ์์๋ค... ์ฌ์ค ๋ฌธ์ ์ ์ถ๋ ฅ ์์๋ ๊ทธ ์์ ๋ฐ๋ก ์ ๊ทธ๋ฆผ์ ํด๋นํ๋ ์ค ์๊ณ ๋ฌธ์ ์ดํด๋ง ์ญ๋ถ ๋๊ฒ ๊ฑธ๋ ธ๋ค ํํณ ์๋๋ ์ ค ์์ ๊ทธ๋ฆผ์ ํด๋นํ ์์์๋ ๊ฒ. ๋ฌธ์ ์ดํด์ ์๊ฐ ์ผ๋ค๋ ์๊ฐ์ ๋ง ๊ธํด์ ธ์ ๊ทธ๋ฅ ์๊ฐ๋๋ ๋๋ก ๋ฐ๋ก๋ฐ๋ก ์ฝ๋ ์น๋๊น ์ค๋ฅ๊ฐ ๋ง ๋๋๋ผ๊ตฌ..?! "์ด๋ด๋ ์ฒ์ฒํ ๊ฐ๋๋ผ๋ ์๋์ง"๋ผ๊ณ ์๊ฐํด์ ์ํฉ์ ์ต๋ํ ์ธ์ธํ ๋๋์ด์ ์๋์ฝ๋๋ฅผ ๋จผ์ ์์ฑํ๊ณ ๊ทธ๊ฑฐ์ ๋ฐ๋ผ์ ์ฝ๋ฉ์ ํด๋ดค๋๋ ๋๋ค. ๋์ค์๋ ์ด๋ฐ ๋ฌธ์ ๋ ๋ฐ๋ก๋ฐ๋ก ๋ด ๋จธ๋ฆฟ์์์ ๊ตฌ์กฐํ ๋ ์ ์๊ธธ...๐ function solution(board, moves) { //board์ ๊ฐ์ด 0์ด ์๋ ๋ /..
โ ์๋ก ๋ฐฐ์ด ์ ๋ฐฐ์ด์ 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..
โ ์๋ก ๋ฐฐ์ด ์ 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..
โ ์๋ก ๋ฐฐ์ด ์ 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..