题目来源
题目: http://hihocoder.com/problemset/problem/1136
前几天Google onsite面试,已挂。今天仔细思考了面试中一道没写出来的题,发现也并不难。诶,只能怪当时脑抽了。
给定一个巨大的无序数组,输出数组中出现次数最多的K个数。
参数都是一样的:
make_heap(first ,last)
make_heap(first ,last, cmpObject)
将[first, last)
范围进行堆排序,默认使用less<int>
, 即最大元素放在第一个。
pop_heap(first ,last)
pop_heap(first ,last, cmpObject)
在一个排序的链表中,存在重复的结点,请删除该链表中重复的结点,重复的结点不保留,返回链表头指针。例如,链表 1->2->3->3->4->4->5 处理后为 1->2->5
这题看似很简单,但是务必考虑如下情形:
时间复杂度最低的方法是,修改归并排序(Merge Sort),在排序同时对逆序对计数。时间复杂度为 \(O(n\log{n})\)。
C99 inline semantics are often misunderstood. The inline specifier serves two purposes:
First, as a compiler hint in case of
static inline
andextern inline
declarations. Semantics remain unchanged if you remove the specifier.
Second, in case of raw inline (ie without
static
orextern
) to provide an inline definition as an alternative to an external one, which has to be present in a different translation unit. Not providing the external one is undefined behaviour, which will normally manifest as linking failure.
写过C程序都知道,malloc了新的struct之后,经常跟着一大串的赋值。其实这些可以用一行漂亮的代码搞定。
先上代码:
1 | #define new(type, ...) ({\ |
前段时间脑子一热就投了阿里巴巴的平台型产品经理。这段时间一直忙自己的事情,也没时间顾及这个面试。昨天晚上查了下资料,平台型产品经理是今年才有的职位,所以网上也没有什么资料,于是改改PPT就睡了(PPT是阿里面试前发邮件给大家要求做的作业)。
博主是一只大三渣本,计算机专业。三月份开学之后,各种实习机会纷纷开始,以死猪不怕开水烫的陆续投了五家业内顶尖的公司,拿到了4个Offer。能有这样的结局也出乎我预料,为了照顾以后的学弟学妹们,在此把我的经历和体会都记下来。