Java short solution


  • 0
    C
    public class Solution {
        int l;
        public List<String> generateAbbreviations(String word) {
            l=Math.max(l,word.length());
            List<String> res=new ArrayList<String>();
            int len=word.length();
            res.add(word);
            for(int i=1;i<=len;i++){
                for(int j=0;j+i<=len;j++){
                    if(j==0&&l!=len) continue;
                    List<String> ans=generateAbbreviations(word.substring(j+i,len));
                    for(String s:ans){
                        res.add(word.substring(0,j)+i+s);
                    }
                }
            }
            return res;
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.