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
| n = 3 | |
| # 外层控制层数,生成几行;内层控制每行中的数字,外层作为因子控制每次相加的n的倍数 | |
| matrix = [[s + n * k for s in range(1, n+1)] for k in range(0, n)] | |
| print(matrix) | |
| # version 2 | |
| m, n = 7, 4 | |
| matrix = [[k * n + 1 * s for s in range(1, n)] for k in range(0, m)] |
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; | |
| } |
NewerOlder