MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / increasingTriplet

Method increasingTriplet

Array/IncreasingTripletSubsequence.py:60–86  ·  view source on GitHub ↗

:type nums: List[int] :rtype: bool

(self, nums)

Source from the content-addressed store, hash-verified

58"""
59class Solution(object):
60 def increasingTriplet(self, nums):
61 """
62 :type nums: List[int]
63 :rtype: bool
64 """
65
66 if len(nums) < 3:
67 return False
68
69 one = None
70 two = None
71 for i, d in enumerate(nums):
72 if one:
73 if d <= one[1]:
74 one = (i, d)
75 continue
76
77 if two:
78 if d <= two[1]:
79 two = (i, d)
80 else:
81 return True
82 else:
83 two = (i, d)
84 else:
85 one = (i, d)
86 return False
87
88
89

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected