网易互娱笔试0ac代码

# 插入子串成为回文串 91.3%
class Solution:
    def canBePalindromicString(self, str1):
        n = len(str1)
        left = 0
        right = n - 1
        while left < right:
            if str1[left] == str1[right]:
                n -= 2
            left += 1
            right -= 1
        if n <= 5:
            return 1
        else:
            return 0


# 最长连续1的长度 90%
C, K = map(int, input().split())
c = str(C)
n = len(c)
ANS = []
for i in range(K, n):
    K1 = K
    ans = 0
    for j in range(i, -1, -1):
        if c[j] == '1':
            ans += 1
        else:
            K1 -= 1
            if K1 >= 0:
                ans += 1
            if K1 < 0:
                break
    ANS.append(ans)
print(max(ANS))


# 航班选座系统 10%
N, C = map(int, input().split())
zuowei = []
for i in range(N):
    zuowei.append(list(map(str, input().split())))
mat = [[0]*7 for _ in range(N)]
ans = 0
# for i in range(N):
#     for j in range(9):
#         if zuowei[i][0][j] == '.' and j < 3:
#             mat[i][j] = 1
#             ans += 1
#         if zuowei[i][0][j] == '.' and j > 5:
#             mat[i][j-2] = 1
#             ans += 1
# if ans > C:
#     print('SUCCESS')
# for i in range(N):
#     for j in range(9):
#         if zuowei[i][0][j] == '.' and j == 0:
#             print(str(j+1)+'A')
#             C -= 1
#         if zuowei[i][0][j] == '.' and j == 1:
#             print(str(j+1)+'B')
#             C -= 1
#         if zuowei[i][0][j] == '.' and j == 2:
#             print(str(j+1)+'C')
#             C -= 1
#         if zuowei[i][0][j] == '.' and j == 6:
#             print(str(j-2)+'D')
#             C -= 1
#         if zuowei[i][0][j] == '.' and j == 7:
#             print(str(j-2)+'E')
#             C -= 1
#         if zuowei[i][0][j] == '.' and j == 8:
#             print(str(j-2)+'F')
#             C -= 1
#         if C == 0:
#             break
#     if C == 0:
#         break
# else:
print('FAILED')


# 升序数组第k小 66.67%
class Solution:
    def find_kth(self, arr1, arr2, k):
        arr = arr1 + arr2
        arr.sort()
        return arr[k-1]

#网易互娱##笔经#
全部评论
我过了三题,航班也是只有10%好像是没有标准答案。数组排序会让时间复杂度到达nlog(n)不符合规定,连续1我用回溯法暴力解了,不过leetcode的话应该过不了。 python可以这么简洁的吗,🤔我用C++写了几百行,难受
点赞 回复
分享
发布于 2021-09-10 22:59
什么时候考的?话说我也是0ac啊哈哈哈(虽然第一道过了10%,不过和0也差不多了
点赞 回复
分享
发布于 2021-09-11 18:23
联易融
校招火热招聘中
官网直投
可以用python的吗..看见笔试邀请里说只有cpp和java有点慌..
点赞 回复
分享
发布于 2021-09-16 10:35

相关推荐

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