HR_Jumping on the Clouds

1.没有考虑i+2越界的问题

2.没有考虑结尾三个零导致 -5

3.没有考虑len(c)<2 导致 -5

 

#!/bin/python3

import math
import os
import random
import re
import sys

# Complete the jumpingOnClouds function below.
def jumpingOnClouds(c):

    count = 0
    i = 0
    while(i + 2 < len(c)):
        if c[i+2] == 0:
            count = count + 1
            i = i + 2
        else:
            count = count + 1
            i = i + 1
    if len(c)<=2:
        count = count + 1
    else:
        if c[-2] == 0 and c[-3] == 1:
            count = count + 1

    return count


if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    n = int(input())

    c = list(map(int, input().rstrip().split()))

    result = jumpingOnClouds(c)

    fptr.write(str(result) + '\n')

    fptr.close()

  

posted @ 2018-09-30 17:59  夜歌乘年少  阅读(348)  评论(0编辑  收藏  举报