Advertisement
leoalvaleo

skyline_solution() - Leonardo Alvarez

May 25th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. int skyline_solution(const unsigned int skylineHeights[], unsigned int arrLen) {
  2.  
  3.     if (arrLen <= 0) { return 0; }
  4.  
  5.     unsigned int stripes = skylineHeights[0];
  6.  
  7.     for (int i = 1; i < arrLen; i++)
  8.     {
  9.         if (skylineHeights[i] > skylineHeights[i - 1]) {
  10.             stripes += (skylineHeights[i] - skylineHeights[i - 1]);
  11.         }
  12.     }
  13.  
  14.     if (stripes > 1000000000) { return -1; }
  15.  
  16.     return stripes;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement