class Solution {
public:
string largestOddNumber(string num) {
// Traverse the string from the end
for (int i = num.size() - 1; i >= 0; --i) {
// If the current character is an odd digit
if ((num[i] - '0') % 2 != 0) {
// Return the substring from the start to the current position
return num.substr(0, i + 1);
}
}
// If no odd digit is found, return an empty string
return "";
}
};
class Solution {
public:
string removeOuterParentheses(string s) {
string result;
stack<char> stack;
int start = 0; // Start index of a primitive block
int n = s.size();
for(int i = 0; i <n; i++){
if(s[i] == '(') {
stack.push('(');
}else{
stack.pop();
}
// When the stack is empty, we found a complete primitive block
if(stack.empty()){
// Append all except the outermost parentheses
result += s.substr(start + 1, i - start - 1);
start = i + 1; // Update the start for the next primitive block
}
}
return result;
}
};