cswork / OA打开练习工作台

Valkyrie TradingOA #2

BST Path Distance Between Two Values

估计中等评测数据准备中,可先阅读题面

考点(AI 标注)二叉搜索树

Construct a binary search tree from a list of integers in the order given (no balancing, no duplicates). Then return the distance (number of edges) between two nodes with given values. If either value is missing, return -1.

Examples:

  • strArr = ["1","2","3","4"], u = 4, v = 2 → 2
  • strArr = ["1","2","3","4"], u = 4, v = 0 → -1
  • [8,7,13,6,2,5,1,9,11,3,4,10], u = 4, v = 2 → 3