Last active
April 2, 2022 17:38
-
-
Save a-agmon/93953e8bc2085abd42e85f804dc3d075 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 perm(orig_str, new_str=""): | |
if(len(new_str) == len(orig_str)): | |
print(new_str) | |
else: | |
for char in orig_str: | |
if(char not in new_str): | |
perm(orig_str, new_str + char) | |
# another version | |
def perm(orig_str, new_str=""): | |
if(len(orig_str) == 0): | |
print(new_str) | |
else: | |
for char in orig_str: | |
perm(orig_str.replace(char,""), new_str + char) | |
perm("ABC") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment