상위 150개 인터뷰쉬움

조합합 II

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

문제 설명

쉬움

후보 번호(후보)와 목표 번호(목표)의 모음이 주어지면 후보 번호의 합이 목표와 일치하는 후보의 고유한 조합을 모두 찾습니다.

후보의 각 숫자는 조합에 한 번만 사용할 수 있습니다.

참고: 솔루션 세트에는 중복된 조합이 포함되어서는 안 됩니다.

combinationSum2(candidates: list, target: int) -> list 함수를 구현하세요.

제약
  • 1 <= candidates.length <= 100
  • 1 <= candidates[i] <= 50
  • 1 <= target <= 30

Example 1
Input
[10,1,2,7,6,1,5], 8
Output
[[1,1,6],[1,2,5],[1,7],[2,6]]
Explanation

All unique combinations that sum to 8, using each element at most once.

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

1+2+2 = 5 and 5 = 5. These are the only unique combinations.

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

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