本文整理汇总了C++中Solution::FindPath方法的典型用法代码示例。如果您正苦于以下问题:C++ Solution::FindPath方法的具体用法?C++ Solution::FindPath怎么用?C++ Solution::FindPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Solution
的用法示例。
在下文中一共展示了Solution::FindPath方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
TreeNode* tree = (TreeNode*)malloc(sizeof(TreeNode));
TreeNode* p = tree;
tree->val = 0;
for(int i = 1; i < 10; i+=2){
TreeNode* left = (TreeNode*)malloc(sizeof(TreeNode));
TreeNode* right = (TreeNode*)malloc(sizeof(TreeNode));
left->val = i;
right->val = i+1;
p->left = left;
p->right = right;
if((i-1)%4 == 0){
p = left;
}else{
p = right;
}
}
Solution s = Solution();
vector<vector<int> >result = s.FindPath(tree,17);
cout<<"the path that sum is 17 is:"<<endl;
for(int i = 0; i < result.size(); i++){
for(int j = 0; j < result[0].size(); j++){
cout<<result[i][j]<<",";
}
cout<<endl;
}
}
示例2: main
int main()
{
TreeNode* root = new TreeNode(1);
root->left = new TreeNode(1);
root->right = new TreeNode(1);
root->left->left = new TreeNode(1);
root->left->right = new TreeNode(1);
root->right->left = new TreeNode(2);
root->right->right = new TreeNode(1);
Solution a;
//auto results = a.FindPath(root, 2);
auto results = a.FindPath(root, 3);
for (auto res : results)
{
for (auto data : res)
cout << data << " ";
cout << endl;
}
DestoryTree(root);
system("pause");
return 0;
}
示例3: __tmain
int __tmain( )
{
// 0 1 2 3 4
// {10,5,12,4,7},22
TreeNode tree[5];
tree[0].val = 10;
tree[0].left = &tree[1];
tree[0].right = &tree[2];
tree[1].val = 5;
tree[1].left = &tree[3];
tree[1].right = &tree[4];
tree[2].val = 12;
tree[2].left = NULL;
tree[2].right = NULL;
tree[3].val = 4;
tree[3].left = NULL;
tree[3].right = NULL;
tree[4].val = 7;
tree[4].left = NULL;
tree[4].right = NULL;
Solution solu;
vector< vector<int> > res = solu.FindPath(&tree[0], 22);
cout <<"size = " <<res.size( ) <<endl;
for(int i = 0; i < res.size( ); i++)
{
for(int j = 0; j < res[i].size( ); j++)
{
cout <<res[i][j] <<" ";
}
cout <<endl;
}
return 0;
}