class StringDup: def getMax(self, input_1): x= {} for i in input_1: k = str(i) if k not in x: x[k] = 1 else: x[k] += 1 max_num = 0 max_char = '' for i in input_1: if x[i] > max_num: max_num = x[i] max_char = i return max_char x = StringDup().getMax('aabbcc') print x ''' Create a class called StringDup. Given a string made up of ONLY letters and digits, determine which character is repeated the most in the string ('A' is different than 'a'). If there is a tie, the character which appears first in the string (from left to right) should be returned. Examples : aaiicccnn = c aabbccdd = a ab2sbf2dj2skl = 2 Here is the method signature : public char getMax(String input); We will check to make sure that the input contains only letters and digits (no punctuation marks or spaces). Definition Class: StringDup Method: getMax Parameters: String Returns: char Method signature: char getMax(String param0) (be sure your method is public) Test Arguments Expected Results Success "fjk8lfdw8uio8432shjk3297883" 8 Passed "ure4397fds30" 3 Passed "qwertyuiopasdfjkl2346789" q Passed "777888333555" 7 Passed "778833555" 5 Passed '''
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question