<jupyter_start><jupyter_text>面经约瑟夫环<jupyter_code>def joshPh(n,m):
    if n == 1:
        return n 
    return (joshPh(n-1,m)+m-1)%n+1
joshPh(3,3)<jupyter_output><empty_output><jupyter_text>剑指 Offer 37. 序列化二叉树  LCP 07. 传递信息小朋友 A 在和 ta 的小伙伴们玩传信息游戏，游戏规则如下：有 n 名玩家，所有玩家编号分别为 0 ～ n-1，其中小朋友 A 的编号为 0每个玩家都有固定的若干个可传信息的其他玩家（也可能没有）。传信息的关系是单向的（比如 A 可以向 B 传信息，但 B 不能向 A 传信息）。每轮信息必须需要传递给另一个人，且信息可重复经过同一个人给定总玩家数 n，以及按 [玩家编号,对应可传递玩家编号] 关系组成的二维数组 relation。返回信息从小 A (编号 0 ) 经过 k 轮传递到编号为 n-1 的小伙伴处的方案数；若不能到达，返回 0。示例 1：`输入：n = 5, relation = [[0,2],[2,1],[3,4],[2,3],[1,4],[2,0],[0,4]], k = 3`输出：3解释：信息从小 A 编号 0 处开始，经 3 轮传递，到达编号 4。共有 3 种方案，分别是 0->2->0->4， 0->2->1->4， 0->2->3->4。示例 2：输入：n = 3, relation = [[0,2],[2,1]], k = 2输出：0解释：信息不能从小 A 处经过 2 轮传递到编号 2限制：2 <= n <= 101 <= k <= 51 <= relation.length <= 90, 且 relation[i].length == 20 <= relation[i][0],relation[i][1] < n 且 relation[i][0] != relation[i][1]<jupyter_code>from collections import defaultdict
def numWays(n,relation,k):
    if not relation:
        return 0 
    relations = defaultdict(list)
    for i,j in relation:
        relations[i].append(j)
    print(relations)
    ways = 0 
    def dfs(index,cost):
        nonlocal ways
        if cost == k:
            if index == n-1:
                ways += 1 
            return 
        for i in relations[index]:
            dfs(i,cost+1)
        return ways 
    dfs(0,0)
    return ways  
n = 5
relation = [[0,2],[2,1],[3,4],[2,3],[1,4],[2,0],[0,4]]
k = 3
numWays(n,relation,k)
def numWays2(n,relation,k):
    relations = defaultdict(list)
    for i,j in relation:
        relations[i].append(j)
    print(relations)
    queue = [0]
    cost = 0 

    while queue and cost < k:
        cost += 1 
        size = len(queue)
        for i in range(size):
            node = queue.pop(0)
            for nextnode in relations[node]:
                queue.append(nextnode)
    numways = 0 
    if cost == k:
        while queue:
            if queue.pop() == n-1:
                numways += 1 
    return numways 
                

    
numWays2(n,relation,k)
# [168] Excel表列名称
#
# https://leetcode-cn.com/problems/excel-sheet-column-title/description/
#
# algorithms
# Easy (40.78%)
# Likes:    409
# Dislikes: 0
# Total Accepted:    67.9K
# Total Submissions: 161.4K
# Testcase Example:  '1'
# 给你一个整数 columnNumber ，返回它在 Excel 表中相对应的列名称。
# 例如：
# A -> 1
# B -> 2
# C -> 3
# ...
# Z -> 26
# AA -> 27
# AB -> 28
# ...
# 示例 1：
# 输入：columnNumber = 1
# 输出："A"
# 示例 2：
# 输入：columnNumber = 28
# 输出："AB"
# 示例 3：
# 输入：columnNumber = 701
# 输出："ZY"
# 示例 4：
# 输入：columnNumber = 2147483647
# 输出："FXSHRXW"
def convertToTitle(columnNumber):
    ans = ''

    while columnNumber:
        columnNumber -= 1 
        ans += chr((columnNumber % 26 ) + ord('A'))
        columnNumber //= 26 
    return ans[::-1]
convertToTitle(2147483647)
from collections import Counter
s = "eert"
        
count = Counter(s) 

sorted(count.keys(),key=lambda x:-count[x])        

count 
ans
dic = {5:8}
nums = [1,2,2,4]

nums
nums.sort()
n = len(nums)


def findErrorNums(nums):
    
    nums.sort()
    n = len(nums)
    temp = [0] * n 
    for i in range(n):
        if temp[i] != nums[i]:
            temp[nums[i] - 1] = nums[i]
            continue
        repeate = temp[i]
        
    for i in range(len(temp)):
        if temp[i] == 0:
            miss = i + 1 
    return [repeate,miss]
                

findErrorNums([1,2,2,4])
help(isUpperCase())
s = {}
s[1] = 0
s<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1621933621933622, 'fraction_numerical': 0.05367965367965368, 'mean_word_length': 2.4384920634920637, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 24, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '52736', 'license': 'MIT', 'n_tokens_mistral': 1730, 'n_tokens_neox': 1685, 'n_words': 322, 'path': '每日刷题/2021/07/20210701.ipynb', 'repo_name': 'ZhengyangXu/Algorithm-Daily-Practice', 'size': '3465'}