diff --git a/longest-substring-without-repeating-characters/higeuni.js b/longest-substring-without-repeating-characters/higeuni.js new file mode 100644 index 000000000..747c1b614 --- /dev/null +++ b/longest-substring-without-repeating-characters/higeuni.js @@ -0,0 +1,28 @@ +/** + * @param {string} s + * @return {number} + * + * complexity + * time: O(n) + * space: O(n) + */ +var lengthOfLongestSubstring = function(s) { + let set = new Set(); + let left = 0; + let answer = 0; + + for(let i=0; i { + if (row < 0 || col < 0 || row >= numRows || col >= numCols || grid[row][col] === '0') return; + + grid[row][col] = '0'; + + for (let i = 0; i < 4; ++i) { + dfs(row + dr[i], col + dc[i]); + } + }; + + for (let r = 0; r < numRows; ++r) { + for (let c = 0; c < numCols; ++c) { + if (grid[r][c] === '1') { + dfs(r, c); + answer++; + } + } + } + + return answer; +}; + diff --git a/reverse-linked-list/higeuni.js b/reverse-linked-list/higeuni.js new file mode 100644 index 000000000..01944bafb --- /dev/null +++ b/reverse-linked-list/higeuni.js @@ -0,0 +1,25 @@ +/** + * @param {ListNode} head + * @return {ListNode} + * + * 접근 + * ListNode 타입에 대해서 공부하고, 링크드 리스트 개념을 접목해서 문제를 풀이 + * + * complexity + * time: O(n) + * space: O(1) + */ +var reverseList = function(head) { + let newList = null + let curNode = null + + while(head){ + curNode = head.next + head.next = newList + newList = head + head = curNode + } + + return newList +}; + diff --git a/unique-paths/higeuni.js b/unique-paths/higeuni.js new file mode 100644 index 000000000..3040bbbd7 --- /dev/null +++ b/unique-paths/higeuni.js @@ -0,0 +1,24 @@ +/** + * @param {number} m + * @param {number} n + * @return {number} + * + * 접근 + * dynamic programming으로 접근 + * 초기 점화식 : dp[i][j] = dp[i-1][j] + dp[i][j-1] + * 하지만 1차원만 사용해도 되기 때문에 1차원으로 접근 + * + * complexity + * time: O(m*n) + * space: O(n) + */ +var uniquePaths = function (m, n) { + const dp = Array(n).fill(1); + for (let i = 1; i < m; ++i) { + for (let j = 1; j < n; ++j) { + dp[j] += dp[j - 1]; + } + } + return dp[n - 1]; +}; +