Created
November 17, 2018 06:36
-
-
Save MacTanomsup/fb0095f5c67c5545678ba9e23cbaecd0 to your computer and use it in GitHub Desktop.
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(sortedValue){ | |
| if(sortedValue.length === 0) { | |
| return 0; | |
| } | |
| var left = 0; | |
| var right = 1; | |
| while(right < sortedValue.length) { | |
| if(sortedValue[left] === sortedValue[right]) { | |
| right++; | |
| } else if(sortedValue[left] !== sortedValue[right]) { | |
| if(right - left > 1) { | |
| sortedValue[++left] = sortedValue[right]; | |
| } else { | |
| left++; | |
| right++; | |
| } | |
| } | |
| } | |
| return left + 1; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment