> For the complete documentation index, see [llms.txt](https://cai-sen-se.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cai-sen-se.gitbook.io/leetcode/1-200/89.-ge-lei-bian-ma.md).

# 89. 格雷编码

<https://leetcode-cn.com/problems/gray-code/>

## 解法一：

思路很简单，用异或G(i) = i^ (i/2)

```python
class Solution:
    def grayCode(self, n: int) -> List[int]:
        res = []
        for i in range(2**n):
            res.append(i ^ i//2)
        return res
```
