`class Solution {
public:
string postToInfix(string exp) {
// Write your code here
stack<string>st;
for(int i=0;i<exp.length();i++){
if(!isalpha(exp[i])){
string A=st.top(); st.pop();
string B=st.top(); st.pop();
string s="(" + B + exp[i] + A + ")";
st.push(s);
}
else st.push(string(1,exp[i]));
}
return st.top();
}
};`
- The problem is from geeks of geeks.I am getting time limit exceeded.What can I do to optimize it? problem link
New contributor
Shreya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.