二叉树遍历144. Binary Tree Preorder Traversal
来源:互联网 发布:hdfs数据删除如何恢复 编辑:程序博客网 时间:2024/04/30 14:17
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: vector<int> preorderTraversal(TreeNode* root) { vector<int> ans; stack<TreeNode *>s; TreeNode *current; if (root == NULL) { return ans; } s.push(root); while (!s.empty()) { current = s.top(); s.pop(); ans.push_back(current->val); if (current->right != NULL) s.push(current->right); if (current->left !=NULL) s.push(current->left); } return ans; }};
0 0
- 二叉树遍历144. Binary Tree Preorder Traversal
- 【二叉树先序遍历】Binary Tree Preorder Traversal
- 144.Binary Tree Preorder Traversal(二叉树先序遍历)
- 144.leetcode Binary Tree Preorder Traversal(medium)[二叉树先序遍历]
- [leetcode-二叉树先序遍历]--144.Binary Tree Preorder Traversal
- 二叉树先序遍历——144. Binary Tree Preorder Traversal
- [LeetCode]144. Binary Tree Preorder Traversal--二叉树前序遍历
- leetcode 144. Binary Tree Preorder Traversal 二叉树前序遍历 + DFS
- 二叉树的先序遍历 Binary Tree Preorder Traversal
- Binary Tree Preorder Traversal--二叉树的先序遍历
- Binary Tree Preorder Traversal 二叉树的前序遍历
- binary-tree-preorder-traversal(二叉树的前序遍历)
- binary-tree-preorder-traversal(先序遍历二叉树)
- LeetCode 144. Binary Tree Preorder Traversal(二叉树前缀遍历)
- 144. Binary Tree Preorder Traversal (二叉树的先序遍历)
- 144. Binary Tree Preorder Traversal 二叉树的前序遍历
- LeetCode 二叉树 | 144. Binary Tree Preorder Traversal
- 【二叉树经典问题】 144. Binary Tree Preorder Traversal
- Linux下oracle数据库启动和关闭操作
- Idea利用Git提交代码到github步骤
- 二叉树遍历94. Binary Tree Inorder Traversal
- JAVA多线程和并发基础面试问答(转载)
- 136. Single Number
- 二叉树遍历144. Binary Tree Preorder Traversal
- myisam和innodb的区别
- 数据库的原理
- HDU 5072Coprime
- 冒泡排序
- 计算机网路(四)使用广播信道的以太网
- 调用Activity返回结果
- Android 自定义视频录制终极解决方案(翻转问题)
- luogu【P1478】陶陶摘苹果(升级版)