首页 > 其他 > 详细

[LeetCode]Generalized Abbreviation

时间:2016-01-03 23:47:14      阅读:194      评论:0      收藏:0      [点我收藏+]

感觉我的方法逻辑不够清晰

public class Solution {
    private List<String> result;
    public List<String> generateAbbreviations(String word) {
        result = new ArrayList<String>();
        helper(word, -2, 0);
        result.add(word);
        return result;
    }
    public void helper(String word, int index, int l) {
        int length = word.length();
        for (int i = index + 2 + l; i < length; i++) {
            for (int j = 1; j + i <= length; j++) {
                String str = word.substring(0, i) + String.valueOf(j) + word.substring(i + j);
                result.add(str);
                helper(str, i, String.valueOf(j).length() - 1);
            }
        }
    }
}

 

[LeetCode]Generalized Abbreviation

原文:http://www.cnblogs.com/vision-love-programming/p/5097452.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!