标签:can double tco empty ret size int turn pos
1 class Solution 2 { 3 public: 4 bool canReorderDoubled(vector<int>& A) 5 { 6 if(A.empty()) 7 return true; 8 sort(A.begin(),A.end()); 9 int zcnt = 0; 10 int sz = A.size(); 11 for(int i = 0; i < sz; i ++) 12 { 13 if(A[i]>0) 14 { 15 int pos1 = lower_bound(A.begin(),A.end(),A[i]*2)-A.begin(); 16 if(pos1==A.size()||A[pos1]!=2*A[i]) 17 return false; 18 A.erase(A.begin()+pos1); 19 sz --; 20 } 21 else if(A[i]<0) 22 { 23 int pos2 = lower_bound(A.begin(),A.end(),A[i]/2)-A.begin(); 24 if(pos2==A.size()||A[pos2]!=A[i]/2) 25 return false; 26 A.erase(A.begin()+pos2); 27 sz --; 28 } 29 else if(A[i]==0) 30 zcnt ++; 31 } 32 return (zcnt%2)==0; 33 } 34 };
真-瞎j8写写就过了
Leetcode-954 Array of Doubled Pairs(二倍数对数组)
标签:can double tco empty ret size int turn pos
原文地址:https://www.cnblogs.com/Asurudo/p/10090745.html