
others
文章平均质量分 50
benbenab
这个作者很懒,什么都没留下…
展开
-
Set Matrix Zeroes
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.Follow up:Did you use extra space?A straight forward solution using O(mn) space is probably a b原创 2012-11-02 11:46:39 · 459 阅读 · 0 评论 -
【FB】
小肥的面经,小肥的代码:http://collabedit.com/gmysb1. 开会的题目,问给一堆会议,每个会议一个开始时间,结束时间,问有没有 overlap2. 如果这些会议有overlap 求最小需要多少房间第二个解法简直是精典!struct Meeting{ double start;转载 2013-01-10 00:59:54 · 758 阅读 · 0 评论 -
[leetcode]longest Valid Parentheses(!!)
class Solution {public: int longestValidParentheses(string s) { // Start typing your C/C++ solution below // DO NOT write int main() function int nSize = s.size();转载 2013-01-08 06:00:56 · 374 阅读 · 0 评论 -
[leetcode] combination (不会做)
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4转载 2012-12-31 05:08:40 · 396 阅读 · 0 评论 -
[leetcode] Best Time to Buy and Sell Stock
Best Time to Buy and Sell StockSay you have an array for which the ith element is the price of a given stock on day i.1 If you were only permitted to complete at most one transaction (i原创 2012-12-24 01:15:33 · 407 阅读 · 0 评论 -
用multiset/priority_Queue来实现最大最小堆
面试题:实现KNN,给定各个点之间的距离,返回某个点的k个neighbor。思路: 考虑到A家喜欢问海量数据,所以用heap,复杂度O(nlogk)。 当时是自己实现的heap。后来发现可以直接调用STL中的set 或者multiset来实现。 Mulitiset: STL中 set 和multisetset的含义是集合,它是一个有序的容器,里原创 2012-11-25 04:23:49 · 3934 阅读 · 0 评论 -
求一个无序数组的子数组, 子数组的和最接近0
方法讨论:http://blog.kingsamchen.com/archives/649typedef struct{ int value; int index;}info;bool less_b (const info& info1, const info& info2){ return info1.value < info2.value;}int * temp = new原创 2012-12-10 22:25:28 · 873 阅读 · 0 评论 -
最大公约数 最小公倍数
给2个整数 相除,输出精确结果如果是非循环,输出所有数字, 如果是循环数,标注哪里开始循环用长除做 然后用表记下来之前的余数1. 先找到最大公约数2. a/b 只可能有 b-1种余数, 然后建一个 大小为 b的 hashtable或者数组,查找是不是有重复3. 如果 x/k 0Greatest common divisor 最大公约数least转载 2012-12-06 09:06:26 · 815 阅读 · 0 评论 -
related with 有序数组中第K小的数
http://www.cnblogs.com/ider/archive/2012/09/08/binary_search_advanced.html转载 2012-12-06 09:20:09 · 484 阅读 · 0 评论 -
N queen
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens pu转载 2012-11-26 00:12:22 · 615 阅读 · 0 评论 -
sort colors
Sort ColorsGiven an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we wil原创 2012-11-04 12:26:42 · 464 阅读 · 0 评论 -
given stream of integers, find first 100 large numbers (!!!)
最开始的idea很自然想到用heap,size为100的heap, 计算复杂度为O(nlog100).不如用bubble sort,bubble100次,因为不需要让这100个数sorted,O(100n) = O(n)转载 2013-01-12 07:19:45 · 350 阅读 · 0 评论