代码随想录算法训练营第56天 | 42. 接雨水 、84.柱状图中最大的矩形

图论理论基础

大家可以在看图论理论基础的时候,很多内容 看不懂,例如也不知道 看完之后 还是不知道 邻接矩阵,邻接表怎么用, 别着急。
理论基础大家先对各个概念有个印象就好,后面在刷题的过程中,每个知识点都会得到巩固。
https://www.programmercarl.com/kamacoder/图论理论基础.html

深搜理论基础
了解一下深搜的原理和过程
https://www.programmercarl.com/kamacoder/图论深搜理论基础.html

  1. 所有可达路径
    https://www.programmercarl.com/kamacoder/0098.所有可达路径.html
/**
 * @param {number[][]} graph
 * @return {number[][]}
 */
var allPathsSourceTarget = function(graph) {
    const path = [];
    const len = graph.length - 1;
    const res = [];
    const dfs = (graph, x) => {
        if (x === len) {
            res.push([...path]);
            return;
        }

        for (let i=0; i< graph[x].length; i++) {
            path.push(graph[x][i]);
            dfs(graph, graph[x][i]);
            path.pop();
        }
    }
    path.push(0);
    dfs(graph, 0);
    return res;
};

广搜理论基础
https://www.programmercarl.com/kamacoder/图论广搜理论基础.html


posted @ 2024-07-07 23:19  YuanYF6  阅读(1)  评论(0编辑  收藏  举报