Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another O(N) solution using an Object #77

Closed
wants to merge 1 commit into from

Conversation

Ada-11
Copy link

@Ada-11 Ada-11 commented Oct 30, 2020

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

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
Copy link
Contributor

dupe of #78

@lhchavez lhchavez closed this Oct 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants