京东数据分析笔试编程题
做来做去只能AC 91%
思路是 每位学生拥有一个号码牌,上面写着【姓出现次数】* N + 录入列表倒序之后的索引
然后按照号码牌的数字倒序排列即符合题意
import sys count = dict() names = [] while True: line = sys.stdin.readline().strip('') if line == '': break names.append(line) x,m = line.split(' ') if x in count: count[x] += 1 else: count[x] = 1 N = len(names) if N == 0: sys.stdout.write(''+'\n') else: names = names[::-1] newnames = [] i = 0 while i<N: name = names[i] x,m = name.split(' ') newnames.append([name,count[x]*N+i]) i += 1 newnames.sort(key=lambda x:x[1],reverse=True) for res in newnames: sys.stdout.write(str(res[0])+'\n')时间复杂度应该是O(N),空间复杂度应该也不高吧
改来改去都只有91%,有大神看看这思路有什么问题嘛?