LeetCode(116) Populating Next Right Pointers in Each Node
2015-08-06 21:28
615 查看
深度优先搜索
[code]/** * Definition for binary tree with next pointer. * struct TreeLinkNode { * int val; * TreeLinkNode *left, *right, *next; * TreeLinkNode(int x) : val(x), left(NULL), right(NULL), next(NULL) {} * }; */ class Solution { public: void connect(TreeLinkNode *root) { if(root == NULL) return; if(root->left == NULL) return; if(root->next == NULL) { root->left->next = root->right; root->right->next = NULL; } if(root->next != NULL) { root->left->next = root->right; root->right->next = root->next->left; } connect(root->left); connect(root->right); } };
相关文章推荐
- Nodejs学习笔记01【EventEmitter】
- leetcode_Delete Node in a Linked List
- node.js概述
- ERROR: Can't get master address from ZooKeeper; znode data == null
- node 日志管理log4js【转】
- JS childNodes属性
- inode 耗尽处理
- Populating Next Right Pointers in Each Node II
- UbuntuServer安装Node.js
- sudo 运行 npm或node时,出现找不到命令
- Populating Next Right Pointers in Each Node
- ENode简介与各种教学视频资源汇总(要进群这篇文章必看)
- 30. Element parentNode 属性
- 28. Element nodeValue 属性
- 27. Element nodeType 属性
- 26. Element nodeName 属性
- Node.js 文件系统fs模块
- Delete Node in a Linked List
- Node.js 异步式 I/O 与事件驱动实战
- [LeetCode]Swap Nodes in Pairs