techqueria / data-structures-and-algorithms

Let's go over data structures and algorithms together. We will use Cracking the Coding Interview as reference
113 stars 94 forks source link

Another O(N) solution using an Object #77

Closed Ada-11 closed 3 years ago

Ada-11 commented 3 years ago

Another solution without additional data structures but using objects, with performance O(N).

function isUnique3(str){ let obj = {} for( let elem of str){ if(obj.hasOwnProperty(elem)) obj[elem]++ else obj[elem]=1 } for( key in obj){ if (obj[key]=== 1) return true else return false } }

isUnique3('ada') // false isUnique3("golden") // true

lhchavez commented 3 years ago

dupe of #78