Repository navigation
Add unit tests for the "Kth Smallest Element in a BST" problem. - #32
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the KthSmallestElementInABST230 solution by migrating it from a loose file structure to a proper Maven-style project layout with separate source and test directories.
- Moved the solution from
src/KthSmallestElementInaBST230.javato the proper package structure atsrc/main/java/com/leetcode/medium/KthSmallestElementInABST230.java - Created a dedicated JUnit test class
KthSmallestElementInABST230Test.javareplacing the main method testing approach - Updated imports to use the packaged
TreeNodeclass fromcom.leetcode.datastructure
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/main/java/com/leetcode/medium/KthSmallestElementInABST230.java | Refactored solution with proper package structure, updated imports, removed explicit this references, and renamed variable from res to values |
| src/test/java/com/leetcode/medium/KthSmallestElementInABST230Test.java | New JUnit test file with two test cases covering the examples, replacing manual main method testing |
| src/KthSmallestElementInaBST230.java | Deleted old file from incorrect location |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return values.get(k - 1); | ||
| } |
There was a problem hiding this comment.
The method lacks validation for the parameter k. If k is less than 1 or greater than the number of nodes in the tree, this will throw an IndexOutOfBoundsException. Consider adding validation to check that k is within the valid range (1 <= k <= tree size) and throw a more meaningful exception (e.g., IllegalArgumentException) with a descriptive error message.
| return values.get(k - 1); | |
| } | |
| if (k < 1 || k > values.size()) { | |
| throw new IllegalArgumentException("Parameter k is out of bounds. Valid range: 1 <= k <= " + values.size() + ", but got k = " + k); | |
| } | |
| return values.get(k - 1); |
No description provided.