[Leetcode] 527. Word Abbreviation 解题报告

博客介绍了LeetCode 527题目的解法,涉及字符串处理和排序。首先对单词按长度和字典序排序,然后计算相邻单词的公共前缀,确定缩写的最小可能长度。如果缩写后长度减少,则采用缩写,否则保留原词。最后按原顺序返回结果。算法复杂度为O(nlogn),空间复杂度为O(n)。
摘要由CSDN通过智能技术生成

题目

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&#
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值