Advertisement
AI_UBI

Optimized search amount of numbers between few maximum nums

Dec 10th, 2015
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.29 KB | None | 0 0
  1. unsigned check(int *Items, int Count)
  2. {
  3.     int max = 0, start = 0, end = 0;
  4.    
  5.     while(Count--)
  6.     {
  7.         if (Items[Count] > max)
  8.         {
  9.             max = Items[Count];
  10.             start = end = Count;
  11.         }
  12.         else if (Items[Count] == max)
  13.         {
  14.             end = Count;
  15.         }
  16.     }
  17.  
  18.     return start == end ? 0 : (start - end - 1);
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement