Sum of positive

* *
链接 Sum of positive
难度 8kyu
状态
日期 2018-11-30

题意

题解1

def positive_sum(arr):
    # Your code here
    sum = 0
    len1 = len(arr)
    a = 0
    while a < len1:
        if arr[a] > 0:
            sum = sum + arr[a]
            a = a + 1
        else:
            a = a + 1
    return sum

题解2

def positive_sum(arr):
    # Your code here
    sum = 0
    length = len(arr)
    i = 0
    while i < length:
        if arr[i] > 0:
            sum += arr[i]
        i += 1
    return sum

题解3

def positive_sum(arr):
    # Your code here
    sum = 0
    length = len(arr)
    for i in range(0, length):
        if arr[i] > 0:
            sum += arr[i]
    return sum

题解4

def positive_sum(arr):
    # Your code here
    sum = 0
    for n in arr:
        if n > 0:
            sum += n
    return sum

题解5

def positive_sum(arr):
    # Your code here
    return sum([c for c in arr if c > 0])
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 不错的博客求next数组: 注意:求next数组得到的最长公共前缀后缀是可以重叠的:比如:ababa,next[5...
    Gitfan阅读 4,383评论 0 0
  • G - Cyclic Tour题意:图中有n个点和m条有向边现在要将该图分成若干环,每个环中至少有两个点。环与环不...
    Gitfan阅读 4,166评论 0 1
  • A - 数字三角形题解:假设getMax(i,j)表示点(i,j)到底部的最长路径,那么getMax(i,j)=m...
    Gitfan阅读 4,363评论 0 0
  • https://vjudge.net/problem/HDU-3980题意: 两个人在一个由 n 个玻璃珠组成的...
    Gitfan阅读 4,610评论 0 0
  • 棒棒方方阅读 1,020评论 0 1