谁能帮我解决这个sequece.I已经尝试了多次,但没有得到解决。一些解决方案如下
1
11
21
1211
11121
但我需要以下解决方案。I want to print this sequece in console. Can anyone help me out with this sequece.
1
11
21
1211
3112
132112
311322
var last = [1, 3, 2, 1, 1, 2]
var next = [Int]()
func getNext() {
if last.count == 0 { return }
let first = last.first!
let firstCount = last.filter{ $0 == first }.count
next.append(firstCount)
next.append(first)
last.removeAll { $0 == first }
getNext()
}
getNext()
print(next)//[3, 1, 1, 3, 2, 2]