problemscpp
A collection of my answers to algorithm problems in c++.
载入中...
搜索中...
未找到
leetcode::word_break::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static void search (const TrieNode *tn, const string &s, int i, vector< bool > &end)
 
static bool wordBreak (const string &s, vector< string > &wordDict)
 

详细描述

在文件 leetcode.h2482 行定义.

成员函数说明

◆ search()

void leetcode::word_break::Solution::search ( const TrieNode * tn,
const string & s,
int i,
vector< bool > & end )
static

在文件 leetcode.cpp6701 行定义.

6701 {
6702 const TrieNode *node = tn;
6703 for(; i < s.length(); i++) {
6704 node = node->nexts[s[i] - 'a'];
6705 if(node == nullptr) {
6706 return;
6707 }
6708 if(node->end_of_word) {
6709 end[i] = true;
6710 }
6711 }
6712 }
array< TrieNode *, 26 > nexts

引用了 TrieNode::end_of_word , 以及 TrieNode::nexts.

被这些函数引用 wordBreak().

◆ wordBreak()

bool leetcode::word_break::Solution::wordBreak ( const string & s,
vector< string > & wordDict )
static

在文件 leetcode.cpp6683 行定义.

6683 {
6684 vector end(s.length(), false);
6685 TrieNode tn(0);
6686 for(const auto &word: wordDict) {
6687 tn.insert(word);
6688 }
6689 search(&tn, s, 0, end);
6690 for(int i = 1; i < s.length(); i++) {
6691 if(end[i - 1]) {
6692 search(&tn, s, i, end);
6693 if(end.back()) {
6694 return true;
6695 }
6696 }
6697 }
6698 return end.back();
6699 }
static void search(const TrieNode *tn, const string &s, int i, vector< bool > &end)

引用了 TrieNode::insert() , 以及 search().

被这些函数引用 leetcode::word_break::TEST(), leetcode::word_break::TEST() , 以及 leetcode::word_break::TEST().


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