Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool checkArr(vector <int> nums){
- int numMoves=0; //number of moves taken
- int pos=0; //current position
- int move; //temporary storage of current spot
- if(nums.size()==1)//if there's only one, then it's proven to always work
- return true;
- if(!nums.size())//if it's empty, say it doesn't work. Unless we say it does?
- return false;
- while( (pos!=0) && numMoves<nums.size() ){ //run through array
- move=nums[pos];
- pos+=move; //move over
- if(pos<0) //adjust to fit inside array
- pos+=nums.size();
- pos%=nums.size();
- numMoves++;
- }
- if(pos==0 && numMoves==nums.size())
- return true;
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement