You are viewing a single comment's thread. Return to all comments →
int seaLevel = 0; int valleyCount = 0; for (char step : path.toCharArray()) { if (step == 'U') { seaLevel++; if (seaLevel == 0) { valleyCount++; } } else { seaLevel--; } } return valleyCount;
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 →