leetcode-86-分割链表
Posted oldby
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode-86-分割链表相关的知识,希望对你有一定的参考价值。
题目描述:
方法一:
# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def partition(self, head: ListNode, x: int) -> ListNode: before = before_head = ListNode(0) after = after_head = ListNode(0) while head: if head.val<x: before.next = ListNode(head.val) before = before.next else: after.next = ListNode(head.val) after = after.next head = head.next after.next = None before.next = after_head.next return before_head.next
以上是关于leetcode-86-分割链表的主要内容,如果未能解决你的问题,请参考以下文章