Created
March 4, 2019 04:42
-
-
Save lastday154/a63d413a044021d78c7937db0a81a1ec to your computer and use it in GitHub Desktop.
length of linked list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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