Leetcode doesn't compile with C++14 features?


  • 0
    G
    int findLHS(vector<int>& nums) {
        unordered_map<int, int> cache;
        for (auto&& val : nums) {
            if (cache.find(val) == std::end(cache)) {
                cache.emplace(val, 0);
            }
            cache[val]++;
        }
        
        auto sol = 0;
        for (auto&& p : cache) {
            if (cache.find(p.first+1) != std::end(cache)) {
                sol = max(sol, cache[p.first+1] + p.second);
            }
        }
        
        return sol;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.