思路:数字小于15,果断的进行dfs搜索,简单暴力
void dfs(vector<vector<int> >& graph, vector<int> temp, int start, int end, vector<vector<int> > &res) {
//找到target进行结果push
if (start == end) {
res.push_back(temp);
return;
}
for (int i = 0; i < graph[start].size(); i++) {
temp.push_back(graph[start][i]);
dfs(graph, temp, graph[start][i], end, res);
temp.erase(temp.end() - 1);
}
}
vector<vector<int>> allPathsSourceTarget(vector<vector<int>>& graph) {
vector<vector<int> > res;
vector<int> temp;
//开始位置
temp.push_back(0);
dfs(graph, temp, 0, graph.size() - 1, res);
return res;
}