From 2120e408f0d438f4ec12dd376590281d0725c4f8 Mon Sep 17 00:00:00 2001 From: Hilal Morrar Date: Fri, 4 Jul 2025 12:44:08 -0500 Subject: [PATCH 1/2] Update Go solution for 0011 --- go/0011-container-with-most-water.go | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/go/0011-container-with-most-water.go b/go/0011-container-with-most-water.go index a2b4bf806..379e2b429 100644 --- a/go/0011-container-with-most-water.go +++ b/go/0011-container-with-most-water.go @@ -1,28 +1,19 @@ func maxArea(height []int) int { - left := 0 - right := len(height) - 1 + l, r := 0, len(height)-1 res := 0 - for left < right { - area := min(height[left], height[right]) * (right - left) + for l < r { + area := min(height[l], height[r]) * (r - l) if area > res { res = area } - if height[left] > height[right] { - right-- + if height[l] <= height[r] { + l++ } else { - left++ + r-- } } - return res -} - -func min(a, b int) int { - if a < b { - return a - } - return b } \ No newline at end of file From a928a990efde3a44a9d5b6784bba19ddc8470a7a Mon Sep 17 00:00:00 2001 From: Hilal Morrar Date: Sun, 6 Jul 2025 14:02:37 -0500 Subject: [PATCH 2/2] Update Go solution for 0104 --- go/0104-maximum-depth-of-binary-tree.go | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/go/0104-maximum-depth-of-binary-tree.go b/go/0104-maximum-depth-of-binary-tree.go index e2c292b92..88931ed17 100644 --- a/go/0104-maximum-depth-of-binary-tree.go +++ b/go/0104-maximum-depth-of-binary-tree.go @@ -3,12 +3,5 @@ func maxDepth(root *TreeNode) int { return 0 } - left := maxDepth(root.Left) - right := maxDepth(root.Right) - - if left > right { - return 1 + left - } - - return right + 1 + return 1 + max(maxDepth(root.Left), maxDepth(root.Right)) } \ No newline at end of file