상위 150개 인터뷰쉬움

두 개의 정렬된 목록 병합

'두 개의 정렬된 목록 병합' 문제에 대한 자세한 가이드 및 Python 구현입니다.

문제 설명

쉬움

두 개의 정렬된 연결 목록 list1과 list2의 헤드가 제공됩니다. 두 목록을 하나의 정렬된 목록으로 병합합니다. 목록은 처음 두 목록의 노드를 함께 연결하여 만들어야 합니다. 병합된 연결 목록의 헤드를 반환합니다.

연결된 목록은 Python 목록으로 표시됩니다. 병합된 정렬 목록을 반환하는 mergeTwoLists(list1: list, list2: list) -> list 함수를 구현하세요.

제약
  • The number of nodes in both lists is in the range [0, 50]
  • -100 <= Node.val <= 100
  • Both list1 and list2 are sorted in non-decreasing order

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

Merging 1->2->4 and 1->3->4 gives 1->1->2->3->4->4.

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

Both lists are empty, so the merged list is also empty.

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

Merging an empty list with [0] gives [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 리소스

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