国产探花免费观看_亚洲丰满少妇自慰呻吟_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(); }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 阳新县| 博兴县| 安阳市| 始兴县| 建德市| 板桥市| 南投市| 齐齐哈尔市| 东兰县| 吉安县| 沅江市| 岗巴县| 轮台县| 宜春市| 旅游| 佛坪县| 从化市| 银川市| 醴陵市| 赤城县| 宜兰市| 长丰县| 彭山县| 定远县| 自贡市| 锡林浩特市| 荃湾区| 方山县| 五常市| 伊春市| 甘德县| 南华县| 文昌市| 乌审旗| 芒康县| 涞水县| 三门县| 乌海市| 穆棱市| 清流县| 吴桥县|