随笔分类 - 初级算法
每日一练
摘要:遵循四个原则, 1) 程序执行一个函数时,就创建一个新的受保护的独立空间(新函数栈) 2) 函数的局部变量是独立的,不会相互影响 3) 递归必须向退出递归的条件逼近,否则就是无限递归,死龟了:) 4) 当一个函数执行完毕,或者遇到 return,就会返回,遵守谁调用,就将结果返回给谁。 斐波那契数列
阅读全文
摘要:先知道原理,代码会在后面补充(其实是我还没看懂代码。。。) 二叉树的遍历主要有三种: (1)先(根)序遍历(根左右) (2)中(根)序遍历(左根右) (3)后(根)序遍历(左右根) 相关例子:二叉树的先序、中序、后序遍历序列 题目: 先序 A B D E H I C F K G 中序 D B H E
阅读全文
摘要:不能因为每次做一道算法题就开个随笔,故开个记录贴。坚持就是胜利! IT:https://blog.csdn.net/hackbuteer1/category_9261019.html 初期我不知道该怎么讲解,所以先以代码显示为主。。。。 题库: 每日一题 2021/2/28 单调数列:如果数组是单调
阅读全文
摘要:回文:正过来和反过来的顺序是相同的就是回文。 比如:122221 #include <iostream> class Solution{ public: bool ishuiwen(int val) { if(val<0 || (val != 0) && (val %10 == 0)) { retu
阅读全文
摘要:顾名思义, 就是将链表的所有结点反转。 解释见:【剑指offer】反转链表,C++实现(链表) 代码: #include <iostream> struct NodeList { int data; struct NodeList* next; NodeList() :data(0), next(N
阅读全文
摘要:效率高于冒泡排序和选择排序。 初始数组:{ 27,1,11,200,31,4,58,78,23,47,9,10000}; 第一轮QuickSort的排序见, 27,1,11,200,31,4,58,78,23,47,9,10000 9,1,11,200,31,4,58,78,23,47,27,100
阅读全文
摘要:很著名的一个问题。 简单描述,n个人坐成一圈,然后按k的顺序将人剔除,直到剩下最后一个人。 参考:约瑟夫问题 我的思路就是将n个人标志为0,按k的顺序剔除的人改为标志1。 代码如下: #include <iostream> int main() { int total, n,i = 0,k=0,co
阅读全文
摘要:两种算法一起使用 冒泡算法的时间复杂度是n的平方,二分法是log(m+n) #include <iostream> #include <vector> #include <string> int main() { std::vector<int> nums{ 20,10,324,43,415,2,4
阅读全文
摘要:#include <iostream> #include <vector> #include <string> #include <unordered_set> #define max(a, b) ((a) > (b) ? (a) : (b)) struct ListNode{ int val; L
阅读全文
摘要:/* 桶排序 */ #include <iostream> #include <algorithm> using namespace std; int a, m, n[1000] = { 0 }; int main() { cin >> m; for (int i = 0; i < m; i++)
阅读全文
摘要:#include <iostream> #include <stdio.h> using namespace std; char* Capital_to_Small(char* str) { char* temp = str; int len = strlen(temp); for (int i =
阅读全文
摘要:#include <iostream> #include <string> #include <sstream> #include <fstream> #include <Windows.h> using namespace std; int main() { char str[MAX_PATH];
阅读全文
摘要:#include <iostream> #pragma warning(disable:4996); using namespace std; char* t = (char*)malloc(1024); char* _strcut(char* des, char* src) { memset(t,
阅读全文
摘要:#include <iostream> #include <stdio.h> using namespace std; char *_strcpy(char* des, char* src) { if (des == NULL || src == NULL) { return 0; } // cou
阅读全文

浙公网安备 33010602011771号