Skip to content

Commit 168ff46

Browse files
committed
格雷编码
1 parent a9009c2 commit 168ff46

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

gray_code.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# -*- coding: utf-8 -*-
2+
3+
class Solution:
4+
# @param {int} n a number
5+
# @return {int[]} Gray code
6+
def grayCode(self, n):
7+
# Write your code here
8+
ret = []
9+
for i in xrange(1 << n):
10+
ret.append((i >> 1) ^ i)
11+
return ret

0 commit comments

Comments
 (0)