You are viewing a single comment's thread. Return to all comments →
public static void main(String[] args) { Scanner scan = new Scanner(System.in); int times = scan.nextInt(); scan.nextLine(); String UDs = scan.nextLine(); int[] levels = new int[times]; int up = 0, down = 0, count = 0; for (int i = 0; i < times; i++) { if (UDs.charAt(i) == 'U') { up++; } else { down++; } levels[i] = up - down; } for(int i=0; i<times;i++){ if(levels[i]<0){ for(int ii = i; ii<times;ii++){ if(levels[ii]==0){ count++; i=ii; break; } } } } System.out.println(count); } }
I thought i did well but looking at the very first commment, I realized im not good
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 →
I thought i did well but looking at the very first commment, I realized im not good