Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- 파이썬
- SW Expert Academy
- 편스토랑
- 금융문자분석경진대회
- 데이콘
- gs25
- 코로나19
- 백준
- 더현대서울 맛집
- Kaggle
- programmers
- ubuntu
- PYTHON
- 프로그래머스
- 프로그래머스 파이썬
- Git
- github
- 자연어처리
- 맥북
- 편스토랑 우승상품
- Baekjoon
- 우분투
- hackerrank
- Real or Not? NLP with Disaster Tweets
- AI 경진대회
- dacon
- Docker
- leetcode
- 캐치카페
- ChatGPT
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 47. Permutations II (Python) 본문
728x90
반응형
Given a collection of numbers, nums, that might contain duplicates, return all possible unique permutations in any order.
Example 1:
Input: nums = [1,1,2]
Output:
[[1,1,2],
[1,2,1],
[2,1,1]]
Example 2:
Input: nums = [1,2,3]
Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
Constraints:
- 1 <= nums.length <= 8
- -10 <= nums[i] <= 10
Solution
from itertools import permutations
class Solution:
def permuteUnique(self, nums: List[int]) -> List[List[int]]:
answer = []
permus = list(permutations(nums, len(nums)))
for permu in permus:
if permu not in answer:
answer.append(permu)
return answer
먼저 Permutations를 활용해서 리스트를 만들어주고 그 중 유니크한 값들만 남겼습니다.
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 165. Compare Version Numbers (Python) (0) | 2020.11.19 |
---|---|
[leetCode] 77. Combinations (Python) (0) | 2020.11.18 |
[leetCode] 19. Remove Nth Node From End of List (Python) (0) | 2020.11.16 |
[leetCode] 397. Integer Replacement (Python) (0) | 2020.11.15 |
[leetCode] 747. Largest Number At Least Twice of Others (Python) (0) | 2020.11.13 |
Comments