yangjian0219
BAN USERit accept a string, but the pointer pch pointed to char.
if(*pch==NULL || !strcmp(pch," ")) instead of take off the first*, I think should add the second*...
It should be if(*pch==NULL || strcmp(*pch," "))
How about using Heap; First create Heap cost O(n). Then every node in the heap only need to compare with the lower level. In this way, there are at most 2n comparison. In this way, the time complexity is O(n).
- yangjian0219 March 20, 2011
Repamberdjohnson859, Backend Developer at ABC TECH SUPPORT
We are Responsible Environmental Technicians utilizing all of the resources available to develop practical solutions to corporate issues. Currently doing ...
RepKayraKing, abc at A9
I am an expert aircraft maintenance engineer with a high degree of technical knowledge and manual dexterity. In my spare ...
RepKarlOlson, job tessio at design
I am Karl .Transportation ticket agent, I help plan travel itineraries by suggesting local tourist attractions and places of interest ...
RepJulianMiller, abc at ABC TECH SUPPORT
I am a professional auditing assistant with extensive experience in handling administrative duties and executive responsibilities associated with both internal ...
How about using max heap
- yangjian0219 April 19, 20111. take out the first K number, reverse it and save it in a heap H;
2. i=1 at first, compare A[i]+A[i+1] with the root of heap H[0], if lesser then abstract the maximum and insert the sum. loop until A[i]+A[i+1]>H[0].
3. i=1 at first,compare A[i]+A[i+1]+A[i+2] with the root of heap H[0], if lesser then abstract the maximum and insert the sum. loop until A[i]+A[i+1]+A[i+2]>H[0].
the first step cost O(K) while second and third step take O(KlogK).