Python | Leetcode Python题解之第461题汉明距离

题目:

题解:

python 复制代码
class Solution:
    def hammingDistance(self, x, y):
        ret = 0
        bx, by = bin(x)[2:].zfill(32), bin(y)[2:].zfill(32)
        for i in range(32):
            if bx[i] != by[i]:
                ret += 1
        return ret
相关推荐
外收内放13 小时前
Python基础语法练习题(31-33)
开发语言·python
2601_9628857213 小时前
如何用 Python 画 K 线图(蜡烛图)?(mplfinance + 均线 + 成交量)
开发语言·python
Y38153266214 小时前
行业动态周报:用新闻 API 追踪一个赛道的声音变化
python·搜索引擎
零域码客14 小时前
零基础Python爬虫入门:从HTTP协议到 requests + BeautifulSoup 实战
爬虫·python·http
“AI国潮设计-小江”14 小时前
【SDXL实战】用AI生成“财神爷蛋糕×英歌舞人物”潮汕国潮甜品IP,附Prompt与批量生成思路
开发语言·人工智能·python·aigc
DD云验证14 小时前
DD云验证,免费网络验证系统
服务器·python·易语言·网络验证·卡密验证
Navigator_Z14 小时前
LeetCode //C - 1269. Number of Ways to Stay in the Same Place After Some Steps
c语言·算法·leetcode
茶栀(*´I`*)15 小时前
【Python数据分析利器】Pandas从入门到实战:核心数据结构DataFrame与Series全解析
python·数据分析·pandas
码云数智-大飞15 小时前
新手写 Python 代码,如何规范命名、减少 Bug
开发语言·python·php
天天被压力15 小时前
【别再到处找免费股票数据API了:官方204个接口,32篇一次讲透 #06】Python实时行情总报错?五档盘口+逐笔一次跑通
java·人工智能·python