Skip to content

84. Largest Rectangle in Histogram#12

Open
yamashita-ki wants to merge 2 commits intomainfrom
leetcode/84
Open

84. Largest Rectangle in Histogram#12
yamashita-ki wants to merge 2 commits intomainfrom
leetcode/84

Conversation

@yamashita-ki
Copy link
Owner

public int largestRectangleArea(int[] heights) {
ArrayDeque<ContinuousBar> continuousBars = new ArrayDeque<>();
int maxSize = 0;
int heightsLength = heights.length;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

私はこれ変数に置かないかもしれません。(特に扱いやすくなっていないので。)まあ、置いてもいいでしょう。

- 最後にStackに残った要素を計算する
- このコードしか思いつかなかったが、ACできなかった理由としては
- addFirstしているため単調増加Stackを保てなかった
- 落ちるケース[3,6,5,7,4,8,1,0]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

できればこういうときは最小のケースを書いておきたいです。
[1, 3, 2, 2] であってますか?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最小ケースは両端が低くて中盤に山がくる [1, 3, 2, 1] です。

}
rectangleCandidate.addLast(new RectangleCandidate(start, heights[i]));
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heights の後ろに0を追加すると、後ろのコード不要になりそうですね。(番兵。)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

確認ありがとうございます!
下記で対応しましたmm
面積を算出するコードが重複しており気になっていたのでリファクタできてよかったです
Step4を追加

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants