We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d925e96 commit 0496a4bCopy full SHA for 0496a4b
Readme.md
@@ -1034,6 +1034,28 @@ f = lambda n: 1 if n < 2 else f(n - 1) + f(n - 2)
1034
1035
在一个m行n列二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。
1036
1037
+使用Step-wise线性搜索。
1038
+
1039
+```python
1040
+def get_value(l, r, c):
1041
+ return l[r][c]
1042
1043
+def find(l, x):
1044
+ m = len(l) - 1
1045
+ n = len(l[0]) - 1
1046
+ r = 0
1047
+ c = n
1048
+ while c >= 0 and r <= m:
1049
+ value = get_value(l, r, c)
1050
+ if value == x:
1051
+ return True
1052
+ elif value > x:
1053
+ c = c - 1
1054
+ elif value < x:
1055
+ r = r + 1
1056
+ return False
1057
+```
1058
1059
## 5 去除列表中的重复元素
1060
1061
用集合
0 commit comments