هک‌ها و تشعشعات وجدان آزاد

نوشته‌های سیدمحمدمسعود صدرنژاد

ابزار کاربر

ابزار سایت


courseware:python_programming:resources:answer:13

پاسخ پرسش اولین زمان رسیدن قورباغه به سمت دیگر رودخانه

def solution(x, a):
    covered_time = [-1] * x  # Record the time, each position is covered
    uncovered = x  # Record the number of uncovered position
 
    for index in range(0, len(a)):
        if covered_time[a[index] - 1] != -1:
            # This position is already covered
            continue
        else:
            # This position is to be covered
            covered_time[a[index] - 1] = index
            uncovered -= 1
            if uncovered == 0:
                # All positions are covered
                return index
 
    # Finally, some positions are not covered
    return -1
courseware/python_programming/resources/answer/13.txt · آخرین ویرایش: 2020/09/15 15:46 (ویرایش خارجی)