You are viewing a single comment's thread. Return to all comments →
public static int countingValleys(int steps, String path) { // Write your code here int step =0; int count = 0; for(int i = 0; i < path.length(); i++){ if(path.charAt(i) == 'U'){ step++; }else if(path.charAt(i) == 'D'){ if(step == 0){ count++; } step--; } } 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 →