How can my c++ code be compiled on oj ?


  • 0
    X

    hi,my c++ code can be compiled by vs2013, but when it being compiled on oj, the following error happened: "required from ‘struct std::_and<std::__is_fast_hash<my_hashcode>, std::__detail::__is_noexcept_hash<int*, my_hashcode> >’".
    please help me, thx!

    struct my_hashcode {
    	size_t operator()(int *cnt) {
    		size_t hash = 0;
    		for (int i = 0; i < 26; i++)
    			hash = hash * 131 + cnt[i];
    		return hash;
    	}
    };
    
    struct my_equal {
    	bool operator()(int *cnt1, int *cnt2) {
    		return memcmp(cnt1, cnt2, 26*sizeof(int)) == 0;
    	}
    };
    
    int *cal_cnt(string &s) {
    	int *cnt = new int[26];
    	memset(cnt, 0, 26 * sizeof(int));
    	for (auto c : s) {
    		cnt[c - 'a']++;
    	}
    	return cnt;
    }
    
    class Solution {
    public:
    	vector<string> &anagrams(vector<string> &strs) {
    		unordered_map<int *, vector<string *>, my_hashcode, my_equal> map;
    		for (auto &s : strs) {
    			int *cnt = cal_cnt(s);
    			auto itr = map.find(cnt);
    			if (itr != map.end()) {
    				itr->second.push_back(&s);
    			} else {
    				itr = map.insert(make_pair(cnt, vector<string *>())).first;
    				itr->second.push_back(&s);
    			}
    		}
    		for (auto &itr : map) {
    			auto &group = itr.second;
    			if (group.size() > 0) {
    				for (auto s : group) {
    					_ans.push_back(*s);
    				}
    			}
    		}
    		return _ans;
    	}
    private:
    	vector<string> _ans;
    };

Log in to reply
 

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