An interesting question. The key is: can you make your code cleaner?
See one of example below:
int jumpingOnClouds(vector<int> c) { int res = 0; for(int i=0; i+1<c.size(); ) {//only need to reach the last one; if(i+2<c.size() && c[i+2] == 1) ++i;//can only jump one step; else i += 2;//jump two steps; ++res; } return res; }
No comments:
Post a Comment