89. Gray Code 发表于 2022-04-13 12345678910111213141516class Solution { public List<Integer> grayCode(int n) { List<Integer> list = new ArrayList<>((int) Math.pow(2, n)); list.add(0); int powVal = 1; for (int i = 0; i < n; i++) { // 注意此处需要镜像,所以倒序 for (int j = list.size() - 1; j >= 0; j--) { list.add(powVal + list.get(j)); } powVal <<= 1; } return list; }} Reference89. Gray Code