Commit 35565e57 by “安晓东”

第四次作业

parent 9522dc17
# 时间复杂度较高 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)
#
# # 时间复杂度较高 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)
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)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment