Блог пользователя lol4lol

Автор lol4lol, история, 5 лет назад, По-английски

It can be solve by storing node value in an array and then calculating the minimum difference by native approach. But i was trying to solve it using DFS. I have tried to see discussion of many solver who tried DFS but not getting out the actually how it has been solved by DFS. Can anyone help me by figure(skecth by nodes) out the way DFS would work to solve this problem? Thanks in Advance.

One of Discussions: https://leetcode.com/problems/minimum-distance-between-bst-nodes/discuss/856052/My-Java-SOlution-DFS/705372 Problem Link: https://leetcode.com/problems/minimum-distance-between-bst-nodes/

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
5 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

For each vertice $$$v$$$ in the tree, calculate the absolute difference between the value of $$$v$$$ and the values of $$$v$$$'s predecessor and successor. Predecessor of $$$v$$$ is the vertice with the largest value smaller than the value of $$$v$$$ and successor of $$$v$$$ is the vertice with the least value larger than the value of $$$v$$$.