Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. bool checkArr(vector <int> nums){
  2.   int numMoves=0;   //number of moves taken
  3.   int pos=0;        //current position
  4.   int move;         //temporary storage of current spot
  5.   if(nums.size()==1)//if there's only one, then it's proven to always work
  6.     return true;
  7.   if(!nums.size())//if it's empty, say it doesn't work. Unless we say it does?
  8.     return false;
  9.   while( (pos!=0) && numMoves<nums.size() ){ //run through array
  10.     move=nums[pos];
  11.     pos+=move;   //move over
  12.     if(pos<0)    //adjust to fit inside array
  13.       pos+=nums.size();
  14.     pos%=nums.size();
  15.     numMoves++;
  16.   }
  17.   if(pos==0 && numMoves==nums.size())
  18.     return true;
  19.   return false;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement