Skip to content

Commit 125b71e

Browse files
[LEET-0000] add problem descriptions
1 parent 9681ab3 commit 125b71e

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

leetcode-algorithms/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
|220|[Contains Duplicate III](https://leetcode.com/problems/contains-duplicate-iii/)|[Solution](../../master/leetcode-algorithms/src/main/java/com/stevesun/solutions/ContainsDuplicateIII.java)| O(nlogn)|O(n) | Medium| TreeSet
130130
|219|[Contains Duplicate II](https://leetcode.com/problems/contains-duplicate-ii/)|[Solution](../../master/leetcode-algorithms/src/main/java/com/stevesun/solutions/ContainsDuplicateII.java)| O(n)|O(n) | Easy| HashMap
131131
|217|[Contains Duplicate](https://leetcode.com/problems/contains-duplicate/)|[Solution](../../master/leetcode-algorithms/src/main/java/com/stevesun/solutions/ContainsDuplicate.java)| O(n)|O(n) | Easy| HashSet
132+
|212|[Word Search II](https://leetcode.com/problems/word-search-ii/)|[Solution](../../master/leetcode-algorithms/src/main/java/com/stevesun/solutions/WordSearchII.java)| O(m*n*l)|O(l) | Hard | Trie
132133
|209|[Minimum Size Subarray Sum](https://leetcode.com/problems/minimum-size-subarray-sum/)|[Solution](../../master/leetcode-algorithms/src/main/java/com/stevesun/solutions/MinimumSizeSubarraySum.java)| O(n)|O(1) | Medium|
133134
|208|[Implement Trie](https://leetcode.com/problems/implement-trie-prefix-tree/)|[Solution](../../master/leetcode-algorithms/src/main/java/com/stevesun/solutions/ImplementTrie.java)| O(n)|O(1) | Medium|
134135
|206|[Reverse Linked List](https://leetcode.com/problems/reverse-linked-list/)|[Solution](../../master/leetcode-algorithms/src/main/java/com/stevesun/solutions/ReverseLinkedList.java)| O(n)|O(1) | Easy

leetcode-algorithms/src/main/java/com/stevesun/solutions/WordSearch.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
package com.stevesun.solutions;
22

3+
/**Given a 2D board and a word, find if the word exists in the grid.
4+
5+
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.
6+
7+
For example,
8+
Given board =
9+
10+
[
11+
['A','B','C','E'],
12+
['S','F','C','S'],
13+
['A','D','E','E']
14+
]
15+
word = "ABCCED", -> returns true,
16+
word = "SEE", -> returns true,
17+
word = "ABCB", -> returns false.*/
318
public class WordSearch {
419
//I made it this time, completely by myself! Cheers! This let me completely understand backtracking!
520
public boolean exist(char[][] board, String word) {

leetcode-algorithms/src/main/java/com/stevesun/solutions/WordSearchII.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
package com.stevesun.solutions;
22

33
import java.util.*;
4+
/**Given a 2D board and a list of words from the dictionary, find all words in the board.
45
6+
Each word must 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 in a word.
7+
8+
For example,
9+
Given words = ["oath","pea","eat","rain"] and board =
10+
11+
[
12+
['o','a','a','n'],
13+
['e','t','a','e'],
14+
['i','h','k','r'],
15+
['i','f','l','v']
16+
]
17+
Return ["eat","oath"].
18+
Note:
19+
You may assume that all inputs are consist of lowercase letters a-z.
20+
21+
You would need to optimize your backtracking to pass the larger test. Could you stop backtracking earlier?
22+
23+
If the current candidate does not exist in all words' prefix, you could stop backtracking immediately. What kind of data structure could answer such query efficiently? Does a hash table work? Why or why not? How about a Trie? If you would like to learn how to implement a basic trie, please work on this problem: Implement Trie (Prefix Tree) first.*/
524
public class WordSearchII {
625

726
public List<String> findWords(char[][] board, String[] words) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy