Skip to content

103.binary tree zigzag level order traversal#26

Open
nicah4o wants to merge 1 commit into
mainfrom
103.binary-tree-zigzag-level-order-traversal
Open

103.binary tree zigzag level order traversal#26
nicah4o wants to merge 1 commit into
mainfrom
103.binary-tree-zigzag-level-order-traversal

Conversation

@nicah4o
Copy link
Copy Markdown
Owner

@nicah4o nicah4o commented Jun 4, 2026

if (!root) return values_by_level;
queue<TreeNode*> nodeq;
nodeq.push(root);
bool is_left = true;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

識別子が動詞の原形や命令形から始まっている場合、関数名のように感じる場合があります。避けたほうが無難かもしれません。自分なら left_to_right と名付けると思います。

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.

レビューありがとうございます。
なるほど、そのような感覚があるというのは参考になります。
意味的にもleft_to_rightの方が正確で、bool型からの連想でis_leftと付けましたが不正確でした。

TreeNode* node = nodeq.front();
nodeq.pop();
values.push_back(node->val);
if(node->left){
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

こちらのコメントをご参照ください。
colorbox/leetcode#49 (comment)

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.

ありがとうございます。
leetcodeのformat codeをよく使うのでここら辺気を配れていませんでした。

vector<vector<int>> zigzagLevelOrder(TreeNode* root) {
vector<vector<int>> values_by_level;
bool is_reversed = false;
stack<TreeNode*> nodest;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

こちらのコメントをご参照ください。
hemispherium/LeetCode_Arai60#10 (comment)

また、変数名に型名を入れても、読み手にとってあまり有益ではないように感じました。 nodes で十分だと思います。 stack であることを特に明示したい場合は node_stack も良いと思います。

```cpp
class Solution {
public:
vector<deque<int>> values_deque;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

こちらのコメントをご参照ください。
5ky7/arai60#22 (comment)

class Solution {
public:
vector<deque<int>> values_deque;
void dfs(TreeNode* node, int level) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

メンバー変数とメンバー関数間、メンバー関数とメンバー関数間には空行を入れても良いと思います。

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.

ありがとうございます。
メンバー変数関数の間は改行するという感覚参考にさせていただきます。

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.

2 participants