Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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)

AltStyle によって変換されたページ (->オリジナル) /