@sharingaccount I thought we cannot perform direct int operations
like return int(s1)*int(s2).However thanks for pointing out I have now edited my code.
If there are still any concerns feel free to point out
S
sankalp6
@sankalp6
1
Reputation
16
Posts
156
Profile views
0
Followers
3
Following
Posts made by sankalp6

RE: My Python Solution

Share my O(n) Time and O(1) space python solution With Comments
def maxProfit(self, prices): """ :type prices: List[int] :rtype: int """ prevmax=float('inf') prevmin=float('inf') maxprofit=0 for i in range(0,len(prices)): if prices[i]<prevmin:#if A[i] less than previously found minimum we will update both max and min tiil now to A[i] prevmin=prices[i] prevmax=prices[i] elif prevmax<prices[i]:# if A[i] is greater than prevmax we will update prevmax prevmax=prices[i] maxprofit=max(maxprofit,prevmaxprevmin) return maxprofit