1
2
3
4
5
6
7
|
from itertools import permutations
class Solution:
def permute(self, nums: List[int]) -> List[List[int]]:
ans=[]
for i in permutations(nums) :
ans.append(list(i))
return(ans)
|
cs |
1
2
3
4
5
|
from itertools import permutations
class Solution:
def permute(self, nums: List[int]) -> List[List[int]]:
ans=list(map(list, (permutations(nums))))
return(ans)
|
cs |
위. permutations 안에 개체들이 tuple이라 문제에서 요청하는데로
list 로 type casting 하고 빈 list에 append 하는방법
아래. map 함수 사용
메모리나 시간상 차이가 별로 없네용 (머쓱 ^^;)
반응형
'python-algorithm' 카테고리의 다른 글
Codeforces A. Watermelon (0) | 2022.04.28 |
---|---|
leetcode 1910. Remove All Occurrences of a Substring (0) | 2022.04.26 |
leetcode 2221. Find Triangular Sum of an Array (0) | 2022.04.25 |
백준 9012 괄호 (0) | 2022.04.22 |
백준 24510 시간복잡도를 배운 도도 (0) | 2022.04.21 |
댓글