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

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

leetcode-Hamming Distance

2019-11-11 00:19:25
字體:
來源:轉載
供稿:網友

漢明碼距離

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.

class Solution {public: int hammingDistance(int x, int y) { int dis = 0; int sx[32] = {0}; int sy[32] = {0}; int xi = 0; int yi = 0; while(x != 0){ sx[xi++] = x % 2; x /= 2; } while(y != 0){ sy[yi++] = y % 2; y /= 2; } for(int i = 0 ; i < 32; i++){ if(sx[i] != sy[i]){ dis++; } } return dis; }};
上一篇:eclipes快捷鍵

下一篇:軟件定時器(一)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 兰西县| 瑞金市| 馆陶县| 呼玛县| 阜平县| 嘉义市| 同江市| 永嘉县| 阿合奇县| 永宁县| 瓦房店市| 龙岩市| 东平县| 德格县| 获嘉县| 清徐县| 葫芦岛市| 白朗县| 富锦市| 资中县| 瓦房店市| 玉山县| 泗阳县| 海林市| 九龙县| 哈尔滨市| 桐柏县| 黄大仙区| 高雄市| 大关县| 商洛市| 拉孜县| 龙陵县| 冷水江市| 方城县| 曲靖市| 特克斯县| 三江| 土默特右旗| 贵州省| 出国|