Skip to content

Commit aea3459

Browse files
authored
Merge pull request #2687 from gil906/patch-2
Create 0334-increasing-triplet-subsequence.py
2 parents 052d492 + de40df7 commit aea3459

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def increasingTriplet(self, nums: List[int]) -> bool:
3+
first = float('inf') # Initialize first to positive infinity
4+
second = float('inf') # Initialize second to positive infinity
5+
6+
for num in nums:
7+
if num <= first:
8+
first = num # Update first if num is smaller or equal
9+
elif num <= second:
10+
second = num # Update second if num is smaller or equal
11+
else:
12+
return True # We found a triplet: first < second < num
13+
14+
return False # No triplet exists

0 commit comments

Comments
 (0)