classSolution: defisPathCrossing(self, path: str) -> bool: path_set = set([(0,0)]) pre = (0,0) for p in path: x, y = pre if p == 'N': y += 1 elif p == 'S': y -= 1 elif p == 'E': x += 1 elif p == 'W': x -= 1 # print(x,y) if (x,y) in path_set: returnTrue path_set.add((x,y)) pre = (x,y) returnFalse
classSolution: defcanArrange(self, arr: List[int], k: int) -> bool: num_map = [0] * k for i in range(len(arr)): arr[i] = (arr[i] % k + k) % k num_map[arr[i]] += 1 # print(num_map) if num_map[0] % 2: returnFalse for i in range(1, k // 2+1): if num_map[i] != num_map[k-i]: returnFalse returnTrue