У нас вы можете посмотреть бесплатно Leetcode 79 | Word Search | C++ | Depth First Search | Backtracking | Cpp Interview Problem или скачать в максимальном доступном качестве, видео которое было загружено на ютуб. Для загрузки выберите вариант из формы ниже:
Если кнопки скачивания не
загрузились
НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если возникают проблемы со скачиванием видео, пожалуйста напишите в поддержку по адресу внизу
страницы.
Спасибо за использование сервиса ClipSaver.ru
To solve this problem we use DFS(dept first search) and backtracking. For each cell in the board, we mark it as visited, then check if it’s equal to the first character in the word – in which case we perform DFS on this cell, and finally we backtrack and mark the cell as not visited - if a solution was not found, otherwise we return true, as we have found the word in the board. The time complexity is O(N*M * 3^L) because we can traverse the whole N*M board in the worst case and we can choose to go in 4 directions at each step (to search for neighbors). However, only 3 of the directions are actually new paths we want to explore, as the other one would be the position we came from which will be marked as visited. The space complexity is linear with respect to the board, meaning O(N*M) size. This is used by the 2D vector, visited. It is possible to improve on this solution by marking the visited board cells with a special character like #, instead of using a 2D vector to keep track of the visited state. 0:00 - Problem Statement 1:22 - Drawing & Explanation 8:00 - Coding & Implementation Related article on Medium, with full explanation: / leetcode-79-word-search-c-depth-first-sear... leetcode 79 #cpp #leetcode #dfs #backtrack #codinginterview