- #美国面经
- #码农类general
- #面试经验
Twitter OA

19816
刚做的OA:
1) rational sum: 就是分式求和,主要是用了 Euclid’s algorithm 来求 gcd.
2) give string S,T : 1)如果T 是 S的 substring., 将T从S中删除。2)看T是不是剩下的S的substring. 如果是,继续删
求一共可以删几次
example: S,T='aabb', 'ab'. result = 2
S,T = 'aabdbc','abd'. result =1
本帖隐藏的内容需要积分高于 188 才可浏览,点击前往一亩三分地论坛阅读。
rn a*b//gcd(a,b)
def add(a,b):
de = lcm(a[1],b[1])
nu = a[0]*de//a[1] + b[0]*de//b[1]
return(nu,de)
#test
A=[(2,4),(3,5),(1,3)]
print(rationalSum(A))
B=[(4,2),(2,4),(2,4),(2,3)]
print(rationalSum(B))
1) rational sum: 就是分式求和,主要是用了 Euclid’s algorithm 来求 gcd.
2) give string S,T : 1)如果T 是 S的 substring., 将T从S中删除。2)看T是不是剩下的S的substring. 如果是,继续删
求一共可以删几次
example: S,T='aabb', 'ab'. result = 2
S,T = 'aabdbc','abd'. result =1
本帖隐藏的内容需要积分高于 188 才可浏览,点击前往一亩三分地论坛阅读。
rn a*b//gcd(a,b)
def add(a,b):
de = lcm(a[1],b[1])
nu = a[0]*de//a[1] + b[0]*de//b[1]
return(nu,de)
#test
A=[(2,4),(3,5),(1,3)]
print(rationalSum(A))
B=[(4,2),(2,4),(2,4),(2,3)]
print(rationalSum(B))
6条回复
热度排序