Advertisement
0xPrototype

Untitled

Jul 5th, 2022
618
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None
  1. class Array(object):
  2.  
  3.     def __init__(self, items: list) -> None:
  4.         self.items = items
  5.         self.length = len(items)
  6.  
  7.     def set_length(self, new_len):
  8.         self.length = new_len
  9.  
  10.     def __repr__(self) -> str:
  11.         return '{}({})'.format(self.__class__.__name__, self.items)
  12.  
  13.     def __len__(self) -> int:
  14.         return self.length
  15.  
  16.     def __contains__(self, item: any) -> bool:
  17.         return item in self.items
  18.  
  19.     def __getitem__(self, key: int) -> any:
  20.         return self.items[key - 1]
  21.  
  22.     def __setitem__(self, key: int, value: any) -> None:
  23.         self.items[key - 1] = value
  24.  
  25.     def __delitem__(self, key: int) -> None:
  26.         del self.items[key - 1]
  27.  
  28.  
  29. def check_arr(arr: Array) -> bool:
  30.     n = len(arr)
  31.     res = False
  32.     for i in range(1, n + 1):
  33.         n = n
  34.         for j in range(n, i + 1, -1):
  35.             n = n - i
  36.             print(n)
  37.             if arr[j] == arr[i]:
  38.                 res = True
  39.     return res
  40.  
  41.  
  42. def main():
  43.     A = Array([5, 7, 1, 8, 5, 7])
  44.     res = check_arr(A)
  45.     print(res)
  46.  
  47.  
  48. if __name__ == '__main__':
  49.     main()
  50.  
Advertisement
RAW Paste Data Copied
Advertisement