蚂蚁金服开发笔试
1.小红的字符生成(AC)
from math import log n = int(input()) if n == 1: print('a') else: res = '' while n: k = int(log(n, 2)) temp = chr(ord('a')+k) res += temp n -= 2**k print(res)
2.树上节点(妈的,这题不会做,有做过的带老可以教教我)
3.好串数量。(超时了30%)
from collections import Counter, defaultdict strs = input() size = len(strs) res = 0 for i in range(size): for j in range(i, size): acc = Counter(strs[i:j+1]) n1, n2 = 0, 0 for k, v in acc.items(): if v % 2 == 0: n2 += 1 else: n1 += 1 if n1 == 1 and n2>=0: res += 1 print(res)