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.
Jumping on the Clouds
Jumping on the Clouds
+ 49 comments My python solution
def jumpingOnClouds(c): if len(c) == 1 : return 0 if len(c) == 2: return 0 if c[1]==1 else 1 if c[2]==1: return 1 + jumpingOnClouds(c[1:]) if c[2]==0: return 1 + jumpingOnClouds(c[2:])
+ 80 comments My Java solution:
import java.util.*; 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 i=0; i < n; i++){ c[i] = in.nextInt(); } int count = -1; for (int i = 0; i < n; i++, count++) { if (i<n-2 && c[i+2]==0) i++; } System.out.println(count); } }
+ 40 comments java solution
int count = 0; for (int i = 0; i < n - 1; i++) { if (c[i] == 0) i++; count++; } System.out.println(count);
+ 6 comments C#
var jumps = 0; for(int i=0; i<n-1; i++, jumps++) if (i+2 < n && c[i+2] == 0) i++; Console.WriteLine(jumps);
+ 13 comments two line code
for(i=0;i<(n-1);) arr[i+2]?(res++,i++):(res++,i+=2); cout<<res;
Load more conversations
Sort 2900 Discussions, By:
Please Login in order to post a comment