Created
June 8, 2014 05:44
-
-
Save letusfly85/7db6a24ce8314a7c520f 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
object CheckSame { | |
def main(args: Array[String]) { | |
println(checkSame("abca", "bcaa")) | |
println(checkSame("abc", "bcaa")) | |
} | |
/** | |
* check the sameness of each words by sort | |
* refs: http://www.ne.jp/asahi/hishidama/home/tech/scala/sample/sort.html#h_scala | |
* | |
*/ | |
def checkSame(str1: String, str2: String): Boolean = { | |
val sorted1 = str1.map(_.toChar).sortWith(_ < _) | |
val sorted2 = str2.map(_.toChar).sortWith(_ < _) | |
return (sorted1 == sorted2) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment