Skip to content

Conversation

@shining-ai
Copy link
Owner

# brute forceと同じ考え方だが、左右の壁の最大値を記憶しておく
class Solution:
def trap(self, height: List[int]) -> int:
max_left = [0] * len(height) # [0,i]の範囲の最大値
Copy link

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 あたりはいかがでしょうか?

Copy link
Owner Author

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 = []
Copy link

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とは別のループで構築する

Choose a reason for hiding this comment

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

max_height_in_rightmax_heights_in_leftの二つの変数名何か気になるところありませんか?

Copy link

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の二つの変数名何か気になるところありませんか?

これ、私が推奨した変数名ですね…。申し訳ないです…。

Copy link
Owner Author

Choose a reason for hiding this comment

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

right側だけheightが複数形になってませんでした。

Choose a reason for hiding this comment

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

いえいえ、変数名は複数形でも単数形でも良さそうなのですが、統一した方が良さそうですよね。

Copy link

Choose a reason for hiding this comment

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

height と heights の違い、見落としておりました。 nice catch です。

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.

4 participants