LintCode: Judging Triangle

Judging Triangle



Similar Problems:


Description
Given an array arr, ask if you can find 3 elements from the array as the sides of the three sides, so that the three sides can form a triangle. If yes, return yes, if not, return no

  • 1 <= n<= 100000
  • 1 <= arr[i] <= 1000000000
  • The program will be run 500 times

Example

Give arr=[2,3,5,8], return no.

Explanation:
2, 3, 5 cannot form a triangle
2, 3, 8 cannot form a triangle
3, 5, 8 cannot form a triangle
So, return "no"

Give arr=[3,4,5,8] , return yes.

Explanation:
3, 4, 5 can form a triangle
So return "yes"

Github: code.dennyzhang.com

Credits To: lintcode.com

Leave me comments, if you have better ways to solve.


  • Solution:
// Blog link: https://code.dennyzhang.com/judging-triangle

linkedin
github
slack

Share It, If You Like It.

Leave a Reply

Your email address will not be published.