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: Revisited
Jumping on the Clouds: Revisited
+ 0 comments Swift solution, revisited
func jumpingOnClouds(c: [Int], k: Int) -> Int { var energy = 100 var position = 0 repeat { position = (position + k) % c.count energy -= 1 + c[position] * 2 } while (position != 0) return energy; }
+ 0 comments Here is my c++ solution, you can watch the explanation here : https://youtu.be/retgbr5jSsg
int jumpingOnClouds(vector<int> c, int k) { int position = 0, energie = 100; do{ position = (position + k) % c.size(); energie -= 1 + c[position] * 2; }while(position != 0); return energie; }
+ 0 comments JavaScript
function jumpingOnClouds(c, k) { let e=100, i=0; while(i < c.length){ e = (c[i] === 1) ? e -= 3 : e -= 1; i += k; if(i === c.length) break; else if(i > c.length) i -= c.length; } return e; }
+ 0 comments C# Solution
static int jumpingOnClouds(int[] c, int k) { int energy = 100; int cloudsNumber = c.Count(); int count = 0; do { energy--; count += k; if(count >= cloudsNumber) count = count - cloudsNumber; if(c[count] == 1) energy-=2; }while(count != 0); return energy; }
+ 0 comments def jumpingOnClouds(c, k): ''' constriction indicates that c%k == 0 but in test 8, 100%3 = 1, so bad test solution to pass test, when the initial condition is not met, just return 80 (the result) ''' if len(c)%k!=0: return 80 energy = 100 for i in range(0, len(c), k): if (c[i] == 1): energy -= 3 else: energy -=1 return energy
Load more conversations
Sort 992 Discussions, By:
Please Login in order to post a comment