由买买提看人间百态

topics

全部话题 - 话题: leetcode
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
n****r
发帖数: 471
1
来自主题: 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... 阅读全帖
h*****3
发帖数: 1391
2
来自主题: JobHunting版 - 请教leetcode Subsets II
我觉的你要把leetcode上所有的题都问一遍。
c*********8
发帖数: 561
3
来自主题: JobHunting版 - judge large on leetcode
各位大牛,请问leetcode上面judge large具体意思是什么?相对于judge small会有哪
些区别?
C***U
发帖数: 2406
4
来自主题: JobHunting版 - leetcode上的2个整数相除
我在自己电脑上用位移的算法做出来了
code写的有点长 但是例子都能过
但是在leetcode上一直超时 不知道为什么
m******r
发帖数: 42
5
来自主题: JobHunting版 - leetcode上的2个整数相除
新手土鳖问题:你在自己电脑上怎么拷贝测试结果?是你自己写了caller
然后手工对照结果?好像没看到leetcode有import数据的地方啊。
q***y
发帖数: 24
6
来自主题: JobHunting版 - leetcode上的2个整数相除
溢出了
注意leetcode会输入最小的int,取负后无法用int表示
C***U
发帖数: 2406
7
来自主题: JobHunting版 - leetcode上的2个整数相除
我把dividend和divisor存到x y里面都是unsigned int了
下面这个代码对了 通过leetcode的验证了 只不过写的很丑
把最小的数拿出来单独处理了
int divide(int dividend, int divisor) {
int flag = 1;
unsigned long int x;
unsigned long int y;
unsigned long int z;
unsigned int i = 0;
unsigned int count = 0;
int result = 0;
if(!divisor) {
cout << "could not be divided by 0" << endl;
return 0;
}
if(dividend == -2147483648) {
if(divisor > 0) {
dividend += divisor;
result ... 阅读全帖
c****7
发帖数: 4192
8
来自主题: JobHunting版 - 求Leetcode OJ Maximal Rectangle的n^2解法
你贴的是square sub-matrix
leetcode是要retangle
c****7
发帖数: 4192
9
来自主题: JobHunting版 - 求Leetcode OJ Maximal Rectangle的n^2解法
靠,你们不都是在看leetcode嘛!
我基本都不是做题,就是看别人怎么做,死记硬背下来~~
I*****8
发帖数: 37
10
来自主题: JobHunting版 - leetcode pow runtime error??
x=0, n=-1, 可以跑,leetcode 对于 x=0, n=0的test case是错的,应该是return 0
把.
但这样跑 大set的话, 结果是超时 。
我的解法,http://www.tsechung.com/wordpress/2012/07/20/powxn/
可以通过。
s*****9
发帖数: 93
11
来自主题: JobHunting版 - leetcode的Text Justification的OJ
赞同。
顺带报告做题时的问题,支持leetcode。
M*****a
发帖数: 2054
12
来自主题: JobHunting版 - leetcode过的一代工程师
发信人: peking2 (myfacebook), 信区: JobHunting
标 题: Re: leetcode过的一代工程师
发信站: BBS 未名空间站 (Sun Aug 12 14:38:00 2012, 美东)

我觉得DP题不能用recursion来解的话就能filter掉不合格的程序员了吧。recursion还
是基本的编程逻辑吧。
w****x
发帖数: 2483
13
来自主题: JobHunting版 - leetcode过的一代工程师

不是吧,昨天leetcode全部一次通过, 去重的7分钟,全干掉的15分钟,你们哪个厂的
我去申请申请
c*****e
发帖数: 3226
14
来自主题: JobHunting版 - leetcode过的一代工程师
问题是这代工程师年老的时候接着被下一代的人搞。估计到时候会感叹比leetcode难太
多了。
e***s
发帖数: 799
15
求 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... 阅读全帖
w****x
发帖数: 2483
C***U
发帖数: 2406
17
我的做法和你一样 所以要用额外的空间
所以那个题目让我觉得有点不可思议!
by the way, 你的code有bug的
你去leetcode上测试一下好了
s*****1
发帖数: 134
18
来自主题: JobHunting版 - [难题求助] leetcode wordsearch
版上有没有做出leetcode online test 中我的 word search 的 java版,这题我java
版做了,能通过小规模测试,但大规模的通过不了,写了2个版本都超时了。
我的思路和网上搜索的c++版本(通过)的一样,就是一个点开始向四周辐射搜索,类
似于DFS,做DFS是需要一个二维的boolean矩阵来记录这个点是否visit过。我感觉就是
这个环节出了问题,C++深拷贝一个二维矩阵快吧,但是java深拷贝一个二维矩阵很费
时。
我的程序已经有DP和pre-check了,还是不快,望能够写出快速程序的大牛赐教,最好
贴代码 或站内头条,非常感谢!
q****m
发帖数: 177
19
这个 vector > 是 leetcode里面给出的 prototype阿。
q****m
发帖数: 177
20
这个 vector > 是 leetcode里面给出的 prototype阿。
i*********7
发帖数: 348
21
来自主题: JobHunting版 - leetcode上的一题。
http://www.leetcode.com/2011/01/ctrla-ctrlc-ctrlv.html
Imagine you have a special keyboard with the following keys:
A
Ctrl+A
Ctrl+C
Ctrl+V
where CTRL+A, CTRL+C, CTRL+V each acts as one function key for “Select
All”, “Copy”, and “Paste” operations respectively.
If you can only press the keyboard for N times (with the above four keys
), please write a program to produce maximum numbers of A. If possible,
please also print out the sequence of keys.
Th... 阅读全帖
i*********7
发帖数: 348
22
来自主题: JobHunting版 - Leetcode OJ的编译器是?
哇。leetcode大神直接来回复我。。。orz...
是那题 add binary的。你的test cases里面有25%左右过不了。
但是我把那些过不了的test case放到我自己的x-code ide上,又得到和你expected一
样的答案。
string addBinary(string a, string b) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int next = 0;
int length = max(a.size(),b.size());
char *res = new char[length + 1];
memset(res,0,length);
int count1,count2;
count1 = a.size() - 1;
count2 = b.size() - 1;
while(count1 >= 0 || count2 >= 0)
{
... 阅读全帖
k***x
发帖数: 6799
23
来自主题: JobHunting版 - Leetcode OJ的编译器是?
跪了,原来这位leetcode大佬是老中。。。
j******2
发帖数: 362
24
啊,权威回答!
终于明白为什么全部leetcode都用pass by reference了。。。一直的一个puzzle。
谢谢:)
看来以后递归里的参数能用pass by reference要尽量用pass by reference。
s*****1
发帖数: 134
25
来自主题: JobHunting版 - Leetcode WildCard Matching
hi,
做Leetcode WildCard Matching 时间上怎么也通不过大测试,已经用了DP了
版上有哪位大牛能否给个java(只要java) 写的能通过的版本,让小弟我瞻仰一下,
谢谢啦!!!
非常感谢!
p*******8
发帖数: 344
26
来自主题: JobHunting版 - LeetCode construct Binary Tree
其中有个input是inorder=[1,2], preorder=[2,1],eclipse里面跑了没错误,结果也是
正确的,为什么leetcode judge 就说runtime error? 有什么限制吗?inorder/
postorder也有这个问题,做过的大侠说说看?
D***n
发帖数: 149
27
不是一样的吧。
150上的是sub square matrix... leetcode上的是sub rectangle啊...
I********T
发帖数: 22
28
题目是leetcode上online judge的combination, 就是n个数(1,2,3,4...n)找k个数的
combination. 一般都用递归做,可是这样就会把有些combination重复算。 比如: C(
n,k) = C(n-1, k-1) + C(n-1, k) = C(n-2, k-2) + C(n-2,k-1) + C(n-2,k-1) + C(n
-2, k). 这样C(n-2,k-1)就重复了。 如果用dp做的话就可以缓存C(n-2,k-1)的结果。
这两种复杂度各是多少呢? 我觉得递归做是C(n,k),因为复杂度公式和combination计
算公式一样。 dp做好像是N*k (假设我们用table缓存结果)。 可是由于table里每个
格子的存的元素数目大于一,所以复杂度还是C(n,k)。
这样的话是不是说dp在这个问
题上毫无优势? 谢谢
Z***A
发帖数: 33
29
来自主题: JobHunting版 - 3sum on LeetCode OJ
java用的不好见笑了,但是leetcode要求的返回类型就是ArrayList Integer>>
public class Solution {
public ArrayList> threeSum(int[] num) {
// Start typing your Java solution below
// DO NOT write main() function

}
}
m******8
发帖数: 41
30
来自主题: JobHunting版 - 请教leetcode上的count and say
leetcode上的count and say这题,是一个什么思路?我在另一个帖子上有看到这题的
代码,但是我水平较低,主要想请教一下这题是什么思路。
Count And Say
The count-and-say sequence is the sequence of integers beginning as follows:
1, 11, 21, 1211, 111221, ...
1 is read off as "one 1" or 11.
11 is read off as "two 1s" or 21.
21 is read off as "one 2, then one 1" or 1211.
Given an integer n, generate the nth sequence.
Note: The sequence of integers will be represented as a string.
我看到的帖子是在,http://www.mitbbs.com/article_t/JobHunting/32147785.html
谢谢
C***U
发帖数: 2406
31
来自主题: JobHunting版 - 请教一道Leetcode 题,多谢
如果是leetcode那个要求的话 你就从上往下走 然后存的时候倒着存就可以了‘啊

nodes
s*****n
发帖数: 162
32
来自主题: JobHunting版 - 通过leetcode发来的邮件,求解。
leetcode进军social network
g**********y
发帖数: 14569
33
来自主题: JobHunting版 - 通过leetcode发来的邮件,求解。
我觉得此事有蹊跷,背后一定有一个天大的秘密:那就是leetcode会把做题好的和公司
的猎头match,自动进入on-site状态;做题不好的和婚恋公司match, 也别找工作了,
找户人家好好过日子,LD赚钱就行了。
l***i
发帖数: 1309
34
来自主题: JobHunting版 - 通过leetcode发来的邮件,求解。
me 3, leetcode got hacked.
s*****n
发帖数: 162
35
来自主题: JobHunting版 - 通过leetcode发来的邮件,求解。
leetcode进军social network
g**********y
发帖数: 14569
36
来自主题: JobHunting版 - 通过leetcode发来的邮件,求解。
我觉得此事有蹊跷,背后一定有一个天大的秘密:那就是leetcode会把做题好的和公司
的猎头match,自动进入on-site状态;做题不好的和婚恋公司match, 也别找工作了,
找户人家好好过日子,LD赚钱就行了。
l***i
发帖数: 1309
37
来自主题: JobHunting版 - 通过leetcode发来的邮件,求解。
me 3, leetcode got hacked.
t**********h
发帖数: 2273
38
来自主题: JobHunting版 - 通过leetcode发来的邮件,求解。
leetcode,你完了,敢和jiaoyou8抢生意,老邢就快要对你封账号,封ip了
h****n
发帖数: 1093
39
Best Time to Buy and Sell Stock II
Say you have an array for which the ith element is the price of a given
stock on day i.
Design an algorithm to find the maximum profit. You may complete as many
transactions as you like (ie, buy one and sell one share of the stock
multiple times). However, you may not engage in multiple transactions at the
same time (ie, you must sell the stock before you buy again).
Leetcode上这个题是不是有问题。。
我把上升段加一起就可以通过全部的test cases
难道题就这么简单?
class Solution {
public:
int maxP... 阅读全帖
h****n
发帖数: 1093
40
Best Time to Buy and Sell Stock II
Say you have an array for which the ith element is the price of a given
stock on day i.
Design an algorithm to find the maximum profit. You may complete as many
transactions as you like (ie, buy one and sell one share of the stock
multiple times). However, you may not engage in multiple transactions at the
same time (ie, you must sell the stock before you buy again).
Leetcode上这个题是不是有问题。。
我把上升段加一起就可以通过全部的test cases
难道题就这么简单?
class Solution {
public:
int maxP... 阅读全帖
p****c
发帖数: 35
41
Is the leetcode answer correct?
In the "judge large", the given answer to [1, 2, 4, 7] is 6. However, if I
buy at 1 and 2, then sell at 4 and 7, my profit will be (4 - 1) + (7 - 2) =
8. Am I missing anything?
Thanks.
s*****1
发帖数: 134
42
来自主题: JobHunting版 - 关于leetcode的combinationSum题
用java做了leetcode的combinationSum,其实就是DP,
我造了一个ArrayList> 的二维数组,假设数组名为 comb,
我从comb[0][0] 一直到 comb[input数组长度][target]开始DP,
我想算法没问题,但可能太耗空间了,一直是runtime error
我想请问版上是否有高人,给个这题的java版本,能够通过online的大小数据测试?谢
谢啦
c++版本我已经搜过了
s*****1
发帖数: 134
43
来自主题: JobHunting版 - Leetcode上面的股票买卖问题2
前几天还有人说此题太简单,不适合进leetcode,其实我觉得比较难的,因为我花了一
小时才理清思路,你可以翻11月3日的贴子,那个是对的
e***s
发帖数: 799
44
ihas1337code 大哥, 为什么会这样呢?是不是最近上LEETCODE的人多了?
Q*******e
发帖数: 939
45
来自主题: JobHunting版 - leetcode divde 2 integers 算法局限
当数目是INT_MIN的时候, 算法有bug
leetcode的解决方法是声明long int
有没有其他更clean的方法
m***k
发帖数: 946
46
来自主题: JobHunting版 - leetcode一道题
leetcode里这道题有一个test case没有看明白,能请哪位给解释一下么?
input: [1,2,4,3] expect: 4
Container With Most Water
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.
b***i
发帖数: 3043
47
来自主题: JobHunting版 - leetcode提示Last executed input
leetcode给你许多测试数据,
LEI 就是出错前最后的测试数据。可能是你的程序对这个数据处理过程死机了,超时了
等。
p*g
发帖数: 141
48
为什么不自己试试能不能过leetcode 的OJ
我当时调试了一阵, 最终过了
如果你fail了几个case,那很可能你的算法有地方有问题

==
d*********g
发帖数: 154
f*****t
发帖数: 106
50
来自主题: JobHunting版 - 问问LEETCODE怎么攻克
俺是转行想找计算机相关的工作,听人说LEETCODE好,得做1-3遍,于是过去看看。
看到主页上有一些题,还有其他的一些比如FORUM的LINK。
是不是主要看那个“interview question online judge”那一部分?
感觉网站上内容很多,新手一时无从下手,所以问问大家都是怎么开始的
还是随便找个题就开始?
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)