139. Word Break Medium
1/**
2 * [139] Word Break
3 *
4 * Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary words.
5 * Note that the same word in the dictionary may be reused multiple times in the segmentation.
6 *
7 * Example 1:
8 *
9 * Input: s = "leetcode", wordDict = ["leet","code"]
10 * Output: true
11 * Explanation: Return true because "leetcode" can be segmented as "leet code".
12 *
13 * Example 2:
14 *
15 * Input: s = "applepenapple", wordDict = ["apple","pen"]
16 * Output: true
17 * Explanation: Return true because "applepenapple" can be segmented as "apple pen apple".
18 * Note that you are allowed to reuse a dictionary word.
19 *
20 * Example 3:
21 *
22 * Input: s = "catsandog", wordDict = ["cats","dog","sand","and","cat"]
23 * Output: false
24 *
25 *
26 * Constraints:
27 *
28 * 1 <= s.length <= 300
29 * 1 <= wordDict.length <= 1000
30 * 1 <= wordDict[i].length <= 20
31 * s and wordDict[i] consist of only lowercase English letters.
32 * All the strings of wordDict are unique.
33 *
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/word-break/
38// discuss: https://leetcode.com/problems/word-break/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43 pub fn word_break(s: String, word_dict: Vec<String>) -> bool {
44 false
45 }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn test_139() {
56 }
57}
58
Back
© 2025 bowen.ge All Rights Reserved.