Friday, July 27, 2018

Leetcode 671: Second minimum node in a binary tree

July 27, 2018

Introduction


It is an easy level binary tree algorithm. I spent 22 minutes and then fixed the bugs a few time and passed online judge.

My practice


Here is my C# code.

Highlights of bug fix:

1. Line 48, if current value is smaller than the smallest one, then current is the smallest, previous smallest one should be second smallest one. I forgot the previous smallest one should be replaced existing one.

2. Line 50, duplicate value with smallest one; the value should not be counted toward second smallest one.

Follow up


August 29, 2018  10:40 PM

I gave the algorithm to the mock interviewee on interviewing.io, and also I had chance to review other solutions.

I like to share my solution on Leetcode discuss first. And also I like to write another solution based on given constraint, the root node is smallest one if there are two children.

No comments:

Post a Comment