码迷,mamicode.com
首页 > 其他好文 > 详细

[LeetCode] Concatenated Words 连接单词

时间:2017-01-06 01:18:26      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:note   muse   array   tca   without   write   单词   ase   not   

 

Given a list of words (without duplicates), please write a program that returns all concatenated words in the given list of words.

A concatenated word is defined as a string that is comprised entirely of at least two shorter words in the given array.

Example:

Input: ["cat","cats","catsdogcats","dog","dogcatsdog","hippopotamuses","rat","ratcatdogcat"]

Output: ["catsdogcats","dogcatsdog","ratcatdogcat"]

Explanation: "catsdogcats" can be concatenated by "cats", "dog" and "cats"; 
"dogcatsdog" can be concatenated by "dog", "cats" and "dog";
"ratcatdogcat" can be concatenated by "rat", "cat", "dog" and "cat".

 

Note:

  1. The number of elements of the given array will not exceed 10,000
  2. The length sum of elements in the given array will not exceed 600,000.
  3. All the input string will only include lower case letters.
  4. The returned elements order does not matter.

 

s

 

[LeetCode] Concatenated Words 连接单词

标签:note   muse   array   tca   without   write   单词   ase   not   

原文地址:http://www.cnblogs.com/grandyang/p/6254527.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!