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
/** | |
* Определяет все ли символы в строке | |
* встречаются по одному разу. | |
* | |
* @param {string} str | |
* @returns {boolean} | |
*/ | |
function isUniqueChars(str) { | |
// Строка из набора символов ASCII, | |
// поэтому максимальная длина строки 128 |
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
/** | |
* Определяет все ли символы в строке | |
* встречаются по одному разу. | |
* Подходит только для алфавита с количеством | |
* символов не более 32. В данном случае, a-z в нижнем регистре. | |
* | |
* @param {string} str | |
* @returns {boolean} | |
*/ | |
function isUniqueChars(str) { |
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
/** | |
* Определяет является ли одна строка перестановкой другой. | |
* | |
* @param {string} a | |
* @param {string} b | |
* @returns {boolean} | |
*/ | |
function isPermutation(a, b) { | |
return a.split('').sort().join('') === b.split('').sort().join(''); | |
} |
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
/** | |
* Определяет является ли одна строка перестановкой другой. | |
* Используются счетчики символов. Сложность O(n). | |
* | |
* @param {string} a | |
* @param {string} b | |
* @returns {boolean} | |
*/ | |
function isPermutation(a, b) { | |
// ASCII |
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
/** | |
* Заменяет пробелы на %20. | |
* Выполняет замену «на месте». | |
* | |
* @param {string} str | |
* @returns {string} | |
*/ | |
function replaceSpaces(str) { | |
str = str.split(''); | |
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
/** | |
* Удаляет дубликаты из связаного списка. | |
* Функция принимает на вход указатель на начало списка. | |
* | |
* @param {Node} head | |
* @returns {Node} | |
*/ | |
function removeNode(head) { | |
// Предполагается, что head объект вида { data: <*>, next: <Node> } | |
const hash = {}; |
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
/** | |
* Удаляет дубликаты из связаного списка. | |
* Не использует дополнительную память. | |
* Функция принимает на вход указатель на начало списка. | |
* | |
* @param {Node} head | |
* @returns {Node} | |
*/ | |
function removeNode(head) { | |
// Предполагается, что head объект вида { data: <*>, next: <Node> } |
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
/** | |
* Возвращает k-й элемент с конца списка. | |
* Принимает ссылку на начало спиcка, номер элемента, | |
* а так же специальный объект-хранилище, который нужен | |
* чтобы вернуть ссылку на нужный элемент списка. | |
* | |
* @example | |
* const store = []; | |
* getKthElementToLast(head, 3, store); | |
* const theThirdElement = store.pop(); |
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
/** | |
* Возвращает k-й элемент с конца списка. | |
* Реализует метод «двух указателей». | |
* | |
* @param {Node} head | |
* @param {Numner} k | |
* @returns {?Node} | |
*/ | |
function getKthElementToLast(head, k) { | |
let p1 = head; |
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
/** | |
* Стек, который реализует метод min, | |
* кроме стандартный push и pop | |
* | |
* @example | |
* const s = new Stack(); | |
* s.push(5); | |
* // 5 | |
* console.log(s.min()); | |
* s.push(6); |