Skip to content

98.validate binary search tree#27

Open
nicah4o wants to merge 3 commits into
mainfrom
98.validate-binary-search-tree
Open

98.validate binary search tree#27
nicah4o wants to merge 3 commits into
mainfrom
98.validate-binary-search-tree

Conversation

@nicah4o
Copy link
Copy Markdown
Owner

@nicah4o nicah4o commented Jun 5, 2026

Added explanation and code for validating a binary search tree, including step-by-step reasoning and examples.
public:
bool search_left(TreeNode* node, int max) {
if (!node)
return true;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こちらのコメントをご参照ください。
Shunii85/arai60#17 (comment)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

レビューありがとうございます。
見た目的にもぶら下がりifを選んでしまいがちですが注意します。。

};
```

時間かけると解ける時があるので損切りに時間がかかってしまった。解けることが目的ではないが快楽が大きい。
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

快楽が大きいという認識はとても重要だと思います。快楽を制御できるととても良いのだと思います。

}

private:
bool valid(TreeNode* node, long min, long max) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

valid は形容詞です。形容詞は関数名にはあまり使わないように思います。 validate はいかがでしょうか?

こちらのコメントもご参照ください。
quinn-sasha/leetcode#29 (comment)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます。
解答を写すにしても変数名関数名に気を配るようにします。

nicah4o added 2 commits June 5, 2026 19:01
Added explanations and code examples for validating a binary search tree using BFS, inorder traversal with a stack, and recursion. Included links to related pull requests.
Refactor isValidBST function for better readability and performance. Implemented inorder traversal and improved variable naming.
Comment thread step3
```

ifとwhileのスペースがない他、ぶら下がりif、引数スペースなし。
long型(32byte)はlong long(64byte)にしてもよい。
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ビットとバイトを混同していますかね?intは何バイトでしょうか?

Comment thread step3
return true;
}
private:
void inorder_sort(TreeNode* node, vector<TreeNode*>& nodes) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sortでしょうか?

class Solution {
public:
bool isValidBST(TreeNode* root) {
return valid(root, min, max);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

min, maxはどこから来ましたか?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants