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 Node(data) { | |
| this.data = data; | |
| this.next = null; | |
| } | |
| function sortedInsert(head, data) { | |
| let currentNode = head; | |
| let prevNode = head; | |
| const target = new Node(data); | |
| // insert in begining; |
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 ListNode(val) { | |
| * this.val = val; | |
| * this.next = null; | |
| * } | |
| */ | |
| var mergeTwoLists = function(l1, l2) { | |
| const dummy = new ListNode(0); | |
| let current = dummy; |
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
| var isAnagram = function(s, t) { | |
| if (s === t ) return true; | |
| if (s.length !== t.length) return false; | |
| const map = s.split("").reduce((obj,n) => { | |
| obj[n] = !obj[n] ? 1 : obj[n] + 1; | |
| return obj; | |
| },{}); | |
| for(let letter of t){ |
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 indexOf (string, sub) { | |
| if(string === sub || !sub) return 0; | |
| if(!string ) return -1; | |
| let res = -1; | |
| let k = 0; | |
| for(let i = 0 ; i < string.length; i++){ | |
| if(string.charAt(i) === sub.charAt(k)){ | |
| k++; |
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
| // ключевой принцип | |
| // prefix иницилизирован как первое слово | |
| // сравнение символов из prefix с символами каждого слова слова | |
| // если символ не совпадает - перезаписываем префикс и продолжаем | |
| function longestCommonPrefix(strs) { | |
| if(!strs || strs.length === 0 ) return ""; | |
| let prefix = strs[0]; | |
| for(let j = 1; j < strs.length; j++){ |
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 removeDuplicates(nums){ | |
| return nums.reduce((acc, n) => { | |
| if(acc.indexOf(n) === -1) { | |
| acc.push(n) | |
| } | |
| return acc; |
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 isBalanced(s) { | |
| const temp = { | |
| "[": "]", | |
| "(": ")", | |
| "{": "}" | |
| }; | |
| const stack = []; | |
| let closed; |
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
| Array.prototype.isSorted = function () { | |
| if(this.length < 2) return false; | |
| let dir = this[0] < this[1] ? 1 : -1; | |
| for(let i = 1; i < this.length-1; i++) { | |
| if(dir === 1 && this[i] > this[i+1]) { | |
| return false; | |
| } | |
| if(dir === -1 && this[i] < this[i+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
| function getRandomInt(min, max) { | |
| return Math.floor(Math.random() * (max - min)) + min; | |
| } |
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 debounce(func,delay = 200){ | |
| let timer = null; | |
| return function(...args){ | |
| if(timer){ | |
| clearTimeout(timer); | |
| } | |
| timer = setTimeout(() => { | |
| func.apply(null,args) |
NewerOlder