Python学习——leetcode(Compare Version Numbers)

class Solution:
    # @param a, a string
    # @param b, a string
    # @return a boolean,这里有错误,其实是返回1,0,-1
    def compareVersion(self, version1, version2):
		v1=version1.split('.')
		v2=version2.split('.')
		i=0
		print 'length:',len(v1),len(v2)
		while i<len(v1) and i<len(v2):			
			if int(v1[i])>int(v2[i]):
				return 1
			elif int(v1[i])<int(v2[i]):
				return -1
			else:
				i+=1
		#pdb.set_trace()
		if i==len(v1) and i==len(v2):
			return 0
		elif i<len(v1):
			while i < len(v1):
				print 'i:',i
				print int(v1[i])>0
				if(int(v1[i]))>0:
					return 1
				else:
					return 0
		else:
			while i < len(v2):
			    if int(v2[i])>0:
			        return -1
			    else:
			        return 0

你可能感兴趣的:(LeetCode,python)