Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- fun findAllConcatenatedWordsInADict(words: Array<String>): List<String> {
- val result: MutableList<String> = LinkedList()
- val set = words.toSet()
- words.forEach { word ->
- var wordsCnt = 0
- var concatWord = ""
- var part = ""
- word.forEach { ch ->
- part += ch
- if(set.contains(part)) {
- concatWord += part
- wordsCnt++
- part = ""
- }
- }
- if(part.isEmpty() && wordsCnt > 1) result.add(concatWord)
- }
- return result
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement