import java.util.List;
import java.util.LinkedList;

public class GrayCode {

    public List<Integer> grayCode(int n) {
        List<Integer> ans = null;
        if (n == 0) {
            ans = new LinkedList<>();
            ans.add(0);
            return ans;
        }

        ans = grayCode(n - 1);
        int weight = 1 << (n - 1);
        int size = ans.size();

        for (int i = size - 1; i >= 0; i--) {
            ans.add(weight + ans.get(i));
        }

        return ans;
    }

    public static void main(String[] args) {
        int n = 2;
        System.out.printf("n = %d\n", n);

        GrayCode solution = new GrayCode();
        System.out.printf("%s\n", solution.grayCode(n));
    }
}
@@ -110,24 +110,243 @@
 de(int n) %7B%0A
+        List%3CInteger%3E ans = new LinkedList%3C%3E();%0A%0A        for (int i = 0; i %3C (1 %3C%3C n); i++) %7B%0A            ans.add((i %3E%3E 1) %5E i);%0A        %7D%0A        %0A        return ans;%0A    %7D%0A%0A    public List%3CInteger%3E grayCode1(int n) %7B%0A
         List

add another solution of gray code