标签:return sum null tor solution back lis find syn
1 static int wing=[]() 2 { 3 std::ios::sync_with_stdio(false); 4 cin.tie(NULL); 5 return 0; 6 }(); 7 8 class Solution 9 { 10 public: 11 vector<string> findRestaurant(vector<string>& list1, vector<string>& list2) 12 { 13 unordered_map<string,int> simap; 14 int sz1=list1.size(); 15 int sz2=list2.size(); 16 for(int i=0;i<sz1;i++) 17 simap[list1[i]]=i; 18 int count=INT_MAX; 19 vector<string> res; 20 for(int i=0;i<sz2;i++) 21 { 22 if(simap.find(list2[i])!=simap.end()) 23 { 24 int cur=i+simap[list2[i]]; 25 if(cur==count) 26 res.push_back(list2[i]); 27 else if(cur<count) 28 { 29 res.clear(); 30 res.push_back(list2[i]); 31 count=cur; 32 } 33 } 34 } 35 return res; 36 } 37 };
用个map,挺简单,问题不大
599. Minimum Index Sum of Two Lists
标签:return sum null tor solution back lis find syn
原文地址:https://www.cnblogs.com/zhuangbijingdeboke/p/9144190.html