Skip to content

LeetCode-150: Evaluate Reverse Polish Notation#144

Merged
WazedKhan merged 1 commit into
mainfrom
leetcode-150
Jul 15, 2026
Merged

LeetCode-150: Evaluate Reverse Polish Notation#144
WazedKhan merged 1 commit into
mainfrom
leetcode-150

Conversation

@WazedKhan

@WazedKhan WazedKhan commented Jul 15, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Added support for evaluating Reverse Polish Notation expressions using addition, subtraction, multiplication, and division.
    • Division results truncate toward zero, returning an integer result.
  • Tests

    • Added coverage for multiple expression scenarios, including division behavior.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds Solution.evalRPN to evaluate Reverse Polish Notation with a stack and operator mapping, plus parametrized tests covering arithmetic expressions and division truncation toward zero.

Changes

RPN evaluator

Layer / File(s) Summary
Stack-based evaluator
LeetCode/medium/evalRPN_150.py
Solution.evalRPN processes operands with a stack, applies mapped arithmetic operators, and returns the final integer result.
Parameterized evaluator tests
tests/test_leetcode_medium.py
Adds multiple RPN test cases, including division truncation toward zero.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately names the LeetCode 150 RPN evaluation change and matches the implemented solution and tests.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch leetcode-150

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
LeetCode/medium/evalRPN_150.py (1)

10-22: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Implement the suggested refactor to maintain a uniform stack.

As mentioned in your note, converting tokens to int before appending them to the stack simplifies the logic. This ensures that the stack contains only integers, avoiding a mix of types (str, int, float) and eliminating the need for repetitive conversions during operations.

♻️ Proposed refactor
         for token in tokens:
             if token in ops:
                 num_1 = stack.pop()
                 num_2 = stack.pop()
-                operation = ops[token]
-                res = operation(int(num_2), int(num_1))
-                stack.append(res)
+                # truediv returns a float, so cast to int to truncate toward zero
+                stack.append(int(ops[token](num_2, num_1)))
             else:
-                stack.append(token)
+                stack.append(int(token))
 
-        return int(stack[0])
-        # NOTE: we could append token as int() then we wouldn't need to convert it before return or operation
+        return stack[0]
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@LeetCode/medium/evalRPN_150.py` around lines 10 - 22, Update the
token-handling loop in evalRPN so non-operator tokens are converted to integers
before being pushed onto stack. Remove the int conversions around operands and
the final stack result, while preserving the existing operation order and
returned value.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@LeetCode/medium/evalRPN_150.py`:
- Around line 10-22: Update the token-handling loop in evalRPN so non-operator
tokens are converted to integers before being pushed onto stack. Remove the int
conversions around operands and the final stack result, while preserving the
existing operation order and returned value.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: caa6eb5a-1443-413a-b896-9ee55bae7225

📥 Commits

Reviewing files that changed from the base of the PR and between 8add45b and c5789c9.

📒 Files selected for processing (2)
  • LeetCode/medium/evalRPN_150.py
  • tests/test_leetcode_medium.py

@WazedKhan
WazedKhan merged commit a14d504 into main Jul 15, 2026
3 checks passed
@WazedKhan
WazedKhan deleted the leetcode-150 branch July 15, 2026 04:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant