Generalized Abbreviation
Posted keepshuatishuati
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Generalized Abbreviation相关的知识,希望对你有一定的参考价值。
1 public class Solution { 2 public List<String> generateAbbreviations(String word) { 3 List<String> result = new ArrayList<>(); 4 5 getAbb(word, 0, 0, "", result); 6 return result; 7 } 8 9 private void getAbb(String word, int index, int count, String str, List<String> result) { 10 if (index == word.length()) { 11 if (count > 0) { 12 str += count; 13 } 14 result.add(str); 15 return; 16 } 17 18 getAbb(word, index + 1, count + 1, str, result); 19 getAbb(word, index + 1, 0, str + (count > 0 ? count : "") + word.charAt(index), result); 20 } 21 }
1. Do not need to check boundary case since the helper function can add "" into result.
2. Do not forget to add that character if not counting into abb.
以上是关于Generalized Abbreviation的主要内容,如果未能解决你的问题,请参考以下文章