摘要: 621. 任务调度器 class Solution: def leastInterval(self, tasks: List[str], n: int) -> int: # 1. 假设任务间隔为n,最短完成任务时间就是任务总数 # 2.1 假设只有一种taskA,那么可以将A分成k组,每组间隔为n, 阅读全文
posted @ 2022-11-25 09:24 7aughing 阅读(77) 评论(0) 推荐(0) 编辑
摘要: 分割回文串 https://leetcode.cn/problems/palindrome-partitioning/ class Solution: def dfs(self, s, idx, path): """ idx:当前处理到的第idx个字符 """ if idx == len(s): s 阅读全文
posted @ 2022-11-24 09:33 7aughing 阅读(16) 评论(0) 推荐(0) 编辑
摘要: C++11常用特性的使用经验总结 std::unordered_map与std::map用法基本差不多,std::map使用的数据结构为二叉树,而std::unordered_map内部是哈希表的实现方式; // std::unordered_map与std::map用法基本差不多,但STL在内部实 阅读全文
posted @ 2022-11-18 01:37 7aughing 阅读(15) 评论(0) 推荐(0) 编辑
摘要: 洗牌算法 点评:上面即为洗牌算法的思想,其本质是对数组元素进行随机重排。数组中每个元素经过洗牌算法后落在数组某个位置上的概率是相等的,洗牌算法在牌类游戏中非常有用。我们最终将算法的时间复杂度优化到了O(n),空间复杂度优化到了O(1)。 java代码实现: import java.util.Rand 阅读全文
posted @ 2022-11-18 00:30 7aughing 阅读(52) 评论(0) 推荐(0) 编辑
摘要: vector<vector<int>> vec; // 定义行列未知的二维数组 vector<vector<int>> array(5); //定义行为5的二维数组 vector< vector<int> > asd1(row, vector<int>(column, 0)); //初始化row*c 阅读全文
posted @ 2022-11-16 23:32 7aughing 阅读(87) 评论(0) 推荐(0) 编辑
摘要: 注意空指针 指针的三种写法: int *p; int * p; int* p; 堆和栈 栈: local variable 函数调用 变量的生命周期由scope决定 堆 在运行时分配内存 变量的生命周期由开发者决定,与scope无关 new/delete 如何操作堆上的数据 C++delete一个指 阅读全文
posted @ 2022-11-16 00:44 7aughing 阅读(75) 评论(0) 推荐(0) 编辑
摘要: C++ 11 Lambda表达式 C++11中的匿名函数(lambda函数,lambda表达式) https://gitlab.com/yzzy/modern-cpp/-/blob/main/c16_lambda/main.cpp [](int x, int y) { return x + y; } 阅读全文
posted @ 2022-11-15 23:15 7aughing 阅读(39) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2022-11-15 14:29 7aughing 阅读(5) 评论(0) 推荐(0) 编辑
摘要: // sizeof求数组长度 int arr1[]{1, 2, 3, 4}; int arrsize{sizeof(arr1)/ sizeof(arr1[0])}; 阅读全文
posted @ 2022-11-15 14:16 7aughing 阅读(11) 评论(0) 推荐(0) 编辑
摘要: https://segmentfault.com/a/1190000039844285 int i = 0; int i = {0}; int i{0}; int i(0); 阅读全文
posted @ 2022-11-15 13:43 7aughing 阅读(10) 评论(0) 推荐(0) 编辑