美团笔试第一题

下午美团笔试算法岗,第一问是一个简单字符串排序问题,为啥我老是0,然后用第二题的代码作为第一题的代码,竟然还能过16%,大家有遇到这个问题吗?#笔试题目##美团#
全部评论
#python AC str1 = input().split(',') for i in range(len(str1)):     for j in range(len(str1)-2,-1,-1):         if str1[j+1]=='':             tem = str1[j]             str1[j] = str1[j+1]             str1[j+1]=tem         elif str1[j]=='':             continue         else:             if str1[j+1][0]>str1[j][0]:                 tem = str1[j]                 str1[j] = str1[j+1]                 str1[j+1]=tem             elif  str1[j+1][0]<str1[j][0]:                 continue             else:                 if  str1[j+1] in str1[j]:                     tem = str1[j]                     str1[j] = str1[j+1]                     str1[j+1]=tem                 else:                     k = 0                     while  k<min(len(str1[j]),len(str1[j+1]))-1:                         if str1[j+1][k]==str1[j][k]:                              k +=1                         else:                             break                     if k<min(len(str1[j]),len(str1[j+1]))-1 and str1[j+1][k]>str1[j][k]:                         tem = str1[j]                         str1[j] = str1[j+1]                         str1[j+1]=tem                          print(','.join(str1))             
点赞 回复
分享
发布于 2019-08-22 17:27
算法67,0,第一题调了好久
点赞 回复
分享
发布于 2019-08-22 17:16
阅文集团
校招火热招聘中
官网直投
逆字典序排多个字符串,这个题有人a吗?求分享下思路或代码。
点赞 回复
分享
发布于 2019-08-22 17:19
我第一题也一直是0,第二题50
点赞 回复
分享
发布于 2019-08-22 17:21
第一题没搞明白空字符串排前面是啥意思,比如输入“a,空格,b ”,输出"空格,b,a”么 调试不出来不知道是不是空格没处理好QAQ
点赞 回复
分享
发布于 2019-08-22 17:22
def longestCommonPrefix(strs): """ :param strs:list() :return: len """ res = '' idx = 0 for i in zip(*strs): if idx == 0 and len(set(i)) != 1: return 0 # 如果第一个没一样,则return idx += 1 if len(set(i)) == 1: res += i[0] return len(res) n = int(input()) strs = [] nums = [] for i in range(n): strs.append(input()) lens = len(strs) while True: a,b = map(int,input().split()) #print(a,b) if 0<=a-1<lens and 0<=b-1<lens: print(longestCommonPrefix([strs[a-1],strs[b-1]])) 第二题ac代码,等第一题的ac出现
点赞 回复
分享
发布于 2019-08-22 17:23
mark一下,等大佬解答
点赞 回复
分享
发布于 2019-08-22 17:26
两道都ac了。代码写的没保存
点赞 回复
分享
发布于 2019-08-22 17:27
第一题归并调了好久,样例过了,最后没贴上去🤣🤣🤣 第二题不知道咋回事一直 .33,这下是凉透了
点赞 回复
分享
发布于 2019-08-22 21:23
点赞 回复
分享
发布于 2019-08-22 21:25

相关推荐

点赞 6 评论
分享
牛客网
牛客企业服务