diff --git a/climbing-stairs/robinyoon-dev.js b/climbing-stairs/robinyoon-dev.js new file mode 100644 index 000000000..59d3fa399 --- /dev/null +++ b/climbing-stairs/robinyoon-dev.js @@ -0,0 +1,19 @@ +/** + * @param {number} n + * @return {number} + */ +var climbStairs = function(n) { + //(n) = f(n - 1) + f(n - 2) + let tempArray = []; + + for(let i = 0; i <= n; i++){ + if(i === 0 || i === 1){ + tempArray.push(1); + }else{ + let tempSum = 0; + tempSum = tempArray[i - 2] + tempArray[i - 1]; + tempArray.push(tempSum); + } + } + return tempArray[n]; +}; diff --git a/product-of-array-except-self/robinyoon-dev.js b/product-of-array-except-self/robinyoon-dev.js new file mode 100644 index 000000000..53ec7fcad --- /dev/null +++ b/product-of-array-except-self/robinyoon-dev.js @@ -0,0 +1,43 @@ +/** + * @param {number[]} nums + * @return {number[]} + */ +var productExceptSelf = function (nums) { + + const NUMS_LENGTH = nums.length; + const isZeroArray = []; //boolean + let zeroCount = 0; + + let totalProduct = nums.reduce((acc, item) => { + if (item === 0) { + zeroCount++; + isZeroArray.push(true); + return acc; + } else { + isZeroArray.push(false); + return acc * item; + } + }, 1); + + // 엣지 케이스 대비 1: nums의 요소 중 0이 두 개 이상인 경우 + if (zeroCount >= 2) { + totalProduct = 0; + } + + const tempArray = []; + + for (let i = 0; i < NUMS_LENGTH; i++) { + if (isZeroArray[i] === true) { + tempArray.push(totalProduct); + } else if (zeroCount >= 1) { + // 엣지 케이스 대비 2: isZeroArray[i]가 false 더라도 nums의 요소 중 zero가 하나라도 있는 경우 + // (지금 보니 이 부분은 zeroCount === 1로 했어도 될 것 같네요...) + tempArray.push(0); + } else { + tempArray.push(totalProduct / nums[i]); + } + } + + return tempArray; +}; + diff --git a/valid-anagram/robinyoon-dev.js b/valid-anagram/robinyoon-dev.js new file mode 100644 index 000000000..fca7358e3 --- /dev/null +++ b/valid-anagram/robinyoon-dev.js @@ -0,0 +1,21 @@ +/** + * @param {string} s + * @param {string} t + * @return {boolean} + */ +var isAnagram = function (s, t) { + //1. s와 t를 Array로 만든다. + const sArray = s.split(""); + const tArray = t.split(""); + + //2. sArray와 tArray의 sort를 같게 만든다. + const sortedSArray = sArray.sort(); + const sortedTArray = tArray.sort(); + + //3. sArray와 tArray가 같은지 판별한다. + const result = JSON.stringify(sortedSArray) === JSON.stringify(sortedTArray); + + //4. 같으면 true를, 다르면 false를 반환한다. + return result; + +};