棋盘格里面的每个位置都是以该位置为左上角,最大的方形的边长,从下往上,从右往左,那么每个格子就是由右下角的三个决定的。initialize的时候注意initialize最右边一条和最下边一条
208. Implement Trie (Prefix Tree)
注意这个构造的结构:自己创造了node,node是一个class,class里面需要有variabl,function,和constructor。注意写public。这个node class里有一个Node* 的variable。variable的名字是children/next...trie结构需要26的children,所以children后面要有[26]。
node构建好之后,开始构建trie。trie也是一个class。trie本身也有variable和function和constructor。题目需要自己写variable,填constructor和function。trie只需要一个variable:root。所以constructor只需要initialize一个varible:root = new Node(): root本身是一个node,作为node就有自己的constructor。
struct和class的区别:
-
Structures are value types; classes are reference types. A variable of a structure type contains the structure's data, rather than containing a reference to the data as a class type does.
-
Structures use stack allocation; classes use heap allocation.
-
All structure elements are
Public
by default; class variables and constants arePrivate
by default, while other class members arePublic
by default.
211. Design Add and Search Words Data Structure
trie+search
选dfs还是bfs呢?找path,选dfs(一般用recursion)
注意循环node->children[i]和word[i]的i不是一个i