
DFS
desyang66
代码改变世界
展开
-
PAT Highest Price in Supply Chain
Highest Price in Supply Chain原创 2022-07-26 15:29:20 · 104 阅读 · 0 评论 -
PTA L3-001 凑零钱
题目链接 本题可通过回溯算法解决 #include "bits/stdc++.h" using namespace std; const int N = 110; int a[N]; vector<int> res; bool dfs(int sum, int target) { if(sum == target) { return true; } for(int i = 1; i < N; i++) { if(a[i]原创 2022-05-22 11:37:06 · 157 阅读 · 0 评论 -
二叉树的最近公共祖先问题
二叉树的最近公共祖先问题 问题描述: 给你一棵二叉树,给你两个节点值,要你求出他们的最近公共祖先节点问题。 解题思路: 问题会有两种情况,其中一个节点是另一个节点的祖先节点次数只需要返回该节点就行或祖先节点的左子树找到了一个值右子树找到另外一个值时返回当前节点就行。 参考链接 #include "bits/stdc++.h" using namespace std; struct node{ int val; node* left; node* right; }; node* bu原创 2022-05-10 23:25:54 · 130 阅读 · 0 评论