Skip to content

Commit

Permalink
Merge pull request #359 from sarcodian/python_5 reviewed by ningyuansg
Browse files Browse the repository at this point in the history
[Python] Challenge 5 (reviewed and merged)
  • Loading branch information
Steven Landau committed Jan 23, 2017
2 parents ce470ff + 7a66043 commit 0009821
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 0 deletions.
1 change: 1 addition & 0 deletions challenge_5/python/sarcodian/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Finds the added char in t when compared to s using dictionaries
23 changes: 23 additions & 0 deletions challenge_5/python/sarcodian/src/challenge_5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
def find_the_diff(s, t):
'''
s: string, a string made up of lower case letters
t: string, a string made up of shuffled up s plus one additional char
returns: char, the single element string that was not in s
'''

t_dict = {}
s_dict = {}

for i in s:
s_dict[i] = s_dict.get(i, 0) + 1

for i in t:
t_dict[i] = t_dict.get(i, 0) + 1

for i in t_dict.keys():
if t_dict[i] > s_dict.get(i, 0):
return i

s = "aaaaab"
t = "aaaaaab"
print(find_the_diff(s,t))
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution(object):
def findTheDifference(self, s, t):
t_dict = {}
s_dict = {}

for i in s:
s_dict[i] = s_dict.get(i, 0) + 1

for i in t:
t_dict[i] = t_dict.get(i, 0) + 1

for i in t_dict.keys():
if t_dict[i] > s_dict.get(i, 0):
return i


65 changes: 65 additions & 0 deletions challenge_5/python/sarcodian/src/unittest-from-mjuiuc/test.py

Large diffs are not rendered by default.

0 comments on commit 0009821

Please sign in to comment.