forked from RyanFehr/HackerRank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
32 lines (26 loc) · 836 Bytes
/
Solution.java
File metadata and controls
32 lines (26 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//Problem: https://www.hackerrank.com/challenges/jumping-on-the-clouds
//Java 8
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int c[] = new int[n];
for(int c_i=0; c_i < n; c_i++){
c[c_i] = in.nextInt();
}
int jumps = 0;
int i = 0;
while(i < n-3) //goes through all clouds up until the last jump
{
i += (c[i+2] == 0) ? 2 : 1;
jumps++;
}
jumps++;//This is the last jump that will be either a 1 or 2
System.out.println(jumps);
}
}