题解 | #数字颠倒#
数字颠倒
https://www.nowcoder.com/practice/ae809795fca34687a48b172186e3dafe
直接print(input()[::-1]) 考试加入循环支持多次输入和异常处理比较好
while True: try: # 输入一个整数 s1=input() # 直接将字符串逆序 s2=s1[::-1] # 输出 print(s2) except: break
数字颠倒
https://www.nowcoder.com/practice/ae809795fca34687a48b172186e3dafe
while True: try: # 输入一个整数 s1=input() # 直接将字符串逆序 s2=s1[::-1] # 输出 print(s2) except: break
相关推荐
球球与墩墩:这不是前端常考的对象扁平化吗,面试官像是前端出来的
const flattern = (obj) => {
const res = {};
const dfs = (curr, path) => {
if(typeof curr === 'object' && curr !== null) {
const isArray = Array.isArray(curr);
for(let key in curr) {
const newPath = path ? isArray ? `${path}[${key}]` : `${path}.${key}` : key;
dfs(curr[key], newPath);
}
} else {
res[path] = curr
}
}
dfs(obj);
return res;
}
查看3道真题和解析