LeetCode
String
class Solution {
public:
int finalValueAfterOperations(vector<string>& operations) {
int num = 0;
for(string i : operations){
if(i[1] == '+')
num++;
else
num--;
}
return num;
}
};
class Solution {
public:
int mostWordsFound(vector<string>& sentences) {
vector<int>v;
for(string str : sentences){
int count = 0;
for(int i = 0; i < str.size(); i++){
if(str[i] == ' '){
count++;
}
}
v.push_back(count);
}
sort(v.begin(), v.end());
return v.back() + 1;;
}
};
class Solution
{
public:
int minPartitions(string n)
{
return *max_element(n.begin(), n.end()) - '0';
}
};
class Solution {
public:
vector<string> cellsInRange(string s) {
vector<string> ans;
for (char a = s[0]; a <= s[3]; a++) {
for (char b = s[1]; b <= s[4]; b++) {
string tmp = {a, b};
ans.push_back(tmp);
}
}
return ans;
}
};
class Solution {
public:
vector<string> res;
vector<string> generateParenthesis(int n) {
backtrack(n,0,"");
return res;
}
void backtrack(int left,int right,string path){
if(!left&&!right){res.push_back(path);return;}
if(left)backtrack(left-1,right+1,path+'(');
if(right)backtrack(left,right-1,path+')');
}
};
class Solution {
public:
int numJewelsInStones(string jewels, string stones) {
int count = 0;
for(int i = 0; i < jewels.size(); i++){
for(int j = 0; j < stones.size(); j++){
if(jewels[i] == stones[j]){
count++;
}
}
}
return count;
}
};
class Solution {
public:
int maxDepth(string s) {
int ans = 0, size = 0;
for (char ch : s) {
if (ch == '(') {
++size;
ans = max(ans, size);
} else if (ch == ')') {
--size;
}
}
return ans;
}
};