国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

【LeetCode】461. Hamming Distance【E】【90】

2019-11-08 19:25:34
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

The Hamming distance between two integers is the number of positions at which the corresponding bits are different.

Given two integers x and y, calculate the Hamming distance.

Note:0 ≤ xy < 231.

Example:

Input: x = 1, y = 4Output: 2Explanation:1   (0 0 0 1)4   (0 1 0 0)       ↑   ↑The above arrows point to positions where the corresponding bits are different.

Subscribe to see which companies asked this question.思路很簡(jiǎn)單,先轉(zhuǎn)成二進(jìn)制,然后計(jì)算異或,然后看一共有多少個(gè)1 就是結(jié)果了 
class Solution(object):    def hammingDistance(self, x, y):        return ((bin(x ^ y)[2:])).count('1')        """        :type x: int        :type y: int        :rtype: int        """
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 天等县| 沁阳市| 翼城县| 怀柔区| 横山县| 青铜峡市| 合江县| 文安县| 金塔县| 五华县| 朝阳区| 日照市| 循化| 广饶县| 连云港市| 通城县| 溧水县| 澄城县| 金沙县| 化隆| 山西省| 小金县| 安图县| 隆化县| 醴陵市| 鄄城县| 麻栗坡县| 灵宝市| 孟州市| 广宗县| 山阴县| 鄂托克旗| 云林县| 鄂州市| 罗甸县| 华坪县| 许昌县| 嘉鱼县| 唐河县| 华容县| 渭源县|