<jupyter_start><jupyter_text>说明：    给定字母数字字符串s。 （字母数字字符串是由小写英文字母和数字组成的字符串）。    您必须找到字符串的排列，其中没有字母后跟另一个字母，没有数字后跟另一个数字。    即，没有两个相邻的字符具有相同的类型。    如果无法重新格式化字符串，则返回重新格式化的字符串或返回空字符串。Example 1:    Input: s = "a0b1c2"    Output: "0a1b2c"    Explanation: No two adjacent characters have the same type in "0a1b2c". "a0b1c2", "0a1b2c", "0c2a1b" are also valid permutations.Example 2:    Input: s = "leetcode"    Output: ""    Explanation: "leetcode" has only characters so we cannot separate them by digits.Example 3:    Input: s = "1229857369"    Output: ""    Explanation: "1229857369" has only digits so we cannot separate them by characters.Example 4:    Input: s = "covid2019"    Output: "c2o0v1i9d"Example 5:    Input: s = "ab123"    Output: "1a2b3" Constraints:1、1 <= s.length <= 5002、s consists of only lowercase English letters and/or digits.<jupyter_code>class Solution:
    def reformat(self, s: str) -> str:
        a_idx, n_idx = [], []
        for a in s:
            if a.isdigit():
                a_idx.append(a)
            else:
                n_idx.append(a)
        if abs(len(a_idx) - len(n_idx)) > 1:
            return False
        
        if len(a_idx) < len(n_idx):
            a_idx, n_idx = n_idx, a_idx
        res = ''
        idx = 0
        while idx < min(len(a_idx), len(n_idx)):
            res += a_idx[idx] + n_idx[idx]
            idx += 1
        if idx == len(a_idx):
            return res
        return res + a_idx[-1]
solution = Solution()
solution.reformat("covid2019")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11515940143135979, 'fraction_numerical': 0.04619388418998048, 'mean_word_length': 2.551963048498845, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '94785', 'license': 'Apache-2.0', 'n_tokens_mistral': 665, 'n_tokens_neox': 654, 'n_words': 142, 'path': 'String/1011/1417. Reformat The String.ipynb', 'repo_name': 'YuHe0108/Leetcode', 'size': '1537'}