Counting Valleys

def countingValleys(n, s): valleys = 0 hikes = 0 for i in s: if i==’D’: if hikes==0: valleys += 1 hikes -= 1 else: hikes += 1 return valleys Gary is an avid hiker. He tracks his hikes meticulously, paying close attention to small details like topography. During his last hike, he took exactly  steps. For […]

Atoi

class Solution: # @param A : string # @return an integer def atoi(self, A): mx = (2**31)-1 mn = -(2**31) s = ” for x in A: if x.isdigit() or (A.index(x)==0 and x in (‘-‘, ‘+’)): s += x else: break if (s and s[0].isdigit()) or (len(s)>1 and s[0] in (‘+’, ‘-‘)): if 0 <= […]