1234567891011121314151617181920 |
- /* Create a function that takes an
- * array of hurdle heights and a jumper's jump height, and determine
- * whether or not the hurdler can clear all the hurdles.
- * A hurdler can clear a
- * hurdle if their jump height is greater than or equal to the hurdle height.
- */
- bool hurdleJump(std::vector<int> hurdles, int jumpHeight) {
- if (hurdles.size()==0){return true;}
- int greatestHurdleheight = hurdles[0];
- // loop through array of hurdles comparing the jump height to each hurdle
- // return true only if the jumper height is greater than EVERY hurdle in the array
- for(int i=0;i<hurdles.size()-1;i++){
- // compare each hurdle to the previous one, save greatest hurdle
- if(hurdles[i]<hurdles[i+1]){
- greatestHurdleheight = hurdles[i+1];
- }
- }
- return jumpHeight>=greatestHurdleheight;
- }
|