We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
publicstaticintcountingValleys(intsteps,Stringpath){// Write your code hereintsea_Level=0;intvalley=0;for(inti=0;i<path.length();i++){charch=path.charAt(i);switch(ch){case'U':sea_Level++;// Check if we just came up to sea level from a valleyif(sea_Level==0){valley++;}break;case'D':sea_Level--;break;}}returnvalley;}
Cookie support is required to access HackerRank
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 →
JavaSolution