Lowest Common Ancestor of a Binary Search Tree #29
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Lowest Common Ancestor of a Binary Search Treeを解きました。レビューをお願い致します。
問題:https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/
言語:Go
すでに解いている方々:
colorbox/leetcode#12
NobukiFukui/Grind75-ProgrammingTraining#22
thonda28/leetcode#12
今回のエラー処理について:
#29
無限ループの危険性
今回の場合は
Val
がint型なので問題ないが、float型だとすると値としてNaN
が入る可能性があり、その場合はNaN
はどの値と比較しても(Nan != n
以外は)常にfalse
になるので、この書き方だと無限ループになってしまう。必ずどこかしらで
true
が返ることを期待する書き方をしてしまうと思わぬところで無限ループになる可能性があるのでそもそもこういう書き方自体すべきではない。