由买买提看人间百态

topics

全部话题 - 话题: helpers
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
j******g
发帖数: 40
1
来自主题: Seattle版 - Household Helper/Nanny available
Mandarin speaking household helper, available Monday to Friday in the
afternoon, 3-4 hours per day. Services include but not limited to picking up
kids, cooking, cleaning. Eastside preferred. If interested, please send private email.
T****a
发帖数: 4651
2
I don't know if anyone has shared the experience as a helper, rather than a
runner, in a marathon. Well, I'm going to get that experience first hand on
Nov 21 at Philly marathon.
Several running buddies at our RC are going to run their very first FM, and
our coach is asking us who aren't running that day to help out. We will man
a water station at the 10/20 mile marker, and run the last 10K with one or
more of our buddies.
I know a few on this board are running at Philly, so if you tell me your ... 阅读全帖
n*****k
发帖数: 11
3
来自主题: Software版 - Element hiding Helper是个好东西
Firefox里面加上插件Adblock Plus这个不用说了,干掉了大部分广告。但是有些广告
还是能躲过Adblock Plus的手心,这时候,Element hiding Helper就大显身手了。
这个附件是没有Adblock Plus时,看到的mitbbs首页
n*****k
发帖数: 11
4
来自主题: Software版 - Element hiding Helper是个好东西
还是不爽,上面的空白,和少量的广告,以及下面我不关心的“移民专栏”,“赞助链
接”,“海外人才网”,统统都可以通过Element Hiding Helper干掉
下面看起来爽快多了
h******y
发帖数: 351
5
来自主题: Biology版 - Paper help - 2 Baozi for 1st helper
Please send me a copy of this paper to z*****[email protected]
Cells Tissues Organs. 2007;186(3):157-68. Epub 2007 Jul 26.
http://www.karger.com/Article/FullText/106670
http://www.ncbi.nlm.nih.gov/pubmed/17657137
Please include your mitbbs ID in the email and 2 baozi will be sent to the
1st helper.
Thanks a lot.
w*******y
发帖数: 60932
6
at lowes:
http://www.lowes.com/pd_314797-16878-61461_0__?catalogId=10051& &Ntt=314797 &N=0&langId=-1&storeId=10151&rpp=24
also 50% off:
LIL HELPER 20-Piece Carpenter's Tool Kit for Kids $9.95 at lowes:
http://www.lowes.com/ProductDisplay?partNumber=314795-16878-539
G**Y
发帖数: 33224
7
摘自05年的信,按当时的估计,花街每年拿走了美国企业20%的增长。
如果这个估计正确的话,如果没有花街吸血,美股应该是现在6倍的价格?!
To understand how this toll has ballooned, imagine for a moment that all
American corporations are, and always will be, owned by a single family. We
’ll call them the Gotrocks. After paying taxes on dividends, this family –
generation after generation – becomes richer by the aggregate amount
earned by its companies. Today that amount is about $700 billion annually.
Naturally, the family spends some of these dollars. But the por... 阅读全帖
T******7
发帖数: 1419
8
class Solution {
public:
int helper(vector &num, int st, int end) {
if (st == end)
return num[st];
if (end - st == 1)
return (num[st] > num[end]) ? num[end] : num[st];
int mid = st + (end - st + 1) / 2;
if (num[mid] > num[end]) {
if (num[end] <= num[st])
return helper(num, mid, end);
else
return helper(num, st, mid);
}
else if (num[mid] < num[end]) {
... 阅读全帖
w****3
发帖数: 110
9
来自主题: JobHunting版 - 请教一道, leetcode题.
我贴一个,另外可以直接用linkedhashmap做,设为accessOnly直接用
removeeldestentry,只要几行就能写完。下面的是自己用doubleLinkedList做的。
public class LRUCache {
HashMap data = new HashMap DoubleLinkedListNode>();
int cap;
int count = 0;
DoubleLinkedListNode head = null;
DoubleLinkedListNode helper;
public LRUCache(int capacity) {
cap = capacity;
helper = new DoubleLinkedListNode(-1,-1);
head = helper;
}

public int get(int key) {
... 阅读全帖
T******7
发帖数: 1419
10
写了一个很丑的code.
求拍。
public class uniValueTree {
public int countUniTree(TreeNode root){
if(root.left == null && root.right == null) return 1;

return helper(root);
}

private int helper(TreeNode node){
if(node.left == null && node.right == null){
return 1;
}
if(node.left == null){
if(isUni(node.right)){
if(node.val == node.right.val){
return 1 + helper(node.right);
... 阅读全帖
a***e
发帖数: 413
11
知道要O(1)space的得用Morris Traversal。但想先写个简单的,却发现改了好几次。
1。 开始没想清楚怎么把那两个错误的node找出来
2. 应该用*& 的地方用了*。 后来发现不作为param来pass还更简单。
但这样也有很多行,等有时间写个Morris的比较下。感觉也不是那么简单啊,sigh!
class Solution {
public:
TreeNode *first, *second, *pre;
void helper(TreeNode *cur)
{
if (cur==NULL)
return;

helper(cur->left);
if (pre)
{
if (pre->val>cur->val)
{
if (first==NULL)
{
first = pre;
sec... 阅读全帖
c*********y
发帖数: 135
12
来自主题: JobHunting版 - 问一道google面经
这是我写的代码。大体测了下。
class Solution {
public:
int helper(TreeNode * root, int &global_max){
//this returns max value of the subtree root
//global_max is the results value we are looking for
if(root==NULL)return 0;
int left = max(0,helper(root->left, global_max)); // the key point
is here that we make the return value always larger than or equal to zero.
int right = max(0,helper(root->right, global_max));
int left_next = root->left?max(helper(root->le... 阅读全帖
k****r
发帖数: 807
13
来自主题: JobHunting版 - 一道facebook面试题
some logic as follows:
helper(s, 0, 0, "", res, new HashSet set);
public void helper(String s, int idx, int blc, String tmp, List res,
Set set) {
if (idx == s.length()) {
if (blc == 0 && !set.contains(tmp)) {
res.add(tmp);
set.add(tmp);
}
return;
}
if (s.charAt(idx) == '(') {
helper(s, idx + 1, blc + 1, tmp + "(", res);
helper(s, idx + 1, blc + 1, tmp, res);
} else if (s.charAt(idx) == ')') ... 阅读全帖
l*3
发帖数: 2279
14
来自主题: JobHunting版 - 讨论下lc最新的那道hard题吧
我的c++过了。之前也是超时,改进方法就是要把每一步临时算出来的结果保存,不要
在最后的时候重复算。不过说实话我觉得这个影响不大,理论上讲无非就是把一个最坏
是 O(n * 4^n) 的东西降到了 O(4^n),少了一个factor而已,不过确实是过例子很快
。。只要44ms(我不知道超时一般判定是多少,不过之前有的题跑了600ms也算过了,
不过也不知道是不是所有题的超时判定都一样?我估计是1000ms,如果这么说的话其实
实际上改进还挺大)
贴一段我的代码,最tricky的地方就是楼上说的,你需要知道这些:
乘法运算的优先级比加减法高,所以你要保存一个 “连乘串” 的结果。直到你某一步
走到了某个你想插入加减法的地方,你才把连乘串的结果去添加到临时的sum结果中,
否则就要一直保留。
另外什么是加法和减法呢?其实就相当于你update你临时的sum,并且把新的乘积起始
点赋值成 1 (对应加法) 或者 -1 (对应减法)
code 如下:
class Solution {
public:
//主函数,没有干什么大事,就是预处理一下字符串,把两个位置之间的字符转换的整
数结果都保存下... 阅读全帖
m******y
发帖数: 219
15
来自主题: JobHunting版 - 求指点一个G家题
照着leetcode原题改的,这个case可以过,但是仅仅用curr_res == target来加入结果
感觉不够,必须要所有的数都visited。
public class Solution {
public static void main(String[] args) {
int[] nums = {1,2,3, 60, 7};
System.out.println(get(nums, 48));
}
public static List get(int[] nums, int target) {
List result = new ArrayList<>();
if (nums == null || nums.length == 0) return result;
boolean[] visited = new boolean[nums.length];
helper(nums, 0, 0, target, visited, ... 阅读全帖
B****e
发帖数: 124
16
1 以前我家的helper开车。现在我们住DT,helper住的远的做地铁,近的骑自行车
2 靠这份工资生活的helper另外有别的小时工作。因为我家用了晚饭时间,其他的只能
做打扫卫生,看孩子之类的没有时间要求的零工。还有的helper是移民来的,老公养家
,自己挣些零用钱,并不靠着生活,有就做,没有就算。
3 我一般一周付一次钱。有时周中出去不需要helper来,那周就少给那一天,事先讲好
helper都OK。他们偶尔也会打电话来说孩子学校有事来不了,也没关系。
4 我住湾区的时候helper是同事推荐的。不过我知道可以在中文报纸上登广告,有网络
版,很方便,我在上面找过保姆。比如这个世界日报,应该还有别的报纸
http://sf.worldjournal.com/
选分类 --》家庭聘请
比如下面这条广告
內容: 位Cupertino請鐘點阿姨,做晚餐(會做上海菜或川菜)有意請電:(408)-660-
6529
A*******e
发帖数: 2419
17
来自主题: Programming版 - 请教unit test的best practice
比如有这样一个类。
class Foo {
public:
void A() {
Helper();
...
}
void B() {
Helper();
...
}
private:
void Helper() {
// complicated logic
}
};
A和B共享了复杂代码。写unit tests时,需要对A和B分别写一套测试吗?如此很多工作
都重复了。
还有一个办法是让Helper public,单独写针对Helper的测试,简化A和B的测试。可是
这样需要假定用户知道A和B的实现都是依赖于Helper,违背了写测试只针对接口,不针
对实现的原则。
或者干脆把Helper提取出来作为一个类,然后A和B的数据成员使用这个类。如此解决了
上一个想法里的问题,但这样似乎又过于复杂。
大家是怎么处理这种情况的?
c***d
发帖数: 26
18
来自主题: JobHunting版 - [难题求助] leetcode wordsearch
这题野蛮暴力就能通过大case呀。
public class Solution {
public boolean exist(char[][] board, String word) {
// Start typing your Java solution below
// DO NOT write main() function
if (board==null) return false;
boolean visited[][] = new boolean[board.length][board[0].length];
for(int i = 0; i < board.length; i++) {
for(int j = 0; j < board[0].length; j++) {
if (helper(board, visited, word, i, j, 0)) return true;
}
}
... 阅读全帖
h****n
发帖数: 1093
19
来自主题: JobHunting版 - 明天A家onsite
写了最后那个,没测,大牛测测
void helper(vector > &Input, int i, int j, int n, int m)
{
if(i<0||i>n-1||j<0||j>m-1)
return;

Input[i][j] = -1;

if(i>0&&Input[i-1][j]==1)
helper(Input, i-1, j, n, m);
if(i helper(Input, i+1, j, n, m);
if(j>0&&Input[i][j-1]==1)
helper(Input, i, j-1, n, m);
if(j helper(Input, i, j+1, n, m);
return;
}
int GetAdjArea(vector > input)
{
i... 阅读全帖
s***g
发帖数: 257
20
来自主题: JobHunting版 - G棉经
面试2,给一个NxN的矩阵,找包括连续递增数字最长的子串的长度。比如
4 3 9
6 5 1
7 8 2
这个返回4,因为5,6,7,8,方向可以是上,下,左,右,不可以斜角
写了下第二题的dfs思路(java),大家看下对吗?
static int count = 0;
public static int maxSequentialNumbers(int[][] board){

int len = 0;
if (board == null || board.length == 0) return len;


for (int i=0; i for (int j=0; j count = 1;
helper(board, i, j);
len = Math.max(len, count);
}
}

return len;
}
pu... 阅读全帖
a***e
发帖数: 413
21
嗯,试图写O(1)的,发现用vector把指针装起来,再pass reference容易一些。但是
不知道为啥初始化的时候下面这个不行
vector m(2, NULL);
Compile Error
required from ‘std::vector<_Tp, _Alloc>::vector(_InputIterator, _
InputIterator, const allocator_type&) [with _InputIterator = int; _Tp =
TreeNode*; _Alloc = std::allocator; std::vector<_Tp, _Alloc>::
allocator_type = std::allocator]’
得换成这几行
vector m;
m.push_back(NULL);
m.push_back(NULL);
还没仔细debug 为什么下面这个答案不对,而后面那个就对。
错... 阅读全帖
l***4
发帖数: 1788
22
来自主题: JobHunting版 - 一道Facebook题如何避免溢出
public static long atm(int x) {
long[] arr = new long[x+1];
Arrays.fill(arr, -1);
return helper(arr, x);
}
private static long helper(long[] arr, int x) {
if (x < 0) {
return 0;
}
if (x == 0) {
return 1;
}
if (arr[x] < 0) {
arr[x] = helper(arr, x-1) + helper(arr, x-5) + helper(arr, x-20)
+ helper(arr, x-50);
}
return arr[x];
}
l******t
发帖数: 490
23
来自主题: TrustInJesus版 - 基和穆的神应该是同一个吧?
解答:Allah為什麼有時候用複數代詞“我們”
The Quran, Allah and Plurality Issues (Sam Shamoun)
The Quran, much like the Holy Bible, uses plural pronouns for God even more
so than what we find in God’s true Word. Here are several examples:
This is part of the tidings of the things unseen, which We reveal unto thee
(O Apostle!) by inspiration: Thou wast not with them when they cast lots
with arrows, as to which of them should be charged with the care of Mary:
Nor wast thou with them when they disputed (the point). S... 阅读全帖
l**b
发帖数: 457
24
来自主题: JobHunting版 - 分享Imo电面题
二爷不用DP,奇怪啊!第3题用Trie的话memory吃不消吧?用DP是不是好点?
贴个简单的代码,helper是recursive的,helper2是DP的,2爷帮忙看看,是不是又出
错了:
public boolean isSubSequence(String s, String t) {
assert(s != null && t != null);
if (t.length() == 0) return true;
//return helper(s, t, 0, 0);
return helper2(s, t);
}

private boolean helper(String s, String t, int si, int ti) {
if (ti == t.length()) return true;
if (si >= s.length()) return false;

if (s.charAt(si) == t... 阅读全帖
l**b
发帖数: 457
25
来自主题: JobHunting版 - 分享Imo电面题
二爷不用DP,奇怪啊!第3题用Trie的话memory吃不消吧?用DP是不是好点?
贴个简单的代码,helper是recursive的,helper2是DP的,2爷帮忙看看,是不是又出
错了:
public boolean isSubSequence(String s, String t) {
assert(s != null && t != null);
if (t.length() == 0) return true;
//return helper(s, t, 0, 0);
return helper2(s, t);
}

private boolean helper(String s, String t, int si, int ti) {
if (ti == t.length()) return true;
if (si >= s.length()) return false;

if (s.charAt(si) == t... 阅读全帖
B*****7
发帖数: 137
26
自己写了一个code,和大多数网上的code一样,基本思路就是bfs。但要过大oj还真不
容易。我refactor了半天也只能有大概一半的概率过。过的时候时间都是800 ms 以下
(~750 ms),只有一次到过800 ms. 所以强烈怀疑这道题的时间上限是800 ms. LOL
我附了code,用java写的。大牛们帮忙看看该怎么改进?先谢谢啦。
public class Solution {
public void solve(char[][] board) {
// Start typing your Java solution below
// DO NOT write main() function
int m = board.length;
if( m == 0 ) return;
int n = board[0].length;
// special cases
if( m < 3 || n < 3 ) return;
// p... 阅读全帖
p*****e
发帖数: 537
27
来自主题: JobHunting版 - reorder list 递归方法超时
其实和你的方法差不多啊,你用一个length,我用一个start index和end index。
比如:
0 -> 1 -> 2 -> 3 -> 4 -> 5,
helper(start=0, end=5) calls helper(start=1, end=4). helper(start=1, end=4)
把 1->2->3->4 reverse成 4->3->2->1,还返回5,那么helper(start=0, end=5)就把
header(0)和返回的那个5link起来,再link helper(start=1, end=4)的header就行
了。
a***e
发帖数: 413
28
下面这两个1.2.写法都是O(N^2)吧?为啥2说是O(N)呢?另外,看到lc上一个
discussion的iterative的解法3.https://oj.leetcode.com/discuss/2297/the-
iterative-solution-is-easier-than-you-think
时间复杂度是O(N)吧?
我看了helper的function signature能写出1,对2中用到的好多STL要搜索才能写出来
,不熟。
Binary tree和recursion现在是我最弱处,多谢!
1.
class Solution {
public:
TreeNode *buildTree(vector &preorder, vector &inorder) {
if (preorder.size()==0) return NULL;
else if (preorder.size()==1)
{
TreeNode *t = new TreeNode(preorder[0])... 阅读全帖
h***k
发帖数: 161
29
来自主题: JobHunting版 - 请教一道g算法题
我觉得如果每次只删除叶节点的话就dfs,因为不一定每次删的leaf在同一个高度:
while(root has children) {
helper(root, root.left);
helper(root, root.right);
}
helper(Node parent, Node child) {
if (child has no children){
parent.left/right = null; // check if its left or right of parent.
} else {
helper(child, child.right);
helper(child, child.left);
}
}
当然复杂度有点高。。
k**********i
发帖数: 36
30
►►►Regular Expression Matching
Implement regular expression matching with support for '.' and '*'.
'.' Matches any single character.
'*' Matches zero or more of the preceding element.
The matching should cover the entire input string (not partial).
The function prototype should be:
bool isMatch(const char *s, const char *p)
Some examples:
isMatch("aa","a") → false
isMatch("aa","aa") → true
isMatch("aaa","aa") → false
isMatch("aa", "a*") → true
isMatch("aa", ".*") → true
isMatch... 阅读全帖
l******9
发帖数: 26
31
来自主题: JobHunting版 - F家onsite悲剧了,求refer
我的two cents
public void print(int[] a) {
helper(a, 0, a.length - 1);
}

public void print(int[] a) {
helper(a, 0, a.length - 1);
}
public void helper(int[] a, int left, int right) {
if (right - left < 2) {
return;
}
int mid = left + (right - left) / 2;
if (a[mid] > a[mid-1] && a[mid] > a[mid+1]) {
System.out.println(a[mid]);
} else if (a[mid] < a[mid-1] && a[mid] < a[mid+1]) {
System.out.println(a[mid]);
}
if (Math.abs(a[mid] - a[left]) < mid - left) {
helper(a, left, mid);
}... 阅读全帖
I*B
发帖数: 151
32
来自主题: HongKong版 - 外傭爭取最低月薪四千
they worry about HK allowing mainland women to come work as helper.
they worry about current helpers seducing their husbands.
they worry about helpers getting pregnant in HK.
You can't imagine how mean some of those peole are towards helpers.
see how they prevent helpers from getting pregnant
http://www.baby-kingdom.com/forum.php?mod=viewthread&tid=140678
l*****a
发帖数: 38403
33
New International Version (©1984)
The LORD God said, "It is not good for the man to be alone. I will make a
helper suitable for him."
New Living Translation (©2007)
Then the LORD God said, "It is not good for the man to be alone. I will make
a helper who is just right for him."
English Standard Version (©2001)
Then the LORD God said, “It is not good that the man should be alone; I
will make him a helper fit for him.”
New American Standard Bible (©1995)
Then the LORD God said,... 阅读全帖
z****e
发帖数: 54598
34
来自主题: Java版 - 关于singleton
补充一个真正难的
用final来替换volatile
public class FinalWrapper {
public final T value;
public FinalWrapper(T value) {
this.value = value;
}
}
public class Foo {
private FinalWrapper helperWrapper = null;
public Helper getHelper() {
FinalWrapper wrapper = helperWrapper;
if (wrapper == null) {
synchronized(this) {
if (helperWrapper == null) {
helperWrapper = new FinalWrapper(new Helper());
... 阅读全帖
A*******e
发帖数: 2419
35
来自主题: Programming版 - 请教unit test的best practice
这个只是怎么访问Helper的问题。
我的问题是,假定Helper已经充分测试,如何测试A和B?
如果是纯黑箱测试,用户不知道A和B里都调用了Helper,并且Helper已经充分测试,是
否应该各写一套,分别测试A和B?其中有关Helper的测试用例都重复出现。
s******y
发帖数: 28562
36
来自主题: Biology版 - Invitrogen Neon electorporation system?
老兄,你有没有helper transposase 啊?
我实在是找不到能在mammalian cells 里面用的helper, JHU 的 Nancy Craig 说因为她
做的那个质粒涉及到版权问题不能给别人用,而Notre Dame 的Malcolm J. Fraser主要是
做果蝇里面用的,他们的清单里(http://piggybac.bio.nd.edu/
唯一一个貌似能够在mammalian cell 里面用的helper 是 p3xP3-DsRed1-orf ( The
CMV promoter driven piggyBac ORF helper plasmid. Also contains a 3xP3
controlled DsRed1 genetic maker)。
但是我们要转进去的蛋白正好也是红色的,我不知道这个helper 会不会把它自己的质
粒包括DsRed1 genetic maker 也一道stably转进去?如果也会的话那我们就不能用了!
d*******r
发帖数: 3875
37
http://www.bloomberg.com/news/2011-08-22/philippine-maid-seeks-
Hong Kong’s policy of denying permanent-residence rights to foreign maids is being challenged as unconstitutional, stoking public debate over ethnic discrimination in the Chinese city.
Evangeline Banao Vallejos, a domestic helper from the Philippines who has lived in Hong Kong since 1986, asked the Court of First Instance today to rule that an immigration law, which deems imported domestic helpers ineligible for rights such as votin... 阅读全帖
y******n
发帖数: 47
38
来自主题: JobHunting版 - G家onsite面经
感觉功力还是不行, 看着不难, 写起来还是花了好一阵功夫. lastNode用来处理i大于
树节点总数的情况, 也就是返回right most node.
int findith(Node *r, int i) {
assert(r != NULL);
assert(i > 0);
int k = i; Node *lastNode;
Node * ret = helper(r, k, lastNode);
return (ret != NULL) ? ret->value : lastNode->value;
}
Node *helper(Node *n, int& k, Node *& lastNode) {
if (n == NULL)
return NULL;
Node *ret = helper(n->left, k, lastNode);
if (ret != NULL)
return ret;
k--;
if (k == 0)
return n;
lastNode = n;
return helpe... 阅读全帖
S**I
发帖数: 15689
39
来自主题: JobHunting版 - [合集] G家onsite面经
☆─────────────────────────────────────☆
sharc (sharc) 于 (Mon Aug 22 15:15:14 2011, 美东) 提到:
刚从G家onsite归来。新鲜面经奉上。
总共5轮,4轮technical interview, 一个thesis discussion。在technical里,有编
程题,有open design。我记得的问题有:
1. 编程题:一堆字符串。找longest common prefix。
我的方法就是找最短的字符串,对它的每个字符,逐个与其他字符串对应位置比较。(
求更好方法)
2. open question: 一堆文件,size差别极大( from KB to many GB). 找出所有内
容相同的文件。
3. 编程题: 有一个observer 类,监视另一个类foo 的成员变量的值,每当那个值被
修改,就要调用 该observer.updated() 方法。需要实现 foo.registerObserver(ob)
, foo.unregisterObserver( ob )... 阅读全帖
h****n
发帖数: 1093
40
来自主题: JobHunting版 - 请教这么一个题:BST maximum sum path
贴一个通过OJ的版本,能处理全部负数的情况
楼主的版本很牛逼,不过有个大的bug,就是递归的结束条件没法达到,因为调用前判
断是不是指针为空了,不为空才调用,但是需要为空的时候才能达到递归结束条件
g才能正确的自底向上
/**
* Definition for binary tree
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
int maxPathSum(TreeNode *root) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int res;
int g;

res = ... 阅读全帖
h****n
发帖数: 1093
41
第一题
vector GetNumOfUnival(TreeNode * root)
{
vector res;
helper(root, res);
return res;
}
int helper(TreeNode * root, vector & res)
{
if(root==NULL)
return 0;

int leftNum = helper(root->left);
int rightNUm = helper(root->right);
if(leftNum==-1||rightNum==-1)
return -1;
else if(leftNum!=rightNum)
return -1;
else
{
res.push_back(root);
return leftNum+rightNum+1;
}
}
第二题
... 阅读全帖
h****n
发帖数: 1093
42
和值有关系么,理解错了,以为是所有子树一样的节点,不过道理都一样
代码如下
vector GetAllUnivalNodes(TreeNode * root)
{
vector res;
helper(root, res);
return res;
}
bool helper(TreeNode * root, vector & res)
{
if(root==NULL)
return true;
bool leftRes = helper(root->left, res);
bool rightRes = helper(root->left, res);
if(!leftRes||!rightRes)
return false;
if(root->left&&root->val!=root->left->val)
return false;
if(root->right&&root->val!=r... 阅读全帖
h****n
发帖数: 1093
43
面试写成这样子就挂了
class Solution {
public:
int maxPathSum(TreeNode *root) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int res;
int g;

res = helper(root, g);
return res;
}

int helper(TreeNode * root, int & g)
{
if(!root)
{
g = 0;
return 0;
}

int leftG, rightG;
int maxSum = INT_MIN;

int leftMax = helper(root... 阅读全帖
l*******b
发帖数: 2586
44
int maxPathSII(Node *h) {
int m = h->val;
int res = helper(h, m);
return m;
}
int helper(Node *h, int &m) {
if(NULL == h) return 0;
int ml = max(helper(h->l, m), 0);
int mr = max(helper(h->r, m), 0);
m = max(m, h->val + mr + ml);
return h->val + max(mr, ml);
}
学习一下递归的写法。。
d*********g
发帖数: 154
45
来自主题: JobHunting版 - 亚麻三面面经,攒人品,求好运
第三题贴个刚写的java代码:
public boolean isBalanced(TreeNode root) {
if(root == null) return true;
return helper(root) != -1;
}
private int helper(TreeNode root)
{
if(root == null) return 0;

int leftHeight = helper(root.left);
int rightHeight = helper(root.right);

if(leftHeight >= 0 && rightHeight >= 0 && Math.abs(leftHeight -
rightHeight) <= 1)
return Math.max(leftHeight, rightHeight)+1;
return -1;
}
x*****0
发帖数: 452
46
来自主题: JobHunting版 - unique binary tree 2 (leetcode)
下面是这道题的链接:
http://leetcode.com/onlinejudge#question_95
下面是我的代码:
class Solution {
private:
vector helper(int start, int end) {
if (start > end) {
return vector(1, NULL);
}

vector result;

for (int i = start; i <= end; ++i) {
vector left = helper(start, i-1);
vector right = helper(i+1, end);

for (int m = 0; m < left.size(); ++m) ... 阅读全帖
f********a
发帖数: 1109
47
Unique Binary Search Trees II
class Solution {
public:
// return all combinations of trees with given start/end;
// if start>end return single item NULL in vector.
vector Helper(vector array, int s, int e) {
if (s>e) return vector(1, NULL);
// each item in the array range can be root.
vector combo;
for (int i=s; i<=e; ++i) {
vector left = Helper(array, s, i-1);
vector r... 阅读全帖
a***e
发帖数: 413
48
这道题的iterative解法比较好懂,但看到下面这个recursive的就觉得想不清楚了。一
直对树的recursion挺糊涂的。怎么才能搞清楚呢?多谢!
class Solution {
public:
void flatten(TreeNode *root) {
helper(root, NULL);
}

TreeNode *helper(TreeNode *root, TreeNode *tail){
if (NULL==root) return tail;

root->right = helper(root->left, helper(root->right, tail));
root->left = NULL;
return root;
}
};
h******o
发帖数: 6
49
bool helper(TreeNode *node, int min, int max) {
if (node == nullptr) return true;
return node->val < max && node->val > min && helper(node->left, min
, node->val) && helper(node->right, node->val, max);
}
bool isValidBST(TreeNode *root) {
if (root && (root->val == INT_MIN || root->val == INT_MAX)) {
if (!root->left && !root->right) {
return true;
}
}
return helper(root, INT_MIN, INT_MAX);
}
fail {-21... 阅读全帖
a***e
发帖数: 413
50
这样是不是 O(N^N)的复杂度?
class Solution {
public:
int maximalRectangle(vector > &matrix) {
int row=matrix.size();
if (row==0) return 0;
int col=matrix[0].size();
if (col==0) return 0;

//find all disjoint rectangles
vector> flag(row, vector(col,false));
int maxArea=INT_MIN;

for (int r=0; r for (int c=0; c {
int area=0;
if (matrix[... 阅读全帖
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)