由买买提看人间百态

topics

全部话题 - 话题: 解法
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
b***k
发帖数: 2673
1
来自主题: Quant版 - 发个general linear sde的解法
这个解法基于很多假定条件,比如
X=X1*X2
dX2=Adt+BdW
我觉得不是个非常elegant的解法。
Of course if you could intuitively know these preconditions,
it works good.
z*****8
发帖数: 2546
2
三步道车新解法Easy 3-Step Parallel Parking With 3 Simple Markers
http://youtu.be/No-rx8hjDZY
Easy 3-Step Parallel Parking With 3 Simple Markers
For new drivers, parallel parking is considered to be the hardest skill. For
non-new drivers, the problem is not remembering how to do it when it is
needed. Or you may not have the confidence to do it in one shot.
Mathematically, there is only a single fixed solution to parallel parking.
If you follow the instructions exactly, there should be no variations and... 阅读全帖
s******g
发帖数: 605
3
在ebay卖了咖啡机,过了两个星期,病人说不好使,有塑料味,要退。
好吧,退就退。刚把return label发了。马上就留了个negative。 问它为啥?不是同
意退了吗?
它说它不应该收到一个坏的。和它说收到货就给退钱。
这货马上上paypal dispute。 又和他说收到货给退钱。 马上escalate case.
nm, 这货脑子有病啊
有啥办法啊?好好的100%给个神经病弄坏了,心不甘, 有啥解法?
谢谢
n********u
发帖数: 194
4
来自主题: JobHunting版 - 问几个老算法题的最佳解法
我也有一个问题昨天看到的,自己想了以后觉得很混乱,理不出个头绪,不知道有谁有
比较好的解法。
问题:painting a cube with different 3 colors, how many ways?
m*****k
发帖数: 64
5
来自主题: JobHunting版 - rand5 -> rand7的解法?
我看了很多解法,好像没有哪个是绝对even distribution 的。
careercup上也没有公认的答案。
http://www.careercup.com/question?id=3043
谁能解答一下,谢谢!
s****a
发帖数: 528
6
NUANCE的,我做了3天,给出的解法据面试的说是最好的,为此拿到OFFER
做的不比我差的可以拿20个包子,欢迎讨论
下礼拜给答案
The Fibonacci palindrome problem
g*********s
发帖数: 1782
7
来自主题: JobHunting版 - sqrt的数值解法 (转载)
【 以下文字转载自 Programming 讨论区 】
发信人: gandjmitbbs (Nothing), 信区: Programming
标 题: sqrt的数值解法
发信站: BBS 未名空间站 (Wed Jan 26 18:44:22 2011, 美东)
如果用Newton's method,是否sqrt函数性质(单增且二阶连续可导)能保证任意初值
都可收敛?
B*******1
发帖数: 2454
8
来自主题: JobHunting版 - 问个google面试题的最佳解法
Given an input array of integers of size n, and a query array of integers of
size k, find the smallest window of input array that contains all the
elements of query array and also in the same order.
如果不要求保持order,ihas1337上面有解法,如果要保持order,怎么做才最好呢。
是不是最好应该是O(n)呢?
K*****k
发帖数: 430
9
这道题在ihasleetcode的网站上有巧妙的log(m+n)的解法,但对面试来说太难。
有人onsite的时候被问过这题么?
B*******1
发帖数: 2454
10
1337那个帖子下面有个读者给出的也是最优化的,1337也肯定了那个人的code,而且写
得很简单,就是改mit的解法出来的。
1337那个写得太复杂了。
x*******7
发帖数: 223
11
到底怎么答好呢?leetcode上面找中位数和找kth解法好像不一样吧。
k*******r
发帖数: 355
12
split a string into words in a dictionary
我想到的不管是递归还是dp,最坏情况都要O(2^n).有在最坏情况还能维持多项式时间
的解法么?哪位说一下?
w****x
发帖数: 2483
13
DP解法:
dpRec[strlen(str)]
dpRec[i]: if true, previous character can split to words
for (int i = 0; i < strLen; i++)
for (int j = i; j >=0 && !dpRec[i]; j--)
dpRec[i] = true if dpRec[j] && isWord(str[j..i])
时间复杂度O(n^2)
w****x
发帖数: 2483
14
刚发现题目不大一样, 我的是string的permutation.
一般去重都是先排序, 不过permutation这题好像排序搞不定, 不知道最好的解法是什
H****r
发帖数: 2801
15
这个估计size一般不会超过256,string如果可以解也行啊,大牛能说说解法怎么避免
重复的吗?
i**********e
发帖数: 1145
16
有两种解法,第一种就像 lolhaha 的思路:
先排序,这样能跳过同样的元素,避免重复。
第二种是实现 next_permutation(),
next_permutation 的好处是没有递归,而且可以处理重复。
算法可以参考这里,解说的很好:
http://wordaligned.org/articles/next-permutation#tocwhats-happe
代码也可以参考 C++ STL 里的 next_permutation.
w****x
发帖数: 2483
17

我会用hash map在每一层递归记录swap到a[0]的数据来避免重复,
但是排序的话swap以后就不能保证下层递归的排序性啊,
next_permutation的确是种解法, 赞一个, 就是难了点
h****e
发帖数: 928
18
LeetCode上ValidNumber题的解法:
http://dl.dropbox.com/u/19732851/LeetCode/ValidNumber.html
代码写得太简洁了,都不敢相信是对的。看了十几分钟,实在是找
不出一个反例。
l**********g
发帖数: 426
19
数组 3, 5,1, 8, 9, 7, 0, 2
找到 3, 1, 0, 2 ----最长序列
要求复杂度好于 O(nlog(n))
有hashmap记录间隔的解法,写起来蛮复杂。
大侠指点。
f*******t
发帖数: 7549
20
以前讨论过,有O(n) time&space解法
w****x
发帖数: 2483
21
我的解法不对吗??
j*******e
发帖数: 1058
22
没java解法么?
h****e
发帖数: 928
23
多谢!我对这道题的最优解法也是纠结了好久,总觉得binary search
是不行的,以前也在版上问过。看来O(M+N)就是最优解了。
f*********m
发帖数: 726
24
来自主题: JobHunting版 - 求leetcode 4sum的O(n^2)解法
好像有O(n^2)的解法吧?
http://www.mitbbs.com/article_t/JobHunting/32038595.html
d**********x
发帖数: 4083
25
来自主题: JobHunting版 - 求leetcode 4sum的O(n^2)解法
看起来似乎是没有不用hashtable的n^2解法
f*********m
发帖数: 726
26
来自主题: JobHunting版 - 求leetcode 4sum的O(n^2)解法
好像有O(n^2)的解法吧?
http://www.mitbbs.com/article_t/JobHunting/32038595.html
d**********x
发帖数: 4083
27
来自主题: JobHunting版 - 求leetcode 4sum的O(n^2)解法
看起来似乎是没有不用hashtable的n^2解法
l****o
发帖数: 43
28
来自主题: JobHunting版 - 求leetcode 4sum的O(n^2)解法
有比O(n^3)更好的解法吗?好像输出的最大size是O(n^3)。
S*******e
发帖数: 379
29
把matrix每个格子作为起始点,递归尝试每个方向,用一个extra matrix记录到过的点。
每visit一个点,跟字典比较是不是合法的单词。
如果字典保存在trie里,递归的时候可以terminate的早一点。
有其他更好的解法吗?
S*******e
发帖数: 379
30
把matrix每个格子作为起始点,递归尝试每个方向,用一个extra matrix记录到过的点。
每visit一个点,跟字典比较是不是合法的单词。
如果字典保存在trie里,递归的时候可以terminate的早一点。
有其他更好的解法吗?
n****r
发帖数: 471
31
来自主题: JobHunting版 - 请教leetcode Permutations II 解法和code
谁能给讲解一下这位大牛的解法? http://discuss.leetcode.com/questions/225/permutations-ii
Code:
class Solution {
public:
vector > permuteUnique(vector &num) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
vector used(num.size(), false);
vector path;
vector > ret;
sort(num.begin(), num.end());
sub(num, used, path, ret);
return ret;
}
void sub(vector &num, vector... 阅读全帖
n****r
发帖数: 471
32
来自主题: JobHunting版 - 请教leetcode Permutations II 解法和code
谁能给讲解一下这位大牛的解法? http://discuss.leetcode.com/questions/225/permutations-ii
Code:
class Solution {
public:
vector > permuteUnique(vector &num) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
vector used(num.size(), false);
vector path;
vector > ret;
sort(num.begin(), num.end());
sub(num, used, path, ret);
return ret;
}
void sub(vector &num, vector... 阅读全帖
e***s
发帖数: 799
33
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,−1,2,1,−5,4],
the contiguous subarray [4,−1,2,1] has the largest sum = 6.
More practice:
If you have figured out the O(n) solution, try coding another solution using
the divide and conquer approach, which is more subtle.
想知道O(nlogn)的解法。
w****x
发帖数: 2483
34
来自主题: JobHunting版 - 求OJ container with most water O(n)解法
Given n non-negative integers a1, a2, ..., an, where each represents a point
at coordinate (i, ai). n vertical lines are drawn such that the two
endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together
with x-axis forms a container, such that the container contains the most
water.
Note: You may not slant the container.
[2,3,10,5,7,8,9] => 36 => 10...9
给个O(n)解法的思路??
w****x
发帖数: 2483
35
来自主题: JobHunting版 - 求OJ container with most water O(n)解法
我有个nlogn的解法,建立一个structure {value, index}, 根据value增序排序,然后
用一个iterator, 这个iterator假设为最小边, 从右往左扫, 过程中记录最大index
和最小index, 扫一遍, 就成了股票买卖问题。
w****x
发帖数: 2483
36
来自主题: JobHunting版 - 求OJ container with most water O(n)解法
Given n non-negative integers a1, a2, ..., an, where each represents a point
at coordinate (i, ai). n vertical lines are drawn such that the two
endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together
with x-axis forms a container, such that the container contains the most
water.
Note: You may not slant the container.
[2,3,10,5,7,8,9] => 36 => 10...9
给个O(n)解法的思路??
w****x
发帖数: 2483
37
来自主题: JobHunting版 - 求OJ container with most water O(n)解法
我有个nlogn的解法,建立一个structure {value, index}, 根据value增序排序,然后
用一个iterator, 这个iterator假设为最小边, 从右往左扫, 过程中记录最大index
和最小index, 扫一遍, 就成了股票买卖问题。
z***2
发帖数: 3
c***e
发帖数: 542
39
来自主题: JobHunting版 - 求Leetcode OJ Maximal Rectangle的n^2解法
有人能讲一下O(n^3)的解法吗?
e***s
发帖数: 799
40
求 Leetcode Online Judge Sort Color one pass constant space 解法。
Copy 下题目:
Given 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 will use the integers 0, 1, and 2 to represent the color red, white
, and blue respectively.
Note:
You are not suppose to use the library's sort function for this problem.
Follow up:
A rather straight forward solution is a two-pass algorithm using coun... 阅读全帖
g****y
发帖数: 240
41
来自主题: JobHunting版 - 这种解法对吗?merge two BST
你这样解法不对。你不能保证root2左树中的所有node比root1小。

root2
i**********e
发帖数: 1145
42
longway2008 贴过的代码,估计是我看过非递归解法最短的行数了。。。但不好消化
bool isMatch(const char *str, const char *pat, bool hasStar=false)
{
if (!*pat) return !*str || hasStar;

const char *s, *p;
for (s = str, p = pat; *s; ++s, ++p) {
if (*p == '*')
return isMatch(s, p+1, true);
else if ( *p != '?' && *s != *p)
return !hasStar ? false : isMatch(str+1, pat, hasStar);
}

while (*p == '*') ++p;
return (!*p);
}
i**********e
发帖数: 1145
43
要通过large case 只能用非递归的。不过那个面试写太复杂了,很多edge case 要考
虑。
DP 的解法复杂度是 O(m*n) 一般都是 memory exceed,我不知道二爷的为什么 time
limit exceed。也有可能java 跑得慢的缘故吧。二爷的代码如果转换成C++应该是
memory exceed 的。
h****n
发帖数: 1093
44
来自主题: JobHunting版 - 再问Maximal Rectangle的N^2解法
large rectangle in histogram的变形,那个会N解法的话,自然这个就是N square解
s*********s
发帖数: 140
45
来自主题: JobHunting版 - 再问Maximal Rectangle的N^2解法
恩,那个blog的解法是基于histogram那道题的。但是large judge会报time limit
exceeded.我自己写了一遍也过不了large judge。能帮忙看看是哪里的时间复杂度太高
呢?
public class Solution {
public int maximalRectangle(char[][] matrix) {

if(matrix == null || matrix.length == 0)
return 0;

int max = 0;

for(int i = 0; i < matrix[0].length; i++){
int[] height = getHeight(matrix, i);
max = Math.max(max, largestRectangleArea(height));
}

return max;
... 阅读全帖
c********t
发帖数: 5706
46
Queens的题都是用backtracking+recursion吧?
N-Queens II与N-Queens 解法有什么不同?除了更简单,因为不用存结果.
R**y
发帖数: 72
47
这个解法是recursion吧。

()
d******9
发帖数: 36
48
来自主题: JobHunting版 - leetcodeOJ上的sudoku有简单解法吗?
直接DFS超时啊
不知道有没有更简单的解法
c********t
发帖数: 5706
49
我用两个stack, DFS比较,可是因为null无法进入stack,每次人前都要一堆if判断比较
,感觉很差。
有没有好点的iterative的解法?
多谢!
b*******3
发帖数: 145
50

这是jordandong的java版本,比我的前一种解法少用了一个stack,谢谢,代码如下:
public boolean isSymmetric(TreeNode root) {
// Start typing your Java solution below
// DO NOT write main() function
if(root == null){
return true;
}else{
Queue que = new LinkedList();
Queue que1 = new LinkedList();
que.add(root.left);
que1.add(root.right);
while(que.size() > 0 && que1.size() > 0){
... 阅读全帖
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)