Created
July 22, 2021 12:06
-
-
Save dongwooklee96/b834cc35fdf8fd0adc42f4ec5f8ea85c to your computer and use it in GitHub Desktop.
4.4.2
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
| """ | |
| 문제 4.4.2 모든 문자열 치환 | |
| 입력으로 주어진 문자열의 가능한 치환을 모두 출력해보는 문제이다. | |
| 예를 들어, 입력된 문자열이 'abc' 라면 결과는 ["abc", "acb", "bac", "cab", "cba"] 가 되어야 한다. | |
| 각 문자가 놓이는 모든 위치의 조합을 만들어라. | |
| """ | |
| from typing import List | |
| def find_permutation(s: str) -> List[str]: | |
| if len(s) == 1: | |
| return list(s) | |
| ans = [] | |
| curr = s[0] | |
| s = s[1:] | |
| words = find_permutation(s) | |
| for sub in words: | |
| for i in range(len(sub) + 1): | |
| ans.append("".join([sub[:i], curr, sub[i:]])) | |
| return ans | |
| if __name__ == '__main__': | |
| s = input() | |
| res = find_permutation(s) | |
| print(*res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment