首页 > 其他 > 详细

leetcode1122

时间:2019-07-14 13:29:28      阅读:72      评论:0      收藏:0      [点我收藏+]
 1 import collections
 2 class Solution:
 3     def relativeSortArray(self, arr1: List[int], arr2: List[int]) -> List[int]:
 4         n1 = len(arr1)
 5         n2 = len(arr2)
 6         if n2 == 0:
 7             return arr1
 8         distinct = collections.OrderedDict()
 9         others = []
10         for i in range(n2):
11             distinct[arr2[i]] = 0
12         #print(distinct)
13         for j in range(n1):
14             if arr1[j] in distinct:
15                 distinct[arr1[j]] += 1
16             else:
17                 others.append(arr1[j])
18         res = []
19         for k,v in distinct.items():
20             res = res + [k] * v
21         others = sorted(others)
22         res = res + others
23         return res

 

leetcode1122

原文:https://www.cnblogs.com/asenyang/p/11183548.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!