Class Tree

java.lang.Object
g0201_0300.s0212_word_search_ii.Tree

public class Tree extends java.lang.Object
212 - Word Search II.

Hard

Given an m x n board of characters and a list of strings words, return all words on the board.

Each word must be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once in a word.

Example 1:

Input: board = [[“o”,“a”,“a”,“n”],[“e”,“t”,“a”,“e”],[“i”,“h”,“k”,“r”],[“i”,“f”,“l”,“v”]], words = [“oath”,“pea”,“eat”,“rain”]

Output: [“eat”,“oath”]

Example 2:

Input: board = [[“a”,“b”],[“c”,“d”]], words = [“abcb”]

Output: []

Constraints:

  • m == board.length
  • n == board[i].length
  • 1 <= m, n <= 12
  • board[i][j] is a lowercase English letter.
  • 1 <= words.length <= 3 * 104
  • 1 <= words[i].length <= 10
  • words[i] consists of lowercase English letters.
  • All the strings of words are unique.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    java.lang.String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    addWord(Tree root, java.lang.String word)
     
    static void
    deleteWord(Tree root, java.lang.String word)
     
    getChild(char c)
     
    int
    len()
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • end

      public java.lang.String end
  • Constructor Details

    • Tree

      public Tree()
  • Method Details

    • getChild

      public Tree getChild(char c)
    • len

      public int len()
    • addWord

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

      public static void deleteWord(Tree root, java.lang.String word)