Created
May 21, 2021 21:20
-
-
Save misterpoloy/c890832ac7d3f77593a5d8a0b42e97d9 to your computer and use it in GitHub Desktop.
2 pointers pattern: Count Unique values
This file contains hidden or 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 countUniqueValues(numbers){ | |
// add whatever parameters you deem necessary - good luck! | |
if (!numbers.length) return 0; | |
let left = 0; | |
let right = 1; | |
let counter = 1; | |
while (right < numbers.length) { | |
if (numbers[left] !== numbers[right]) { | |
left = right; | |
counter++; | |
} | |
right++; | |
} | |
return counter; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment