Skip to content

Conversation

@skypenguins
Copy link
Owner

6. Zigzag Conversion

次回予告: 8. String to Integer (atoi)

@skypenguins skypenguins self-assigned this May 27, 2025
if numRows == 1 or numRows >= len(s):
return s

row_i = 0
Copy link

Choose a reason for hiding this comment

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

個人的にはrow_iと省略せずにrow_indexとしたほうがわかりやすい気がします。
より名前の長いdirectionと同じぐらい(というより、組になって)重要な変数だからだと思います。

Copy link

Choose a reason for hiding this comment

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

単に row としてもよいと思います。


for i in range(numRows):
zigzag_rows[i] = ''.join(zigzag_rows[i])
flattened_rows = ''.join(zigzag_rows)
Copy link

@potrue potrue May 28, 2025

Choose a reason for hiding this comment

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

itertools.chain.from_iterable(zigzag_rows)
としたり、わかりにくいですが
[s for row in zigzag_rows for s in row]
という書き方もあるみたいです。

https://docs.python.org/3/library/itertools.html#itertools.chain
https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions

Copy link

Choose a reason for hiding this comment

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

そうですね。Generator comprehension は nest することができます。二重に内包表記を書けるということです。
[] はリストが作られますが、() にしておくと、List comprehension ではなくてジェネレーターになります。

"".join(c for row_chars in rows for c in row_chars)
https://discord.com/channels/1084280443945353267/1322513618217996338/1361352231668158564

* 解答時間
- 1回目: 3:47
- 2回目: 3:55
- 3回目: 5:07
Copy link

@potrue potrue May 28, 2025

Choose a reason for hiding this comment

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

余談ですが、恐らく直近で問題問わずレビュー依頼を出していた5人にdiscordでメンションをしている気がするのですが、直近で同じ問題(今回であれば6. zigzag conversion)を解いた方にメンションを送っているのが多数派だと思います。(やったことない問題のレビューも面白いので、自分は大丈夫ですが)

自分はdiscordの検索欄で「in: レビュー依頼 6. zigzag」などと検索して探しています。

Copy link
Owner Author

@skypenguins skypenguins May 29, 2025

Choose a reason for hiding this comment

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

ありがとうございます。いつも誰に出そうか迷っていたので、そういった情報はとても助かります。

row_i += direction

for i in range(numRows):
zigzag_rows[i] = ''.join(zigzag_rows[i])
Copy link

Choose a reason for hiding this comment

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

zigzag_rowsがlist[list[str]]からlist[str]になるのは驚きました。避けたほうが無難かと思います

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants