由买买提看人间百态

topics

全部话题 - 话题: cur
1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
h*****4
发帖数: 4219
1
来自主题: Programming版 - 如何让这个cur变量正确指向新地址
本人刚学数据结构,有个问题没找到解决方法,还请各位大牛帮忙看下。具体情况如下:
const int BUFFERSIZE=512;
struct TreeItem {
KeyType teamName;
int gameWins;
};
TreePtr insertItem(TreePtr root, const TreeItem newItem){
if(root==NULL)
root=new TreeNode(newItem,NULL,NULL);
else if(strcmp(newItem.teamName,root->item.teamName)<0)
insertItem(root->left,newItem);
else insertItem(root->right,newItem);
return root;
}
TreePtr fileInit(ifstream & db_input)
{ char buf[BUFFERSIZE];
char *bufpt... 阅读全帖
h*****4
发帖数: 4219
2
来自主题: Programming版 - 如何让这个cur变量正确指向新地址
对对,你一指出我发现这个错误了。多谢多谢!
我刚刚接到老师的邮件,说可以不用把cur变pointer也可以完成:"You simply use cur
as a TreeItem for the current team being input, then
pass that to your insert function where the copy is made and it's inserted."
现在的疑问是,我直接用cur保存着值,然后调用insertItem,怎么它只能得到文件中
的第一个值呢?其他的值完全没进入Tree里
f****e
发帖数: 923
3
这样为什么能去重呢, 看到3sum, 4sum, subset, 和permutation 里面很多这样写来去
重的?
我原来以为是因为 nums[i] 和 nums[i-1] 相同,
https://discuss.leetcode.com/topic/19845/java-solution-using-dfs-easy-
understand/16
cuyuan
Reputation: 3
For those who don't understand how to avoid duplicate by:
if "(i > cur && cand[i] == cand[i-1]) continue;
when we should skip a number? not just it's the same as previous number, but
also when it's previous number haven't been added!
i > cur means cand[i - 1] is not added to the path (you should kn... 阅读全帖
G*********r
发帖数: 538
4
来自主题: Joke版 - Where do most women have curly hair?
I lost the trivia contest at the church social last night by one point.
The last question was:
"Where do most women have curly hair?
Apparently the correct answer is: Africa
I’ve been asked to find another place to worship.
X****r
发帖数: 3557
5
来自主题: Programming版 - 如何让这个cur变量正确指向新地址
TreeItem *cur;

下:
X****r
发帖数: 3557
6
来自主题: Programming版 - 如何让这个cur变量正确指向新地址
insertItem(root->left,newItem);
==>
root->left = insertItem(root->left,newItem);
Same for right.

cur
inserted."
c*****r
发帖数: 439
7
来自主题: _pennystock版 - CUR
上午没时间写更多,这里补充一下:
新药公司都是烧钱的,cur也不例外,所以为什么这股常常是涨上去了又马上被出货的
力量给拉下来。是不是药股都这德性?我一般都是见大阳棒就跑,能喝汤就喝汤,毕竟
股价不高,10%的增幅也是不少。
今天表现不错,值得期待。
小盘股,药股,新股。这里估计有很多玩penny和biotech的高手,请多提宝贵建议:)
a***e
发帖数: 413
8
多谢各位,但现在试着在纸上跑程序,但有些就是搞不清哪里错了,比如这个
Copy List with Random Pointer
􀫭􀶍
A linked list is given such that each node contains an additional random
pointer which could point to
any node in the list or null.
Return a deep copy of the list.
􀙳􀼅
我看了idea,自己写了如下程序,但就是
Submission Result: Runtime Error
Last executed input:
{-1,#}
看了半天,试着一步一步走进去,还是不知道哪里错了,打算在VS里面debug一下看。
觉得和能通过的答案没有多少区别啊。。。。。。。。
My wrong answer.
/**
* Definition for sin... 阅读全帖
a***e
发帖数: 413
9
多谢各位,但现在试着在纸上跑程序,但有些就是搞不清哪里错了,比如这个
Copy List with Random Pointer
􀫭􀶍
A linked list is given such that each node contains an additional random
pointer which could point to
any node in the list or null.
Return a deep copy of the list.
􀙳􀼅
我看了idea,自己写了如下程序,但就是
Submission Result: Runtime Error
Last executed input:
{-1,#}
看了半天,试着一步一步走进去,还是不知道哪里错了,打算在VS里面debug一下看。
觉得和能通过的答案没有多少区别啊。。。。。。。。
My wrong answer.
/**
* Definition for sin... 阅读全帖
a***e
发帖数: 413
10
嗯,试图写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 为什么下面这个答案不对,而后面那个就对。
错... 阅读全帖
h****n
发帖数: 1093
11
来自主题: JobHunting版 - M家 onsite 悲剧,同胞们弄死烙印吧
我的递归和非递归解法,贴在下面 OJ通过 ,还有每K个reverse那个,不过那个只有递
归版本
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode *swapPairs(ListNode *head) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
/*
//递归做法很简单,但是要切记前面几行的顺序,别放错了
ListNode* cur = head;
if(cur==NULL) return NULL;
ListNode* n... 阅读全帖
h****n
发帖数: 1093
12
来自主题: JobHunting版 - M家 onsite 悲剧,同胞们弄死烙印吧
我的递归和非递归解法,贴在下面 OJ通过 ,还有每K个reverse那个,不过那个只有递
归版本
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode *swapPairs(ListNode *head) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
/*
//递归做法很简单,但是要切记前面几行的顺序,别放错了
ListNode* cur = head;
if(cur==NULL) return NULL;
ListNode* n... 阅读全帖
z*****0
发帖数: 63
13
请不要嘲笑我的无知,我在看cc150的时候,给的答案都是用LinkedListNode,但是我
在java编辑中,LinkedListNode 下面是红色的波浪,说没有此定义的class。我在网上
搜索 找到了 http://fisheye.igniterealtime.org/browse/openfire/trunk/src/java/org/jivesoftware/util/LinkedListNode.java?r=13651&r=13651 这个网址,我下载了这里得linkelistnode得定义。感觉还是不对。
根据我对答案的理解,她用的是一个双向链表,于是我写了这个class:
package cc150;
public class dNode {
private dNode pre = null;
private dNode next = null;
private int data;

dNode(int data){
this.data = data;
}

void addNode(dN... 阅读全帖
a***e
发帖数: 413
14
这些题看着容易,老是写不对或者代码很冗长,有大牛们指点一下如何提高么?
呜呜,不知道哪年哪月才能刷完一遍,有同学互勉一下么?
比如
Given a linked list and a value x, partition it such that all nodes less
than x come before nodes greater than or equal to x.
You should preserve the original relative order of the nodes in each of the
two partitions.
For example,
Given 1->4->3->2->5->2 and x = 3,
return 1->2->2->4->3->5.
我的
Runtime Error

Last executed input:
{1}, 0
ListNode *partition(ListNode *head, int x) {
... 阅读全帖
f**********t
发帖数: 1001
15
来自主题: JobHunting版 - 热腾腾的 LinkedIn 电面题攒RP
// Given a binary tree where all the right nodes are either leaf nodes with
a sibling (a left node that shares the same parent node) or empty, flip it
upside down and turn it into a tree where the original right nodes turned
into left leaf nodes. Return the new root.
// {1,2,3,4,5}, to [4,5,2,#,#,3,1]
class BiTree {
struct Node {
char val;
Node *left, *right;
Node(char c) : val(c), left(nullptr), right(nullptr) {}
};
Node *_root;
public:
BiTree(string s) {
queue qu... 阅读全帖
a***e
发帖数: 413
16
最近几天的少得可怜的准备时间都在看这个。60多行程序改个地方就通不过了。区别仅
在于
while(1)
{
r.push_back(p->val);
if(p==from)
break;
p = p->right;
}
不能改成
while(p!=from)
{
r.push_back(p->val);
p = p->right;
}
哎,可能还是因为这个算法不是自己想出来的,总是糊涂。
偶尔说起来,别人说那种属于比较偏的题了,如果问道肯定是存心要fail某人。
就是好奇有没有人真被问到。
能通过OJ的,
void reverse(TreeNode *from, TreeNode *to)
{
if (from==to)
return;

TreeNode *... 阅读全帖
t*******0
发帖数: 16
17
来自主题: JobHunting版 - 谷歌 电面
1. Find the given node, add the track to stack
2. Find next right node
void findnextnode(BinaryTree *root, int node_val)
{
stack s;
int error = 0;
BinaryTree *cur = root;
BinaryTree *cur = NULL;
//Find match node
while(cur!=NULL)
{
s.push(cur);
if(cur->value==node_val)
break;
else if((cur->valueright!=NULL))
{
... 阅读全帖
f*******t
发帖数: 7549
18
来自主题: JobHunting版 - large file的一道题
这个是很基本的数据结构,建议看一下wiki
我前几天实现了它,只有基本的insert和search,没有对查找child list进行优化,代
码贴出来供参考:
#include
#define MAX_LENGTH 64
using namespace std;
static char buff[MAX_LENGTH];
class Trie {
public:
Trie();
Trie(char value);
bool Insert(const char *str);
bool Search(const char *str) const;
void PrintAll(int pos) const;
private:
char _value;
Trie *_sibling;
Trie *_child;
};
Trie::Trie()
{
_value = 0;
_sibling = NULL;
_child = NULL;
}
Trie::Trie(char value)
... 阅读全帖
p****U
发帖数: 109
19
来自主题: JobHunting版 - leetcode Copy List with Random Pointer
RandomListNode *copyRandomList(RandomListNode *head) {
// Note: The Solution object is instantiated only once and is reused by
each test case.
//first parse
if(!head)
return NULL;
RandomListNode *cur=head;
while(cur){
RandomListNode *tmp=cur->next;
cur->next=new RandomListNode(cur->label);
cur=cur->next;
cur->next=tmp;
cur=cur->next;
}
//second parse
cur=head;
RandomListNode *copy;
while(cur){
copy=cu... 阅读全帖
f*******t
发帖数: 7549
20
来自主题: JobHunting版 - 2道算法题。 求教大家!
找出了一年多前写的逆波兰处理算数表达式的代码,强烈建议有兴趣的自己实现一下:
#include
#include
#include
#include
#define BUFFSIZE 1024
using namespace std;
struct Token {
bool isNum;
int num;
char op;
Token();
Token(const Token& t);
};
Token::Token()
{
isNum = false;
num = 0;
op = 0;
}
Token::Token(const Token& t)
{
isNum = t.isNum;
num = t.num;
op = t.op;
}
Token *getToken(const char expr[], int& idx)
{
Token *res = NULL;
while(expr[idx] == ' ')
... 阅读全帖
M*********n
发帖数: 4839
21
来自主题: JobHunting版 - G phone interview
响应党的号召,也贴一个:
static int substr(char[] arr) {
String s=new String(arr);
if(arr.length<=2)
return arr.length;
int n=arr.length;

int init=0;
int pre=0;
int cur=0;

int maxLen=Integer.MIN_VALUE;
while(cur cur++;

if (cur==n)
return n;
char c1=arr[init];
char c2=arr[cur];

pre=cur;

for(cur=cur+1;cur阅读全帖
l*3
发帖数: 2279
22
来自主题: 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:
//主函数,没有干什么大事,就是预处理一下字符串,把两个位置之间的字符转换的整
数结果都保存下... 阅读全帖
p********s
发帖数: 37
23
来自主题: JobHunting版 - leetcode过的一代工程师
凑个热闹
ListNode* deleteDuplicates(ListNode *head) {
for(ListNode *cur = head; cur && cur->next; cur = cur->next)
while (cur->next && cur->val == cur->next->val) {
ListNode *tmp = cur->next;
cur->next = tmp->next;
delete tmp;
}
return head;
}
如果再猥琐点的话:
ListNode* deleteDuplicates(ListNode *head) {
for(ListNode *cur = head; cur && cur->next; cur = cur->next)
while (cur->next && cur->val == cur->next->val)
cur->next = cur->next->next;
return head;
}
h****n
发帖数: 1093
24
来自主题: JobHunting版 - Amazon 电面
呵呵,那估计没有通用模式了
如果允许加visited flag那么就有通用模式了
只需要调整else语句块里面几句的顺序即可:
post order:
cur->visited = true;
st.push(cur);
if(cur->right) st.push(cur->right);
if(cur->left) st.push(cur->left);
in order:
if(cur->right) st.push(cur->right);
cur->visited = true;
st.push(cur);
if(cur->left) st.push(cur->left);
pre order:
if(cur->right) st.push(cur->right);
if(cur->left) st.push(cur->left);
cur->visited = true;
st.push(cur);
x*****0
发帖数: 452
25
来自主题: JobHunting版 - 两道最近onsite算法题
(2) C++ code:
void split_by_whitespace(string& s, vector& result)
{
stringstream ss(s);
string cur;

while(ss >> cur)
result.push_back(cur);
}
void maxi_assonance(vector& x)
{
vector::iterator it = x.begin();
vector > r;
map key_ind;

for(; it!=x.end(); ++it)
{
string cur = *it;
if(cur[0]=='a' || cur[0]=='e' ||
cur[0]=='i' || cur[0]=='o' ||
cur[0]=='u')
{ ... 阅读全帖
f****s
发帖数: 74
26
leetcode上给出的思想很好。就是keep一个pre和一个cur,
如果cur是pre的孩子,说明我们正从上到下,如果反过来,说明我们从下往上,就该打
印节点了。
顺便练一个,
void postorder(Node* r)
{
if(!r) return;
stack s;
Node* pre=0;
Node* cur=r;
s.push(r);
while(!s.empty()){
cur=s.top();
if(pre==0||cur==pre->left||cur==pre->right){
if(cur->left) s.push(cur->left);
else if(cur->right) s.push(cur->right);
else{
cout<val;
s.pop();
}
}else{
if(pre=cu... 阅读全帖
d***8
发帖数: 1552
27
来自主题: JobHunting版 - 谷歌 电面
BinaryTree* findnextnode(BinaryTree *root, int node_val)
{
stack stk;
BinaryTree *cur = root;
//Find match node
while(cur != NULL)
{
stk.push(cur);
if(cur->value == node_val)
break;
else if (cur->value < node_val)
cur = cur->right;
else if(cur->value > node_val)
cur = cur->left;
}
if (cur == NULL)... 阅读全帖
i********m
发帖数: 332
28
来自主题: JobHunting版 - 弱问题,连反转链表都看不懂了
练习了
public ListNode reverseBetween(ListNode head, int m, int n) {
// Start typing your Java solution below
// DO NOT write main() function

int diff = n-m;
if (diff < 0 || m <= 0)
return null;
boolean flag = false;
ListNode cur = head;
ListNode prev = head;

while (m-- > 1) {
if (cur == head) {
cur = cur.next;
}
else {
cur = cur.next;
... 阅读全帖
o*******y
发帖数: 362
29
Stack stack = new Stack();
List list = new ArrayList();
TreeNode cur = root, pre = null;
stack.push(cur);
while(!stack.isEmpty()){
cur = stack.peek();
if((cur.left == null && cur.right == null) || (pre != null && (
cur.left == pre || cur.right == pre))){
cur = stack.pop();
if(cur.left == null && cur.right == null){
list.add(cur);
... 阅读全帖
h****n
发帖数: 1093
30
不需要vector吧,假设binary tree是complete binary tree
已通过online judge测试
/**
* Definition for binary tree with next pointer.
* struct TreeLinkNode {
* int val;
* TreeLinkNode *left, *right, *next;
* TreeLinkNode(int x) : val(x), left(NULL), right(NULL), next(NULL) {}
* };
*/
class Solution {
public:
void connect(TreeLinkNode *root) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(root==NULL) return;
TreeLinkNode * cur = root;
TreeLinkNode ... 阅读全帖
h****n
发帖数: 1093
31
不需要vector吧,假设binary tree是complete binary tree
已通过online judge测试
/**
* Definition for binary tree with next pointer.
* struct TreeLinkNode {
* int val;
* TreeLinkNode *left, *right, *next;
* TreeLinkNode(int x) : val(x), left(NULL), right(NULL), next(NULL) {}
* };
*/
class Solution {
public:
void connect(TreeLinkNode *root) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(root==NULL) return;
TreeLinkNode * cur = root;
TreeLinkNode ... 阅读全帖
R*****i
发帖数: 2126
32
来自主题: JobHunting版 - 大牛们帮忙,Rverse Nodes in k-Group
我用C++测试了一下,好象没问题。
class ListNode
{
public:
int value;
ListNode *next;
ListNode(int v)
{
value = v;
next = 0;
}
};
ListNode* reverseKGroup(ListNode*, int);
ListNode* reverseLinkedList(ListNode*, ListNode*);
void main()
{
ListNode *ln = new ListNode(1);
ListNode *cur = ln;
for(int i=2; i<=11; i++)
{
ListNode *lnNew = new ListNode(i);
cur->next = lnNew;
cur = lnNew;
}
ln = reverseKGroup(ln, 4);
}
ListNode* reverseKGroup(List... 阅读全帖
b****z
发帖数: 176
33
代码如下:
基本思路是,用queue 进行BFS,记录了每个node的parent,找到之后,通过parent来
recover path。感觉没有任何冗余计算啊!!!为什么过不了?
谢谢各位!!
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Set;
public class Solution {
public List> findLadders(String start, String end, Set<
String> dict) {

List> res = new ArrayList>();
Set visited = new HashSet();

... 阅读全帖
b****z
发帖数: 176
34
代码如下:
基本思路是,用queue 进行BFS,记录了每个node的parent,找到之后,通过parent来
recover path。感觉没有任何冗余计算啊!!!为什么过不了?
谢谢各位!!
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Set;
public class Solution {
public List> findLadders(String start, String end, Set<
String> dict) {

List> res = new ArrayList>();
Set visited = new HashSet();

... 阅读全帖
a***e
发帖数: 413
35
知道要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... 阅读全帖
B*****t
发帖数: 335
36
not tested code.
void postOrderTraveral(Node *root) {
stack s;
Node *pre, *cur;
cur = root;
while(!s.empty()||cur) {
while(cur) {
s.push(cur->right);
cur = cur->left;
}
cur = s.top();
if(cur==pre||cur->right==NULL) {
visit(cur);
pre = cur;
cur = NULL;
s.pop()
}
else cur = cur->left;
}
}
h****n
发帖数: 1093
37
恩 O(n)时间 O(1)空间
typedef struct nodeT{
struct nodeT * next;
struct nodeT * down;
int value;
}node;
void FlattenSinglyList(node * head)
{
node*tail;
node* cur = head;
while(cur->next)
{
cur=cur->next;
}
tail = cur;
cur = head;
while(cur)
{
if(cur->down)
{
appendToTail(cur->down, tail);
}
}
}
void appendToTail(node* down, node* &tail)
{
node* cur = down;
tail->next = cur;
while(cur->next)
... 阅读全帖
w*******e
发帖数: 285
38
用bfs level print同时记住每个node的parent,看到leaf node就向上一直找到root
//none re-cursive level order, BFS
void levelorder(treenode* root){
if (root == nullptr) return;
map parent;
parent[root] = nullptr;
queue q;
q.push(root);
while (!q.empty()) {
auto cur = q.front(); q.pop();
if (cur->left) {
parent[cur->left] = cur;
q.push(cur->left);
}
if (cur->right) {
parent[cur->right] = cur;
q.push(cur->right);
}... 阅读全帖
b*********s
发帖数: 115
39
preorder traversal, path存着从root到cur的所有点,如果cur是leaf则打印path
def printAllPaths(self, root):
stack = []
cur = root
path = []
while cur or stack:
if cur:
stack.append(cur)
path.append(cur)
if not cur.left and not cur.right:
print [node.val for node in path]
cur = cur.left
else:
cur = stack.pop()
while path[-1] is not cur:
... 阅读全帖
f**********t
发帖数: 1001
40
来自主题: JobHunting版 - 一道dropbox面试题
自己先写点抛砖引玉好了,还没写完
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import sys
from collections import defaultdict
from os.path import join, getsize
# Write a basic file system and implement the commands ls, pwd, mkdir ,
# create, rm, cd, cat, mv.
class TreeNode:
def __init__(self, name, isDir):
self.name = name
self.children = defaultdict()
self.isDir = isDir
class FileSystem(object):
def __init__(self):
self.root = TreeNode("", True)
self.cur = ... 阅读全帖
r*****n
发帖数: 35
41
来自主题: JobHunting版 - 请教个G题目
case class TreeNode(value: Char, var left: Option[TreeNode] = None, var
right: Option[TreeNode] = None)
object TreeBuilder {
//recursive version
def recursive(input: String, start: Int): (Int, Option[TreeNode]) ={
if (start >= input.length) {
(start, None)
} else {
val cur = Some(TreeNode(input(start)))
if (start == input.length - 1) {
(start + 1, cur)
} else {
input(start + 1) match {
case '?' =>
val (loffset, l) = recursiv... 阅读全帖
s******n
发帖数: 226
42
来自主题: JobHunting版 - 算法题:合并两个排序二叉树
void merge(node* root1, node* root2){
int count =0;
node* cur = root1;
for(;cur;cur = cur->right, count++)
while(rightRotate(cur));
cur = root2;
for(;cur;cur = cur->right, count++)
while(rightRotate(cur));
// Merge 2 linked list in place
for(int i=count/2;i;i = i/2){
cur = root;
for(int j=0;j leftRotate(cur);
cur = cur->right;
}
}
}
C*N
发帖数: 1792
43
#include
#include
#include
using namespace std;
struct currentListStruct
{
double A;
double B;
std::vector values;
};
void getMaxNSum (std::vector & array1, std::vector & array2,
currentListStruct & cur, int N)
{
if (array1.empty () || array2.empty ()) {
return;
}
cur.A = array1.back();
cur.B = array2.back();
cur.values.push_back (cur.A + cur.B);

double a=array1.front()-1, b=array2.front()-1;
... 阅读全帖
a***e
发帖数: 413
44
Ft, 用VS不到半分钟就发现问题。。。。。。。。。。。。
// while(cur){
while(cur&&oc){ //加这个check就行了
oc->next = oc->next->next;
oc = oc->next;
if (cur->next){
cur->next = cur->next->next;
cur = cur->next;
}
}
但这段程序就不用那么多check
// 􀙳􀒷􀨆􀛱􀖆􀧽􀑖
RandomListNode dummy(-1);
for (RandomListNode* cur = head, *new_cur = &dummy;
cur != nullptr; ) {
new_cur->next = cur->next;
new... 阅读全帖
g***s
发帖数: 3811
45
来自主题: JobHunting版 - 生物男的Google面经节略版
It is very quick even for n = Integer.MAX_VALUE;
public static void main(String arg[]){
preprocess();
int n=Integer.MAX_VALUE;
System.out.println("squares sum of " + n + " : ");
for (int num : getSquaresSum(n)){
System.out.print(" " + num);
}
System.out.println("\ntotal callCount= " + callCount);
}
public static Collection getSquaresSum(int n){
Stack cur = new Stack();
Stack阅读全帖
f*******t
发帖数: 7549
46
来自主题: JobHunting版 - 谁能写个trie的框架?
struct Trie
{
Trie();
~Trie();
Trie *children[26];
bool isEnd;
};
Trie::Trie()
{
for(int i = 0; i < 26; i++)
children[i] = NULL;
isEnd = false;
}
Trie::~Trie()
{
for(int i = 0; i < 26; i++) {
if(children[i]) {
delete children[i];
children[i] = NULL;
}
}
}
void TrieInsert(Trie *root, const char *str)
{
if(!str || *str < 'a' || *str > 'z') {
printf("Invalid line\n");
return;
}

Trie *cur ... 阅读全帖
S**I
发帖数: 15689
47
来自主题: JobHunting版 - [合集] G一面,感觉不咋的
☆─────────────────────────────────────☆
libei (Bei) 于 (Wed Jan 11 15:43:39 2012, 美东) 提到:
面试官是Google+组的,
一上来她说看到我简历上的一篇测试自动化的文章,读了一遍,感觉"very
informative",让后让我介绍一下相关经验。让我小高兴了一下。
第一题是coding,做的还算顺利,后来她评价说所有的cases都覆盖到了。可能算是过
关吧。
第二题我想复杂了,然后在她提示下才解决。自我感觉很不好。其实sort一下就差不多
了,不过我往复杂的树结构想去了。虽然树结构确实能解决这个问题,不过当时我解释
得很不清楚。反正很不爽。
最后瞎聊时间,她说我提到的测试自动化实践和Google内部的基本完全一样blahblah。
。。,不过我觉得这点也算不上加分吧,是个人进google一段时间后都能学会。就怕她
觉得我想问题太复杂,直接negative。
大家有啥建议想法??
☆─────────────────────────────────────☆
peking2 (myfac... 阅读全帖
f*******t
发帖数: 7549
48
来自主题: JobHunting版 - amazon面试题目讨论贴2
#include
#include
#include
#define ENTRYNOTFOUND 0
#define ENTRYFOUND 1
#define NOTCOMPLETE 2
struct Trie;
void FindWords(Trie *root);
struct Trie
{
Trie();
~Trie();
Trie *children[26];
bool isEnd;
};
Trie::Trie()
{
for(int i = 0; i < 26; i++)
children[i] = NULL;
isEnd = false;
}
Trie::~Trie()
{
for(int i = 0; i < 26; i++) {
if(children[i]) {
delete children[i];
children[i] = NULL;
}
}
}
... 阅读全帖
w***o
发帖数: 109
49
来一个java的。space是O(1),复杂度应该是O(n)。
两个指针,一个current level的cur,一个是下一层link的头-nexthead:
void linkSibling(Node root)
Node cur = root;
Node nexthead = null;
while(cur != null) {
nexthead = null;
while(cur != null) {
Node runner = null;
if(cur.left != null) {
if(nexthead == null) {
nexthead = cur.left;
runner = nexthead;
} else {
runner.sibling = cur.left;
runner = runner.sibling;
}
... 阅读全帖
w***o
发帖数: 109
50
来一个java的。space是O(1),复杂度应该是O(n)。
两个指针,一个current level的cur,一个是下一层link的头-nexthead:
void linkSibling(Node root)
Node cur = root;
Node nexthead = null;
while(cur != null) {
nexthead = null;
while(cur != null) {
Node runner = null;
if(cur.left != null) {
if(nexthead == null) {
nexthead = cur.left;
runner = nexthead;
} else {
runner.sibling = cur.left;
runner = runner.sibling;
}
... 阅读全帖
1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)