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

[LeetCode] Word Abbreviation 单词缩写

时间:2017-05-06 23:04:03      阅读:336      评论:0      收藏:0      [点我收藏+]

标签:sed   ima   first   lower   intern   example   minimal   note   pre   

 

Given an array of n distinct non-empty strings, you need to generate minimal possible abbreviations for every word following rules below.

  1. Begin with the first character and then the number of characters abbreviated, which followed by the last character.
  2. If there are any conflict, that is more than one words share the same abbreviation, a longer prefix is used instead of only the first character until making the map from word to abbreviation become unique. In other words, a final abbreviation cannot map to more than one original words.
  3. If the abbreviation doesn‘t make the word shorter, then keep it as original.

Example:

Input: ["like", "god", "internal", "me", "internet", "interval", "intension", "face", "intrusion"]
Output: ["l2e","god","internal","me","i6t","interval","inte4n","f2e","intr4n"]

 

Note:

  1. Both n and the length of each word will not exceed 400.
  2. The length of each word is greater than 1.
  3. The words consist of lowercase English letters only.
  4. The return answers should be in the same order as the original array.

 

s

 

[LeetCode] Word Abbreviation 单词缩写

标签:sed   ima   first   lower   intern   example   minimal   note   pre   

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

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