国产探花免费观看_亚洲丰满少妇自慰呻吟_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

下一篇:位運算

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 南汇区| 鹤山市| 阿鲁科尔沁旗| 阳曲县| 晋中市| 连州市| 新闻| 化德县| 海安县| 建昌县| 克拉玛依市| 陈巴尔虎旗| 株洲市| 明星| 新昌县| 方山县| 临高县| 古交市| 黄山市| 江津市| 禹州市| 柳林县| 昭苏县| 宝坻区| 正定县| 阿拉尔市| 石台县| 广昌县| 新巴尔虎左旗| 上饶市| 平谷区| 日喀则市| 安龙县| 汾阳市| 鹤壁市| 高陵县| 江口县| 蛟河市| 渭南市| 德化县| 长海县|