From 40e9431ca751d24bc519e10ff001c0e26818dee0 Mon Sep 17 00:00:00 2001 From: Ada-11 <52932540+Ada-11@users.noreply.github.com> Date: Fri, 30 Oct 2020 11:32:56 -0500 Subject: [PATCH] Another O(N) solution using an Object 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 --- JavaScript/chapter01/p01_is_unique/avc278.js | 1 + 1 file changed, 1 insertion(+) diff --git a/JavaScript/chapter01/p01_is_unique/avc278.js b/JavaScript/chapter01/p01_is_unique/avc278.js index a49d9ceb..1db0ca33 100644 --- a/JavaScript/chapter01/p01_is_unique/avc278.js +++ b/JavaScript/chapter01/p01_is_unique/avc278.js @@ -1,3 +1,4 @@ + // Is Unique: Implement an algorithm to determine if a string has all unique characters. // What if you cannot used additional data structures?