problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::array_of_doubled_pairs::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static bool canReorderDoubled (vector< int > &arr)
 

详细描述

在文件 leetcode.h1999 行定义.

成员函数说明

◆ canReorderDoubled()

bool leetcode::array_of_doubled_pairs::Solution::canReorderDoubled ( vector< int > &  arr)
static

在文件 leetcode.cpp5338 行定义.

5338 {
5339 multiset<int> positive;
5340 multiset<int, greater<>> negative;
5341 for(auto num: arr) {
5342 if(num >= 0) {
5343 positive.insert(num);
5344 } else {
5345 negative.insert(num);
5346 }
5347 }
5348 while(!positive.empty()) {
5349 const int num = *positive.begin();
5350 positive.erase(positive.begin());
5351 auto it = positive.find(num * 2);
5352 if(it == positive.end()) {
5353 return false;
5354 }
5355 positive.erase(it);
5356 }
5357 while(!negative.empty()) {
5358 const int num = *negative.begin();
5359 negative.erase(negative.begin());
5360 auto it = negative.find(num * 2);
5361 if(it == negative.end()) {
5362 return false;
5363 }
5364 negative.erase(it);
5365
5366 negative.erase(it);
5367 }
5368 return true;
5369 }

被这些函数引用 leetcode::array_of_doubled_pairs::TEST().


该类的文档由以下文件生成: