Skip to content

Commit fb3e2f8

Browse files
authored
Update 1896.Minimum-Cost-to-Change-the-Final-Value-of-Expression.cpp
1 parent 8031e3d commit fb3e2f8

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

Stack/1896.Minimum-Cost-to-Change-the-Final-Value-of-Expression/1896.Minimum-Cost-to-Change-the-Final-Value-of-Expression.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ class Solution {
2727
else if (a.first + b.first == 1)
2828
return 1;
2929
else
30-
return min(a.second, b.second)+1;
31-
30+
return min(a.second, b.second)+1;
3231
}
3332
else
3433
{
@@ -47,10 +46,7 @@ class Solution {
4746
stack<char>s2;
4847
pair<int,int> cur = {-1, -1};
4948
char op = '#';
50-
51-
int ret = 0;
52-
expression = "(" + expression + ")";
53-
49+
5450
for (auto ch:expression)
5551
{
5652
if (ch=='&'||ch=='|')
@@ -61,7 +57,6 @@ class Solution {
6157
int val = evalVal(op, cur, nxt);
6258
int flip = evalFlip(op, cur, nxt);
6359
cur = {val, flip};
64-
ret = flip;
6560
}
6661
else if (ch=='(')
6762
{
@@ -80,11 +75,10 @@ class Solution {
8075
int val = evalVal(op, last, cur);
8176
int flip = evalFlip(op, last, cur);
8277
cur = {val, flip};
83-
ret = flip;
8478
}
8579
}
8680

87-
return ret;
81+
return cur.second;
8882
}
8983
};
9084

0 commit comments

Comments
 (0)