百战尚学tang 大厂算法特训班
func addPath(_ res: inout [Int], _ node: inout TreeNode?) {
var count: Int = 0
while (nil != node) {
count += 1
res.append(node!.val)
node = node?.right
}
var leftCount = res.count - count
var rightCount = res.count - 1
while (leftCount < rightCount) {
let temp: Int = res[leftCount]
res[leftCount] = res[rightCount]
res[rightCount] = temp
leftCount += 1
rightCount -= 1
}
}