/**
Description
* Implements an algorithm that determines whether all characters of a string are all different.
* What if you do not allow the use of additional data structures?
* Details: 1) Unicode character set or ASCII character set
* 2) If the ASCII encoding, the length is greater than 256, the direct return false
*/
functionno_multiple_str (str) {if(Str.length > 256)return false; varTMP = {}; for(vari=0; i<str.length; i++){ var Char=Str.charat (i); if(tmp[Char]) { return false; } Else{tmp[Char] =Char; } } return true; } varstr = "Rept"; Console.log (' No multiple char--and ' + NO_MULTIPLE_STR (str). toString ());
/**
* Use bit arithmetic to reduce space complexity
*/
functionno_multiple_str_2 (str) {if(Str.length > 256)return false; varChecker = 0; for(vari=0; i<str.length; i++){ varValue = Str.charcodeat (i)-' a '. charCodeAt (); Console.log (Checker& (1 <<value)); if((Checker & (1 << value)) > 0) { return false; } Checker|= (1 <<value); } return true;}varstr = "Repte"; Console.log (' No multiple char--and ' + no_multiple_str_2 (str). toString ());
/**
* The most basic method
* Cycle Comparison
*/
functionno_multiple_str_3 (str) {if(Str.length > 256)return false; for(vari=0; i<str.length-1; i++){ for(varj=i+1; j<str.length; J + +) { if(Str.charat (i) = =Str.charat (j)) { return false; } } } return true;} varstr = "Rept"; Console.log (' No multiple char--and ' + no_multiple_str_3 (str). toString ());
javascript--Interview--algorithm--string-1