LeetCode--两句话中的不常见单词(scala实现)

it2025-09-07  7

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实现的话:两个串拼一个找出现一次的即可
最新回复(0)