/** * 时间复杂度O(n*k*logk) */ defgroupAnagrams(strs: Array[String]): List[List[String]] = { val map = new mutable.HashMap[List[Char], ListBuffer[String]]()
strs.foreach(a => { val key = a.toCharArray.toList.sortWith((a, b) => if (a > b) trueelsefalse) if (!map.contains(key)) { map.put(key, ListBuffer(a)) } else { map.get(key).get += a } })