From d05dc41bc86f5642797ca47bcf449b1926be1406 Mon Sep 17 00:00:00 2001 From: "junfeng.fj" Date: Sun, 24 Jan 2021 14:55:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=86lcof-cpp=E4=B8=AD[?= =?UTF-8?q?=E4=BB=8E=E4=B8=8A=E5=88=B0=E4=B8=8B=E6=89=93=E5=8D=B0=E4=BA=8C?= =?UTF-8?q?=E5=8F=89=E6=A0=91]=E4=B8=ADREADME.md=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../README.md" | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git "a/lcof/\351\235\242\350\257\225\351\242\23032 - I. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23032 - I. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221/README.md" index 0223442d02e5e..bf6b689fada0b 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23032 - I. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23032 - I. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221/README.md" @@ -150,6 +150,38 @@ func levelOrder(root *TreeNode) []int { } ``` +### **C++** + +```cpp +class Solution { +public: + vector levelOrder(TreeNode* root) { + vector ret; + if (!root) { + return ret; + } + + queue q; + q.push(root); + + while (!q.empty()) { + auto head = q.front(); + q.pop(); + ret.push_back(head->val); + if (head->left) { + q.push(head->left); + } + + if (head->right) { + q.push(head->right); + } + } + + return ret; + } +}; +``` + ### **...** ```