Help!! i wanna know why the solution can't be accepeted


  • 0
    L
    /**
    
    • Definition for binary tree

    • struct TreeNode {

    • int val;
      
    • TreeNode *left;
      
    • TreeNode *right;
      
    • TreeNode(int x) : val(x), left(NULL), right(NULL) {}
      
    • };
      */
      // #include<vector>

      class Solution {
      public:
      vector<int> postorderTraversal(TreeNode *root) {
      vector<int> iter;
      if (root != NULL) {
      postorderTraversal(root->left);
      postorderTraversal(root->right);
      iter.push_back(root->val);
      }

       }
      

      };


  • 0
    A

    there are several mistakes in your code.

    1. iter is a local variable which means you will only get the root value.
    2. you didn't return value.

    so you can take iter as a class data member and add 'return iter' in the end of func.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.