관리 메뉴

솜씨좋은장씨

[leetCode] 46. Permutations (Python) 본문

Programming/코딩 1일 1문제

[leetCode] 46. Permutations (Python)

솜씨좋은장씨 2020. 6. 4. 22:03
728x90
반응형

Given a collection of distinct integers, return all possible permutations.

 

Example:

Input: [1,2,3]
Output:
[
  [1,2,3],
  [1,3,2],
  [2,1,3],
  [2,3,1],
  [3,1,2],
  [3,2,1]
]

Solution

from itertools import permutations

class Solution:
    def permute(self, nums: List[int]) -> List[List[int]]:
        
        permu = list(permutations(nums, len(nums)))
        
        return permu

 

 

SOMJANG/CODINGTEST_PRACTICE

1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.

github.com

 

Comments