-
Notifications
You must be signed in to change notification settings - Fork 0
【Grind75Hard】3問目42. Trapping Rain Water #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| # brute forceと同じ考え方だが、左右の壁の最大値を記憶しておく | ||
| class Solution: | ||
| def trap(self, height: List[int]) -> int: | ||
| max_left = [0] * len(height) # [0,i]の範囲の最大値 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
max_left ですと、最大の左を表しているように感じられます。 max_heights_in_left あたりはいかがでしょうか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
うまく命名できていないと思っていたので、ありがたいです。
前置詞をあまり使っていなかったので、勉強になります。
| # 左側の壁をstackで記憶し、右側の壁が見つかったら、貯まる水を計算する。 | ||
| class Solution: | ||
| def trap(self, height: List[int]) -> int: | ||
| left_walls = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
変数名 left_walls ですと、中にどのような値が含まれているのか分かりませんでした。 left_wall_indexes 等、インデックスが含まれていることを表す変数名のほうが良いと思います。
| @@ -0,0 +1,37 @@ | |||
| # DPを使って解く | |||
| # 変数名を修正 | |||
| # max_height_in_rightはmax_heights_in_leftとは別のループで構築する | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
max_height_in_rightとmax_heights_in_leftの二つの変数名何か気になるところありませんか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
max_height_in_rightとmax_heights_in_leftの二つの変数名何か気になるところありませんか?
これ、私が推奨した変数名ですね…。申し訳ないです…。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right側だけheightが複数形になってませんでした。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
いえいえ、変数名は複数形でも単数形でも良さそうなのですが、統一した方が良さそうですよね。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
height と heights の違い、見落としておりました。 nice catch です。
問題
https://leetcode.com/problems/trapping-rain-water/