You are viewing a single comment's thread. Return to all comments →
my java solution
public static int countingValleys(int steps, String path) { int level = 0; int valleys = 0; char[] charPath = path.toCharArray(); for(char ch: charPath){ int startLevel = level; if(ch=='U'){ level++; }else{ level--; } if(level<0 && startLevel>=0){ valleys++; } } return valleys; }
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 java solution