zoukankan      html  css  js  c++  java
  • 替换字符串中的字符为“(” 或“)”

    题目描述:
    # The goal of this exercise is to convert a string to a new string where each character
    # in the new string is "(" if that character appears only once in the original string,
    # or ")" if that character appears more than once in the original string.
    # Ignore capitalization when determining if a character is a duplicate

    我的解答:
    def duplicate_letter(b):
    c = {}
    for i in b:
    if i not in c.keys():
    c[i] = 1
    elif i in c.keys():
    c[i] = c[i] + 1
    new_word = b.lower()
    for j in new_word:
    if c[j] > 1:
    new_word = new_word.replace(j, ")")
    elif c[j] == 1:
    new_word = new_word.replace(j, "(")
    return new_word
  • 相关阅读:
    开发细节
    html
    java学习
    Promise对象
    强制转换和隐式转换
    借助防抖解决输入框的非空校验
    setTimeout
    Symbol类型
    js API
    vue 使用mixin
  • 原文地址:https://www.cnblogs.com/wlj-axia/p/12637780.html
Copyright © 2011-2022 走看看