Rotting Oranges#91
Open
Yuto729 wants to merge 1 commit into
Open
Conversation
nodchip
reviewed
Jul 23, 2026
| fresh_count = 0 | ||
| for i in range(m): | ||
| for j in range(n): | ||
| if grid[i][j] == 2: |
There was a problem hiding this comment.
1 と 2 がマジックナンバーになっているのが気になりました。 FRESH と ROTTING などの定数に置くと良いと思いました。
| minutes += 1 | ||
| for r, c in current_level: | ||
| for dr, dc in direction: | ||
| next_r, next_c = r + dr, c + dc |
There was a problem hiding this comment.
1 行で複数の変数に代入しても、あまり読みやすくならないと思います。変数の代入は 1 行ずつ行ったほうが良いと思います。
| minutes += 1 | ||
| for r, c in rotten_oranges: | ||
| for dr, dc in [(1, 0), (0, 1), (-1, 0), (0, -1)]: | ||
| if r + dr < 0 or len(grid) <= r + dr or c + dc < 0 or len(grid[0]) <= c + dc: |
There was a problem hiding this comment.
Step 1 のように変数に置いたほうが、見通しが良くなると思いました。
next_r = r + dr
next_c = c + dc| minutes += 1 | ||
| for r, c in rotten_oranges: | ||
| for dr, dc in [(1, 0), (0, 1), (-1, 0), (0, -1)]: | ||
| if r + dr < 0 or len(grid) <= r + dr or c + dc < 0 or len(grid[0]) <= c + dc: |
There was a problem hiding this comment.
Step 1 のように数直線上に一直線になるように書いたほうが、見通しが良くなると思いました。
if not (0 <= r + dr < len(grid) and 0 <= c + dc < len(grid[0])):
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.
解く問題
Rotting Oranges
次に解く問題