通常采取尾插法:一开始链表是空的,后来每来一个节点,就加入到链表尾部。实现的效果如下👇
输入:2 7 11 15
链表:2 -> 7 -> 11 -> 15 -> null //顺序跟输入一模一样
给定一个整数数组 nums,要求 先构建一个链表,然后遍历链表并输出所有元素。
输入共两行:
输出 n 个整数,每个数字占一行,按链表顺序输出。
4
2 7 11 15
2
7
11
15
3
3 2 4
3
2
4
Scan the QR code below with WeChat to sign in
First-time scan will create your account automatically
请使用微信扫描下方二维码完成注册