Skip to content

Commit

Permalink
[WEEK6](gmlwls96) Container With Most Water
Browse files Browse the repository at this point in the history
  • Loading branch information
gmlwls96 committed Jan 13, 2025
1 parent ceda89c commit 871575e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions container-with-most-water/gmlwls96.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Solution {
/** 시간 : O(n), 공간 : O(1)*/
fun maxArea(height: IntArray): Int {
var maxDiff = 0
var left = 0
var right = height.lastIndex
// left, right값을 순차적으로 조회해서 물높이를 구하고,
// left < right값 보다 작으면 left증가시킨다. 반대는 right 감소
while (left < right) {
maxDiff = max(maxDiff, (right - left) * min(height[left], height[right]))
// 너비 : right - left
// 현재 높이 : min(height[left], height[right])
// 너비 * 현재 높이가 maxDiff 비교하여 더 큰값이 maxDiff가 된다.
if (height[left] < height[right]) {
left++
} else {
right--
}
}
return maxDiff
}
}
1 change: 1 addition & 0 deletions valid-parentheses/gmlwls96.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package leetcode_study

class Solution {
/** 시간 : O(n), 공간 : O(n) */
fun isValid(s: String): Boolean {
val stack = Stack<Char>()
val openParentheses = "([{"
Expand Down

0 comments on commit 871575e

Please sign in to comment.