상위 150개 인터뷰쉬움

두 개의 숫자 추가

'두 숫자 더하기' 문제에 대한 자세한 가이드 및 Python 구현입니다.

문제 설명

쉬움

두 개의 음수가 아닌 정수를 나타내는 두 개의 비어 있지 않은 연결 목록이 제공됩니다. 숫자는 역순으로 저장되며 각 노드에는 단일 숫자가 포함됩니다. 두 숫자를 더하고 그 합계를 연결된 목록으로 반환합니다.

숫자 0 자체를 제외하고는 두 숫자에 선행 0이 포함되어 있지 않다고 가정할 수 있습니다.

연결된 목록은 Python 목록으로 표시됩니다. 합계를 역순의 목록으로 반환하는 함수 addTwoNumbers(l1: list, l2: list) -> list을 구현하세요.

제약
  • The number of nodes in each linked list is in the range [1, 100]
  • 0 <= Node.val <= 9
  • It is guaranteed that the list represents a number that does not have leading zeros

Example 1
Input
[2,4,3], [5,6,4]
Output
[7,0,8]
Explanation

342 + 465 = 807. Represented in reverse: [7,0,8].

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

0 + 0 = 0.

Example 3
Input
[9,9,9,9,9,9,9], [9,9,9,9]
Output
[8,9,9,9,0,0,0,1]
Explanation

9999999 + 9999 = 10009998. Represented in reverse: [8,9,9,9,0,0,0,1].

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

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