Conversation
| col = len(image[0]) | ||
| same_value = image[sr][sc] | ||
|
|
||
| def dfs(r,c): |
There was a problem hiding this comment.
dfs は名前が悪いので、もうちょっと意味のある名前をつけませんか。いや、なんか、冷蔵庫に「電気」とか「断熱膨張」とかって名前つけないじゃないですか。「冷やす貯蔵庫」ですよね。意味といっているのは、要は、どうやってそれを作っているか動いているかは書いている人は興味があるけれども、読んでいる人、呼び出す人はそれを伝えられたからって困るわけですよ。
| same_value = image[sr][sc] | ||
|
|
||
| def dfs(r,c): | ||
| if r<0 or r > row-1 or c<0 or c > col -1 or image[r][c] != same_value or image[r][c] == newColor: |
There was a problem hiding this comment.
<や>などの演算子の前後にスペースを空けるか、空けないかはどちらでもいいですが統一されていないと読みづらいです。
There was a problem hiding this comment.
https://peps.python.org/pep-0008/#other-recommendations
Always surround these binary operators with a single space on either side: assignment (=), augmented assignment (+=, -= etc.), comparisons (==, <, >, !=, <>, <=, >=, in, not in, is, is not), Booleans (and, or, not).
If operators with different priorities are used, consider adding whitespace around the operators with the lowest priority(ies). Use your own judgment; however, never use more than one space, and always have the same amount of whitespace on both sides of a binary operator:
https://google.github.io/styleguide/pyguide.html#316-naming
Surround binary operators with a single space on either side for assignment (=), comparisons (==, <, >, !=, <>, <=, >=, in, not in, is, is not), and Booleans (and, or, not). Use your better judgment for the insertion of spaces around arithmetic operators (+, -, *, /, //, %, **, @).
| def floodFill(self, image: List[List[int]], sr: int, sc: int, newColor: int) -> List[List[int]]: | ||
| row = len(image) | ||
| col = len(image[0]) | ||
| same_value = image[sr][sc] |
There was a problem hiding this comment.
same_valueは命名に改善の余地がありそうです。base_color, target_color, old_colorとかでしょうか。
https://leetcode.com/problems/flood-fill/