From de40df7970af15a8cd621703f430a04f038c1c7b Mon Sep 17 00:00:00 2001 From: Gilbert De Leon Date: Sun, 9 Jul 2023 03:10:58 -0700 Subject: [PATCH] Create 0334-increasing-triplet-subsequence.py --- python/0334-increasing-triplet-subsequence.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 python/0334-increasing-triplet-subsequence.py diff --git a/python/0334-increasing-triplet-subsequence.py b/python/0334-increasing-triplet-subsequence.py new file mode 100644 index 000000000..e193f0fd1 --- /dev/null +++ b/python/0334-increasing-triplet-subsequence.py @@ -0,0 +1,14 @@ +class Solution: + def increasingTriplet(self, nums: List[int]) -> bool: + first = float('inf') # Initialize first to positive infinity + second = float('inf') # Initialize second to positive infinity + + for num in nums: + if num <= first: + first = num # Update first if num is smaller or equal + elif num <= second: + second = num # Update second if num is smaller or equal + else: + return True # We found a triplet: first < second < num + + return False # No triplet exists 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