File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
container-with-most-water Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ /* * 시간 : O(n), 공간 : O(1)*/
3
+ fun maxArea (height : IntArray ): Int {
4
+ var maxDiff = 0
5
+ var left = 0
6
+ var right = height.lastIndex
7
+ // left, right값을 순차적으로 조회해서 물높이를 구하고,
8
+ // left < right값 보다 작으면 left증가시킨다. 반대는 right 감소
9
+ while (left < right) {
10
+ maxDiff = max(maxDiff, (right - left) * min(height[left], height[right]))
11
+ // 너비 : right - left
12
+ // 현재 높이 : min(height[left], height[right])
13
+ // 너비 * 현재 높이가 maxDiff 비교하여 더 큰값이 maxDiff가 된다.
14
+ if (height[left] < height[right]) {
15
+ left++
16
+ } else {
17
+ right--
18
+ }
19
+ }
20
+ return maxDiff
21
+ }
22
+ }
Original file line number Diff line number Diff line change 1
1
package leetcode_study
2
2
3
3
class Solution {
4
+ /* * 시간 : O(n), 공간 : O(n) */
4
5
fun isValid (s : String ): Boolean {
5
6
val stack = Stack <Char >()
6
7
val openParentheses = " ([{"
You can’t perform that action at this time.
0 commit comments