SHOW:
|
|
- or go back to the newest paste.
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( (!nums[pos]) && numMoves<nums.size() ){ //run through array |
9 | + | while( (pos!=0) && numMoves<nums.size() ){ //run through array |
10 | move=nums[pos]; | |
11 | - | nums[pos]=0; //set position to zero |
11 | + | |
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 | } |