In an array, all the numbers are appearing 3 times(or odd no. of times) except one number,which appears once, Find that number using bit-manipulation? [closed]
温馨提示:
本文最后更新于 2024年04月12日,已超过 48 天没有更新。若文章内的图片失效(无法正常加载),请留言反馈或直接联系我。
I am following this video and @1.17.00, there is an explanation for solution which goes something like this:
lets say arr = {1,2,2,1,3,2,1}
1 -> 0001
2 -> 0010
2 -> 0010
1 -> 0001
3 -> 0011
2 -> 0010
1 -> 0001
summing bits -> 0044
n -> no. of repetion, which in this case is 3
modulo of the elements of sum by n -> 0044 % 3 = 0011 = 3
Hence 3 is the answer.
How to implement this in code in java?
正文到此结束
- 本文标签: 家庭宠物
- 本文链接: https://www.coder6.net/article/2511
- 版权声明: 本文由蚂蚁原创发布,转载请遵循《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权
热门推荐
-
浏览(193) 评论(0)