算法
kotomi_du
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
红黑树与平衡二叉树
红黑树和平衡二叉树区别如下:1、红黑树放弃了追求完全平衡,追求大致平衡,在与平衡二叉树的时间复杂度相差不大的情况下,保证每次插入最多只需要三次旋转就能达到平衡,实现起来也更为简单。2、平衡二叉树追求绝对平衡,条件比较苛刻,实现起来比较麻烦,每次插入新节点之后需要旋转的次数不能预知。平衡二叉树介绍:https://blog.youkuaiyun.com/lpp0900320123/article/det...原创 2018-09-07 09:44:52 · 3202 阅读 · 0 评论 -
手写 queue 和dequeue
参考链接 https://blog.youkuaiyun.com/foreyes_1001/article/details/52215243原创 2018-08-14 23:02:35 · 1270 阅读 · 0 评论 -
几种排序算法的比较
https://www.cnblogs.com/lizr-ithouse/p/5839384.html转载 2018-08-12 16:14:01 · 153 阅读 · 0 评论 -
leetcode 二叉树 两个结点的最短距离
参考链接 https://www.cnblogs.com/wxdjss/p/5698071.html原创 2018-08-15 08:55:03 · 4944 阅读 · 1 评论 -
leetcode record list
题目:Given a singly linked list L: L 0→L 1→…→L n-1→L n,reorder it to: L 0→L n →L 1→L n-1→L 2→L n-2→…You must do this in-place without altering the nodes' values.For example,Given{1,2,3,4}, reord...原创 2018-08-20 10:42:50 · 263 阅读 · 0 评论 -
leetcode binary-tree-maximum-path-sum
key:1.递归,每次返回当前节点作为父节点到任意子节点之间的最大距离。2.最大距离的评判标准:max(res,sum),其中 sum表示当前节点作为父节点时,任意子节点之间的距离和。 int res; int maxPathSum(TreeNode *root) { if(!root) return 0; res = INT_MIN;...原创 2018-08-23 08:55:12 · 136 阅读 · 0 评论 -
字符串反转或转数字相关操作
https://www.jianshu.com/p/bc96329df0f7key:指针的使用 char * pstr;原创 2018-08-23 14:24:17 · 207 阅读 · 0 评论 -
leetcode 重建二叉树
key:1. 递归的返回条件:ps > pe;2. 左右子树的索引更新:其中index是根据前序遍历在中序遍历中找到的值preorder: (ps+1, ps+index-is); (ps+index-is+1, pe)inorder: (is, index-1); (index+1, ie) class Solution {public: Tree...原创 2018-08-24 11:43:53 · 568 阅读 · 0 评论 -
位运算小结
n >>=1 : n = n/2 n&1==1 : n%2 == 1 n = n&(n-1) 可以将n二进制中最右边1后面的数都变为0 如n =6,则 n = 110 & 101 = 100 求n的二进制位(反向 ) while(n){ cout<< n&1 ; n >> =1;}//n=6 (11...原创 2018-08-31 16:05:03 · 174 阅读 · 0 评论 -
leetcode 反转链表
key:1. 定义三个指针,cur;newhead;cur的前一个结点 pre2.判断最后一个结点,直接赋值给newhead*** 如果是双向链表,就是多了一步往前的指针处理**** 如果是将二叉搜索树转换成有序的双向链表,也是一样的:中序遍历 + 根节点处的指针转换;同时要注意对于参数pre,要用*&解释:指针是一个存放地址的变量,而指针引用指的是这个变量的引用,...原创 2018-08-24 22:21:59 · 303 阅读 · 0 评论 -
深度学习 反向传播的过程
参见链接https://www.cnblogs.com/charlotte77/p/5629865.htmlkey:1.链式求导2.更新当前层的w 和 b 是对求导;而反向传播的delta 是对该层的输入求导。原创 2018-08-24 22:30:53 · 569 阅读 · 0 评论 -
perpetual loss的定义和作用
https://www.jianshu.com/p/58fd418fcabf原创 2018-09-04 18:01:41 · 715 阅读 · 0 评论 -
关于走格子的问题
dfs: 所有可能的路径,是否存在某一条路径bfs: 遍历图,最短路径深度优先搜索利用了栈进行计算,而宽度优先搜索则利用了队列进行计算1.简单版:从(0,0)走到(n,m),只能往下或往右走,最短的路径。(这里最短路径的意思就是只会走m+n个空格)注意这里的矩阵大小是(m+1)*(n+1)多少种走法:C(m+n,n),或者用动态规划的方式求解。记录路径:用dfstyped...原创 2018-09-16 12:18:05 · 1502 阅读 · 0 评论 -
编程题 字符串A在字符串B中出现的次数
腾讯笔试题之一,过了70%,超时。输入:整数k, 字符串a,字符串b输出:字符串a中k个字符在b出现的次数。int main(){ int k; string a; string b; set<string> tempset; while(cin >>k >> a >> b){ i...原创 2018-09-16 17:23:15 · 6372 阅读 · 0 评论 -
leetcode z形遍历二叉树
key: use two stack s1,s2 /** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NU...原创 2018-08-14 22:49:59 · 889 阅读 · 0 评论 -
网格索引 和四叉树索引
参考链接:https://blog.youkuaiyun.com/zhshulin/article/details/19031177问题:在一个平面层上面,给出一个矩形,找出这个矩形里的所有点。暴力法:遍历所有点,判断是否在矩形里面 网格索引:划分网格,对于每个网格元素,作为集合对象,记录包含在这个网格里面的所有图元的信息(地址或引用)。缺点:如果索引一条线的时候,一条线的引用在多个网格中都被记录...原创 2018-09-07 11:35:05 · 2717 阅读 · 0 评论 -
单链表的操作
带头结点的链表操作:参考链接:https://www.cnblogs.com/KGvito/p/8111047.html注意插入操作中,有两步 ptemp->next = p->next; p->next = ptemp; ...原创 2018-09-07 12:01:27 · 160 阅读 · 0 评论 -
PCA与LDA的异同
PCA和LDA虽然都用到数据降维的思想。监督方式不一样,PCA是无监督的,LDA是有监督的。 目的也不一样。PCA是为了去除原始数据集中冗余的维度,让投影子空间的各个维度的方差尽可能大,也就是熵尽可能大。LDA(线性判别式分析)关注的是标注,希望投影之后不同类别的数据点距离尽量大,相同类别的数据点距离尽量紧凑。...原创 2018-09-07 14:52:38 · 2596 阅读 · 1 评论 -
四则运算
1.构造后缀表达式利用stack,存储操作符;自定义一个数据结构,存放val 和 op; 入栈的操作符优先级要高于栈顶的操作符。如果当前op优先级低,则需要把栈顶的op先出栈,再入栈 有可能输入的字符大于9, 则需要判断:从字符串中找出数字的计算方法 https://blog.youkuaiyun.com/liqiutuoyuan/article/details/728544712.利用后...原创 2018-09-13 18:14:43 · 762 阅读 · 0 评论 -
leetcode :Sort Colors
https://leetcode.com/problems/sort-colors/description/问题: 0,1,2组成的数组,在in-place的空间复杂度条件下进行排序思路:利用划分的思想,以一个数字作为anchor,每划分一次,确定这个anchor的顺序。void sortColors(vector<int>& nums) { /...原创 2018-09-19 08:24:21 · 181 阅读 · 0 评论 -
leetcode Insertion Sort List
问题: 对链表进行排序思路1:链表是顺序存储的,通过简单插入排序法。记录以下指针:当前指针;当前指针的下一个指针;链表的第一个指针(通过头结点实现):沿着头结点找到插入的前一个位置和后一个位置。 ListNode* insertionSortList(ListNode* head) { //链表的插入方式是 直接断开原来的链接 ListNode* du...原创 2018-09-19 09:07:54 · 259 阅读 · 0 评论 -
利用数组计算大数的阶乘/幂/加
计算m! 注意这里的m可以>10,同样适用下面的规则。temp 当前index所在值与乘数相乘的结果digit 当前的最高位数next 进位#define MAX_SIZE 100000int num[MAX_SIZE];int main(){ int m; cin>>m; //temp digit next num[0]...原创 2018-09-24 23:15:04 · 508 阅读 · 0 评论 -
最长子序列
// 最长子序列int main(){ string a; string b; cin>>a>>b; string::size_type alen = a.size(); string::size_type blen = b.size(); int f[alen+1][blen+1]; for(int i ...原创 2018-10-02 09:02:34 · 379 阅读 · 0 评论 -
leetcode 快慢指针的使用
使用方式(head是头指针) if(head == nullptr) return head; Node* slow = head->next; Node* fast = head->next; while(fast && fast->next){ slow = slow->next...原创 2018-09-20 22:38:09 · 519 阅读 · 0 评论 -
关于回溯的题目
不关心起始点的位置:https://leetcode.com/problems/max-area-of-island/description/ 找到矩阵中最大连通子区域的块数 剑桥offer 找到矩阵中相同的路径起始点是固定的:剑桥offer 机器人的运动范围 二叉树找到最长路径/最大距离 https://www.cnblogs.com/wangzaizhen/p/517...原创 2018-09-20 23:11:59 · 442 阅读 · 0 评论 -
c++ 数组指针的使用
定义一个字符串数组,按首字母从小到大进行排序。void sort(char **p, int n){ char *temp; for(int i = 0; i < n-1; i++){ for(int j = 0; j < n - i -1; j++){ cout<< *(p+j)<<","<&...原创 2018-10-03 17:25:05 · 1558 阅读 · 0 评论 -
二叉树的构造
struct Node{ char data; Node* right, *left;};class Bitree{public: Bitree(){ root = new Node(); root->left = nullptr; root->right = nullptr; } void...原创 2018-10-04 16:43:18 · 1614 阅读 · 0 评论 -
程序员数学之卡特兰数(catalan number)
原文链接 http://lanqi.org/skills/10939/卡特兰数的应用问题有:出栈入栈;括号匹配;。。。等基本模型如下转载 2017-10-10 15:37:50 · 529 阅读 · 0 评论 -
leetcode Roman& Integer
参考:http://blog.youkuaiyun.com/ljiabin/article/details/399685831、罗马字母与数值的对应关系,罗马数字的范围0~3999int toNumber(char ch) { switch (ch) { case 'I': return 1; case 'V': return 5;原创 2017-05-24 09:51:11 · 249 阅读 · 0 评论 -
leetcode92. Reverse Linked List II
某位大牛写的算法,简直五体投体,里面灵活地运用了简单逆序链表的思想,为啥我就想不到呢,真的比较笨,要多体会public ListNode reverseBetween(ListNode head, int m, int n) { ListNode dummyhead = new ListNode(0); dummyhead.next = head; ListNode sublisthea原创 2017-05-20 16:45:34 · 244 阅读 · 0 评论 -
算法总结
对于数组查找:1、for循环,遍历2、构建hashmap, 直接查找Map map=new HashMap();map.put(array[i],i)map.containsKey(temp)原创 2017-05-19 14:39:33 · 249 阅读 · 0 评论 -
LeetCode 15. 3Sum
For example, given array S = {-1 0 1 2 -1 -4}, A solution set is: (-1, 0, 1) (-1, -1, 2)【解析】K Sum问题是一个系列,博客 http://tech-wonderland.NET/blog/summary-of-ksum-problems.html 总结得比较转载 2017-05-25 08:12:38 · 222 阅读 · 0 评论 -
leetcode 3. Longest Substring Without Repeating Characters
A sliding window is an abstract concept commonly used inarray/string problems. A sliding window is a window "slides" its two boundaries to the certain direction. For example, if we slide [i, j)[i,j)原创 2017-05-25 21:04:27 · 213 阅读 · 0 评论 -
longest common sequence(最长公共子序列)
参考博客:http://blog.youkuaiyun.com/u012150590/article/details/51474731原创 2017-05-26 11:30:41 · 390 阅读 · 0 评论 -
排序算法笔记
直接插入排序(On^2,稳定的)将最左边的作为一个有序数列;设立哨兵,比较并插入已形成的有序数列中。希尔排序(时效不好分析,不稳定)直接插入排序的升级版,调整不同的增量d/2----缩小增量排序,PS:是否稳定的标准:相等元素的前后顺序没有改变。原创 2017-05-20 16:44:46 · 284 阅读 · 0 评论 -
leetcode476. Number Complement
Input: 5Output: 2Explanation: The binary representation of 5 is 101 (no leading zero bits), and its complement is 010. So you need to output 2.一:知识补充java中取反 是会看第一位是符号位 如果是1就会转为负数 我不想要这样的结果 就是把原创 2017-09-07 10:17:06 · 326 阅读 · 0 评论 -
LeetCode Weekly Contest 39
public class Solution { public boolean judgeSquareSum(int c) { if(c == 0) return true; int left = 0 , right = (int)Math.sqrt(c); //需要18ms,如果是用自己的算法,是12ms // int mid ,tem原创 2017-07-02 11:43:44 · 235 阅读 · 0 评论 -
Max Consecutive Ones
Q:Input: [1,0,1,1,0]Output: 4Explanation: Flip the first zero will get the the maximum number of consecutive 1s. After flipping, the maximum number of consecutive 1s is 4.原文链接:https://discus转载 2017-09-19 11:48:15 · 382 阅读 · 0 评论 -
算法知识要点
非递归的题目:二叉树的前序、中序、后序,全排列,全子集原创 2017-09-14 10:38:21 · 294 阅读 · 0 评论 -
算法规律 rotate String
str = "abcdef"//找到翻转中心 str.len-offset-1 和 str.len-offset之间reverse(str, 0, str.length - offset - 1); //翻转前一部分reverse(str, str.length - offset, str.length - 1); //翻转后一部分reverse(str, 0, str.lengt原创 2017-09-21 12:03:32 · 253 阅读 · 0 评论
分享