/* 自定義代碼塊樣式 */

herrDeng網內搜尋

自訂搜尋

Ads

2026年7月1日 星期三

Beats 100%|C++ UnionFind BFS解Leetcode 2812 Find the Safest Path in a Grid


Beats 100%|C++ unionFind BFS linkedList解Leetcode 2812  Find the Safest Path in a Grid
本影片詳細講解如何結合 UnionFind與 BFS(廣度優先搜尋)來解決 LeetCode 2812. Find the Safest Path in a Grid。透過 BFS 預處理所有格子到最近小偷的距離,再利用 UnionFind 找出具有最大安全性係數的路徑,最終在 C++ 實作中達到 182ms 並擊敗 100% 的紀錄!
--------
In this video, I walk through how to combine UnionFind and BFS to solve LeetCode 2812. Find the Safest Path in a Grid. We use BFS to pre-calculate the distance to the nearest thief for all cells, then leverage UnionFind to find the path with the maximum safeness factor. This implementation achieves 182ms in C++, beating 100% of other submissions!
 #anwendeng 
=====
English timestamps for the video LeetCode 2812. Find the Safest Path in a Grid (C++ UNION-FIND + BFS) BEATS 100%:
00:00 - Introduction & Problem Overview (LeetCode 2812)
00:18 - Initial Submission & Performance Result (182ms, Beats 100%)
00:34 - Problem Analysis: Graph Theory & Grid Definition
02:03 - Defining the Safeness Factor & Manhattan Distance
03:31 - Example 3 Walkthrough: BFS for Distance Calculation
05:16 - Edge Case: Example 1 (Start or End has a Thief)
05:41 - Example 2 Walkthrough: L1 Distance Calculation
06:26 - Solution Strategy: Union-Find & Optimization (LeetCode 1971 Ref.)
07:25 - Complexity Analysis: Binary Search vs. Union-Find Approach
08:25 - Two-Phase Process: Multi-source BFS & Union-Find
09:05 - Performance Optimization: Using Linked Lists for Speed
11:00 - Queue Implementation Optimization using Arrays
11:28 - Code Walkthrough: Global Variables & Union-Find Method
12:23 - Code Walkthrough: Grid Traversal & Distance Calculation
14:24 - Code Walkthrough: Main Loop & Connectivity Check
15:53 - Final Run & Submission Confirmation

沒有留言:

Related Posts Plugin for WordPress, Blogger...

熱門文章