Leetcode 99:recovery Binary Search tree finally understand the algorithm, write the code clearly, so that the error is nowhere to hide.

Source: Internet
Author: User

Want to write something, because this spent maths me for a few hours, in Sunday, in addition to running on the field for two hours, it is on the problem.

Read blogs:

http://www.lifeincode.net/programming/leetcode-recover-binary-search-tree-java/
Http://www.cnblogs.com/AnnieKim/archive/2013/06/15/MorrisTraversal.html

C # implementations:


Did not understand the algorithm, wrote a C # version, from reading code, see what does not understand the place.
Https://github.com/jianminchen/Leetcode_C-/blob/master/99RecoverBinarySearchTree.cs

Simple recursive version, however, finding two violations is not in place.
Https://github.com/jianminchen/Leetcode_C-/blob/master/99RecoverBinarySearchTreeB.cs

Finally understand, start to write a few small functions, see can remember, easy maintenance, test case is not very clear. more satisfactory code. Look at the notes, and after a few months, hopefully you can recall the algorithm in a few minutes.
Work on extracting small functions, and then, understand the algorithm better.
Https://github.com/jianminchen/Leetcode_C-/blob/master/99RecoveryBinarySearchTree_C.cs

Leetcode 99:recovery Binary Search tree finally understand the algorithm, write the code clearly, so that the error is nowhere to hide.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.