The test case in LeetCode is more readable compare to other online judges.
[1] 1
doesn't mean there are only 2 params. [1]
indicates the n=1
and the array has one element 1. The last 1
represents the k.
The test case in LeetCode is more readable compare to other online judges.
[1] 1
doesn't mean there are only 2 params. [1]
indicates the n=1
and the array has one element 1. The last 1
represents the k.
The code definition is
class Solution {
public:
int hammingWeight(uint32_t n) {
}
};
not
class Solution {
public:
int hammingWeight(int n) {
}
};
The time complexity of this code is O(N*N), but the solution is O(N).