快慢指针
class Node {
constructor(val, next) {
this.val = val;
this.next = next;
}
}
function create(values) {
const head = new Node(values[0], null);
let p = head;
for (let i = 1; i < values.length; i++) {
let val = values[i];
let node = new Node(val, null);
p.next = node;
p = node;
}
return head;
}
while (readline()) {
let values = readline().split(" ");
let head = create(values);
let k = parseInt(readline());
let fast = head;
let slow = head;
while (k > 0) {
fast = fast.next;
k--;
}
while (fast) {
fast = fast.next;
slow = slow.next;
}
print(slow.val);
}