一道機試題

2021-07-10 21:48:45 字數 1673 閱讀 3037

and return the new length.

do not allocate extra space for another array, you must do this in place with constant memory.

for example, given input array a = [1,1,2] ,

your function should return length = 2, and a is now [1,2] .

my method:

/*

and return the new length.

do not allocate extra space for another array, you must do this in place with constant memory.

for example, given input array a = [1,1,2] ,

your function should return length = 2, and a is now [1,2] .

*/#include#includevoid main()

; //陣列樣式

int len = sizeof(a)/sizeof(a[0]); //len為陣列長度

int stc_len = len;

int temp;

for (int i = 0; i < len - 1; i++) }

printf("陣列的長度為%d\n", stc_len);

for (int i = 0; i < stc_len; i++)

printf("%d ", a[i]);

printf("\n");

system("pause");

}

the reference:

/*

and return the new length.

do not allocate extra space for another array, you must do this in place with constant memory.

for example, given input array a = [1,1,2] ,

your function should return length = 2, and a is now [1,2] .

*/#include#includevoid main()

; //陣列樣式

int len = sizeof(a)/sizeof(a[0]); //len為陣列長度

int index = 0;

for (int i = 1; i < len; i++)

index++;

for (int i = 0; i < index; i++)

printf("%d ", a[i]);

system("pause");

}

執行結果:

陣列的長度為2

1 2

請按任意鍵繼續. . .

思考???

對於無序的陣列應該這麼做呢???

一道oracle試題

做不出來時感覺好難啊,思路千千萬,就是沒想到用 order by 和 rownum 題目如下 有下面三個表 商品product 商品號productid,商品名productname,單價unitprice,商品類別category,商provider 顧客customer 顧客號customeri...

一道筆試題

看到一道筆試題,跟自己想的有點出入,就跑了下,看了看原因。我稍微改了下 include int main int argc,char argv 輸出結果 c 5 d 245 press any key to continue vc6.0 debug下的彙編 5 unsigned char a 0xa...

一道筆試題

上次去筆試的時候,有一道題,怎麼也沒做出來,當時也是很緊張,有些思路,但卻沒有做出來。有四個人要過乙個獨木橋,因為天比較黑,而且橋只能允許兩個人同時通過,並且他們只有乙個手電筒。四個人單獨同時橋的時間是1,2,5,8分鐘。問最短的時間是多少?當時我的答案 1和8,1回來,1 5,1回來,1 2 8 ...