s*********9 发帖数: 53 | 1 public class Solution {
public ListNode insertionSortList(ListNode head) {
// IMPORTANT: Please reset any member data you declared, as
// the same Solution instance will be reused for each test case.
ListNode dummy = new ListNode(0);
while(head!=null){
ListNode tmp = head;
ListNode pre = dummy;
while(pre.next!=null && pre.next.val < tmp.val){
pre = pre.next;
}
head = head.next;... 阅读全帖 |
|
I**********s 发帖数: 441 | 2 // IMPORTANT: Please reset any member data you declared, as
// the same Solution instance will be reused for each test case.
在public void recoverTree(TreeNode root) {}开始加上这一句就可以了:
badNode1 = badNode2 = prev = null; |
|
k****r 发帖数: 807 | 3 我是这样写的,但是不能通过,
ListNode *insertionSortList(ListNode *head) {
// IMPORTANT: Please reset any member data you declared, as
// the same Solution instance will be reused for each test case.
if (head == NULL || head->next == NULL) return head;
ListNode dummyHead(INT_MIN);
(&dummyHead)->next = head;
ListNode *cur = head->next;
while (cur) {
ListNode *pre = &dummyHead;
while(pre->next && pre->next->val < cur->val) pre = pre... 阅读全帖 |
|
b*********s 发帖数: 115 | 4 public class Solution {
public ArrayList postorderTraversal(TreeNode root) {
// IMPORTANT: Please reset any member data you declared, as
// the same Solution instance will be reused for each test case.
ArrayList res = new ArrayList();
visit(res, root);
return res;
}
private void visit(ArrayList res, TreeNode root) {
if (root == null) return;
visit(res, root.left);
visit(res, root.r... 阅读全帖 |
|
b*******n 发帖数: 8 | 5 做了这道题,被accepted, 但觉得代码很罗嗦冗长。
怎么改进呢?
/**
* Definition for singly-linked list.
* class ListNode {
* int val;
* ListNode next;
* ListNode(int x) {
* val = x;
* next = null;
* }
* }
*/
class ListNodeWrapper {
ListNode start;
ListNode end;
}
public class Solution {
private ListNode partionList(ListNode start, ListNode end) {
ListNode end1 = start;
ListNode fast = start;
while (fast != end) {
fast = fast.next;
... 阅读全帖 |
|
g*********e 发帖数: 14401 | 6 我的也很长,但不用每个recursion都寻找中间node的位置。
class Solution {
public:
ListNode *merge(ListNode *a, ListNode *b, ListNode *&last) {
ListNode *res=NULL;
ListNode *prev=NULL;
while(a && b) {
if(res==NULL)
res=(a->val < b->val) ? a:b;
if(a->val < b->val) {
if(prev)
prev->next=a;
prev=a;
a=a->next;
} else {
if(prev)
prev->next=b;... 阅读全帖 |
|
c**z 发帖数: 669 | 7 vector inorderTraversal(TreeNode *root) {
// IMPORTANT: Please reset any member data you declared, as
// the same Solution instance will be reused for each test case.
vector ret;
stack s;
for( ; ; )
{
if ( root != NULL)
{
s.push(root);
root = root->left;
}
else
{
if ( s.empty())
return ret;
else
{
... 阅读全帖 |
|
s********u 发帖数: 1109 | 8 struct Line{
double slope;
double intercept;
Line(Point p, Point q){
if(p.x == q.x){
slope = numeric_limits::max();
intercept = p.x;
}else{
slope = (double)(p.y - q.y)/(double)(p.x - q.x);
intercept = p.y - slope * p.x;
}
}
};
struct Comp{
static double eps;
bool operator()( const Line &l1, const Line &l2){
if( l1.slope - l2.slope < -eps )
... 阅读全帖 |
|
b******p 发帖数: 49 | 9 我来贴个CPP的(注意:以下有乱七八糟的code……)
合并排序确实比较好用,我还在写第一遍leetcode,代码风格也比较乱,带了很多
debug code,还带了测试用例,试了9次才通过…
有一些多边界条件需要判断的。我的方法是加很多debug,或加很多assertion(我做别
的题里面经常用assertion……不知道是不是好习惯)
============================
#include
#include
using namespace std;
/*
Merge sort ?
*/
// Start: 22:40
// End: 23:45 用了一个小时
//Definition for singly-linked list.
struct ListNode {
int val;
ListNode *next;
ListNode(int x) : val(x), next(NULL) {}
};
#define TOMMYDBG
class Solution {
public:
... 阅读全帖 |
|
S******6 发帖数: 55 | 10 pass了,不过不是replace
class Solution {
public:
ListNode *sortList(ListNode *head) {
// IMPORTANT: Please reset any member data you declared, as
// the same Solution instance will be reused for each test case.
vector res;
if(head == NULL || head->next == NULL) return head;
ListNode *cur = head;
while(cur)
{
res.push_back(cur->val);
cur = cur->next;
}
sort(res.begin(), res.end());
ListNode ... 阅读全帖 |
|
y*****3 发帖数: 451 | 11 看到网上每个人都说是用DP解法,其实不就是个最普通不过的iterative解法吗?为什
么大家都把这个叫DP解法??
网上最流行的解法:
public int climbStairs(int n) {
// Note: The Solution object is instantiated only once and is reused
by each test case.
if (n==1) return 1;
if (n==2) return 2;
int f1 = 1;
int f2 = 2;
int fi = 0;
for(int i=3; i<=n; i++)
{
fi = f1 + f2;
f1 = f2;
f2 = fi;
}
return fi;
} |
|
d********e 发帖数: 239 | 12 ListNode *sortList(ListNode *head) {
// IMPORTANT: Please reset any member data you declared, as
// the same Solution instance will be reused for each test case.
if(head == NULL || head->next == NULL) {
return head;
}
ListNode* mid = head;
ListNode* end = head;
while(end->next){
end = end->next;
if (end->next == NULL)
break;
end = end->next;
mid = mid->next;... 阅读全帖 |
|
n********e 发帖数: 41 | 13 楼主 看到 你 isDiffByOne 函数就知道你必然要超时
Leetcode免费给你用 就别挑剔了。凡事要先从自身找问题
你那个测试不是大数据
真正的大数据在这里:
start = "nanny";
end = "aloud";
String[] d = {"ricky","grind","cubic","panic","lover","farce","gofer
","sales","flint","omens","lipid","briny","cloth","anted","slime","oaten","
harsh","touts","stoop","cabal","lazed","elton","skunk","nicer","pesky","
kusch","bused","kinda","tunis","enjoy","aches","prowl","babar","rooms","
burst","slush","pines","urine","pinky","bayed","mania","light","flare","
wares","wom... 阅读全帖 |
|
a********e 发帖数: 53 | 14 class Solution {
public:
Write a function to find the longest common prefix string amongst an array
of strings.
The Time complexity is O(logM * N), while M is the size of strs, N is the
shortest length of the str in the strs
而我觉得这个时间复杂度应该是O(MN). 因为isEqual()的复杂度应该是O(M), as T(M
) = 2T(M/2) + O(1). 谢谢。
============================
bool isEqual(vector &strs, int index, int start, int end) {
if(end < start) return true;
if(end == start) {
if(strs[start].size() > index) return ... 阅读全帖 |
|
p*****2 发帖数: 21240 | 15
longway的解法比较靠谱,注意一下reuse。 |
|
p*****2 发帖数: 21240 | 16
longway的解法比较靠谱,注意一下reuse。 |
|
g***j 发帖数: 1275 | 17 为啥这个可以过? 下面这个时间复杂度是 O^3 吧?
class Solution {
public:
vector > fourSum(vector &num, int target) {
// Note: The Solution object is instantiated only once and is reused
by each test case.
vector tmp;
vector> results;
if(num.empty()) return results;
sort(num.begin(), num.end());
for(int i=0; i
{
for(int j=i+1; j
{
int temp ... 阅读全帖 |
|
m******3 发帖数: 346 | 18 应该不是N^3,最里面一层是binary search, 应该复杂度是N^2LogN
reused |
|
A****L 发帖数: 138 | 19 这个事我以前开的帖子。
http://www.mitbbs.com/article_t0/JobHunting/32682961.html
代码如下:
public class Solution {
public class Ladder {//Define Ladder class it's important
public ArrayList parentList;
public String word;
public Ladder(String w, Ladder parent) {word=w; parentList = new
ArrayList(); parentList.add(parent);}
}
ArrayList> ladders=new ArrayList>();;
public ArrayList> findLadders(String sta... 阅读全帖 |
|
A****L 发帖数: 138 | 20 这个事我以前开的帖子。
http://www.mitbbs.com/article_t0/JobHunting/32682961.html
代码如下:
public class Solution {
public class Ladder {//Define Ladder class it's important
public ArrayList parentList;
public String word;
public Ladder(String w, Ladder parent) {word=w; parentList = new
ArrayList(); parentList.add(parent);}
}
ArrayList> ladders=new ArrayList>();;
public ArrayList> findLadders(String sta... 阅读全帖 |
|
w**********9 发帖数: 105 | 21 我这个解法也》30行,
int candy(vector &ratings) {
// Note: The Solution object is instantiated only once and is reused
by each test case.
int sum = ratings.size();
int r=0, l=0, nsum=0;
for (int i=1; i
if (ratings[i]>=ratings[i-1]) {
if (l<0) {
sum += -1*(nsum-l);
if (r+l<0) sum += -1*(r+l);
l=0;
nsum = 0;
r= (rating... 阅读全帖 |
|
|
l*****a 发帖数: 14598 | 23 着两端的code是否应该reuse呢
if (prev+1==a[i]-1)
System.out.println(prev+1);
else
System.out.println((prev+1) + "-" + (a[i]-1));
if (a[i]==98) System.out.println(99);
else System.out.println((a[i]+1)+"-"+99); |
|
N**********i 发帖数: 34 | 24 从7月份到现在,磕磕盼盼终于拿到了FB的offer,准备从了。就此做个总结,希望能对
还在找工作的朋友们有所帮助...
准备: lc(没刷完,但是有些高频题做了好几遍,还有水中的鱼的博客),cc150(先
刷了一遍,然后又看了好几遍,反复看了书中的一些不错的解法),g4g(稍稍做了一
些题),各大面经、版上大牛总结帖。我不是new grad(2年工作经验),所以简历上的
工作时的projects好好准备了一下。
整体感觉就是:
1. 被拒多半还是实力问题+少许运气问题。onsite interview最好保证每一轮都不差(
哪怕都没有很突出),否则就很容易悲剧。所以还是得要多做题甚至多面试找感觉
2. 最有用的是lc+面经+大牛总结,面试时至少有30%-50%会遇到类似甚至一样的
3. bug free很难做到,也没啥必要. 之前有人说FB要求bug free被吓到了,但是感觉
思路+clean code更重要
4. 在三三面试官面前不要害怕,反正你做的多好他们都可以想办法阴你,还不如放松
心态跟他们好好一战
L(电面跪了)
HR分组的时候有点奇怪,分到了类似Site Reliabil... 阅读全帖 |
|
|
a*********i 发帖数: 86 | 26 国人哥们主面, 小印跟班. 面Backend infra
给了一道这样的题
/*
Question Description: You are to write an abstraction layer for a persistent
buffer. Provide an implementation of the following abstract class:
*/
public abstract class pBuffer {
protected final int BLOCK_SIZE = 1024;
protected final int BLOCK_COUNT = 1024;
protected byte[] buffer = new byte[BLOCK_COUNT * BLOCK_SIZE]; // A sample
1mb buffer, to be allocated in 1k chunks.
public pBuffer() {
fillBufferFromFile(); // Reads the buffer from file an... 阅读全帖 |
|
b**********5 发帖数: 7881 | 27 code refactoring is not the same as coding standard...注意modularize code,
reuse code, basically code design。。。我本人对这个也比较anal。。。 |
|
b******b 发帖数: 713 | 28 if you can reuse the char, then the trie solution above is the best. sorry
didn't read it carefully. |
|
p******o 发帖数: 4 | 29
澄清一下: N 定义为 size of input list. K 定义为 number of list.
递归调用 merge 2 sorted list: 每次merge N*K records, 递归树深度 lg(K). 所
以我回答 N*K* lg(K)
Heap: heap size K, total N*K records. 也是 N * K * lg(K)
主要问题是在实际应用中 recursive merge 2 sorted 需要多次读写disk. 我一开始回
答说merge K list 可以 code-reuse merge 2 list (本来以为要写code, 已经写了
merge 2 sorted, 写一个新函数就可),但这显然不是他想听到的 |
|
g********s 发帖数: 3652 | 30 Email [email protected]
/* */
Hello everyone,
There are several Contract roles that don't require prior Wall Street
experience.
Please send me your resume if you were interested.
1. Barclays, Java/J2EE
2. Citigroup, Warren, NJ, Java/Spring/DesignPattern/Oracle. Multi-threading
3. Bridgewater, in Westport CT, C# high level 900/day
Software Developer/Engineer: Responsible for reusing and applying patterns
to enable our technology consolidation. These developers are responsible
for adding ... 阅读全帖 |
|
g*****9 发帖数: 4125 | 31 I visited a friend in Toronto last year, they had this installed in their
home. I like it so much, I put one in my house too.
Drain water heat recovery is the use of a energy recovery heat exchanger
technology to recover and reuse hot water heat from various activities such
as dishwashing, clothes washing and especially showers. The technology is
used to reduce primary energy consumption for domestic water heating.
Standard units save up to 60% of the heat energy that is otherwise lost down
the |
|
g*****9 发帖数: 4125 | 32 Assume your stove is 30 inch wide and you have a cabinet is also 30 inch
wide. You can just swap them and get new counter top, not too bad in cost.
Move or adding some gas piping is at most half day work if the cabinets are
out of the way.
It is really hard to give you a number with out more detail. For example,
corian counter top can be reused, they can cut and seam again using your
existing pieces, so just a little labor is involved. |
|
|
g*****9 发帖数: 4125 | 34
If you do this yourself, you might be able to reuse the studs, so the cost
is only some new sheet rock (green kind) and maybe a few studs.
Yes, you can just frame a closet. |
|
s***2 发帖数: 240 | 35 I did not get dish installed in my house because the tall tree block all the
signal, the installation was cancelled. I guess someone else can reuse that
code. |
|
g*****9 发帖数: 4125 | 36 All the water I use for my lawn is grey water, even the energy to run the
computer and pump come from solar and wind.
I try to live as green as posible, I still have a little over 900 cubic
meter of grey water left in my tank according to the computer, which should
be enough to last this season.
I even collect the little bit of water come from AC to reuse.
Transpiration by lawn is a major part of water cycle system and there is no
shortage of fresh water in north east us (Great lakes alone have |
|
g*****9 发帖数: 4125 | 37
http://www.hydroponicsonline.com/
室内还是室外?
Both
种子也需要特殊的?
No, just regular.
This is just a more clean on controlled way to grow vegetables or plants.
Here is some of the reason why is better:
No soil is needed
The water stays in the system and can be reused- thus, lower water costs
It is possible to control the nutrition levels in their entirety- thus,
lower nutrition costs
No nutrition pollution is released into the environment because of the
controlled system
Stable and high yields
Pests and d |
|
w*****y 发帖数: 760 | 38 是指这样么?
How Saltwater Pools Work
Step 1
Add a chlorine generator to your pool's plumbing system. The generator works
with salt added to the water to produce the active chlorine required to
keep your pool water clean, so you don't need to continually add chlorine
and other chemicals.
Step 2
Start the conversion by adding salt to your pool water. The amount of salt
your pool requires will depend on the size of your pool, however a working
estimate is 50 pounds of salt per 1,200 gallons of capacity.... 阅读全帖 |
|
x*****i 发帖数: 4035 | 39 microfiber cloths
wipe, wash, dry and reuse |
|
g*****9 发帖数: 4125 | 40 Rubbermaid Hygen cloth.
You can wash and reuse (do not use softener) |
|
m***y 发帖数: 14763 | 41 Did you reuse the water after rinsing rice? |
|
p**********g 发帖数: 9558 | 42 传统的方法是安装一个quarter round的边条贴在baseboard上,盖住木地板和
baseboard的间隙。也有把baseboard拆掉,用baseboard盖住gap的,请人做的话,不会
reuse这个baseboard,会买新的。
如果baseboard不够高的话,安装quarter round的边条不一定好看。
工具估计你会花2k左右.
base |
|
h****u 发帖数: 45 | 43 那如果都换得话,是不是就不要用R22了?我看帖子里的同学都用R410A。铜管可以
reuse吧? |
|
f****i 发帖数: 20252 | 44 My last setup cost me around $1k. If I can do it again, I would get a better
mic, maybe the SM58.
The receiver and speaker can be reused for home theater purpose.
can |
|
a********a 发帖数: 3082 | 45 buy a towel stand(can be over the door type) and let it dry before reuse/put
to laundry basket |
|
p**********g 发帖数: 9558 | 46 reuse baseboard一般都没有问题吧 |
|
l******g 发帖数: 6771 | 47 是,wasp一年每年消亡,蜂皇第二年另找地方,一般也不reuse以前的巢,所以一般晚
秋的wasp都不用理会了,等他死了清理就好
蜜蜂就不是了,冬天不死的 |
|
|
f*1 发帖数: 837 | 49 A healthy lawn needs 4-6" of good topsoil (not subsoil like the yellow one).
If you want to save money and have the extra time and energy, you can try
this: Say the current hole is 5" deep, so you cut the grass (like sod),
water it and save it aside. The grass is probably 2", so the hole is about
7" deep. You dig 5" down and those soil should be the old topsoil you can
reuse later. Now the hole is about 12" deep. You fill it with about 5.5"
yellow soil. Jump on it or compact it, but don't o... 阅读全帖 |
|
x****u 发帖数: 12955 | 50
That's an under mount sink. There should be some mounting clip under the
counter that attaches the sink to the counter. Remove those, then use a
thin knife to cut the silicon sealant between sink bowl and counter, the
sink should come loose from the counter. Make sure you have something to
support the sink while you are doing this so it doesn't fall 3 feet and
crash your cabinet.
Then you need to find a new sink bowl with exact physical dimension, and I
mean very exact. Otherwise you won't ... 阅读全帖 |
|