题解 | #比较版本号#
比较版本号
https://www.nowcoder.com/practice/2b317e02f14247a49ffdbdba315459e7
class Solution: def compare(self , version1: str, version2: str) -> int: # write code here f=lambda a:''.join([i.rjust(30,'0') for i in a.split('.')])+''.join(['0'*30]*(3-len(a.split('.')))) version1=f(version1) version2=f(version2) if version1>version2: return 1 elif version1<version2: return -1 else: return 0直接补齐了3个部分,然后字符串连接比大小