The code is from https://leetcode.com/
How does opened++ > 0
work in the if statement below?
I'm new to Java and have never seen using increment and >
in the same conditional statement.
public String removeOuterParentheses(String S) {
StringBuilder s = new StringBuilder();
int opened = 0;
for (char c : S.toCharArray()) {
if (c == '(' && opened++ > 0) s.append(c);
if (c == ')' && opened-- > 1) s.append(c);
}
return s.toString();
}