Redian新闻
>
提高警惕,谨防骗子!
avatar
提高警惕,谨防骗子!# Living
s*d
1
没什么好说的,还是自己不行。
第一题
abstract class absClass
{
public int AddTwoNumbers(int Num1, int Num2)
{
return Num1 + Num2;
}
public abstract int MultiplyTwoNumbers(int Num1, int Num2);
}
实例化 absclass
interviewer 说 不需要用考到任何算法知识。只考java。
answer :
public class aaClass extends absClass {
public int MultiplyTwoNumbers(int Num1, int Num2){
int multiplyresult = 0 ;
multiplyresult=Num1*Num2;

return multiplyresult;
}
这个有什么问题?
Q2:经典题
Q2:
Given a sorted 2-D array (M x N) containing integers with the following
properties:
* All integers in any row are sorted left to right
* The first integer in any row is greater than the last integer in the
previous row
E.g.
1 3 5 7
10 11 16 20
23 30 34 50
我先说从last column search 再在row line search O(N+M);
interview说有better 方法。
我说可以用binary search。
他说combine both。 我就total lost了(我就没想出来怎么叫combine both)
死活想不出来 在m/2 n/2 开始binary search。
之后提出跟种方法。比如展开成1D 直接做binary search。得到否定答案。
说了用对角线 查找 也不是最优的。
interviewer 提示了说matrix 很大
谈论了半天不得要领。
直接先写程序,那时,心都凉了,紧张死了。后来连怎么算[][]size的搞错了。
哎。
肯定挂了。
讨论贴:
http://stackoverflow.com/questions/2457792/given-a-2d-array-sor
increasing-order-from-left-to-right-and-top-to-bottom
问个问题,在java 里2D是怎么放的? 如果实际上是1D存储的话。是不是用1D更快。
在讨论贴了好像O(logn))并不是比(n+M)更快。
谢谢
avatar
b*k
2
昨天才在同一個店買的 用的discover 不知道能不能拿到5%
今天再去就被告知 boss通知只能cash了....
avatar
y*y
3
由于LD工作变动,最近我们把房子买了,为减轻搬家负担,我们在craigslist上发了卖
某些家俱的广告。
很快收到电邮,来信者称对我们卖的东西很感兴趣,由于她的工作性质,她不能自由地
打电话、上网,她只能通过Paypal付钱给我们,她不在我们所在城市,她本人也不能来
取家俱,只能委托运输公司来取货。而对于家俱的价格却只字未提,没有还价。
开始我们很高兴,一发广告就有人要买,而且不还价。我们回复她,如果搬家公司在搬
运家俱时能够确认家俱的良好状态(我们怕万一家俱运出门后在运输过程中发生破损)
,她可以通过Paypal付款,一旦付款成功,她就可以委托运输公司来提货。
很快,她的电邮来了,这时我们已经有点怀疑了,她自称上网不方便,可是从她回复电
邮的速度看,似乎她一直在网上。她说需要我们的地址,以便让运输公司报价。我们想
了想,虽然有点疑心,但一想应该不会有大问题,就告之了地址。
很快,她的电邮来了,说已经通过Paypal支付给我们钱了,支付我们的钱包括家俱的钱
、运费以及额外50块可能发生的费用,要我们把运费400块付给运输公司。很快,我们
收到了运输公司电邮,说必须收到400元费用才能来取家俱,并告之详细的电汇信息。
很快我们又收到号称Paypal的电邮,说已经有一笔钱汇到我们Paypal户口上,但我们必
须先付400元给运输公司,这笔钱才能release给我们。
这最后的一连串三个电邮“露出了狐狸尾巴”,我和LD一看,就觉得其中有诈。我们马
上打电话给Paypal服务热线,询问我们账户最近是否有交易,对方查了说没有,我们把
收到的号称Paypal发来的电邮告诉对方,对方查了说Paypal没有给我们发任何电邮,并
告诉我们把收到的号称来自Paypal的电邮转发给他们。还好,我们有足够的警惕,没有
上当!
要我们汇钱过去的地址是尼日利亚。又是尼日利亚骗子?
请大家提高警惕,不要受骗上当。
avatar
p*2
4
第一题是考溢出吗?
avatar
w*3
5
换个小二, 或换个7-11
it is normal.
avatar
z*n
6
学到就好了,这个骗子太普通太典型了,早就应该看出来了
btw,paypal那,根本不需要给paypal打电话,直接登录你帐号就看到了,没钱到帐啊

【在 y*****y 的大作中提到】
: 由于LD工作变动,最近我们把房子买了,为减轻搬家负担,我们在craigslist上发了卖
: 某些家俱的广告。
: 很快收到电邮,来信者称对我们卖的东西很感兴趣,由于她的工作性质,她不能自由地
: 打电话、上网,她只能通过Paypal付钱给我们,她不在我们所在城市,她本人也不能来
: 取家俱,只能委托运输公司来取货。而对于家俱的价格却只字未提,没有还价。
: 开始我们很高兴,一发广告就有人要买,而且不还价。我们回复她,如果搬家公司在搬
: 运家俱时能够确认家俱的良好状态(我们怕万一家俱运出门后在运输过程中发生破损)
: ,她可以通过Paypal付款,一旦付款成功,她就可以委托运输公司来提货。
: 很快,她的电邮来了,这时我们已经有点怀疑了,她自称上网不方便,可是从她回复电
: 邮的速度看,似乎她一直在网上。她说需要我们的地址,以便让运输公司报价。我们想

avatar
p*2
7
第二题两次binary search是不是就行了?
avatar
b*k
8

周邊另外兩個 一個直接說只能cash 一個完全沒有香草

【在 w*****3 的大作中提到】
: 换个小二, 或换个7-11
: it is normal.

avatar
a*e
9
第一封信一看就是骗子
很经典的骗局
avatar
w*x
10

第二题他说combine both是不是指的是当M, N很大的时候, 开始用binary search, 当
范围缩小后再用linear scan,因为数量小的时候linear scan效率更高? 不过放在这也没什么意
思, 毕竟不是像quick sort那样会产生很多小节点.
写程序不会叫你写二分的solution吧。。。

【在 s*********d 的大作中提到】
: 没什么好说的,还是自己不行。
: 第一题
: abstract class absClass
: {
: public int AddTwoNumbers(int Num1, int Num2)
: {
: return Num1 + Num2;
: }
: public abstract int MultiplyTwoNumbers(int Num1, int Num2);
: }

avatar
w*3
11
same here. so if you can buy, just buy it as much and soon as possible
avatar
H*7
12
外地人来买你的家具,一听就是扯蛋么
avatar
s*d
13
估计是了。这是个问题
public class aaClass extends absClass {
public long MultiplyTwoNumbers(int Num1, int Num2){
long multiplyresult = 0 ;
multiplyresult=Num1*Num2;

return multiplyresult;
}
avatar
b*k
14
昨天買的時候只剩一張

【在 w*****3 的大作中提到】
: same here. so if you can buy, just buy it as much and soon as possible
avatar
z*n
15
craigslist上的回帖一旦有“故事“, 100%是骗子
回帖超过三行,骗子可能性90%

【在 H******7 的大作中提到】
: 外地人来买你的家具,一听就是扯蛋么
avatar
y*g
16
你以前的答案是对的,这个错了。

【在 s*********d 的大作中提到】
: 估计是了。这是个问题
: public class aaClass extends absClass {
: public long MultiplyTwoNumbers(int Num1, int Num2){
: long multiplyresult = 0 ;
: multiplyresult=Num1*Num2;
:
: return multiplyresult;
: }

avatar
m*f
17
看着貌似是一直生活在温室中,生活应该很幸福。。。

【在 y*****y 的大作中提到】
: 由于LD工作变动,最近我们把房子买了,为减轻搬家负担,我们在craigslist上发了卖
: 某些家俱的广告。
: 很快收到电邮,来信者称对我们卖的东西很感兴趣,由于她的工作性质,她不能自由地
: 打电话、上网,她只能通过Paypal付钱给我们,她不在我们所在城市,她本人也不能来
: 取家俱,只能委托运输公司来取货。而对于家俱的价格却只字未提,没有还价。
: 开始我们很高兴,一发广告就有人要买,而且不还价。我们回复她,如果搬家公司在搬
: 运家俱时能够确认家俱的良好状态(我们怕万一家俱运出门后在运输过程中发生破损)
: ,她可以通过Paypal付款,一旦付款成功,她就可以委托运输公司来提货。
: 很快,她的电邮来了,这时我们已经有点怀疑了,她自称上网不方便,可是从她回复电
: 邮的速度看,似乎她一直在网上。她说需要我们的地址,以便让运输公司报价。我们想

avatar
p*2
18

为什么还需要linear scan呢?

【在 w****x 的大作中提到】
:
: 第二题他说combine both是不是指的是当M, N很大的时候, 开始用binary search, 当
: 范围缩小后再用linear scan,因为数量小的时候linear scan效率更高? 不过放在这也没什么意
: 思, 毕竟不是像quick sort那样会产生很多小节点.
: 写程序不会叫你写二分的solution吧。。。

avatar
m*n
19
要先给钱的一看就是骗子
avatar
s*n
20
第一题太搞了吧,就是要用add实现multiply,他没提示你???
第二题就是M*N一维数组的binary search。复杂度log(M*N)
avatar
l*a
21
这个还好了,以前甲板还有一个真被骗走钱的。

【在 m*f 的大作中提到】
: 看着貌似是一直生活在温室中,生活应该很幸福。。。
avatar
s*d
22
我问了他要不要实现,他说不要的!说这题就靠java 基本

【在 s******n 的大作中提到】
: 第一题太搞了吧,就是要用add实现multiply,他没提示你???
: 第二题就是M*N一维数组的binary search。复杂度log(M*N)

avatar
l*s
23
有一个平常心
一般都不会发生这种事
avatar
w*x
24

不知道面试官什么意思, 没太大必要用,比如quicksort当样本很小的时候用
insertsort是为了避免产生很多递归小节点, 这里就直接下来了没多大必要, 不知道
interviewer要什么结果, 可能interviewer随便说说的吧

【在 p*****2 的大作中提到】
:
: 为什么还需要linear scan呢?

avatar
y*y
25
我们没有卖东西的经验,开始只是觉得东西有人买很高兴。还好始终保持警惕性,没让
骗子得手。一定牢记张兄的经验。

【在 z*********n 的大作中提到】
: craigslist上的回帖一旦有“故事“, 100%是骗子
: 回帖超过三行,骗子可能性90%

avatar
w*x
26

为什么是一维数组??

【在 s*********d 的大作中提到】
: 我问了他要不要实现,他说不要的!说这题就靠java 基本
avatar
y*i
27
craigslist上面的警告,是红字的,看起来还不够醒目,要换成48号字才行。
avatar
p*2
28

为什么一维数组?这个不是logN+logM的复杂度吗?这题L面过我,我就是用的logN+
logM的。

【在 s******n 的大作中提到】
: 第一题太搞了吧,就是要用add实现multiply,他没提示你???
: 第二题就是M*N一维数组的binary search。复杂度log(M*N)

avatar
C*K
29
還有寄超額cashier check給你, 然後要求你退差額的....
總之一定要cash only, local only. 其它免談.
avatar
y*u
30
第一题难道不用二进制???

【在 s*********d 的大作中提到】
: 没什么好说的,还是自己不行。
: 第一题
: abstract class absClass
: {
: public int AddTwoNumbers(int Num1, int Num2)
: {
: return Num1 + Num2;
: }
: public abstract int MultiplyTwoNumbers(int Num1, int Num2);
: }

avatar
i*a
31
please read the BIG BOLD RED COLOR HIGHLIGHTED UNDERLINED WARNING on top of
every craigslist ad and email.

【在 y*****y 的大作中提到】
: 由于LD工作变动,最近我们把房子买了,为减轻搬家负担,我们在craigslist上发了卖
: 某些家俱的广告。
: 很快收到电邮,来信者称对我们卖的东西很感兴趣,由于她的工作性质,她不能自由地
: 打电话、上网,她只能通过Paypal付钱给我们,她不在我们所在城市,她本人也不能来
: 取家俱,只能委托运输公司来取货。而对于家俱的价格却只字未提,没有还价。
: 开始我们很高兴,一发广告就有人要买,而且不还价。我们回复她,如果搬家公司在搬
: 运家俱时能够确认家俱的良好状态(我们怕万一家俱运出门后在运输过程中发生破损)
: ,她可以通过Paypal付款,一旦付款成功,她就可以委托运输公司来提货。
: 很快,她的电邮来了,这时我们已经有点怀疑了,她自称上网不方便,可是从她回复电
: 邮的速度看,似乎她一直在网上。她说需要我们的地址,以便让运输公司报价。我们想

avatar
b*v
32
log(mn)=log(m)+log(n)

★ 发自iPhone App: ChineseWeb - 中文网站浏览器

【在 p*****2 的大作中提到】
:
: 为什么一维数组?这个不是logN+logM的复杂度吗?这题L面过我,我就是用的logN+
: logM的。

avatar
p*2
33

我数学太差了。呵呵。

【在 b******v 的大作中提到】
: log(mn)=log(m)+log(n)
:
: ★ 发自iPhone App: ChineseWeb - 中文网站浏览器

avatar
p*2
34

这个比较靠谱。不然没什么好考察的。

【在 y**********u 的大作中提到】
: 第一题难道不用二进制???
avatar
y*g
35
第一题什么都不用,主要用来拒三年制阿三的。
avatar
w*o
36
第二题的2D Matrix 和这个网站上的数组不一样吧。你的这个数组更简单些。
http://stackoverflow.com/questions/2457792/given-a-2d-array-sor
这道题就做两次binary search就好了。先是最后一列,确定某行,然后在那行在做一
次BS.
http://stackoverflow.com/questions/2457792/given-a-2d-array-sor
的解法,本版过去有讨论过。

【在 s*********d 的大作中提到】
: 没什么好说的,还是自己不行。
: 第一题
: abstract class absClass
: {
: public int AddTwoNumbers(int Num1, int Num2)
: {
: return Num1 + Num2;
: }
: public abstract int MultiplyTwoNumbers(int Num1, int Num2);
: }

avatar
S*t
37
Java不懂,第一题就不讨论了
第二题我看了很久都不明白这和1D的binary search有任何区别
任意一个sorted array不都可以排成这样一个2d matrix么
没有任何附加信息啊,还是O(logM + logN)啊。。。

【在 s*********d 的大作中提到】
: 没什么好说的,还是自己不行。
: 第一题
: abstract class absClass
: {
: public int AddTwoNumbers(int Num1, int Num2)
: {
: return Num1 + Num2;
: }
: public abstract int MultiplyTwoNumbers(int Num1, int Num2);
: }

avatar
w*x
38

你面试时候写的是binary search的code? 那得花多长时间啊

【在 p*****2 的大作中提到】
:
: 这个比较靠谱。不然没什么好考察的。

avatar
a*o
39
弱问一下L家是哪家?

【在 s*********d 的大作中提到】
: 没什么好说的,还是自己不行。
: 第一题
: abstract class absClass
: {
: public int AddTwoNumbers(int Num1, int Num2)
: {
: return Num1 + Num2;
: }
: public abstract int MultiplyTwoNumbers(int Num1, int Num2);
: }

avatar
p*2
40

好像code不长呀。不过那时候我太弱了,只是有个概念,code里有bug,但是还给我过
了。

【在 w****x 的大作中提到】
:
: 你面试时候写的是binary search的code? 那得花多长时间啊

avatar
m*n
41
在stackoverflow上看到一个算法。。不知道对不对
bool numberSearch(int[][] arr, int value, int minX, int maxX, int minY, int
maxY)
if (minX == maxX and minY == maxY and arr[minX,minY] != value)
return false
if (arr[minX,minY] > value) return false; // Early exits if the value can't
be in
if (arr[maxX,maxY] < value) return false; // this subrange at all.
int nextX = (minX + maxX) / 2
int nextY = (minY + maxY) / 2
if (arr[nextX,nextY] == value)
{
print nextX,nextY
return true
}
else if (arr[nextX,nextY] < value)
{
if (numberSearch(arr, value, minX, maxX, nextY + 1, maxY))
return true
return numberSearch(arr, value, nextX + 1, maxX, minY, nextY)
}
else
{
if (numberSearch(arr, value, minX, nextX - 1, minY, maxY))
return true
reutrn numberSearch(arr, value, nextX, maxX, minY, nextY)
}
avatar
s*d
42
我自己做出来了,主要是边界条件的问题。
public boolean bsearch2(int[][] p, int val, int xlo, int xhi, int ylo,
int yhi) {
if (xlo == xhi && ylo == yhi && (p[xlo][ylo] != val))
return false;
if (p[xlo][ylo] > val)
return false;
if (p[xhi][yhi] < val)
return false;// end conditon
int midi = (xlo + xhi) / 2;
int midj = (ylo + yhi) / 2;
//binary search
if (p[midi][midj] == val) {
System.out.println(midi);
System.out.println(midj);
return true;
} else if (p[midi][midj] < val) {
if (bsearch2(p, val, midi, midi, midj + 1, yhi)) {
return true;
} else
return bsearch2(p, val, midi + 1, xhi, ylo, yhi);
} else if (p[midi][midj] > val) {
if (bsearch2(p, val, midi, midi, ylo, midj-1)) {
return true;
} else
return bsearch2(p, val, xlo, midi - 1, ylo, yhi);
}
return false;
}
avatar
i*e
43
写了非递归的版本:
const int MAX_ROW = 512;
const int MAX_COL = 512;
int searchRow(int A[][MAX_COL], int m, int target) {
int L = 0, R = m-1;
while (L < R) {
int M = (L+R+1)/2;
if (target < A[M][0]) {
R = M-1;
} else {
L = M;
}
}
return (A[L][0] <= target) ? L : -1;
}
int searchCol(int A[][MAX_COL], int row, int n, int target) {
int L = 0, R = n-1;
while (L < R) {
int M = (L+R+1)/2;
if (target < A[row][M]) {
R = M-1;
} else {
L = M;
}
}
return (A[row][L] == target) ? L : -1;
}
bool search(int A[][MAX_COL], int m, int n, int target) {
int row = searchRow(A, m, target);
if (row == -1) return false;
int col = searchCol(A, row, n, target);
if (col == -1) return false;
return true;
}
avatar
w*x
44

这个不对吧, 怎么一横一竖跑两遍就完了呢?? 我贴一个超长版的:
int _inner_search_row(int A[M][N], int nIterRow, int nIterCol, int nTg);
int _inner_search_col(int A[M][N], int nIterRow, int nIterCol, int nTg);
bool FindTarget2(int A[M][N], int nTg)
{
int nIterRow = 0;
int nIterCol = N-1;
while (nIterCol >= 0 && nIterRow < M && A[nIterRow][nIterCol] != nTg)
{
nIterRow = _inner_search_row(A, nIterRow, nIterCol, nTg);
nIterCol = _inner_search_col(A, nIterRow, nIterCol, nTg);
}
return nIterRow >= 0 && nIterRow < M;
}
int _inner_search_col(int A[M][N], int nIterRow, int nIterCol, int nTg)
{
if (nIterCol < 0 && nIterRow >= M)
return nIterCol;
int nBeg = 0;
int nEnd = nIterCol;
while (nBeg <= nEnd)
{
int nMid = (nBeg + nEnd)/2;
if (A[nIterRow][nMid] == nTg || (A[nIterRow][nMid] < nTg
&& (nMid == nIterCol || A[nIterRow][nMid+1] >= nTg)))
return nMid;
else if (A[nIterRow][nMid] < nTg)
nBeg = nMid + 1;
else nBeg = nMid - 1;
}
return -1;
}
int _inner_search_row(int A[M][N], int nIterRow, int nIterCol, int nTg)
{
if (nIterCol < 0 && nIterRow >= M)
return nIterRow;
int nBeg = nIterRow;
int nEnd = M-1;
while (nBeg <= nEnd)
{
int nMid = (nBeg + nEnd)/2;
if (A[nMid][nIterCol] == nTg || (A[nMid][nIterCol] > nTg
&& (nMid == 0 || A[nMid-1][nIterCol] <= nTg)))
return nMid;
else if (A[nMid][nIterCol] < nTg)
nBeg = nMid + 1;
else nBeg = nMid - 1;
}
return -1;
}

【在 i**********e 的大作中提到】
: 写了非递归的版本:
: const int MAX_ROW = 512;
: const int MAX_COL = 512;
: int searchRow(int A[][MAX_COL], int m, int target) {
: int L = 0, R = m-1;
: while (L < R) {
: int M = (L+R+1)/2;
: if (target < A[M][0]) {
: R = M-1;
: } else {

avatar
q*y
45
弱问,第二题最优解不是Young tableau http://en.wikipedia.org/wiki/Young_tableau linear search吗,从左下角开始,复杂度 O(m+n)?

【在 s*********d 的大作中提到】
: 没什么好说的,还是自己不行。
: 第一题
: abstract class absClass
: {
: public int AddTwoNumbers(int Num1, int Num2)
: {
: return Num1 + Num2;
: }
: public abstract int MultiplyTwoNumbers(int Num1, int Num2);
: }

avatar
l*a
46
binary search一遍结束,你这个recursion cost有点大

int
't

【在 m***n 的大作中提到】
: 在stackoverflow上看到一个算法。。不知道对不对
: bool numberSearch(int[][] arr, int value, int minX, int maxX, int minY, int
: maxY)
: if (minX == maxX and minY == maxY and arr[minX,minY] != value)
: return false
: if (arr[minX,minY] > value) return false; // Early exits if the value can't
: be in
: if (arr[maxX,maxY] < value) return false; // this subrange at all.
: int nextX = (minX + maxX) / 2
: int nextY = (minY + maxY) / 2

avatar
l*a
47
第一题到底考什么?
为什么不是
return Num1*Num2;
如果说溢出的话,那个Add就不溢出了?
请牛人指点!!!

【在 s*********d 的大作中提到】
: 没什么好说的,还是自己不行。
: 第一题
: abstract class absClass
: {
: public int AddTwoNumbers(int Num1, int Num2)
: {
: return Num1 + Num2;
: }
: public abstract int MultiplyTwoNumbers(int Num1, int Num2);
: }

avatar
l*a
48
根据题意,实际上可以看成一个有序一维数组。一遍binary search will work
bool contains(int a[][],int index,int target)
{
int y=index%n;
int x=index/n;
return target==a[x][y];
}
bool Search(int a[][],int m,int n,int target)
{
int lo=0;
int hi=m*n-1;
int x,y;
while(lo{
int mid=lo+(hi-lo)>>1;
if(contains(a,mid,target) return true;
if(targetelse lo=mid;
}
if(contains(a,hi,target) return true;
if(contains(a,lo,target) return true;
return false;
}
avatar
p*2
49

chengdu说的,考察的是binary search。

【在 l*****a 的大作中提到】
: 第一题到底考什么?
: 为什么不是
: return Num1*Num2;
: 如果说溢出的话,那个Add就不溢出了?
: 请牛人指点!!!

avatar
i*e
50
对所有行第一列进行 binary search,然后对那一行的所有列进行第二次的 binary
search.
先找出最大的一行的第一个值满足 <= target 条件,然后要找的target必定在那一行
的其中一列。如果不在的话,那就代表matrix没有那个值。

【在 w****x 的大作中提到】
:
: 这个不对吧, 怎么一横一竖跑两遍就完了呢?? 我贴一个超长版的:
: int _inner_search_row(int A[M][N], int nIterRow, int nIterCol, int nTg);
: int _inner_search_col(int A[M][N], int nIterRow, int nIterCol, int nTg);
: bool FindTarget2(int A[M][N], int nTg)
: {
: int nIterRow = 0;
: int nIterCol = N-1;
: while (nIterCol >= 0 && nIterRow < M && A[nIterRow][nIterCol] != nTg)
: {

avatar
i*e
51
不是。
读清楚题意,这个是每一列的第一个值大于之前一行的最后一个值。
Young tableau 是某一列的值不小于之前一行同一列的值。

【在 q***y 的大作中提到】
: 弱问,第二题最优解不是Young tableau http://en.wikipedia.org/wiki/Young_tableau linear search吗,从左下角开始,复杂度 O(m+n)?
avatar
l*8
52
没人回,我回一下吧:)
LinkedIn

【在 a*******o 的大作中提到】
: 弱问一下L家是哪家?
avatar
w*x
53

是吗? 我一直认为是不断的search, 下面这个matrix找左下角的7:
1 2 3 4
3 5 8 9
6 6 8 10
7 15 18 20
我的方法是 4->9 9->5 5->15, 15->7
你怎么一行一列找出来??

【在 i**********e 的大作中提到】
: 对所有行第一列进行 binary search,然后对那一行的所有列进行第二次的 binary
: search.
: 先找出最大的一行的第一个值满足 <= target 条件,然后要找的target必定在那一行
: 的其中一列。如果不在的话,那就代表matrix没有那个值。

avatar
p*2
54

你这个例子不是这道题的吧?

【在 w****x 的大作中提到】
:
: 是吗? 我一直认为是不断的search, 下面这个matrix找左下角的7:
: 1 2 3 4
: 3 5 8 9
: 6 6 8 10
: 7 15 18 20
: 我的方法是 4->9 9->5 5->15, 15->7
: 你怎么一行一列找出来??

avatar
y*g
55
我已经说过了,第一题没什么考点。。
http://www.mitbbs.com/article0/JobHunting/32088049_0.html

【在 l*****a 的大作中提到】
: 第一题到底考什么?
: 为什么不是
: return Num1*Num2;
: 如果说溢出的话,那个Add就不溢出了?
: 请牛人指点!!!

avatar
w*x
56

晕, 还以为是杨氏矩阵, 不好意思哈哈

【在 p*****2 的大作中提到】
:
: 你这个例子不是这道题的吧?

avatar
d*a
57
写个简单的啊,O(lgn)时间,O(1)空间。
const int ROW = 100;
const int COLUMN = 50;
int get_value(int a[][COLUMN], int m, int n, int pos)
{
int row_pos = pos / n;
int col_pos = pos % n;

return a[row_pos][col_pos];
}

bool binary_search(int a[][COLUMN], int m, int n, int target)
{
int middle;
int start = 0;
int end = m * n - 1;
int middle_value;

while(start <= end)
{
middle = start + (end - start) / 2;
middle_value = get_value(a, m, n, middle);
if( target == middle_value)
return true;
else if(target < middle_value)
{
end = middle - 1;
}
else
{
start = middle + 1;
}
}

return false;
}
avatar
X*K
58
第一题如果不考虑溢出的话似乎也就是加一个可有可无的@Override了:
public class aaClass extends absClass {
@Override
public int MultiplyTwoNumbers(int Num1, int Num2) {
int multiplyresult = 0 ;
multiplyresult=Num1*Num2;

return multiplyresult;
}

【在 s*********d 的大作中提到】
: 没什么好说的,还是自己不行。
: 第一题
: abstract class absClass
: {
: public int AddTwoNumbers(int Num1, int Num2)
: {
: return Num1 + Num2;
: }
: public abstract int MultiplyTwoNumbers(int Num1, int Num2);
: }

avatar
l*a
59
why not
return Num1*Num2?

【在 X*K 的大作中提到】
: 第一题如果不考虑溢出的话似乎也就是加一个可有可无的@Override了:
: public class aaClass extends absClass {
: @Override
: public int MultiplyTwoNumbers(int Num1, int Num2) {
: int multiplyresult = 0 ;
: multiplyresult=Num1*Num2;
:
: return multiplyresult;
: }

avatar
w*y
60
第一题什么意思? 完全不明白在问什么。。。。。。。。。。 5555555555
第二题,就是mid =(low+high)/2, 从low = 0, high =m*n-1开始做binary search吧?
每次用/ %把 mid转化为矩阵里面的行、列值
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。