codility CountTriangles

Question:codility Lesson15 CountTriangles

My Answer:

def solution(A):
    A.sort()

    lenA = len(A)
    res = 0

    for i in range(lenA - 2):
        k = i + 2
        for j in range(i + 1,lenA - 1):
            while k  lenA and A[i] + A[j]  A[k]:
                k += 1
            res += k - j - 1
    return res
最新回复(0)
/jishuQf61Cvrp3qRgXKCuYLULxugB_2FBTpeiOgzmDKsA_3D_3D4795021
8 简首页