摘要:
Question Given n non negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in 阅读全文
摘要:
Question Given a non empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time 阅读全文
摘要:
Question Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three 阅读全文
摘要:
Question Sort a linked list in O(n log n) time using constant space complexity. Solution 分析,时间复杂度要求为nlogn,因此得考虑归并排序,但是空间必须为常量,因此得注意指针的操作。 Code 阅读全文
摘要:
为了依次求个位,十位,百位中1的个数,我们可以把这个数字分为三部分,高位数字,当前位数字,低位数字。 如果当前位为0,那么此位为1的数目与高位数字有关 如果当前位为1,那么此位为1的数目与高位和地位都有关 如果当前位其他,那么此位为1的数目与高位数字有关 具体规律看源代码 C++ include u 阅读全文
摘要:
这个和一个数组中,存在某个数的数目是超过总数的一半的,找出这个数的原理是一样的。 做法就是统计三个数的数目,相同就加1,和三个数都不同,三个数都减1,因为它们的数目是超过1/4的,那么它们三个最后肯定是留下来的。 算法时间复杂度O(N) C++ include include using names 阅读全文