首页 > 其他 > 详细

Gray Code

时间:2015-05-22 07:02:18      阅读:204      评论:0      收藏:0      [点我收藏+]
public class Solution {
    public ArrayList<Integer> grayCode(int n) {
        if(n==0){
            ArrayList<Integer> res = new ArrayList<Integer>();
            res.add(0);
            return res;
        }
        ArrayList<Integer> res =  grayCode(n-1);
        int tmp = 1<< (n-1);
        int size = res.size(); // 注意这个size必须要计算,不能直接用n
        for(int i=size-1;i>=0;i--){
            res.add(res.get(i)+tmp);
        }
        return res;
    }
}

 

Gray Code

原文:http://www.cnblogs.com/jiajiaxingxing/p/4521299.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!