牛客中的代码都是封装好的库,然后我们就可以直接进行调用,像在牛客中使用容器,以及二叉树时,我们直接进行调用就行了,而不需要进行声明以及定义
但是如果我们在复制牛客中的代码到其他的平台进行运行的时候,我们就需要考虑一下这个转化的问题。
像vector,我们在使用的时候就需要进行声明。像二叉树,我们在使用的时候,需要进行定义。
下面我举一个例子进行说明
#include <vector> //#include<stdlib.h> #include<iostream> using namespace std; struct TreeNode { int val; TreeNode* left; TreeNode* right; }; class Solution { public: vector<vector<int> > buffer; vector<int> tmp; vector<vector<int> > FindPath(TreeNode* root,int expectNumber) { if(root==NULL) return buffer; tmp.push_back(root->val); if((expectNumber-root->val)==0 && root->left==NULL && root->right==NULL) { buffer.push_back(tmp); } FindPath(root->left,expectNumber-root->val); FindPath(root->right,expectNumber-root->val); if(tmp.size()!=0) tmp.pop_back(); return buffer; } }; int main() { cout<<"现在是对了吗?"<<endl; cout<<"我真的是非常的开心了"<<endl; return 0; }