2022-9-14

53 阅读1分钟

算法

  1. 利用后续遍历,先处理左右子节点
  2. 判断条件就是左右子节点为空,当前节点值为target

ts

Push

// ============= Test Cases =============
import type { Equal, Expect } from './test-utils'

type cases = [
  Expect<Equal<Push<[], 1>, [1]>>,
  Expect<Equal<Push<[1, 2], '3'>, [1, 2, '3']>>,
  Expect<Equal<Push<['1', 2, '3'], boolean>, ['1', 2, '3', boolean]>>,
]


// ============= Your Code Here =============
type Push<T extends any[], U> = [...T, U]