由买买提看人间百态

topics

全部话题 - 话题: emptiness
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
B********s
发帖数: 1617
1
更新一下,关于涂层的问题。主要就是两代:PTFE, PFOA.
新的不沾锅牌子有的说自己有纳米颗粒,比如swiss diamond, 其实就是PTFE材料中混
合了纳米颗粒,该掉还是掉,没意思。
Polytetrafluoroethylene (PTFE)
Back in 1938, there was a fellow by the name of Plunkett who was working for
a chemical company. His job was to make refrigerants using
tetrafluoroethylene gas. He noticed the canister registered empty before it
weighed empty, so, he cut open a canister and discovered a slippery white
waxy coating lining the inside of the tin. In 1945, the Teflon trademark was
register... 阅读全帖
p*****r
发帖数: 6
2
来自主题: JobHunting版 - Another Bloomberg Phone Interview
1) difference between c and c++
2) key components in stl
3) what's functor? comparison of function pointer and functor
4) difference between malloc and new
5) how is free(void*) implemented?
6) which methods would be in an empty class?
7) size of an empty class, how about adding one virtual function in empty
class?
8) how is virtual function implemented?
9)
class Base{
virtual g();
};
class Derived{
virtual g();
};
Base* p = new Derived();
p->g(), which g function would be called.
10)
class Base
s*****r
发帖数: 773
3
来自主题: JobHunting版 - 发发我自己的Bloomberg的面经
二月底投的简历, 三月中旬第一轮, 然后三月25号电话面试, 中间要答辩, 拖到4月14号onsite, 然后一个星期后22号offer
主要就是C++ , 偶尔算法, 和linux
第一轮online test就不用发了
=======================================================
第二轮phone interview
前面的暖场的问题
1 你知道bloomberg啥?
2 简要介绍你自己;
3 做了什么project, 用了什么技术(对方明显没兴趣, 于是我引导他往C++靠);
后来开始正式的了, 都很简单, 但是很细节很细节很细节
1 什么是class? (听到这个问题我就吐血了, 这不完全藐视我通过了online test 么?)
2 如果是empty class, 是不是真的是empty class?
3 如果不是empty, 里面都有什么啊? 假设现在有个class Cat
4 跟我写一个copy constructor的signature
5 跟我写一个opertator assignment的signature
6 cl
j*****g
发帖数: 223
4
总结一下面试的准备活动,希望有帮助.
==================== AREAS/TOPICS to study/prep/review ====================
复习的东西还挺多的。比不过刚毕业的呀 :), 脑子不好使了,东西也差不多忘光了...
嘿嘿....
• Sorting
o Bubble/select/insertion/counting/qsort/heap/merge/bst
o Time/space complexity analysis
• Caching design
o Replacement policy (LRU, LFU, NRU, etc…)
o Efficiency/complexity/performance
o Distributed cache
o Hashing
• Multi-thread
o Locking/mutex/semaphore/critical sec... 阅读全帖
j*****g
发帖数: 223
5
总结一下面试的准备活动,希望有帮助.
==================== AREAS/TOPICS to study/prep/review ====================
复习的东西还挺多的。比不过刚毕业的呀 :), 脑子不好使了,东西也差不多忘光了...
嘿嘿....
• Sorting
o Bubble/select/insertion/counting/qsort/heap/merge/bst
o Time/space complexity analysis
• Caching design
o Replacement policy (LRU, LFU, NRU, etc…)
o Efficiency/complexity/performance
o Distributed cache
o Hashing
• Multi-thread
o Locking/mutex/semaphore/critical sec... 阅读全帖
y*********e
发帖数: 518
6
贴一贴代码 :)
void postorder(const Node* node) {
std::stack stack;
while (node != NULL || !stack.empty()) {
if (node == NULL) {
while (!stack.empty() && node == stack.top()->right) {
node = stack.top(); stack.pop();
process(node->value);
}
node = stack.empty() ? NULL : stack.top()->right;
}
if (node != NULL) {
stack.push(node);
node = node->left;
}
}
}
x****k
发帖数: 2932
7
来自主题: JobHunting版 - C++相关的面经
银行相关的职位,题目比较多,尽量拣记得住的写一下。
1. the difference of new/delete malloc/free. what if new/free, and malloc/
delete?
2. sizeof an empty class
3. sizeof an empty class with virtual function.
4. can we call virtual function in constructor/destructor?
5. what is pure virtual function?
6. How to disable class initialized on heap,
7. How disable class initialized on stack,
8. where static varible saved, heap or stack?(bss, data)
9. what does static mean in C++
10. what is 4 default functions for empty class
... 阅读全帖
g**u
发帖数: 583
8
来自主题: JobHunting版 - Google Onsite 面经
用stl的priority_queue写了下multi-way merge, 请大家拍砖。
其中: myPair的第一个就是要存储的值, 第二个表示ownership.
/*
*multiple way merge using the priority_heap
*/
#include "vector"
#include "queue"
class myPair{
friend std::ostream & operator<<(std::ostream & out, const myPair &p)
{
out<<" ( "< return out;
}
public:
myPair(int x, int y):_first(x),_second(y)
{
}
bool operator >(const myPair & p)const
{
return this->_fir... 阅读全帖
b*****n
发帖数: 482
9
来自主题: JobHunting版 - aababccbc remove abc
How to check the top 2 objects? It seem we can only look at the top
object.
Another question is we have to check N-1 chars from the top of the
stack, where N is the length of the str2. If there are multiple
characters in str2 that are the same as its last char (e.g. accccbc),
then even if str1 is the same as string 2, we have to do extra check 4
times whenever we meet a 'c' in str1.
My idea is to have a companion array recording the maximum matched index
of the char sequence in str1. If there is... 阅读全帖
s******n
发帖数: 226
10
int MaxInt(int a[], int n){

vector s;
vector::iterator iter;


for(int i=0;i if(!s.empty() && a[i]>=a[s.back()]) continue;
s.push_back(i);
}

int max =0;
for(int i=n-1;i>=0;i--){
while(!s.empty() && a[i]>a[s.back()]) s.pop_back();
if(s.empty()) return i;

if(max }
return max;
p*i
发帖数: 411
11
来自主题: JobHunting版 - 上一道题吧
#include
#include
#include
using namespace std;
void process(const string& str) {
stack s, s1;
for (unsigned i = 0; i < str.size(); i++) {
if ('(' == str[i]) {
s.push(i);
} else {
if (!s.empty()) {
unsigned left = s.top(); s.pop();
unsigned& right = i;
if (s1.empty() || (s1.top()+1 < left)) {
s1.push(left);
s1.push(right);
... 阅读全帖
w****x
发帖数: 2483
12
来自主题: JobHunting版 - 直方图下雨这道题怎么解?
int CalculateContain(int a[], int n)
{
assert(a && n > 0);
int nRet = 0;
stack stk;
for (int i = 0; i < n; i++)
{
if (!stk.empty() && a[stk.top()] < a[i])
{
int nPrev = stk.top();
stk.pop();
while (!stk.empty() && a[stk.top()] <= a[i])
{
int nCur = stk.top();
stk.pop();
int nLimit = a[nCur] <= a[i] ? a[nCur] : a[i];
nRet += (nLimit - a[nPrev]) *... 阅读全帖
r********g
发帖数: 1351
13
来自主题: JobHunting版 - 2道面试题.
第二题如果不用递归,就是iterative的post order遍历?
另外,打印也很麻烦,是不是用一个辅助stack?这样复杂度是O(nlgn)吗?
void printStack(stack S){
stack T;
while(!S.empty()){
T.push(S.top());
S.pop();
}
while(!T.empty()){
cout << T.top()->value << ' ';
T.pop();
}
cout << endl;
}
// post order traverse
void printAllPath(Node* root) {
if(!root) return;
stack S;
Node* prev = NULL;
S.push(root);
while(!S.empty()){
Node* p = S.top();
if(!prev || p == prev->left || p==prev->right... 阅读全帖
p**v
发帖数: 853
14
来自主题: JobHunting版 - 请教leetcode Subsets II
我的思路是用一个类似于binary tree的图来做的,
开始时只有0 (empty set), 然后左边不加新元素,右边加,
遇到重复就在现有set的基础上加1至cnt+1个,因为我这里的cnt
是从0开始的,程序中就是从0到cnt loop的。
希望能帮助你理解
vector > subsets2(vector &s) {
vector > results;
if (s.empty()) return results;
results.push_back(vector());//init with an empty set
int cnt;
sort(s.begin(), s.end());
for (size_t i=0; i //compute this first because it will increase during the loop
size_t limit=results.... 阅读全帖
g****y
发帖数: 240
15
来自主题: JobHunting版 - 求教一道面试题
stack s1, s2;
s1.push(T);
while(!s1.empty() || !s2.empth())
{
if(!s1.empty())
{
Node* n = s1.top();
s1.pop();
cout << n->val << " ";
if(n->right) s2.push(n->right);
if(n->left) s2.push(n->left);
}
else // s2 is not empty
{
Node* n = s2.top();
s2.pop();
cout << n->val << " ";
if(n->left) s2.push(n->left);
if(n->right) s2.push(n->right);
}
}
s***0
发帖数: 117
16
来自主题: JobHunting版 - 问个括号问题的迭代解法
#include
#include
#include
#include
#include
using namespace std;
class ProcessParen
{
public:
ProcessParen(){};
void processString(string& inString)
{
stack charStack;
for (int i = 0; i< inString.length(); ++i)
{
if(inString[i] == '{')
{
mResult += "{";
charStack.push('{');
}
if(inString[i] == '}')
{
... 阅读全帖
c***d
发帖数: 26
17
来自主题: JobHunting版 - 问个括号问题的迭代解法
是leetcode的generateParenthesis吗?
写了个dp的
public class Solution {
public ArrayList generateParenthesis(int n) {
// Start typing your Java solution below
// DO NOT write main() function
ArrayList one = new ArrayList();
if (n < 1) return one;
HashMap> dp = new HashMap ArrayList>();
ArrayList empty = new ArrayList();
empty.add(new String(""));
one.add(... 阅读全帖
w****x
发帖数: 2483
18
来自主题: JobHunting版 - T家电面一般有几轮? [UPDATE面经]
随手写了一个,没测
class CMinHeap
{
public:
int GetSize() { return m_vec.size(); }
bool empty() { return m_vec.empty(); }
int top() { return m_vec[0]; }
void pop()
{
swap(m_vec[0], m_vec[m_vec.size()-1]);
m_vec.pop_back();
int nCur = 0;
while (2*nCur+1 < m_vec.size())
{
int nSwap = 2*nCur+1;
if (2*nCur+2 < m_vec.size() && m_vec[2*nCur+2] < m_vec[2*nCur+1])
nSwap = 2*nCur+2;

if (m_ve... 阅读全帖
w****x
发帖数: 2483
19
来自主题: JobHunting版 - T家电面一般有几轮? [UPDATE面经]
随手写了一个,没测
class CMinHeap
{
public:
int GetSize() { return m_vec.size(); }
bool empty() { return m_vec.empty(); }
int top() { return m_vec[0]; }
void pop()
{
swap(m_vec[0], m_vec[m_vec.size()-1]);
m_vec.pop_back();
int nCur = 0;
while (2*nCur+1 < m_vec.size())
{
int nSwap = 2*nCur+1;
if (2*nCur+2 < m_vec.size() && m_vec[2*nCur+2] < m_vec[2*nCur+1])
nSwap = 2*nCur+2;

if (m_ve... 阅读全帖
c**s
发帖数: 159
20
来自主题: JobHunting版 - 再问Maximal Rectangle的N^2解法
int maximalRectangle(vector > &matrix) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int m = matrix.size();
if (m == 0) {
return 0;
}
int n = matrix[0].size();
vector height;
height.resize(n,0);
stack > st;
int i, j ,answer = 0;
for (i = 0; i < m; ++i) {
for (j = 0; j < n; ++j) {
if (matrix[i][j] == '1') {
++height[j];
... 阅读全帖
w****x
发帖数: 2483
21
来自主题: JobHunting版 - 谷歌面经
class CIterIter
{
public:
CIterIter(vector>& vec) : m_vec(vec)
{
m_ni = -1;
m_nj = 0;
}
void next()
{
prob(m_ni, m_nj);
}
bool hasNext()
{
if (m_ni < 0)
{
m_ni = 0;
if (!m_vec.empty() && !m_vec[0].empty())
return true;
}
int i,j;
return prob(i, j);
}
int getVal() { return m_vec[m_ni][m_nj]; }
private:
bool prob(int& i, int& j)
{
... 阅读全帖
y****n
发帖数: 192
22
来自主题: JobHunting版 - 狗电面
用java写了一下,切磋一下哈
main:
// a[0] = (1, 2)-> (7, 9)
// a[1] = (1, 3) -> (4, 5)
// a[2] = (12, 15)
// a[3] = (15, 20)
Interval[] intervals = new Interval[4];
intervals[0] = new Interval(1, 2);
intervals[0].next = new Interval(7, 9);
intervals[1] = new Interval(1, 3);
intervals[1].next = new Interval(4, 5);
intervals[2] = new Interval(12, 15);
intervals[3] = new Interval(15, 20);
Interval result = getUnifiedIntervals(... 阅读全帖
j*****y
发帖数: 1071
23
来自主题: JobHunting版 - Google电面
armortized 是 O(n) 吧?
两个 stack: s1, s2
s2 is empty.
enque: s1.push
deque: pop s1 to s2 until s1 is empty, s2.pop(). then push s2 back to s1
until s2 is empty
for the amortized time: T(n). firstly T(n) <= O(n)
But we can show T(n) >= \Omega(n)
enque n times, then enque(time cost is 1 ), deque(time cost is 3(n + 1)),
enque(time cose is 1), deque(time cost is 3(n + 1)),...., in this case, the
average time cose >= \Omega(n)
So the amortized cost is O(n)
f*******t
发帖数: 7549
24
来自主题: JobHunting版 - Wildcard Matching题求助
问过1337哥,他说最大数据是32768*32768,肯定会MLE。
我有个优化的版本,但最后一个test case还是TLE。十分想看谁有能AC的代码!
public boolean isMatch(String s, String p) {
if (s == null || p == null)
return false;
if (s.isEmpty() && p.isEmpty()) { //Both are empty string -> true
return true;
} else if (s.isEmpty()) { // If s is empty, p must not contain
any character other than '*'
for (int i = 0; i < p.length(); i++) {
if (p.charAt(i) != '*')
... 阅读全帖
b******g
发帖数: 77
25
来自主题: JobHunting版 - 我也贡献一个B家店面
Example
{a[b]c} is valid
[a{b]c} is invalid
{{a} is invalid
{a}} is invalid
bool isExpressionValid(fstream & fin)
{
stack s;
char c;
while (fin.good())
{
fin >> c;
if (c == '{' || c == '[')
s.push(c);
else if (c == '}')
if (s.empty() || s.top() != '{')
return false;
else s.pop();
else if (c == ']')
if (s.empty() || s.top() != '[')
return false;
el... 阅读全帖
f*******t
发帖数: 7549
26
来自主题: JobHunting版 - leetcode出了新题word ladder
相当丑陋的BFS,已经尽量去除copy string的时间了,但还是超时,求指点T_T
class Path {
public:
Path() { path = new vector; }

~Path() { delete path; }

Path* duplicate() const {
Path *np = new Path;
np->path = new vector(*path);
return np;
}

vector *path;
};
class Solution {
public:
vector> findLadders(string start, string end, unordered_
set &dict) {
vector> ans;
queue<... 阅读全帖
f*******t
发帖数: 7549
27
来自主题: JobHunting版 - leetcode出了新题word ladder
相当丑陋的BFS,已经尽量去除copy string的时间了,但还是超时,求指点T_T
class Path {
public:
Path() { path = new vector; }

~Path() { delete path; }

Path* duplicate() const {
Path *np = new Path;
np->path = new vector(*path);
return np;
}

vector *path;
};
class Solution {
public:
vector> findLadders(string start, string end, unordered_
set &dict) {
vector> ans;
queue<... 阅读全帖
p*****p
发帖数: 379
28
刚写了个,可以过
class Solution {
public:
vector > levelOrderBottom(TreeNode *root) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
deque > traversal;
vector > ret;
if(!root) return ret;
vector q1;
vector q2;
q1.push_back(root);

while (!q1.empty() || !q2.empty()) {
if (!q1.empty()) {
vector row;
... 阅读全帖
x*****0
发帖数: 452
29
Given a linked list where in addition to the next pointer, each node has a
child pointer, which may or may not point to a separate list. These child
lists may have one or more children of their own, and so on, to produce a
multilevel data structure, as shown in below figure.You are given the head
of the first level of the list. Flatten the list so that all the nodes
appear in a single-level linked list. You need to flatten the list in way
that all nodes at first level should come first, then nod... 阅读全帖
a*s
发帖数: 425
30
来自主题: JobHunting版 - 请教一道题
请教一道题
和hanoi tower有点像,不过有点不一样
有N个stack, 每个stack都有几个数字,
每次,可以从其中的一个stack里取出一个或者几个数,然后放到另外一个stack里,
比如
stack_1里,有数字 4,3,6,2
stack_2里,有5,7,8
那么一次操作,可以从stack_1里,取6,2,然后放入stack_2,
那么,
stack_1里就成了4,3,
stack_2里变成了5,7,8,6,2
或者,可以从stack_1里,去3,6,2 放入 stack_2
那么,
stack_1里就变成了4,
stack_2里就变成了5,7,8,3,6,2
现在的问题是,给定一个初始的状态,一个最终的状态,通过上面的移数规则,找出最
少的移数步骤,
一个简单的例子,
初始状态:
stack_1:3,1,4
stack_2:2,5,
stack_3:(empty)
最终状态:
stack_1:(empty)
stack_2:(empty)
stack_3:1,2,3,4,5
那么最少的移动步骤是5步
1:move 5 from stack_2 to stack_1
2... 阅读全帖
b******7
发帖数: 92
31
来自主题: JobHunting版 - implement 3 stack in an array
注意左移右移就行了
第一个栈[0...capacity0 - 1)
第二、三个栈[capacity0,...,N)分别一个从头开始++,一个从尾开始--
当第一个栈满而第二、三个栈不满时,做右移操作
反过来,但第二、三个栈满,而第一个栈伟满时,做左移操作
template
class TripleStack{
public:
TripleStack()
{
head0 = 0;
head1 = capacity0 = N/3;
head2 = N-1;
}
void push0(const T & e)
{
if(!isSubStackFull(0))
arr[head0++] = e;
else if(!isSubStackFull(1))
{
shiftRight();
arr[head0++] = e;
}
... 阅读全帖
d****n
发帖数: 397
32
来自主题: JobHunting版 - 请教一道比身高题目
这个算法行不行,基本上和上面的同学说的差不多。
第一步,把身高数组和b数组,一起按身高数组排序。
第二步,从最小的element开始,reconstruct 新的数组。
第一步是O(nlgn).第二步,最坏是O(n^2)。(当b全为0)时。
以下是程序。
#include
#include
#include
using namespace std;
struct mypair {
int a;
int b;
mypair(int c,int d) {a=c;b=d;}
friend bool operator<(const mypair&,const mypair&);
};
bool operator<(const mypair &p1,const mypair &p2) {
return (p1.a }
vector heightcomp(vector& a,vector& b) {
int i,k,j,n,m;
n=a.size();
vector阅读全帖
b********g
发帖数: 28
33
来自主题: JobHunting版 - Largest Rectangle in Histogram
public class Solution {
public int largestRectangleArea(int[] height) {
// Start typing your Java solution below
// DO NOT write main() function
if(height == null || height.length == 0) return 0;
int n = height.length;
int[] left = new int[n];
Stack stack = new Stack();
int max = 0;
for(int i = 0; i < n; i++){
if(stack.empty() || height[stack.peek()] <= height[i]){
left[i] = i;
... 阅读全帖
p****o
发帖数: 46
34
来自主题: JobHunting版 - ebay第一轮电话面经
第二题如果是, . ' '结束的情况, 用stack
否则的话,结尾还得把stack输出.
确实,一步小心就容易忽略
写个c++的代码
#include
#include
using namespace std;
string strProc(string input){
stack stk;
string result;
for(string::const_iterator it = input.begin(); it!=input.end(); ++it){
if (*it < '9' && *it > '0' && stk.empty()){
result+=*it;
}
else if (*it == ' ' || *it ==',' || *it =='.'){
while (!stk.empty()){
char c= stk.top();
... 阅读全帖
n****e
发帖数: 678
35
来自主题: JobHunting版 - 问个题。
不客气,互相学习。
如前面有人提到的,这里用到double-ended queue,也就是deque。这里是求最小值的
方法,最大值的方法是相似的
input: int A[]
deque myque; // queue 里面存的是数组A的index
int i = 0
for (; i < n; i++) {
while(!myque.empty() && A[i] <= A[myque.back()] ) {
myque.pop_back();
}
myque.push_back(i);
}
// 处理后面所有的数;
while(1) {
cout << "min number for [i-n, i-1] is " << A[myque.front()];
while(!myque.empty() && A[i] <= A[myque.back()] ) {
myque.pop_back();
}

if (!myque.empty() && myque.front() + n <= i) {
myque.pop_f... 阅读全帖
m*****n
发帖数: 204
36
来自主题: JobHunting版 - 小弟求问LinkedIn那道Deep Iterator的题
攒了个段子请大牛点评一下:
// Not thread-safe
// Talk about validation requirement: none vs in next() vs in constructor
private static class DeepIterator implements Iterator {
private final Iterator myIterator;

private final Class eleType;

private final Iterator empty = new ArrayList().iterator();

private Iterator head = empty;

DeepIterator(List list, Class eleType) {
this.myIterator = list.iterator();
this.eleType = e... 阅读全帖
m*****n
发帖数: 204
37
来自主题: JobHunting版 - 小弟求问LinkedIn那道Deep Iterator的题
攒了个段子请大牛点评一下:
// Not thread-safe
// Talk about validation requirement: none vs in next() vs in constructor
private static class DeepIterator implements Iterator {
private final Iterator myIterator;

private final Class eleType;

private final Iterator empty = new ArrayList().iterator();

private Iterator head = empty;

DeepIterator(List list, Class eleType) {
this.myIterator = list.iterator();
this.eleType = e... 阅读全帖
a***e
发帖数: 413
38
请教leetcode上的那道Word Break II
Given a string s and a dictionary of words dict, add spaces in s to
construct a sentence where each word is a valid dictionary word.
Return all such possible sentences.
For example, given
s = "catsanddog",
dict = ["cat", "cats", "and", "sand", "dog"].
A solution is ["cats and dog", "cat sand dog"].
http://oj.leetcode.com/problems/word-break-ii/
Can anyone tell me why the following code generated Memory Limit Exceeded? I
tested it in VS for that catsanddog string, whic... 阅读全帖
a***e
发帖数: 413
39
再请问为啥下面这个程序就没有 Memory Limit Exceeded呢?我怎么觉得做法差不多,
只不过这个程序是从后往前做的?
vector wordBreak(string s, unordered_set &dict) {
int len = s.length();
vector dp(len + 1,false);
vector > dp2(len + 1,vector());
dp2[len].push_back("");
dp[len] = true;
for (int i = len - 1; i >= 0; i--) {
for (int j = i; j < len; j++) {
string str = s.substr(i,j - i + 1);
if (dict.... 阅读全帖
a*****y
发帖数: 22
40
假设Quack的顺序是递增
我的思路是,想办法找到最大的元素(尾),然后push进一个标志(如MIN_INT);下次
peek的时候,只pop非MIN_INT的元素,直到再次遇到最大的那个元素,此时可以pop标
志,直至空
void PopQuackToArray(Quack& quack, vector& array) {
vector tmp;
int last = quack.pop();
tmp.push_back(last);
int curr;
while (!quack.empty()) {
curr = quack.pop();
if (curr != last) {
break;
}
tmp.push_back(last);
}
if (quack.empty()) {
if (curr < last) {
array.push_back(curr);
... 阅读全帖
a*****y
发帖数: 22
41
假设Quack的顺序是递增
我的思路是,想办法找到最大的元素(尾),然后push进一个标志(如MIN_INT);下次
peek的时候,只pop非MIN_INT的元素,直到再次遇到最大的那个元素,此时可以pop标
志,直至空
void PopQuackToArray(Quack& quack, vector& array) {
vector tmp;
int last = quack.pop();
tmp.push_back(last);
int curr;
while (!quack.empty()) {
curr = quack.pop();
if (curr != last) {
break;
}
tmp.push_back(last);
}
if (quack.empty()) {
if (curr < last) {
array.push_back(curr);
... 阅读全帖
s******d
发帖数: 424
42
来自主题: JobHunting版 - Amazon Onsite 面经
有parent的
vector FindDistanceN(TreeNode* start, int N)
{
vector result;
if(!start || N < 1)
return result;
unordered_set visited;
queue curr, next;
curr.push(start);
int dis = 0;
while(!curr.empty() && dis < N)
{
while(!curr.empty())
{
TreeNode* n = curr.front();
curr.pop();
visited.insert(n);
if(n->parent && visited.find(n->parent) != visited.end())
next.push(n->parent);
if(n->left &&... 阅读全帖
g********t
发帖数: 39
43
来自主题: JobHunting版 - 贡献Rocket Fuel 4 hour online test
贡献刚做的online test,职位是Machine Learning related。
Question 1 / 2 (LaserMaze)
You are standing in a rectangular room and are about to fire a laser toward
the east wall. Inside the room a certain number of prisms have been placed.
They will alter the direction of the laser beam if it hits them. There
are north-facing, east-facing, west-facing, and south-facing prisms. If the
laser beam strikes an east-facing prism, its course will be altered to be
East, regardless of what direction it had been goi... 阅读全帖
M****g
发帖数: 162
44
来自主题: JobHunting版 - 急求rocket fuel 3小时的online test!!!
Question 1 / 2 (LaserMaze)
You are standing in a rectangular room and are about to fire a laser toward
the east wall. Inside the room a certain number of prisms have been placed.
They will alter the direction of the laser beam if it hits them. There
are north-facing, east-facing, west-facing, and south-facing prisms. If the
laser beam strikes an east-facing prism, its course will be altered to be
East, regardless of what direction it had been going in before. If it hits
a south-facing prism... 阅读全帖
s********x
发帖数: 81
45
来自主题: JobHunting版 - leetcode的run time error
大家好,最近做了两题leetcode, 但是都遇到了run time error. 但是我遇到run time
error 的例子在别的c++编译器上都顺利通过了,请大家帮我看一下是什么问题. 谢谢
大家!
问题一:next permutation:
class Solution {
public:
int findSecondMax(vector &num, int cur){
int max1=-1, max2=-2;
int index1=-1, index2=-2;
for(int i=cur; i if(max1 max2=max1;
index2=index1;
max1=num[i];
index1=i;
}
}
if(max2!=-2 || max2!=-1) return index2;
else return index1;
}

... 阅读全帖
a**********0
发帖数: 422
46
来自主题: JobHunting版 - 发个我总结的unix常用命令
The Unix Commands
其实就是攒了一下网上的资料
# Create a new tar archive.
# the folder dirname/ is compressed into archive_name.tar
tar cvf archive_name.tar dirname/
# Extract from an existing tar archive
tar xvf archive_name.tar
# View an existing tar archive
tar tvf archive_name.tar
# Search for a given string in a file (case in-sensitive search).
grep -i "the" demo_file
# Print the matched line, along with the 3 lines after it.
grep -A 3 -i "example" demo_text
# Search for a given string in all files recur... 阅读全帖
a***e
发帖数: 413
47
leetcode上的,感觉如果选择的语言有split这个function,就会好写很多,比如C#和
Java。
C++就麻烦些。而且选择是algorithm 的find还是string的find也很不同。
面试时碰到这类题能说我这道题用C#或者Java,其他用C++行么?其实现在主要用C#,
但C++是总共用得最久的。Java感觉和C#很像,但实际工作中没用过,也不想为面试而
学。多谢
Given an absolute path for a file (Unix-style), simplify it.
For example,
path = "/home/", => "/home"
path = "/a/./b/../../c/", => "/c"
两个C++的
1. string simplifyPath(string path) {
vector a;
int n = path.size();
for (int i = 0; i {
string t;
... 阅读全帖
f**********t
发帖数: 1001
48
来自主题: JobHunting版 - G家on site问一道题目
void DistanceAround(const vector &rooms, vector> &res,
int i, int k) {
const static int directions[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
res[i][k] = 0;
queue> qu;
qu.push(make_pair(i, k));
while(!qu.empty()) {
int x = qu.front().first;
int y = qu.front().second;
qu.pop();
for (int z = 0; z < 4; ++z) {
int xx = x + directions[z][0];
int yy = y + directions[z][1];
if (0 <= xx && xx < (int)rooms.size()
... 阅读全帖
m*********a
发帖数: 3299
49
Given n pairs of parentheses, write a function to generate all combinations
of well-formed parentheses.
For example, given n = 3, a solution set is:
"((()))", "(()())", "(())()", "()(())", "()()()"
递归很容易
void generateParenthesisRecr(string str,int n,int l,int r,vector&
result){
if (l==n && r==n){
result.push_back(str);
return;
}
if (l if (l>r) generateParenthesisRecr(str+")",n,l,r+... 阅读全帖
w****0
发帖数: 803
50
You are given 10 empty boxes. You distribute 5 black balls to these empty
boxes so that no two black balls can go into the same box. Now you have 4
white balls and you distribute them in the same fashion but this time a
white ball can go into a box where you put a black ball. That is, in the end
, you might have at least 5 full boxes or at most 9 full boxes. What is the
probability of choosing an empty box?
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)