mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-23 09:42:28 +08:00
build
This commit is contained in:
@ -638,7 +638,7 @@ comments: true
|
||||
func levelOrder() -> [Int] {
|
||||
var res: [Int] = []
|
||||
// 直接遍历数组
|
||||
for i in stride(from: 0, to: size(), by: 1) {
|
||||
for i in 0 ..< size() {
|
||||
if let val = val(i: i) {
|
||||
res.append(val)
|
||||
}
|
||||
|
@ -311,7 +311,7 @@ AVL 树既是二叉搜索树,也是平衡二叉树,同时满足这两类二
|
||||
/* 获取节点高度 */
|
||||
func height(node: TreeNode?) -> Int {
|
||||
// 空节点高度为 -1 ,叶节点高度为 0
|
||||
node == nil ? -1 : node!.height
|
||||
node?.height ?? -1
|
||||
}
|
||||
|
||||
/* 更新节点高度 */
|
||||
@ -2142,7 +2142,7 @@ AVL 树的节点插入操作与二叉搜索树在主体上类似。唯一的区
|
||||
node?.right = removeHelper(node: node?.right, val: val)
|
||||
} else {
|
||||
if node?.left == nil || node?.right == nil {
|
||||
let child = node?.left != nil ? node?.left : node?.right
|
||||
let child = node?.left ?? node?.right
|
||||
// 子节点数量 = 0 ,直接删除 node 并返回
|
||||
if child == nil {
|
||||
return nil
|
||||
|
@ -1106,7 +1106,7 @@ comments: true
|
||||
// 子节点数量 = 0 or 1
|
||||
if cur?.left == nil || cur?.right == nil {
|
||||
// 当子节点数量 = 0 / 1 时, child = null / 该子节点
|
||||
let child = cur?.left != nil ? cur?.left : cur?.right
|
||||
let child = cur?.left ?? cur?.right
|
||||
// 删除节点 cur
|
||||
if cur !== root {
|
||||
if pre?.left === cur {
|
||||
|
Reference in New Issue
Block a user