def uncommonFromSentences
(A
: String, B
: String): Array
[String] = {
(A
.split
(" ") ++ B
.split
(" ")).map
(x
=> (x
, 1)).groupBy
(t
=> t
._1
).filter
(x
=> x
._2
.size
==1).keys
.toArray
}
val astr
= "this apple is sweet"
val bstr
= "this apple is sour"
println
(uncommonFromSentences
(astr
, bstr
).toBuffer
)
java或python实现的话:两个串拼一个找出现一次的即可
转载请注明原文地址: https://lol.8miu.com/read-29190.html