Open
Conversation
oda
reviewed
Sep 30, 2025
| public int largestRectangleArea(int[] heights) { | ||
| ArrayDeque<ContinuousBar> continuousBars = new ArrayDeque<>(); | ||
| int maxSize = 0; | ||
| int heightsLength = heights.length; |
There was a problem hiding this comment.
私はこれ変数に置かないかもしれません。(特に扱いやすくなっていないので。)まあ、置いてもいいでしょう。
| - 最後にStackに残った要素を計算する | ||
| - このコードしか思いつかなかったが、ACできなかった理由としては | ||
| - addFirstしているため単調増加Stackを保てなかった | ||
| - 落ちるケース[3,6,5,7,4,8,1,0] |
There was a problem hiding this comment.
できればこういうときは最小のケースを書いておきたいです。
[1, 3, 2, 2] であってますか?
Owner
Author
There was a problem hiding this comment.
最小ケースは両端が低くて中盤に山がくる [1, 3, 2, 1] です。
| } | ||
| rectangleCandidate.addLast(new RectangleCandidate(start, heights[i])); | ||
| } | ||
|
|
There was a problem hiding this comment.
heights の後ろに0を追加すると、後ろのコード不要になりそうですね。(番兵。)
Owner
Author
There was a problem hiding this comment.
確認ありがとうございます!
下記で対応しましたmm
面積を算出するコードが重複しており気になっていたのでリファクタできてよかったです
Step4を追加
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://leetcode.com/problems/largest-rectangle-in-histogram/description/