Inconsistance happens!
This piece of code goes well
class Solution {
public:
vector<int> topKFrequent(vector<int>& nums, int k) {
unordered_map<int, int> num_freq_map;
for(const auto &ele : nums) {
++num_freq_map[ele];
}
}
};
but when I changed from unordered_map<int, int> num_freq_map;
to unordered_map<int, int> num_freq_map
()
;
, appending a pair of brackets.
class Solution {
public:
vector<int> topKFrequent(vector<int>& nums, int k) {
unordered_map<int, int> num_freq_map();
for(const auto &ele : nums) {
++num_freq_map[ele];
}
}
};
I got an error:
Line 6: lvalue required as increment operand
Why? What happend to my variable num_freq_map
when initializing?
How should I learn this sort of things. Read the Standard Template Library source code, right?