You are viewing a single comment's thread. Return to all comments →
This is my java code which is easy to understand.
public static int countingValleys(int steps, String path) { int valleyCount = 0; boolean valleyEntered = false; int level = 0; for(int i=0; i<steps; i++){ if(path.charAt(i)== 'U') level++; else level--; if(level < 0) valleyEntered = true; if(valleyEntered == true && level == 0){ valleyCount++; valleyEntered = false; } } 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 →
This is my java code which is easy to understand.