fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Ideone
  6. {
  7. public static int maxArea(int[] height) {
  8. int maxarea = 0, l = 0, r = height.length - 1;
  9. while (l < r) {
  10. // Code obtained from http://w...content-available-to-author-only...s.com
  11. maxarea = Math.max(maxarea, Math.min(height[l], height[r]) * (r - l));
  12. if (height[l] < height[r])
  13. l++;
  14. else
  15. r--;
  16. }
  17. return maxarea;
  18. }
  19.  
  20. public static void main (String[] args) throws java.lang.Exception
  21. {
  22. int[] heights = {1, 8, 6, 2, 5, 4, 8, 3, 7};
  23. int maxarea = maxArea(heights);
  24. System.out.println(maxarea);
  25. }
  26. }
Success #stdin #stdout 0.05s 2184192KB
stdin
Standard input is empty
stdout
49