You are viewing a single comment's thread. Return to all comments →
int countingValleys(int steps, string path) { int path_counter = 0, valeys = 0; bool topo = true; for(char c : path){ if(c=='U'){ path_counter++; if(path_counter>=0){ topo = true; } } if(c=='D'){ path_counter--; if(path_counter<0 && topo){ valeys++; topo = false; } } } return valeys; }
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 →