Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6af2984

Browse files
committed
🐱(array): 832. 翻转图像
1 parent 42a8a36 commit 6af2984

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

docs/data-structure/array/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2961,6 +2961,31 @@ class Solution:
29612961
return ans
29622962
```
29632963

2964+
## 832. 翻转图像
2965+
2966+
[原题链接](https://leetcode-cn.com/problems/flipping-an-image/)
2967+
2968+
### 思路
2969+
2970+
遍历二维数组,利用双指针进行元素的原地替换。
2971+
2972+
```python
2973+
class Solution:
2974+
def flipAndInvertImage(self, A: List[List[int]]) -> List[List[int]]:
2975+
for line in A:
2976+
line_length = len(line)
2977+
for i in range(line_length):
2978+
j = line_length - 1 - i
2979+
if i < j:
2980+
line[i], line[j] = line[j], line[i]
2981+
line[i] = 1 - line[i]
2982+
line[j] = 1 - line[j]
2983+
elif i == j:
2984+
line[i] = 1 - line[i]
2985+
2986+
return A
2987+
```
2988+
29642989
## 914. 卡牌分组
29652990

29662991
[原题链接](https://leetcode-cn.com/problems/x-of-a-kind-in-a-deck-of-cards/)

0 commit comments

Comments
 (0)