zoukankan      html  css  js  c++  java
  • Leetcode-954 Array of Doubled Pairs(二倍数对数组)

     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写写就过了

  • 相关阅读:
    JavaScript跨域总结与解决办法
    css IFC 与 BFC分析
    JavaScript Note
    Knowledge Architecture
    BSP
    Olympiad
    Software Engineering
    Assembly Language
    Algorithm
    Data Structure
  • 原文地址:https://www.cnblogs.com/Asurudo/p/10090745.html
Copyright © 2011-2022 走看看