摘要: 两次遍历,第一次先计算A,如果对应位置的字符一样,则A+1;如果对应位置的字符不同,则分别计算两个串不匹配字符的数量。 第二次计算B,在不匹配的字符中,两个字典都出现的,就符合B,其值为这个字符在两个字典中的值较小的。 阅读全文
posted @ 2019-10-04 16:06 Sempron2800+ 阅读(125) 评论(0) 推荐(0) 编辑
摘要: 1 import collections 2 class Solution: 3 def uniqueOccurrences(self, arr: List[int]) -> bool: 4 obj = collections.Counter(arr).items() 5 dic = {} 6 for o in obj: 7 if o[1] not in dic: 8 dic[o[1]] = o[ 阅读全文
posted @ 2019-10-04 15:27 Sempron2800+ 阅读(156) 评论(0) 推荐(0) 编辑
摘要: 先将数据排序,然后计算相邻数组的差值,使用字典保存最小差值所包含的元素对。 阅读全文
posted @ 2019-10-04 15:18 Sempron2800+ 阅读(158) 评论(0) 推荐(0) 编辑