随笔分类 -  每周算法练习

上一页 1 ··· 7 8 9 10 11
摘要:Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that duplicates do not exist in the tree. For example, 阅读全文
posted @ 2018-06-22 21:28 Shendu.CC 阅读(242) 评论(0) 推荐(0)
摘要:Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and 阅读全文
posted @ 2018-06-21 21:28 Shendu.CC 阅读(147) 评论(0) 推荐(0)
摘要:Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example:Given binary tree [3 阅读全文
posted @ 2018-06-20 22:14 Shendu.CC 阅读(147) 评论(0) 推荐(0)
摘要:Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest l 阅读全文
posted @ 2018-06-18 16:02 Shendu.CC 阅读(123) 评论(0) 推荐(0)
摘要:随机数生成 (1)可使用random等系统函数,构造函rand 15 :在[1,5]范围,均匀分布随机函数 (2)不可使用random,仅仅基于rand15构造rand112:在[1,12]范围,均匀分贝的随机函数 (3)函数randint26:在【2,3,4,5范围内等概率生成某个整数的随机函数。 阅读全文
posted @ 2018-04-26 18:56 Shendu.CC 阅读(717) 评论(0) 推荐(0)
摘要:有一份5000万个用户的数据,有一份2亿个用户看电影的记录。只有1G的内存,找到看电影最多的前1000个用户? 应该怎么做呢? 我一开始的想法,哎呀,快速排序!把2亿个用户的数据提取出来放到5000万长度的数组里进行快速排序。把2亿个用户的数据提取出来,只能靠HashMap了,那么就要在建一个500 阅读全文
posted @ 2018-04-24 10:24 Shendu.CC 阅读(254) 评论(0) 推荐(0)
摘要:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree [1,2,2,3,4,4,3] is symmet 阅读全文
posted @ 2018-04-20 17:41 Shendu.CC 阅读(359) 评论(0) 推荐(0)
摘要:有1,2,3....n个数组,每个数组包含一系列一维线段的表示,每个数组的元素结构为(point,length)(point>=0 且 length>=1,都为整数),表示从point开始长为length的线段,现将n个数组中的线段合并,其中需要考虑数组的优先级:1>2>....>n,高优先级的数组 阅读全文
posted @ 2018-04-03 11:55 Shendu.CC 阅读(550) 评论(2) 推荐(0)
摘要:在博问上有个人提问汉字字典树的问题,于是自己手动了实现了一个汉字字典树。和英文字典树不同的是,每个节点的指针不是26个英文字母,汉字字典树的节点的指针是根据输入的汉词来决定的。节点中使用map<string,int>来存放每个汉字的指针 阅读全文
posted @ 2018-03-31 17:47 Shendu.CC 阅读(1368) 评论(0) 推荐(0)
摘要:一条长为n的路,需要用路灯点亮,其中"."表示需要点亮的位置,"X"表示无需点亮的位置,假设灯立在i处,则它可以点亮i-1,i,i+1三个位置,问至少需要多少灯才能点亮整条路。 乍一看,肯定是动态规划: 上代码,敲了两个小时的动态规划: 而实际上呢,如果不要那么浮躁,再看看题目,你就会发现,这题目贪 阅读全文
posted @ 2018-03-28 13:31 Shendu.CC 阅读(661) 评论(0) 推荐(0)
摘要:正数转二进制很简单,转十六进制也很简单。 那么负数的情况下呢?在计算机中无法识别你给的符号“+”,"-",计算机只认识0和1 那么在二进制中如何表示负数。 先简单介绍一下负数如何转二进制,八进制,十六进制: 比如给的是-4 那么先算出+4的二进制表示: 1 0 0 但是请记住我们需要在前面补0,因为 阅读全文
posted @ 2018-03-22 20:15 Shendu.CC 阅读(5120) 评论(0) 推荐(0)
摘要:最近由于某些原因,又回顾了一次KMP算法。上一次回顾KMP算法还是在刷题的时候遇到的: http://blog.csdn.net/dacc123/article/details/50994611 在我的记忆力,每次回顾KMP算法都会有新的理解,以为自己理解的很透彻了,等过一段时间再去回顾,又要花一些 阅读全文
posted @ 2018-03-20 10:26 Shendu.CC 阅读(153) 评论(0) 推荐(0)
摘要:括号匹配(二) 时间限制:1000 ms | 内存限制:65535 KB 难度:6 括号匹配(二) 时间限制:1000 ms | 内存限制:65535 KB 难度:6 动态规划:区间DP 好久没写题目了,第一次写,有点生疏。还好是一遍过。要不然丢人了。 区间DP经典题: 阅读全文
posted @ 2018-01-31 16:44 Shendu.CC 阅读(250) 评论(2) 推荐(0)

上一页 1 ··· 7 8 9 10 11