This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sum(1 for obj in s[0:k] if obj in ('a', 'e', 'i', 'o', 'u')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
auto getWords = [&](string &sentence) -> vector<string> { | |
vector<string> ans; | |
istringstream iss(sentence); | |
string word = ""; | |
while (iss >> word) { | |
ans.push_back(word); | |
} | |
return ans; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
auto getWords = [&](string &sentence) -> vector<string> { | |
int n = sentence.size(); | |
vector<string> ans; | |
for (int i = 0; i < n; i++) { | |
string word=""; | |
int j = i; | |
while (j < n && (!isblank(sentence[j]))) { | |
word += sentence[j]; | |
j ++; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
auto less = [](int a, int b){ | |
return a >= b; | |
}; | |
vector<int> array{65,100,29,73,85,1,92,16,95,41,7,33,100,83,40,37,99,9,63,25,62,9,43,55,77,49,62,94,28,82,80,97,55,12,34}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
const int N = 100010; | |
int main(void) { | |
for (int i = 100000;; i++) { | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
preSum = [0] | |
for num in nums: | |
preSum.append(preSum[-1] + num) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
deque<int> train; | |
for (int i = 0; i < n; i++) { | |
// 向右错一位,因为默认和初始值均为1 | |
preSum[i+1] = preSum[i] + nums[i]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vector<vector<int>> reconstructQueue(vector<vector<int>>& people) { | |
// 多值排序,使用匿名函数 [](){} 没有不能访问的变量,形参; 排序规则:身高递增(数组位序0)或者 (身高相等排序人数(数组位序1),递减顺序) | |
sort(people.begin(), people.end(), [](const vector<int>& u, const vector<int>& v) { | |
return u[0] < v[0] || (u[0] == v[0] && u[1] > v[1]); | |
}); | |
int n = people.size(); | |
vector<vector<int>> ans(n); | |
for (const vector<int>& person: people) { | |
int spaces = person[1] + 1; | |
for (int i = 0; i < n; i++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 内联函数,注意原地修改,因此传参均为字符指针,不需要返回值 | |
static inline void swap(char* a, char* b) { | |
char c = *a; | |
*a = *b; | |
*b = c; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 宏定义,相当于匿名函数,因此需要括号包裹,但三元运算符后面的部分,相当于返回值,因此不需要括号包裹 | |
#define MAX(a, b) ((a) > (b) ? a : b) |
NewerOlder