算法1000题Day3

'''Write a function that will return the count of distinct case-insensitive 
alphabetic characters and numeric digits that occur more than once in the input string. 
The input string can be assumed to contain only alphabets
 (both uppercase and lowercase) and numeric digits.

Example
"abcde" -> 0 # no characters repeats more than once
"aabbcde" -> 2 # 'a' and 'b'
"aabBcde" -> 2 # 'a' occurs twice and 'b' twice (`b` and `B`)
"indivisibility" -> 1 # 'i' occurs six times
"Indivisibilities" -> 2 # 'i' occurs seven times and 's' occurs twice
"aA11" -> 2 # 'a' and '1'
"ABBA" -> 2 # 'A' and 'B' each occur twice'''

#My Solution

def duplicate_count(text):
    # Your code goes here
    c = {}
    for i in set(text.lower()):
        c[i] = text.count(i) + text.count(i.swapcase())
    print(c)
    count = 0
    for i in c.keys():
        if c[i] > 1:
            count+=1
    return count

#the most clever solution

def def duplicate_count(s):
    return len(c for c in set(s) if s.lower().count(c) > 1)

#这道题我做的确实太丑了,但是核心思想是基本不变的,大小写转换/字符串计数是这道题的核心
#怎么说呢,思维还是要再活络一些。


'''Return the number (count) of vowels in the given string.

We will consider a, e, i, o, and u as vowels for this Kata.

The input string will only consist of lower case letters and/or spaces.'''

#my solution

def getCount(inputStr):
    # your code here
    return len([i for i in inputStr if i in ['a','e','i','o','u']])

#现学现卖...

 

你可能感兴趣的:(算法1000题Day3)