diff --git "a/008\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260.py" "b/008\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260.py" new file mode 100644 index 0000000..afebf6d --- /dev/null +++ "b/008\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260.py" @@ -0,0 +1,30 @@ +import re +class Solution: + def myAtoi(self, s: str) -> int: + ''' + #re简洁方法 + return max(min(int(*re.findall('^[\+\-]?\d+', s.lstrip())), 2**31 - 1), -2**31) + '''#本人方法 + s=s.strip() + flag=True + if len(s)==0: + return 0 + if s[0]=='-' or s[0]=='+': + if s[0]=='-': + flag=False + s=s[1:] + n=0 + for i in s: + if i<='9' and i>='0': + n+=1 + else: + break + num=0 if n==0 else int(s[0:n]) + if flag==True: + return min(2**31-1,num) + return max(-2**31,-num) + +p1=Solution() +print(p1.myAtoi("+-+21k")) + + diff --git "a/009\345\233\236\346\226\207\346\225\260.py" "b/009\345\233\236\346\226\207\346\225\260.py" new file mode 100644 index 0000000..cfade61 --- /dev/null +++ "b/009\345\233\236\346\226\207\346\225\260.py" @@ -0,0 +1,9 @@ +class Solution: + def isPalindrome(self, x: int) -> bool: + s=str(x) + for i in range(int(len(s)/2)): + if s[i]!=s[len(s)-i-1]: + return False + return True +p1=Solution() +print(p1.isPalindrome(121)) diff --git "a/011\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250.py" "b/011\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250.py" new file mode 100644 index 0000000..53e7ce3 --- /dev/null +++ "b/011\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250.py" @@ -0,0 +1,27 @@ +class Solution: + def maxArea(self, height) -> int: + '''#本人超时代码 + num=0 + h=0 + for i in range(len(height)): + for j in range(len(height)-1,i-1,-1): + th=min(height[i],height[j]) + if th>h: + tnum=(j-i)*th + if tnum>num: + num=tnum + h=th + return num + ''' + #双指针法 + i, j, res = 0, len(height) - 1, 0 + while i < j: + if height[i] < height[j]: + res = max(res, height[i] * (j - i)) + i += 1 + else: + res = max(res, height[j] * (j - i)) + j -= 1 + return res +p1=Solution() +print(p1.maxArea([1,8,6,2,5,4,8,3,7]))