letxbe the sum of all elements currently in your array. choose indexi, such that0 <= i < target.sizeand set the value ofAat indexitox. You may repeat this procedure as many times as needed. Return True if it is possible to construct thetargetarray fromAotherwise return False. Example...
typedeflonglongint_int;classSolution{public: priority_queue<_int> q;boolisPossible(vector<int>& target){intlen = target.size(); _int sum =0;for(inti=0;i<len;i++) { q.push((_int)target[i]); sum +=(_int) target[i]; }while(1) { _int term = (_int)q.top();//第一小q....
{ sum += target[i]; if (target[i] > max) { max = target[i]; index = i; } } // 如果目标数组的最大值是1,说明数组里全是1 if (max == 1) return true; long left = sum - max; // 如果数组中数字之和 和 最大值相等,说明其他数字都成0了 if (left == 0) return false; /...