LinkedLists 203: From Last

Just another list gif
function fromLast(list, n) {
let fast = list.head
while (n > 0) {
fast = fast.next
n--
}
}
function fromLast(list, n) {   
let slow = list.head
let fast = list.head
while (n > 0) {
fast = fast.next
n--
}

while (fast.next) {
slow = slow.next
fast = fast.next
} return slow
}
bunny ❤

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store