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

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

LeetCode: Hamming Distance

2019-11-09 19:37:45
字體:
來(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.

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ā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 长阳| 伊吾县| 额尔古纳市| 土默特左旗| 桓仁| 广河县| 洪江市| 浦北县| 中牟县| 共和县| 建平县| 东阿县| 攀枝花市| 涞水县| 茌平县| 井陉县| 富宁县| 潼南县| 桑植县| 井冈山市| 吉木萨尔县| 和平县| 永新县| 尼勒克县| 蓝田县| 巧家县| 温州市| 韶关市| 黔南| 张家港市| 榆中县| 托里县| 拉萨市| 宜良县| 洛宁县| 丁青县| 吴忠市| 永春县| 若尔盖县| 固阳县| 江源县|