From df8a888b1b7ca701ec48f90c239f1390850443c8 Mon Sep 17 00:00:00 2001 From: HiGeuni Date: Sat, 18 Jan 2025 21:52:54 +0900 Subject: [PATCH] Feat: Solution for Week6 --- container-with-most-water/higeuni.js | 28 ++++++++++++++ longest-increasing-subsequence/higeuni.js | 41 ++++++++++++++++++++ valid-parentheses/higeuni.js | 47 +++++++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 container-with-most-water/higeuni.js create mode 100644 longest-increasing-subsequence/higeuni.js create mode 100644 valid-parentheses/higeuni.js diff --git a/container-with-most-water/higeuni.js b/container-with-most-water/higeuni.js new file mode 100644 index 000000000..2c3c73377 --- /dev/null +++ b/container-with-most-water/higeuni.js @@ -0,0 +1,28 @@ +/** + * @param {number[]} height + * @return {number} + * + * complexity + * time: O(n) + * space: O(1) + */ + +var maxArea = function(height) { + let answer = 0; + let l = 0, r = height.length - 1; + + while(l < r) { + const area = (r - l) * Math.min(height[l], height[r]); + + answer = area > answer ? area : answer; + + if(height[l] < height[r]) { + l += 1; + }else { + r -= 1; + } + } + + return answer; +}; + diff --git a/longest-increasing-subsequence/higeuni.js b/longest-increasing-subsequence/higeuni.js new file mode 100644 index 000000000..77194d178 --- /dev/null +++ b/longest-increasing-subsequence/higeuni.js @@ -0,0 +1,41 @@ +/** + * @param {number[]} nums + * @return {number} + * + * complexity + * time: O(nlogn) : lower_bound : O(logn), for문 : O(n) + * space: O(n) + */ +var lengthOfLIS = function(nums) { + const lower_bound = (arr, value) => { + let ret = -1; + let l = 0; + let r = arr.length - 1; + + while(l <= r) { + const mid = Math.floor((l + r) / 2); + if(arr[mid] >= value) { + ret = mid; + r = mid - 1; + } else { + l = mid + 1; + } + } + + return ret; + } + + let sequence = []; + + for(let i=0; i