LeetCode 刷题记录: 79. Word Search [Python]

原题

https://leetcode.com/problems/word-search/

Given a 2D board and a word, find if the word exists in the grid.

The word can be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once.

思路

DFS。四个方向搜寻即可。

LeetCode 刷题记录: 46. Permutations [Python]

原题

https://leetcode.com/problems/permutations/

Given a collection of distinct integers, return all possible permutations.

思路

Backtrack。当temp长度等于所有数字时,添加进结果。否则遍历数字,每个数字添加进temp中,进行下一次迭代。当temp中存在相同数字时跳过。

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×