Skip to content

09_Flood Fill.md#12

Open
Kitaken0107 wants to merge 1 commit intomainfrom
Kitaken0107-patch-13
Open

09_Flood Fill.md#12
Kitaken0107 wants to merge 1 commit intomainfrom
Kitaken0107-patch-13

Conversation

@Kitaken0107
Copy link
Owner

Copy link

@hayashi-ay hayashi-ay left a comment

Choose a reason for hiding this comment

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

こちらはもう少し改善の余地がありそうです。

col = len(image[0])
same_value = image[sr][sc]

def dfs(r,c):

Choose a reason for hiding this comment

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

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:

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.

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]

Choose a reason for hiding this comment

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

same_valueは命名に改善の余地がありそうです。base_color, target_color, old_colorとかでしょうか。

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.

3 participants