Skip to content

Commit 10a90cd

Browse files
committed
[DFS] Rectify time and space complexity of Word Search
1 parent 9a565a4 commit 10a90cd

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

DFS/WordSearch.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Question Link: https://leetcode.com/problems/word-search/
33
* Primary idea: Classic Depth-first Search, go up, down, left, right four directions
44
*
5-
* Time Complexity: O((n^2)!), Space Complexity: O(n^2)
5+
* Time Complexity: O(mn * 4^(k - 1)), m and n stand for width and height of matrix, k is the word size, Space Complexity: O(mn)
66
*
77
*/
88

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@
235235
[Is Graph Bipartite](https://leetcode.com/problems/is-graph-bipartite/)| [Swift](./DFS/IsGraphBipartite.swift)| Medium| O(n)| O(n)|
236236
[Number of Islands](https://leetcode.com/problems/number-of-islands/)| [Swift](./DFS/NumberofIslands.swift)| Medium| O((mn)^2)| O(1)|
237237
[Walls and Gates](https://leetcode.com/problems/walls-and-gates/)| [Swift](./DFS/WallsGates.swift)| Medium| O(n!)| O(2^n)|
238-
[Word Search](https://leetcode.com/problems/word-search/)| [Swift](./DFS/WordSearch.swift)| Medium| O((n^2)!)| O(n^2)|
238+
[Word Search](https://leetcode.com/problems/word-search/)| [Swift](./DFS/WordSearch.swift)| Medium| O((mn * 4 ^ (k - 1))| O(mn)|
239239
[Word Search II](https://leetcode.com/problems/word-search-ii/)| [Swift](./DFS/WordSearchII.swift)| Hard| O(((mn)^2))| O(n^2)|
240240
[Add and Search Word - Data structure design](https://leetcode.com/problems/add-and-search-word-data-structure-design/)| [Swift](./DFS/WordDictionary.swift)| Medium| O(n)| O(n)|
241241
[N-Queens](https://leetcode.com/problems/n-queens/)| [Swift](./DFS/NQueens.swift)| Hard| O((n!))| O(n^2)|

0 commit comments

Comments
 (0)