Class Tree

java.lang.Object
g0201_0300.s0212_word_search_ii.Tree

public class Tree extends Object
212 - Word Search II.<p>Hard</p> <p>Given an <code>m x n</code> <code>board</code> of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The same letter cell may not be used more than once in a word.</p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2020/11/07/search1.jpg" alt="" /></p> <p><strong>Input:</strong> board = [[&ldquo;o&rdquo;,&ldquo;a&rdquo;,&ldquo;a&rdquo;,&ldquo;n&rdquo;],[&ldquo;e&rdquo;,&ldquo;t&rdquo;,&ldquo;a&rdquo;,&ldquo;e&rdquo;],[&ldquo;i&rdquo;,&ldquo;h&rdquo;,&ldquo;k&rdquo;,&ldquo;r&rdquo;],[&ldquo;i&rdquo;,&ldquo;f&rdquo;,&ldquo;l&rdquo;,&ldquo;v&rdquo;]], words = [&ldquo;oath&rdquo;,&ldquo;pea&rdquo;,&ldquo;eat&rdquo;,&ldquo;rain&rdquo;]</p> <p><strong>Output:</strong> [&ldquo;eat&rdquo;,&ldquo;oath&rdquo;]</p> <p><strong>Example 2:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2020/11/07/search2.jpg" alt="" /></p> <p><strong>Input:</strong> board = [[&ldquo;a&rdquo;,&ldquo;b&rdquo;],[&ldquo;c&rdquo;,&ldquo;d&rdquo;]], words = [&ldquo;abcb&rdquo;]</p> <p><strong>Output:</strong> []</p> <p><strong>Constraints:</strong></p> <ul> <li><code>m == board.length</code></li> <li><code>n == board[i].length</code></li> <li><code>1 <= m, n <= 12</code></li> <li><code>board[i][j]</code> is a lowercase English letter.</li> <li><code>1 <= words.length <= 3 * 10<sup>4</sup></code></li> <li><code>1 <= words[i].length <= 10</code></li> <li><code>words[i]</code> consists of lowercase English letters.</li> <li>All the strings of <code>words</code> are unique.</li> </ul>
  • Field Details

  • Constructor Details

    • Tree

      public Tree()
  • Method Details

    • getChild

      public Tree getChild(char c)
    • len

      public int len()
    • addWord

      public static void addWord(Tree root, String word)
    • deleteWord

      public static void deleteWord(Tree root, String word)