【第一部分】09Leetcode刷题

一、位1的个数

题目:191. Number of 1 Bits

C++ Soution 1:

 1 class Solution {
 2 public:
 3     int hammingWeight(uint32_t n) 
 4     {
 5         int res = 0;
 6         for (int i = 0; i < 32; ++i) 
 7         {
 8             res += (n & 1);
 9             n = n >> 1;
10         }
11         return res;
12     }
13 };

二、第k个排列

 题目:60. Permutation Sequence

C++ Soution 1:

猜你喜欢

转载自www.cnblogs.com/sunbines/p/10607586.html