상위 150개 인터뷰쉬움

하위 집합

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

문제 설명

쉬움

고유한 요소 수의 정수 배열이 주어지면 가능한 모든 하위 집합(멱집합)을 반환합니다.

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

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

제약
  • 1 <= nums.length <= 10
  • -10 <= nums[i] <= 10
  • All the numbers of nums are unique

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

All 2^3 = 8 subsets of [1,2,3] are generated, including the empty set and the full set.

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

The two subsets of [0] are the empty set [] and [0].

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 리소스

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