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 groupAnagrams(strs: string[]): string[][] { | |
const wordTracker: Map<string, string[]> = new Map(); | |
for (let i = 0; i < strs.length; i++) { | |
const sorted = strs[i].split('').sort().join(''); | |
if (wordTracker.has(sorted)) { | |
wordTracker.get(sorted).push(strs[i]); | |
} else { | |
wordTracker.set(sorted, [strs[i]]); | |
} | |
} |
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 twoSum(nums: number[], target: number): number[] { | |
const numTracker: Map<number, number> = new Map(); | |
for (let i = 0; i < nums.length; i++) { | |
const balance = target - nums[i]; | |
if (numTracker.has(balance)) { | |
return [numTracker.get(balance), i]; | |
} | |
numTracker.set(nums[i], i) | |
} |
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} s | |
* @param {string} t | |
* @return {boolean} | |
*/ | |
var isAnagram = function(s, t) { | |
const first_length = s.length; | |
const second_length = t.length; | |
if (first_length !== second_length) { |
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 {number[]} nums | |
* @return {boolean} | |
*/ | |
var containsDuplicate = function(nums) { | |
const numsSet = new Set(); | |
for (num of nums) { | |
if (numsSet.has(num)) { | |
return true; |