A
描述:
给定一个二叉树,返回其节点值的锯齿形层次遍历。(即先从左往右,再从右往左进行下一层遍历,以此类推,层与层之间交替进行)。
分析:
仍旧可以基于 102. 二叉树的层序遍历 的遍历逻辑,在遍历完1层后判断是否要对当前层的遍历结果取反即可。
R
Swift: Comparing Objects the Right Way With Equatable
在 Swift 中判断两个对象相等时,使用 == 进行对比时,比较的是引用而不是值。使用 === 进行对比时,会验证对比两边的对象是否是同一个类型,不是时在编译时就会报错。
let x : Int = 3
let y : Int8 = 3
print(x == y) // <---- true
print(x === y) // <---- won't compile
如果需要实现通过对比对象里属性的值来判断相等,则可以通过 Equatable Protocol 来实现。
import UIKit
class Car : Equatable {
var horsePower : Int
var plate : String
init(power: Int, id: String) {
horsePower = power
plate = id
}
static func == (lhs: Car, rhs: Car) -> Bool {
return lhs.plate == rhs.plate
}
}
let a = Car(power: 200, id: "AX993JE")
let b = Car(power: 147, id: "AX993JE")
print(a == b) // <---- true
T
inline fun Animator.addListener(
crossinline onEnd: (animator: Animator) -> Unit = {},
crossinline onStart: (animator: Animator) -> Unit = {},
crossinline onCancel: (animator: Animator) -> Unit = {},
crossinline onRepeat: (animator: Animator) -> Unit = {}
): AnimatorListener
androidx.core.animation 里的新增方法,可以简化对动画状态的监听逻辑。