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

[LeetCode]Generalized Abbreviation

时间:2016-01-03 23:49:20      阅读:308      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!