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 buy_and_sell = (values:number[]):number => { | |
let maxProfit = 0; | |
let minPrice = Number.MAX_SAFE_INTEGER; | |
for(let val of values){ | |
if(val<minPrice) { | |
minPrice = val; | |
}else if(val - minPrice > maxProfit){ | |
maxProfit = val - minPrice; | |
} | |
} |
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
/* Int64 hash (String s) { | |
Int64 h = 7 | |
String letters = "acdegilmnoprstuw" | |
for(Int32 i = 0; i < s.length; i++) { | |
h = (h * 37 + letters.indexOf(s[i])) | |
} | |
return h | |
} */ | |
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
/** | |
* Given a string, we want to remove 2 adjacent characters that are the same, and repeat the process with the new string until we can no longer perform the operation. | |
* | |
* @param base the original string | |
* | |
* @returns the `cleansed` string | |
*/ | |
const remove_adjacent_dup = (base:string): string => { | |
const adjacentDupRegex = new RegExp(/(\w)\1/g); | |
while(adjacentDupRegex.test(base)){ |
OlderNewer