461. Hamming Distance 难度:easy
来源:互联网 发布:页游 知乎 编辑:程序博客网 时间:2024/05/17 07:24
题目:
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 = 4Output: 2Explanation: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 temp = x ^ y; int count = 0; while(temp) { count += (temp % 2); temp /= 2; } return count; }};
0 0
- 461. Hamming Distance 难度:easy
- [easy]461. Hamming Distance
- LeetCode :【Easy】461. Hamming Distance
- easy 1 : 461. Hamming Distance
- leetcode 461.Hamming Distance(easy)[位运算]
- 【leetcode】【Easy】【461. Hamming Distance】【bit manipulation】
- 477. Total Hamming Distance 难度:medium
- LeetCode 461. Hamming Distance
- 461. Hamming Distance
- 【Leetcode】461. Hamming Distance
- 461. Hamming Distance
- LeetCode 461. Hamming Distance
- 461. Hamming Distance
- LeetCode - 461. Hamming Distance
- 461. Hamming Distance*
- LeetCode-461. Hamming Distance
- 461. Hamming Distance
- 【LeetCode】 461. Hamming Distance
- Java编程思想笔记——第八章 多态
- php 的九大全局变量$_GET,$_POST,$_SERVER
- 无题
- Lua的协程
- 一看就懂的数据库范式介绍(1NF—5NF)
- 461. Hamming Distance 难度:easy
- CentOS6.7安装TeamViewer
- Java总结篇系列:Java多线程(一)
- 数据分析与数据挖掘在常规工作中的应用——数据 离散化
- u-boot之添加一块新板子的支持
- 深入了解JAVA可变长度的参数(Varargs)
- support-percent
- 微信小程序checkbox排列方向
- 4.面向对象