算法设计与应用基础
来源:互联网 发布:dota2饰品淘宝 编辑:程序博客网 时间:2024/06/06 20:52
226. Invert Binary Tree
Invert a binary tree.
4
/ \
2 7
/ \ / \
1 3 6 9
to
4
/ \
7 2
/ \ / \
9 6 3 1
Recursive
TreeNode* invertTree(TreeNode* root) { if (root) { invertTree(root->left); invertTree(root->right); std::swap(root->left, root->right); } return root;}
Non-Recursive
TreeNode* invertTree(TreeNode* root) { std::stack<TreeNode*> stk; stk.push(root); while (!stk.empty()) { TreeNode* p = stk.top(); stk.pop(); if (p) { stk.push(p->left); stk.push(p->right); std::swap(p->left, p->right); } } return root;}
阅读全文
0 0
- 算法设计与应用基础
- 算法设计与应用基础
- 算法设计与应用基础
- 算法设计与应用基础
- 算法设计与应用基础
- 算法设计与应用基础
- 算法设计与应用基础
- 算法设计与应用基础
- 算法设计与应用基础
- 算法设计与应用基础
- 算法设计与应用基础
- 算法设计与应用基础
- 算法设计与应用基础
- 算法设计与应用基础
- 算法设计与应用基础
- 算法设计与应用基础
- 算法设计与应用基础
- 算法设计与应用基础
- bzoj2295: 【POJ Challenge】我爱你啊
- 【LeetCode】Insert Delete GetRandom O(1) 系列
- 浅谈Android LRecyclerView
- HTML 基本入门
- linux安装svn使用解压包的方式
- 算法设计与应用基础
- 万物皆对象
- 网络请求框架对比
- 有监督分类:支持向量机分类
- 6月8日云栖精选夜读:mac下eclipse配置tomcat无法启动问题
- SPI时序解析
- ORACLE FlashBack操作
- Win7系统右键计算机不能打开管理选项的解决方法
- 在VirtualBox如何使其中的GNU Linux操作系统能够在全屏时进行自适应