Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 맛집
- java
- Find the Duplicate Number
- prefix sum
- 발리인망원
- Python
- 해물감성포차
- string
- algorithm
- Array
- two sum
- map
- findDulicate
- 알탕뚝배기
- 른당사피
- two pointers
- LeetCode
- tree
- 사당돈
- invert Binary Tree
- 6월 첼린지
- algorithum
- 망원 밥집
- 코테
- 발리 음식
- linked list
- 투포인터
- 코딩 테스트
- 알고리즘
- 코딩 테세트
Archives
- Today
- Total
기록하는 공간
[leetcode/python3] 206. Reverse Linked List 본문
Reverse Linked List - LeetCode
Reverse Linked List - Given the head of a singly linked list, reverse the list, and return the reversed list. Example 1: [https://assets.leetcode.com/uploads/2021/02/19/rev1ex1.jpg] Input: head = [1,2,3,4,5] Output: [5,4,3,2,1] Example 2: [https://asset
leetcode.com
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:
previous = None
while head != None:
temp = head
head = head.next
temp.next = previous
previous = temp
return previous
자료구조 Linked List를 사용
'알고리즘 > leetcode' 카테고리의 다른 글
[leetcode/python3] 876. Middle of the Linked List (0) | 2023.02.10 |
---|---|
[leetcode/python3] 21. Merge Two Sorted Lists (0) | 2023.02.08 |
[leetcode/python3] 392. Is Subsequence (1) | 2023.01.25 |
[leetcode/python3] 205. Isomorphic Strings (0) | 2023.01.25 |
[leetcode/python3] 724. Find Pivot Index (0) | 2023.01.22 |
Comments