Lintcode.66 Binary Tree forward traversal, lintcode.66 Binary Tree

Source: Internet
Author: User
Tags lintcode

Lintcode.66 Binary Tree forward traversal, lintcode.66 Binary Tree
Forward traversal of Binary Trees 

  • Description
  • Notes
  • Data
  • Evaluation

Returns a binary tree that traverses the node values in the forward order.

Have you ever encountered this question during a real interview? Yes Example

Returns a binary tree.{1,#,2,3},

   1    \     2    /   3

Return[1,2,3].

 

 

/** * 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 Tree     * @return: Preorder in ArrayList which contains node values.     */    vector<int> l;    vector<int> preorderTraversal(TreeNode * root) {        // write your code here        if(root==NULL)            return l;        l.push_back(root->val);        preorderTraversal(root->left);        preorderTraversal(root->right);        return l;    }};

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.