Skip to content

fix: operator precedence for leetcode 227 [basic calculator ii]#11

Open
Gumparthypavankumar wants to merge 2 commits into
AlgoMaster-io:mainfrom
Gumparthypavankumar:main
Open

fix: operator precedence for leetcode 227 [basic calculator ii]#11
Gumparthypavankumar wants to merge 2 commits into
AlgoMaster-io:mainfrom
Gumparthypavankumar:main

Conversation

@Gumparthypavankumar
Copy link
Copy Markdown

@Gumparthypavankumar Gumparthypavankumar commented Jul 27, 2025

  1. What is now different from before?
    A. The implementation now tracks the precedence of - symbols by checking during execution of operation type.
  2. What is the reason for the change?
    A. + and - are left-associative operators with the same precedence, and must be processed in the order they appear.
  3. Anything to watch out for?
    A. N/A

1. What is now different from before?
> The implementation now reverses the numbers and operators stacks before applying + and - operators.This ensures that + and - are evaluated in left-to-right order, which matches the expected behavior of the expression (i.e., left-associative evaluation). Previously, operators were applied in reverse order, leading to incorrect results like 1-1+1 → -1 instead of 1.
2. What is the reason for the change?
> + and - are left-associative operators with the same precedence, and must be processed in the order they appear.
3. Anything to watch out for?
> Space complexity increases slightly due to the temporary numRev and opRev stacks, but remains O(n).
1. What is now different than before?
A. The implementation now tracks the precedence of - symbols by checking during execution of operation type
2. What is the reason for the change?+ and - are left-associative operators with the same precedence, and must be processed in the order they appear.
    3. Anything to watch out for?
    > Space complexity increases slightly due to the temporary numRev and opRev stacks, but remains O(n).
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