Skip to content

Commit c4eef37

Browse files
authored
Create Increasing_Triplet_Subsequence.py
1 parent 6dbb29e commit c4eef37

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Solution - 1: Time: O(N)
2+
class Solution:
3+
def increasingTriplet(self, nums: List[int]) -> bool:
4+
# Set both the first and the second values as MAX value
5+
first = second = float('inf')
6+
7+
for i in nums:
8+
if i <= first: # This will ensure that we always store the minimum value in first
9+
first = i
10+
elif i <= second: # This will ensure that we always store a value greater than first
11+
second = i
12+
else: # If we have reached here, we have seen a value greater than first and second. So return True
13+
return True
14+
15+
return False

0 commit comments

Comments
 (0)