We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 052d492 + de40df7 commit aea3459Copy full SHA for aea3459
python/0334-increasing-triplet-subsequence.py
@@ -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