Skip to content

Create 6. Zigzag Conversion.md#57

Open
fuga-98 wants to merge 1 commit into
mainfrom
6.-Zigzag-Conversion
Open

Create 6. Zigzag Conversion.md#57
fuga-98 wants to merge 1 commit into
mainfrom
6.-Zigzag-Conversion

Conversation

@fuga-98
Copy link
Copy Markdown
Owner

@fuga-98 fuga-98 commented Jun 1, 2025

Comment thread 6. Zigzag Conversion.md
- 二次元のほうがジグザグを作っている感じがあって好みかなあ。
- "".join(c for row_chars in rows for c in row_chars)

こう書けるらしい。少し読みにくく感じたのですが、許容ですかね。
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

はじめてみる文法があったら、一応、公式ドキュメントをあたっておきましょう。
https://docs.python.org/3/reference/expressions.html#generator-expressions

Comment thread 6. Zigzag Conversion.md
class Solution:
def convert(self, s: str, numRows: int) -> str:
s_length = len(s)
zigzag = [['' for _ in range(len(s))] for _ in range(numRows)]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

(コピペミスだと思いますが)謎のインデントがあります。

Comment thread 6. Zigzag Conversion.md
Comment on lines +125 to +139
def move_down(index):
row = 0
while index < len(s) and row < numRows:
zigzag[row].append(s[index])
row += 1
index += 1
return index

def move_up(index):
row = numRows - 2
while index < len(s) and row > 0:
zigzag[row].append(s[index])
row -= 1
index += 1
return index
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

現在位置の移動を関数化して切り出しているのは読みやすいと感じました。
変数 column を取り除いているので好みの問題ですが、 move_up だと垂直移動を想起するので mode_up_diagonallyでも良いかと思いました。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

これ関数の実体に合わせるか、やりたいことに合わせるか迷いました。

@hroc135
Copy link
Copy Markdown

hroc135 commented Jun 15, 2025

いいと思いました。60問お疲れ様でした!

Comment thread 6. Zigzag Conversion.md
row -= 1
column += 1
return s_i, column

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

関数中の空行は 1 行で十分だと思います。

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.

5 participants