题解 | #杨辉三角的变形#

杨辉三角的变形

https://www.nowcoder.com/practice/8ef655edf42d4e08b44be4d777edbf43

尴尬我也超时了,然后看了答案

import sys

num = int(input())

# def get(lst,index):
#     try:
#         if index <0 or index >=len(lst):
#             return 0 

#         return lst[index]
#     except IndexError:
#         return 0

# r = -1

# lst = []
# for i in range(1,num+1):
#     if i==1:
#         lst = [1]
#         continue

#     _lst = []
#     for j in range(i*2-1):
#         res = get(lst,j-2)+get(lst,j-1)+get(lst,j)
#         if i==num and res>0 and res%2==0:
#             r=j+1
#             break
#         _lst.append(res)

#     lst = _lst
# print(r)

# -1 -1 2 3 2 4 2 3 2 4
lst = [2,4,2,3]

if num<3:
    print(-1)
else:
    print(lst[num%4-1])





全部评论

相关推荐

ohs的小木屋:比不少实习待遇高了
点赞 评论 收藏
分享
05-22 09:23
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务