47日目-Count IP Addresss
8087 ワード
--------------------------------------------🤞 My Solution -----------------------------------------
def ips_between(start, end):
start = start.split('.')
start.reverse()
start = list(map(int, start))
end = end.split('.')
end.reverse()
end = list(map(int, end))
arr = []
start_num = 0
end_num = 0
for i in range(0, start.__len__()):
if i == 0:
start_num += start[0]
end_num += end[0]
if i == 1:
if start[i] != 0:
start_num += 256 * start[i]
if end[i] != 0:
end_num += 256 * end[i]
if i == 2:
if start[i] != 0:
start_num += 256 * 256 * start[i]
if end[i] != 0:
end_num += 256 * 256 * end[i]
if i == 3:
if start[i] != end[i]:
if start[i] != 0:
start_num += 256 * 256 * 256 * start[i]
if end[i] != 0:
end_num += 256 * 256 * 256 * end[i]
arr.append(start_num)
arr.append(end_num)
result = arr[1] - arr[0]
return result
5 kyuにアップグレードし、、、Reference
この問題について(47日目-Count IP Addresss), 我々は、より多くの情報をここで見つけました https://velog.io/@vivala0519/47일차-Count-IP-Addressesテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol