# # # 时间复杂度较高 O(N^2) # def numJewelsInStones(J, S): # # count = 0 # # for i in S: # # if i in J: # # count+=1 # # print(count) # return sum([i in J for i in S]) # # # print(numJewelsInStones("aA", "aAAbbbb")) # 预期输出 3 # # # # # # o(n)的版本 # def numJewelsInStones(J, S): # stores = {} # for c in S: # if c in stores: # stores[c] = stores[c] + 1 # else: # stores[c] = 1 # # count = 0 # for c in J: # if c in stores: # count += stores[c] # print(count) # # # J = "aA" # S = "aAAbbbb" # numJewelsInStones(J, S) # J = "z" # S = "ZZ" # numJewelsInStones(J, S) # 山峰数组 # def peakIndexInMountainArray(A): # """ # :type A: List[int] # :rtype: int # """ # return A.index(max(A)) # peakIndexInMountainArray([0,1,0]) # 预期输出 1 # 宝石与石头 # def numJewelsInStones(J, S): # """ # :type J: str # :type S: str # :rtype: int # """ # return sum([s in J for s in S]) # numJewelsInStones("aA","aAAbbbb") # 预期输出 3 import re s ='1324.231.432.1234,192.168.1.6,10.25.11.8这些信息中,哪些是ip呢?' ret = re.findall('((?:(?:25[0-5]|2[0-4]\d|[01]?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d?\d))', s) print(ret)