6. Zigzag Conversion#60
Open
ryosuketc wants to merge 1 commit into
Open
Conversation
yakataN
reviewed
Jul 31, 2025
| 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: |
There was a problem hiding this comment.
i==0かどうかと端にたどり着いたかの判定は分けたほうが読みやすく思います。
if i == 0:
continue
if row_index == 0 or row_index == numRows - 1:
going_down = not going_down
nodchip
reviewed
Jul 31, 2025
| * これを理解した段階で解答のコードなとは見ず、再度考えた。 | ||
| * トータル 25:00 弱くらいで `Solution1` 書いた。 | ||
| * 最初、`numRows <= 1` のケースを考えていなくて WA | ||
| * また2次元リストに対する list comprehension を久しぶりに書いたので |
There was a problem hiding this comment.
list comprehension をネストすると読みにくいため、避けたほうが良いと思います。
fuga-98
reviewed
Jul 31, 2025
| row_index += 1 | ||
| else: | ||
| row_index -= 1 | ||
| return ''.join(c for row in zigzag for c in row) |
skypenguins
reviewed
Aug 2, 2025
| while row_index < numRows - 1: | ||
| yield row_index | ||
| row_index += 1 | ||
| while row_index > 0: |
There was a problem hiding this comment.
好みの範囲かもしれませんが、0 < row_index も直観的で一考の余地があると思います。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
6. Zigzag Conversion
https://leetcode.com/problems/zigzag-conversion/