30.283. Move Zeroes
class Solution:
def moveZeroes(self, nums: List[int]) -> None:
"""
Do not return anything, modify nums in-place instead.
"""
zero_idx = 0
for i in range(len(nums)):
if nums[i]!=0:
nums[i],nums[zero_idx] = nums[zero_idx],nums[i]
zero_idx +=1
31.414. Third Maximum Number
class Solution:
def thirdMax(self, nums: List[int]) -> int:
res = [float('-inf'),float('-inf'),float('-inf')]
for n in nums:
if n not in res:
if n>res[0]:
res = [n, res[0],res[1]]
elif n>res[1]:
res = [res[0],n,res[1]]
elif n>res[2]:
res = [res[0],res[1],n]
return res[2] if res[2]!=float('-inf') else res[0]