題目是
{
"dog",
"google",
"facebook",
"internationalization",
"blabla"
}
中, 最長的單詞集合為 ["internationalization"]
在詞典
{
"like",
"love",
"hate",
"yes"
}
中,最長的單詞集合為 ["like", "love", "hate"]
scala略入門的寫法
val sort_array = List("dog",
"google",
"facebook",
"internationalization",
"blabla").sortWith(_.length<_.length)
sort_array.filter(_.length == sort_array.last.length).foreach(println)
List("dog",
"google",
"facebook",
"internationalization",
"blabla").map(str=>(str,str.length)).maxBy(_._2)._1