又一道面试题,我是不是想多了?# Programming - 葵花宝典
h*o
1 楼
Question: Given the following prototype:
int compact(int * p, int size);
Write a function that will take a sorted array, possibly with duplicates,
and compact the array, returning the new length of the array. That is, if p
points to an array containing: 1, 3, 7, 7, 8, 9, 9, 9, 10, when the function
returns, the contents of p should be: 1, 3, 7, 8, 9, 10, with a length of 6
returned.
我觉得要分情况如果min(p)和max(p)差距小,就用设标注位的方法。
如果min(p)和max(p)差距大,size小,就用hash的方法。对吗?
用hash怎么做那?
int compact(int * p, int size);
Write a function that will take a sorted array, possibly with duplicates,
and compact the array, returning the new length of the array. That is, if p
points to an array containing: 1, 3, 7, 7, 8, 9, 9, 9, 10, when the function
returns, the contents of p should be: 1, 3, 7, 8, 9, 10, with a length of 6
returned.
我觉得要分情况如果min(p)和max(p)差距小,就用设标注位的方法。
如果min(p)和max(p)差距大,size小,就用hash的方法。对吗?
用hash怎么做那?