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

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

LeetCode:Hamming Distance

2019-11-08 01:58:49
字體:
來源:轉載
供稿:網友

Total Accepted: 32005 Total Submissions: 45111 Difficulty: Easy Contributors: Samuri 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) { vector<int>result; int dst = x^y; while(dst) { if(dst%2==1) { result.push_back(dst%2); } dst/=2; } return result.size(); }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 赤壁市| 内乡县| 普宁市| 永胜县| 府谷县| 晴隆县| 三明市| 巢湖市| 浦县| 温泉县| 宁安市| 马鞍山市| 巴林右旗| 巴彦县| 诏安县| 抚远县| 陕西省| 丹棱县| 青州市| 临漳县| 汕头市| 朝阳市| 叙永县| 饶阳县| 阿鲁科尔沁旗| 马边| 垫江县| 永宁县| 离岛区| 鹿泉市| 锦州市| 克什克腾旗| 虹口区| 兴海县| 雷山县| 大庆市| 施秉县| 鄂托克前旗| 棋牌| 南靖县| 洛阳市|