标签:style class blog code java http
class Solution { public: vector<int> grayCode(int n) { vector<int> res; res.push_back(0); long pow2 = 1; for (int i=1; i <= n; i++) { int old_len = res.size(); for (int i=0; i<old_len; i++) { res.push_back(pow2 + res[old_len - i - 1]); } pow2<<=1; } return res; } };
再水一发, 不过n==0时,觉得应该返回一个空的vector
LeetCode GrayCode,布布扣,bubuko.com
标签:style class blog code java http
原文地址:http://www.cnblogs.com/lailailai/p/3783919.html