File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
docs/data-structure/array Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -2961,6 +2961,31 @@ class Solution:
2961
2961
return ans
2962
2962
```
2963
2963
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
+
2964
2989
## 914. 卡牌分组
2965
2990
2966
2991
[ 原题链接] ( https://leetcode-cn.com/problems/x-of-a-kind-in-a-deck-of-cards/ )
You can’t perform that action at this time.
0 commit comments