We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b34dcf8 commit 2a7adf3Copy full SHA for 2a7adf3
lcof/面试题32 - I. 从上到下打印二叉树/README.md
@@ -150,6 +150,38 @@ func levelOrder(root *TreeNode) []int {
150
}
151
```
152
153
+### **C++**
154
+
155
+```cpp
156
+class Solution {
157
+public:
158
+ vector<int> levelOrder(TreeNode* root) {
159
+ vector<int> ret;
160
+ if (!root) {
161
+ return ret;
162
+ }
163
164
+ queue<TreeNode *> q;
165
+ q.push(root);
166
167
+ while (!q.empty()) {
168
+ auto head = q.front();
169
+ q.pop();
170
+ ret.push_back(head->val);
171
+ if (head->left) {
172
+ q.push(head->left);
173
174
175
+ if (head->right) {
176
+ q.push(head->right);
177
178
179
180
181
182
+};
183
+```
184
185
### **...**
186
187
0 commit comments