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 赞同 分享...
int *a = new int;不会将申请到的int空间初始化,而int *a = new int();则会将申请到的int空间初始化为0。 以下两个语句的区别是:第一个动态申请的空间里面的值是随机值,第二个进行了初始化,里面的值为0: int*p1 =newint[10]; int*p2 =newint[10](); 结论:别使用不带括号的new。 class A{ ...
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...