diff --git a/contests/Leetcode/weekly/weekly 259/Detect Squares.py b/contests/Leetcode/weekly/weekly 259/Detect Squares.py new file mode 100644 index 0000000..423916c --- /dev/null +++ b/contests/Leetcode/weekly/weekly 259/Detect Squares.py @@ -0,0 +1,43 @@ +class DetectSquares: + + def __init__(self): + self.store={} + + def add(self, point: List[int]) -> None: + point=tuple(point) + if point not in self.store: + self.store[point]=0 + self.store[point]+=1 + + def count(self, point: List[int]) -> int: + ans=0 + x,y = point[0]-1,point[1]-1 + while x>=0 and y>=0: + if (x,y) in self.store and (x,point[1]) in self.store and (point[0],y) in self.store: + ans += self.store[(x,y)] * self.store[(x,point[1])] * self.store[(point[0],y)] + x-=1 + y-=1 + x,y = point[0]-1,point[1]+1 + while x>=0 and y<=1000: + if (x,y) in self.store and (x,point[1]) in self.store and (point[0],y) in self.store: + ans += self.store[(x,y)] * self.store[(x,point[1])] * self.store[(point[0],y)] + x-=1 + y+=1 + x,y = point[0]+1,point[1]-1 + while x<=1000 and y>=0: + if (x,y) in self.store and (x,point[1]) in self.store and (point[0],y) in self.store: + ans += self.store[(x,y)] * self.store[(x,point[1])] * self.store[(point[0],y)] + x+=1 + y-=1 + x,y = point[0]+1,point[1]+1 + while x<=1000 and y<=1000: + if (x,y) in self.store and (x,point[1]) in self.store and (point[0],y) in self.store: + ans += self.store[(x,y)] * self.store[(x,point[1])] * self.store[(point[0],y)] + x+=1 + y+=1 + return ans + +# Your DetectSquares object will be instantiated and called as such: +# obj = DetectSquares() +# obj.add(point) +# param_2 = obj.count(point) diff --git a/contests/Leetcode/weekly/weekly 259/Final Value of Variable After Performing Operations.py b/contests/Leetcode/weekly/weekly 259/Final Value of Variable After Performing Operations.py new file mode 100644 index 0000000..2567f51 --- /dev/null +++ b/contests/Leetcode/weekly/weekly 259/Final Value of Variable After Performing Operations.py @@ -0,0 +1,9 @@ +class Solution: + def finalValueAfterOperations(self, op: List[str]) -> int: + ans=0 + for i in op: + if '++' in i: + ans+=1 + else: + ans-=1 + return ans diff --git a/contests/Leetcode/weekly/weekly 259/Sum of Beauty in the Array.py b/contests/Leetcode/weekly/weekly 259/Sum of Beauty in the Array.py new file mode 100644 index 0000000..95d170c --- /dev/null +++ b/contests/Leetcode/weekly/weekly 259/Sum of Beauty in the Array.py @@ -0,0 +1,21 @@ +class Solution: + def sumOfBeauties(self, nums: List[int]) -> int: + n=len(nums) + ans=0 + for i in range(1,n-1): + if nums[i-1]