由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - Compare Version Numbers
相关主题
问一个问题(4)请问一个题目
A家白板interview失败Fitbit 面经
请教一个查找算法问题Google Phone Interview
construct bst from post and inorder 总是Memory Limit Exceeded贴一道老算法题
lintcode 上的 Count of Smaller Number before itselfC++ Q69: #if (skillport)
Find top K most frequent numbers?问一个算法题
leetcode的2sumfind subset that sum up to given number
下周要去onsite了,求bless 顺便发些最近FLGAM的面经C++ Q 99-102
相关话题的讨论汇总
话题: res1话题: return话题: res2话题: v2话题: v1
进入JobHunting版参与讨论
1 (共1页)
w********n
发帖数: 4752
1
It's my codes below. Any other better solutions?
class Solution:
# @param version1, a string
# @param version2, a string
# @return an integer
def compareVersion(self, version1, version2):
v1=version1.split('.')
v2=version2.split('.')
size1=len(v1)
size2=len(v2)
size=max(size1,size2)
res1=0
for i in range(size1):
res1 += 10**(size-i)*int(v1[i])
res2=0
for i in range(size2):
res2 += 10**(size-i)*int(v2[i])
if res1>res2:
return 1
elif res1 return -1
else:
return 0
t********5
发帖数: 522
2
class Solution:
# @param version1, a string
# @param version2, a string
# @return an integer
def compareVersion(self, version1, version2):
v1 = version1.split('.')
v2 = version2.split('.')

while v1 and v2:
sectionV1 = int(v1.pop(0))
sectionV2 = int(v2.pop(0))
if sectionV1 > sectionV2:
return 1
elif sectionV1 < sectionV2:
return -1
if v1 and int(''.join(v1)):
return 1
elif v2 and int(''.join(v2)):
return -1
return 0
w********n
发帖数: 4752
3
thanks!!

【在 t********5 的大作中提到】
: class Solution:
: # @param version1, a string
: # @param version2, a string
: # @return an integer
: def compareVersion(self, version1, version2):
: v1 = version1.split('.')
: v2 = version2.split('.')
:
: while v1 and v2:
: sectionV1 = int(v1.pop(0))

1 (共1页)
进入JobHunting版参与讨论
相关主题
C++ Q 99-102lintcode 上的 Count of Smaller Number before itself
攒人品:google电面面经Find top K most frequent numbers?
现在怎么都是讨论offer的,没有做题的了?leetcode的2sum
One interview question (A)下周要去onsite了,求bless 顺便发些最近FLGAM的面经
问一个问题(4)请问一个题目
A家白板interview失败Fitbit 面经
请教一个查找算法问题Google Phone Interview
construct bst from post and inorder 总是Memory Limit Exceeded贴一道老算法题
相关话题的讨论汇总
话题: res1话题: return话题: res2话题: v2话题: v1