You are given a string s and a dictionary of words dictionary.
Your task is to determine if the string s can be segmented into a space-separated sequence of one or more words, where each word in the sequence is found in your dictionary.
You may assume that:
dictionary may be reused multiple times in the segmentation.Return true if s can be segmented, false otherwise.
s = "helloworld"
dictionary = ["hello", "world"]
True
"helloworld" can be segmented as "hello world" using the words from the dictionary.
s = "penpineappleapplepen"
dictionary = ["apple", "pen", "pineapple"]
True
"penpineappleapplepen" can be segmented as "pen pineapple apple pen".
s = "helloearth"
dictionary = ["hello", "art", "ear", "heart"]
False
"helloearth" cannot be fully segmented using the provided dictionary words.
s = "helloworld"
dictionary = ["hello", "world"]
True