Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// Tags: Two Pointers, Greedy
package com.leetcode.medium;

public class ContainerWithMostWater11 {
/*
Time Complexity: O(n)
Space Complexity: O(1)
/**
* Time Complexity: O(n)
* <p>
* Space Complexity: O(1)
*/
public int maxArea(int[] height) {
int l = 0;
Expand All @@ -18,9 +22,4 @@ public int maxArea(int[] height) {
}
return res;
}

public static void main(String[] args) {
int[] height = new int[]{1, 8, 6, 2, 5, 4, 8, 3, 7};
System.out.println(new ContainerWithMostWater11().maxArea(height)); // 49
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.leetcode.medium;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class ContainerWithMostWater11Test {
private ContainerWithMostWater11 solution;

@BeforeEach
void setUp() {
solution = new ContainerWithMostWater11();
}

@Test
void testMaxArea_Example1() {
int[] height = {1, 8, 6, 2, 5, 4, 8, 3, 7};
int expected = 49;

int result = solution.maxArea(height);

assertEquals(expected, result);
}

@Test
void testMaxArea_Example2() {
int[] height = {1, 1};
int expected = 1;

int result = solution.maxArea(height);

assertEquals(expected, result);
}
}
Loading