Conversation
|
|
||
| rows = [[] for _ in range(numRows)] | ||
| current = 0 | ||
| adding = -1 |
There was a problem hiding this comment.
step2ではaddingをstepに変更していますが、addingでも悪くはないと思っています。
どうでしょうか。
感覚のすり合わせを行いたいです!
There was a problem hiding this comment.
ちょっとaddingという名前から中に何が入っているか分からない気がしました。ここでもstepとなってるので、stepの方がいいかと思います。
https://docs.python.org/3/library/stdtypes.html#range
|
(ちなみにですが、一度解いたことがあります) |
| for i in range(numRows): | ||
| merged_rows.extend(rows[i]) | ||
| zigzag = "".join(merged_rows) | ||
| return zigzag |
There was a problem hiding this comment.
return "".join(c for c in row for row in rows)でどうですか?上の書き方だと、コピーがあります。(forループの順番は間違っているかもしれないです…)
There was a problem hiding this comment.
コピーというと
for i in range(numRows):
merged_rows.extend(rows[i])
の部分ですかね?
提案していただいたコードだと個人的には可読性が下がる気がしており、できれば別の方式を採用したい感覚です。
There was a problem hiding this comment.
はい、rowsから文字(列)がmerged_rowsにコピーされているので、無駄な処理になっているかと。
こちらが正しかったです。"".join(char for row in rows for char in row)。これ見てすぐ意味分かると思ったのですが、そうでもないですか?
There was a problem hiding this comment.
ありがとうございます。
自分がその記法に慣れていないだけな気がしてきたので、今後使って慣れていこうと思います!
|
|
||
| rows = [[] for _ in range(numRows)] | ||
| current = 0 | ||
| adding = -1 |
問題: https://leetcode.com/problems/zigzag-conversion/description
参考:
goto-untrapped/Arai60#5
shining-ai/leetcode#60
SuperHotDogCat/coding-interview#4