题解 | #查找兄弟单词#
查找兄弟单词
https://www.nowcoder.com/practice/03ba8aeeef73400ca7a37a5f3370fe68
import Foundation func checkStr(_ x: String, _ borStr: String) -> Bool { if x == borStr || x.count != borStr.count{ return false } //字符串变成数组 然后给数组排序 来比较两个数组 如果数组想等 就是bro let currentArr = Array(x) let borArr = Array(borStr) if currentArr.sorted() == borArr.sorted() { return true } return false } while let line = readLine() { let list = line.components(separatedBy: " ") let n = Int(list[0]) let x = list[list.count - 2] let k = Int(list.last!)! var broArr = [String]() for str in list[1...list.count - 3] { if checkStr(x, str) { broArr.append(str) } } print(broArr.count) if(broArr.count >= k) { print(broArr.sorted()[k - 1]) } }