You are viewing a single comment's thread. Return to all comments →
int countingValleys(int steps, string path) { int down=0,in_valleys=0,up=0,count=0 ; for(int i=0;i<path.size();i++){ if(path[i]=='U') up++; if(path[i]=='D') down++; if(down-up>0&&in_valleys==0){ count++; in_valleys++; } if(down-up==0&&in_valleys!=0){ in_valleys =0; } } return count; }
Seems like cookies are disabled on this browser, please enable them to open this website
Counting Valleys
You are viewing a single comment's thread. Return to all comments →