题解 | #提取不重复的整数#
提取不重复的整数
https://www.nowcoder.com/practice/253986e66d114d378ae8de2e6c4577c1
import Foundation while let line = readLine() { var num = Int(line)! var list = [Int]() while num > 0 { let n = num % 10 num = num / 10 if !list.contains(n) { list.append(n) } } var p = list.count - 1 let result = list.reduce(0) { v, t in let temp = Int(v) + Int(Double(t) * pow(Double(10), Double(p))) p -= 1 return temp } print("\(result)") // let parts = line.split(separator: " ") // print(Int(parts[0])! + Int(parts[1])!) }