simple C++ solution without hashmap


  • 0
    Z
    class Solution {
    public:
        vector<string> findRestaurant(vector<string>& list1, vector<string>& list2) {
            vector<string> result;
            for(int index=0;index<=list1.size()+list2.size()-2;++index)
            {
                for(int i=0;i<list1.size();++i)
                {
                    if(index-i<list2.size())
                    {
                        if(list1[i]==list2[index-i])
                         result.push_back(list1[i]);
                    }
                    
                }
                if (result.size()>0)
                return result;
            }
         
        }
    };
    

Log in to reply
 

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