【LeetCode】191. Number of 1 Bits
生活随笔
收集整理的這篇文章主要介紹了
【LeetCode】191. Number of 1 Bits
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目:
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the?Hamming weight).
For example, the 32-bit integer ’11' has binary representation?00000000000000000000000000001011, so the function should return 3.
提示:
考察的是程序遞歸調用,以及對二進制表示的理解。
代碼:
class Solution { public:int hammingWeight(uint32_t n) {if (!n) return 0;return (n % 2) + hammingWeight(n >> 1);} };?
轉載于:https://www.cnblogs.com/jdneo/p/4738942.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的【LeetCode】191. Number of 1 Bits的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: iOS开发——多线程篇——GCD
- 下一篇: iOS开发日记4-第三方登录(Share