- 博客(24)
- 资源 (2)
- 问答 (1)
- 收藏
- 关注
原创 promotion for 35 years coder-Day23-kmp算法
#include <iostream>#include <string.h>using namespace std;void getNext(char *pattern, int len, int* next){ int i = 0; int j = -1; next[0] = -1; while(i < len) { if (j == -1 || pattern[i] == pattern[j])...
2021-09-29 21:45:59 135
原创 promotion for 35 years coder-Day22-省份数量
#include <iostream>#include <queue>using namespace std;int connection1[4][4] = {{1,0,1,1},{0,1,0,0},{1,0,1,1},{1,0,1,1}};int connection2[4][4] = {{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}};//深度优先void dfs(int array[4][4], int *flag, int po
2021-09-12 07:56:47 114
原创 promotion for 35 years coder-Day21-morris中序遍历
#include <iostream>#include <queue>using namespace std;typedef struct treeNode_t{ int val; struct treeNode_t *plchild; struct treeNode_t *prchild; treeNode_t(int v, struct treeNode_t *pl, struct treeNode_t *pr) {...
2021-08-24 17:15:52 119
原创 promotion for 35 years coder-Day20-二叉树层序遍历
#include <iostream>#include <vector>#include <queue>using namespace std;typedef struct treeNode_t{ int value; struct treeNode_t *plchild; struct treeNode_t *prchild; treeNode_t(int v, struct treeNode_t *pl, stru...
2021-08-15 22:42:08 104
原创 promotion for 35 years coder-Day19-二叉树后续遍历
#include <iostream>#include <stack>using namespace std;typedef struct treeNode_t{ int value; struct treeNode_t *plchild; struct treeNode_t *prchild; treeNode_t(int v, struct treeNode_t *pl, struct treeNode_t *pr) {...
2021-08-14 21:40:40 135
原创 promotion for 35 years coder-Day18-二叉树中序遍历
#include <iostream>#include <stack>using namespace std;typedef struct treeNode_t{ int value; struct treeNode_t *plchild; struct treeNode_t *prchild; treeNode_t(int v, struct treeNode_t *pl, struct treeNode_t *pr) {...
2021-08-14 21:13:28 91
原创 promotion for 35 years coder-Day17-二叉树前序遍历
#include <iostream>#include <stack>using namespace std;typedef struct treeNode_t{ int value; struct treeNode_t *plchild; struct treeNode_t *prchild; treeNode_t(int v, struct treeNode_t *pl, struct treeNode_t *pr) {...
2021-08-14 07:49:56 137
原创 promotion for 35 years coder-Day16-有序数组求最大升序子序列长度
#include <iostream>using namespace std;int orderLen(int *array, int len){ int start = 0; int max = 0; for (int i = 1; i < len; i++) { if (array[i] < array[i - 1]) { int tmplen = i - start; ...
2021-08-08 21:31:07 80
原创 promotion for 35 years coder-Day15-广度优先求二叉树最小深度
#include <iostream>#include <queue>using namespace std;typedef struct treeNode_t{ int deep; struct treeNode_t *plchild; struct treeNode_t *prchild; treeNode_t(struct treeNode_t *pl, struct treeNode_t *pr) { ...
2021-08-07 16:28:43 75
原创 promotion for 35 years coder-Day14-深度优先求二叉树最小深度
#include <iostream>using namespace std;typedef struct treeNode_t{ struct treeNode_t *plchild; struct treeNode_t *prchild; treeNode_t(struct treeNode_t *pl, struct treeNode_t *pr) { plchild = pl; prchild = pr;...
2021-08-07 16:01:09 82
原创 promotion for 35 years coder-Day13-滑动窗口求子数组最大均值
#include <iostream>using namespace std;double maxSubArraySum(int *array, int len, int sublen){ if (len < sublen) { return -1.0; } int sum = 0; for (int i = 0; i < sublen; i++) { sum += array[i];...
2021-08-07 10:40:48 78
原创 promotion for 35 years coder-Day12-合并有序数组
#include <iostream>#include <string.h>using namespace std;//base:array1d的实际空间长度等于两个数组长度之和//空间复杂度O(n),即归并排序void merge1(int *array1, int len1, int *array2, int len2){ int *arrayTmp = new int[len1]; memcpy(arrayTmp, array1, len1 * ...
2021-08-06 21:57:40 128
原创 promotion for 35 years coder-Day11-链表判定是否有环
#include <iostream>#include <set>using namespace std;struct T_LstNode;typedef struct T_LstNode{ int value; T_LstNode *pNext; T_LstNode(int v, T_LstNode *next) { value = v; pNext = next; }}Node;//快...
2021-08-05 07:11:11 82
原创 promotion for 35 years coder-Day10-两种方法求斐波拉契数列
#include <iostream>#include <string.h>using namespace std;//迭代法,时间复杂度O(n),空间复杂度O(1)int iterator_Fibonacci(int n){ if (n < 2) return n; int lo = 0; int hi = 1; int sum = 0; for (int i = 2; i < n ...
2021-08-02 20:03:03 136
原创 promotion for 35 years coder-Day09-双指针求有序数组两数之和
#include <iostream>using namespace std;int result[2] = {0};void twoSum(int *pArray, int len, int target){ result[0] = -1; result[1] = -1; int lo = 0; int hi = len - 1; while(lo < hi) { int sum = pArray[lo]...
2021-08-02 09:41:48 85
原创 promotion for 35 years coder-Day08-利用hash求无序数组两数之和
#include <iostream>#include <map>using namespace std;int result[2] = {0};void gettarget(int *pArray, int len, int target){ result[0] = result[1] = -1; map<int, int> tag; for (int i = 0; i < len; i++) { ...
2021-08-01 22:36:09 88
原创 promotion for 35 years coder-Day07-求无序数组三元素乘积最大值
思路:当把元素排序后,分为三种情况(1)元素全正:最大三个元素相乘即可(2)元素全负:最大三个元素相乘即可(3)有正有负:必须保证最后乘积为正才可能最大,最大值只可能有两种情况最大三个数相乘,负数最小两个数相乘再和最大的数相乘综上,结果就是max(min1*min2*max1, max1*max2*max3)所以无需排序,只需遍历一遍找到上述5个值即可#include <iostream>using namespace std;int getMax(int
2021-07-31 22:26:30 180
原创 promotion for 35 years coder-Day06-牛顿法求平方根的整数部分
#include <iostream>#include <math.h>using namespace std;int newton(double factor, int dest){ if (factor < 0 || dest < 0) { return -1; } if (dest == 0 || dest == 1) { return dest; } doubl...
2021-07-30 17:32:17 73
原创 promotion for 35 years coder-Day05-二分法求平方根整数部分
#include <iostream>#include <math.h>using namespace std;int findSqrt(int t){ if (t <= 0) { return -1; } if (t == 1) { return 1; } int index = -1; int lo = 2; int hi = t - 1; w...
2021-07-30 11:12:03 88
原创 promotion for 35 years coder-Day04-求数组中两边和相等的位置
#include <iostream>using namespace std;int find_balance(int* array, int len){ int sum = 0; for (int i = 0; i < len; i++) { sum += array[i]; } int partSum = 0; for (int i = 0; i < len; i++) { if ...
2021-07-28 09:10:51 82
原创 promotion for 35 years coder-Day03-去除排序数组重复数据,返回去重后数组长度,空间复杂度O(1)
include <iostream>using namespace std;int subject1[] = {1,2,2,2,3,3,4,4,4,4,5,7,9}; //result is 7int subject2[] = {1,1,3,4,5,5,5,5,7,10,10,12,20,20}; //result is 8int ArrayTrip(int *subject, int len){ if (NULL == subject) { ret...
2021-07-26 21:31:57 102
原创 promotion for 35 years coder-Day02-素数
#include <iostream>#include <string.h>using namespace std;bool isPrime(int n){ for (int i = 2; i * i <= n; i++) { if (n % i == 0) { return false; } } return true;}int countPrim...
2021-07-25 21:50:12 72
原创 promotion for 35 years coder-Day01-链表反转
#include <iostream>#include <string>struct T_LstNode;typedef struct T_LstNode{ int value; T_LstNode *pNext; T_LstNode(int v, T_LstNode *next) { value = v; pNext = next; }}LstNode;//递归方式LstNode *li...
2021-07-22 13:52:17 76
请教关于ffmpeg解码rtp码流的问题
2015-01-05
TA创建的收藏夹 TA关注的收藏夹
TA关注的人