88ms slow AC solutions, where to improve ?

  • 0

    Guess my logic is clear, but can someone tell me which of my sentences takes too much time? If I am going to optimize the code, where to start? Thank you guys.

    class Solution {
        bool canConstruct(string ransomNote, string magazine) {
            if(ransomNote.size()>magazine.size())   return false;
            unordered_map<char,int>     ransom;
            unordered_map<char,int>     maga;
            for(int i = 0;i<ransomNote.size();i++)
            for(int i = 0;i<magazine.size();i++)
            if(ransom.size()>maga.size())   return false;
            for(auto iterR = ransom.begin();iterR != ransom.end();iterR++)
                if(iterR->second > maga[iterR->first])  return false;
            return true;

Log in to reply

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