IT 討論區(48)最強工種,FG25K,你!敢唔敢成功?

1001 回覆
6 Like 0 Dislike
2018-11-26 18:33:47
果d題目啱哂先最難,仲要限數
總有d陰濕野例如俾個array你要預埋length係1
佢sample全正數你要預埋有負數
佢sample隻隻數唔同你要預可能隻隻數一樣
甚至result唔好加到多過int max value
好多陰濕野

衰左,果刻最後慌撚左諗唔到點做return
2018-11-26 18:37:32
<pre><code data-type="">public class Solution {

public int[] powerSet;

public int[] solution(int[] A) {
int length = A.length;
if (length == 0)
return A;
powerSet = new int[length];
int sum = 0;
for (int i = 0; i < A.length; i++) {
if (A[i] == 1) {
int power = pow(-2, i);
powerSet[i] = power;
sum += power;
}
}

int ceil;
if (sum % 2 == 1 && sum > 0) {
ceil = sum / 2 + 1;
} else {
ceil = sum / 2;
}
if (ceil == 0) {
return A;
}

int index = getLeadingIndex(ceil);
int[] array = new int[index+1];
array[index] = 1;
ceil -= powerSet[index];
while (ceil != 0) {
index = getLeadingIndex(ceil);
array[index] = 1;
ceil -= powerSet[index];
}

return array;
}

public int pow(int base, int power) {
int number = 1;
while (power-- > 0) {
number *= base;
}
return number;
}

public int getLeadingIndex (int number) {
int index = 0;
int sum = 0;
if (number > 0) {
index = -2;
while (sum < number) {
index += 2;
sum += powerSet[index];
}
} else if (number < 0) {
index = -1;
while (sum > number) {
index += 2;
sum += powerSet[index];
}
}
return index;
}
}</code></pre>
漏咗個checking ceil == 0

cap少左野
最尾一定要1
2018-11-26 18:48:05
依家xamarin 多唔多公司用
2018-11-26 19:02:29
int[] array = new int[index+1];
array[index] = 1;

有呢兩行,所以一定係1,唔明你意思
2018-11-26 19:09:18
通常題目一堆test case,maybe 20個,大部分test case 係test time complexity即係big input,少部分係test careless mistakes,通常time complexity過都過,不過做得多就可以排除埋D careless mistakes
2018-11-26 19:31:13
個offer包D咩?
2018-11-26 19:32:39
日本妹
2018-11-26 19:33:18
EG:
[0,1,1]
[1,1,1]
[0,0,0,0,1]
2018-11-26 19:33:37
咁你仲唔遞信?
2018-11-26 19:34:18
想痴住你
2018-11-26 19:34:54
上面咪再貼曲啦
一間無囡入來做IT,DLLM
2018-11-26 19:36:29
咁我遞信囉
2018-11-26 19:37:09
風褸 —— IT professional 的象徵

http://lih.kg/bOqxBT
2018-11-26 19:37:14
跟,你apply邊間單聲,一齊
2018-11-26 19:37:46
係囉,毒氣熏天
2018-11-26 19:44:32
本來都無架啦
2018-11-26 19:50:38
屌,好撚gay
2018-11-26 19:53:09


今朝嗰條題目⋯
返工時試咗陣,諗唔到點樣可以唔洗用if(試過&1 x-2 +1呢啲低能野,計得啱但好難睇)
又諗唔到點樣可以純bitwise op做到

其實正常IT狗係咪真係要識寫
2018-11-26 19:55:02
有女,不了
2018-11-26 19:55:19
唔洗識, 呢D題目只會出現學校
番工剪剪貼貼就夠
2018-11-26 20:01:14
好想去日本剪剪貼貼
2018-11-26 20:03:00
有冇人識proof條題upper bound
2018-11-26 20:05:10
請外援都想請個叻啲醒啲過去做架
反正都係剪剪貼貼
咁樣睇落抵啲平靚正嘛
2018-11-26 20:12:04
香港吹水in又係3xk,日本搞咁多嘢都係3xk,但去日本搞完咁多嘢可以避免第時遇到咩都唔識嘅60k
吹水台自選台熱 門最 新手機台時事台政事台World體育台娛樂台動漫台Apps台遊戲台影視台講故台健康台感情台家庭台潮流台美容台上班台財經台房屋台飲食台旅遊台學術台校園台汽車台音樂台創意台硬件台電器台攝影台玩具台寵物台軟件台活動台電訊台直播台站務台黑 洞