<jupyter_start><jupyter_text>多存储一个信息，最后一个为 dir信息，不能往回走，上方向为 2，下方向为 -2， 左方向为3，右方向为 - 3<jupyter_code>class Solution:
    def containsCycle(self, grid):
        def is_circle(a, b, direc):
            nonlocal visited
            # 返回两个值，如果为 False 的话，那么从探索点开始的周围点也是 False
            seen = set()
            stack = [(a, b, direc)]
            symbol = grid[a][b]
            while stack:
                r, c, d = stack.pop()
                seen.add((r, c))
                nd = 0
                for nr, nc, nd in (r+1, c, -2), (r-1, c, 2), (r, c+1, -3), (r, c-1, 3):
                    if nr < 0 or nc < 0 or nr >= rows or nc >= cols or grid[nr][nc] != symbol:
                        continue
                    if nd + d == 0:
                        continue
                    if (nr, nc) in seen:
                        return seen, True
                    stack.append((nr, nc, nd))
            return seen, False
        
        rows, cols = len(grid), len(grid[0])
        visited = set()
        for r in range(rows):
            for c in range(cols):
                if (r, c) in visited:
                    continue
                state, res = is_circle(r, c, -1)
                if res is True:
                    return True
                visited |= state
        return False
solution = Solution()
solution.containsCycle([["c","a","d"],["a","a","a"],["a","a","d"],["a","c","d"],["a","b","c"]])
a = {1, 2}
b = {2, 5}
c = a | b
c
a = [1, 2, 4]
a.index(2)<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup