一面
八股:
解决过拟合的方法
为什么改LN为mean square root norm?
项目:
为什么不训练一个reward model
评测和数据筛选方法
上线效率,上线后使用情况
手撕:1
# 求最长回文子串。比如 "55787" 返回 "787"
s = "557887"
n = len(s)
dp = [[0]*n for _ in range(n)]
for i in range(n):
dp[i][i]=1
res = s[0]
res_len = 1
for t in range(1,n):
for i in range(n-1,-1,-1):
if i-t<0:
break
if s[i]==s[i-t]:
if t==1:
dp[i-t][i]=2
else:
dp[i-t][i]=dp[i-t+1][i-1]+2 if dp[i-t+1][i-1]>0 else 0 #这里
if dp[i-t][i]>res_len:
res_len = dp[i-t][i]
res = s[i-t:i+1] #这里数据越界了。
print(res)
################## leetcode 5
n = len(s)
if n<2:
return s
begin = 0
maxlen = 1
dp = [[False]*n for _ in range(n)]
for i in range(n):
dp[i][i] = True
for l in range(2,n+1):
for i in range(n):
j = i+l-1
if j>=n: break
if s[i]!=s[j]:
dp[i][j]=False
elif j-i<2:
dp[i][j]=True
else:
dp[i][j]=dp[i+1][j-1]
Reference
-
https://leetcode.cn/problems/longest-palindromic-substring/ ↩