AM MS 878. Boundary of Binary Tree
Code ( Language :C++) ( Judger :ip-172-31-21-252) Edit /** * Definition of TreeNode: * class TreeNode { * public: * int val; * TreeNode *left, *right; * TreeNode(int val) { * this->val = val; * this->left = this->right = NULL; * } * } */ class Solution { public : /** * @param root: a TreeNode * @return: a list of integer */ void findLeaves (TreeNode *root, vector < int > &res) { if (root == NULL ){ return ; } if (root->left == NULL && root->right == NULL ){ res.push_back(root->val); } findLeaves(root->left, res); findLeaves(root->right, res); return ; } vector < int > boundaryOfBinaryTree(TreeNode * root) { // write your code here //这种题就要拼思路了,有思路很简单。没思路现象,容易走错路。 //1, 找leaves。 //2, 找左边界。 //3, 找右边界。 vector < ...