题目Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window...
问题描述Givennpoints on a 2D plane, find the maximum number of points that lie on the same straight line.解决思路1.定义Line类{slope; intercept; isVertical; isHor...
分类:
其他好文 时间:
2015-08-11 22:53:24
阅读次数:
163
August 10, 2015有二种解法, Greedy算法, 和DP算法. 二种算法都通过leetcode online judge. 贪婪算法, 花了一个小时理解代码, 修改后很好理解.Problem statement:Find the contiguous subarray within a...
分类:
其他好文 时间:
2015-08-11 09:44:20
阅读次数:
127
QestionGiven a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, (the...
分类:
其他好文 时间:
2015-08-11 07:18:19
阅读次数:
124
Given n points
on a 2D plane, find the maximum number of points that lie on the same straight line.
分析:
任意一条直线都可以表述为
y = ax + b
假设,有两个点(x1,y1), (x2,y2),如果他们都在这条直线上则有
y1 = kx1 +b...
分类:
其他好文 时间:
2015-08-09 20:47:26
阅读次数:
98
题目描述:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [?2,1,?3,4,?...
分类:
编程语言 时间:
2015-08-09 20:16:09
阅读次数:
134
Given a stringS, find the longest palindromic substring inS. You may assume that the maximum length ofSis 1000, and there exists one unique longest pa...
分类:
其他好文 时间:
2015-08-09 01:57:22
阅读次数:
134
Codeforces 566F 的传送门As you must know, the maximum clique problem in an arbitrary graph is NP-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively.Just in case, let us remi...
分类:
其他好文 时间:
2015-08-08 19:59:04
阅读次数:
133
【104-Maximum Depth of Binary Tree(二叉树的最大深度)】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】原题 Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from th...
分类:
编程语言 时间:
2015-08-08 07:59:24
阅读次数:
126
不知道为啥,这样的题目跑到贪心里面去了,动态规矩挺简单,最后之前看了一遍他的问题,所以很容易就敲出来了,贪心暂时告一段落,开始dp,加油
思路:
最大子矩阵和的问题可以通过最大字段和的问题解出来,普通的暴力枚举是枚举行和列,时间复杂度为m^2*n^2,但是我们可以在行的上界和下界确定的情况下将这个矩阵压缩为一个一维数组存起来,然后利用最大字段和的求解解出来,代码应该很容易就能看懂,如果对动...
分类:
其他好文 时间:
2015-08-07 14:46:09
阅读次数:
168