2301-2310¶
2311-2320¶
class Solution {
public:
int countAsterisks(string s) {
int cnt = 0;
bool valid = true;
for (auto &it: s) {
if (it == '|') valid = !valid;
else if (it == '*' && valid) cnt += 1;
}
return cnt;
}
};
class Solution {
public:
bool checkXMatrix(vector<vector<int>>& grid) {
int len=grid.size();
for(int i=0;i<len;++i){
for(int j=0;j<len;++j){
if(i==j||len-j-1==i){
if(!grid[i][j]) return false;
}else{
if(grid[i][j]) return false;
}
}
}
return true;
}
};
2321-2330¶
class Solution {
public:
string decodeMessage(string key, string message) {
char map[26];
memset(map, 0, sizeof map);
stringstream res;
int index = 0;
for (int i = 0; i < key.length(); ++i) {
if (key[i] != ' ' && map[key[i] - 'a'] == 0) {
map[key[i] - 'a'] = 'a' + index++;
}
}
for (char &it: message) {
if (it == ' ') res.put(' ');
else res.put(map[it - 'a']);
}
return res.str();
}
};
2331-2340¶
class Solution {
public:
bool evaluateTree(TreeNode *root) {
if (root->val == 2) return evaluateTree(root->left) || evaluateTree(root->right);
if (root->val == 3) return evaluateTree(root->left) && evaluateTree(root->right);
return root->val;
}
};
2341-2350¶
2351-2360¶
class Solution {
public:
int minimumOperations(vector<int>& nums) {
unordered_map<int,bool> heap;
for(auto &it:nums) if(it) heap[it]=true;
return heap.size();
}
};