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

首頁 > 學院 > 開發設計 > 正文

Leetcode-Algorithms Hamming Distance(漢明距離)

2019-11-08 02:30:25
字體:
來源:轉載
供稿:網友

從今天開始每天用python做幾道leetcode的題目練手,從easy到hard遞進。

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 ≤ x, y < 231.

Example:

Input: x = 1, y = 4

Output: 2

Explanation: 1 (0 0 0 1) 4 (0 1 0 0) ↑ ↑

The above arrows point to positions where the corresponding bits are different.

兩個integer的漢明距離就是二進制下對應位置不相同的數目。用^運算符后在count 1 的數量即可。

class Solution(object): def hammingDistance(self, x, y): """ :type x: int :type y: int :rtype: int """ return "{0:b}".format(x^y).count("1")
上一篇:Crackme 22

下一篇:位運算

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 东莞市| 盐山县| 麻栗坡县| 金平| 长宁区| 阳城县| 乐山市| 青冈县| 土默特左旗| 金乡县| 星座| SHOW| 博湖县| 洛扎县| 石林| 临清市| 普陀区| 宣武区| 瑞金市| 青铜峡市| 金乡县| 平武县| 涿州市| 邯郸市| 凤城市| 汉川市| 台中市| 庆安县| 白山市| 武夷山市| 广东省| 莱西市| 三门县| 禹州市| 柏乡县| 沂水县| 噶尔县| 凤冈县| 九台市| 永丰县| 宁国市|