Leecode 89.格雷編碼

題目

在這裏插入圖片描述

題解

代碼實現:

class Solution(object):
    def grayCode(self, n):
            """        
            :type n: int        
            :rtype: List[int]        
            """        
            res = []        
            for i in range(2 ** n):       
                 res.append(i ^ (i // 2))        
            return res 

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章