Sort by

recency

|

3241 Discussions

|

  • + 0 comments

    Here is my c++ solution, you can watch the explanation here : https://youtu.be/GNof9B-9CN0

    int jumpingOnClouds(vector<int> c) {
        int result = 0, index = 0;
        while(index < c.size() - 1){
            if(c[index + 2] == 1) index++;
            else index+=2;
            result++;
        }
        return result;
    }
    
  • + 0 comments
    func jumpingOnClouds(c: [Int]) -> Int {
        // Write your code here Swift
        var jump = 0
        var i = 0
       repeat{
            if i+2 < c.count && c[i+2] == 0{
                i += 2
            }else{
                i += 1
            }
            jump += 1
    				
            
        } while i < c.count - 1
        
        return jump
    }
    
  • + 0 comments

    JavaCode

    public static int jumpingOnClouds(List<Integer> c) {
        int jumps = 0;
        int index = 0;
        
        while (index < c.size() - 1) {
            if (index + 2 < c.size() && c.get(index + 2) == 0) {
                index += 2;
            } else {
                index += 1;
            }
            jumps++;
        }
        
        return jumps;
    }
    
  • + 0 comments

    def jumpingOnClouds(c): # Write your code here

        if len(c) == 1 : return 0
    
        elif len(c) ==2: return 0 if c[1] == 1 else 1
    
        elif c[2] == 1: return 1 + jumpingOnClouds(c[1:])
    
    elif c[2] == 0: return 1 + jumpingOnClouds(c[2:])
    
  • + 0 comments

    This is my code in C# 🙌

            int counterJumps = 0;
            int counterZero = 0;
    
            for (int i = 0; i < c.Count; i++)
            {
                if (c[i] == 1)
                {
                    counterJumps++;                    
                    counterZero = 0;
                    continue;
                }
                else
                {
                    counterZero++;
                }
    
                if (counterZero == 2)
                {
                    counterJumps++;
                    counterZero = 0;
                }
            }
            return counterJumps;