60 lines
1.0 KiB
Python
60 lines
1.0 KiB
Python
from string import *
|
|
from re import *
|
|
from datetime import *
|
|
from collections import *
|
|
from heapq import *
|
|
from bisect import *
|
|
from copy import *
|
|
from math import *
|
|
from random import *
|
|
from statistics import *
|
|
from itertools import *
|
|
from functools import *
|
|
from operator import *
|
|
from io import *
|
|
from sys import *
|
|
from json import *
|
|
from builtins import *
|
|
import string
|
|
import re
|
|
import datetime
|
|
import collections
|
|
import heapq
|
|
import bisect
|
|
import copy
|
|
import math
|
|
import random
|
|
import statistics
|
|
import itertools
|
|
import functools
|
|
import operator
|
|
import io
|
|
import sys
|
|
import json
|
|
from typing import *
|
|
|
|
|
|
# @leet start
|
|
# 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]:
|
|
prev = None
|
|
curr = head
|
|
|
|
while curr:
|
|
next_node = curr.next
|
|
curr.next = prev
|
|
prev = curr
|
|
curr = next_node
|
|
|
|
return prev
|
|
|
|
|
|
# @leet end
|