problemscpp
A collection of my answers to algorithm problems in c++.
Public 成员函数 | Public 属性 | 所有成员列表
leetcode::concatenated_words::TrieNode类 参考

#include <leetcode.h>

Public 成员函数

 TrieNode (char)
 
bool dfs (TrieNode *, const string &, int, bool) const
 
void insert (const string &str)
 

Public 属性

char ch
 
bool is_end
 
TrieNodenexts [26]
 

详细描述

在文件 leetcode.h79 行定义.

构造及析构函数说明

◆ TrieNode()

TrieNode::TrieNode ( char  ch)
explicit

在文件 leetcode.cpp61 行定义.

61 {
62 this->ch = ch;
63 this->is_end = false;
64 }

引用了 ch , 以及 is_end.

被这些函数引用 insert().

成员函数说明

◆ dfs()

bool TrieNode::dfs ( TrieNode root,
const string &  str,
int  start,
bool  flag 
) const

在文件 leetcode.cpp79 行定义.

79 {
80 if(this->ch == 0) {
81 //根节点
82 const auto *const node = this->nexts[str[start] - 'a'];
83 if(node == nullptr) {
84 return false;
85 }
86 return node->dfs(root, str, start, flag);
87 }
88 //非根节点
89 //到一个单词结束处
90 if(this->is_end) {
91 if(start == str.length() - 1) {
92 return flag;
93 }
94 const auto res = root->dfs(root, str, start + 1, true);
95 if(res) {
96 return true;
97 }
98 }
99 const TrieNode *node = nullptr;
100 if(str[start + 1] - 'a' >= 0) {
101 node = this->nexts[str[start + 1] - 'a'];
102 }
103 return node != nullptr && node->dfs(root, str, start + 1, flag);
104 }
vector< int > root
Definition: acwing408.cpp:349
bool dfs(TrieNode *, const string &, int, bool) const
Definition: leetcode.cpp:79
字典树节点
Definition: templates.h:9

引用了 ch, dfs(), is_end, nexts , 以及 acwing::acwing836_408::root.

被这些函数引用 dfs().

◆ insert()

void TrieNode::insert ( const string &  str)

在文件 leetcode.cpp66 行定义.

66 {
67 auto *node = this->nexts[str[0] - 'a'];
68 if(node == nullptr) {
69 node = new TrieNode(str[0]);
70 this->nexts[str[0] - 'a'] = node;
71 }
72 if(str.length() == 1) {
73 node->is_end = true;
74 return;
75 }
76 return node->insert(str.substr(1));
77 }

引用了 TrieNode(), is_end , 以及 nexts.

类成员变量说明

◆ ch

char leetcode::concatenated_words::TrieNode::ch

在文件 leetcode.h82 行定义.

被这些函数引用 TrieNode() , 以及 dfs().

◆ is_end

bool leetcode::concatenated_words::TrieNode::is_end

在文件 leetcode.h81 行定义.

被这些函数引用 TrieNode(), dfs() , 以及 insert().

◆ nexts

TrieNode* leetcode::concatenated_words::TrieNode::nexts[26]
初始值:
= {
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}

在文件 leetcode.h83 行定义.

被这些函数引用 dfs() , 以及 insert().


该类的文档由以下文件生成: