Check out Codility training tasks
Tasks Details
easy
Determine whether a triangle can be built from a given set of edges.
Task Score
100%
Correctness
100%
Performance
100%

对于一个长度为 N 的整型数组, 如果存在三个元素 i,j,k i ≠ j ≠ k, 0 ≤ i,j,k < N) 满足如下条件:

  • A[i] + A[j] > A[k],
  • A[j] + A[k] > A[i],
  • A[k] + A[i] > A[j].

实现如下一个函数:

def solution(A)

则返回1, 否则返回0.

对于数组:

A[0] = 10 A[1] = 2 A[2] = 5 A[3] = 1 A[4] = 8 A[5] = 20

函数应该返回 1, 因为坐标为i=0, j=2, k=4的元素满足所有的判定条件(例如: A[2] + A[4] > A[0]). 对于数组:

A[0] = 10 A[1] = 50 A[2] = 5 A[3] = 1

函数应该返回 0.

假定:

  • N 是 [0..100,000] 内的 整数;
  • 数组 A 每个元素是取值范围 [−2,147,483,648..2,147,483,647] 内的 整数 .
Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
Solution
Programming language used Python
Time spent on task 3 minutes
Notes
not defined yet
Task timeline