Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Logic:
- IF we get a number less than or equal to i then update i.
- if element is greater than i but less than equal to j,then update j.
- and if less than j also then we have k also so return k.
- try to deny this algo:
- first we get 2 then 4 so i=2 and j=4
- then again we get 1 so i=1 and j=4 now we get 6 so now k=6 and
- we got the triplet. so it works in all case.
- ie. 2,4,1,6
- '''
- class Solution:
- def increasingTriplet(self, nums: list[int]) -> bool:
- a=math.inf
- b=math.inf
- for i in nums:
- if i<=a:
- a=i
- elif i<=b:
- b=i
- else:
- return True
- return False
Advertisement
Add Comment
Please, Sign In to add comment