mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-02-11 06:26:05 +08:00
Update dynamic_programming/word_break.cpp
Co-authored-by: David Leal <halfpacho@gmail.com>
This commit is contained in:
@@ -148,6 +148,24 @@ bool wordBreak(const std::string &s, const std::vector<std::string> &wordDict) {
|
|||||||
} // namespace word_break
|
} // namespace word_break
|
||||||
} // namespace dynamic_programming
|
} // namespace dynamic_programming
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Test implementations
|
||||||
|
* @returns void
|
||||||
|
*/
|
||||||
|
static void test() {
|
||||||
|
// the complete string
|
||||||
|
const std::string s = "applepenapple";
|
||||||
|
// the dictionary to be used
|
||||||
|
const std::vector<std::string> wordDict = {"apple", "pen"};
|
||||||
|
|
||||||
|
assert(dynamic_programming::word_break::wordBreak(s, wordDict));
|
||||||
|
|
||||||
|
// should return true, as applepenapple can be segmented as apple + pen +
|
||||||
|
// apple
|
||||||
|
std::cout << dynamic_programming::word_break::wordBreak(s, wordDict)
|
||||||
|
<< std::endl;
|
||||||
|
std::cout << "Test implementation passed!\n";
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @brief Main function
|
* @brief Main function
|
||||||
* @returns 0 on exit
|
* @returns 0 on exit
|
||||||
|
|||||||
Reference in New Issue
Block a user