89. Gray Code

来源:互联网 发布:php 读取图片并输出 编辑:程序博客网 时间:2024/06/08 04:37

格雷码

For example, given n = 2, return [0,1,3,2].

代码

public class Solution {    public List<Integer> grayCode(int n) {        List<Integer> result = new LinkedList<>();        for (int i = 0; i < 1<<n; i++) result.add(i ^ i>>1);        return result;    }}
0 0