|  | 
|  | 
| back to board | Memory Limit Error Using Dictionary with Python2.7 Posted by jdneo  25 Jun 2014 09:57I used dictionary in python 2.7 to solve this problem, but got MLE on test#21. Can anybody give me some advise or hint about how to deal with this problem? Thanks a lot!!!
 Here is my code:
 
 from sys import stdin
 
 num = int(stdin.readline())
 notes = {}
 for i in range(num):
 key = int(stdin.readline().strip())
 if notes.has_key(key):
 notes[key] += 1
 else:
 notes[key] = 1
 max = -1
 note = -1
 for key, value in notes.items():
 if value > max:
 note = key
 max = value
 print note
Re: Memory Limit Error Using Dictionary with Python2.7 I have MLE too :(
 def main():
 
 import sys
 from collections import Counter
 n = raw_input()
 lns = sys.stdin.readlines()
 cnt = Counter(lns)
 print max(cnt, key=cnt.get)[:-1]
 
 main()
 | 
 | 
|