You are viewing a single comment's thread. Return to all comments →
Basic Understading: Valley when hiker at sea level after last step is U.
public static int countingValleys(int steps, String path) { // Write your code here int valleys = 0, route = 0; char[] ch = path.toCharArray(); for (int i = 0; i < steps; i++) { if ('U' == (ch[i])) route += 1; else route += -1; if (route == 0 && 'U' == ch[i]) // Basic Understanding 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 →
Java Solution
Basic Understading: Valley when hiker at sea level after last step is U.