{"id":22513877,"url":"https://github.com/emahtab/binary-tree-zigzag-level-order-traversal","last_synced_at":"2026-02-12T18:02:51.023Z","repository":{"id":79525316,"uuid":"238518579","full_name":"eMahtab/binary-tree-zigzag-level-order-traversal","owner":"eMahtab","description":"Binary Tree Zigzag (Spiral) Order Traversal","archived":false,"fork":false,"pushed_at":"2020-02-05T18:23:53.000Z","size":4,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-03T08:49:20.865Z","etag":null,"topics":["bfs","binary-tree","leetcode","problem-solving"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eMahtab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-05T18:20:49.000Z","updated_at":"2020-02-05T18:24:55.000Z","dependencies_parsed_at":"2023-05-10T17:00:41.016Z","dependency_job_id":null,"html_url":"https://github.com/eMahtab/binary-tree-zigzag-level-order-traversal","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/eMahtab/binary-tree-zigzag-level-order-traversal","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fbinary-tree-zigzag-level-order-traversal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fbinary-tree-zigzag-level-order-traversal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fbinary-tree-zigzag-level-order-traversal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fbinary-tree-zigzag-level-order-traversal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eMahtab","download_url":"https://codeload.github.com/eMahtab/binary-tree-zigzag-level-order-traversal/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fbinary-tree-zigzag-level-order-traversal/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29375620,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-12T08:51:36.827Z","status":"ssl_error","status_checked_at":"2026-02-12T08:51:26.849Z","response_time":55,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bfs","binary-tree","leetcode","problem-solving"],"created_at":"2024-12-07T03:14:46.919Z","updated_at":"2026-02-12T18:02:50.989Z","avatar_url":"https://github.com/eMahtab.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Binary Tree Zigzag Level Order Traversal\n## https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal\n\nGiven a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).\n```\nFor example:\nGiven binary tree [3,9,20,null,null,15,7],\n    3\n   / \\\n  9  20\n    /  \\\n   15   7\nreturn its zigzag level order traversal as:\n[\n  [3],\n  [20,9],\n  [15,7]\n]\n```\n\n## Implementation :\n\n```java\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n *     int val;\n *     TreeNode left;\n *     TreeNode right;\n *     TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n    public List\u003cList\u003cInteger\u003e\u003e zigzagLevelOrder(TreeNode root) {\n        List\u003cList\u003cInteger\u003e\u003e list = new ArrayList\u003c\u003e();\n        if(root == null)\n            return list;\n        Queue\u003cTreeNode\u003e queue = new LinkedList\u003c\u003e();\n        queue.offer(root);\n        int currentLevel = 0;\n        while(!queue.isEmpty()){\n            currentLevel++;\n            List\u003cInteger\u003e level = new ArrayList\u003c\u003e();\n            int size = queue.size();\n            for(int i = 0; i \u003c size; i++){\n                TreeNode current = queue.poll();\n                level.add(current.val);\n                if(current.left != null)\n                    queue.offer(current.left);\n                if(current.right != null)\n                    queue.offer(current.right);\n            }\n            if(currentLevel % 2 == 0)\n                Collections.reverse(level);\n            list.add(level);\n            \n        }\n       return list; \n    }\n}\n```\n\n# References :\nhttps://www.youtube.com/watch?v=smjr2ow6oKc (Alternate approach using two stacks)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fbinary-tree-zigzag-level-order-traversal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femahtab%2Fbinary-tree-zigzag-level-order-traversal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fbinary-tree-zigzag-level-order-traversal/lists"}