@@ -0,0 +1,1199 @@
+package leetcode;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.List;%0Aimport java.util.Stack;%0Aimport java.util.stream.Collectors;%0A%0A/**%0A * https://leetcode.com/problems/gray-code/%0A */%0Apublic class Problem89 %7B%0A    public List%3CInteger%3E grayCode(int n) %7B%0A        // using this algorithm%0A        // https://en.wikipedia.org/wiki/Gray_code#Constructing_an_n-bit_Gray_code%0A        if (n == 0) %7B%0A            return Arrays.asList(0);%0A        %7D%0A        List%3CString%3E tmp = new ArrayList%3C%3E();%0A        tmp.add(%220%22);%0A        tmp.add(%221%22);%0A        for (int i = 1; i %3C n; i++) %7B%0A            List%3CString%3E tmp1 = new ArrayList%3C%3E();%0A            for (String binary : tmp) %7B%0A                tmp1.add(%220%22 + binary);%0A            %7D%0A            Stack%3CString%3E tmp2 = new Stack%3C%3E();%0A            for (String binary : tmp) %7B%0A                tmp2.push(binary);%0A            %7D%0A            tmp = new ArrayList%3C%3E();%0A            for (String binary : tmp1) %7B%0A                tmp.add(binary);%0A            %7D%0A            while (!tmp2.isEmpty()) %7B%0A                tmp.add(%221%22 + tmp2.pop());%0A            %7D%0A        %7D%0A        return tmp.stream().map(e -%3E Integer.parseInt(e, 2)).collect(Collectors.toList());%0A    %7D%0A%7D%0A

Solve problem 89