Last active
February 25, 2017 13:02
-
-
Save vitkarpov/cdaa756f5406922f1431576812e4f044 to your computer and use it in GitHub Desktop.
"Cracking the coding interview", strings 1.1
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
/** | |
* Определяет все ли символы в строке | |
* встречаются по одному разу. | |
* | |
* @param {string} str | |
* @returns {boolean} | |
*/ | |
function isUniqueChars(str) { | |
// Строка из набора символов ASCII, | |
// поэтому максимальная длина строки 128 | |
const set = new Array(128); | |
if (str.length > 128) { | |
return false; | |
} | |
for (let i = 0; i < str.length; i++) { | |
const code = str.charCodeAt(i); | |
if (set[code]) { | |
return false; | |
} | |
set[code] = true; | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment