From 4a96974b5ee4194a19cb812119f1b21bbe16d6f3 Mon Sep 17 00:00:00 2001 From: yanglbme Date: Fri, 13 May 2022 14:16:15 +0800 Subject: [PATCH] feat: update python solutions to lc problems --- solution/0400-0499/0490.The Maze/README.md | 2 +- solution/0400-0499/0490.The Maze/README_EN.md | 2 +- solution/0400-0499/0490.The Maze/Solution.py | 2 +- solution/0700-0799/0773.Sliding Puzzle/README.md | 2 +- .../0700-0799/0773.Sliding Puzzle/README_EN.md | 2 +- .../0864.Shortest Path to Get All Keys/README.md | 2 +- .../README_EN.md | 2 +- .../0864.Shortest Path to Get All Keys/Solution.py | 2 +- .../1100-1199/1197.Minimum Knight Moves/README.md | 9 +++++---- .../1197.Minimum Knight Moves/README_EN.md | 7 ++++--- .../1197.Minimum Knight Moves/Solution.py | 14 +++----------- .../README.md | 2 +- .../README_EN.md | 2 +- .../Solution.py | 2 +- .../README.md | 2 +- .../README_EN.md | 2 +- .../Solution.py | 2 +- .../README.md | 2 +- .../README_EN.md | 2 +- .../Solution.py | 2 +- solution/1400-1499/1496.Path Crossing/README.md | 2 +- solution/1400-1499/1496.Path Crossing/README_EN.md | 2 +- solution/1400-1499/1496.Path Crossing/Solution.py | 2 +- .../README.md | 2 +- .../README_EN.md | 2 +- .../Solution.py | 2 +- .../1631.Path With Minimum Effort/README.md | 2 +- .../1631.Path With Minimum Effort/README_EN.md | 2 +- .../README.md | 2 +- .../README_EN.md | 2 +- .../README.md | 2 +- .../README_EN.md | 2 +- .../Solution.py | 2 +- 33 files changed, 42 insertions(+), 48 deletions(-) diff --git a/solution/0400-0499/0490.The Maze/README.md b/solution/0400-0499/0490.The Maze/README.md index c082e1e87f248..02d5d5fcba638 100644 --- a/solution/0400-0499/0490.The Maze/README.md +++ b/solution/0400-0499/0490.The Maze/README.md @@ -103,7 +103,7 @@ class Solution: m, n = len(maze), len(maze[0]) q = deque([start]) rs, cs = start - vis = set([(rs, cs)]) + vis = {(rs, cs)} while q: i, j = q.popleft() for a, b in [[0, -1], [0, 1], [-1, 0], [1, 0]]: diff --git a/solution/0400-0499/0490.The Maze/README_EN.md b/solution/0400-0499/0490.The Maze/README_EN.md index 8c236457c8e70..759c91fdebbd1 100644 --- a/solution/0400-0499/0490.The Maze/README_EN.md +++ b/solution/0400-0499/0490.The Maze/README_EN.md @@ -87,7 +87,7 @@ class Solution: m, n = len(maze), len(maze[0]) q = deque([start]) rs, cs = start - vis = set([(rs, cs)]) + vis = {(rs, cs)} while q: i, j = q.popleft() for a, b in [[0, -1], [0, 1], [-1, 0], [1, 0]]: diff --git a/solution/0400-0499/0490.The Maze/Solution.py b/solution/0400-0499/0490.The Maze/Solution.py index 568bde97329e9..c93a05d47ad42 100644 --- a/solution/0400-0499/0490.The Maze/Solution.py +++ b/solution/0400-0499/0490.The Maze/Solution.py @@ -5,7 +5,7 @@ def hasPath( m, n = len(maze), len(maze[0]) q = deque([start]) rs, cs = start - vis = set([(rs, cs)]) + vis = {(rs, cs)} while q: i, j = q.popleft() for a, b in [[0, -1], [0, 1], [-1, 0], [1, 0]]: diff --git a/solution/0700-0799/0773.Sliding Puzzle/README.md b/solution/0700-0799/0773.Sliding Puzzle/README.md index 015d7d452eac6..aaea7361d2ee1 100644 --- a/solution/0700-0799/0773.Sliding Puzzle/README.md +++ b/solution/0700-0799/0773.Sliding Puzzle/README.md @@ -121,7 +121,7 @@ class Solution: end = "123450" if start == end: return 0 - vis = set([(start)]) + vis = {start} q = deque([(start)]) ans = 0 while q: diff --git a/solution/0700-0799/0773.Sliding Puzzle/README_EN.md b/solution/0700-0799/0773.Sliding Puzzle/README_EN.md index 839bab0eef12b..3cdebd0aaa111 100644 --- a/solution/0700-0799/0773.Sliding Puzzle/README_EN.md +++ b/solution/0700-0799/0773.Sliding Puzzle/README_EN.md @@ -98,7 +98,7 @@ class Solution: end = "123450" if start == end: return 0 - vis = set([(start)]) + vis = {start} q = deque([(start)]) ans = 0 while q: diff --git a/solution/0800-0899/0864.Shortest Path to Get All Keys/README.md b/solution/0800-0899/0864.Shortest Path to Get All Keys/README.md index d3fe6bbcfe8ad..100ce0c581acc 100644 --- a/solution/0800-0899/0864.Shortest Path to Get All Keys/README.md +++ b/solution/0800-0899/0864.Shortest Path to Get All Keys/README.md @@ -89,7 +89,7 @@ class Solution: dirs = [-1, 0, 1, 0, -1] ans = 0 mask = (1 << cnt) - 1 - vis = set([(start[0], start[1], 0)]) + vis = {(*start, 0)} while q: for _ in range(len(q)): i, j, state = q.popleft() diff --git a/solution/0800-0899/0864.Shortest Path to Get All Keys/README_EN.md b/solution/0800-0899/0864.Shortest Path to Get All Keys/README_EN.md index b24ea5afe13f6..cc54c4a0e54d5 100644 --- a/solution/0800-0899/0864.Shortest Path to Get All Keys/README_EN.md +++ b/solution/0800-0899/0864.Shortest Path to Get All Keys/README_EN.md @@ -78,7 +78,7 @@ class Solution: dirs = [-1, 0, 1, 0, -1] ans = 0 mask = (1 << cnt) - 1 - vis = set([(start[0], start[1], 0)]) + vis = {(*start, 0)} while q: for _ in range(len(q)): i, j, state = q.popleft() diff --git a/solution/0800-0899/0864.Shortest Path to Get All Keys/Solution.py b/solution/0800-0899/0864.Shortest Path to Get All Keys/Solution.py index 97bc706c23f4c..100338a96e057 100644 --- a/solution/0800-0899/0864.Shortest Path to Get All Keys/Solution.py +++ b/solution/0800-0899/0864.Shortest Path to Get All Keys/Solution.py @@ -11,7 +11,7 @@ def shortestPathAllKeys(self, grid: List[str]) -> int: dirs = [-1, 0, 1, 0, -1] ans = 0 mask = (1 << cnt) - 1 - vis = set([(start[0], start[1], 0)]) + vis = {(*start, 0)} while q: for _ in range(len(q)): i, j, state = q.popleft() diff --git a/solution/1100-1199/1197.Minimum Knight Moves/README.md b/solution/1100-1199/1197.Minimum Knight Moves/README.md index a5ac0bc39f3ca..61e83f334e3c0 100644 --- a/solution/1100-1199/1197.Minimum Knight Moves/README.md +++ b/solution/1100-1199/1197.Minimum Knight Moves/README.md @@ -67,13 +67,14 @@ class Solution: def minKnightMoves(self, x: int, y: int) -> int: q = deque([(0, 0)]) ans = 0 - vis = set([(0, 0)]) + vis = {(0, 0)} + dirs = ((-2, 1), (-1, 2), (1, 2), (2, 1), (2, -1), (1, -2), (-1, -2), (-2, -1)) while q: for _ in range(len(q)): i, j = q.popleft() if (i, j) == (x, y): return ans - for a, b in [[-2, 1], [-1, 2], [1, 2], [2, 1], [2, -1], [1, -2], [-1, -2], [-2, -1]]: + for a, b in dirs: c, d = i + a, j + b if (c, d) not in vis: vis.add((c, d)) @@ -82,7 +83,7 @@ class Solution: return -1 ``` -双向 BFS; +双向 BFS: ```python class Solution: @@ -91,7 +92,7 @@ class Solution: for _ in range(len(q)): i, j = q.popleft() step = m1[(i, j)] - for a, b in [[-2, 1], [-1, 2], [1, 2], [2, 1], [2, -1], [1, -2], [-1, -2], [-2, -1]]: + for a, b in ((-2, 1), (-1, 2), (1, 2), (2, 1), (2, -1), (1, -2), (-1, -2), (-2, -1)): x, y = i + a, j + b if (x, y) in m1: continue diff --git a/solution/1100-1199/1197.Minimum Knight Moves/README_EN.md b/solution/1100-1199/1197.Minimum Knight Moves/README_EN.md index 969449fb8de63..f156455e71685 100644 --- a/solution/1100-1199/1197.Minimum Knight Moves/README_EN.md +++ b/solution/1100-1199/1197.Minimum Knight Moves/README_EN.md @@ -48,13 +48,14 @@ class Solution: def minKnightMoves(self, x: int, y: int) -> int: q = deque([(0, 0)]) ans = 0 - vis = set([(0, 0)]) + vis = {(0, 0)} + dirs = ((-2, 1), (-1, 2), (1, 2), (2, 1), (2, -1), (1, -2), (-1, -2), (-2, -1)) while q: for _ in range(len(q)): i, j = q.popleft() if (i, j) == (x, y): return ans - for a, b in [[-2, 1], [-1, 2], [1, 2], [2, 1], [2, -1], [1, -2], [-1, -2], [-2, -1]]: + for a, b in dirs: c, d = i + a, j + b if (c, d) not in vis: vis.add((c, d)) @@ -72,7 +73,7 @@ class Solution: for _ in range(len(q)): i, j = q.popleft() step = m1[(i, j)] - for a, b in [[-2, 1], [-1, 2], [1, 2], [2, 1], [2, -1], [1, -2], [-1, -2], [-2, -1]]: + for a, b in ((-2, 1), (-1, 2), (1, 2), (2, 1), (2, -1), (1, -2), (-1, -2), (-2, -1)): x, y = i + a, j + b if (x, y) in m1: continue diff --git a/solution/1100-1199/1197.Minimum Knight Moves/Solution.py b/solution/1100-1199/1197.Minimum Knight Moves/Solution.py index d233346ebc148..f8ee3acae1a08 100644 --- a/solution/1100-1199/1197.Minimum Knight Moves/Solution.py +++ b/solution/1100-1199/1197.Minimum Knight Moves/Solution.py @@ -2,22 +2,14 @@ class Solution: def minKnightMoves(self, x: int, y: int) -> int: q = deque([(0, 0)]) ans = 0 - vis = set([(0, 0)]) + vis = {(0, 0)} + dirs = ((-2, 1), (-1, 2), (1, 2), (2, 1), (2, -1), (1, -2), (-1, -2), (-2, -1)) while q: for _ in range(len(q)): i, j = q.popleft() if (i, j) == (x, y): return ans - for a, b in [ - [-2, 1], - [-1, 2], - [1, 2], - [2, 1], - [2, -1], - [1, -2], - [-1, -2], - [-2, -1], - ]: + for a, b in dirs: c, d = i + a, j + b if (c, d) not in vis: vis.add((c, d)) diff --git a/solution/1200-1299/1210.Minimum Moves to Reach Target with Rotations/README.md b/solution/1200-1299/1210.Minimum Moves to Reach Target with Rotations/README.md index 83fa7162528b1..0f34d03f9adf1 100644 --- a/solution/1200-1299/1210.Minimum Moves to Reach Target with Rotations/README.md +++ b/solution/1200-1299/1210.Minimum Moves to Reach Target with Rotations/README.md @@ -86,7 +86,7 @@ class Solution: n = len(grid) target = (n * n - 2, n * n - 1) q = deque([(0, 1)]) - vis = set([(0, 1)]) + vis = {(0, 1)} ans = 0 while q: for _ in range(len(q)): diff --git a/solution/1200-1299/1210.Minimum Moves to Reach Target with Rotations/README_EN.md b/solution/1200-1299/1210.Minimum Moves to Reach Target with Rotations/README_EN.md index 0b1e0f61c63e6..5a1b88fb35b4a 100644 --- a/solution/1200-1299/1210.Minimum Moves to Reach Target with Rotations/README_EN.md +++ b/solution/1200-1299/1210.Minimum Moves to Reach Target with Rotations/README_EN.md @@ -78,7 +78,7 @@ class Solution: n = len(grid) target = (n * n - 2, n * n - 1) q = deque([(0, 1)]) - vis = set([(0, 1)]) + vis = {(0, 1)} ans = 0 while q: for _ in range(len(q)): diff --git a/solution/1200-1299/1210.Minimum Moves to Reach Target with Rotations/Solution.py b/solution/1200-1299/1210.Minimum Moves to Reach Target with Rotations/Solution.py index e7f10b0b0ef38..668ab6e12994d 100644 --- a/solution/1200-1299/1210.Minimum Moves to Reach Target with Rotations/Solution.py +++ b/solution/1200-1299/1210.Minimum Moves to Reach Target with Rotations/Solution.py @@ -8,7 +8,7 @@ def check(a, b): n = len(grid) target = (n * n - 2, n * n - 1) q = deque([(0, 1)]) - vis = set([(0, 1)]) + vis = {(0, 1)} ans = 0 while q: for _ in range(len(q)): diff --git a/solution/1200-1299/1284.Minimum Number of Flips to Convert Binary Matrix to Zero Matrix/README.md b/solution/1200-1299/1284.Minimum Number of Flips to Convert Binary Matrix to Zero Matrix/README.md index 95de264935584..dbce8c7ba704a 100644 --- a/solution/1200-1299/1284.Minimum Number of Flips to Convert Binary Matrix to Zero Matrix/README.md +++ b/solution/1200-1299/1284.Minimum Number of Flips to Convert Binary Matrix to Zero Matrix/README.md @@ -73,7 +73,7 @@ class Solution: state = sum(1 << (i * n + j) for i in range(m) for j in range(n) if mat[i][j]) q = deque([state]) - vis = set([state]) + vis = {state} ans = 0 dirs = [0, -1, 0, 1, 0, 0] while q: diff --git a/solution/1200-1299/1284.Minimum Number of Flips to Convert Binary Matrix to Zero Matrix/README_EN.md b/solution/1200-1299/1284.Minimum Number of Flips to Convert Binary Matrix to Zero Matrix/README_EN.md index da74ae85ed4b8..0ceacfd064ca8 100644 --- a/solution/1200-1299/1284.Minimum Number of Flips to Convert Binary Matrix to Zero Matrix/README_EN.md +++ b/solution/1200-1299/1284.Minimum Number of Flips to Convert Binary Matrix to Zero Matrix/README_EN.md @@ -60,7 +60,7 @@ class Solution: state = sum(1 << (i * n + j) for i in range(m) for j in range(n) if mat[i][j]) q = deque([state]) - vis = set([state]) + vis = {state} ans = 0 dirs = [0, -1, 0, 1, 0, 0] while q: diff --git a/solution/1200-1299/1284.Minimum Number of Flips to Convert Binary Matrix to Zero Matrix/Solution.py b/solution/1200-1299/1284.Minimum Number of Flips to Convert Binary Matrix to Zero Matrix/Solution.py index 91baf72739270..d6eac7aa1578f 100644 --- a/solution/1200-1299/1284.Minimum Number of Flips to Convert Binary Matrix to Zero Matrix/Solution.py +++ b/solution/1200-1299/1284.Minimum Number of Flips to Convert Binary Matrix to Zero Matrix/Solution.py @@ -3,7 +3,7 @@ def minFlips(self, mat: List[List[int]]) -> int: m, n = len(mat), len(mat[0]) state = sum(1 << (i * n + j) for i in range(m) for j in range(n) if mat[i][j]) q = deque([state]) - vis = set([state]) + vis = {state} ans = 0 dirs = [0, -1, 0, 1, 0, 0] while q: diff --git a/solution/1200-1299/1293.Shortest Path in a Grid with Obstacles Elimination/README.md b/solution/1200-1299/1293.Shortest Path in a Grid with Obstacles Elimination/README.md index 1fb8cf4e654e2..3609811937fb2 100644 --- a/solution/1200-1299/1293.Shortest Path in a Grid with Obstacles Elimination/README.md +++ b/solution/1200-1299/1293.Shortest Path in a Grid with Obstacles Elimination/README.md @@ -68,7 +68,7 @@ class Solution: if k >= m + n - 3: return m + n - 2 q = deque([(0, 0, k)]) - vis = set([(0, 0, k)]) + vis = {(0, 0, k)} ans = 0 while q: ans += 1 diff --git a/solution/1200-1299/1293.Shortest Path in a Grid with Obstacles Elimination/README_EN.md b/solution/1200-1299/1293.Shortest Path in a Grid with Obstacles Elimination/README_EN.md index 9a58aadceea83..0f72df5c266eb 100644 --- a/solution/1200-1299/1293.Shortest Path in a Grid with Obstacles Elimination/README_EN.md +++ b/solution/1200-1299/1293.Shortest Path in a Grid with Obstacles Elimination/README_EN.md @@ -52,7 +52,7 @@ class Solution: if k >= m + n - 3: return m + n - 2 q = deque([(0, 0, k)]) - vis = set([(0, 0, k)]) + vis = {(0, 0, k)} ans = 0 while q: ans += 1 diff --git a/solution/1200-1299/1293.Shortest Path in a Grid with Obstacles Elimination/Solution.py b/solution/1200-1299/1293.Shortest Path in a Grid with Obstacles Elimination/Solution.py index 2ef0db1d5a6ae..a8cc93c7bd92b 100644 --- a/solution/1200-1299/1293.Shortest Path in a Grid with Obstacles Elimination/Solution.py +++ b/solution/1200-1299/1293.Shortest Path in a Grid with Obstacles Elimination/Solution.py @@ -4,7 +4,7 @@ def shortestPath(self, grid: List[List[int]], k: int) -> int: if k >= m + n - 3: return m + n - 2 q = deque([(0, 0, k)]) - vis = set([(0, 0, k)]) + vis = {(0, 0, k)} ans = 0 while q: ans += 1 diff --git a/solution/1400-1499/1496.Path Crossing/README.md b/solution/1400-1499/1496.Path Crossing/README.md index ac78380b9d934..4bc64a1f9f749 100644 --- a/solution/1400-1499/1496.Path Crossing/README.md +++ b/solution/1400-1499/1496.Path Crossing/README.md @@ -55,7 +55,7 @@ class Solution: def isPathCrossing(self, path: str) -> bool: x = y = 0 - vis = set([(x, y)]) + vis = {(x, y)} for c in path: if c == 'N': y += 1 diff --git a/solution/1400-1499/1496.Path Crossing/README_EN.md b/solution/1400-1499/1496.Path Crossing/README_EN.md index d4eb47e334e92..69cfc93879e5f 100644 --- a/solution/1400-1499/1496.Path Crossing/README_EN.md +++ b/solution/1400-1499/1496.Path Crossing/README_EN.md @@ -42,7 +42,7 @@ class Solution: def isPathCrossing(self, path: str) -> bool: x = y = 0 - vis = set([(x, y)]) + vis = {(x, y)} for c in path: if c == 'N': y += 1 diff --git a/solution/1400-1499/1496.Path Crossing/Solution.py b/solution/1400-1499/1496.Path Crossing/Solution.py index aabf3c0c563ad..faaedd009cd51 100644 --- a/solution/1400-1499/1496.Path Crossing/Solution.py +++ b/solution/1400-1499/1496.Path Crossing/Solution.py @@ -1,7 +1,7 @@ class Solution: def isPathCrossing(self, path: str) -> bool: x = y = 0 - vis = set([(x, y)]) + vis = {(x, y)} for c in path: if c == 'N': y += 1 diff --git a/solution/1500-1599/1546.Maximum Number of Non-Overlapping Subarrays With Sum Equals Target/README.md b/solution/1500-1599/1546.Maximum Number of Non-Overlapping Subarrays With Sum Equals Target/README.md index 81af839eae614..f188e75588d67 100644 --- a/solution/1500-1599/1546.Maximum Number of Non-Overlapping Subarrays With Sum Equals Target/README.md +++ b/solution/1500-1599/1546.Maximum Number of Non-Overlapping Subarrays With Sum Equals Target/README.md @@ -69,7 +69,7 @@ class Solution: ans = 0 while i < n: s = 0 - seen = set([0]) + seen = {0} while i < n: s += nums[i] if s - target in seen: diff --git a/solution/1500-1599/1546.Maximum Number of Non-Overlapping Subarrays With Sum Equals Target/README_EN.md b/solution/1500-1599/1546.Maximum Number of Non-Overlapping Subarrays With Sum Equals Target/README_EN.md index ac2ee13b39f2b..e43da4d93f192 100644 --- a/solution/1500-1599/1546.Maximum Number of Non-Overlapping Subarrays With Sum Equals Target/README_EN.md +++ b/solution/1500-1599/1546.Maximum Number of Non-Overlapping Subarrays With Sum Equals Target/README_EN.md @@ -46,7 +46,7 @@ class Solution: ans = 0 while i < n: s = 0 - seen = set([0]) + seen = {0} while i < n: s += nums[i] if s - target in seen: diff --git a/solution/1500-1599/1546.Maximum Number of Non-Overlapping Subarrays With Sum Equals Target/Solution.py b/solution/1500-1599/1546.Maximum Number of Non-Overlapping Subarrays With Sum Equals Target/Solution.py index 351a9194e91bf..5d4276a245cb5 100644 --- a/solution/1500-1599/1546.Maximum Number of Non-Overlapping Subarrays With Sum Equals Target/Solution.py +++ b/solution/1500-1599/1546.Maximum Number of Non-Overlapping Subarrays With Sum Equals Target/Solution.py @@ -4,7 +4,7 @@ def maxNonOverlapping(self, nums: List[int], target: int) -> int: ans = 0 while i < n: s = 0 - seen = set([0]) + seen = {0} while i < n: s += nums[i] if s - target in seen: diff --git a/solution/1600-1699/1631.Path With Minimum Effort/README.md b/solution/1600-1699/1631.Path With Minimum Effort/README.md index 789427d855f40..9a85ed2f17040 100644 --- a/solution/1600-1699/1631.Path With Minimum Effort/README.md +++ b/solution/1600-1699/1631.Path With Minimum Effort/README.md @@ -174,7 +174,7 @@ class Solution: while left < right: mid = (left + right) >> 1 q = deque([(0, 0)]) - vis = set([(0, 0)]) + vis = {(0, 0)} while q: i, j = q.popleft() for a, b in [[0, 1], [0, -1], [1, 0], [-1, 0]]: diff --git a/solution/1600-1699/1631.Path With Minimum Effort/README_EN.md b/solution/1600-1699/1631.Path With Minimum Effort/README_EN.md index 208e29dede7a9..31513be0f6981 100644 --- a/solution/1600-1699/1631.Path With Minimum Effort/README_EN.md +++ b/solution/1600-1699/1631.Path With Minimum Effort/README_EN.md @@ -112,7 +112,7 @@ class Solution: while left < right: mid = (left + right) >> 1 q = deque([(0, 0)]) - vis = set([(0, 0)]) + vis = {(0, 0)} while q: i, j = q.popleft() for a, b in [[0, 1], [0, -1], [1, 0], [-1, 0]]: diff --git a/solution/2000-2099/2059.Minimum Operations to Convert Number/README.md b/solution/2000-2099/2059.Minimum Operations to Convert Number/README.md index 9d375997edf8b..d4464a343f5e3 100644 --- a/solution/2000-2099/2059.Minimum Operations to Convert Number/README.md +++ b/solution/2000-2099/2059.Minimum Operations to Convert Number/README.md @@ -143,7 +143,7 @@ class Solution: return res q = deque([start]) - vis = set([(start)]) + vis = {start} ans = 0 while q: ans += 1 diff --git a/solution/2000-2099/2059.Minimum Operations to Convert Number/README_EN.md b/solution/2000-2099/2059.Minimum Operations to Convert Number/README_EN.md index f4e1ac0391f1b..c32f6f1d3ac2a 100644 --- a/solution/2000-2099/2059.Minimum Operations to Convert Number/README_EN.md +++ b/solution/2000-2099/2059.Minimum Operations to Convert Number/README_EN.md @@ -101,7 +101,7 @@ class Solution: return res q = deque([start]) - vis = set([(start)]) + vis = {start} ans = 0 while q: ans += 1 diff --git a/solution/2100-2199/2174.Remove All Ones With Row and Column Flips II/README.md b/solution/2100-2199/2174.Remove All Ones With Row and Column Flips II/README.md index fcbe1c55dcbf8..c56a792646d73 100644 --- a/solution/2100-2199/2174.Remove All Ones With Row and Column Flips II/README.md +++ b/solution/2100-2199/2174.Remove All Ones With Row and Column Flips II/README.md @@ -81,7 +81,7 @@ class Solution: state = sum(1 << (i * n + j) for i in range(m) for j in range(n) if grid[i][j]) q = deque([state]) - vis = set([state]) + vis = {state} ans = 0 while q: for _ in range(len(q)): diff --git a/solution/2100-2199/2174.Remove All Ones With Row and Column Flips II/README_EN.md b/solution/2100-2199/2174.Remove All Ones With Row and Column Flips II/README_EN.md index 72dca0f1e5fe1..5ed9b8c31eeb9 100644 --- a/solution/2100-2199/2174.Remove All Ones With Row and Column Flips II/README_EN.md +++ b/solution/2100-2199/2174.Remove All Ones With Row and Column Flips II/README_EN.md @@ -73,7 +73,7 @@ class Solution: state = sum(1 << (i * n + j) for i in range(m) for j in range(n) if grid[i][j]) q = deque([state]) - vis = set([state]) + vis = {state} ans = 0 while q: for _ in range(len(q)): diff --git a/solution/2100-2199/2174.Remove All Ones With Row and Column Flips II/Solution.py b/solution/2100-2199/2174.Remove All Ones With Row and Column Flips II/Solution.py index 2441c27209614..99ed9655e5f43 100644 --- a/solution/2100-2199/2174.Remove All Ones With Row and Column Flips II/Solution.py +++ b/solution/2100-2199/2174.Remove All Ones With Row and Column Flips II/Solution.py @@ -3,7 +3,7 @@ def removeOnes(self, grid: List[List[int]]) -> int: m, n = len(grid), len(grid[0]) state = sum(1 << (i * n + j) for i in range(m) for j in range(n) if grid[i][j]) q = deque([state]) - vis = set([state]) + vis = {state} ans = 0 while q: for _ in range(len(q)):