• 2.135-分发糖果


     1 def candy(ratings):
     2     result=[1 for i in range(len(ratings))]
     3     for i in range(len(ratings)-1):
     4         if ratings[i]>ratings[i+1] and result[i]<=result[i+1]:
     5             result[i]+=result[i+1]-result[i]+1
     6         if ratings[i]<ratings[i+1] and result[i]>=result[i+1]:
     7             result[i+1]+=result[i]-result[i+1]+1
     8     for j in range(len(ratings)-1,0,-1):
     9         if ratings[j]>ratings[j-1] and result[j]<=result[j-1]:
    10             result[j]+=result[j-1]-result[j]+1
    11         if ratings[j]<ratings[j-1] and result[j]>=result[j-1]:
    12             result[j-1] += result[j ] - result[j-1] + 1
    13     print(result)
    14     return sum(result)
    View Code
  • 相关阅读:
    JS 面向对象
    inline-block元素间隙处理
    MUI
    MUI
    chrome://inspect调试html页面空白,DOM无法加载的解决方案
    MUI
    MUI
    MUI
    MUI
    MUI
  • 原文地址:https://www.cnblogs.com/tangweijqxx/p/10688912.html
Copyright © 2020-2023  润新知