您的位置:首页 > 其它

LeetCode--Gray Code

2014-08-12 00:01 323 查看
格雷码的定义

第二次写的,参考别人。代码写的很简洁

class Solution {
public:
vector<int> grayCode(int n) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
vector<int> res;
res.push_back(0);
int highbit = 0;
while(n--)
{
highbit = res.size();
for(int i= res.size()-1; i >= 0; i--)
res.push_back(highbit|res[i]);
}
return res;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: