File tree Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .io .*;
2
+ import java .math .*;
3
+ import java .security .*;
4
+ import java .text .*;
5
+ import java .util .*;
6
+ import java .util .concurrent .*;
7
+ import java .util .regex .*;
8
+
9
+ public class Solution {
10
+
11
+ // Complete the jumpingOnClouds function below.
12
+ static int jumpingOnClouds (int [] c ) {
13
+ int count = 0 ;
14
+ int pos = 0 ;
15
+ for (int p : c ) {
16
+ if (pos + 2 < c .length && c [pos + 2 ] != 1 ) {
17
+ pos = pos + 2 ;
18
+ count ++;
19
+ } else if (pos + 1 < c .length && c [pos + 1 ] != 1 ) {
20
+ pos = pos + 1 ;
21
+ count ++;
22
+ }
23
+ }
24
+ return count ;
25
+
26
+ }
27
+
28
+ private static final Scanner scanner = new Scanner (System .in );
29
+
30
+ public static void main (String [] args ) throws IOException {
31
+ BufferedWriter bufferedWriter = new BufferedWriter (new FileWriter (System .getenv ("OUTPUT_PATH" )));
32
+
33
+ int n = scanner .nextInt ();
34
+ scanner .skip ("(\r \n |[\n \r \u2028 \u2029 \u0085 ])?" );
35
+
36
+ int [] c = new int [n ];
37
+
38
+ String [] cItems = scanner .nextLine ().split (" " );
39
+ scanner .skip ("(\r \n |[\n \r \u2028 \u2029 \u0085 ])?" );
40
+
41
+ for (int i = 0 ; i < n ; i ++) {
42
+ int cItem = Integer .parseInt (cItems [i ]);
43
+ c [i ] = cItem ;
44
+ }
45
+
46
+ int result = jumpingOnClouds (c );
47
+
48
+ bufferedWriter .write (String .valueOf (result ));
49
+ bufferedWriter .newLine ();
50
+
51
+ bufferedWriter .close ();
52
+
53
+ scanner .close ();
54
+ }
55
+ }
You can’t perform that action at this time.
0 commit comments