Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- #Function to count the number of possible triangles.
- def findNumberOfTriangles(self, arr, n):
- arr.sort()
- ans=0
- for i in range(n-1,1,-1):
- l,r=0,i-1
- while l<r:
- if arr[l]+arr[r]>arr[i]:
- ans=ans+(r-l)
- r=r-1
- else:
- l=l+1
- return ans
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement