func minNumber(_ nums: [Int]) -> String {
var queue = SwiftPriorityQueue<Int>.init(hasHigherPriority: {
return hasHigher(x: $0, compare: $1)
}, isEqual: {
$0 == $1
})
var result: String = ""
nums.forEach {
queue.enqueue($0)
}
while let value = queue.dequeue() {
result.append("\(value)")
}
return result
}
func hasHigher(x: Int, compare y: Int) -> Bool {
let aArr = [Character](String(x))
let bArr = [Character](String(y))
let resultA = Int(String(aArr + bArr)) ?? 0
let resultB = Int(String(bArr + aArr)) ?? 0
return resultA <= resultB
}
func minNumber(_ nums: [Int]) -> String {
let queue = nums.sorted { return hasHigher(x: $0, compare: $1) }
var result: String = ""
queue.forEach {
result.append("\($0)")
}
return result
}
func hasHigher(x: Int, compare y: Int) -> Bool {
let aArr = [Character](String(x))
let bArr = [Character](String(y))
let resultA = Int(String(aArr + bArr)) ?? 0
let resultB = Int(String(bArr + aArr)) ?? 0
return resultA <= resultB
}