leetcode-114. Flatten Binary Tree to Linked List
来源:互联网 发布:南极争夺战 知乎 编辑:程序博客网 时间:2024/06/03 19:40
而叉树的先序遍历。
C++ 代码:
/** * 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: void flatten(TreeNode* root) { queue<TreeNode *> q; if (root==NULL) return; help(root, q); TreeNode *temp1= q.front(); root = temp1; q.pop(); while (q.size()) { TreeNode *temp2 = q.front(); q.pop(); temp1->right = temp2; temp1->left = NULL; temp1 = temp2; } return; } void help(TreeNode* root, queue<TreeNode*> & q) { if (root == NULL) return ; q.push(root); help(root->left, q); help(root->right, q); }};
0 0
- LeetCode: Flatten Binary Tree to Linked List
- LeetCode Flatten Binary Tree to Linked List
- LeetCode: Flatten Binary Tree to Linked List
- [Leetcode] Flatten Binary Tree to Linked List
- [LeetCode] Flatten Binary Tree to Linked List
- Leetcode: Flatten Binary Tree to Linked List
- leetcode Flatten Binary Tree to Linked List
- LeetCode Flatten Binary Tree to Linked List
- LeetCode - Flatten Binary Tree to Linked List
- 【leetcode】Flatten Binary Tree to Linked List
- [LeetCode]Flatten Binary Tree to Linked List
- [Leetcode]Flatten Binary Tree to Linked List
- [leetcode]Flatten Binary Tree to Linked List
- LeetCode-Flatten Binary Tree to Linked List
- [leetcode] Flatten Binary Tree to Linked List
- LeetCode - Flatten Binary Tree to Linked List
- LeetCode:Flatten Binary Tree to Linked List
- [LeetCode] Flatten Binary Tree to Linked List
- Hibernate学习-07:CRUD(增删改查)操作之查询多条/所有记录HQL、QBC、SQL三种方式
- day76_babSport 第二天
- 形参和实参的区别
- 想染指系统架构?看这篇就够了
- jvm 指令
- leetcode-114. Flatten Binary Tree to Linked List
- c++ BYTE、WORD与DWORD类型
- 【linux】虚拟机开发场景下NAT上网配置
- EVT, DVT, PVT分别是什么意思?
- mysql根据时间戳查询数据
- POI EXCEL
- React Native之弹框存在TextInput,输入框有焦点情况下需要点击两次才可触发事件-解决
- 软件构建(Construction)
- 进度条,TabHost,ViewFlipper、菜单