LeetCode 1971. Find if Path Exists in Graph(图的遍历)
文章目錄
- 1. 題目
- 2. 解題
1. 題目
There is a bi-directional graph with n vertices, where each vertex is labeled from 0 to n - 1 (inclusive).
The edges in the graph are represented as a 2D integer array edges, where each edges[i] = [ui, vi] denotes a bi-directional edge between vertex ui and vertex vi.
Every vertex pair is connected by at most one edge, and no vertex has an edge to itself.
You want to determine if there is a valid path that exists from vertex start to vertex end.
Given edges and the integers n, start, and end, return true if there is a valid path from start to end, or false otherwise.
Example 1:
Example 2:
來源:力扣(LeetCode)
鏈接:https://leetcode-cn.com/problems/find-if-path-exists-in-graph
著作權歸領扣網絡所有。商業轉載請聯系官方授權,非商業轉載請注明出處。
2. 解題
- 圖的遍歷,BFS、DFS都可以
312 ms 66.1 MB Python3
我的CSDN博客地址 https://michael.blog.csdn.net/
長按或掃碼關注我的公眾號(Michael阿明),一起加油、一起學習進步!
總結
以上是生活随笔為你收集整理的LeetCode 1971. Find if Path Exists in Graph(图的遍历)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LeetCode 1834. 单线程 C
- 下一篇: Visual Studio Code C