Skip to content

Instantly share code, notes, and snippets.

@lastday154
Created March 4, 2019 04:42
Show Gist options
  • Save lastday154/a63d413a044021d78c7937db0a81a1ec to your computer and use it in GitHub Desktop.
Save lastday154/a63d413a044021d78c7937db0a81a1ec to your computer and use it in GitHub Desktop.
length of linked list
function solution(A) {
const len = A.length;
if (len <= 1) {
return len;
}
let K = 0;
let size = 0;
while (K != -1) {
K = A[K];
console.log("K: ", K);
size++;
}
return size;
// write your code in JavaScript (Node.js 8.9.4)
}
console.log("solution: ", solution([1, 5, -1, 4, 3, 2]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment