Add new course

This commit is contained in:
AndrewTrieu
2023-01-08 18:43:01 +02:00
parent 75313f3f05
commit 6f5c7f67b4
49 changed files with 835669 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
def pairs(s):
result = 0
loc = [x for x in range(len(s)) if s[x] == "1"]
for i in range(len(loc)):
result += loc[i]*(i) - loc[i]*(len(loc)-i-1)
return result
if __name__ == "__main__":
print(pairs("100101")) # 10
print(pairs("101")) # 2
print(pairs("100100111001")) # 71
print(pairs("0011110001110011010111"))