You are viewing a single comment's thread. Return to all comments →
C# solution using stacks a subroutine (which can be replaced with a simple Long Variable). but did for it.
public static long largestRectangle(List<int> h) { long total = 0; Stack<int> stack = new Stack<int>(); for (int i = 0; i < h.Count; i++) { for (int j = i; j < h.Count; j++) { if (h[j] >= h[i]) { stack.Push(h[i]); } else { break; } } for (int j = i - 1; j >= 0; j--) { if (h[j] >= h[i]) { stack.Push(h[i]); } else { break; } } if (stack.Sum() > total) total = stack.Sum(); stack.Clear(); } return total; }
Seems like cookies are disabled on this browser, please enable them to open this website
Largest Rectangle
You are viewing a single comment's thread. Return to all comments →
C# solution using stacks a subroutine (which can be replaced with a simple Long Variable). but did for it.