STRINGS
STRINGS
public:
string removeOuterParentheses(string s) {
int n=s.length();
string res;
int balance=0;
for(int i=0;i<n;i++){
if(s[i]=='('){
if(balance>0){
res+=s[i];
balance++;
}else{
balance--;
if(balance>0){
res+=s[i];
return res;
};
string res="";
for(int j=words.size()-1;j>=0;j--){
res+=s.substr(words[j].first,words[j].second-
words[j].first+1);
if(j!=0){
res+=' ';
return res;
};
class Solution {
public:
string reverseWords(string s) {
int n=s.length();
vector<pair<int,int>>words;
int i=0;
while(i<n){
if(i==n) break;
int start=i;
i++;
int end=i-1;
words.push_back({start,end});
}
class Solution {
public:
int n=num.length();
for(int i=n-1;i>=0;i--){
if(num[i]%2!=0){
return num.substr(0,i+1);
return "";
};
14)
class Solution {
public:
string longestCommonPrefix(vector<string>&
strs) {
sort(strs.begin(),strs.end());
string s1=strs[0];
int n=strs.size()-1;
string s2=strs[n];
int count=0;
for(int i=0;i<min(s1.length(),s2.length());i+
+){
if(s1[i]==s2[i]){
count++;
}else{
break;
return s1.substr(0,count);
}};
class Solution {
if(s.length()!=t.length()){ if(s.length()!=goal.length()){
} } // s.substr(1) is a function call on the string s that returns a substring of s, starting from
index 1 and continuing to the end of the string.
int n=s.length();
for(int i=0;i<n;i++){
vector<char>indexs(200,0);
string rotated=s.substr(1)+s[0];
vector<char>indext(200,0);
if(rotated==goal){
for(int i=0;i<n;i++){
return true;
if(indexs[s[i]]!=indext[t[i]]){
}
return false;
s=rotated;
}else{
}
indexs[s[i]]=i+1;
return false;
indext[t[i]]=i+1;
}
}
}
};
return true;
};
class Solution { class Solution {
public: public:
vector<int>sf(26,0); unordered_map<char,int>mp;
int n=s.length(); }
sf[s[i]-'a']++; if(mp[a]==mp[b]){
}else{
} return mp[a]>mp[b];
for(int i=0;i<26;i++){ }
if(sf[i]!=tf[i]){ });
return false;
} return s;
return true; }
} };
};
class Solution { class Solution {
public: public:
m[s[i]]++;
} for(auto i:s){
m[i]++;
vector<pair<int, char>> v; }
} p.push({i.second,i.first});
while(n--){
string result = "";
ans+=p.top().second;
for (auto it : v) {
}
p.pop();
for (int i = 0; i < it.first; i++) {
}
result += it.second;
return ans;
}
}
}
};
return result;
};
class Solution {
public:
int maxDepth(string s) {
int m=0,ans=0;
for(int i=0;i<s.length();i++){
char c=s[i];
if(c=='('){
class Solution {
st.push(c);
public:
ans++;
int maxDepth(string s) {
}
int maxi=0;
//cout<<ans;
int c=0;
char top=st.top();
int n=s.length();
if(c==')' && top=='('){
for(int i=0;i<n;i++){
st.pop();
if(s[i]=='('){
c++;
m=max(ans,m);
maxi=max(c,maxi);
ans--;
}
}else if(s[i]==')'){
}
c--;
return m;
}else{
}
continue;
};
}
return maxi;
};
class Solution {
public:
int romanToInt(string s) {
unordered_map<char, int> m;
m['I'] = 1;
m['V'] = 5;
m['X'] = 10;
m['L'] = 50;
m['C'] = 100;
m['D'] = 500;
m['M'] = 1000;
int ans = 0;
ans -= m[s[i]];
else{
ans += m[s[i]];
return ans;
};
neg=true;
continue; }
if(c=='+'){
continue;}
if(c=='0'){
continue;}
if(!isdigit(c)){
return 0;}}
if(isdigit(c)){
res+=c;
continue; }
break; }
if(res == ""){
return 0;}
if
catch (...){
return INT_MIN;
class Solution { }}
public:
continue;
read=true; }
if(c=='-'){ };
}
private:
left--;
right++;
class Solution {
}
public:
// Return the length of the palindrome
string longestPalindrome(string s) { found
int n = s.size(); return right - left - 1;
int start = 0, maxLen = 0; }
};
for (int i = 0; i < n; i++) {
maxLen = len;
start = i - (len - 1) / 2;
public: public:
for(auto it:mp){ }
int end=i-1;
mostfreq=max(mostfreq,it.second); words.push_back({start,end});
leastfreq=min(leastfreq,it.second); }
string res="";
} for(int j=words.size()-1;j>=0;j--){
sum+=mostfreq-leastfreq;
res+=s.substr(words[j].first,words[j].second-
words[j].first+1);
}} return sum;}};
if(j!=0){
res+=' ';
approach 2:
permutations of a string