当前位置: 首页>>代码示例>>C++>>正文


C++ Solution::FindPath方法代码示例

本文整理汇总了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;
    }

}
开发者ID:sharpdeep,项目名称:coding-challenge,代码行数:32,代码来源:solution.cpp

示例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;
}
开发者ID:zymix,项目名称:Offer_Code,代码行数:25,代码来源:Coding_013.cpp

示例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;
}
开发者ID:gatieme,项目名称:CodingInterviews,代码行数:39,代码来源:findpath_sum_static.cpp


注:本文中的Solution::FindPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。