Lowest Common Ancestor of a Binary Search Tree#29
Merged
Conversation
thonda28
reviewed
Sep 3, 2024
thonda28
left a comment
There was a problem hiding this comment.
よいと思いました。
この問題に対してというわけではないですが、Golang だとインデントがスペース4つ分のことが多いのかなと思いました。スペース8つ分にしているのは何か意図があったりしますか?
Owner
Author
単にGitHub上の表示の問題な気がします。僕の場合はタブを使ってインデントしています。 |
返信ありがとうございます。ChatGPT に聞いてみたところ、たしかに GitHub のデフォルト設定ではタブがスペース8つ分に変換されて表示されるとのことでした。エディタの設定などでタブを自動でスペース4つ分に置き換えることができるみたいなので、僕が Golang を書いていたときには知らず知らずに置き換わっていてこの現象に出くわさなかったのかもです。 |
oda
reviewed
Sep 6, 2024
rihib
added a commit
that referenced
this pull request
Mar 31, 2025
…search_tree Lowest Common Ancestor of a Binary Search Tree
rihib
added a commit
that referenced
this pull request
Mar 31, 2025
…search_tree Lowest Common Ancestor of a Binary Search Tree
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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が返ることを期待する書き方をしてしまうと思わぬところで無限ループになる可能性があるのでそもそもこういう書き方自体すべきではない。