ListNode head = new ListNode(list.get(0)); ListNode temp = head; for(int i=1;ilt;list.size();i++){ temp.next = new ListNode(list.get(i)); tem_牛客网_牛客在手,offer不愁
ListNode node = head; while (node != null) { list.add(node); node = node.next; } ListNode node1 = list.get(k - 1); ListNode node2 = list.get(list.size() - k); int temp = node1.val; node1.val = node2.val;node2.val = temp 发布于 2022-05-30 09:57 赞同 分享...
class ListNode: def __init__(self, val): self.val = val self.next = None def reverse_node(head): p = head q = head.next head.next = None while q: r = q.next q.next = p p = q q = r head = p return head if __name__ == '__main__': l1 = ListNode(3) l1.next...