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
| const stringHasUniqueChars = (str) => { | |
| for(let i=0;i<str.length; i++) { | |
| for(let j=i+1;j<str.length; j++) { | |
| if(str[i] === str[j]) | |
| return false; | |
| } | |
| } | |
| return true; | |
| } |
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
| const stringHasUniqueChars = (str) => { | |
| str.split('').sort().join(''); | |
| for(let i=0;i<str.length; i++) { | |
| if(str[i] === str[i+1]) { | |
| return false; | |
| } | |
| } | |
| return true; | |
| } |
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
| const stringHasUniqueChars = (str) => { | |
| let count = {}; | |
| for(let i=0; i<str.length; i++) { | |
| count[str[i]] = count[str[i]] === undefined ? 1: count[str[i]]+1; | |
| if(count[str[i]] > 1) | |
| return false; | |
| } | |
| return true; | |
| } |
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
| const stringHasUniqueChars = (str) => { | |
| let checker = 0; //integer used to represent 32-bit operator | |
| for (let i = 0; i < str.length; i++) { | |
| let bitAtIndex = str[i] - 'a'; | |
| if ((checker & (1 << bitAtIndex)) > 0) { | |
| return false; | |
| } | |
| checker = checker | (1<<bitAtIndex); | |
| } | |
| return true; |
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
| const isPermutation = (s1, s2) => { | |
| if(s1.length != s2.length) return false; | |
| return s1.split('').sort().join('') === s2.split('').sort().join(''); | |
| } | |
| let a = isPermutation("paypalishiring", "palpayhiringis"); // true | |
| let b = isPermutation("paypalishiring", "hiringpalsipay"); // true | |
| let c = isPermutation("paypalishiring", "palpayhirising"); // true | |
| let d = isPermutation("paypalishiring", "palpayhiringgg"); // false | |
| console.log(a + ', ' + b + ', ' + c + ', ' + d); |
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
| const isPermutation = (s1, s2) => { | |
| if(s1.length != s2.length) return false; | |
| let count = {}; | |
| for(let i=0; i < s1.length; i++) { | |
| count[s1[i]] = count[s1[i]] === undefined ? 1: count[s1[i]] + 1; | |
| count[s2[i]] = count[s2[i]] === 0 ? 0 : count[s2[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
| const isPermutation = (s1, s2) => { | |
| if(s1.length != s2.length) return false; | |
| let count = new Map(); | |
| for (let i = 0; i < s1.length; ++i) { | |
| count.set(s1[i], count.get(s1[i]) + 1 || 1); | |
| } | |
| for(let j = 0; j < s2.length; ++j) { | |
| let num = count.get(s2[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
| const createUrl = (s1) => { | |
| return s1.split(' ').join('%20'); | |
| } | |
| let url = 'javascript algorithms' | |
| console.log(createUrl(url)); |
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
| const createUrl = (s1) => { | |
| let s1Array = s1.split(' '); | |
| let len = s1Array.length - 1; | |
| if(s1Array[len] === '') { | |
| s1Array.pop(); | |
| s1 = s1Array.join(' '); | |
| return createUrl(s1); | |
| } | |
| return s1Array.join('%20'); | |
| } |
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
| const isPalindrome = (s1) => { | |
| let charMap = new Map(); | |
| for(let i=0; i <s1.length; i++){ | |
| if(charMap.get(s1[i])) { | |
| charMap.delete(s1[i]); | |
| } else { | |
| charMap.set(s1[i], 1); | |
| } | |
| } | |
| if(s1.length%2 === 0 && charMap.size === 0 || |