less than 1 minute read

Tags: ,

Jumping on the Clouds

連續第三天 真的有進步 哈哈 ,過去五個月玩AI 都直接剪貼東西XDD 真的沒好好動腦 XDDD

  • Imgur

  • Imgur

  • python

# Complete the jumpingOnClouds function below.
def jumpingOnClouds(c):
    clounds = len(c)
    step = 0
    i = 0

    while i < clounds-1:
        if i+2 == clounds or c[i+2] == 1 :
            i += 1
            step += 1
        else:
            i +=2
            step += 1

    return step
  • js
// Complete the jumpingOnClouds function below.
function jumpingOnClouds(c) {
    let steps = 0;
    let i = 0;
    while ( i < c.length -1) {
       if (i+2 == c.length || c[i+2] == 1) {
          steps ++;
          i ++; 
       } else {
          i += 2;
          steps ++;
       }
    }
    return steps
}