Created
August 24, 2022 21:42
-
-
Save D-Lite/f4d74f350ca8ab92f7cfdc8358290709 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {number[]} height | |
* @return {number} | |
*/ | |
var maxArea = function(height) { | |
let left = 0 | |
let right = height.length - 1 | |
let answer = 0 | |
while(left < right) { | |
let theight = Math.min(height[left], height[right]) | |
let area = theight * (right - left) | |
answer = Math.max(answer, area) | |
if(height[right] > height[left]) { | |
left++ | |
} else { | |
right-- | |
} | |
} | |
return answer | |
}; | |
/** | |
* @param {number[]} nums | |
* @return {number} | |
*/ | |
var findMin = function(nums) { | |
let left = 0, right = nums.length - 1; | |
const last = nums.length - 1; | |
while (left <= right) { | |
const mid = Math.floor((left + right) / 2); | |
if ( | |
nums[mid] < nums[mid - 1] && nums[mid] < nums[mid + 1] || | |
mid === 0 && nums[mid] < nums[mid + 1] || | |
mid === last | |
) { | |
return nums[mid]; | |
} | |
if (nums[mid] > nums[last]) { | |
left = mid + 1; | |
} else { | |
right = mid - 1; | |
} | |
} | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment