Skip to content

Comments

70. Climbing Stairs#21

Merged
yamcodes merged 28 commits intomainfrom
climbing-stairs
Feb 14, 2026
Merged

70. Climbing Stairs#21
yamcodes merged 28 commits intomainfrom
climbing-stairs

Conversation

@yamcodes
Copy link
Owner

@yamcodes yamcodes commented Feb 14, 2026

Summary by CodeRabbit

  • New Features

    • Added multiple solution implementations for the Climbing Stairs problem (recursive, memoized, DP, and space-optimized).
  • Documentation

    • Added a learning guide explaining bottom-up DP and space optimization.
    • Added test-annotation guidance clarifying when to use value vs. method sources.
    • Added a README entry for Climbing Stairs.
  • Tests

    • Added parameterized tests and a shared test-cases provider covering key inputs.

@coderabbitai
Copy link

coderabbitai bot commented Feb 14, 2026

Walkthrough

Adds four climbing-stairs implementations (naive recursive, memoized, DP array, space-optimized iterative), supporting NOTES and README documentation updates, and parameterized JUnit tests with a shared TestCases provider.

Changes

Cohort / File(s) Summary
Documentation & Guidance
CLAUDE.md, README.md, src/main/java/codes/yam/leetcode/climbingstairs/NOTES.md
Adds guidance contrasting @ValueSource vs @MethodSource, clarifies single-argument vs distinct-expected-output testing, and introduces a NOTES.md describing converting memoized recursion to bottom-up DP with examples and complexity notes.
Primary Solution Implementations
src/main/java/codes/yam/leetcode/climbingstairs/Solution.java, src/main/java/codes/yam/leetcode/climbingstairs/SolutionDp.java, src/main/java/codes/yam/leetcode/climbingstairs/SolutionMemoized.java, src/main/java/codes/yam/leetcode/climbingstairs/SolutionRecursive.java
Adds four package-private solution classes: Solution (space-optimized iterative; note: class and method changed to package-private), SolutionDp (DP array), SolutionMemoized (top-down with memo), and SolutionRecursive (naive recursion).
Tests & Test Helper
src/test/java/codes/yam/leetcode/climbingstairs/SolutionTest.java, src/test/java/codes/yam/leetcode/climbingstairs/SolutionDpTest.java, src/test/java/codes/yam/leetcode/climbingstairs/SolutionMemoizedTest.java, src/test/java/codes/yam/leetcode/climbingstairs/SolutionRecursiveTest.java, src/test/java/codes/yam/leetcode/climbingstairs/TestCases.java
Adds parameterized JUnit 5 tests for each solution using @MethodSource with a shared TestCases.cases() Stream containing (2,2) and (3,3).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through notes and tests today,
Recursive trails and DP play.
Memoized crumbs and rolling two,
I counted steps — one, two, then through.
Tests cheer: the stairs climb true! 🥕

🚥 Pre-merge checks | ✅ 3 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title '70. Climbing Stairs' directly and clearly identifies the main change: adding a complete solution for LeetCode problem 70 (Climbing Stairs), including multiple implementations, tests, and documentation.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch climbing-stairs

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
src/main/java/codes/yam/leetcode/climbingstairs/Solution.java (1)

17-25: Nit: redundant initialization of c.

c is assigned a + b on line 19 but immediately overwritten on the first loop iteration (line 21). Consider initializing to 0 to avoid confusion.

Suggested tweak
     int a = 1;
     int b = 2;
-    int c = a + b;
+    int c = 0;
     for (int i = 3; i <= n; i++) {

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@yamcodes yamcodes marked this pull request as ready for review February 14, 2026 18:42
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
README.md (1)

9-13: ⚠️ Potential issue | 🟡 Minor

Problem 70 (Climbing Stairs) is missing from the Solutions table.

The PR adds a full implementation with multiple solution variants but doesn't update the table.

Proposed addition
 | 9    | [Palindrome Number](https://leetcode.com/problems/palindrome-number/)                                                 | Easy       | `O(log10(n) / 2)` | `O(1)` |
+| 70   | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs/)                                                     | Easy       | `O(n)`             | `O(1)` |
 | 1653 | [Minimum Deletions to Make String Balanced](https://leetcode.com/problems/minimum-deletions-to-make-string-balanced/) | Medium     | `O(n)`            | `O(1)` |
🤖 Fix all issues with AI agents
In `@src/main/java/codes/yam/leetcode/climbingstairs/Solution.java`:
- Line 3: The Solution class is declared public but should be package-scoped and
follow the project prefix naming; remove the public modifier from the class
declaration for class Solution so it has default (package-private) visibility,
and if your repository uses a specific prefix convention for solution classes
(e.g., Cls* or Leet*), rename Solution to the approved prefixed name (update any
references/tests accordingly) while keeping the class body and behavior
unchanged.
- Around line 3-16: Add an HTML-formatted Javadoc block above the Solution class
documenting algorithmic complexity and behavior for climbStairs: state that
climbStairs(int n) runs in O(n) time and uses O(1) space, include a short
description of the method and the complexity lines in HTML (e.g., <p> and <b> or
<pre> tags) to match existing solution classes, and ensure the Javadoc mentions
the input parameter and return value (n: number of steps, returns number of
distinct ways). Reference the class name Solution and method climbStairs when
inserting the Javadoc.

In `@src/main/java/codes/yam/leetcode/climbingstairs/SolutionDp.java`:
- Around line 12-21: The climbStairs method can throw
ArrayIndexOutOfBoundsException for n == 1 because dp[2] is written
unconditionally; fix it by handling small n up-front (e.g., add an early guard
in climbStairs: if (n <= 2) return n) so the dp array is only indexed for valid
positions, or alternatively ensure dp is allocated with size at least 3 and only
write dp[2] when n >= 2; update the dp allocation/initialization in the
climbStairs method accordingly.
🧹 Nitpick comments (2)
src/main/java/codes/yam/leetcode/climbingstairs/Solution.java (1)

7-9: Redundant initialization of c on line 9.

c is assigned a + b here but immediately overwritten on the first loop iteration (line 11). Initialize to 0 or just declare without assignment.

Proposed fix
     int a = 1;
     int b = 2;
-    int c = a + b;
+    int c = 0;
     for (int i = 3; i <= n; i++) {
src/test/java/codes/yam/leetcode/climbingstairs/TestCases.java (1)

8-10: Add more test cases, especially n = 1.

Only two cases are provided. Adding n = 1 would have caught the ArrayIndexOutOfBoundsException in SolutionDp. Consider also adding a larger value (e.g., n = 5 → 8) for better coverage of the recurrence.

Proposed enhancement
   static Stream<Arguments> cases() {
-    return Stream.of(Arguments.of(2, 2), Arguments.of(3, 3));
+    return Stream.of(
+        Arguments.of(1, 1),
+        Arguments.of(2, 2),
+        Arguments.of(3, 3),
+        Arguments.of(5, 8)
+    );
   }

@yamcodes yamcodes merged commit da39f0f into main Feb 14, 2026
2 checks passed
@yamcodes yamcodes deleted the climbing-stairs branch February 14, 2026 18:50
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.

1 participant