好未来笔试
太菜了,一题都没有a出来,都想转行了
1.最长重复子串 40%
class Solution: def Solve(self , s ): # write code here n = len(s) test = [] mt = [] for i in range(n): for j in range(i+1,n): step = 1 while(s[i:i+step] == s[j:j+step] and j+step <= n): if i not in test: test.append(i) step += 1 if step > 1: mt.append(step-1) if len(mt)==0: return '' else: x = max(mt) for k in range(len(mt)): if mt[k] == x: return s[k:k+x]
2.排序后最大整数 不会 40%
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # @param nums int整型一维数组 # @return string字符串 class Solution: def largestNumber(self , nums ): # write code here ans = '' for i in nums: i = str(i) ans = ans + ''.join(i) return ans
3.数组的交集 60%
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # @param nums1 int整型一维数组 # @param nums2 int整型一维数组 # @return int整型一维数组 class Solution: def intersection(self , nums1 , nums2 ): # write code here jiao = [] for i in nums1: if i in nums2 and i not in jiao: jiao.append(i) return jiao