LeetCode461 Hamming Distance java The Hamming distance between two integers is the number osoluotion
来源:互联网 发布:python 网络爬虫代码 编辑:程序博客网 时间:2024/05/29 16:57
题目要求:
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.
注:该题目没有bug free
原因在于:创建循环条件的时候没有注意取最大值
public class Solution { public int hammingDistance(int x, int y) { int step = 0; while(Math.max(x, y) != 0) { int temple1 = x % 2; int temple2 = y % 2; if(temple1 != temple2) step++; x /= 2; y /= 2; } return step; }}
1 0
- LeetCode461 Hamming Distance java The Hamming distance between two integers is the number osoluotion
- LeetCode461 Hamming Distance JAVA题解
- [LeetCode461]Hamming Distance
- leetcode461. Hamming Distance
- leetcode461. Hamming Distance
- python--leetcode461 hamming distance
- 729--The Hamming Distance Problem
- JOJ1466:The Hamming Distance Problem
- 729 - The Hamming Distance Problem
- 729 - The Hamming Distance Problem
- 729 - The Hamming Distance Problem
- UVaOJ729---The Hamming Distance Problem
- UVa729 The Hamming Distance Problem
- uva729 The Hamming Distance Problem
- The Hamming Distance Problem UVA729
- The Hamming Distance Problem-uva
- UVA729 The Hamming Distance Problem
- uva729 The Hamming Distance Problem
- 富爸爸穷爸爸
- C中volatile关键字
- 顺序二叉树链表实现<模版>
- 知识点:HTML5
- 用shell编程实现三个数的排序
- LeetCode461 Hamming Distance java The Hamming distance between two integers is the number osoluotion
- R语言简介
- Verilog HDL DDS设计(作业3)
- 开源项目源码阅读方法
- visual studio 2015 异常错误:HRSULT:0x8CE0000B
- Eslint 规则说明
- 双向循环链表
- 树梅派应用26:树莓派做FM发射器架设小型电台
- Fragment实现懒加载