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

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

LeetCode: Hamming Distance

2019-11-10 18:03:21
字體:
供稿:網(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.

int hammingDistance(int x, int y) {        int d = 0;    for (int i = 0; i < 32; ++i)    {        d += (x & 1) ^ (y & 1);        x >>= 1;        y >>= 1;    }        return d;}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 阳泉市| 兴隆县| 兰坪| 镇江市| 金寨县| 湖南省| 张家口市| 自贡市| 山东省| 河西区| 泰来县| 张家界市| 安宁市| 泸西县| 赫章县| 乐业县| 虞城县| 将乐县| 兖州市| 梁平县| 建瓯市| 石屏县| 苏尼特左旗| 天长市| 社会| 丰顺县| 安庆市| 陆良县| 迭部县| 阿城市| 临海市| 东安县| 红原县| 墨脱县| 高陵县| 柘城县| 民丰县| 垫江县| 万荣县| 章丘市| 四子王旗|