Skip to content

Commit c5d4b16

Browse files
authored
Create 089.Gray-Code.cpp
1 parent 99cd04f commit c5d4b16

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public:
3+
vector<int> grayCode(int n)
4+
{
5+
vector<int>rets;
6+
rets.push_back(0);
7+
for (int i=0; i<n; i++)
8+
{
9+
int len = rets.size();
10+
for (int j=len-1; j>=0; j--)
11+
{
12+
rets.push_back(rets[j]| (1<<i));
13+
}
14+
}
15+
return rets;
16+
}
17+
};

0 commit comments

Comments
 (0)