自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

chaoai4278的博客

算法极客

  • 博客(87)
  • 收藏
  • 关注

原创 数据结构-图-总结

Is Graph Bipartite? Description Given an undirected graph, return true if and only if it is bipartite. Recall that a graph is bipartite if we can split it's set of nodes into two independent subset...

2018-09-04 06:47:10 409

原创 杆子分割

给一个 n 英寸长的杆子和一个包含所有小于 n 的尺寸的价格. 确定通过切割杆并销售碎片可获得的最大值.例如,如果棒的长度为8,并且不同长度部件的值如下,则最大可获得值为 22(通过切割两段长度 2 和 6 )您在真实的面试中是否遇到过这个题?  是样例长度 | 1 2 3 4 5 6 7 8 ---------------------------------...

2018-07-16 11:59:57 248

原创 最小调整代价

给一个整数数组,调整每个数的大小,使得相邻的两个数的差不大于一个给定的整数target,调整每个数的代价为调整前后的差的绝对值,求调整代价之和最小是多少。你可以假设数组中每个整数都是正整数,且小于等于100。您在真实的面试中是否遇到过这个题?  是样例对于数组[1, 4, 2, 3]和target=1,最小的调整方案是调整为[2, 3, 2, 3],调整代价之和是2。返回2。class Solut...

2018-07-13 15:07:57 174

原创 the previous numbers

For an array, for each element, find the value of the first smaller element before it. If not, then output it itself.ExampleGiven arr = [2,3,6,1,5,5], return [2,2,3,1,1,1].Explanation: According to th...

2018-07-12 16:56:41 122

原创 Binary Search Tree Iterator

DescriptionDesign an iterator over a binary search tree with the following rules:Elements are visited in ascending order (i.e. an in-order traversal)next() and hasNext() queries run in O(1) time in av...

2018-07-12 16:36:30 155

原创 第k大元素

在数组中找到第k大的元素你可以交换数组中的元素的位置Have you met this question in a real interview?  YesExample给出数组 [9,3,2,4,8],第三大的元素是 4给出数组 [1,2,3,4,5],第一大的元素是 5,第二大的元素是 4,第三大的元素是 3,以此类推Challenge要求时间复杂度为O(n),空间复杂度为O(1)class ...

2018-07-11 11:49:26 250

原创 Nuts 和 Bolts 的问题

描述给定一组 n 个不同大小的 nuts 和 n 个不同大小的 bolts。nuts 和 bolts 一一匹配。 不允许将 nut 之间互相比较,也不允许将 bolt 之间互相比较。也就是说,只许将 nut 与 bolt 进行比较, 或将 bolt 与 nut 进行比较。请比较 nut 与 bolt 的大小。您在真实的面试中是否遇到过这个题?  是样例给出 nuts = ['ab','bc','d...

2018-07-11 11:46:26 1773

原创 区间DP总结

Scramble String Description Notes Testcase JudgeGiven a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation ...

2018-02-22 15:18:46 145

原创 局部全局思路总结

Maximum Subarray III Description Notes Testcase JudgeGiven an array of integers and a number k, find k non-overlapping subarrays which have the largest sum.The number in each subarray should be contig...

2018-02-22 15:00:27 312

原创 总结-博奕类

There are n coins in a line. Two players take turns to take one or two coins from right side until there are no more coins left. The player who take the last coin wins.Could you please decide the firs...

2018-02-19 20:07:47 132

原创 总结-二叉分治

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 leaf node.Have you met this question in a real inter...

2018-02-17 10:04:54 145

原创 二分查找总结

Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the array return its inde...

2018-02-11 16:31:53 121

原创 大数据相关知识,认真读

Hadoop生态圈 https://www.zhihu.com/question/27974418 http://blog.chinaunix.net/uid-22312037-id-3969789.html http://www.cnblogs.com/gridmix/p/5102694.html https://www.cnblogs.com/zhangwuji/p/759

2018-02-04 19:54:18 131

原创 排列组合总结

Given a set of distinct integers, return all possible subsets. Notice Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets. Have

2018-02-04 16:19:44 249

原创 Jump Game II

Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Your goal i

2018-01-31 17:02:05 97

原创 Jump game

Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Determine if yo

2018-01-31 16:44:52 132

原创 青蛙跳

A frog is crossing a river. The river is divided into x units and at each unit there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water. Given a list of s

2018-01-31 15:54:55 262

原创 验证二叉查找树

给定一个二叉树,判断它是否是合法的二叉查找树(BST) 一棵BST定义为: 节点的左子树中的值要严格小于该节点的值。节点的右子树中的值要严格大于该节点的值。左右子树也必须是二叉查找树。一个节点的树也是二叉查找树。 您在真实的面试中是否遇到过这个题? Yes 样例 一个例子: 2 / \ 1 4 / \ 3 5 上

2018-01-30 07:52:40 137

原创 数字组合 II

给出一组候选数字(C)和目标数字(T),找出C中所有的组合,使组合中数字的和为T。C中每个数字在每个组合中只能使用一次。 注意事项 所有的数字(包括目标数字)均为正整数。 元素组合(a1, a2, … , ak)必须是非降序(ie, a1 ≤ a2 ≤ … ≤ ak)。 解集不能包含重复的组合。  您在真实的面试中是否遇到过这个题? Ye

2018-01-29 22:04:42 361

原创 数字组合

给出一个候选数字的set(C)和目标数字(T),找到C中所有的组合,使找出的数字和为T。C中的数字可以无限制重复被选取。 例如,给出候选数组[2,3,6,7]和目标数字7,所求的解为: [7], [2,2,3] 注意事项 所有的数字(包括目标数字)均为正整数。 元素组合(a1, a2, … , ak)必须是非降序(ie, a1 ≤ a2 ≤ … ≤ ak)。

2018-01-29 22:02:40 816

原创 分割回文串

给定一个字符串s,将s分割成一些子串,使每个子串都是回文串。 返回s所有可能的回文串分割方案。 您在真实的面试中是否遇到过这个题? Yes 样例 给出 s = "aab",返回 [ ["aa", "b"], ["a", "a", "b"] ] class Solution { public: /* * @

2018-01-29 22:01:19 671

原创 N皇后问题

n皇后问题是将n个皇后放置在n*n的棋盘上,皇后彼此之间不能相互攻击。 给定一个整数n,返回所有不同的n皇后问题的解决方案。 每个解决方案包含一个明确的n皇后放置布局,其中“Q”和“.”分别表示一个女王和一个空位置。 您在真实的面试中是否遇到过这个题? Yes 样例 对于4皇后问题存在两种解决的方案: [     [".Q..", //

2018-01-29 21:59:41 696

原创 带重复元素的子集

给定一个可能具有重复数字的列表,返回其所有可能的子集 注意事项 子集中的每个元素都是非降序的两个子集间的顺序是无关紧要的解集中不能包含重复子集 您在真实的面试中是否遇到过这个题? Yes 样例 如果 S = [1,2,2],一个可能的答案为: [ [2], [1], [1,2,2], [2,2],

2018-01-29 21:58:17 416

原创 子集

给定一个含不同整数的集合,返回其所有的子集 注意事项 子集中的元素排列必须是非降序的,解集必须不包含重复的子集 您在真实的面试中是否遇到过这个题? Yes 样例 如果 S = [1,2,3],有如下的解: [ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2

2018-01-29 21:56:53 218

原创 全排列

给定一个数字列表,返回其所有可能的排列。 注意事项 你可以假设没有重复数字。 您在真实的面试中是否遇到过这个题? Yes 样例 给出一个列表[1,2,3],其全排列为: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1] ] cla

2018-01-29 21:55:23 124

原创 拓扑排序

给定一个有向图,图节点的拓扑排序被定义为: 对于每条有向边A--> B,则A必须排在B之前   拓扑排序的第一个节点可以是任何在图中没有其他节点指向它的节点   找到给定图的任一拓扑排序 注意事项 你可以假设图中至少存在一种拓扑排序 您在真实的面试中是否遇到过这个题? Yes /** * De

2018-01-29 21:31:49 125

原创 克隆图

克隆一张无向图,图中的每个节点包含一个 label 和一个列表 neighbors。 数据中如何表示一个无向图?http://www.lintcode.com/help/graph/ 你的程序需要返回一个经过深度拷贝的新图。这个新图和原图具有同样的结构,并且对新图的任何改动不会对原图造成任何影响。 您在真实的面试中是否遇到过这个题? Yes 样

2018-01-29 21:30:25 441

原创 HITS

http://blog.csdn.net/rubinorth/article/details/52231620 HITS算法的缺点 计算效率低 这里说的“效率低”是针对其实时计算的特点而提出的。HITS算法是在用户提出搜索请求之后才开始运行的,然而计算出结果又需要多次迭代计算,所以就这点上来说HITS算法效率仍然较低。 主题漂移 在算法原理部分我们介绍了HIT

2018-01-29 11:17:01 587

原创 排序矩阵中的从小到大第k个数

在一个排序矩阵中找从小到大的第 k 个整数。 排序矩阵的定义为:每一行递增,每一列也递增。 您在真实的面试中是否遇到过这个题? Yes 样例 给出 k = 4 和一个排序矩阵: [ [1 ,5 ,7], [3 ,7 ,8], [4 ,8 ,9], ] 返回 5。 挑战 使用O(k log n)的方法

2018-01-28 20:32:45 616

原创 数据流中位数

数字是不断进入数组的,在每次添加一个新的数进入数组的同时返回当前新数组的中位数。 您在真实的面试中是否遇到过这个题? Yes 说明 中位数的定义: 中位数是排序后数组的中间值,如果有数组中有n个数,则中位数为A[(n-1)/2]。比如:数组A=[1,2,3]的中位数是2,数组A=[1,19]的中位数是1。 样例

2018-01-28 17:46:03 160

原创 丑数 II

设计一个算法,找出只含素因子2,3,5 的第 n 小的数。 符合条件的数如:1, 2, 3, 4, 5, 6, 8, 9, 10, 12... 注意事项 我们可以认为1也是一个丑数 您在真实的面试中是否遇到过这个题? Yes 样例 如果n = 9, 返回 10 挑战 要求时间复杂度为O(nl

2018-01-28 17:43:38 104

原创 将数组堆化

给出一个整数数组,堆化操作就是把它变成一个最小堆数组。 对于堆数组A,A[0]是堆的根,并对于每个A[i],A [i * 2 + 1]是A[i]的左儿子并且A[i * 2 + 2]是A[i]的右儿子。 您在真实的面试中是否遇到过这个题? Yes 说明 什么是堆? 堆是一种数据结构,它通常有三种方法:push, pop 和 top。其中,“pu

2018-01-28 14:17:18 2431

原创 复制带随机指针的链表-解法2

给出一个链表,每个节点包含一个额外增加的随机指针可以指向链表中的任何节点或空的节点。 返回一个深拷贝的链表。  您在真实的面试中是否遇到过这个题? Yes 样例 挑战 可否使用O(1)的空间 /** * Definition for singly-linked list with a random pointe

2018-01-27 11:18:03 167

原创 最长连续序列

给定一个未排序的整数数组,找出最长连续序列的长度。 您在真实的面试中是否遇到过这个题? Yes 说明 要求你的算法复杂度为O(n) 样例 给出数组[100, 4, 200, 1, 3, 2],这个最长的连续序列是 [1, 2, 3, 4],返回所求长度 4 点题:思维的技巧性,一定要想清楚 class

2018-01-27 11:09:55 201

原创 乱序字符串

给出一个字符串数组S,找到其中所有的乱序字符串(Anagram)。如果一个字符串是乱序字符串,那么他存在一个字母集合相同,但顺序不同的字符串也在S中。 注意事项 所有的字符串都只包含小写字母 您在真实的面试中是否遇到过这个题? Yes 样例 对于字符串数组 ["lint","intl","inlt","code"] 返回

2018-01-26 21:15:57 186

原创 PageRank

http://www.cnblogs.com/fengfenggirl/p/pagerank-introduction.html http://blog.csdn.net/rubinorth/article/details/52215036 这两篇文章里重要介绍了PageRank算法,几个关键的点: 图不是强连通,怎么办?有一些节点没有出链闭环,几个节点形成闭环解决办法就是从地址

2018-01-25 16:46:28 148

原创 最大正方形

在一个二维01矩阵中找到全为1的最大正方形 您在真实的面试中是否遇到过这个题? Yes 样例 1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1 0 0 1 0 返回 4 class Solution { public: /* * @param matrix: a matrix of 0 and 1

2018-01-24 19:44:20 139

原创 最大矩形

给你一个二维矩阵,权值为False和True,找到一个最大的矩形,使得里面的值全部为True,输出它的面积 您在真实的面试中是否遇到过这个题? Yes 样例 给你一个矩阵如下 [ [1, 1, 0, 0, 1], [0, 1, 0, 0, 1], [0, 0, 1, 1, 1], [0, 0, 1, 1, 1], [0, 0,

2018-01-24 19:13:40 171

原创 直方图最大矩形覆盖

Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram. Above is a histogram where width of each

2018-01-24 14:16:25 270

原创 二叉树的锯齿形层次遍历

给出一棵二叉树,返回其节点值的锯齿形层次遍历(先从左往右,下一层再从右往左,层与层之间交替进行)  您在真实的面试中是否遇到过这个题? Yes 样例 给出一棵二叉树 {3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7 返回其锯齿形的层次遍历为: [ [3], [20,9]

2018-01-24 08:41:24 170

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除