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> | |
#include <stack> | |
using namespace std; | |
int main() { | |
stack<int> stack; | |
stack.push(21); | |
stack.push(22); | |
stack.push(24); | |
stack.push(25); | |
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
def reverse(char:list, charSize:int) ->None: | |
# 遍历数组的前半部分 | |
for j in range(0, charSize // 2): | |
# 设置中间变量,用于交换; | |
# 将用于交换的部分赋值给中间变量 | |
tmp = char[j] | |
# 将左半边的值赋值为右半边的值 | |
char[j] = char[charSize - j - 1] | |
# 将右半边值赋值为左半边的值 | |
char[charSize - j - 1] = tmp |
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
void reverse(char * str, int strSize) { | |
for (int j = 0; j < strSize / 2; j++) { | |
// 区间二分,对换字符串,只需要交换前 2 / 1 | |
char tmp = str[j]; | |
str[j] = str[strSize - j - 1]; | |
str[strSize - j - 1] = tmp; | |
} | |
} |
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
// 去重 ---> 满足两个条件,不是第一个元素【下标非零】,其次与前一个数不相等 | |
// 注意迭代器申明 | |
vector<int> :: iterator unique(vector<int> &a) { | |
int j = 0; | |
for (int i = 0; i < a.size(); i++) { | |
// 下标的值域为 [0, n] | |
if (!i || a[i] != a[i - 1]) { | |
a[j++] = a[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
def dfs(self,root: TreeNode) -> int: | |
if not root: | |
return 0 | |
cur_level=[root] | |
res = 0 | |
while cur_level: | |
# 为 next数组申请空间 | |
next_level=[] | |
res +=1 | |
for node in cur_level: |
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
def dfs(root: TreeNode) -> int: | |
if not root: | |
return 0 | |
return 1 + max(dfs(root.left), dfs(root.right)) |
NewerOlder