Fetch the repository succeeded.
class Solution {
public boolean canReorderDoubled(int[] A) {
List<Integer>pos=new ArrayList<>();
List<Integer>neg=new ArrayList<>();
int cnt=0;
for(int i:A){
if(i==0){
cnt++;continue;
}
if(i>0){
pos.add(i);
}else{
neg.add(i);
}
}
Collections.sort(pos);
Collections.sort(neg,(a,b)->{
return b-a;
});
return check(pos)&check(neg)&(cnt%2==0);
}
public boolean check(List<Integer>list){
Map<Integer,Integer>map=new HashMap<>();
for(int i:list){
if(!map.containsKey(i))map.put(i,0);
map.put(i,map.get(i)+1);
}
for(int i:list){
if(!map.containsKey(i))continue;
if(!map.containsKey(i*2))return false;
map.put(i,map.get(i)-1);
if(map.get(i)==0)map.remove(i);
map.put(i*2,map.get(i*2)-1);
if(map.get(i*2)==0)map.remove(i*2);
}
return true;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。