-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path954.py
More file actions
34 lines (30 loc) · 750 Bytes
/
954.py
File metadata and controls
34 lines (30 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Solution(object):
def canReorderDoubled(self, A):
"""
:type A: List[int]
:rtype: bool
"""
res = sorted(A, key=abs)
dic = {}
for i in res:
if dic.has_key(i):
dic[i] += 1
else:
dic[i] = 1
print res
print dic
for i in res:
d = i * 2
print d
print dic
if i in dic and dic[i] == 0:
continue
if d not in dic or dic[d] == 0:
return False
else:
dic[i] -= 1
dic[d] -= 1
continue
return True
solu = Solution()
print solu.canReorderDoubled([3,1,3,6])