package leetcode;

import java.util.List;

/**
 * https://leetcode.com/problems/brace-expansion-ii/
 */
public class Problem1096 {
    public List<String> braceExpansionII(String expression) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem1096 prob = new Problem1096();
        System.out.println(prob.braceExpansionII("{a{b,c}d{e,f}}")); // ["abde",abdf","acde","acdf"]
//        System.out.println(prob.braceExpansionII("a{b,c}")); // ["ab","ac"]
//        System.out.println(prob.braceExpansionII("{c{d,e}f}")); // ["cdf","cef"]
//        System.out.println(prob.braceExpansionII("{a,b}{c{d,e}}")); // ["acd","ace","bcd","bce"]
//        System.out.println(prob.braceExpansionII("{{a,z},a{b,c},{ab,z}}")); // ["a","ab","ac","z"]
//        System.out.println(prob.braceExpansionII("{a,b,c}")); // ["a","b","c"]
//        System.out.println(prob.braceExpansionII("{{a,b},{b,c}}")); // ["a","b","c"]
//        System.out.println(prob.braceExpansionII("{a,b}{c,d}")); // ["ac","ad","bc","bd"]
//        System.out.println(prob.braceExpansionII("{a{b,c}}{{d,e}f{g,h}}")); // ["abdfg", "abdfh", "abefg", "abefh", "acdfg", "acdfh", "acefg", "acefh"]
    }
}

@@ -33,13 +33,114 @@
 til.
+Array
 List;
+%0Aimport java.util.Arrays;%0Aimport java.util.List;%0Aimport java.util.Set;%0Aimport java.util.TreeSet;
 %0A%0A/*
@@ -299,35 +299,1423 @@
     
-// TODO%0A        return null
+List%3CList%3CList%3CString%3E%3E%3E groups = new ArrayList%3C%3E();%0A        groups.add(new ArrayList%3C%3E());%0A        int level = 0;%0A        int start = -1;%0A        for (int i = 0; i %3C expression.length(); i++) %7B%0A            char c = expression.charAt(i);%0A            if (c == '%7B') %7B%0A                if (level == 0) %7B%0A                    start = i + 1;%0A                %7D%0A                level++;%0A            %7D else if (c == '%7D') %7B%0A                level--;%0A                if (level == 0) %7B%0A                    groups.get(groups.size() - 1).add(%0A                        braceExpansionII(expression.substring(start, i)));%0A                %7D%0A            %7D else if (c == ',' && level == 0) %7B%0A                groups.add(new ArrayList%3C%3E());%0A            %7D else if (level == 0) %7B%0A                groups.get(groups.size() - 1).add(Arrays.asList(String.valueOf(c)));%0A            %7D%0A        %7D%0A%0A        Set%3CString%3E set = new TreeSet%3C%3E();%0A        for (List%3CList%3CString%3E%3E group : groups) %7B%0A            List%3CString%3E pre = new ArrayList%3C%3E();%0A            pre.add(%22%22);%0A            for (List%3CString%3E g : group) %7B%0A                List%3CString%3E tmp = new ArrayList%3C%3E();%0A                for (String pStr : pre) %7B%0A                    for (String gStr : g) %7B%0A                        tmp.add(pStr + gStr);%0A                    %7D%0A                %7D%0A                pre = tmp;%0A            %7D%0A            set.addAll(pre);%0A        %7D%0A        return new ArrayList%3C%3E(set)
 ;%0A  

Update problem 1096