-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #359 from sarcodian/python_5 reviewed by ningyuansg
[Python] Challenge 5 (reviewed and merged)
- Loading branch information
Showing
4 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
16 changes: 16 additions & 0 deletions
16
challenge_5/python/sarcodian/src/unittest-from-mjuiuc/FindTheDifference.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
65
challenge_5/python/sarcodian/src/unittest-from-mjuiuc/test.py
Large diffs are not rendered by default.
Oops, something went wrong.