leetcode(1)

268:

int an = nums.size();
return (an + an*an) / 2 - accumulate(nums.begin(), nums.end(), 0);

389:

int len = s.size();
int res = 0, i;
        
for (i = 0; i < len; ++i)
    res ^= s[i]^t[i];

res ^= t[i];
return res;

771:

unordered_set<char> s;
int cnt = 0;

for_each(J.begin(), J.end(), [&](const char& ch) {
    s.insert(ch);
});

for_each(S.begin(), S.end(), [&](const char& ch) {
    cnt += s.count(ch);
});
return cnt;

657:

int lr = 0, ud = 0;

for (auto& ch : moves) {
    if (ch == 'R') --lr;
    else if (ch == 'L') ++lr;
    else if (ch == 'U') ++ud;
    else if (ch == 'D') --ud;
}

return !lr && !ud;

344:

reverse(s.begin(), s.end());
return s;

292:

return n % 4;

104:

return root ? max(maxDepth(root->left), maxDepth(root->right)) + 1 : 0;

1:

unordered_map<int, int> maps;
int len = nums.size();

for (int i = 0; i < len; ++i) {
    if (maps.find(nums[i]) != maps.end()) return {maps.at(nums[i]), i};
    else maps.insert({target - nums[i], i});
}

237:

swap(node->val, node->next->val);
node->next = node->next->next;

58:

s.erase(0, s.find_first_not_of(' '));  
s.erase(s.find_last_not_of(' ') + 1); 
return s.substr(s.rfind(' ')+1).size();

猜你喜欢

转载自my.oschina.net/u/3655970/blog/1789852