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
Lines changed: 14 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy