DEV Community

Cover image for LeetCode Problem Solving
Mahamud Pino
Mahamud Pino

Posted on

LeetCode Problem Solving

**

2. Two Sum

**
var twoSum = function (nums, target) {
for (let i = 0; i < nums.length; i++) {
let remaining = target - nums[i]
for (let j = i + 1; j < nums.length; j++) {
if (remaining === nums[j]) return [i, j]
}
}
return false
};
console.log(twoSum([3, 2, 4], 6)) //[1,2]

Image description

**

11. Container With Most Water

**
var maxArea = function (height) {
let total = 0
let start = 0
let end = height.length - 1
while (start < end) {
let heights = Math.min(height[start], height[end])
let width = end - start
let current = heights * width
total = Math.max(total, current)
if (height[start] <= height[end]) {
start++
}
else {
end--
}
}
return total
};
console.log(maxArea([1, 8, 6, 2, 5, 4, 8, 3, 7])) //49

Image description

Top comments (0)