本文整理汇总了Python中ListNode.ListNode.next方法的典型用法代码示例。如果您正苦于以下问题:Python ListNode.next方法的具体用法?Python ListNode.next怎么用?Python ListNode.next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ListNode.ListNode
的用法示例。
在下文中一共展示了ListNode.next方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_test_list3
# 需要导入模块: from ListNode import ListNode [as 别名]
# 或者: from ListNode.ListNode import next [as 别名]
def generate_test_list3():
n1 = ListNode(1)
n2 = ListNode(2)
n3 = ListNode(3)
n1.next = n2
n2.next = n3
return n1
示例2: test2
# 需要导入模块: from ListNode import ListNode [as 别名]
# 或者: from ListNode.ListNode import next [as 别名]
def test2():
n1a = ListNode(1)
n1b = ListNode(1)
n1c = ListNode(1)
n1a.next = n1b
n1b.next = n1c
rslt = removeElement(n1a, 1)
print(ListNode.print_ll(rslt))
示例3: test2
# 需要导入模块: from ListNode import ListNode [as 别名]
# 或者: from ListNode.ListNode import next [as 别名]
def test2():
n1 = ListNode(1)
n2 = ListNode(2)
n3 = ListNode(3)
n4 = ListNode(4)
n1.next = n2
n2.next = n3
n3.next = n4
ListNode.print_ll(reorderList(n1))
示例4: test2
# 需要导入模块: from ListNode import ListNode [as 别名]
# 或者: from ListNode.ListNode import next [as 别名]
def test2():
n1 = ListNode(1)
n2 = ListNode(2)
n3 = ListNode(3)
n3.next = n2
n2.next = n1
h = n3
rslt = mergeSort(h)
ListNode.print_ll(rslt)
示例5: test3
# 需要导入模块: from ListNode import ListNode [as 别名]
# 或者: from ListNode.ListNode import next [as 别名]
def test3():
n6 = ListNode(6)
n7 = ListNode(7)
n9 = ListNode(9)
n5 = ListNode(5)
n6.next = n7
n7.next = n9
ListNode.print_ll(addTwoNumbers(n6, n5, 0))
ListNode.print_ll(addTwoNumbersNoCarry(n6, n5))
示例6: test2
# 需要导入模块: from ListNode import ListNode [as 别名]
# 或者: from ListNode.ListNode import next [as 别名]
def test2():
n1 = ListNode(1)
n2 = ListNode(2)
n3 = ListNode(3)
n4 = ListNode(4)
n1.next = n2
n2.next = n3
n3.next = n4
print(findCycleNode(n1))
示例7: test1
# 需要导入模块: from ListNode import ListNode [as 别名]
# 或者: from ListNode.ListNode import next [as 别名]
def test1():
n0 = ListNode(0)
n1 = ListNode(1)
n2 = ListNode(2)
n3 = ListNode(3)
n4 = ListNode(4)
n0.next = n1
n1.next = n2
n2.next = n3
n3.next = n4
ListNode.print_ll(reorderList(n0))
示例8: generate_test_list1
# 需要导入模块: from ListNode import ListNode [as 别名]
# 或者: from ListNode.ListNode import next [as 别名]
def generate_test_list1():
n1 = ListNode(1)
n2 = ListNode(2)
n3 = ListNode(3)
n4 = ListNode(4)
n5 = ListNode(5)
n1.next = n2
n2.next = n3
n3.next = n4
n4.next = n5
return n1
示例9: test3
# 需要导入模块: from ListNode import ListNode [as 别名]
# 或者: from ListNode.ListNode import next [as 别名]
def test3():
n1 = ListNode(1)
n1a = ListNode(1)
n1b = ListNode(1)
n2a = ListNode(2)
n2b = ListNode(2)
n1.next = n1a
n1a.next = n1b
n1b.next = n2a
n2a.next = n2b
ListNode.print_ll(removeDupComp(n1))
示例10: test2
# 需要导入模块: from ListNode import ListNode [as 别名]
# 或者: from ListNode.ListNode import next [as 别名]
def test2():
n1 = ListNode(1)
n1a = ListNode(1)
n1b = ListNode(1)
n2 = ListNode(2)
n3 = ListNode(3)
n1.next = n1a
n1a.next = n1b
n1b.next = n2
n2.next = n3
ListNode.print_ll(removeDupComp(n1))
示例11: partition
# 需要导入模块: from ListNode import ListNode [as 别名]
# 或者: from ListNode.ListNode import next [as 别名]
def partition(self, head, x):
"""
:type head: ListNode
:type x: int
:rtype: ListNode
"""
if not head:
return head
# maintain the tail of sub-list with (nodes <= target)
tail = ListNode(0)
tail.next = head
dummy = tail # record it
currentPrev = tail
current = head
# two operation: 1. cut smaller node; 2. insert to sublist
while current:
'''
@note:@memorize:
下面的反人类解法我也给自己跪了,找到比x小的,插入。
一直维护小于x的sublist的tail,被main里的测试fail
其实,维护大于等于x的sublit的head,要更加简单,符合人类思维。。。
'''
if current.val < x: # update tail pointer, but do nothing
# 1. cut
currentPrev.next = current.next
currentForNextLoop = current.next # record it first
# 2. insert
tmp = tail.next
tail.next = current
current.next = tmp
tail = current # update smaller-node-list tail
current = currentForNextLoop # for next loop
# @note: here, no update for currentPrev, still the same one
else:
currentPrev = current
current = current.next
return dummy.next
示例12: test4
# 需要导入模块: from ListNode import ListNode [as 别名]
# 或者: from ListNode.ListNode import next [as 别名]
def test4():
l1 = ListNode(1)
l2 = ListNode(2)
l3 = ListNode(3)
l4 = ListNode(4)
l5 = ListNode(5)
l1.next = l2
l2.next = l3
l3.next = l4
l4.next = l5
ListNode.print_ll(l1)
ListNode.print_ll(removeNtoLast(l1, 2))
示例13: test3
# 需要导入模块: from ListNode import ListNode [as 别名]
# 或者: from ListNode.ListNode import next [as 别名]
def test3():
n1 = ListNode(1)
n2 = ListNode(2)
n3 = ListNode(3)
n4 = ListNode(4)
n5 = ListNode(5)
n6 = ListNode(6)
n1.next = n2
n2.next = n3
n3.next = n4
n4.next = n5
n5.next = n6
ListNode.print_ll(revKGrp(n1, 4))
示例14: test2
# 需要导入模块: from ListNode import ListNode [as 别名]
# 或者: from ListNode.ListNode import next [as 别名]
def test2():
n1 = ListNode(1)
n2 = ListNode(2)
n3 = ListNode(3)
n4 = ListNode(4)
n5 = ListNode(5)
n6 = ListNode(6)
n1.next = n2
n2.next = n3
n3.next = n4
n4.next = n5
n5.next = n6
ListNode.print_ll(n1)
ListNode.print_ll(rotateLSegment(n1, 1, 4))
示例15: test1
# 需要导入模块: from ListNode import ListNode [as 别名]
# 或者: from ListNode.ListNode import next [as 别名]
def test1():
n1 = ListNode(1)
n2 = ListNode(2)
n3 = ListNode(3)
n4 = ListNode(4)
n5 = ListNode(5)
n6 = ListNode(6)
n1.next = n2
n2.next = n3
n3.next = n4
n4.next = n5
n5.next = n6
#ListNode.print_ll(revKGrp(n1, 2))
ListNode.print_ll(revKGroup_r(n1, 1))