68 lines
1.8 KiB
Python
68 lines
1.8 KiB
Python
# def compress_string(s: str) -> str:
|
|
# result=""
|
|
# count=1
|
|
|
|
# for i in range(1, len(s)):
|
|
# if s[i] == s[i - 1]:
|
|
# count += 1
|
|
# else:
|
|
# result += s[i - 1]
|
|
# if count > 1:
|
|
# result += str(count)
|
|
# count = 1
|
|
# result+=s[-1]
|
|
# if count > 1:
|
|
# result+=str(count)
|
|
# return result
|
|
|
|
# if __name__ == "__main__":
|
|
# # print(compress_string('aaabbbbbccddddddddrrraaaa'))
|
|
# =====================================
|
|
# def is_armstrong(n: int) -> bool:
|
|
# digits=str(n)
|
|
# power=len(digits)
|
|
# total=0
|
|
|
|
# for digit in digits:
|
|
# total += int(digit)**power
|
|
# return total == n
|
|
|
|
# if __name__ == '__main__':
|
|
# print(is_armstrong(160))
|
|
# print('=================')
|
|
# print(is_armstrong(153))
|
|
# ================================
|
|
# def interseption_of_sorted(a: list, b: list) -> list:
|
|
# return sorted(set(a) & set(b))
|
|
|
|
# if __name__ == '__main__':
|
|
# print(interseption_of_sorted([1, 1, 1, 2, 3, 4, 5],[1, 5, 2, 3, 45, 5]))
|
|
# =============================
|
|
# def remove(s: str) -> str:
|
|
# seen=set()
|
|
# result=""
|
|
|
|
# for i in s:
|
|
# if i not in seen:
|
|
# seen.add(i)
|
|
# result+=i
|
|
# return result
|
|
# if __name__ == "__main__":
|
|
# print(remove('bebebebeaaaassdsdsad'))
|
|
# ================================
|
|
# def most_frequent(d: dict) -> tuple:
|
|
# count={}
|
|
# for value in d.values():
|
|
# count[value]=count.get(value, 0)+1
|
|
# best_value=max(count, key=count.get)
|
|
# return best_value, count[best_value]
|
|
|
|
# if __name__ == "__main__":
|
|
# print(most_frequent({'a': 4, 'b': 4, 'c': 4, 'g': 3}))
|
|
def gcd(a: int, b: int) -> int:
|
|
while b!=0:
|
|
a, b = b,a%b
|
|
return a
|
|
|
|
if __name__=='__main__':
|
|
print(gcd(121, 11)) |