You are viewing a single comment's thread. Return to all comments →
My solution c++
int countingValleys(int steps, string path) { int stepsCount=0,valley=0; for(int i=0; i<steps; i++){ if(path[i]=='U'){ stepsCount++; if(stepsCount==0) valley++; } else if(path[i]=='D'){ stepsCount--; } } return valley; }
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 →
My solution c++