Last active
August 29, 2015 14:02
-
-
Save letusfly85/7e435e66515121a97d0c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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