상위 150개 인터뷰쉬움

하위 집합 II

'하위 집합 II' 문제에 대한 자세한 가이드 및 Python 구현입니다.

문제 설명

쉬움

중복을 포함할 수 있는 정수 배열 nums가 주어지면 가능한 모든 하위 집합(멱집합)을 반환합니다.

솔루션 세트에는 중복된 하위 세트가 포함되어서는 안 됩니다. 어떤 순서로든 솔루션을 반환합니다.

subsetsWithDup(nums: list) -> list 함수를 구현하세요.

제약
  • 1 <= nums.length <= 10
  • -10 <= nums[i] <= 10

Example 1
Input
[1,2,2]
Output
[[],[1],[1,2],[1,2,2],[2],[2,2]]
Explanation

Unlike the basic subsets problem, [1,2,2] has duplicate 2's. We skip duplicate subsets like having two copies of [2].

Example 2
Input
[0]
Output
[[],[0]]
Explanation

Same as basic subsets for a single element.

Need a Hint?
세트 또는 힙과 같은 역추적 관련 데이터 구조를 사용하는 것이 좋습니다.
Edge Cases to Watch
  • 빈 입력 구조
  • 단일 요소 입력
  • 큰 수치 범위

해결할 준비가 되셨나요?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

편집기에서 열기
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

권장 Python 리소스

관련 대화형 튜토리얼, 치트 시트, 코드 비교를 통해 지식을 확장하세요.