Skip to content

6. Zigzag Conversion#60

Open
ryosuketc wants to merge 1 commit into
mainfrom
6_zigzag_conversion
Open

6. Zigzag Conversion#60
ryosuketc wants to merge 1 commit into
mainfrom
6_zigzag_conversion

Conversation

@ryosuketc
Copy link
Copy Markdown
Owner

row_index = 0
for i, c in enumerate(s):
zigzag[row_index].append(c)
if i != 0 and row_index == 0 or row_index == numRows - 1:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

i==0かどうかと端にたどり着いたかの判定は分けたほうが読みやすく思います。

if i == 0:
    continue
if row_index == 0 or row_index == numRows - 1:
    going_down = not going_down

* これを理解した段階で解答のコードなとは見ず、再度考えた。
* トータル 25:00 弱くらいで `Solution1` 書いた。
* 最初、`numRows <= 1` のケースを考えていなくて WA
* また2次元リストに対する list comprehension を久しぶりに書いたので
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

list comprehension をネストすると読みにくいため、避けたほうが良いと思います。

row_index += 1
else:
row_index -= 1
return ''.join(c for row in zigzag for c in row)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

読みやすいです。

while row_index < numRows - 1:
yield row_index
row_index += 1
while row_index > 0:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

好みの範囲かもしれませんが、0 < row_index も直観的で一考の余地があると思います。

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