leetcode之ThirdmMaximumNumber的解法
class Solution(object):
def thirdMax(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
l=[-2147483649,-2147483649,-2147483649]
for n in nums:
if n==l[0] or n==l[1] or n==l[2]:
continue
if n>l[2]:
l[0]=l[1]
l[1]=l[2]
l[2]=n
elif n>l[1]:
l[0]=l[1]
l[1]=n
elif n>l[0]:
l[0]=n
if l[0]==l[1] or l[1]==l[2]:
return l[2]
elif l[0]==-2147483649:
return l[2]
else:
return l[0]
学习总结
1.python的语法与之前的语法之间差距是很大的,但是和matlab的代码是类似的
2.python的语法中冒号是经常忘记的,写代码的时候一定要注意
3.python整数理论上是无限大的,但是受限于机器的内存,这和之前学习的迭代器类似,可以无限迭代
更多leetcode解题源码,请查看我的github地址https://github.com/Jum1023/leetcode