반응형
Notice
Recent Posts
Recent Comments
- Today
- Total
작심삼일
[LeetCode] 47 | Permutations II | Python 본문
728x90
반응형
문제 링크: https://leetcode.com/problems/permutations-ii/
문제
Given a collection of numbers, nums, that might contain duplicates, return all possible unique permutations in any order.
조건
- 1 <= nums.length <= 8
- -10 <= nums[i] <= 10
내 풀이
itertools의 permutations를 사용한다.
다만 예시에서 주어진 것처럼 [1, 1, 2]와 같이 중복된 숫자가 있을 경우, permutation을 진행했을 때 중복된 집합이 나올 수 있다.
이는 set으로 제거한다.
코드
from itertools import permutations
class Solution:
def permuteUnique(self, nums: List[int]) -> List[List[int]]:
return set(permutations(nums))
728x90
반응형
'스터디 > 코테' 카테고리의 다른 글
[LeetCode] 1192 | Critical Connections in a Network | Python (0) | 2022.05.18 |
---|---|
[LeetCode] 1091 | Shortest Path in Binary Matrix | Python (0) | 2022.05.16 |
[LeetCode] 1641 | Count Sorted Vowel Strings | Python (0) | 2022.05.11 |
[LeetCode] 216 | Combination Sum III | Python (0) | 2022.05.10 |
[LeetCode] 17 | Letter Combinations of a Phone Number | Python (0) | 2022.05.09 |
Comments