If You and Me

What is Forever?

导航

2015年7月21日 #

面试题五 数组中出现次数超过一半的数字 时间为O(n)

摘要: 也就是说该数字出现的次数比其他所有数字出现次数的和还要多。因此可以保存两个值,一个数字,一个次数。遍历时1、如果数字相同,count++2、如果count == 0 count = 1 number替换 3、如果不相同 count--int main(){ int array[] = {... 阅读全文

posted @ 2015-07-21 23:20 alwaystiys 阅读(377) 评论(0) 推荐(0) 编辑