Last active
August 29, 2015 14:02
-
-
Save habina/19a729085f14c9d2a3bc to your computer and use it in GitHub Desktop.
1.3 Given two strings, write a method to decide if one is a permutation of the other.
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
def permutationString(firstStr, secondStr): | |
"Return True if the second string is a permutation of the other" | |
"""If the length of two strings are different, | |
directly return false | |
""" | |
if(len(firstStr) != len(secondStr)): | |
return False | |
"Change all characters to lowercase" | |
fistrStr = firstStr.lower() | |
secondStr = secondStr.lower() | |
"Create a list and fill with all characters from first string" | |
charArray = [] | |
for i in range(len(firstStr)): | |
charArray.append(firstStr[i]) | |
"Remove all characters from the second string" | |
for i in range(len(secondStr)): | |
if(secondStr[i] in charArray): | |
charArray.remove(secondStr[i]) | |
"Return True if the array is empty" | |
if(len(charArray) != 0): | |
print(charArray) | |
return False | |
else: | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment