不明觉厉 格雷码

不想看知道一点就行。学点位运算也是好的。

http://www.cnblogs.com/lihaozy/archive/2012/12/31/2840437.html

public class Solution {
public List<Integer> grayCode(int n) {
int l=1<<n; // pow(2,n)
List<Integer> list=new ArrayList<Integer>();
for(int i=0;i<l;i++)
{
int temp=i^i>>1;//get the gray code;
list.add(temp);

}

return list;

}
}

posted @ 2014-07-22 19:42  hansongjiang8  阅读(94)  评论(0编辑  收藏  举报