赞
踩
class Solution { public: vector<int> arraysIntersection(vector<int>& arr1, vector<int>& arr2, vector<int>& arr3) { int N1 = arr1.size(); int N2 = arr2.size(); int N3 = arr3.size(); int a,b,c; a = b = c = 0; vector<int> ans ; while(a < N1 && b < N2 && c < N3){ if(arr1[a] == arr2[b] && arr1[a] == arr3[c]){ ans.push_back(arr1[a]); a++;b++;c++; continue; } int A = a; int B = b; int C = c; bool flag1,flag2,flag3; flag1 = flag2 = flag3 = true; if(flag2 && arr1[A] > arr2[B]) b++,flag2 = false; if(flag3 && arr1[A] > arr3[C]) c++,flag3 = false; if(flag1 && arr2[B] > arr1[A]) a++,flag1 = false; if(flag3 && arr2[B] > arr3[C]) c++,flag3 = false; if(flag1 && arr3[C] > arr1[A]) a++,flag1 = false; if(flag2 && arr3[C] > arr2[B]) b++,flag2 = false; } return ans; } };
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。