two pointer method, timed out at 41/48 test cases
This commit is contained in:
parent
9f70612630
commit
4d8fd333e4
@ -22,13 +22,15 @@ class Solution(object):
|
||||
# return int(stack[-1])
|
||||
|
||||
# Recursion Solution
|
||||
print(tokens)
|
||||
s = tokens[len(tokens) - 1]
|
||||
tokens.pop()
|
||||
print(tokens)
|
||||
if(s not in '+-/*'): return int(s)
|
||||
else:
|
||||
a = self.evalRPN(tokens)
|
||||
b = self.evalRPN(tokens)
|
||||
# print(a)
|
||||
# print(b)
|
||||
if(s == "+"): return a + b
|
||||
elif(s == "*"): return a * b
|
||||
elif(s == "-"): return b - a
|
||||
@ -37,8 +39,8 @@ class Solution(object):
|
||||
obj = Solution()
|
||||
print(obj.evalRPN(["2","1","+","3","*"])) # 9
|
||||
print(obj.evalRPN(["4","13","5","/","+"])) # 6
|
||||
print(obj.evalRPN(["10","6","9","3","+","-11","*","/","*","17","+","5","+"])) # 22
|
||||
print(obj.evalRPN(["0","3","/"])) # 0
|
||||
print(obj.evalRPN(["3","11","+","5","-"])) # 9
|
||||
print(obj.evalRPN(["3","-4","+"])) # -1
|
||||
print(obj.evalRPN(["3","11","5","+","-"])) # -13
|
||||
# print(obj.evalRPN(["10","6","9","3","+","-11","*","/","*","17","+","5","+"])) # 22
|
||||
# print(obj.evalRPN(["0","3","/"])) # 0
|
||||
# print(obj.evalRPN(["3","11","+","5","-"])) # 9
|
||||
# print(obj.evalRPN(["3","-4","+"])) # -1
|
||||
# print(obj.evalRPN(["3","11","5","+","-"])) # -13
|
||||
46
NeetCodeRoadmap/Stack/739_Daily_Temperatures.py
Normal file
46
NeetCodeRoadmap/Stack/739_Daily_Temperatures.py
Normal file
@ -0,0 +1,46 @@
|
||||
class Solution(object):
|
||||
def dailyTemperatures(self, temperatures):
|
||||
"""
|
||||
:type temperatures: List[int]
|
||||
:rtype: List[int]
|
||||
"""
|
||||
count = 0
|
||||
warmer_days = []
|
||||
l = 0
|
||||
r = 1
|
||||
while l < r:
|
||||
# print(r)
|
||||
if r == len(temperatures)-1:
|
||||
if l != len(temperatures)-2:
|
||||
if temperatures[r] > temperatures[l]:
|
||||
count += 1
|
||||
warmer_days.append(count)
|
||||
else:
|
||||
warmer_days.append(0)
|
||||
l += 1
|
||||
r = l + 1
|
||||
count = 0
|
||||
else:
|
||||
if temperatures[r] > temperatures[l]:
|
||||
count += 1
|
||||
warmer_days.append(count)
|
||||
else:
|
||||
warmer_days.append(0)
|
||||
break
|
||||
elif temperatures[r] > temperatures[l]:
|
||||
count += 1
|
||||
warmer_days.append(count)
|
||||
count = 0
|
||||
l += 1
|
||||
r = l + 1
|
||||
else:
|
||||
r += 1
|
||||
count += 1
|
||||
warmer_days.append(0)
|
||||
return warmer_days
|
||||
|
||||
obj = Solution()
|
||||
# print(obj.dailyTemperatures([73,74,75,71,69,72,76,73])) # [1,1,4,2,1,1,0,0]
|
||||
# print(obj.dailyTemperatures([30,40,50,60])) # [1,1,1,0]
|
||||
# print(obj.dailyTemperatures([55,38,53,81,61,93,97,32,43,78])) # [3,1,1,2,1,1,0,1,1,0]
|
||||
print(obj.dailyTemperatures([77,77,77,77,77,41,77,41,41,77])) # [0,0,0,0,0,1,0,2,1,0]
|
||||
7
NeetCodeRoadmap/Stack/tempCodeRunnerFile.py
Normal file
7
NeetCodeRoadmap/Stack/tempCodeRunnerFile.py
Normal file
@ -0,0 +1,7 @@
|
||||
elif r == len(temperatures)-1:
|
||||
if l != len(temperatures)-2:
|
||||
l += 1
|
||||
r = l + 1
|
||||
else:
|
||||
warmer_days.append(0)
|
||||
break
|
||||
Loading…
Reference in New Issue
Block a user