Skip to content

Instantly share code, notes, and snippets.

@letusfly85
Last active August 29, 2015 14:02
Show Gist options
  • Save letusfly85/7e435e66515121a97d0c to your computer and use it in GitHub Desktop.
Save letusfly85/7e435e66515121a97d0c to your computer and use it in GitHub Desktop.
import scala.collection.mutable.HashMap
object CheckUnique {
def main (args: Array[String]) {
val str = "abc"
val res = checkUnique(str)
println(str + "->" + res.toString)
val str2 = "aab"
val res2 = checkUnique(str2)
println(str2 + "->" + res2.toString)
}
def checkUnique(str: String): Boolean = {
val uMap: HashMap[Char, Boolean] = new HashMap()
str.map(_.toChar).foreach {c =>
uMap.get(c) match {
case Some(true) => return false
case Some(false) => return false
case None => uMap.put(c, true)
}
}
return true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment